Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 34 additions & 19 deletions S1API/Internal/Patches/ProductPackagingContentPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -127,4 +108,38 @@ private static bool GetIconPrefix(
return false;
}
}

/// <summary>
/// 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 <c>ProductIconManager.GenerateIcons</c>; 0.4.7f11 replaced the batch with
/// on-demand <c>GenerateRuntimeIcons(productID)</c>, where the packaging-icon prefix generates custom icons
/// directly. Kept apart from <see cref="ProductPackagingContentPatches"/> so a missing batch method skips only
/// these two patches instead of failing that whole class.
/// </summary>
[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;
}
}
}
Loading