DWORD GetModuleBase(LPSTR lpModuleName, DWORD dwProcessId)
{
MODULEENTRY32 lpModuleEntry = { 0 };
HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwProcessId);
if (!hSnapShot) return NULL;
lpModuleEntry.dwSize = sizeof(lpModuleEntry);
BOOL bModule = Module32First(hSnapShot, &lpModuleEntry);
while (bModule)
{
if (!strcmp(lpModuleEntry.szModule, lpModuleName))
{
CloseHandle(hSnapShot);
return (DWORD)lpModuleEntry.modBaseAddr;
}
bModule = Module32Next(hSnapShot, &lpModuleEntry);
}
CloseHandle(hSnapShot);
return NULL;
}
int main()
{
DWORD pID = 0;
HWND hwnd = FindWindowA(0, "Counter-Strike Source");
GetWindowThreadProcessId(hwnd, &pID);
HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, 0, pID);
DWORD dwEngine = GetModuleBase("engine.dll", pID);
int sv_cheats = 0x51F774 + dwEngine;
int Value = 1;
WriteProcessMemory(hProc, (LPVOID)sv_cheats, &Value, 4, 0);
return 0;
}