Code:
int _tmain(int argc, _TCHAR* argv[])
{
printf("x64 compatible launcher v3.23\n");
printf("\n");
STARTUPINFO startupinfo = { sizeof(STARTUPINFO) };
PROCESS_INFORMATION processinformation = {0};
TCHAR exedir[MAX_PATH];
TCHAR HookPath[MAX_PATH];
TCHAR GamePath[MAX_PATH];
TCHAR WindowerPath[MAX_PATH];
// No idea what this is
LPTSTR args = _T(" /game eAZcFcB");
if(GetFileAttributes(_T("hook.dll"))==0xFFFFFFFF)
{
printf("Launcher must be run from the windower directory.");
getchar();
return 0;
}
int real_xres = GetSystemMetrics(SM_CXSCREEN);
int real_yres = GetSystemMetrics(SM_CYSCREEN);
TCHAR lang[3],conkey[2];
int xres,yres,truefull,trueresize,debug,fullscreen;
int region;
GetPrivateProfileString(_T("Windower Settings"),_T("Language"),_T("EU"),lang,sizeof(lang),_T(".\\Windower.ini"));
GetPrivateProfileString(_T("Windower Settings"),_T("Console Key"),_T("`"),conkey,sizeof(conkey),_T(".\\Windower.ini"));
xres=GetPrivateProfileInt(_T("Windower Settings"),_T("X Resolution"),real_xres,_T(".\\Windower.ini"));
yres=GetPrivateProfileInt(_T("Windower Settings"),_T("Y Resolution"),real_yres,_T(".\\Windower.ini"));
truefull=GetPrivateProfileInt(_T("Windower Settings"),_T("True Fullscreen"),0,_T(".\\Windower.ini"));
trueresize=GetPrivateProfileInt(_T("Windower Settings"),_T("True Resizing"),0,_T(".\\Windower.ini"));
debug=GetPrivateProfileInt(_T("Windower Settings"),_T("Debug"),0,_T(".\\Windower.ini"));
if(xres>real_xres) xres=real_xres;
if(yres>real_yres) yres=real_yres;
if(xres!=real_xres || yres!=real_yres)
fullscreen = 0;
else
fullscreen = 1;
HKEY hKey = NULL;
if(!_tcscmp(lang,_T("NA")) || !_tcscmp(lang,_T("US")))
{
RegOpenKeyEx(HKEY_LOCAL_MACHINE,_T("SOFTWARE\\PlayOnlineUS\\InstallFolder"),0,KEY_READ,&hKey);
region = 1;
}
else if(!_tcscmp(lang,_T("JP")))
{
RegOpenKeyEx(HKEY_LOCAL_MACHINE,_T("SOFTWARE\\PlayOnline\\InstallFolder"),0,KEY_READ,&hKey);
region = 0;
}
else if(!_tcscmp(lang,_T("EU")))
{
RegOpenKeyEx(HKEY_LOCAL_MACHINE,_T("SOFTWARE\\PlayOnlineEU\\InstallFolder"),0,KEY_READ,&hKey);
region = 2;
}
if(!hKey)
{
printf("Couldn't open PlayOnline registry key. Check windower.ini");
getchar();
return 0;
}
DWORD dwLen=sizeof(exedir);
if(RegQueryValueEx(hKey,_T("1000"),NULL,NULL,(LPBYTE)exedir,&dwLen))
{
printf("Couldn't read PlayOnline registry key. Check windower.ini");
getchar();
return 0;
}
CloseHandle(hKey);
GetCurrentDirectory(sizeof(WindowerPath),WindowerPath);
_tcscpy(GamePath,exedir);
_tcscat(GamePath,_T("\\pol.exe"));
_tcscpy(HookPath,WindowerPath);
_tcscat(HookPath,_T("\\hook.dll"));
HANDLE hMap = CreateFileMapping(INVALID_HANDLE_VALUE,0,PAGE_READWRITE,0,0x8034,_T("WindowerMMFSettingsHandler"));
LPBYTE pMap = (LPBYTE)MapViewOfFile(hMap,FILE_MAP_WRITE,0,0,0);
_tcscpy((LPWSTR)pMap,exedir);
_tcscpy((LPWSTR)(pMap+0x4000),WindowerPath);
struct _data
{
DWORD region;
DWORD x;
DWORD y;
BYTE true_resizing,true_fullscreen,fullscreen,unk4;
WORD console,unk5;
BYTE unk[32];
};
_data* pParms = (_data*)(pMap+0x8000);
pParms->region=region;
pParms->x=xres;
pParms->y=yres;
pParms->true_resizing=trueresize;
pParms->true_fullscreen=truefull;
pParms->fullscreen=fullscreen;
pParms->unk4=0;
pParms->console=conkey[0];
printf("Loading game........");
BOOL result = CreateProcess(GamePath,
args,
NULL,
NULL,
FALSE,
CREATE_SUSPENDED|NORMAL_PRIORITY_CLASS,
NULL,
exedir,
&startupinfo,
&processinformation
);
if(!result)
{
printf("Game load failed - error %08x\n",GetLastError());
getchar();
}
printf("Done... Hooking...\n");
HANDLE hLibModule;
LPVOID pLibRemote = VirtualAllocEx(processinformation.hProcess,NULL,sizeof(HookPath),MEM_COMMIT,PAGE_READWRITE);
WriteProcessMemory(processinformation.hProcess,pLibRemote,HookPath,sizeof(HookPath),NULL);
HANDLE hThread = CreateRemoteThread(processinformation.hProcess,NULL,0,(LPTHREAD_START_ROUTINE)::GetProcAddress(GetModuleHandle(_T("Kernel32")),"LoadLibraryW"), pLibRemote, 0, NULL);
WaitForSingleObject(hThread,INFINITE);
GetExitCodeThread(hThread,(LPDWORD)&hLibModule);
CloseHandle(hThread);
VirtualFreeEx(processinformation.hProcess,pLibRemote,sizeof(HookPath),MEM_RELEASE);
if(!hLibModule)
{
printf("Load of hook.dll failed.. continuing anyway without windower.\n");
}
printf("Done.. Running game..\n");
ResumeThread(processinformation.hThread);
printf("Closing handles.......");
CloseHandle(processinformation.hProcess);
CloseHandle(processinformation.hThread);
printf("Done! Thanks for travelling with us\n");
return 0;
}