Esempio n. 1
0
        private void OnTick(object sender, EventArgs eventArgs)
        {
            var process = AcProcess.TryToFind();

            if (process != null)
            {
                _timer.IsEnabled = false;
                _process         = process;
                _processTcs?.TrySetResult(process);
            }
        }
Esempio n. 2
0
        private bool IsAcWindowActive()
        {
            if (_cancelled)
            {
                return(false);
            }

            if (_process == null)
            {
                _process = AcProcess.TryToFind();
                if (_process == null)
                {
                    return(false);
                }
            }

            return(_process.MainWindowHandle == User32.GetForegroundWindow());
        }
Esempio n. 3
0
        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.Handle == LogitechG29HandleOptions.NoHandle)
            {
                AcToolsLogging.Write("Handle won’t be specified");
                initializationHandle = null;
            }
            else if (_options.Handle == LogitechG29HandleOptions.MainHandle)
            {
                AcToolsLogging.Write("Main CM handle will be used");
                initializationHandle = GetMainWindowHandle();
            }
            else if (_options.Handle == LogitechG29HandleOptions.FakeHandle)
            {
                AcToolsLogging.Write("Fake CM handle will be used");
                initializationHandle = CreateNewFormForHandle();
            }
            else if (_options.Handle == LogitechG29HandleOptions.AcHandle)
            {
                AcToolsLogging.Write("AC handle will be used");
                initializationHandle = process.MainWindowHandle;
            }
            else
            {
                AcToolsLogging.Write("Unknown value! Fallback to AC handle");
                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);
            }
        }
Esempio n. 4
0
 protected virtual string GetExeFileName()
 {
     return(AcProcess.TryToFind()?.GetFilenameSafe());
 }
Esempio n. 5
0
        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);
            }
        }