JustPaste.it

#include <iostream>
#include <windows.h>
#include <string>
#include <ctime>


DWORD FindDmaAddy(int PointerLevel, HANDLE hProc, DWORD Offsets[], DWORD BaseAdress);
void WriteToMemory(HANDLE hProcHandle);


std::string GameName = "Plants vs. Zombies";
LPCSTR LGameWindow = "Plants vs. Zombies";
std::string GameStatus;
bool IsGameAvail;
bool UpdateOnNextRun;

//Sun VARS
bool SunStatus;
BYTE SunValue[] = {0x39, 0x5, 0x0, 0x0};
DWORD SunBaseAdress = { 0x00729670 };
DWORD SunOffsets[] = { 0x5578, 0x868};

int main()
{
HWND hGameWindow = NULL;
int timeSinceLastUpdate = clock();
int GameAvailTMR = clock();
int onePressTMR = clock();
DWORD dwProcID = NULL;
HANDLE hProcHandle = NULL;
UpdateOnNextRun = true;
std::string sSunStatus = "OFF";
std::string sHealthStatus = "OFF";

while (!GetAsyncKeyState(VK_INSERT))
{
if (clock() - GameAvailTMR > 100)
{
GameAvailTMR = clock();
IsGameAvail = false;

hGameWindow = FindWindow(NULL, LGameWindow);
if (hGameWindow)
{
GetWindowThreadProcessId(hGameWindow, &dwProcID);
if (dwProcID != 0)
{
hProcHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcID);
if (hProcHandle == INVALID_HANDLE_VALUE || hProcHandle == NULL)
{
GameStatus = "Failed to open process for valid handle";
}
else
{
GameStatus = "Game is ready to hack!";
IsGameAvail = true;
}

}
else
{
GameStatus = "Failed to get process ID";
}

}
else
{
GameStatus = "PvZ not found!";
}

if (UpdateOnNextRun = true || clock() - timeSinceLastUpdate > 5000)
{
system("cls");
std::cout << "-----------------------------------------------" << std::endl;
std::cout << " Skinnys PvZ Trainer v1" << std::endl;
std::cout << "-----------------------------------------------" << std::endl << std::endl;
std::cout << "GAME STATUS: " << GameStatus << std::endl << std::endl;
std::cout << "[F1] Unlimited Suns -> " << sSunStatus << " <- " << std::endl << std::endl;
std::cout << "[INSERT] Exit" << std::endl;
UpdateOnNextRun = false;
timeSinceLastUpdate = clock();
}

if (IsGameAvail)
{
WriteToMemory(hProcHandle);

 

}


}
if (clock() - onePressTMR > 400)
{
if (IsGameAvail)
{ //Sun
if (GetAsyncKeyState(VK_F1))
{
onePressTMR = clock();
SunStatus = !SunStatus;
UpdateOnNextRun = true;
if (SunStatus)sSunStatus = "ON";
else sSunStatus = "OFF";
}

}
}

 

}

CloseHandle(hProcHandle);
DestroyWindow(hGameWindow);

return ERROR_SUCCESS;

}


DWORD FindDmaAddy(int PointerLevel, HANDLE hProcHandle, DWORD Offsets[], DWORD BaseAdress)
{
DWORD pointer = BaseAdress;
DWORD pTemp;

DWORD pointerAddr;
for (int c = 0; c < PointerLevel; c++)
{
if (c == 0)
{
ReadProcessMemory(hProcHandle, (LPCVOID)pointer, &pTemp, sizeof(pTemp), NULL);
}

pointerAddr = pTemp + Offsets[c];
ReadProcessMemory(hProcHandle, (LPCVOID)pointerAddr, &pTemp, sizeof(pTemp), NULL);
}
return pointerAddr;

 


}

void WriteToMemory(HANDLE hProcHandle)
{
DWORD AdressToWrite;
if (SunStatus)
{
AdressToWrite = FindDmaAddy(2, hProcHandle, SunOffsets, SunBaseAdress);
WriteProcessMemory(hProcHandle, (BYTE*)AdressToWrite, &SunValue, sizeof(SunValue), NULL);
}
}