diff --git a/Assets/MeatKit/MeatKitPlugin.cs b/Assets/MeatKit/MeatKitPlugin.cs index 919d2d7..ac79819 100644 --- a/Assets/MeatKit/MeatKitPlugin.cs +++ b/Assets/MeatKit/MeatKitPlugin.cs @@ -68,7 +68,7 @@ public static AssetBundle bundle; public static ConfigEntry cfgHealthCrystalIndicator; // Take and Hold modifications - private static InPlay instance; + private static InPlay playInstance; // Searching for old leaderboards player count mod to disable private float lpcSearchTime; @@ -83,21 +83,40 @@ 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) { + StartCoroutine("SceneChangedCoroutine"); + } + + private IEnumerator SceneChangedCoroutine() + { + Destroy(playInstance); + for (int i = 0; i < 11; ++i) + { + // TNH patches + if (GameObject.Find("_GameManager") != null || FindObjectOfType() != null) + { + Logger.LogInfo("We are in a TNH game!"); + playInstance = new GameObject().AddComponent(); + playerCamera = GameObject.FindGameObjectWithTag("MainCamera"); + break; + } + else + { + Logger.LogInfo(String.Format("Couldn't find a TNH game. Trying again...({0}/10)", i)); + yield return new WaitForEndOfFrame(); + } + } + + if (playInstance == null) + { + Logger.LogInfo("We are NOT in a TNH game!"); + } + + // setup non-TNH specific static objects + // running AFTER searching for TNH_Manager ensures we have everything initialized playerCamera = GameObject.FindGameObjectWithTag("MainCamera"); hpDisplay = FindObjectOfType(); - GetFonts(); - // apply health counter tweaks globally if (hpDisplay != null) { @@ -112,34 +131,7 @@ public static AssetBundle bundle; { WristMenuAPI.Buttons.Remove(wmbHPToggle); } - - StartCoroutine("TryTNH"); - } - - private IEnumerator TryTNH() - { - for (int i = 0; i < 11; ++i) - { - // TNH patches - if (GameObject.Find("_GameManager") != null || FindObjectOfType() != null) - { - Logger.LogInfo("We are in a TNH game!"); - instance = new GameObject().AddComponent(); - break; - } - else - { - Logger.LogInfo(String.Format("Couldn't find a TNH game. Trying again...({0}/10)", i)); - yield return new WaitForEndOfFrame(); - } - } - - // destroy self only if we are FOR SURE not in a TNH game - if (GameObject.Find("_GameManager") == null || FindObjectOfType() == null) - { - Logger.LogInfo("We are NOT in a TNH game!"); - Destroy(instance); - } + GetFonts(); } // called on scene change, find fonts from game if they're not set diff --git a/Assets/_Scripts/Extensions.meta b/Assets/_Scripts/Extensions.meta new file mode 100644 index 0000000..074387f --- /dev/null +++ b/Assets/_Scripts/Extensions.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: a7e0925cb0a2d20488bcb5d230cf74f7 +folderAsset: yes +timeCreated: 1690792321 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/_Scripts/_RectTransformExtensions.cs b/Assets/_Scripts/Extensions/RectTransformExtensions.cs similarity index 100% rename from Assets/_Scripts/_RectTransformExtensions.cs rename to Assets/_Scripts/Extensions/RectTransformExtensions.cs diff --git a/Assets/_Scripts/_RectTransformExtensions.cs.meta b/Assets/_Scripts/Extensions/RectTransformExtensions.cs.meta similarity index 100% rename from Assets/_Scripts/_RectTransformExtensions.cs.meta rename to Assets/_Scripts/Extensions/RectTransformExtensions.cs.meta diff --git a/Assets/_Scripts/HPHideWhenAiming.cs b/Assets/_Scripts/HPHideWhenAiming.cs index 0ceb499..8151266 100644 --- a/Assets/_Scripts/HPHideWhenAiming.cs +++ b/Assets/_Scripts/HPHideWhenAiming.cs @@ -1,11 +1,10 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; +using UnityEngine; using UnityEngine.UI; using FistVR; // To be attached to FVRHealthBar object -public class HPHideWhenAiming : MonoBehaviour { +public class HPHideWhenAiming : MonoBehaviour +{ CanvasGroup canvasGroup; GameObject gObjHUD; @@ -25,7 +24,8 @@ public class HPHideWhenAiming : MonoBehaviour { //LineRenderer colliderRenderer; // Use this for initialization - void Start() { + void Start() + { gObjHUD = transform.GetChild(0).gameObject; leftHand = MeatKitPlugin.playerCamera.transform.parent.GetChild(1).GetComponent(); rightHand = MeatKitPlugin.playerCamera.transform.parent.GetChild(0).GetComponent(); diff --git a/Assets/_Scripts/InPlay.cs b/Assets/_Scripts/InPlay.cs index af5b471..555b1b3 100644 --- a/Assets/_Scripts/InPlay.cs +++ b/Assets/_Scripts/InPlay.cs @@ -1,6 +1,4 @@ -using HarmonyLib; -using System.Reflection; -using UnityEngine; +using UnityEngine; using FistVR; namespace TNHQoLImprovements @@ -32,7 +30,6 @@ namespace TNHQoLImprovements void OnDestroy() { - // Destroy statics tnhManager = null; } } diff --git a/Assets/_Scripts/TNHInfo.cs b/Assets/_Scripts/TNHInfo.cs index f09deb2..0e019ee 100644 --- a/Assets/_Scripts/TNHInfo.cs +++ b/Assets/_Scripts/TNHInfo.cs @@ -95,8 +95,8 @@ namespace TNHQoLImprovements private void Update() { - // game over area; do not update anything else - if (InPlay.tnhManager.Phase == TNH_Phase.Dead || InPlay.tnhManager.Phase == TNH_Phase.Completed) + // game over area; do not update anything else + if (InPlay.tnhManager.Phase == TNH_Phase.Dead || InPlay.tnhManager.Phase == TNH_Phase.Completed) { if (tokenCounter != null) tokenCounter.SetActive(true);