From 0853801bda90496d137ea47843dbb5d9edebe148 Mon Sep 17 00:00:00 2001 From: Daemon Date: Wed, 19 May 2021 16:01:42 +0100 Subject: [PATCH 1/2] Add ability to always change username --- Reactor/Patches/BetterGuestPatch.cs | 20 ------------ Reactor/Patches/FreeNamePatch.cs | 49 +++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 20 deletions(-) create mode 100644 Reactor/Patches/FreeNamePatch.cs diff --git a/Reactor/Patches/BetterGuestPatch.cs b/Reactor/Patches/BetterGuestPatch.cs index f6b3615..8c32db5 100644 --- a/Reactor/Patches/BetterGuestPatch.cs +++ b/Reactor/Patches/BetterGuestPatch.cs @@ -15,25 +15,5 @@ namespace Reactor.Patches return false; } } - - [HarmonyPatch(typeof(AccountTab), nameof(AccountTab.Open))] - public static class EditNamePatch - { - public static void Prefix(AccountTab __instance) - { - Fix(__instance, __instance.guestMode); - Fix(__instance, __instance.offlineMode); - } - - private static void Fix(AccountTab __instance, GameObject mode) - { - var randomizeName = mode.transform.Find("RandomizeName").gameObject; - if (!randomizeName.active) - return; - - randomizeName.active = false; - Object.Instantiate(__instance.loggedInMode.editNameButton, mode.transform); - } - } } } diff --git a/Reactor/Patches/FreeNamePatch.cs b/Reactor/Patches/FreeNamePatch.cs new file mode 100644 index 0000000..9e749ed --- /dev/null +++ b/Reactor/Patches/FreeNamePatch.cs @@ -0,0 +1,49 @@ +using System; +using HarmonyLib; +using TMPro; +using UnityEngine; +using UnityEngine.UI; + +namespace Reactor.Patches +{ + internal static class FreeNamePatch + { + [HarmonyPatch(typeof(SetNameText), nameof(SetNameText.Start))] + public static class NameInputPatch + { + public static void Postfix(SetNameText __instance) + { + if (!__instance) + { + return; + } + + var nameText = __instance.gameObject; + + var textBox = nameText.AddComponent(); + textBox.Background = nameText.GetComponentInChildren(); + textBox.OnChange = textBox.OnEnter = textBox.OnFocusLost = new Button.ButtonClickedEvent(); + textBox.characterLimit = 10; + + var textMeshPro = nameText.GetComponentInChildren(); + textBox.outputText = textMeshPro; + textBox.SetText(SaveManager.PlayerName); + + textBox.OnChange.AddListener((Action) (() => + { + SaveManager.PlayerName = textBox.text; + })); + + var pipeGameObject = GameObject.Find("Pipe"); + if (!pipeGameObject) + { + return; + } + + var pipe = UnityEngine.Object.Instantiate(pipeGameObject, textMeshPro.transform); + pipe.GetComponent().fontSize = 4f; + textBox.Pipe = pipe.GetComponent(); + } + } + } +} From 6a7f878560a6964c17b3fc198acc5227ad5f9705 Mon Sep 17 00:00:00 2001 From: js6pak Date: Tue, 8 Jun 2021 00:00:19 +0200 Subject: [PATCH 2/2] Add CursorPosPatch --- Reactor/Patches/CursorPosPatch.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Reactor/Patches/CursorPosPatch.cs diff --git a/Reactor/Patches/CursorPosPatch.cs b/Reactor/Patches/CursorPosPatch.cs new file mode 100644 index 0000000..3ebe3af --- /dev/null +++ b/Reactor/Patches/CursorPosPatch.cs @@ -0,0 +1,25 @@ +using System.Linq; +using HarmonyLib; +using TMPro; +using UnityEngine; + +namespace Reactor.Patches +{ + /// + /// "Fixes" an issue where empty TextBoxes have wrong cursor positions + /// + [HarmonyPatch(typeof(TextMeshProExtensions), nameof(TextMeshProExtensions.CursorPos))] + internal static class CursorPosPatch + { + public static bool Prefix(TextMeshPro self, ref Vector2 __result) + { + if (self.textInfo == null || self.textInfo.lineCount == 0 || self.textInfo.lineInfo[0].characterCount <= 0) + { + __result = self.GetTextInfo(" ").lineInfo.First().lineExtents.max; + return false; + } + + return true; + } + } +}