Skip to content

Commit

Permalink
Fix various compat issues + hugslib bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Byass committed Feb 27, 2020
1 parent b7ee372 commit 0e27689
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ModMetaData>
<name>BetterLoading</name>
<author>Samboy063</author>
<packageId>me.samboycoding.betterloading</packageId>
<packageId>me.samboycoding.betterloading.dev</packageId>
<url></url>
<supportedVersions>
<li>1.0</li>
Expand Down
2 changes: 1 addition & 1 deletion Source/BetterLoading.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<Optimize>true</Optimize>
<OutputPath>..\1.1\Assemblies\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
Expand Down
21 changes: 18 additions & 3 deletions Source/Stage/InitialLoad/7StageRunPostLoadPreFinalizeCallbacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Threading;
using HarmonyLib;
using UnityEngine;
using Verse;

namespace BetterLoading.Stage.InitialLoad
Expand Down Expand Up @@ -50,7 +51,7 @@ public override int GetCurrentProgress()

public override int GetMaximumProgress()
{
return _numTasksToRun - 1;
return _numTasksToRun;
}

public override void DoPatching(Harmony instance)
Expand All @@ -71,9 +72,21 @@ public static bool PreExecToExecWhenFinished(ref List<Action> ___toExecuteWhenFi

_hasBeenCalled = true;

var targetTypeName = typeof(PlayDataLoader).FullName;
var targetTypeName = typeof(PlayDataLoader).FullName ?? throw new Exception("WTF where has playdataloader gone.");

var indexOfStaticCtor = ___toExecuteWhenFinished.FindIndex(task => task.Method.DeclaringType?.FullName == targetTypeName && task.Method.Name.Contains("m__2"));
var last = ___toExecuteWhenFinished.Skip(2900).Take(int.MaxValue).Select(i => i.Method.DeclaringType).ToList();

Debug.Log($"BL Debug: last few task defining types: {last.ToStringSafeEnumerable()}");

Debug.Log($"BL Debug: Looking for actions defined in type beginning with {targetTypeName}");

var declaredInPDL = ___toExecuteWhenFinished.Where(task => task.Method.DeclaringType?.FullName?.StartsWith(targetTypeName) == true).ToList();

Debug.Log($"BL Debug: types declared in PDL: {declaredInPDL.Select(a => a.Method).ToStringSafeEnumerable()}");

var indexOfStaticCtor = ___toExecuteWhenFinished.IndexOf(declaredInPDL.Find(task => task.Method.Name.Contains("b__4_2"))); //The anon class that calls static ctors.

Debug.Log($"BL Debug: Identified target index as {indexOfStaticCtor} which maps to the action-method {___toExecuteWhenFinished[indexOfStaticCtor].Method.FullDescription()}");

//Ones to execute now are the ones before the ctors
var toExecute = ___toExecuteWhenFinished.Take(indexOfStaticCtor).ToList();
Expand All @@ -85,6 +98,8 @@ public static bool PreExecToExecWhenFinished(ref List<Action> ___toExecuteWhenFi

//To execute after are the ones after the ctors - if there are any.
var remainder = ___toExecuteWhenFinished.Skip(indexOfStaticCtor + 1).Take(int.MaxValue).ToList();

Debug.Log($"BL Debug: This leaves {toExecute.Count} tasks to execute now, that one to execute in the middle, and then {remainder.Count} to execute after static ctors");

LongEventHandlerMirror.ToExecuteWhenFinished = remainder;

Expand Down

0 comments on commit 0e27689

Please sign in to comment.