Exemplo n.º 1
0
        protected static bool LoadLogitechSteeringWheelDll()
        {
            if (_logitechDllInitialized.HasValue)
            {
                return(_logitechDllInitialized.Value);
            }

            // Library is in PATH, next to executable, somewhere in system or in a list of libraries to load, nice.
            try {
                if (Kernel32.LoadLibrary(LogitechSteeringWheel) != IntPtr.Zero)
                {
                    return((_logitechDllInitialized = true).Value);
                }
            } catch (Exception e) {
                AcToolsLogging.Write($"Failed to load: {e.Message}");
            }

            // Trying to find the library in Logitech Gaming Software installation…
            AcToolsLogging.Write($"Trying to locate {LogitechSteeringWheel}…");

            foreach (var location in LocateLogitechSteeringWheelDll().Where(File.Exists))
            {
                AcToolsLogging.Write($"Found: {location}");
                try {
                    Kernel32.LoadLibrary(location);
                    return((_logitechDllInitialized = true).Value);
                } catch (Exception e) {
                    AcToolsLogging.Write($"Failed to load: {e.Message}");
                }
            }

            AcToolsLogging.NonFatalErrorNotifyBackground($"Failed to find “{LogitechSteeringWheel}”",
                                                         "Please, make sure you have Logitech Gaming Software installed, or simply put that library next to executable.");
            return((_logitechDllInitialized = false).Value);
        }
Exemplo n.º 2
0
        protected static bool LoadLogitechSteeringWheelDll()
        {
            if (_logitechDllInitialized.HasValue)
            {
                return(_logitechDllInitialized.Value);
            }

            // Library is in PATH, next to executable, somewhere in system or in a list of libraries to load, nice.
            try {
                if (Kernel32.LoadLibrary(LogitechSteeringWheelOld) != IntPtr.Zero)
                {
                    _logitechDllUseOld = true;
                    return((_logitechDllInitialized = true).Value);
                }
            } catch (Exception e) {
                AcToolsLogging.Write($"Failed to load: {e.Message}");
            }

            // Library is in PATH, next to executable, somewhere in system or in a list of libraries to load, nice.
            try {
                if (Kernel32.LoadLibrary(LogitechSteeringWheelNew) != IntPtr.Zero)
                {
                    _logitechDllUseOld = false;
                    return((_logitechDllInitialized = true).Value);
                }
            } catch (Exception e) {
                AcToolsLogging.Write($"Failed to load: {e.Message}");
            }

            // Trying to find the library in Logitech Gaming Software installation…
            AcToolsLogging.Write($"Trying to locate {LogitechSteeringWheelOld}…");

            var location = LocateLogitechSteeringWheelDll();

            if (location != null)
            {
                AcToolsLogging.Write($"Found: {location}");
                try {
                    Kernel32.LoadLibrary(location);
                    _logitechDllUseOld = location.EndsWith(LogitechSteeringWheelOld, StringComparison.OrdinalIgnoreCase);
                    return((_logitechDllInitialized = true).Value);
                } catch (Exception e) {
                    AcToolsLogging.Write($"Failed to load: {e.Message}");
                }
            }

            AcToolsLogging.NonFatalErrorNotifyBackground($"Failed to find “{LogitechSteeringWheelOld}”",
                                                         "Please, make sure you have Logitech Gaming Software installed, or simply put that library next to executable.");
            return((_logitechDllInitialized = false).Value);
        }
Exemplo 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);
            }
        }
Exemplo n.º 4
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);
            }
        }