Code:
#include <iostream>
#include <stdio.h>
#include <string>
#include <Windows.h>
#include <TlHelp32.h>
using namespace std;
__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;
}
LPCSTR GameWindow;
LPCSTR GameID;
HWND WindowID;
__int64 BaseAddress;
DWORD PID;
HANDLE pHandle;
byte EnableGod = 9;
byte DisableGod = 0;
DWORD GodOffset = 0x189;
DWORD HealthOffset = 0x280;
DWORD MaxHealthOffset = 0x2A0;
DWORD ArmorOffset = 0x14B8;
DWORD PlayerOffset = 0x8;
DWORD WorldOffset_SocialClub = 0x23DE120; // Update on when new dlc come out
DWORD WorldOffset_Steam = 0x23E2130; // Update on when new dlc come out
__int64 GodAddress;
__int64 PedAddress;
__int64 PlayerPedAddress;
__int64 HealthAddress;
__int64 MaxHealthAddress;
__int64 ArmorAddress;
__int64 WantedAddress;
float MaxHealth;
float MaxArmor = 50;
void console() {
HWND console = GetConsoleWindow();
SetWindowLong(console, GWL_STYLE, GetWindowLong(console, GWL_STYLE) & ~WS_MAXIMIZEBOX & ~WS_SIZEBOX);
RECT r;
GetWindowRect(console, &r);
MoveWindow(console, r.left, r.top, 500, 500, TRUE);
system("color d");
}
void load() {
GameWindow = "Grand Theft Auto V";
GameID = "GTA5.exe";
WindowID = FindWindow(NULL, GameWindow);
BaseAddress = GetModuleBaseAddress(GameID, GameID);
GetWindowThreadProcessId(WindowID, &PID);
pHandle = OpenProcess(PROCESS_ALL_ACCESS, 0, PID);
}
void address() {
ReadProcessMemory(pHandle, (void*)(BaseAddress + WorldOffset_Steam), &PedAddress, sizeof(PedAddress), NULL);
ReadProcessMemory(pHandle, (void*)(PedAddress + PlayerOffset), &PlayerPedAddress, sizeof(PlayerPedAddress), NULL);
GodAddress = (PlayerPedAddress + GodOffset);
HealthAddress = (PlayerPedAddress + HealthOffset);
MaxHealthAddress = (PlayerPedAddress + MaxHealthOffset);
ArmorAddress = (PlayerPedAddress + ArmorOffset);
}
int main() {
load();
address();
console();
while (1)
{
if (BaseAddress == 0) {
MessageBox(NULL, "GTA5 is not running", "Error", MB_OK);
return -1;
}
int choice = 0;
cout << "1 = Toggle Godmode" << endl;
byte CheckGod = 0;
ReadProcessMemory(pHandle, (void*)(GodAddress), &CheckGod, sizeof(CheckGod), NULL);
if (CheckGod == 0) {
cout << "Godmode = Disabled" << endl;
}
if (CheckGod == 9) {
cout << "Godmode = Enabled" << endl;
}
cin >> choice;
if (choice == 1) {
if (CheckGod == 0)
WriteProcessMemory(pHandle, (void*)GodAddress, &EnableGod, sizeof(EnableGod), NULL);
if (CheckGod == 9)
WriteProcessMemory(pHandle, (void*)GodAddress, &DisableGod, sizeof(DisableGod), NULL);
}
system("CLS");
}
return 0;
}
Credits: