Ejemplo n.º 1
0
        public static void Revert()
        {
            foreach (var key in PatchedStorage.Keys.ToList())
            {
                var data = PatchedStorage.GetObject <CommandToPatch>(key);
                if (data.Offset > 0)
                {
                    ObjectExtension.Swap(ref data.OriginalOpCode, ref data.PatchedOpCode);
                    try {
                        PatchFile(key, data, false);
                        PatchedStorage.Remove(key);
                    } catch (PatchException e) {
                        NonfatalError.NotifyBackground("Can’t revert AC to its original state", e.Message.ToSentence());
                    } catch (Exception e) {
                        NonfatalError.NotifyBackground("Can’t revert AC to its original state", e);
                    }
                }
            }

            var ini   = new IniFile(AcPaths.GetCfgVideoFilename());
            var video = ini["VIDEO"];

            if (video.ContainsKey(@"__CM_ORIGINAL_SHADOW_MAP_SIZE"))
            {
                video.Set("SHADOW_MAP_SIZE", video.GetInt("__CM_ORIGINAL_SHADOW_MAP_SIZE", 2048));
                video.Remove(@"__CM_ORIGINAL_SHADOW_MAP_SIZE");
                ini.Save();
            }
        }
Ejemplo n.º 2
0
        public static bool IsSupposedToWork()
        {
            // Loading value directly in case custom preset were applied, but VideoSettings aren’t updated yet
            var video = new IniFile(AcPaths.GetCfgVideoFilename())["VIDEO"];

            return((video.GetIntNullable("__CM_ORIGINAL_SHADOW_MAP_SIZE") ?? video.GetInt("SHADOW_MAP_SIZE", 2048)) < 1);
        }
Ejemplo n.º 3
0
        private static void LaunchReport(string filename)
        {
            try {
                using (var stream = File.OpenRead(Path.Combine(Path.GetDirectoryName(filename) ?? "", Path.GetFileNameWithoutExtension(filename) + ".zip")))
                    using (var archive = new ZipArchive(stream)) {
                        // Apply video config
                        var currentVideo  = new IniFile(AcPaths.GetCfgVideoFilename());
                        var currentWidth  = currentVideo["VIDEO"].GetInt("WIDTH", 1920);
                        var currentHeight = currentVideo["VIDEO"].GetInt("HEIGHT", 1080);
                        var newVideo      =
                            IniFile.Parse((archive.GetEntry("video.ini") ?? throw new Exception("Video config is missing")).Open().ReadAsStringAndDispose());
                        newVideo["VIDEO"].Set("WIDTH", Math.Min(currentWidth, newVideo["VIDEO"].GetInt("WIDTH", 1920)));
                        newVideo["VIDEO"].Set("HEIGHT", Math.Min(currentHeight, newVideo["VIDEO"].GetInt("HEIGHT", 1080)));
                        File.WriteAllText(AcPaths.GetCfgVideoFilename(), newVideo.ToString());

                        // Apply CSP config
                        PatchSettingsModel.Create().ImportFromPresetData(archive.GetEntry("csp.ini")?.Open().ReadAsStringAndDispose() ?? string.Empty);

                        // Apply race config
                        File.WriteAllText(AcPaths.GetRaceIniFilename(),
                                          (archive.GetEntry("race.ini") ?? throw new Exception("Race config is missing")).Open().ReadAsStringAndDispose());

                        Process.Start(new ProcessStartInfo {
                            FileName         = Path.Combine(AcRootDirectory.Instance.Value ?? "", "acs.exe"),
                            WorkingDirectory = AcRootDirectory.Instance.Value ?? ""
                        });
                    }
            } catch (Exception e) {
                NonfatalError.Notify("Failed to launch report race", e);
            }
        }
