diff --git a/HugMod/HugModApi.cs b/HugMod/HugModApi.cs index a22d903..f587d43 100644 --- a/HugMod/HugModApi.cs +++ b/HugMod/HugModApi.cs @@ -1,12 +1,16 @@ using OWML.Common; using System; +using System.Linq; using UnityEngine; namespace HugMod { public class HugModApi : IHugModApi { - public void AddHugComponent(GameObject hugObject, bool initialiseImmediately) + public GameObject[] GetAllHuggables() => Resources.FindObjectsOfTypeAll().Select(obj => obj.gameObject).ToArray(); + + + public void AddHugComponent(GameObject hugObject, bool initialiseImmediately) { if (hugObject.GetComponent() == null) { diff --git a/HugMod/HugPatches.cs b/HugMod/HugPatches.cs index c16b822..a17baad 100644 --- a/HugMod/HugPatches.cs +++ b/HugMod/HugPatches.cs @@ -19,12 +19,12 @@ public class HugPatches [HarmonyPatch(typeof(PlayerCharacterController), nameof(PlayerCharacterController.UpdateMovement))] public static IEnumerable PlayerCharacterController_UpdateMovement_Transpiler(IEnumerable instructions) { - var matcher = new CodeMatcher(instructions).MatchForward(true, + var matcher = new CodeMatcher(instructions).MatchForward(true, //matching to the part where it accepts player input new CodeMatch(OpCodes.Call, AccessTools.Method(typeof(OWInput), nameof(OWInput.GetAxisValue), new Type[] { typeof(IInputCommands), typeof(InputMode) })), new CodeMatch(OpCodes.Stloc_0) ); - matcher.Insert( + matcher.Insert( //sneakily swapping out the value on top of the stack before it gets stored Transpilers.EmitDelegate>((input) => { if (WalkingTowardsHugTarget) return new Vector2(0, WalkingTowardsHugSpeed); diff --git a/HugMod/IHugModApi.cs b/HugMod/IHugModApi.cs index be8b5d8..83a6774 100644 --- a/HugMod/IHugModApi.cs +++ b/HugMod/IHugModApi.cs @@ -5,6 +5,14 @@ namespace HugMod { public interface IHugModApi { + /// + /// Returns an array of all GameObjects that have a hug script attached
+ /// This may falsely return null if used directly on scene load, so it's good to wait a frame first + ///
+ /// The array of GameObjects, including deactivated ones + public GameObject[] GetAllHuggables(); + + /// /// Makes a suitable GameObject huggable /// diff --git a/HugMod/Targets/TargetManager.cs b/HugMod/Targets/TargetManager.cs index 76e430a..9146863 100644 --- a/HugMod/Targets/TargetManager.cs +++ b/HugMod/Targets/TargetManager.cs @@ -90,8 +90,8 @@ private static void HugReenable(Target target) //prevent loss of huggability aft { var hugComponent = target.GetHugComponent() ?? AddHugComponent(target); if (hugComponent == null) return; - var receiver = hugComponent.gameObject.GetComponentInChildren(); - if (receiver._owCollider._active) return; //this is meant to reenable the receiver without reenabling dialogue, so don't do the thing if everything is still enabled + var receiver = hugComponent.HugReceiver; + if (receiver == null || receiver._owCollider._active) return; //this is meant to reenable the receiver without reenabling dialogue, so don't do the thing if everything is still enabled receiver.OnPressInteract -= hugComponent.gameObject.GetComponentInChildren().OnPressInteract; receiver.OnGainFocus += () => { Locator.GetPromptManager().RemoveScreenPrompt(receiver._screenPrompt); }; receiver.EnableInteraction(); diff --git a/HugMod/manifest.json b/HugMod/manifest.json index 67b793a..5fe507f 100644 --- a/HugMod/manifest.json +++ b/HugMod/manifest.json @@ -4,7 +4,7 @@ "author": "VioVayo", "name": "Hug Mod", "uniqueName": "VioVayo.HugMod", - "version": "1.0.3", + "version": "1.1.0", "owmlVersion": "2.9.0", "dependencies": [], "pathsToPreserve": [ "settings.json" ]