From 2f6d8b97b4cd9eab5aed8952becf78071e58acfd Mon Sep 17 00:00:00 2001 From: dogdie233 Date: Fri, 16 Aug 2024 04:29:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8D=95=E7=8B=AC=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E6=AF=8F=E4=B8=AA=E8=A7=92=E8=89=B2=E7=9A=84BreakLevel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ricca_Uncensor_Plugin/ArmorBreakPatch.cs | 105 +++++++++++++++++++++++ Ricca_Uncensor_Plugin/Plugin.cs | 2 + 2 files changed, 107 insertions(+) create mode 100644 Ricca_Uncensor_Plugin/ArmorBreakPatch.cs diff --git a/Ricca_Uncensor_Plugin/ArmorBreakPatch.cs b/Ricca_Uncensor_Plugin/ArmorBreakPatch.cs new file mode 100644 index 0000000..d157a6f --- /dev/null +++ b/Ricca_Uncensor_Plugin/ArmorBreakPatch.cs @@ -0,0 +1,105 @@ +using ACT; + +using HarmonyLib; + +using Il2CppSystem.Runtime.Remoting.Channels; + +using System.Collections.Generic; + +using UnityEngine; + +namespace Ricca_Uncensor_Plugin; + +[HarmonyPatch] +public class ArmorBreakPatch +{ + [HarmonyPatch(typeof(CharacterArmorBreaker), nameof(CharacterArmorBreaker.Initialize))] + [HarmonyPostfix] + public static void InitializePostfix(CharacterArmorBreaker __instance) + { + ArmorBreakGUI.Instance.AddCharacterArmorBreaker(__instance); + } +} + +public class ArmorBreakGUI : MonoBehaviour +{ + private static bool isEnabled = false; + private static ArmorBreakGUI instance; + private readonly List breakers = new(); + private readonly string[] translateText = ["崭新出厂", "久经沙场", "破损不堪", "无了"]; + + public static ArmorBreakGUI Instance => instance; + + private void Awake() + { + if (instance != null && instance != this) + { + Destroy(this); + return; + } + instance = this; + } + + private void OnDestroy() + { + instance = null; + } + + public void OnGUI() + { + if (Event.current.type == EventType.KeyUp) + { + if (Event.current.keyCode == KeyCode.F12) + isEnabled = !isEnabled; + } + if (!isEnabled) + return; + + EnsureBreakerListNotNull(); + float buttonHeight = 20, buttonWidth = 80; + + var y = 100f; + for (var i = 0; i < breakers.Count; i++) + { + var breaker = breakers[i]; + var x = 10f; + + if (!breaker.isActiveAndEnabled) + continue; + + GUI.Label(new(x, y, 200f, buttonHeight), breaker.transform.parent.gameObject.name); + x += 200f + 10f; + + if (GUI.Button(new(x, y, buttonWidth, buttonHeight), translateText[0])) + breaker.SetArmorLevel(-1); + x += buttonWidth + 10f; + for (int id = 0; id < breaker.LevelList.Count; id++) + { + if (GUI.Button(new(x, y, buttonWidth, buttonHeight), translateText[id + 1])) + breaker.SetArmorLevel(id); + x += buttonWidth + 10f; + } + + y += buttonHeight + 10f; + } + } + + private void EnsureBreakerListNotNull() + { + for (int i = breakers.Count - 1; i >= 0; i--) + { + if (breakers[i] == null || !breakers[i].IsProfileValid) + breakers.RemoveAt(i); + } + } + + public void RemoveCharacterArmorBreaker(CharacterArmorBreaker instance) + { + breakers.Remove(instance); + } + + public void AddCharacterArmorBreaker(CharacterArmorBreaker instance) + { + breakers.Add(instance); + } +} \ No newline at end of file diff --git a/Ricca_Uncensor_Plugin/Plugin.cs b/Ricca_Uncensor_Plugin/Plugin.cs index 6619c3b..2450791 100644 --- a/Ricca_Uncensor_Plugin/Plugin.cs +++ b/Ricca_Uncensor_Plugin/Plugin.cs @@ -35,7 +35,9 @@ public override void Load() Harmony harmony = new Harmony("moe.KazamataNeri.Ricca_Uncensor_Plugin"); harmony.PatchAll(); ClassInjector.RegisterTypeInIl2Cpp(); + ClassInjector.RegisterTypeInIl2Cpp(); base.AddComponent(); + base.AddComponent(); base.AddComponent(); }