From f4b47275c854c0d7f1f090dff3ff48dc2387bb34 Mon Sep 17 00:00:00 2001 From: DaXcess Date: Tue, 21 May 2024 17:44:50 +0200 Subject: [PATCH] Changed how the startup UI elements are found --- Source/Patches/UIPatches.cs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Source/Patches/UIPatches.cs b/Source/Patches/UIPatches.cs index d19c1090..63c8906a 100644 --- a/Source/Patches/UIPatches.cs +++ b/Source/Patches/UIPatches.cs @@ -22,18 +22,18 @@ internal static class UIPatches /// [HarmonyPatch(typeof(PreInitSceneScript), nameof(PreInitSceneScript.Start))] [HarmonyPostfix] - private static void OnPreInitMenuShown() + private static void OnPreInitMenuShown(PreInitSceneScript __instance) { - InitMenuScene(); - - var canvas = GameObject.Find("Canvas"); + var canvas = __instance.launchSettingsPanelsContainer.GetComponentInParent(); + + InitMenuScene(canvas); if (Plugin.Flags.HasFlag(Flags.UnityExplorerDetected)) { - var textObject = Object.Instantiate(canvas.Find("GameObject/LANOrOnline/OnlineButton/Text (TMP) (1)")); + var textObject = Object.Instantiate(canvas.gameObject.Find("GameObject/LANOrOnline/OnlineButton/Text (TMP) (1)")); var text = textObject.GetComponent(); - text.transform.parent = canvas.Find("GameObject").transform; + text.transform.parent = __instance.launchSettingsPanelsContainer.transform; text.transform.localPosition = new Vector3(200, -100, 0); text.transform.localScale = Vector3.one; text.text = "Unity Explorer Detected!\nUI controls are most likely nonfunctional!"; @@ -46,10 +46,10 @@ private static void OnPreInitMenuShown() if (Plugin.Flags.HasFlag(Flags.InvalidGameAssembly)) { - var textObject = Object.Instantiate(canvas.Find("GameObject/LANOrOnline/OnlineButton/Text (TMP) (1)")); + var textObject = Object.Instantiate(canvas.gameObject.Find("GameObject/LANOrOnline/OnlineButton/Text (TMP) (1)")); var text = textObject.GetComponent(); - text.transform.parent = canvas.Find("GameObject").transform; + text.transform.parent = __instance.launchSettingsPanelsContainer.transform; text.transform.localPosition = new Vector3(200, -30, 0); text.transform.localScale = Vector3.one; text.text = "Invalid Game Assembly Detected!\nYou are using an unsupported version of the game!"; @@ -68,7 +68,9 @@ private static void OnPreInitMenuShown() [HarmonyPrefix] private static void OnMainMenuShown(MenuManager __instance) { - InitMenuScene(); + var canvas = __instance.menuButtons.GetComponentInParent(); + + InitMenuScene(canvas); if (__instance.isInitScene) return; @@ -81,12 +83,11 @@ private static void OnMainMenuShown(MenuManager __instance) if (Plugin.Compatibility.IsLoaded("MoreCompany")) Compatibility.MoreCompany.MoreCompanyCompatibility.SetupMoreCompanyUI(); - InitializeKeyboard(); + InitializeKeyboard(canvas); } - private static void InitMenuScene() + private static void InitMenuScene(Canvas canvas) { - var canvas = GameObject.Find("Canvas")?.GetComponent(); var input = GameObject.Find("EventSystem")?.GetComponent(); if (input != null) @@ -149,9 +150,8 @@ private static void DisableKeybindsSetting() /// /// Add a keyboard to the main menu /// - private static void InitializeKeyboard() + private static void InitializeKeyboard(Canvas canvas) { - var canvas = GameObject.Find("Canvas")?.GetComponent(); var keyboard = Object.Instantiate(AssetManager.keyboard).GetComponent(); keyboard.transform.SetParent(canvas.transform, false); @@ -277,12 +277,12 @@ internal static class UniversalUIPatches /// [HarmonyPatch(typeof(PreInitSceneScript), nameof(PreInitSceneScript.Start))] [HarmonyPostfix] - private static void OnPreInitMenuShown() + private static void OnPreInitMenuShown(PreInitSceneScript __instance) { if (!Plugin.Flags.HasFlag(Flags.RestartRequired)) return; - var canvas = GameObject.Find("Canvas"); + var canvas = __instance.launchSettingsPanelsContainer.GetComponentInParent().gameObject; var textObject = Object.Instantiate(canvas.Find("GameObject/LANOrOnline/OnlineButton/Text (TMP) (1)")); var text = textObject.GetComponent();