void Awake() { UnityEngine.Debug.Log($"[VWS] {pluginName} v{pluginVersion}"); var bin = Path.Combine(Paths.PluginPath, "ValheimWebSocket/client.exe"); serverPort = Config.Bind("Server", "Port", 60157, "WebSocket server port"); clientBin = Config.Bind("Client", "BinPath", bin, "WebSocket server bin path"); clientArgs = Config.Bind("Client", "BinArgs", "", "WebSocket server bin arguments"); try { Harmony harmony = new Harmony(pluginGUID); harmony.PatchAll(); ValheimWebSocketServer.Start(serverPort.Value); if (clientBin.Value.Length != 0) { ClientLauncher.Start(clientBin.Value, clientArgs.Value); } } catch (System.Exception e) { Logger.LogError(e); } }
public void Initialize() { // initialize _forbidUpdates = false; _isJustUpdated = false; _type = typeof(IClient); // IApplicationConfigurationManager mock _applicationConfigurationManagerMock = new Mock <IApplicationConfigurationManager>(MockBehavior.Strict); _applicationConfigurationManagerMock.Setup(x => x.GetClientFileName()).Returns(() => _fileName); _applicationConfigurationManagerMock.Setup(x => x.GetSetting <bool>("forbidUpdates")).Returns(() => _forbidUpdates); // IClient mock _clientMock = new Mock <IClient>(MockBehavior.Strict); _clientMock.Setup(x => x.Start(It.IsAny <StartOptions>())); // IApplicationClientUpdater mock _applicationClientUpdaterMock = new Mock <IApplicationClientUpdater>(MockBehavior.Strict); // IConstructorInfoWrapper mock _constructorInfoWrapperMock = new Mock <IConstructorInfoWrapper>(MockBehavior.Strict); _constructorInfoWrapperMock.Setup(x => x.Invoke(It.IsAny <object[]>())).Returns(() => _clientMock.Object); // initialize constructorInfoWrappersArray _constructorInfoWrapperArray = new[] { _constructorInfoWrapperMock.Object }; // IApplicationLogger mock _applicationLoggerMock = new Mock <IApplicationLogger>(MockBehavior.Strict); _applicationLoggerMock.Setup(x => x.LogException(It.IsAny <Exception>(), It.IsAny <string>())) .Returns(() => Task.CompletedTask); // ITypeWrapper mock _typeWrapperMock = new Mock <ITypeWrapper>(MockBehavior.Strict); _typeWrapperMock.Setup(x => x.GetConstructors()).Returns(() => _constructorInfoWrapperArray); _typeWrapperMock.Setup(x => x.GetInterface(It.IsAny <string>())).Returns(() => _type); // initialize typeWrappersArray _typeWrapperArray = new[] { _typeWrapperMock.Object }; // IAssemblyWrapper mock _assemblyWrapperMock = new Mock <IAssemblyWrapper>(MockBehavior.Strict); _assemblyWrapperMock.Setup(x => x.GetTypes()).Returns(() => _typeWrapperArray); AssemblyWrapper.LoadFrom = (assemblyFile) => assemblyFile == _fileName ? _assemblyWrapperMock.Object : throw new ArgumentNullException(); // new ClientLauncher _clientLauncher = new ClientLauncher(_applicationConfigurationManagerMock.Object, _applicationClientUpdaterMock.Object, _applicationLoggerMock.Object); }
private void Form1_Load(object sender, EventArgs e) { eventManager = new UiEventManager(dataGridView1, this); indication = new Indication(this); InitializeAppProperties(); try { client = new ClientLauncher(eventManager, this); client.Launch(); eventManager.client = client; StatusesForOwner.Init(client.GetServerInstance()); eventManager.GetEventList(); eventManager.HideClosedEventsAccordingToConfigValue(); } catch (UserIsNullException) //user has not logged in { ExitApp(); } }
public static bool Launch(OptionsData options, out int index) { /* Could all seem a bit excessive just to get the pid of the client it creates? */ ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.WorkingDirectory = MainWindow.CurrentOptions.UOSFolder; startInfo.FileName = Path.Combine(MainWindow.CurrentOptions.UOSFolder, "UOSteam.exe"); index = -1; Win32.SafeProcessHandle hProcess; Win32.SafeThreadHandle hThread; uint pid, tid; int uopid = 0; UOM.SetStatusLabel("Status : Launching UOSteam"); if (Win32.CreateProcess(startInfo, true, out hProcess, out hThread, out pid, out tid)) { /* Basically rewrites a small piece of code before the client resumes to write the pid of the new client it creates, probably not portable between versions if the registers change, what can i say, I'm a noob * Never had code of old code before RazorLauncher to see how xenoglyph did it before. * Code will need to be cleaned up. */ Process p = Process.GetProcessById((int)pid); IntPtr codeAddress; IntPtr baseAddress = GetBaseAddress(hProcess, hThread); if (baseAddress == null) { UOM.SetStatusLabel("Status : UOS Hook failed"); return(false); } byte[] buffer = new byte[0x17000]; Memory.Read(hProcess.DangerousGetHandle(), (IntPtr)(((int)baseAddress) + 0x1000), buffer, true); UOM.SetStatusLabel("Status : Patching UOSteam"); /* Originally pushes hThread and hProcess on the stack before a call, we'll overwrite here. */ byte[] findBytes = new byte[] { 0x8B, 0x44, 0x24, 0x44, // MOV EAX, [ESP+44] 0x8B, 0x4C, 0x24, 0x40 // MOV ECX, [ESP+40] }; int offset = 0; if (FindSignatureOffset(findBytes, buffer, out offset)) { if ((codeAddress = Memory.Allocate(hProcess.DangerousGetHandle(), IntPtr.Zero, 1024, true)) == IntPtr.Zero) { UOM.SetStatusLabel("Status : Memory Allocation failed"); hProcess.Dispose(); hThread.Dispose(); return(false); } byte[] patchCode1 = new byte[] { 0xB8, 0x00, 0x00, 0x00, 0x00, // MOV EAX, <codeAddress> 0x8B, 0x4C, 0x24, 0x4C, // MOV ECX, [ESP+4C] 0x89, 0x08, // MOV [EAX], ECX 0xB8, 0x00, 0x00, 0x00, 0x00, // MOV EAX, <codeAddress+4> 0x8B, 0x4C, 0x24, 0x44, // MOV ECX, [ESP+4C] 0x89, 0x08, // MOV [EAX], ECX 0x8B, 0x44, 0x24, 0x48, // MOV EAX, [ESP+48] -. 0x8B, 0x4C, 0x24, 0x44, // MOV ECX, [ESP+44] -| Original code we overwrote, but esp incremented 4 due to call return address on stack 0xC3 // RETN }; patchCode1[1] = (byte)codeAddress.ToInt32(); patchCode1[2] = (byte)(codeAddress.ToInt32() >> 8); patchCode1[3] = (byte)(codeAddress.ToInt32() >> 16); patchCode1[4] = (byte)(codeAddress.ToInt32() >> 24); int codeAddress2 = (codeAddress.ToInt32() + 4); patchCode1[12] = (byte)codeAddress2; patchCode1[13] = (byte)(codeAddress2 >> 8); patchCode1[14] = (byte)(codeAddress2 >> 16); patchCode1[15] = (byte)(codeAddress2 >> 24); int patchAddress = codeAddress.ToInt32() + 8; Memory.Write(hProcess.DangerousGetHandle(), (IntPtr)patchAddress, patchCode1, true); byte[] patchCode2 = new byte[] { 0xB8, 0x00, 0x00, 0x00, 0x00, // MOV EAX, <patchAddress> 0xFF, 0xD0, // CALL EAX 0x90 // NOP }; patchCode2[1] = (byte)patchAddress; patchCode2[2] = (byte)(patchAddress >> 8); patchCode2[3] = (byte)(patchAddress >> 16); patchCode2[4] = (byte)(patchAddress >> 24); IntPtr writeAddress = new IntPtr((baseAddress.ToInt32() + 0x1000) + offset); Memory.Write(hProcess.DangerousGetHandle(), writeAddress, patchCode2, true); if (Win32.ResumeThread(hThread.DangerousGetHandle()) == -1) { UOM.SetStatusLabel("Status : ResumeThread failed"); hProcess.Dispose(); hThread.Dispose(); return(false); } // This is dodgy, to be changed to something else. byte[] uopidbytes = new byte[4]; do { Memory.Read(hProcess.DangerousGetHandle(), (IntPtr)codeAddress, uopidbytes, true); uopid = uopidbytes[3] << 24 | uopidbytes[2] << 16 | uopidbytes[1] << 8 | uopidbytes[0]; } while (uopid == 0); } hProcess.Close(); hThread.Close(); return(ClientLauncher.Attach((uint)uopid, options, true, out index)); } UOM.SetStatusLabel("Status : Process creation failed"); return(false); }
public void Play() { try { Dictionary <string, string> table = new Dictionary <string, string>(); string dataString = string.Empty; string[] split = null; dataString = _url; dataString = Uri.UnescapeDataString(dataString); bool encoded = Regex.IsMatch(dataString, "^[A-Za-z0-9+/=]+$", RegexOptions.IgnoreCase); if (encoded) { dataString = Encoding.UTF8.GetString(Convert.FromBase64String(dataString)); } _log.Debug("dataString = {0}", dataString); split = dataString.Split('&'); for (int i = 0; i < split.Length; i++) { string[] keyValue = split[i].Split('='); if (keyValue.Length == 2) { string key = keyValue[0]; string value = keyValue[1]; table.Add(key, value); } } for (int i = 0; i < _requiredFields.Length; i++) { if (!table.ContainsKey(_requiredFields[i])) { MessageBoxEx.Show(Program.MainForm, string.Format("One or more of the following fields was missing from the ConnectUO Url Protocol string: {0}", string.Join(" ", _requiredFields))); return; } } string idString = table[Id]; string name = table[NameTolken]; string portString = table[PortTolken]; string hostAddress = table[HostTolken]; string allowRazor; string removeEnc; string patches; bool razor = Program.Database.LaunchRazor; bool enc; if (!table.TryGetValue(AllowRazorTolken, out allowRazor)) { allowRazor = "false"; } if (!table.TryGetValue(RemoveEncTolken, out removeEnc)) { removeEnc = "true"; } if (!table.TryGetValue(PatchesTolken, out patches)) { patches = ""; } int port; int id; if (!int.TryParse(idString, out id)) { MessageBoxEx.Show(Program.MainForm, "Invalid server id."); return; } if (!int.TryParse(portString, out port) || (port > 65536 || port < 0)) { MessageBoxEx.Show(Program.MainForm, "Invalid port number, please use a valid port number between 0 and 65535"); return; } bool shardAllowsRazor; bool.TryParse(allowRazor, out shardAllowsRazor); bool.TryParse(removeEnc, out enc); //Make sure the user wants razor, and that shard allows it. razor = razor && shardAllowsRazor; if (string.IsNullOrEmpty(Program.Database.UltimaOnlineDirectory)) { MessageBoxEx.Show(Program.MainForm, "ConnectUO was unable to find the directory that Ultima Online is installed to. This must be set in order to launch the client."); return; } if (string.IsNullOrEmpty(Program.Database.UltimaOnlineExe)) { MessageBoxEx.Show(Program.MainForm, "ConnectUO was unable to find the client executable. This must be set in order to launch the client."); return; } string folderName = name; Utility.EnsureValidFolderName(ref folderName); string serverDirectory = Path.Combine(Program.Database.PatchDirectory, folderName); string[] patchFiles = null; Utility.EnsureDirectory(serverDirectory); List <ServerPatch> patchList = new List <ServerPatch>(); split = patches.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < split.Length; i++) { string[] patchVersion = split[i].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); if (patchVersion.Length == 2) { string patchUri = patchVersion[0]; string versionString = patchVersion[1]; int version; int.TryParse(versionString, out version); ServerPatch patch = new ServerPatch(); patch.ShardId = id; patch.PatchUrl = patchUri; patch.Version = version; if (!Program.Database.IsPatchApplied(patch)) { patchList.Add(patch); } } } if (patchList.Count > 0) { if (Program.Database.IsServerBeingPatched(id)) { MessageBoxEx.Show(Program.MainForm, String.Format("{0} is already being patched, you cannot play until the patching process has been completed", name), "ConnectUO 2.0"); return; } else { frmTaskManager taskManager = new frmTaskManager(patchList, serverDirectory); if (taskManager.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } } } patchFiles = Directory.GetFiles(serverDirectory); ThreadPool.QueueUserWorkItem(delegate(object o) { new ConnectUOWebService().UpdatePlayStatistics(Program.Database.Guid, id); }); ClientLauncher.Launch(id, hostAddress, port, Path.Combine(Program.Database.UltimaOnlineDirectory, Program.Database.UltimaOnlineExe), Program.Database.RazorDirectory, razor, enc, Path.Combine(Program.Database.PatchDirectory, folderName), patchFiles); } catch (Exception e) { _log.Error(e); } }
/// <summary> /// Launch a new client instance. /// </summary> /// <param name="options">UOMachine.OptionsData to use for launching client.</param> /// <param name="clientIndex">Client index of launched client.</param> /// <returns>Client index of launched client.</returns> public static bool LaunchClient(OptionsData options, out int clientIndex) { return(ClientLauncher.Launch(options, out clientIndex)); }
/// <summary> /// Launch a new client instance. /// </summary> /// <param name="clientIndex">Client index of launched client.</param> /// <returns>Client index of launched client.</returns> public static bool LaunchClient(out int clientIndex) { return(ClientLauncher.Launch(MainWindow.CurrentOptions, out clientIndex)); }
public void Play(string url) { try { string[] split = null; if (url.Contains("//")) { split = url.Split(new string[] { "//" }, StringSplitOptions.RemoveEmptyEntries); if (split.Length >= 2) { url = split[1]; } } url = url.Replace("/", ""); Dictionary <string, string> table = new Dictionary <string, string>(); string dataString = string.Empty; dataString = url; dataString = Uri.UnescapeDataString(dataString); bool encoded = Regex.IsMatch(dataString, "^[A-Za-z0-9+/=]+$", RegexOptions.IgnoreCase); if (encoded) { dataString = Encoding.UTF8.GetString(Convert.FromBase64String(dataString)); } Tracer.Verbose("dataString = {0}", dataString); split = dataString.Split('&'); for (int i = 0; i < split.Length; i++) { string[] keyValue = split[i].Split('='); if (keyValue.Length == 2) { string key = keyValue[0]; string value = keyValue[1]; table.Add(key, value); } } for (int i = 0; i < _requiredFields.Length; i++) { if (!table.ContainsKey(_requiredFields[i])) { MessageBoxEx.Show(_applicationService.MainForm, string.Format("One or more of the following fields was missing from the ConnectUO Url Protocol string: {0}", string.Join(" ", _requiredFields))); return; } } string idString = table[Id]; string name = table[NameTolken]; string portString = table[PortTolken]; string hostAddress = table[HostTolken]; string allowRazor; string removeEnc; string patches; bool razor = _settingsService.LaunchRazor; bool enc; if (!table.TryGetValue(AllowRazorTolken, out allowRazor)) { allowRazor = "false"; } if (!table.TryGetValue(RemoveEncTolken, out removeEnc)) { removeEnc = "true"; } if (!table.TryGetValue(PatchesTolken, out patches)) { patches = ""; } int port; int id; if (!int.TryParse(idString, out id)) { MessageBoxEx.Show(_applicationService.MainForm, "Invalid server id."); return; } if (!int.TryParse(portString, out port) || (port > 65536 || port < 0)) { MessageBoxEx.Show(_applicationService.MainForm, "Invalid port number, please use a valid port number between 0 and 65535"); return; } bool shardAllowsRazor; bool.TryParse(allowRazor, out shardAllowsRazor); bool.TryParse(removeEnc, out enc); //Make sure the user wants razor, and that shard allows it. razor = razor && shardAllowsRazor; if (string.IsNullOrEmpty(_settingsService.UltimaOnlineDirectory)) { MessageBoxEx.Show(_applicationService.MainForm, "ConnectUO was unable to find the directory that Ultima Online is installed to. This must be set in order to launch the client."); return; } if (string.IsNullOrEmpty(_settingsService.UltimaOnlineExe)) { MessageBoxEx.Show(_applicationService.MainForm, "ConnectUO was unable to find the client executable. This must be set in order to launch the client."); return; } string folderName = name; EnsureValidFolderName(ref folderName); string serverDirectory = Path.Combine(_settingsService.PatchDirectory, folderName); string[] patchFiles = null; FileSystemHelper.EnsureDirectoryExists(serverDirectory); List <ServerPatch> patchList = new List <ServerPatch>(); split = patches.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < split.Length; i++) { string[] patchVersion = split[i].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); if (patchVersion.Length == 2) { string patchUri = patchVersion[0]; string versionString = patchVersion[1]; int version; int.TryParse(versionString, out version); ServerPatch patch = new ServerPatch(); patch.ShardId = id; patch.PatchUrl = patchUri; patch.Version = version; patchList.Add(patch); //if (!_storageService.IsPatchApplied(patch)) //{ // //_storageService.ResetPatches(id); // patchList.Add(patch); // //i = 0; // //continue; //} } } ServerPatch[] notPatched = (from p in patchList where !_storageService.IsPatchApplied(p) select p).ToArray(); if (notPatched.Length > 0) { if (_storageService.IsServerBeingPatched(id)) { MessageBoxEx.Show(_applicationService.MainForm, String.Format("{0} is already being patched, you cannot play until the patching process has been completed", name), "ConnectUO 2.0"); return; } else { //_storageService.ResetPatches(id); PatcherForm taskManager = _kernel.Get <PatcherForm>(); taskManager.Patches = notPatched; taskManager.ServerDirectory = serverDirectory; if (taskManager.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } } } patchFiles = Directory.GetFiles(serverDirectory); _storageService.UpdatePlayStatistics(_settingsService.Guid, id); ClientLauncher.Launch( _kernel, id, hostAddress, port, Path.Combine(_settingsService.UltimaOnlineDirectory, _settingsService.UltimaOnlineExe), _settingsService.RazorDirectory, razor, enc, Path.Combine(_settingsService.PatchDirectory, folderName), patchFiles); } catch (Exception e) { Tracer.Error(e); } }
public void Awake() { clientLauncher = this; }
// Start is called before the first frame update private void Start() { canvasGroup = GetComponent <CanvasGroup>(); larPaCag = loginAndregPanel.GetComponent <CanvasGroup>(); launcher = launcherHost.GetComponent <ClientLauncher>(); }