Search code examples
c++window

Which data type I need to use for [byte] In base memory address?


I working on a program that "hacks" GTA: San Andreas.

I'm using WriteProcessMemory function to write data into the base memory of the specific item, and FindWindow to find the GTA: San Andreas Window.

My Problem is that the second and the third WriteProcessMemory does not working, It does not affect the game and does nothing.

I saw here the base memory addresses and the data type I need, you can scroll down to Cheats options and see that the base memory and the data type [byte] they need.

Example:

#include <iostream>
#include <Windows.h>

using namespace std;

void GameHack(LPCSTR winname)
{
    int newValue = 125555;
    byte bytes = 1;
    HWND GameWindow = FindWindowA(NULL, winname);
    if (GameWindow == NULL) {
        auto errorcode = GetLastError();
        std::cout << "Failed to FindWindow & Error Code: " << errorcode;
        Sleep(3000);
        exit(1);
    }
    else {
        DWORD procID;
        GetWindowThreadProcessId(GameWindow, &procID);
        HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, procID);

        if (handle == NULL) {    // compare handle to NULL, not procID to FALSE
            auto errorcode = GetLastError();  // 1st thing to do                 
            std::cout << "procID Failed & Error Code: " << errorcode;
            Sleep(3000);
            exit(1);
        }
        else {
            int option;
            cout << "\n 1. Money Booster!\n 2. Weapon Set 1\n 3. Max Muscle\n\n";
            cout << " Choose One Option You Want To Do: "; cin >> option;
            if (option == 1) {
                WriteProcessMemory(handle, (LPVOID)0x00C0F188, &newValue, sizeof(newValue), NULL);
            }
            if (option == 2) {
                WriteProcessMemory(handle, (LPVOID)0x969130, &bytes, sizeof(bytes), NULL);
            }
            if (option == 3) {
                WriteProcessMemory(handle, (LPVOID)0x969155, &bytes, sizeof(bytes), NULL);
            }
            CloseHandle(handle);
        }
    }
}

int main()
{
    GameHack("GTA: San Andreas");
    return 0;
}

I want to add Weapon Set 1 to my character and Max Muscle.

Which data type and value should I need to use for this ?


Solution

  • The website you linked lists the data type you need to use as a byte, which you are doing. If your first WriteProcessMemory works but the second 2 do not work, then the addresses have changed.

    Your first address for money is listed as 0x00C0F188 which differs from the one listed on the website and it works.

    If you are having to use a different address for money, then most likely you will have different addresses for all the variables.

    You need to find the version of your game first and compare it against that guide. Either way the best solution is always to reverse the addresses yourself rather than relying on someone else's work which may be outdated.