From 789b1495fbc18789e383ea500797389f22b43750 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Sat, 17 Aug 2019 20:31:06 -0500 Subject: [PATCH] Added early game version detection to code path --- IPA.Injector/GameVersionEarly.cs | 13 +++++++++-- IPA.Injector/Injector.cs | 6 +++-- IPA.Loader/Loader/PluginLoader.cs | 29 +++++++++++++++++++++++- IPA.Loader/Loader/PluginManager.cs | 31 -------------------------- IPA.Loader/Utilities/AlmostVersion.cs | 2 +- Refs/UnityEngine.CoreModule.Net4.dll | Bin 613888 -> 613888 bytes 6 files changed, 44 insertions(+), 37 deletions(-) diff --git a/IPA.Injector/GameVersionEarly.cs b/IPA.Injector/GameVersionEarly.cs index 94f74f4e..b3cbec86 100644 --- a/IPA.Injector/GameVersionEarly.cs +++ b/IPA.Injector/GameVersionEarly.cs @@ -1,4 +1,5 @@ using IPA.Utilities; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -22,7 +23,7 @@ namespace IPA.Injector internal static string GetGameVersion() { - var mgr = ResolveDataPath(BeatSaber.InstallPath); + var mgr = GlobalGameManagers(BeatSaber.InstallPath); using (var stream = File.OpenRead(mgr)) using (var reader = new BinaryReader(stream, Encoding.UTF8)) @@ -52,6 +53,14 @@ namespace IPA.Injector internal static SemVer.Version SafeParseVersion() => new SemVer.Version(GetGameVersion(), true); - internal static void Load() => BeatSaber.SetEarlyGameVersion(SafeParseVersion()); + private static void _Load() => BeatSaber.SetEarlyGameVersion(SafeParseVersion()); + + internal static void Load() + { + // This exists for the same reason the wierdness in Injector.Main does + var unused = Type.GetType("SemVer.Version, SemVer", false); + + _Load(); + } } } diff --git a/IPA.Injector/Injector.cs b/IPA.Injector/Injector.cs index 106d2418..88fd3524 100644 --- a/IPA.Injector/Injector.cs +++ b/IPA.Injector/Injector.cs @@ -92,8 +92,7 @@ namespace IPA.Injector LibLoader.SetupAssemblyFilenames(true); - // causes mono to hate itself - //GameVersionEarly.Load(); + GameVersionEarly.Load(); pluginAsyncLoadTask = PluginLoader.LoadTask(); permissionFixTask = PermissionFix.FixPermissions(new DirectoryInfo(Environment.CurrentDirectory)); @@ -302,6 +301,9 @@ namespace IPA.Injector // wait for plugins to finish loading pluginAsyncLoadTask.Wait(); permissionFixTask.Wait(); + + BeatSaber.EnsureRuntimeGameVersion(); + log.Debug("Plugins loaded"); log.Debug(string.Join(", ", PluginLoader.PluginsMetadata.StrJP())); PluginComponent.Create(); diff --git a/IPA.Loader/Loader/PluginLoader.cs b/IPA.Loader/Loader/PluginLoader.cs index f2f51735..99deaaa5 100644 --- a/IPA.Loader/Loader/PluginLoader.cs +++ b/IPA.Loader/Loader/PluginLoader.cs @@ -1,4 +1,5 @@ -using IPA.Loader.Features; +using IPA.Config; +using IPA.Loader.Features; using IPA.Logging; using IPA.Utilities; using Mono.Cecil; @@ -27,6 +28,7 @@ namespace IPA.Loader { internal static Task LoadTask() => Task.Factory.StartNew(() => { + YeetIfNeeded(); LoadMetadata(); Resolve(); @@ -131,6 +133,31 @@ namespace IPA.Loader public PluginMetadata Metadata { get; internal set; } = new PluginMetadata(); } + 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) + { + var oldPluginsName = Path.Combine(BeatSaber.InstallPath, $"Old {lastVer} Plugins"); + var newPluginsName = Path.Combine(BeatSaber.InstallPath, $"Old {gameVer} Plugins"); + + if (Directory.Exists(oldPluginsName)) + Directory.Delete(oldPluginsName, true); + Directory.Move(pluginDir, oldPluginsName); + if (Directory.Exists(newPluginsName)) + Directory.Move(newPluginsName, pluginDir); + else + Directory.CreateDirectory(pluginDir); + } + + SelfConfig.SelfConfigRef.Value.LastGameVersion = gameVer.ToString(); + SelfConfig.LoaderConfig.Store(SelfConfig.SelfConfigRef.Value); + } + internal static List PluginsMetadata = new List(); internal static List DisabledPlugins = new List(); diff --git a/IPA.Loader/Loader/PluginManager.cs b/IPA.Loader/Loader/PluginManager.cs index d5f37173..6f081c98 100644 --- a/IPA.Loader/Loader/PluginManager.cs +++ b/IPA.Loader/Loader/PluginManager.cs @@ -296,37 +296,6 @@ namespace IPA.Loader internal static IConfigProvider SelfConfigProvider { get; set; } internal static void Load() - { - 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) - { - var oldPluginsName = Path.Combine(BeatSaber.InstallPath, $"Old {lastVer} Plugins"); - var newPluginsName = Path.Combine(BeatSaber.InstallPath, $"Old {gameVer} Plugins"); - - ReleaseAll(); - - if (Directory.Exists(oldPluginsName)) - Directory.Delete(oldPluginsName, true); - Directory.Move(pluginDir, oldPluginsName); - if (Directory.Exists(newPluginsName)) - Directory.Move(newPluginsName, pluginDir); - else - Directory.CreateDirectory(pluginDir); - - LoadTask().Wait(); - } - - SelfConfig.SelfConfigRef.Value.LastGameVersion = gameVer.ToString(); - SelfConfig.LoaderConfig.Store(SelfConfig.SelfConfigRef.Value); - - LoadPlugins(); - } - - private static void LoadPlugins() { string pluginDirectory = BeatSaber.PluginsPath; diff --git a/IPA.Loader/Utilities/AlmostVersion.cs b/IPA.Loader/Utilities/AlmostVersion.cs index 49a066ac..88a4ce09 100644 --- a/IPA.Loader/Utilities/AlmostVersion.cs +++ b/IPA.Loader/Utilities/AlmostVersion.cs @@ -69,7 +69,7 @@ namespace IPA.Utilities throw new ArgumentNullException(nameof(copyMode)); if (!TryParseFrom(vertext, copyMode.StorageMode)) - throw new ArgumentException($"{nameof(vertext)} could not be stored the same way as {copyMode}!"); + TryParseFrom(vertext, StoredAs.String); // silently parse differently } private bool TryParseFrom(string str, StoredAs mode) diff --git a/Refs/UnityEngine.CoreModule.Net4.dll b/Refs/UnityEngine.CoreModule.Net4.dll index a54cfe5d19ed265d16ef940ea2b404129746e6b5..d54be65200936608505332954d9e60a1a807783d 100644 GIT binary patch delta 45 ucmZqJquKyOEsQNpEzB(}TUbNFn0Xl(+QY+GftU@5*@2j2dw3Y