Skip to content

Commit

Permalink
1.5 Support. Unfortunately not backwards compat.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamboyCoding committed Mar 19, 2024
1 parent 283c647 commit 4fd301c
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 9 deletions.
Binary file added 1.5/Assemblies/BetterLoading.dll
Binary file not shown.
Binary file added 1.5/Assemblies/Tomlet.dll
Binary file not shown.
1 change: 1 addition & 0 deletions About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<li>1.2</li>
<li>1.3</li>
<li>1.4</li>
<li>1.5</li>
</supportedVersions>
<loadBefore>
<li>Ludeon.RimWorld</li>
Expand Down
4 changes: 4 additions & 0 deletions LoadFolders.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@
<li>1.4</li>
<li></li>
</v1.4>
<v1.5>
<li>1.5</li>
<li></li>
</v1.5>
</loadFolders>
8 changes: 4 additions & 4 deletions Source/BetterLoading.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<Optimize>true</Optimize>
<OutDir>..\1.4\Assemblies\</OutDir>
<OutputPath>..\1.4\Assemblies\</OutputPath>
<OutDir>..\1.5\Assemblies\</OutDir>
<OutputPath>..\1.5\Assemblies\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutDir>..\1.4\Assemblies\</OutDir>
<OutputPath>..\1.4\Assemblies\</OutputPath>
<OutDir>..\1.5\Assemblies\</OutDir>
<OutputPath>..\1.5\Assemblies\</OutputPath>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp, Culture=neutral, PublicKeyToken=null">
Expand Down
13 changes: 11 additions & 2 deletions Source/Stage/InitialLoad/7StageRunPostLoadPreFinalizeCallbacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,16 @@ public override string GetStageName()
if (_currentAction == null)
return "Waiting for tasks to start being processed...";

if(_currentAction is { Target: ModContentPack mcp, Method.Name: nameof(ModContentPack.ReloadContent) + "Int" })
return $"Reloading content for {mcp.Name}";
if(_currentAction.Method is {} method && method.DeclaringType?.DeclaringType == typeof(ModContentPack))
{
//On 1.4 this Action was directly just a call to ModContentPack.ReloadContentInt.
//Now on 1.5 it's an anon method wrapping that call due to a hotReload bool being added.
//Let's try to grab the mod if we can
var anonTypeInst = _currentAction.Target;
//Compiler generated field `<>4__this` is the ModContentPack itself.
if(anonTypeInst.GetType()?.GetField("<>4__this", AccessTools.all) is {} theField && theField.GetValue(anonTypeInst) is ModContentPack mcp)
return $"Reloading content for {mcp.Name}";
}

var methodDeclaringType = _currentAction.Method.DeclaringType?.FullName ?? "<unknown anonymous method>";
var methodName = _currentAction.Method?.Name ?? "<unknown method>";
Expand Down Expand Up @@ -104,6 +112,7 @@ public static bool PreExecToExecWhenFinished(List<Action> ___toExecuteWhenFinish
2 => "b__4_2",
3 => "b__4_3",
4 => "b__4_5",
5 => "b__4_4",
_ => throw new ArgumentOutOfRangeException()
};

Expand Down
4 changes: 2 additions & 2 deletions Source/Stage/InitialLoad/8StageRunStaticCctors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ public override bool IsCompleted()

public override void DoPatching(Harmony instance)
{
if (VersionControl.CurrentMinor == 4)
if (VersionControl.CurrentMinor is 4 or 5)
{
//1.4, we need to patch the entire <DoPlayLoad>b__4_5 method and make it not run, instead of just CallAll, because there's 2 other method calls in that anon method which we don't wanna do until after static constructors
var anonType = typeof(PlayDataLoader).GetNestedTypes(AccessTools.all).First(t => t.Name.Contains("<>"));
var method = AccessTools.Method(anonType, "<DoPlayLoad>b__4_5");
var method = AccessTools.Method(anonType, VersionControl.CurrentMinor == 4 ? "<DoPlayLoad>b__4_5" : "<DoPlayLoad>b__4_4");
instance.Patch(method, new HarmonyMethod(typeof(StageRunStaticCctors), nameof(PreCallAll)));
}
else
Expand Down
2 changes: 1 addition & 1 deletion Source/Stage/SaveLoad/4FinalizeMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public override void DoPatching(Harmony instance)

//SpawnThings
instance.Patch(
AccessTools.Method(typeof(GenSpawn), nameof(GenSpawn.Spawn), new[] {typeof(Thing), typeof(IntVec3), typeof(Map), typeof(Rot4), typeof(WipeMode), typeof(bool)}),
AccessTools.Method(typeof(GenSpawn), nameof(GenSpawn.Spawn), new[] {typeof(Thing), typeof(IntVec3), typeof(Map), typeof(Rot4), typeof(WipeMode), typeof(bool), typeof(bool)}),
new(typeof(FinalizeMap), nameof(OnThingAboutToSpawn))
);

Expand Down

0 comments on commit 4fd301c

Please sign in to comment.