#include <cstring>
#include <windows.h>
#include <tlhelp32.h>
HANDLE getProcessHandle(const char* const name)
{
PROCESSENTRY32 entry{};
entry.dwSize = sizeof(entry);
HANDLE snapshot{CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL)};
if (TRUE == Process32First(snapshot, &entry))
{
while (TRUE == Process32Next(snapshot, &entry))
{
if (0 == std::strcmp(entry.szExeFile, name))
{
CloseHandle(snapshot);
return OpenProcess(PROCESS_ALL_ACCESS, FALSE, entry.th32ProcessID);
}
}
}
}
int main()
{
HANDLE handle{getProcessHandle("gta_sa.exe")};
if (!handle) {
return EXIT_FAILURE;
}
while (true)
{
static bool infiniteRun{true};
WriteProcessMemory(handle,
reinterpret_cast<LPVOID>(0xB7CEE4),
&infiniteRun,
sizeof(infiniteRun),
nullptr);
Sleep(1000);
}
}