fix loading to world without mods not triggering download

This commit is contained in:
zznty
2025-05-11 18:28:12 +07:00
parent 947fcde9ca
commit 7987664c11

View File

@@ -44,6 +44,22 @@ internal static class ModInjector
__state.Add(mod);
}
}
[HarmonyPatch(typeof(MyWorkshop), nameof(MyWorkshop.DownloadModsAsync))]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> DownloadModsAsyncTranspiler(IEnumerable<CodeInstruction> instructions)
{
var getCount = AccessTools.PropertyGetter(typeof(List<MyObjectBuilder_Checkpoint.ModItem>), nameof(List<MyObjectBuilder_Checkpoint.ModItem>.Count));
return new CodeMatcher(instructions)
.SearchForward(b => b.Calls(getCount))
.Advance(1)
.Insert(
CodeInstruction.LoadField(typeof(ModInjector), nameof(Mods)),
new(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(HashSet<ulong>), nameof(HashSet<ulong>.Count))),
new(OpCodes.Add)
)
.Instructions();
}
[HarmonyPatch(typeof(MyDefinitionManager), nameof(MyDefinitionManager.LoadData))]
[HarmonyPrefix]