Source:Warcraft3GameState/gamestate.cpp
Source.
Parent Directory: Source:Warcraft3GameState
Plain Code: edit
#include <windows.h>#include <iostream>#include <Tlhelp32.h>using namespace std;
void EnableDebugPriv();
DWORD GetPID (char* proc);
DWORD GetDLL (char* DllName, DWORD tPid);
void ClearConsole();
int main()
{SetConsoleTitle("Gamestate");
EnableDebugPriv();
TCHAR War3Name[32] = TEXT("Warcraft III");
HWND hWar3 = FindWindow(War3Name, NULL);
if(!hWar3)
{cout << "Please open Warcraft III first." << endl;
system( "pause" );
return 1;
}DWORD pid;GetWindowThreadProcessId( hWar3, &pid );
HANDLE hOpen = OpenProcess( PROCESS_ALL_ACCESS, false, pid );
if( !hOpen )
{cout << "Can't open Warcraft III." << endl;
system( "pause" );
return 1;
}// Address in decimal.DWORD Address = 11147656;
DWORD Buffer;DWORD WINAPI GetLastError(void);
DWORD GameDLL = GetDLL("Game.dll",GetPID("war3.exe"));
SIZE_T BytesRead = 0;
for (;;)
{// Notice the GameDLL+Address: we are adding our address to the base, AA1988h, because while the base is 6F 95 % of the time, it may change for specific reasons.ReadProcessMemory(hOpen, (LPCVOID)(GameDLL+Address), &Buffer, 4, &BytesRead);
// If our address has value(buffer) 0, then we are not in-game:if(Buffer == 0)
{cout << "Not in game" <<endl;;
Sleep(2000);
ClearConsole();
}else{cout << "In game" <<endl;
Sleep(1000);
ClearConsole();
}}}// Priviledgesvoid EnableDebugPriv( )
{HANDLE hToken;
LUID sedebugnameValue;TOKEN_PRIVILEGES tkp;OpenProcessToken( GetCurrentProcess( ), TOKEN_ADJUST_PRIVILEGES |TOKEN_QUERY, &hToken );
LookupPrivilegeValue( NULL, SE_DEBUG_NAME, &sedebugnameValue );
tkp.PrivilegeCount = 1;tkp.Privileges[0].Luid = sedebugnameValue;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges( hToken, false, &tkp, sizeof( tkp ), NULL, NULL );
CloseHandle( hToken );
}// Get PID for process.DWORD GetPID (char* proc)
{BOOL working=0;
PROCESSENTRY32 lppe= {0};
DWORD targetPid=0;
HANDLE hSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPPROC ESS ,0);
if (hSnapshot)
{lppe.dwSize=sizeof(lppe);
working=Process32First(hSnapshot,&lppe);
while (working)
{if (_stricmp(lppe.szExeFile,proc)==0)
{targetPid=lppe.th32ProcessID;
break;
}working=Process32Next(hSnapshot,&lppe);
}}CloseHandle( hSnapshot );
return targetPid;
}//Base (6F).DWORD GetDLL(char* DllName, DWORD tPid)
{HANDLE snapMod;MODULEENTRY32 me32;if (tPid == 0) return 0;
snapMod = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, tPid);
me32.dwSize = sizeof(MODULEENTRY32);
if (Module32First(snapMod, &me32)){
do{
if (strcmp(DllName,me32.szModule) == 0){
CloseHandle(snapMod);
return (DWORD) me32.modBaseAddr;
}}while(Module32Next(snapMod,&me32));
}CloseHandle(snapMod);
return 0;
}// Function to clear console.void ClearConsole()
{HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coord = {0, 0};
DWORD count;CONSOLE_SCREEN_BUFFER_INFO csbi;if(GetConsoleScreenBufferInfo(hStdOut, &csbi))
{FillConsoleOutputCharacter(hStdOut, (TCHAR) 32, csbi.dwSize.X * csbi.dwSize.Y, coord, &count);
FillConsoleOutputAttribute(hStdOut, csbi.wAttributes, csbi.dwSize.X * csbi.dwSize.Y, coord, &count );
SetConsoleCursorPosition(hStdOut, coord);
}return;
}