private void AttachButton_Click(object aObj, System.Windows.RoutedEventArgs aEvent) { AttachButton.IsEnabled = false; RefreshButton.IsEnabled = false; if (!_attached) { var process = ProcessListBox.SelectedItems.Cast <ProcessInfo>().ToList(); var attached = false; if (process[0].CanUseMono) { _unityMod = new UnityVRMod(); _unityMod.MessageReceivedHandler += OnMessageReceived; _unityMod.Inject(process[0].Id, process[0].FrameworkVersion, process[0].MonoModule); attached = true; } if (process[0].CanUseXInput) { _xinputMod = new XInputMod(); _xinputMod.Attach(process[0].Id); _xinputMod.MessageReceivedHandler += OnMessageReceived; attached = true; } if (attached) { ProcessAttached?.Invoke(this, null); } } else { ProcessDetached?.Invoke(this, null); Detach(); } }
public void Detach() { if (Process != null) { if (Handle != IntPtr.Zero && !Kernel32.CloseHandle(Handle)) { throw new Win32Exception(Marshal.GetLastWin32Error()); } Process.Exited -= ProcessDetached; Process.Dispose(); Process = null; BaseAddress = Build = 0; Handle = IntPtr.Zero; ProcessDetached?.Invoke(this, EventArgs.Empty); } }