Game: Counter-Strike Source Version: v34
Код
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;
}
DWORD GetProcessByName(char* process_name)
{
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (hSnapshot == INVALID_HANDLE_VALUE) return false;
PROCESSENTRY32 pe = { 0 };
pe.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(hSnapshot, &pe))
{
while (Process32Next(hSnapshot, &pe))
{
if (!lstrcmpi(pe.szExeFile, process_name))
{
DWORD pID = pe.th32ProcessID;
CloseHandle(hSnapshot);
return pID;
}
}
}
return FALSE;
}
int main()
{
int Value = 1;
DWORD pID = GetProcessByName("hl2.exe");
HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, 0, pID);
DWORD dwEngine = GetModuleBase("engine.dll", pID);
int sv_cheats = 0x51F774 + dwEngine;
WriteProcessMemory(hProc, (LPVOID)sv_cheats, &Value, 4, 0);
return 0;
}