From bb44e27923a9b6c8cb83d668e29a243c35e4a072 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Sat, 21 Dec 2019 14:11:10 -0600 Subject: [PATCH] Added check for game version boundary --- IPA.Injector/GameVersionEarly.cs | 8 ++++++-- IPA.Injector/Injector.cs | 8 ++++---- IPA.Injector/Updates.cs | 1 - IPA.Loader/Loader/PluginLoader.cs | 12 +++--------- IPA.Loader/Utilities/BeatSaber.cs | 14 ++++++++++++++ 5 files changed, 27 insertions(+), 16 deletions(-) diff --git a/IPA.Injector/GameVersionEarly.cs b/IPA.Injector/GameVersionEarly.cs index 2d088e7d..97dc264f 100644 --- a/IPA.Injector/GameVersionEarly.cs +++ b/IPA.Injector/GameVersionEarly.cs @@ -15,7 +15,7 @@ namespace IPA.Injector { internal static class GameVersionEarly { - internal static string ResolveDataPath(string installDir) => + internal static string ResolveDataPath(string installDir) => Directory.EnumerateDirectories(installDir, "*_Data").First(); internal static string GlobalGameManagers(string installDir) => @@ -53,7 +53,11 @@ namespace IPA.Injector internal static SemVer.Version SafeParseVersion() => new SemVer.Version(GetGameVersion(), true); - private static void _Load() => BeatSaber.SetEarlyGameVersion(SafeParseVersion()); + private static void _Load() + { + BeatSaber.SetEarlyGameVersion(SafeParseVersion()); + BeatSaber.CheckGameVersionBoundary(); + } internal static void Load() { diff --git a/IPA.Injector/Injector.cs b/IPA.Injector/Injector.cs index 7ccc86bd..d611f67b 100644 --- a/IPA.Injector/Injector.cs +++ b/IPA.Injector/Injector.cs @@ -85,17 +85,17 @@ namespace IPA.Injector CriticalSection.Configure(); - Updates.InstallPendingUpdates(); - - LibLoader.SetupAssemblyFilenames(true); - loader.Debug("Prepping bootstrapper"); // updates backup InstallBootstrapPatch(); + LibLoader.SetupAssemblyFilenames(true); + GameVersionEarly.Load(); + Updates.InstallPendingUpdates(); + //HarmonyProtector.Protect(); pluginAsyncLoadTask = PluginLoader.LoadTask(); diff --git a/IPA.Injector/Updates.cs b/IPA.Injector/Updates.cs index 6ded9dc3..13a71250 100644 --- a/IPA.Injector/Updates.cs +++ b/IPA.Injector/Updates.cs @@ -37,7 +37,6 @@ namespace IPA.Injector { Process.Start(new ProcessStartInfo { - // will never actually be null FileName = path, Arguments = $"\"-nw={Process.GetCurrentProcess().Id},s={string.Join(" ", Environment.GetCommandLineArgs().Skip(1).StrJP()).Replace("\\", "\\\\").Replace(",", "\\,")}\"", UseShellExecute = false diff --git a/IPA.Loader/Loader/PluginLoader.cs b/IPA.Loader/Loader/PluginLoader.cs index 99deaaa5..4872a8e9 100644 --- a/IPA.Loader/Loader/PluginLoader.cs +++ b/IPA.Loader/Loader/PluginLoader.cs @@ -136,14 +136,11 @@ namespace IPA.Loader internal static void YeetIfNeeded() { string pluginDir = BeatSaber.PluginsPath; - var gameVer = BeatSaber.GameVersion; - var lastVerS = SelfConfig.LastGameVersion_; - var lastVer = lastVerS != null ? new AlmostVersion(lastVerS, gameVer) : null; - if (SelfConfig.YeetMods_ && lastVer != null && gameVer != lastVer) + if (SelfConfig.YeetMods_ && BeatSaber.IsGameVersionBoundary) { - var oldPluginsName = Path.Combine(BeatSaber.InstallPath, $"Old {lastVer} Plugins"); - var newPluginsName = Path.Combine(BeatSaber.InstallPath, $"Old {gameVer} Plugins"); + var oldPluginsName = Path.Combine(BeatSaber.InstallPath, $"Old {BeatSaber.OldVersion} Plugins"); + var newPluginsName = Path.Combine(BeatSaber.InstallPath, $"Old {BeatSaber.GameVersion} Plugins"); if (Directory.Exists(oldPluginsName)) Directory.Delete(oldPluginsName, true); @@ -153,9 +150,6 @@ namespace IPA.Loader else Directory.CreateDirectory(pluginDir); } - - SelfConfig.SelfConfigRef.Value.LastGameVersion = gameVer.ToString(); - SelfConfig.LoaderConfig.Store(SelfConfig.SelfConfigRef.Value); } internal static List PluginsMetadata = new List(); diff --git a/IPA.Loader/Utilities/BeatSaber.cs b/IPA.Loader/Utilities/BeatSaber.cs index f6d57c2a..091d5b91 100644 --- a/IPA.Loader/Utilities/BeatSaber.cs +++ b/IPA.Loader/Utilities/BeatSaber.cs @@ -46,6 +46,20 @@ namespace IPA.Utilities } } + internal static bool IsGameVersionBoundary { get; private set; } + internal static AlmostVersion OldVersion { get; private set; } + internal static void CheckGameVersionBoundary() + { + var gameVer = GameVersion; + var lastVerS = SelfConfig.LastGameVersion_; + var OldVersion = lastVerS != null ? new AlmostVersion(lastVerS, gameVer) : null; + + IsGameVersionBoundary = OldVersion != null && gameVer != OldVersion; + + SelfConfig.SelfConfigRef.Value.LastGameVersion = gameVer.ToString(); + SelfConfig.LoaderConfig.Store(SelfConfig.SelfConfigRef.Value); + } + /// /// The different types of releases of the game. ///