private void Reset(int value) { if (_initialized) { _initialized = false; SetWheelRange(value); LogiSteeringShutdown(); AcToolsLogging.Write("Previous initialization shutdown"); } if (_form != null) { _form.DestroyHandle(); _form = null; } }
protected static void Reset(Action callback) { if (_initialized) { _initialized = false; callback?.Invoke(); LogiSteeringShutdown(); AcToolsLogging.Write("Previous initialization shutdown"); } if (_form2 != null) { _form2.DestroyHandle(); _form2 = null; } }
protected static IntPtr CreateNewFormForHandle() { AcToolsLogging.Write("Creating new form to get its handle…"); Application.Current.Dispatcher?.Invoke(() => { _form2 = new FormWithHandle(); }); return(_form2.Handle); }
private async void OnGameStarted() { var id = ++_applyId; if (!_valueToSet.HasValue) { return; } var value = _valueToSet.Value; var process = AcProcess.TryToFind(); if (process == null) { AcToolsLogging.NonFatalErrorNotifyBackground($"Can’t set {ControllerName} steer lock", "Failed to find game process"); return; } IntPtr?initializationHandle; if (!_options.SpecifyHandle) { AcToolsLogging.Write("Handle won’t be specified"); initializationHandle = null; } else if (_options.UseOwnHandle) { AcToolsLogging.Write("Creating new form to get its handle…"); Application.Current.Dispatcher.Invoke(() => { _form = new FormWithHandle(); }); initializationHandle = _form.Handle; } else { AcToolsLogging.Write("AC handle will be used"); initializationHandle = process.MainWindowHandle; } Initialize(initializationHandle); await Task.Delay(500); AcToolsLogging.Write("Waited for half a second, moving on…"); if (_applyId != id) { AcToolsLogging.Write("Obsolete run, terminating"); return; } SetWheelRange(value); var isForeground = true; var setIndex = 1; var windows = process.GetWindowsHandles().ToArray(); while (!process.HasExitedSafe()) { var isForegroundNow = Array.IndexOf(windows, User32.GetForegroundWindow()) != -1; if (isForegroundNow != isForeground) { if (isForegroundNow) { SetWheelRange(value + setIndex); setIndex = 1 - setIndex; } isForeground = isForegroundNow; } await Task.Delay(50).ConfigureAwait(false); } }