#include "../PacketDump/main.h" char hostfile[200]; int hostlength=0; void RestoreHOSTS(unsigned char *oldhosts); unsigned char *SaveHOSTS(const char *filestr, const char *authstr); BYTE path[200]; BYTE src[200]; int file_server=0; char fsip[100]; using namespace std; void ModRegistry() { //grab the GW executable path from the registry HKEY h; if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\ArenaNet\\Guild Wars",0,KEY_ALL_ACCESS,&h)!=ERROR_SUCCESS) { //cout << "Could not open registry key!!!" << endl; return; } //Grab the two values will be modifying and save them for later memset(path,0,200); memset(src,0,200); DWORD bs; if(RegQueryValueEx(h,"Path",0,0,path,&bs)!=ERROR_SUCCESS) { //cout << "Could not query value!!!" << endl; return; } if(RegQueryValueEx(h,"Src",0,0,src,&bs)!=ERROR_SUCCESS) { //cout << "Could not query value!!!" << endl; return; } //Modify the values BYTE hahaha[100]; sprintf((char*)hahaha,"c:\\gwerge.exe"); RegSetValueEx(h,"Path",0,REG_SZ,hahaha,strlen((char*)hahaha)+1); RegSetValueEx(h,"Src",0,REG_SZ,hahaha,strlen((char*)hahaha)+1); RegCloseKey(h); } void RestoreRegistry() { //grab the GW executable path from the registry HKEY h; if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\ArenaNet\\Guild Wars",0,KEY_ALL_ACCESS,&h)!=ERROR_SUCCESS) { //cout << "Could not open registry key!!!" << endl; return; } //Modify the values BYTE hahaha[100]; sprintf((char*)hahaha,"C:\\gwerge.exe"); RegSetValueEx(h,"Path",0,REG_SZ,path,strlen((char*)path)+1); RegSetValueEx(h,"Src",0,REG_SZ,src,strlen((char*)src)+1); RegCloseKey(h); } HANDLE proxyHand=NULL; DWORD WINAPI MainProgram(LPVOID param) { char temp[200]; //Load the config file std::ifstream fin("GWLPBin/play.ini"); if(fin.fail()) { ExitProcess(0); return -1; } fin >> temp; fin.close(); if(strcmp(temp,"proxy")==0) { PROCESS_INFORMATION p; STARTUPINFO si; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory(&p,sizeof(p)); char c[100]; strcpy(c,"GWLPBin/ProxyGWLP.exe"); if(CreateProcess(0,c,0,0,false,0,0,0,&si,&p)==0) { MessageBox(0,"Could not find ProxyGWLP.exe Did you install this program using the installer?","Fatal Error",MB_OK | MB_APPLMODAL | MB_ICONSTOP); ExitProcess(0); return -2; } proxyHand=p.hProcess; Sleep(1000); std::ifstream fin2("GWLPBin/pip.txt"); if(fin2.fail()) { ExitProcess(0); } fin2 >> temp; fin2 >> file_server; fin2.close(); if (file_server > 0) { std::ifstream fn("GWLPBin/proxy.ini"); if (fn.fail()) { ExitProcess(0); } fn >> fsip; fn.close(); } } unsigned char *oldhosts=NULL; if (!file_server) { oldhosts=SaveHOSTS(temp, temp); } else { oldhosts=SaveHOSTS(fsip, temp); } //If we cannot save the old hosts file if(oldhosts==NULL) { ExitProcess(0); return -1; } ModRegistry(); //Start GW PROCESS_INFORMATION p; STARTUPINFO si; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory(&p,sizeof(p)); char c[100]; strcpy(c,"GWLPGuildWars/gwgwlp.exe"); if(CreateProcess(0,c,0,0,false,0,0,"GWLPGuildWars",&si,&p)==0) { RestoreRegistry(); MessageBox(0,"Could not find gwgwlp.exe Did you install this program using the installer?","Fatal Error",MB_OK | MB_APPLMODAL | MB_ICONSTOP); ExitProcess(0); return -2; } HWND gw=GetForegroundWindow(); SetForegroundWindow(gw); //Inject key stuff int ret=0; if((ret=KeyInjection(p.hProcess))<0) { CloseHandle(p.hProcess); char err[100]; sprintf(err,"Code=%d",ret); MessageBox(0,err,"Error",MB_OK | MB_ICONSTOP); ExitProcess(0); return -2; } //While gw is still found while(MACRO_IFGW) { Sleep(10); } CloseHandle(p.hProcess); //Restore the HOSTS file RestoreRegistry(); RestoreHOSTS(oldhosts); ExitProcess(0); return 0; } // save old hosts file and write new entries to the file unsigned char *SaveHOSTS(const char *filestr, const char *authstr) { FILE *file; char *windir = getenv("windir"); strcpy(hostfile,windir); strcat(hostfile,"\\System32\\drivers\\etc\\HOSTS"); printf("Windows directory: %s\n",hostfile); if ((file = fopen(hostfile,"rb")) == NULL) { MessageBox(0,"A catastrophic failure has occured. This can be due to one of two scenarios...This program is running without admin priveleges or you are messing with my program. =)","Catastrophic Failure",MB_OK | MB_ICONSTOP); return 0; } fseek(file,0,SEEK_END); hostlength = ftell(file); unsigned char *oldhosts = new unsigned char[hostlength+1]; rewind(file); fread(oldhosts,hostlength,1,file); fclose(file); file = fopen(hostfile,"ab"); // just in case fprintf(file,"\r\n"); for (int i = 1; i <= 20; i++) { fprintf(file,"%s File%d.ArenaNetworks.com\r\n",filestr,i); fprintf(file,"%s Auth%d.ArenaNetworks.com\r\n",authstr,i); } fclose(file); return oldhosts; } // restore old hosts file void RestoreHOSTS(unsigned char *oldhosts) { FILE *file = fopen(hostfile,"wb"); rewind(file); fwrite(oldhosts,hostlength,1,file); fclose(file); delete[] oldhosts; }