Need Help With FindWindow()

Posts 1–2 of 2 · Page 1 of 1
Need Help With FindWindow()
I have some code here that i am using for a trainer i am working on. The code is not mine but i was using it for a template. i forgot where i found it but if the person who wrote this code see's this then credits to you. The problem i am having is the find window part. When i start the program up everything compiles correctly but when i try to find the game it says that i can not find it. Everything is typed out correctly so i dont know what the issue is. I am making a trainer for black ops 3, as i mentioned earlier, and i have posted in the help forums there but i was unable to resolve it, so i am going to post here and see if anyone can help me.

here is the code:
Code:
#include <iostream>
#include <Windows.h>
#include <string>
#include <ctime>

std::string GameStatus;
bool IsGameAvailable;
bool UpdateOnNextRun;

//////////////////////////////
// Params                    //
//////////////////////////////

// Game window title
LPCSTR LGameWindow = "BlackOps3";                    

													 
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 };           

												  
std::string sFeature2Status = "OFF";
bool Feature2Status;
int iFeature2Key = VK_F2;                       
std::string sFeature2Key = "F2";                
std::string sFeature2Desc = "Feature 2";        
BYTE Feature2Value[] = { 0xF, 0xF, 0x0, 0x0 };  
DWORD Feature2BaseAddress = { 0x00000000 };     
int iFeature2Levels = 2;                        
DWORD Feature2Offsets[] = { 0x0, 0x0 };         

												
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 = FindWindowA(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 = "[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");
			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;
}
I use Window Spy for this, it is part of AutoHotKey Installer:



Written in VC++:
Code:
#include "stdafx.h"
#include <Windows.h>


int main()
{
	while (1)
	{
		//2 Ways, same result

		wchar_t* className = L"Notepad";
		HWND ClassWindowHandle = FindWindow(className, NULL); // use first Parameter for finding by ClassName
		printf("Handle with ClassTitle: %d\n", ClassWindowHandle);

		wchar_t* windowName = L"Unbenannt - Editor";
		HWND NameWindowHandle = FindWindow(NULL, windowName); // use second Parameter for finding by WindowName
		printf("Handle with Window Title: %d\n", NameWindowHandle);



		Sleep(100);
	}
    return 0;
}
Result was something like this:
Code:
Handle with Window Title: 988254
Handle with ClassTitle: 988254
Handle with Window Title: 988254
Handle with ClassTitle: 988254
Handle with Window Title: 988254
Handle with ClassTitle: 988254
Handle with Window Title: 988254
Handle with ClassTitle: 988254
Handle with Window Title: 988254
Posts 1–2 of 2 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us