Im having problems with my injecter. I cant find out why its crashing the game
Code:
#include <iostream>
#include <Windows.h>
using namespace std;
bool InjectEngine(const wchar_t *PROC_NAME, const char *DLL_PATH)
{
HANDLE PH, myThread;
DWORD PID, AddressBase, ExitThreadCode;
LPVOID RemoteMem;
GetWindowThreadProcessId(FindWindow(NULL, (LPCWSTR)PROC_NAME), &PID); // Find Window Process ID
if((PH = OpenProcess(PROCESS_VM_READ | PROCESS_VM_WRITE | PROCESS_VM_OPERATION | PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION, false, PID)) != NULL) // Open Process
{
RemoteMem = VirtualAllocEx(PH, NULL, strlen(DLL_PATH) +1, MEM_COMMIT, PAGE_READWRITE); // Locate Memory for DLL
if((WriteProcessMemory(PH, RemoteMem, DLL_PATH, strlen(DLL_PATH) +1, &AddressBase)) == true) // Write into process and checks if it worked or not
{
myThread = CreateRemoteThread(PH, NULL, 0, (LPTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandleA("Kernal32.dll"), "LoadLibarayA"), RemoteMem, 0, 0);
WaitForSingleObject(myThread, INFINITE);
GetExitCodeThread(myThread, &ExitThreadCode);
if(!ExitThreadCode)
return false;
}
else
{
cout << "Could not write to file" << endl;
return false;
}
}
else
{
cout << "Could not find Window" << endl;
return false;
}
cout << GetLastError() << endl;
VirtualFreeEx(PH, RemoteMem, strlen(DLL_PATH) +1, MEM_RELEASE);
CloseHandle(PH);
CloseHandle(myThread);
return true;
}
int main()
{
if(InjectEngine(L"Minesweeper", "TrainerInjectorDll.dll") == false)
cout << "Error" << endl;
else
cout << "Injected" << endl;
cin.get();
return 0;
}