diff --git a/IPA.Injector/GameVersionEarly.cs b/IPA.Injector/GameVersionEarly.cs index b3cbec86..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,12 +53,16 @@ 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() { // This exists for the same reason the wierdness in Injector.Main does - var unused = Type.GetType("SemVer.Version, SemVer", false); + _ = Type.GetType("SemVer.Version, SemVer", false); _Load(); } diff --git a/IPA.Injector/Injector.cs b/IPA.Injector/Injector.cs index 3106c770..238f0b08 100644 --- a/IPA.Injector/Injector.cs +++ b/IPA.Injector/Injector.cs @@ -90,12 +90,12 @@ namespace IPA.Injector // updates backup InstallBootstrapPatch(); + GameVersionEarly.Load(); + Updates.InstallPendingUpdates(); LibLoader.SetupAssemblyFilenames(true); - GameVersionEarly.Load(); - pluginAsyncLoadTask = PluginLoader.LoadTask(); permissionFixTask = PermissionFix.FixPermissions(new DirectoryInfo(Environment.CurrentDirectory)); } 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 6a8051b3..91555a92 100644 --- a/IPA.Loader/Loader/PluginLoader.cs +++ b/IPA.Loader/Loader/PluginLoader.cs @@ -142,14 +142,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); @@ -159,8 +156,6 @@ namespace IPA.Loader else Directory.CreateDirectory(pluginDir); } - - SelfConfig.Instance.LastGameVersion = gameVer.ToString(); } internal static List PluginsMetadata = new List(); diff --git a/IPA.Loader/Utilities/BeatSaber.cs b/IPA.Loader/Utilities/BeatSaber.cs index f6d57c2a..c10ab7af 100644 --- a/IPA.Loader/Utilities/BeatSaber.cs +++ b/IPA.Loader/Utilities/BeatSaber.cs @@ -46,6 +46,19 @@ 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.Instance.LastGameVersion = gameVer.ToString(); + } + /// /// The different types of releases of the game. /// diff --git a/IPA/Program.cs b/IPA/Program.cs index 85b9dadd..0b52ddb9 100644 --- a/IPA/Program.cs +++ b/IPA/Program.cs @@ -27,19 +27,19 @@ namespace IPA public static Version Version => Assembly.GetEntryAssembly().GetName().Version; - public static readonly ArgumentFlag ArgHelp = new ArgumentFlag("--help", "-h") { DocString = "prints this message" }; - public static readonly ArgumentFlag ArgWaitFor = new ArgumentFlag("--waitfor", "-w") { DocString = "waits for the specified PID to exit", ValueString = "PID" }; - public static readonly ArgumentFlag ArgForce = new ArgumentFlag("--force", "-f") { DocString = "forces the operation to go through" }; - public static readonly ArgumentFlag ArgRevert = new ArgumentFlag("--revert", "-r") { DocString = "reverts the IPA installation" }; - public static readonly ArgumentFlag ArgNoWait = new ArgumentFlag("--nowait", "-n") { DocString = "doesn't wait for user input after the operation" }; - public static readonly ArgumentFlag ArgStart = new ArgumentFlag("--start", "-s") { DocString = "uses value_ as arguments to start the game after the patch/unpatch", ValueString = "ARGUMENTS" }; - public static readonly ArgumentFlag ArgLaunch = new ArgumentFlag("--launch", "-l") { DocString = "uses positional parameters as arguments to start the game after patch/unpatch" }; - //public static readonly ArgumentFlag ArgDestructive = new ArgumentFlag("--destructive", "-d") { DocString = "patches the game using the now outdated destructive methods" }; + public static readonly ArgumentFlag ArgHelp = new ArgumentFlag("--help", "-h") { DocString = "prints this message" }; + public static readonly ArgumentFlag ArgWaitFor = new ArgumentFlag("--waitfor", "-w") { DocString = "waits for the specified PID to exit", ValueString = "PID" }; + public static readonly ArgumentFlag ArgForce = new ArgumentFlag("--force", "-f") { DocString = "forces the operation to go through" }; + public static readonly ArgumentFlag ArgRevert = new ArgumentFlag("--revert", "-r") { DocString = "reverts the IPA installation" }; + public static readonly ArgumentFlag ArgNoRevert = new ArgumentFlag("--no-revert", "-R") { DocString = "prevents a normal installation from first reverting" }; + public static readonly ArgumentFlag ArgNoWait = new ArgumentFlag("--nowait", "-n") { DocString = "doesn't wait for user input after the operation" }; + public static readonly ArgumentFlag ArgStart = new ArgumentFlag("--start", "-s") { DocString = "uses the specified arguments to start the game after the patch/unpatch", ValueString = "ARGUMENTS" }; + public static readonly ArgumentFlag ArgLaunch = new ArgumentFlag("--launch", "-l") { DocString = "uses positional parameters as arguments to start the game after patch/unpatch" }; [STAThread] public static void Main(string[] args) { - Arguments.CmdLine.Flags(ArgHelp, ArgWaitFor, ArgForce, ArgRevert, ArgNoWait, ArgStart, ArgLaunch/*, ArgDestructive*/).Process(); + Arguments.CmdLine.Flags(ArgHelp, ArgWaitFor, ArgForce, ArgRevert, ArgNoWait, ArgStart, ArgLaunch, ArgNoRevert).Process(); if (ArgHelp) { @@ -159,10 +159,13 @@ namespace IPA { var backup = new BackupUnit(context); - Console.ForegroundColor = ConsoleColor.Cyan; - Console.WriteLine("Restoring old version... "); - if (BackupManager.HasBackup(context)) - BackupManager.Restore(context); + if (!ArgNoRevert) + { + Console.ForegroundColor = ConsoleColor.Cyan; + Console.WriteLine("Restoring old version... "); + if (BackupManager.HasBackup(context)) + BackupManager.Restore(context); + } var nativePluginFolder = Path.Combine(context.DataPathDst, "Plugins"); bool isFlat = Directory.Exists(nativePluginFolder) &&