Ejemplo n.º 4
0
        private static void SetCurrentFilterIni(string filter)
        {
            var filename = AcPaths.GetCfgVideoFilename();
            var iniFile  = new IniFile(filename);

            iniFile["POST_PROCESS"].Set("FILTER", filter);
            iniFile.Save();
        }
        protected override bool SetOverride(WeatherObject weather, IniFile file)
        {
            var videoCfg = AcPaths.GetCfgVideoFilename();

            if (!File.Exists(videoCfg))
            {
                return(false);
            }

            var customFilter = false;

            if (SettingsHolder.Drive.WeatherSpecificPpFilter)
            {
                var replacement = Path.Combine(weather.Location, "filter.ini");
                if (File.Exists(replacement))
                {
                    customFilter = true;

                    _destination = Destination;
                    if (File.Exists(_destination))
                    {
                        File.Delete(_destination);
                    }

                    FileUtils.HardLinkOrCopy(replacement, _destination);
                }
            }

            var disableShadows = new IniFile(weather.IniFilename)["__LAUNCHER_CM"].GetBool("DISABLE_SHADOWS", false);

            if (!customFilter && !disableShadows)
            {
                return(false);
            }

            var ini = new IniFile(videoCfg);

            if (customFilter)
            {
                var section = ini["POST_PROCESS"];
                section.Set("__CM_PREWEATHER_ORIGINAL_FILTER", section.GetNonEmpty("FILTER"));
                section.Set("FILTER", FilterId);
            }

            if (disableShadows)
            {
                var section = ini["VIDEO"];
                section.Set("__CM_PREWEATHER_ORIGINAL_SHADOW_MAP_SIZE", section.GetNonEmpty("__CM_ORIGINAL_SHADOW_MAP_SIZE") ?? section.GetNonEmpty("SHADOW_MAP_SIZE"));
                section.Set("SHADOW_MAP_SIZE", -1);
            }

            ini.Save();

            return(true);
        }
Ejemplo n.º 6
0
        public void OnProgress(Game.ProgressState progress)
        {
            switch (progress)
            {
            case Game.ProgressState.Preparing:
                Model.WaitingStatus = AppStrings.Race_Preparing;
                break;

            case Game.ProgressState.Launching:
                if (AcRootDirectory.CheckDirectory(MainExecutingFile.Directory) &&
                    MainExecutingFile.Name != "AssettoCorsa.exe" &&
                    new IniFile(AcPaths.GetCfgVideoFilename())["CAMERA"].GetNonEmpty("MODE") == "OCULUS" &&
                    MessageDialog.Show(
                        "Oculus Rift might not work properly with Content Manager is in AC root folder. It’s better to move it to avoid potential issues.",
                        "Important note", new MessageDialogButton {
                    [MessageBoxResult.Yes] = "Move it now",
                    [MessageBoxResult.No] = "Ignore"
                }, "oculusRiftWarningMessage") == MessageBoxResult.Yes)
                {
                    try {
                        var newLocation = FilesStorage.Instance.GetFilename(MainExecutingFile.Name);
                        File.Copy(MainExecutingFile.Location, newLocation, true);
                        WindowsHelper.ViewFile(newLocation);
                        ProcessExtension.Start(newLocation, new[] { @"--restart", @"--move-app=" + MainExecutingFile.Location });
                        Environment.Exit(0);
                    } catch (Exception e) {
                        NonfatalError.Notify("Failed to move Content Manager executable", "I’m afraid you’ll have to do it manually.", e);
                    }
                }

                if (SettingsHolder.Drive.SelectedStarterType == SettingsHolder.DriveSettings.DeveloperStarterType)
                {
                    Model.WaitingStatus = "Now, run AC…";
                }
                else
                {
                    Model.WaitingStatus = _mode == GameMode.Race ? AppStrings.Race_LaunchingGame :
                                          _mode == GameMode.Replay ? AppStrings.Race_LaunchingReplay : AppStrings.Race_LaunchingBenchmark;
                }
                break;

            case Game.ProgressState.Waiting:
                Model.WaitingStatus = _mode == GameMode.Race ? AppStrings.Race_Waiting :
                                      _mode == GameMode.Replay ? AppStrings.Race_WaitingReplay : AppStrings.Race_WaitingBenchmark;
                break;

            case Game.ProgressState.Finishing:
                RevertSizeFix().Ignore();
                Model.WaitingStatus = AppStrings.Race_CleaningUp;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(progress), progress, null);
            }
        }
        public static void Revert()
        {
            if (AcRootDirectory.Instance.Value == null)
            {
                return;
            }

            try {
                var destination = Destination;
                if (File.Exists(destination))
                {
                    File.Delete(destination);
                }

                var changed = false;

                var ini = new IniFile(AcPaths.GetCfgVideoFilename());

                {
                    var section = ini["POST_PROCESS"];
                    if (section.GetNonEmpty("FILTER") == FilterId)
                    {
                        section.Set("FILTER", section.GetNonEmpty("__CM_PREWEATHER_ORIGINAL_FILTER") ?? @"default");
                        section.Remove(@"__CM_PREWEATHER_ORIGINAL_FILTER");
                        changed = true;
                    }
                }

                {
                    var section = ini["VIDEO"];
                    if (section.ContainsKey(@"__CM_PREWEATHER_ORIGINAL_SHADOW_MAP_SIZE"))
                    {
                        section.Set("SHADOW_MAP_SIZE", section.GetNonEmpty("__CM_PREWEATHER_ORIGINAL_SHADOW_MAP_SIZE"));
                        section.Remove(@"__CM_PREWEATHER_ORIGINAL_SHADOW_MAP_SIZE");
                        section.Remove(@"__CM_ORIGINAL_SHADOW_MAP_SIZE");
                        changed = true;
                    }
                }

                if (changed)
                {
                    ini.Save();
                }
            } catch (Exception e) {
                Logging.Warning(e);
            }
        }
