Need Help with FindWindow
So Here is some code i found online and i was wanting to use it for call of duty but for some reason it always says that the game cannot be found for some reason and i dont know why. Can anyone help me with this??
#include <iostream>
#include <Windows.h>
#include <string>
#include <ctime>
std::string GameStatus;
bool IsGameAvailable;
bool UpdateOnNextRun;
//////////////////////////////
// Params //
//////////////////////////////
// Game window title
LPCSTR LGameWindow = "BlackOps3";
// Feature 1
std::string sFeature1Status = "OFF";
bool Feature1Status;
int iFeature1Key = VK_F1;
std::string sFeature1Key = "F1";
std::string sFeature1Desc = "GOD MODE"; /
BYTE Feature1Value[] = { 0x1, 0x8, 0x6, 0xA, 0x0 };
DWORD Feature1BaseAddress = { 0x147621428 };
int iFeature1Levels = 0;
DWORD Feature1Offsets[] = { 0x0, 0x0 };
// Feature 2
std::string sFeature2Status = "OFF";
bool Feature2Status;
int iFeature2Key = VK_F2;
std::string sFeature2Key = "F2";
std::string sFeature2Desc = "UNLIMITED AMMO";
BYTE Feature2Value[] = { 0x0, 0x0, 0x3, 0x2 };
DWORD Feature2BaseAddress = { 0x147B7FB98 };
int iFeature2Levels = 2;
DWORD Feature2Offsets[] = { 0x0, 0x0 };
// Feature 3
std::string sFeature3Status = "OFF";
bool Feature3Status;
int iFeature3Key = VK_F3;
std::string sFeature3Key = "F3";
std::string sFeature3Desc = "Feature 3";
BYTE Feature3Value[] = { 0xF, 0xF, 0x0, 0x0 };
DWORD Feature3BaseAddress = { 0x00000000 };
int iFeature3Levels = 2;
DWORD Feature3Offsets[] = { 0x0, 0x0 };
DWORD findDmaAddress(HANDLE hProcHandle, int levelNumber, DWORD Offsets[], DWORD BaseAddress)
{
DWORD pointer = BaseAddress;
DWORD pTemp;
DWORD pointerAddress;
for (int i = 0; i<levelNumber; i++)
{
if (i == 0)
{
ReadProcessMemory(hProcHandle, (LPCVOID)pointer, &pTemp, sizeof(pTemp), NULL);
}
pointerAddress = pTemp + Offsets[i];
ReadProcessMemory(hProcHandle, (LPCVOID)pointerAddress, &pTemp, sizeof(pTemp), NULL);
}
return pointerAddress;
}
int main()
{
HWND hGameWindow = NULL;
int iTimeSinceLastUpdate = clock();
int iGameAvailableTMR = clock();
int iOnePressTMR = clock();
DWORD dwProcID = NULL;
HANDLE hProcHandle = NULL;
UpdateOnNextRun = true;
while (!GetAsyncKeyState(VK_INSERT))
{
if (clock() - iGameAvailableTMR > 100)
{
iGameAvailableTMR = clock();
IsGameAvailable = false;
hGameWindow = FindWindow("Call of DutyŽ: BlackOps3", NULL);
if (hGameWindow)
{
GetWindowThreadProcessId(hGameWindow, &dwProcID);
if (dwProcID != 0)
{
hProcHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcID);
if (hProcHandle == INVALID_HANDLE_VALUE || hProcHandle == NULL)
{
GameStatus = "[ERROR] Failed to open process for valid handle";
}
else
{
GameStatus = "[SUCCESS] Game is ready to hack";
IsGameAvailable = true;
}
}
else
{
GameStatus = "[ERROR] Failed to get process ID";
}
}
else
{
GameStatus = "[ERROR] Game cannot be found";
}
}
if (UpdateOnNextRun || clock() - iTimeSinceLastUpdate > 5000)
{
system("cls");
system("color a");
std::cout << "--------------------------------------------" << std::endl;
std::cout << " Black Ops 3 Trainer" << std::endl;
std::cout << "--------------------------------------------" << std::endl << std::endl;
std::cout << "Status: " << GameStatus << std::endl << std::endl;
std::cout << "[" << sFeature1Key << "] " << sFeature1Desc << " ->" << sFeature1Status << "<-" << std::endl;
std::cout << "[" << sFeature2Key << "] " << sFeature2Desc << " ->" << sFeature2Status << "<-" << std::endl;
std::cout << "[" << sFeature3Key << "] " << sFeature3Desc << " ->" << sFeature3Status << "<-" << std::endl;
std::cout << std::endl << "[INSERT] Exit" << std::endl;
UpdateOnNextRun = false;
iTimeSinceLastUpdate = clock();
}
if (IsGameAvailable)
{
DWORD AddressToWrite;
// Memory hacking
if (Feature1Status)
{
AddressToWrite = findDmaAddress(hProcHandle, iFeature1Levels, Feature1Offsets, Feature1BaseAddress);
WriteProcessMemory(hProcHandle, (BYTE*)AddressToWrite, &Feature1Value, sizeof(Feature1Value), NULL);
}
else if (Feature2Status)
{
AddressToWrite = findDmaAddress(hProcHandle, iFeature2Levels, Feature2Offsets, Feature2BaseAddress);
WriteProcessMemory(hProcHandle, (BYTE*)AddressToWrite, &Feature2Value, sizeof(Feature2Value), NULL);
}
else if (Feature3Status)
{
AddressToWrite = findDmaAddress(hProcHandle, iFeature3Levels, Feature3Offsets, Feature3BaseAddress);
WriteProcessMemory(hProcHandle, (BYTE*)AddressToWrite, &Feature3Value, sizeof(Feature3Value), NULL);
}
}
if (IsGameAvailable && clock() - iOnePressTMR > 400)
{
// Key pressed
if (GetAsyncKeyState(iFeature1Key))
{
iOnePressTMR = clock();
Feature1Status = !Feature1Status;
UpdateOnNextRun = true;
sFeature1Status = Feature1Status ? "ON" : "OFF";
}
else if (GetAsyncKeyState(iFeature2Key))
{
iOnePressTMR = clock();
Feature2Status = !Feature2Status;
UpdateOnNextRun = true;
sFeature2Status = Feature2Status ? "ON" : "OFF";
}
else if (GetAsyncKeyState(iFeature3Key))
{
iOnePressTMR = clock();
Feature3Status = !Feature3Status;
UpdateOnNextRun = true;
sFeature3Status = Feature3Status ? "ON" : "OFF";
}
}
}
CloseHandle(hProcHandle);
CloseHandle(hGameWindow);
return ERROR_SUCCESS;
}