From 65400fc9b11fa75fa64fb663c1cca8bc43cdf45e Mon Sep 17 00:00:00 2001 From: t0stiman <18124323+t0stiman@users.noreply.github.com> Date: Wed, 13 Mar 2024 20:06:57 +0100 Subject: [PATCH] Fix items can't be picked up #4 --- src/Patches/ItemBase_Patch.cs | 35 ++++++++++++++++++++++++ src/Patches/LocalizationManager_Patch.cs | 2 +- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/Patches/ItemBase_Patch.cs 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)