From 089dada562aa3c68044073e4a00fad90ed1dbc2a Mon Sep 17 00:00:00 2001 From: amsyarasyiq Date: Thu, 26 Aug 2021 08:57:21 +0800 Subject: [PATCH 1/3] Readd FreeNamePatch --- Reactor/Patches/FreeNamePatch.cs | 56 +++++++++++++------------------- Reactor/ReactorPlugin.cs | 1 + 2 files changed, 23 insertions(+), 34 deletions(-) diff --git a/Reactor/Patches/FreeNamePatch.cs b/Reactor/Patches/FreeNamePatch.cs index 06aeef7..5380691 100644 --- a/Reactor/Patches/FreeNamePatch.cs +++ b/Reactor/Patches/FreeNamePatch.cs @@ -1,50 +1,38 @@ using System; -using HarmonyLib; +using System.Collections.Generic; +using System.Linq; using TMPro; using UnityEngine; -using UnityEngine.UI; +using UnityEngine.SceneManagement; +using Object = UnityEngine.Object; namespace Reactor.Patches { - // TODO this needs some changes as text box was entirely removed in 2021.6.15 - internal static class FreeNamePatch + public static class FreeNamePatch { - [HarmonyPatch(typeof(SetNameText), nameof(SetNameText.Start))] - public static class NameInputPatch + public static void Initialize() { - public static void Postfix(SetNameText __instance) + SceneManager.add_sceneLoaded((Action) ((scene, _) => { - if (!__instance) - { - return; - } + if (!scene.name.Equals("MMOnline")) return; + + var editName = DestroyableSingleton.Instance.accountTab.editNameScreen; + var nameText = Object.Instantiate(editName.nameText.gameObject); - var nameText = __instance.gameObject; + nameText.transform.localPosition += Vector3.up * 2.2f; - 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) (() => - { + var textBox = nameText.GetComponent(); + textBox.outputText.alignment = TextAlignmentOptions.CenterGeoAligned; + textBox.outputText.transform.position = nameText.transform.position; + textBox.outputText.fontSize = 4f; + + 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(); - } + textBox.OnEnter = textBox.OnFocusLost = textBox.OnChange; + + textBox.Pipe.GetComponent().fontSize = 4f; + })); } } } diff --git a/Reactor/ReactorPlugin.cs b/Reactor/ReactorPlugin.cs index 80be6ee..1a97780 100644 --- a/Reactor/ReactorPlugin.cs +++ b/Reactor/ReactorPlugin.cs @@ -52,6 +52,7 @@ namespace Reactor _gameObject.AddComponent(); ReactorVersionShower.Initialize(); + FreeNamePatch.Initialize(); SplashSkip.Initialize(); DefaultBundle.Load(); } From 5d362b0885a138668e7281c041beaf34d71f19be Mon Sep 17 00:00:00 2001 From: amsyarasyiq Date: Thu, 26 Aug 2021 08:59:42 +0800 Subject: [PATCH 2/3] Move objects --- Reactor/Patches/FreeNamePatch.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Reactor/Patches/FreeNamePatch.cs b/Reactor/Patches/FreeNamePatch.cs index 5380691..3256f84 100644 --- a/Reactor/Patches/FreeNamePatch.cs +++ b/Reactor/Patches/FreeNamePatch.cs @@ -15,6 +15,7 @@ namespace Reactor.Patches SceneManager.add_sceneLoaded((Action) ((scene, _) => { if (!scene.name.Equals("MMOnline")) return; + if (!TryMoveObjects()) return; var editName = DestroyableSingleton.Instance.accountTab.editNameScreen; var nameText = Object.Instantiate(editName.nameText.gameObject); @@ -34,5 +35,26 @@ namespace Reactor.Patches textBox.Pipe.GetComponent().fontSize = 4f; })); } + + private static bool TryMoveObjects() + { + var toMove = new List + { + "HostGameButton", + "FindGameButton", + "JoinGameButton" + }; + + var offset = Vector3.down * 0.7f; + var gameObjects = toMove.Select(x => GameObject.Find("NormalMenu/" + x)).ToList(); + if (gameObjects.Contains(null)) return false; + + gameObjects.ForEach(x => { + x.transform.position += offset; + offset -= Vector3.down * 0.2f; + }); + + return true; + } } } From 959c5b1fc8732f882a2c7efd2c22bfd4796ae6ab Mon Sep 17 00:00:00 2001 From: amsyarasyiq Date: Thu, 26 Aug 2021 11:27:01 +0800 Subject: [PATCH 3/3] Better math --- Reactor/Patches/FreeNamePatch.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Reactor/Patches/FreeNamePatch.cs b/Reactor/Patches/FreeNamePatch.cs index 3256f84..529f22b 100644 --- a/Reactor/Patches/FreeNamePatch.cs +++ b/Reactor/Patches/FreeNamePatch.cs @@ -45,13 +45,13 @@ namespace Reactor.Patches "JoinGameButton" }; - var offset = Vector3.down * 0.7f; + var offset = Vector3.up; var gameObjects = toMove.Select(x => GameObject.Find("NormalMenu/" + x)).ToList(); if (gameObjects.Contains(null)) return false; gameObjects.ForEach(x => { - x.transform.position += offset; - offset -= Vector3.down * 0.2f; + x.transform.position = offset; + offset += Vector3.down * 1.5f; }); return true;