diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..4eb3024 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "omnisharp.useModernNet": false +} \ No newline at end of file diff --git a/Assets/BuildProfile.asset b/Assets/BuildProfile.asset index 922ddad..0ad2367 100644 --- a/Assets/BuildProfile.asset +++ b/Assets/BuildProfile.asset @@ -13,7 +13,7 @@ MonoBehaviour: m_EditorClassIdentifier: PackageName: TNH_Quality_of_Life_Improvements Author: muskit - Version: 1.2.4 + Version: 1.2.5 Icon: {fileID: 2800000, guid: af542f3f6d6914f4e96d0326e8b296cc, type: 3} ReadMe: {fileID: 102900000, guid: efa2d6091ed77bd4b879a74bd81d6cbc, type: 3} WebsiteURL: https://github.com/muskit/TNH-Quality-of-Life-Improvements diff --git a/Assets/MeatKit/MeatKitPlugin.cs b/Assets/MeatKit/MeatKitPlugin.cs index 7d48654..919d2d7 100644 --- a/Assets/MeatKit/MeatKitPlugin.cs +++ b/Assets/MeatKit/MeatKitPlugin.cs @@ -83,6 +83,15 @@ public static AssetBundle bundle; private Harmony harmony; + // Could soft-lock if we're not in TNH! + public static IEnumerator WaitForTNHInit() + { + while (InPlay.tnhManager == null || FindObjectOfType() == null) + { + yield return null; + } + } + private void SceneChanged(Scene from, Scene to) { playerCamera = GameObject.FindGameObjectWithTag("MainCamera"); @@ -274,7 +283,7 @@ public static AssetBundle bundle; // stick stats to hand after game over if (cfgShowHolds.Value || cfgShowTokens.Value) - InPlay.Patch(harmony); + TNHInfo.Patch(harmony); // show numerical representation of shop values if (cfgShowNumbersAtShop.Value) @@ -284,7 +293,9 @@ public static AssetBundle bundle; // player tokens ShopTokenPatch.Patch(harmony); } - } + + Logger.LogInfo("Successfully ran patches!"); + } private void ToggleHPVisibility(object sender, ButtonClickEventArgs args) { diff --git a/Assets/_Scripts/InPlay.cs b/Assets/_Scripts/InPlay.cs index 3acec19..af5b471 100644 --- a/Assets/_Scripts/InPlay.cs +++ b/Assets/_Scripts/InPlay.cs @@ -1,7 +1,6 @@ using HarmonyLib; using System.Reflection; using UnityEngine; -using UnityEngine.UI; using FistVR; namespace TNHQoLImprovements @@ -13,9 +12,6 @@ namespace TNHQoLImprovements { public static TNH_Manager tnhManager; - private static Transform[] hands; - private static GameObject tnhInfo; - public static bool InHold() { if (tnhManager == null) @@ -24,39 +20,20 @@ namespace TNHQoLImprovements return tnhManager.Phase == TNH_Phase.Hold; } - // Bring extra info into game over - public static void Patch(Harmony harmony) - { - var original = typeof(TNH_Manager).GetMethod("SetPhase", BindingFlags.NonPublic | BindingFlags.Instance); - var patch = typeof(InPlay).GetMethod("MoveStatsToController", BindingFlags.NonPublic | BindingFlags.Static); - harmony.Patch(original, postfix: new HarmonyMethod(patch)); - } - - private static void MoveStatsToController(TNH_Phase p) - { - if (tnhManager == null) - return; - - if (p == TNH_Phase.Dead || p == TNH_Phase.Completed) - { - int handSide = tnhManager.RadarHand == TNH_RadarHand.Left ? 0 : 1; - - tnhInfo.transform.SetParent(hands[handSide], false); - tnhInfo.GetComponent().GameOverPos(); - } - } - void Start() { tnhManager = FindObjectOfType(); - var rig = Object.FindObjectOfType().transform; - hands = new Transform[] { - rig.transform.GetChild(1), rig.transform.GetChild(0) - }; + TNHInfo.instance = Instantiate(MeatKitPlugin.bundle.LoadAsset("TNHInfo"), + FindObjectOfType().transform.GetChild(3)) + .GetComponent(); + TNHInfo.instance.transform.localScale = new Vector3(0.002f, 0.002f, 0.002f); + } - tnhInfo = Instantiate(MeatKitPlugin.bundle.LoadAsset("TNHInfo"), FindObjectOfType().transform.GetChild(3)); - tnhInfo.transform.localScale = new Vector3(0.002f, 0.002f, 0.002f); + void OnDestroy() + { + // Destroy statics + tnhManager = null; } } } \ No newline at end of file diff --git a/Assets/_Scripts/TNHInfo.cs b/Assets/_Scripts/TNHInfo.cs index 45f07a0..f09deb2 100644 --- a/Assets/_Scripts/TNHInfo.cs +++ b/Assets/_Scripts/TNHInfo.cs @@ -1,4 +1,5 @@ using HarmonyLib; +using System.Reflection; using UnityEngine; using FistVR; @@ -6,23 +7,55 @@ namespace TNHQoLImprovements { class TNHInfo : MonoBehaviour { - private GameObject holdCounter; + public static TNHInfo instance; + + public Transform[] hands; + private GameObject holdCounter; private GameObject tokenCounter; private GameObject waveCounter; - public void Start() + // Bring extra info into game over + public static void Patch(Harmony harmony) { - if (MeatKitPlugin.cfgShowHolds.Value) + var original = typeof(TNH_Manager).GetMethod("SetPhase", BindingFlags.NonPublic | BindingFlags.Instance); + var patch = typeof(TNHInfo).GetMethod("MoveStatsToController", BindingFlags.NonPublic | BindingFlags.Static); + harmony.Patch(original, postfix: new HarmonyMethod(patch)); + } + + private static void MoveStatsToController(TNH_Phase p) + { + if (InPlay.tnhManager == null) + return; + + if (p == TNH_Phase.Dead || p == TNH_Phase.Completed) + { + int handSide = InPlay.tnhManager.RadarHand == TNH_RadarHand.Left ? 0 : 1; + + instance.transform.SetParent(instance.hands[handSide], false); + instance.GetComponent().GameOverPos(); + } + } + + void Start() + { + instance = this; + + if (MeatKitPlugin.cfgShowHolds.Value) holdCounter = Instantiate(MeatKitPlugin.bundle.LoadAsset("HoldCounter"), transform); if (MeatKitPlugin.cfgShowTokens.Value) tokenCounter = Instantiate(MeatKitPlugin.bundle.LoadAsset("TokenCounter"), transform); if (MeatKitPlugin.cfgShowWaves.Value) waveCounter = Instantiate(MeatKitPlugin.bundle.LoadAsset("WaveCounter"), transform); + var rig = Object.FindObjectOfType().transform; + hands = new Transform[] { + rig.transform.GetChild(1), rig.transform.GetChild(0) + }; + PlayPos(); } - public void PlayPos() + private void PlayPos() { transform.localPosition = new Vector3(0, 0, -1.2f); if (holdCounter != null) @@ -35,7 +68,7 @@ namespace TNHQoLImprovements waveCounter.transform.localPosition = new Vector3(333, 0, 0); } - public void GameOverPos() + private void GameOverPos() { transform.localScale = new Vector3(.0002f, .0002f, .0002f); transform.localPosition = Vector3.zero; @@ -60,7 +93,7 @@ namespace TNHQoLImprovements } } - public void Update() + private void Update() { // game over area; do not update anything else if (InPlay.tnhManager.Phase == TNH_Phase.Dead || InPlay.tnhManager.Phase == TNH_Phase.Completed) @@ -100,5 +133,10 @@ namespace TNHQoLImprovements waveCounter.SetActive(false); } } + + void OnDestroy() + { + instance = null; + } } }