From 7987664c11ecb2d3f0a7999c2e39e0eba5634c19 Mon Sep 17 00:00:00 2001 From: zznty <94796179+zznty@users.noreply.github.com> Date: Sun, 11 May 2025 18:28:12 +0700 Subject: [PATCH] fix loading to world without mods not triggering download --- Plugin.ClientModLoader/ModInjector.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Plugin.ClientModLoader/ModInjector.cs b/Plugin.ClientModLoader/ModInjector.cs index 7a12da6..ea742c1 100644 --- a/Plugin.ClientModLoader/ModInjector.cs +++ b/Plugin.ClientModLoader/ModInjector.cs @@ -44,6 +44,22 @@ internal static class ModInjector __state.Add(mod); } } + + [HarmonyPatch(typeof(MyWorkshop), nameof(MyWorkshop.DownloadModsAsync))] + [HarmonyTranspiler] + private static IEnumerable DownloadModsAsyncTranspiler(IEnumerable instructions) + { + var getCount = AccessTools.PropertyGetter(typeof(List), nameof(List.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), nameof(HashSet.Count))), + new(OpCodes.Add) + ) + .Instructions(); + } [HarmonyPatch(typeof(MyDefinitionManager), nameof(MyDefinitionManager.LoadData))] [HarmonyPrefix]