08.12.2018, 20:33
Not my code but the SAMPLauncherNET accomplished it, heres the code you'd probably want for your own implementation;
By the looks of it the '-z' parameter is passed for the executable if it has a server password.
Код:
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; } } } } } } } }