static public Process LaunchClient(string path, string args, bool datfix, bool nologin = false) { try { if (Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\ArenaNet\\Guild Wars", "Src", null) != null) { Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\ArenaNet\\Guild Wars", "Src", Path.GetFullPath(path)); Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\ArenaNet\\Guild Wars", "Path", Path.GetFullPath(path)); } if (Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\ArenaNet\\Guild Wars", "Src", null) != null) { Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\ArenaNet\\Guild Wars", "Src", Path.GetFullPath(path)); Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\ArenaNet\\Guild Wars", "Path", Path.GetFullPath(path)); } } catch (System.UnauthorizedAccessException) { MessageBox.Show("Insufficient access rights.\nPlease restart the launcher as admin.", "GWMC - Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } IntPtr hThread = IntPtr.Zero; uint dwPID = LaunchClient(path, args, (GWML_FLAGS)((datfix ? 2 : 3) | (nologin ? 4 : 0)), out hThread); Process proc = Process.GetProcessById((int)dwPID); GWCAMemory mem = new GWCAMemory(proc); if (!GWMem.scanned) { GWMem.FindAddresses(mem); } string dllpath = Directory.GetCurrentDirectory() + "\\plugins"; if (Directory.Exists(dllpath)) { string[] files = Directory.GetFiles(dllpath, "*.dll"); foreach (string file in files) { mem.LoadModule(file); } } dllpath = Path.GetDirectoryName(path) + "\\plugins"; if (Directory.Exists(dllpath)) { string[] files = Directory.GetFiles(dllpath, "*.dll"); foreach (string file in files) { mem.LoadModule(file); } } ResumeThread(hThread); CloseHandle(hThread); return(proc); }
static void Main(string[] args) { Application.EnableVisualStyles(); // Check for admin rights. WindowsIdentity identity = WindowsIdentity.GetCurrent(); WindowsPrincipal principal = new WindowsPrincipal(identity); bool isElevated = principal.IsInRole(WindowsBuiltInRole.Administrator); // names and paths string toolboxdir = Environment.GetEnvironmentVariable("LocalAppData") + Path.DirectorySeparatorChar + "GWToolboxpp" + Path.DirectorySeparatorChar; string inifile = toolboxdir + "GWToolbox.ini"; string dllfile = Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + DLL_NAME; // Install resources ResInstaller installer = new ResInstaller(); installer.Install(); // Download or update if needed. If dll file exists in current directory, use it. if (!File.Exists(dllfile)) { dllfile = toolboxdir + DLL_NAME; } if (File.Exists(dllfile) && (new FileInfo(dllfile).Length) < 1) { File.Delete(dllfile); // Delete file if exists with 0 length } if (!File.Exists(dllfile)) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; WebClient host = new WebClient(); host.Headers.Add(HttpRequestHeader.UserAgent, "GWToolboxpp Launcher"); string remoteversion = GetLatestVersion(); if (remoteversion.Length == 0) { MessageBox.Show("Failed to fetch latest GWToolbox++ version.\n Check your internet connection and try again", "GWToolbox++ Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string dllurl = "https://github.com/" + GITHUB_USER + "/GWToolboxpp/releases/download/" + remoteversion + "_Release/" + DLL_NAME; int tries = 0; // This bit will take a while... while (tries < 3 && dllurl.Length > 0 && !File.Exists(dllfile)) { try { host.DownloadFile(dllurl, dllfile); if (File.Exists(dllfile) && (new System.IO.FileInfo(dllfile).Length) < 1) { File.Delete(dllfile); // Delete file if exists with 0 length } } catch (Exception) { // todo } tries++; } if (!File.Exists(dllfile)) { MessageBox.Show("Failed to download GWToolbox++ dll.\n Check your internet connection and try again", "GWToolbox++ Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } // check again after download/update/build if (!File.Exists(dllfile)) { MessageBox.Show("Cannot find " + DLL_NAME, "GWToolbox++ Launcher Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Look for gw processes. List <Process> processesToInject = new List <Process>(); CharSelector chargui = new CharSelector(); Process[] gwprocs = chargui.GetValidProcesses(); switch (gwprocs.Length) { case 0: // No gw processes found. if (!isElevated && hasElevatedGWProcesses()) { MessageBox.Show("Guild Wars is running as Admin.\n" + "Restart Guild Wars without Admin, or run this launcher as Admin to run GWToolbox++", "GWToolbox++ Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } MessageBox.Show("No Guild Wars clients found.\n" + "Please log into Guild Wars first.", "GWToolbox++ Error", MessageBoxButtons.OK, MessageBoxIcon.Error); break; case 1: // Only one process found, injecting. processesToInject.Add(gwprocs[0]); break; default: // More than one found, make user select client. Application.Run(chargui); processesToInject.AddRange(chargui.SelectedProcesses); break; } if (processesToInject.Count == 0) { return; } for (int i = 0; i < processesToInject.Count; ++i) { IntPtr dll_return; GWCAMemory mem = new GWCAMemory(processesToInject[i]); GWCAMemory.LOADMODULERESULT result = mem.LoadModule(dllfile, out dll_return); if (result == GWCAMemory.LOADMODULERESULT.SUCCESSFUL && dll_return != IntPtr.Zero) { // continue } else if (result == GWCAMemory.LOADMODULERESULT.SUCCESSFUL) { MessageBox.Show("Error loading DLL: ExitCode " + dll_return, "GWToolbox++ Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Module Load Error.\n" + LOADMODULE_RESULT_MESSAGES[(uint)result] + "\n", "GWToolbox++ Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } }
static void Main() { INI_Reader settings = new INI_Reader(Environment.CurrentDirectory + "\\GWMC.ini"); if (!File.Exists(Environment.CurrentDirectory + "\\GWMC.ini")) { GenerateINI(settings); } string gwpath = settings.IniReadValue("MCPatch", "gwpath"); if (gwpath == "Gw.exe") { gwpath = Environment.CurrentDirectory + "\\Gw.exe"; } /* try * { * if (Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\ArenaNet\\Guild Wars", "Src", null) != null) * { * Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\ArenaNet\\Guild Wars", "Src", Path.GetFullPath(gwpath)); * Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\ArenaNet\\Guild Wars", "Path", Path.GetFullPath(gwpath)); * } * * if (Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\ArenaNet\\Guild Wars", "Src", null) != null) * { * Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\ArenaNet\\Guild Wars", "Src", Path.GetFullPath(gwpath)); * Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\ArenaNet\\Guild Wars", "Path", Path.GetFullPath(gwpath)); * } * } * catch (System.UnauthorizedAccessException) * { * MessageBox.Show("Insufficient access rights.\nPlease restart the launcher as admin.", "GWMC - Error", MessageBoxButtons.OK, MessageBoxIcon.Error); * return; * }*/ if (!File.Exists(Environment.CurrentDirectory + "\\GWMC.ini")) { GenerateINI(settings); } STARTUPINFO startup = new STARTUPINFO(); PROCESS_INFORMATION procinfo; bool createprocessresult = CreateProcess( gwpath, Environment.CommandLine, IntPtr.Zero, IntPtr.Zero, false, ProcessCreationFlags.CREATE_SUSPENDED, IntPtr.Zero, null, ref startup, out procinfo); if (createprocessresult == false) { MessageBox.Show("Unable to launch Gw.exe.\nIs the path correct in the ini file?", "GWMC - Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Process gwproc = Process.GetProcessById((int)procinfo.dwProcessId); GWCAMemory memmgr = new GWCAMemory(gwproc); MulticlientPatch patcher = new MulticlientPatch(memmgr); if (settings.IniReadValue("MCPatch", "enabled") == "1") { patcher.ApplyMulticlientPatch(); } if (settings.IniReadValue("MCPatch", "datfix") == "1") { patcher.ApplyDatFix(); } if (settings.IniReadValue("LoadDLL", "enabled") == "1") { memmgr.LoadModule(settings.IniReadValue("LoadDLL", "dllpath")); } ResumeThread(procinfo.hThread); }
static void Main(string[] args) { Application.EnableVisualStyles(); // Check for admin rights. WindowsIdentity identity = WindowsIdentity.GetCurrent(); WindowsPrincipal principal = new WindowsPrincipal(identity); bool isElevated = principal.IsInRole(WindowsBuiltInRole.Administrator); if (!isElevated) { MessageBox.Show("Please run the launcher as Admin.", "GWToolbox++ Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // names and paths string localappdata = Environment.GetEnvironmentVariable("LocalAppData"); string settingsfolder = localappdata + "\\GWToolboxpp\\"; string inifile = settingsfolder + "GWToolbox.ini"; // Install resources ResInstaller installer = new ResInstaller(); installer.Install(); #if DEBUG // do nothing, we'll use GWToolbox.dll in /Debug string dllfile = "GWToolbox.dll"; // same folder where the launcher is built #else // Download or update if needed string dllfile = settingsfolder + "GWToolbox.dll"; if (!File.Exists(dllfile)) { string toolboxdir = Environment.GetEnvironmentVariable("LocalAppData") + "\\GWToolboxpp\\"; WebClient host = new WebClient(); string remoteversion = host.DownloadString( "https://raw.githubusercontent.com/HasKha/GWToolboxpp/master/resources/toolboxversion.txt"); string dllurl = "https://github.com/HasKha/GWToolboxpp/releases/download/" + remoteversion + "_Release/GWToolbox.dll"; host.DownloadFile(dllurl, toolboxdir + "GWToolbox.dll"); } #endif // check again after download/update/build if (!File.Exists(dllfile)) { MessageBox.Show("Cannot find GWToolbox.dll", "GWToolbox++ Launcher Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Look for gw processes. Process[] gwprocs = Process.GetProcessesByName("Gw"); switch (gwprocs.Length) { case 0: // No gw processes found. MessageBox.Show("No Guild Wars clients found.\n" + "Please log into Guild Wars first.", "GWToolbox++ Error", MessageBoxButtons.OK, MessageBoxIcon.Error); break; case 1: // Only one process found, injecting. proctoinject = gwprocs[0]; break; default: // More than one found, make user select client. CharSelector chargui = new CharSelector(); Application.Run(chargui); proctoinject = chargui.SelectedProcess; break; } if (proctoinject == null) { return; } IntPtr dll_return; GWCAMemory mem = new GWCAMemory(proctoinject); GWCAMemory.LOADMODULERESULT result = mem.LoadModule(dllfile, out dll_return); if (result == GWCAMemory.LOADMODULERESULT.SUCCESSFUL && dll_return != IntPtr.Zero) { return; } if (result == GWCAMemory.LOADMODULERESULT.SUCCESSFUL) { MessageBox.Show("Error loading DLL: ExitCode " + dll_return, "GWToolbox++ Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Module Load Error.\n" + LOADMODULE_RESULT_MESSAGES[(uint)result] + "\n", "GWToolbox++ Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }