Beispiel #1
0
        public DiscordJoinRequestDialog(DiscordJoinRequest args, CancellationToken cancellation = default(CancellationToken))
        {
            cancellation.Register(async() => {
                await Task.Delay(200);
                CloseWithResult(MessageBoxResult.Cancel);
            });

            Owner       = null;
            DataContext = this;
            InitializeComponent();
            Buttons = new Control[0];

            TitleBlock.Text = $"User {args.UserName} wants to join. Allow?";

            if (!string.IsNullOrWhiteSpace(args.AvatarUrl))
            {
                Image.Filename = $"{args.AvatarUrl}?size=128";
            }
            else
            {
                Image.Visibility = Visibility.Collapsed;
            }

            this.OnActualUnload(OnUnload);

            var config = new IniFile(AcPaths.GetCfgControlsFilename());

            _yes = new ControlsInput(config["__CM_DISCORD_REQUEST_ACCEPT"], Keys.Enter);
            _no  = new ControlsInput(config["__CM_DISCORD_REQUEST_DENY"], Keys.Back);

            try {
                SetDevices().Ignore();
                _yes.SetIcon(YesIcon, this);
                _no.SetIcon(NoIcon, this);
            } catch (Exception e) {
                Logging.Error(e);
            }

            _inGameAppParams = new CmInGameAppJoinRequestParams(args.UserName, args.UserId, args.AvatarUrl,
                                                                b => (b ? YesCommand : NoCommand).ExecuteAsync().Ignore());
            CompositionTargetEx.Rendering += OnRendering;
        }
Beispiel #2
0
        public static void Revert()
        {
            var controlsFilename = AcPaths.GetCfgControlsFilename();
            var ini        = new IniFile(controlsFilename);
            var iniChanged = Revert(ini, out var originalLock);

            if (originalLock.HasValue)
            {
                try {
                    GetSteerLockSetter(ini)?.Apply(originalLock.Value, true, out _);
                } catch (Exception e) {
                    NonfatalError.NotifyBackground("Failed to apply hardware lock", e);
                }
            }

            if (!new TemporaryFileReplacement(null, controlsFilename, BackupPostfix).Revert() && iniChanged)
            {
                ini.Save();
            }
        }
Beispiel #3
0
        protected override bool SetOverride(CarObject car)
        {
            var controlsFilename       = AcPaths.GetCfgControlsFilename();
            var specificControlsLoaded = car.SpecificControlsPreset && car.ControlsPresetFilename != null &&
                                         new TemporaryFileReplacement(car.ControlsPresetFilename, controlsFilename, BackupPostfix, false).Apply();

            var ini        = new IniFile(controlsFilename);
            var iniChanged = Revert(ini, out _);

            var extra = ini["__EXTRA_CM"];
            var steer = ini["STEER"];

            var carSteerLock = car.SteerLock ?? 0d;

            if (carSteerLock < 40)
            {
                Logging.Warning("Invalid car steer lock");
                Revert();
                return(specificControlsLoaded);
            }

            Logging.Write($"Car steer lock: {carSteerLock}°");
            var hardLock       = extra.GetBool("HARDWARE_LOCK", false);
            var currentDegrees = steer.GetInt("LOCK", 900);

            if (hardLock)
            {
                Logging.Write($"Hardware lock enabled, controls lock: {currentDegrees}");
            }

            if (hardLock && currentDegrees > carSteerLock)
            {
                var lockSetter = GetSteerLockSetter(ini);
                Logging.Write(lockSetter == null
                        ? "Lock setter for provided device not found"
                        : $"Lock setter: {lockSetter.MinimumSteerLock}…{lockSetter.MaximumSteerLock}");

                if (lockSetter != null && carSteerLock < lockSetter.MaximumSteerLock)
                {
                    var newDegrees = carSteerLock.RoundToInt().Clamp(lockSetter.MinimumSteerLock, lockSetter.MaximumSteerLock);
                    Logging.Write("Updated lock: " + newDegrees);

                    try {
                        if (lockSetter.Apply(newDegrees, false, out var appliedValue))
                        {
                            Logging.Write("Hardware lock applied successfully!");
                            steer.Set("__CM_ORIGINAL_LOCK", currentDegrees);
                            steer.Set("LOCK", appliedValue);
                            ini.Save();

                            if (lockSetter.GetOptions() is LogitechOptions logitech)
                            {
                                SpecialLogitechFix(logitech);
                            }

                            return(true);
                        }

                        Logging.Warning("Failed to apply hardware lock");
                    } catch (Exception e) {
                        NonfatalError.NotifyBackground("Failed to apply hardware lock", e);
                    }
                }

                goto End;
            }

            var autoAdjustScale = extra.GetBool("AUTO_ADJUST_SCALE", false);

            if (autoAdjustScale)
            {
                var currentScale = steer.GetDouble("SCALE", 1d);
                var newScale     = Math.Min(currentDegrees / carSteerLock, 1d);
                if (newScale != currentScale)
                {
                    Logging.Write($"Set scale: {newScale}");
                    steer.Set("__CM_ORIGINAL_SCALE", currentScale);
                    steer.Set("SCALE", newScale);
                    ini.Save();
                    return(true);
                }
            }

End:
            if (iniChanged)
            {
                ini.Save();
            }

            return(specificControlsLoaded);
        }