From 8c22c42e2a3703320fc6af58424d0109957cbb84 Mon Sep 17 00:00:00 2001 From: r-melvin <40235254+r-melvin@users.noreply.github.com> Date: Wed, 7 Oct 2026 13:41:02 +0100 Subject: [PATCH] fix(products): keep packaging-content patches working on 0.4.7f11 f11 replaced ProductIconManager.GenerateIcons (one batch at load) with on-demand GenerateRuntimeIcons(productID). The missing target made Harmony reject the whole ProductPackagingContentPatches class, so ApplyVisuals, GeneratePackagingIcon and GetIcon were unpatched too. The two batch hooks move to their own class, applied only when GenerateIcons exists; on f11 the packaging-icon prefix generates custom icons directly. Co-Authored-By: Claude Opus 5.5 --- .../Patches/ProductPackagingContentPatches.cs | 53 ++++++++++++------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/S1API/Internal/Patches/ProductPackagingContentPatches.cs b/S1API/Internal/Patches/ProductPackagingContentPatches.cs index 1f3d1d5c..ec7d0dbf 100644 --- a/S1API/Internal/Patches/ProductPackagingContentPatches.cs +++ b/S1API/Internal/Patches/ProductPackagingContentPatches.cs @@ -35,25 +35,6 @@ private static bool ApplyVisualsPrefix( itemInstance); } - [HarmonyPatch( - typeof(S1Product.ProductIconManager), - nameof(S1Product.ProductIconManager.GenerateIcons))] - [HarmonyPrefix] - private static void GenerateIconsPrefix() - { - ProductPackagingContentRuntime.BeginNativeIconBatch(); - } - - [HarmonyPatch( - typeof(S1Product.ProductIconManager), - nameof(S1Product.ProductIconManager.GenerateIcons))] - [HarmonyFinalizer] - private static Exception? GenerateIconsFinalizer(Exception? __exception) - { - ProductPackagingContentRuntime.EndNativeIconBatch(); - return __exception; - } - [HarmonyPatch( typeof(S1DevUtilities.IconGenerator), nameof(S1DevUtilities.IconGenerator.GeneratePackagingIcon), @@ -127,4 +108,38 @@ private static bool GetIconPrefix( return false; } } + + /// + /// INTERNAL: Defers custom packaging icons while the game generates every product icon in one batch at load. + /// Game builds up to 0.4.7f10 have ProductIconManager.GenerateIcons; 0.4.7f11 replaced the batch with + /// on-demand GenerateRuntimeIcons(productID), where the packaging-icon prefix generates custom icons + /// directly. Kept apart from so a missing batch method skips only + /// these two patches instead of failing that whole class. + /// + [HarmonyPatch] + internal static class ProductIconBatchPatches + { + // Plain reflection: AccessTools.Method logs a warning for every missing method. + private static System.Reflection.MethodBase? Batch() => + Array.Find( + typeof(S1Product.ProductIconManager).GetMethods(AccessTools.all), + method => method.Name == "GenerateIcons"); + + private static bool Prepare() => Batch() != null; + + private static System.Reflection.MethodBase? TargetMethod() => Batch(); + + [HarmonyPrefix] + private static void Prefix() + { + ProductPackagingContentRuntime.BeginNativeIconBatch(); + } + + [HarmonyFinalizer] + private static Exception? Finalizer(Exception? __exception) + { + ProductPackagingContentRuntime.EndNativeIconBatch(); + return __exception; + } + } }