From 8cb6d7788b5e17c266223ffbc061ed0823271ee9 Mon Sep 17 00:00:00 2001 From: FrenchKrab <14005967+FrenchKrab@users.noreply.github.com> Date: Sat, 20 May 2023 18:59:53 +0200 Subject: [PATCH] fix DisplayTrueLevel --- DisplayTrueLevel/DisplayTrueLevel.csproj | 4 ++ DisplayTrueLevel/DisplayTrueLevelMod.cs | 54 +++++++++++++++++++++--- 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/DisplayTrueLevel/DisplayTrueLevel.csproj b/DisplayTrueLevel/DisplayTrueLevel.csproj index dc96179..9730712 100644 --- a/DisplayTrueLevel/DisplayTrueLevel.csproj +++ b/DisplayTrueLevel/DisplayTrueLevel.csproj @@ -34,6 +34,10 @@ ..\_dlls\UnityEngine.CoreModule.dll False + + ..\_dlls\Unity.TextMeshPro.dll + False + diff --git a/DisplayTrueLevel/DisplayTrueLevelMod.cs b/DisplayTrueLevel/DisplayTrueLevelMod.cs index 472744e..84a4ef4 100644 --- a/DisplayTrueLevel/DisplayTrueLevelMod.cs +++ b/DisplayTrueLevel/DisplayTrueLevelMod.cs @@ -4,6 +4,7 @@ using HarmonyLib; using Il2Cpp; using Il2Cppnewdata_H; +using Il2CppTMPro; using MelonLoader; [assembly: MelonInfo(typeof(DisplayTrueLevelMod), "Display true level (0.6 ver.)", "1.0.0", "Matthiew Purple")] @@ -55,17 +56,29 @@ private class Patch3 { public static void Postfix() { - for (int i = 0; i < dds3GlobalWork.DDS3_GBWK.stocklist.Length; i++) + // For the party + for (int i = 1; i <= 4; i++) { - if (dds3GlobalWork.DDS3_GBWK.unitwork[i].level > 99 && dds3GlobalWork.DDS3_GBWK.unitwork[i].level != 255) + string name = cmpInit._campUIScr.transform.Find($"party/party_status/party_status{Utility.GetNumberForPath(i)}/Text_nameTM").gameObject.GetComponent().text; + name = Utility.RemoveMaterial(name); + ushort level = Utility.GetLevelFromName(name); + if (level > 99) { - cmpInit._campUIScr.transform.Find($"party/party_status/party_status{Utility.GetNumberForPath(i + 1)}/num_lv").gameObject.GetComponent().colorIndex = dds3GlobalWork.DDS3_GBWK.unitwork[i].level / 100 + 1; - cmpInit._campUIScr.transform.Find($"party/party_status/party_status{Utility.GetNumberForPath(i + 1)}/num_lv").gameObject.GetComponent().Change(); + cmpInit._campUIScr.transform.Find($"party/party_status/party_status{Utility.GetNumberForPath(i)}/num_lv").gameObject.GetComponent().colorIndex = level / 100 + 1; + cmpInit._campUIScr.transform.Find($"party/party_status/party_status{Utility.GetNumberForPath(i)}/num_lv").gameObject.GetComponent().Change(); } - else if (dds3GlobalWork.DDS3_GBWK.unitwork[i].level == 255) + } + + // For the rest of the stock + for (int i = 1; i <= 12; i++) + { + string name = cmpInit._campUIScr.transform.Find($"party/party_status/stock_status{Utility.GetNumberForPath(i)}/Text_nameTM").gameObject.GetComponent().text; + name = Utility.RemoveMaterial(name); + ushort level = Utility.GetLevelFromName(name); + if (level > 99) { - cmpInit._campUIScr.transform.Find($"party/party_status/party_status{Utility.GetNumberForPath(i + 1)}/num_lv").gameObject.GetComponent().colorIndex = 6; // Displays 55 in black instead of red - cmpInit._campUIScr.transform.Find($"party/party_status/party_status{Utility.GetNumberForPath(i + 1)}/num_lv").gameObject.GetComponent().Change(); + cmpInit._campUIScr.transform.Find($"party/party_status/stock_status{Utility.GetNumberForPath(i)}/num_lv").gameObject.GetComponent().colorIndex = level / 100 + 1; + cmpInit._campUIScr.transform.Find($"party/party_status/stock_status{Utility.GetNumberForPath(i)}/num_lv").gameObject.GetComponent().Change(); } } } @@ -85,5 +98,32 @@ public static string GetNumberForPath(int i) return i.ToString(); } } + + // Removes the beginning of the name (the material) + public static string RemoveMaterial(string text) + { + return text[(text.IndexOf(">") + 1)..]; + } + + // Returns level from name + public static ushort GetLevelFromName(string name) + { + // For each demon in the stock + foreach (datUnitWork_t work in dds3GlobalWork.DDS3_GBWK.unitwork) + { + if (datDevilName.Get(work.id) == name) + { + return work.level; // Compares names + } + } + + // Special case for Demi-fiend's nickname + if (frName.frGetCNameString(0) == name) + { + return dds3GlobalWork.DDS3_GBWK.unitwork[0].level; + } + + return 0; // Not gonna happen + } } }