diff --git a/src/Patches/ItemBase_Patch.cs b/src/Patches/ItemBase_Patch.cs new file mode 100644 index 0000000..0e3cb9b --- /dev/null +++ b/src/Patches/ItemBase_Patch.cs @@ -0,0 +1,35 @@ +using System.Linq; +using DV.CabControls; +using DV.CabControls.Spec; +using HarmonyLib; +using UnityEngine; + +namespace custom_item_mod.Patches; + +[HarmonyPatch(typeof(ItemBase))] +[HarmonyPatch(nameof(ItemBase.Awake))] +public class ItemBase_Patch +{ + private static void Prefix(ref ItemBase __instance) + { + var inventoryItemSpec = __instance.GetComponent(); + if (inventoryItemSpec is null) + { + Main.Error($"{nameof(ItemBase_Patch)}: inventoryItemSpec is null"); + return; + } + + //custom items only + if (!inventoryItemSpec.localizationKeyName.StartsWith(Main.MyModEntry.Info.Id)) + { + return; + } + + var itemComponent = __instance.GetComponent(); + if (itemComponent.colliderGameObjects.Length == 0) + { + itemComponent.colliderGameObjects = __instance.gameObject.GetComponentsInChildren() + .Select(collider => collider.gameObject).ToArray(); + } + } +} \ No newline at end of file diff --git a/src/Patches/LocalizationManager_Patch.cs b/src/Patches/LocalizationManager_Patch.cs index 090672c..abbbeca 100644 --- a/src/Patches/LocalizationManager_Patch.cs +++ b/src/Patches/LocalizationManager_Patch.cs @@ -9,7 +9,7 @@ public static class LocalizationManager_GetTranslation_Patch private static bool Prefix(ref string __result, string Term) { if (!Term.StartsWith(Main.MyModEntry.Info.Id)) { - return true; + return true; // execute original function } foreach (var item in ItemModsFinder.CustomItems)