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]