From 2d188a0bac54c242ba7dfa4221e13287ad2ec01b Mon Sep 17 00:00:00 2001 From: Sam Byass Date: Sun, 16 Feb 2020 19:59:57 +0000 Subject: [PATCH] 2.0.0.1: Fix compat with fluffy's work tab (and probably others) --- About/Manifest.xml | 2 +- .../InitialLoad/7StageRunStaticCctors.cs | 28 ++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/About/Manifest.xml b/About/Manifest.xml index 85325ec..40b2224 100644 --- a/About/Manifest.xml +++ b/About/Manifest.xml @@ -1,7 +1,7 @@ BetterLoading - 2.0.0.0 + 2.0.0.1
  • Core >= 1.0
  • diff --git a/Source/Stage/InitialLoad/7StageRunStaticCctors.cs b/Source/Stage/InitialLoad/7StageRunStaticCctors.cs index d88a594..d534a46 100644 --- a/Source/Stage/InitialLoad/7StageRunStaticCctors.cs +++ b/Source/Stage/InitialLoad/7StageRunStaticCctors.cs @@ -74,9 +74,29 @@ public static IEnumerator StaticConstructAll() Application.runInBackground = Prefs.RunInBackground; - Log.Message("Finished calling static constructors at " + DateTime.Now.ToLongTimeString() + ". AND I didn't make the game freeze. Take that, Tynan."); + Log.Message("[BetterLoading] Finished calling static constructors at " + DateTime.Now.ToLongTimeString() + ". AND I didn't make the game freeze. Take that, Tynan."); var field = typeof(LongEventHandler).GetField("toExecuteWhenFinished", BindingFlags.NonPublic | BindingFlags.Static); - field.SetValue(null, _queue); + + var existing = field.GetValue(null) as List; + + Log.Message($"[BetterLoading] Restoring original job queue of {_queue.Count} item/s and merging with any just added (looking at you, Fluffy) ({existing.Count} entries have been added)."); + if (existing.Count > 0 && _queue.Count == 0) + { + //This is probably usually the case + //Don't touch anything + } else if (existing.Count == 0 && _queue.Count > 0) + { + //Load cached stuff from queue + field.SetValue(null, _queue); + } + else + { + //Need to merge - queue first + var result = _queue; + result.AddRange(existing); + field.SetValue(null, result); + } + _queue = null; StaticConstructorOnStartupUtility.coreStaticAssetsLoaded = true; @@ -95,10 +115,10 @@ public static bool PreCallAll() Log.Message("[BetterLoading] Overriding LongEventHandler's toExecuteWhenFinished"); var field = typeof(LongEventHandler).GetField("toExecuteWhenFinished", BindingFlags.NonPublic | BindingFlags.Static); var result = (List) field.GetValue(null); - + Log.Message($"[BetterLoading] Got list of pending actions: {result}. Removing up to and including the static constructor call..."); - + var staticCallIdx = result.FindIndex(i => i.Method.DeclaringType?.Name == "PlayDataLoader" && i.Method.Name.Contains("m__2")); Log.Message($"[BetterLoading] (Which is at index {staticCallIdx} of {result.Count})");