Browse Source

Added early game version detection to code path

pull/32/head
Anairkoen Schno 5 years ago
parent
commit
14c25b1c98
7 changed files with 44 additions and 37 deletions
  1. +11
    -2
      IPA.Injector/GameVersionEarly.cs
  2. +4
    -2
      IPA.Injector/Injector.cs
  3. +28
    -1
      IPA.Loader/Loader/PluginLoader.cs
  4. +0
    -31
      IPA.Loader/Loader/PluginManager.cs
  5. +1
    -1
      IPA.Loader/Utilities/AlmostVersion.cs
  6. BIN
      Refs/Assembly-CSharp.dll
  7. BIN
      Refs/UnityEngine.CoreModule.Net4.dll

+ 11
- 2
IPA.Injector/GameVersionEarly.cs View File

@ -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();
}
}
}

+ 4
- 2
IPA.Injector/Injector.cs View File

@ -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();


+ 28
- 1
IPA.Loader/Loader/PluginLoader.cs View File

@ -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<PluginMetadata> PluginsMetadata = new List<PluginMetadata>();
internal static List<PluginMetadata> DisabledPlugins = new List<PluginMetadata>();


+ 0
- 31
IPA.Loader/Loader/PluginManager.cs View File

@ -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;


+ 1
- 1
IPA.Loader/Utilities/AlmostVersion.cs View File

@ -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)


BIN
Refs/Assembly-CSharp.dll View File


BIN
Refs/UnityEngine.CoreModule.Net4.dll View File


Loading…
Cancel
Save