0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-12 14:50:43 -05:00

Make GameObject hooks local to their respective plugin (#10)

* Make GameObject hooks local to their respective plugin

* Add DontDestoryOnLoad() just incase
This commit is contained in:
CJ-SPT 2024-12-04 04:59:53 -05:00 committed by GitHub
parent d19354ffef
commit 32f451db61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 11 additions and 32 deletions

View File

@ -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<MenuNotificationManager>();
HookObject.AddComponent<MenuNotificationManager>();
}
catch (Exception ex)
{

View File

@ -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<DumplyLibMono>();
SPTDebuggingPlugin.HookObject.AddComponent<DumplyLibMono>();
}
}

View File

@ -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
{

View File

@ -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<T>() where T : MonoBehaviour
{
return _object.GetOrAddComponent<T>();
}
}
}