Ejemplo n.º 8
0
        private static void PatchAc([NotNull] string acsFilename, bool use32BitVersion)
        {
            try {
                if (_data == null)
                {
                    throw new PatchException("Definitions are missing");
                }

                var dictionary = use32BitVersion ? _data.For32BitVersion : _data.For64BitVersion;
                if (dictionary == null)
                {
                    throw new PatchException("Definitions for selected platform are missing");
                }

                var checksum = ComputeChecksum(acsFilename);
                var toPatch  = dictionary.FirstOrDefault(x => string.Equals(x.Value.Original, checksum, StringComparison.OrdinalIgnoreCase));
                if (toPatch.Value != null)
                {
                    Logging.Write($"Description found: version={toPatch.Key}, checksum={checksum}");
                    PatchFile(acsFilename, toPatch.Value.ToPatch(), true);
                    var ini   = new IniFile(AcPaths.GetCfgVideoFilename());
                    var video = ini["VIDEO"];
                    if (!video.ContainsKey("__CM_ORIGINAL_SHADOW_MAP_SIZE"))
                    {
                        video.Set("__CM_ORIGINAL_SHADOW_MAP_SIZE", video.GetInt("SHADOW_MAP_SIZE", 0));
                        video.Set("SHADOW_MAP_SIZE", 32);
                    }
                    ini.Save();
                }
                else
                {
                    var alreadyPatched = dictionary.FirstOrDefault(x => string.Equals(x.Value.Patched, checksum, StringComparison.OrdinalIgnoreCase));
                    if (alreadyPatched.Value != null)
                    {
                        Logging.Write($"Already patched: version={toPatch.Key}, checksum={checksum}");
                    }
                    else
                    {
                        throw new PatchException($"Description for executable is missing: {checksum}");
                    }
                }
            } catch (PatchException e) {
                NonfatalError.NotifyBackground("Can’t patch AC to disable shadows", e.Message.ToSentence());
            } catch (Exception e) {
                NonfatalError.NotifyBackground("Can’t patch AC to disable shadows", e);
            }
        }
Ejemplo n.º 9
0
        private async Task PrepareToFixSize()
        {
            await Task.Yield();

            if (_disabledWindowHandling != null)
            {
                return;
            }

            var video          = new IniFile(AcPaths.GetCfgVideoFilename())["VIDEO"];
            var width          = video.GetInt("WIDTH", 1920);
            var height         = video.GetInt("HEIGHT", 1080);
            var isAcFullscreen = video.GetBool("FULLSCREEN", false);

            if (isAcFullscreen && (Screen.AllScreens.Any(x => x.Bounds.Width > width) || Screen.AllScreens.Any(x => x.Bounds.Height > height)))
            {
                Logging.Here();
                _disabledWindowHandling = DisableAnyLogic();
            }
        }
Ejemplo n.º 10
0
        private static void Click(Func <Point, Point> coordinatesProvider)
        {
            var originalPosition = Cursor.Position;
            var screen           = Screen.FromPoint(originalPosition);
            var screenWidth      = screen.Bounds.Width;
            var screenHeight     = screen.Bounds.Height;

            var point = Array.IndexOf(new[] {
                "OCULUS", "OPENVR"
            }, new IniFile(AcPaths.GetCfgVideoFilename())["CAMERA"].GetNonEmpty("MODE")) != -1
                    ? new Point(-1, -1) : new Point(screenWidth, screenHeight);

            var coordinates = coordinatesProvider(point);

            AcToolsLogging.Write($"Mouse position: {originalPosition.X}, {originalPosition.Y}; screen resolution: {screenWidth}×{screenHeight}");

            var mouse = new MouseSimulator();

            mouse.MoveMouseTo(65536d * coordinates.X / screenWidth, 65536d * coordinates.Y / screenHeight);
            mouse.LeftButtonClick();
            mouse.MoveMouseTo(65536d * originalPosition.X / screenWidth, 65536d * originalPosition.Y / screenHeight);
        }
