Skip to content

Commit

Permalink
2.0.0.1: Fix compat with fluffy's work tab (and probably others)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Byass committed Feb 16, 2020
1 parent 02d9fc6 commit 2d188a0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion About/Manifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Manifest>
<identifier>BetterLoading</identifier>
<version>2.0.0.0</version>
<version>2.0.0.1</version>
<loadBefore>
<li>Core &gt;= 1.0</li>
</loadBefore>
Expand Down
28 changes: 24 additions & 4 deletions Source/Stage/InitialLoad/7StageRunStaticCctors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Action>;

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;
Expand All @@ -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<Action>) 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})");
Expand Down

0 comments on commit 2d188a0

Please sign in to comment.