From 32f451db61ceb07b1dd5c0f8b1a887c9e5555bc0 Mon Sep 17 00:00:00 2001 From: CJ-SPT <161484149+CJ-SPT@users.noreply.github.com> Date: Wed, 4 Dec 2024 04:59:53 -0500 Subject: [PATCH] Make GameObject hooks local to their respective plugin (#10) * Make GameObject hooks local to their respective plugin * Add DontDestoryOnLoad() just incase --- project/SPT.Custom/SPTCustomPlugin.cs | 8 ++++-- .../SPT.Debugging/Patches/DumpyLibPatch.cs | 2 +- project/SPT.Debugging/SPTDebuggingPlugin.cs | 5 ++++ project/SPT.Reflection/Utils/HookObject.cs | 28 ------------------- 4 files changed, 11 insertions(+), 32 deletions(-) delete mode 100644 project/SPT.Reflection/Utils/HookObject.cs diff --git a/project/SPT.Custom/SPTCustomPlugin.cs b/project/SPT.Custom/SPTCustomPlugin.cs index 0d6887f..7dc8df0 100644 --- a/project/SPT.Custom/SPTCustomPlugin.cs +++ b/project/SPT.Custom/SPTCustomPlugin.cs @@ -2,19 +2,21 @@ using SPT.Common; using SPT.Custom.Patches; using SPT.Custom.Utils; -using SPT.Reflection.Utils; using BepInEx; using UnityEngine; -using BepInEx.Logging; namespace SPT.Custom { [BepInPlugin("com.SPT.custom", "SPT.Custom", SPTPluginInfo.PLUGIN_VERSION)] public class SPTCustomPlugin : BaseUnityPlugin { + internal static GameObject HookObject; + public void Awake() { Logger.LogInfo("Loading: SPT.Custom"); + HookObject = new GameObject(); + DontDestroyOnLoad(HookObject); try { @@ -46,7 +48,7 @@ namespace SPT.Custom new AllowAirdropsInPvEPatch().Enable(); new MemoryCollectionPatch().Enable(); - HookObject.AddOrGetComponent(); + HookObject.AddComponent(); } catch (Exception ex) { diff --git a/project/SPT.Debugging/Patches/DumpyLibPatch.cs b/project/SPT.Debugging/Patches/DumpyLibPatch.cs index baf5895..e5f8682 100644 --- a/project/SPT.Debugging/Patches/DumpyLibPatch.cs +++ b/project/SPT.Debugging/Patches/DumpyLibPatch.cs @@ -25,7 +25,7 @@ public class DumpyLibPatch : ModulePatch public static void PatchPostfix(MenuScreen __instance) { // attach Monobehaviour so we can interact with UE - HookObject._object.AddComponent(); + SPTDebuggingPlugin.HookObject.AddComponent(); } } diff --git a/project/SPT.Debugging/SPTDebuggingPlugin.cs b/project/SPT.Debugging/SPTDebuggingPlugin.cs index 4433a26..19ecd6d 100644 --- a/project/SPT.Debugging/SPTDebuggingPlugin.cs +++ b/project/SPT.Debugging/SPTDebuggingPlugin.cs @@ -5,17 +5,22 @@ using SPT.Common.Utils; using SPT.Debugging.Patches; using BepInEx; using SPT.Custom.Models; +using UnityEngine; namespace SPT.Debugging { [BepInPlugin("com.SPT.debugging", "SPT.Debugging", SPTPluginInfo.PLUGIN_VERSION)] public class SPTDebuggingPlugin : BaseUnityPlugin { + internal static GameObject HookObject; + public static LoggingLevelResponse logLevel; public void Awake() { Logger.LogInfo("Loading: SPT.Debugging"); + HookObject = new GameObject(); + DontDestroyOnLoad(HookObject); try { diff --git a/project/SPT.Reflection/Utils/HookObject.cs b/project/SPT.Reflection/Utils/HookObject.cs deleted file mode 100644 index 6fc12a4..0000000 --- a/project/SPT.Reflection/Utils/HookObject.cs +++ /dev/null @@ -1,28 +0,0 @@ -using UnityEngine; - -namespace SPT.Reflection.Utils -{ - public static class HookObject - { - public static GameObject _object - { - get - { - GameObject result = GameObject.Find("SPT.Hook"); - - if (result == null) - { - result = new GameObject("SPT.Hook"); - Object.DontDestroyOnLoad(result); - } - - return result; - } - } - - public static T AddOrGetComponent() where T : MonoBehaviour - { - return _object.GetOrAddComponent(); - } - } -}