Ejemplo n.º 11
0
        private VideoIniChange(string presetFilename, string ppFilter, bool?fxaa, bool specialResolution, bool maximizeSettings)
        {
            _filename        = AcPaths.GetCfgVideoFilename();
            _originalContent = File.ReadAllText(_filename);

            var parseContent = _originalContent;

            if (presetFilename != null && File.Exists(presetFilename))
            {
                parseContent = File.ReadAllText(presetFilename);
                _changed     = true;
            }

            var video = IniFile.Parse(parseContent);

            if (fxaa.HasValue)
            {
                video["EFFECTS"].Set("FXAA", fxaa.Value);
                video["POST_PROCESS"].Set("FXAA", fxaa.Value);
                _changed = true;
            }

            if (ppFilter != null)
            {
                video["POST_PROCESS"].Set("FILTER", ppFilter);
                _changed = true;
            }

            if (specialResolution)
            {
                video["VIDEO"].Set("FULLSCREEN", false);
                video["VIDEO"].Set("WIDTH", 1920 * 2);
                video["VIDEO"].Set("HEIGHT", 1080 * 2);
                _changed = true;
            }

            if (maximizeSettings)
            {
                video["POST_PROCESS"].Set("ENABLED", true);
                video["POST_PROCESS"].Set("DOF", 0);
                video["POST_PROCESS"].Set("GLARE", 4);
                video["POST_PROCESS"].Set("HEAT_SHIMMER", 0);
                video["POST_PROCESS"].Set("QUALITY", 5);
                video["POST_PROCESS"].Set("RAYS_OF_GOD", 1);
                video["CUBEMAP"].Set("FACES_PER_FRAME", 6);
                video["CUBEMAP"].Set("FARPLANE", 500);
                video["CUBEMAP"].Set("SIZE", 2048);
                _changed = true;
            }

            if (!_changed)
            {
                return;
            }
            _backup = _filename + ".backup";
            if (File.Exists(_backup))
            {
                File.Delete(_backup);
            }
            File.Move(_filename, _backup);
            video.Save(_filename);
        }
Ejemplo n.º 12
0
 private static string GetCurrentFilterIni()
 {
     return(new IniFile(AcPaths.GetCfgVideoFilename())["POST_PROCESS"].GetPossiblyEmpty("FILTER"));
 }
        public static void Revert()
        {
            if (AcRootDirectory.Instance.Value == null)
            {
                return;
            }

            try {
                var destination = Destination;
                if (File.Exists(destination))
                {
                    File.Delete(destination);
                }

                {
                    var changed = false;
                    var ini     = new IniFile(AcPaths.GetCfgVideoFilename());

                    var postProcess = ini["POST_PROCESS"];
                    if (postProcess.GetNonEmpty("FILTER") == FilterId)
                    {
                        postProcess.Set("FILTER", postProcess.GetNonEmpty("__CM_PREWEATHER_ORIGINAL_FILTER") ?? @"default");
                        postProcess.Remove(@"__CM_PREWEATHER_ORIGINAL_FILTER");
                        changed = true;
                    }

                    var video = ini["VIDEO"];
                    if (video.ContainsKey(@"__CM_PREWEATHER_ORIGINAL_SHADOW_MAP_SIZE"))
                    {
                        video.Set("SHADOW_MAP_SIZE", video.GetNonEmpty("__CM_PREWEATHER_ORIGINAL_SHADOW_MAP_SIZE"));
                        video.Remove(@"__CM_PREWEATHER_ORIGINAL_SHADOW_MAP_SIZE");
                        video.Remove(@"__CM_ORIGINAL_SHADOW_MAP_SIZE");
                        changed = true;
                    }

                    if (changed)
                    {
                        ini.Save();
                    }
                }

                {
                    var changed = false;
                    var ini     = new IniFile(AcSettingsHolder.Graphics.Filename);

                    var section = ini["DX11"];
                    if (section.ContainsKey(@"__CM_PREWEATHER_ORIGINAL_SKYBOX_REFLECTION_GAIN"))
                    {
                        section.Set("SKYBOX_REFLECTION_GAIN", section.GetNonEmpty("__CM_PREWEATHER_ORIGINAL_SKYBOX_REFLECTION_GAIN"));
                        section.Remove(@"__CM_PREWEATHER_ORIGINAL_SKYBOX_REFLECTION_GAIN");
                        changed = true;
                    }

                    if (changed)
                    {
                        ini.Save();
                    }
                }
            } catch (Exception e) {
                Logging.Warning(e);
            }
        }