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; + } + } }