Beispiel #1
0
 /// <summary>
 /// Launch SA:MP
 /// </summary>
 /// <param name="server">Server</param>
 /// <param name="username">Username</param>
 /// <param name="serverPassword">Server password</param>
 /// <param name="rconPassword">RCON password</param>
 /// <param name="debug">Debug mode</param>
 /// <param name="quitWhenDone">Quit when done</param>
 /// <param name="createSessionLog">Create session log</param>
 /// <param name="plugins">Plugins</param>
 /// <param name="f">Form to close</param>
 public static void LaunchSAMP(Server server, string username, string serverPassword, string rconPassword, bool debug, bool quitWhenDone, bool createSessionLog, PluginDataContract[] plugins, Form f)
 {
     if ((server != null) || debug)
     {
         if (debug || server.IsValid)
         {
             IntPtr mh = Kernel32.GetModuleHandle("kernel32.dll");
             if (mh != IntPtr.Zero)
             {
                 IntPtr load_library_w = Kernel32.GetProcAddress(mh, "LoadLibraryW");
                 if (load_library_w != IntPtr.Zero)
                 {
                     Kernel32.PROCESS_INFORMATION process_info;
                     Kernel32.STARTUPINFO         startup_info = new Kernel32.STARTUPINFO();
                     if (CheckIfGTASanAndreasIsLaunchable)
                     {
                         string modified_username = ((username == null) ? "" : username.Trim().Replace(' ', '_'));
                         if (createSessionLog)
                         {
                             lastMediaState  = SessionProvider.GetCurrentMediaState();
                             lastSessionData = new SessionDataContract(DateTime.Now, TimeSpan.Zero, SAMPProvider.CurrentVersion.Name, modified_username, (server == null) ? "" : server.IPPortString, (server == null) ? "" : server.Hostname, (server == null) ? "" : server.Gamemode, (server == null) ? "" : server.Language);
                         }
                         if (Kernel32.CreateProcess(GTASAExe, debug ? "-d" : "-c " + ((rconPassword == null) ? "" : rconPassword) + " -h " + server.IPv4AddressString + " -p " + server.Port + " -n " + modified_username + ((serverPassword == null) ? "" : (" -z " + serverPassword)), IntPtr.Zero, IntPtr.Zero, false, /* DETACHED_PROCESS */ 0x8 | /* CREATE_SUSPENDED */ 0x4, IntPtr.Zero, ExeDir, ref startup_info, out process_info))
                         {
                             InjectPlugin(SAMPDLLPath, process_info.hProcess, load_library_w);
                             PluginDataContract[] load_plugins = ((plugins == null) ? PluginsDataIO : plugins);
                             foreach (PluginDataContract plugin in load_plugins)
                             {
                                 if (plugin != null)
                                 {
                                     if (plugin.Enabled)
                                     {
                                         InstalledPlugin installed_plugin = PluginProvider.Update(plugin);
                                         if (installed_plugin != null)
                                         {
                                             InjectPlugin(installed_plugin.Path, process_info.hProcess, load_library_w);
                                         }
                                     }
                                 }
                             }
                             Kernel32.ResumeThread(process_info.hThread);
                             Kernel32.CloseHandle(process_info.hProcess);
                             if ((f != null))
                             {
                                 if (quitWhenDone && (!createSessionLog))
                                 {
                                     f.Close();
                                 }
                                 f.WindowState = FormWindowState.Minimized;
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #2
0
 /// <summary>
 /// Launch SA:MP
 /// </summary>
 /// <param name="server">Server</param>
 /// <param name="username">Username</param>
 /// <param name="serverPassword">Server password</param>
 /// <param name="rconPassword">RCON password</param>
 /// <param name="debug">Debug mode</param>
 /// <param name="quitWhenDone">Quit when done</param>
 /// <param name="f">Form to close</param>
 public static void LaunchSAMP(Server server, string username, string serverPassword, string rconPassword, bool debug, bool quitWhenDone, Form f)
 {
     if ((server != null) || debug)
     {
         if (debug || server.IsValid)
         {
             IntPtr mh = Kernel32.GetModuleHandle("kernel32.dll");
             if (mh != IntPtr.Zero)
             {
                 IntPtr pa = Kernel32.GetProcAddress(mh, "LoadLibraryW");
                 if (pa != IntPtr.Zero)
                 {
                     Kernel32.PROCESS_INFORMATION process_info;
                     Kernel32.STARTUPINFO         startup_info = new Kernel32.STARTUPINFO();
                     if (Kernel32.CreateProcess(GTASAExe, debug ? "-d" : "-c " + ((rconPassword == null) ? "" : rconPassword) + " -h " + server.IPv4AddressString + " -p " + server.Port + " -n " + username + ((serverPassword == null) ? "" : (" -z " + serverPassword)), IntPtr.Zero, IntPtr.Zero, false, /* DETACHED_PROCESS */ 0x8 | /* CREATE_SUSPENDED */ 0x4, IntPtr.Zero, ExeDir, ref startup_info, out process_info))
                     {
                         IntPtr ptr = Kernel32.VirtualAllocEx(process_info.hProcess, IntPtr.Zero, (uint)(SAMPDLLPath.Length + 1) * 2U, Kernel32.AllocationType.Reserve | Kernel32.AllocationType.Commit, Kernel32.MemoryProtection.ReadWrite);
                         if (ptr != IntPtr.Zero)
                         {
                             int    nobw = 0;
                             byte[] p    = Encoding.Unicode.GetBytes(SAMPDLLPath);
                             byte[] nt   = Encoding.Unicode.GetBytes("\0");
                             if (Kernel32.WriteProcessMemory(process_info.hProcess, ptr, p, (uint)(p.Length), out nobw) && Kernel32.WriteProcessMemory(process_info.hProcess, new IntPtr(ptr.ToInt64() + p.LongLength), nt, (uint)(nt.Length), out nobw))
                             {
                                 uint   tid = 0U;
                                 IntPtr rt  = Kernel32.CreateRemoteThread(process_info.hProcess, IntPtr.Zero, 0U, pa, ptr, /* CREATE_SUSPENDED */ 0x4, out tid);
                                 if (rt != IntPtr.Zero)
                                 {
                                     Kernel32.ResumeThread(rt);
                                     unchecked
                                     {
                                         Kernel32.WaitForSingleObject(rt, (uint)(Timeout.Infinite));
                                     }
                                 }
                             }
                             Kernel32.VirtualFreeEx(process_info.hProcess, ptr, 0, Kernel32.AllocationType.Release);
                         }
                         Kernel32.ResumeThread(process_info.hThread);
                         Kernel32.CloseHandle(process_info.hProcess);
                         if (quitWhenDone)
                         {
                             f.Close();
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #3
0
 /// <summary>
 /// Launch SA:MP
 /// </summary>
 /// <param name="server">Server</param>
 /// <param name="username">Username</param>
 /// <param name="serverPassword">Server password</param>
 /// <param name="rconPassword">RCON password</param>
 /// <param name="debug">Debug mode</param>
 /// <param name="quitWhenDone">Quit when done</param>
 /// <param name="useDiscordRichPresence">Use Discord Rich Presence</param>
 /// <param name="f">Form to close</param>
 public static void LaunchSAMP(Server server, string username, string serverPassword, string rconPassword, bool debug, bool quitWhenDone, bool useDiscordRichPresence, Form f)
 {
     if ((server != null) || debug)
     {
         if (debug || server.IsValid)
         {
             IntPtr mh = Kernel32.GetModuleHandle("kernel32.dll");
             if (mh != IntPtr.Zero)
             {
                 IntPtr load_library_w = Kernel32.GetProcAddress(mh, "LoadLibraryW");
                 if (load_library_w != IntPtr.Zero)
                 {
                     Kernel32.PROCESS_INFORMATION process_info;
                     Kernel32.STARTUPINFO         startup_info = new Kernel32.STARTUPINFO();
                     if (Kernel32.CreateProcess(GTASAExe, debug ? "-d" : "-c " + ((rconPassword == null) ? "" : rconPassword) + " -h " + server.IPv4AddressString + " -p " + server.Port + " -n " + username + ((serverPassword == null) ? "" : (" -z " + serverPassword)), IntPtr.Zero, IntPtr.Zero, false, /* DETACHED_PROCESS */ 0x8 | /* CREATE_SUSPENDED */ 0x4, IntPtr.Zero, ExeDir, ref startup_info, out process_info))
                     {
                         InjectPlugin(SAMPDLLPath, process_info.hProcess, load_library_w);
                         if (useDiscordRichPresence)
                         {
                             if (SAMPDiscordPluginProvider.Update())
                             {
                                 InjectPlugin(Path.Combine(Directory.GetCurrentDirectory(), SAMPDiscordPluginProvider.SAMPDiscordPluginPath), process_info.hProcess, load_library_w);
                             }
                         }
                         Kernel32.ResumeThread(process_info.hThread);
                         Kernel32.CloseHandle(process_info.hProcess);
                         if (quitWhenDone)
                         {
                             f.Close();
                         }
                     }
                 }
             }
         }
     }
 }