HelpHelp with base addresses and pointers.

Posts 13 of 3 · Page 1 of 1
Help with base addresses and pointers.
Hello mpgh, I started am trying to make an external mod with my limited C++ knowledge and the help of the internet, but I am struggling with memory addresses/pointers. Here is my code so far:

Code:
#include "stdafx.h"
#include <iostream>
#include <Windows.h>

using namespace std;

int main()
{
	int gravValue = 200;

	HWND hwnd = FindWindowA(NULL, "Grand Theft Auto V");
	if (hwnd == NULL)
	{
		cout << "Could not find game window" << endl;
		Sleep(3000);
		exit(-1);
	}
	else
	{
		static DWORD procID;
		GetWindowThreadProcessId(hwnd, &procID);
		HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, procID);

		if (procID == NULL)
		{
			cout << "Couldnt get PID" << endl;
			Sleep(3000);
			exit(-1);
		}

		else
		{
			for (;;)
			{
				if (GetAsyncKeyState(VK_SPACE))
				{
					WriteProcessMemory(handle, (LPVOID)0x0, &gravValue, sizeof(gravValue), 0);
					cout << "it worked" << endl;
					Sleep(4000);
					exit(-1);
				}
			}
		}
	}


    return 0;
}
I want to be able to change the gravity by pressing the spacebar, and later create different gravity functions triggered by different keys. However I cant figure out how to change the gravity value since the address for gravity changes when the game is restarted. I have the offsets I need (0x08, 0xD28,0xBCC), but I don't know how to implement them. Thanks in advance.
Code:
__int64 GetModuleBaseAddress(LPCSTR szProcessName, LPCSTR szModuleName) {
	HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
	PROCESSENTRY32 pe32;
	if (hSnap == INVALID_HANDLE_VALUE) {
		return 0;
	}
	pe32.dwSize = sizeof(PROCESSENTRY32);
	if (Process32First(hSnap, &pe32) == 0) {
		CloseHandle(hSnap);
		return 0;
	}
	do {
		if (lstrcmp(pe32.szExeFile, szProcessName) == 0) {
			int PID;
			PID = pe32.th32ProcessID;
			HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, PID);
			MODULEENTRY32 xModule;
			if (hSnap == INVALID_HANDLE_VALUE) {
				return 0;
			}
			xModule.dwSize = sizeof(MODULEENTRY32);
			if (Module32First(hSnap, &xModule) == 0) {
				CloseHandle(hSnap);
				return 0;
			}
			do {
				if (lstrcmp(xModule.szModule, szModuleName) == 0) {
					CloseHandle(hSnap);
					return (__int64)xModule.modBaseAddr;
				}
			} while (Module32Next(hSnap, &xModule));
			CloseHandle(hSnap);
			return 0;
		}
	} while (Process32Next(hSnap, &pe32));
	CloseHandle(hSnap);
	return 0;
}
Not sure I understand what this means or how it works. Could I use this function to write to memory? Sorry for the dumb questions but I am a bit lost.
Posts 13 of 3 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?