using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.5", FrameworkDisplayName = "")] [assembly: AssemblyCompany("BatterUpgradeUI")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.2.0")] [assembly: AssemblyInformationalVersion("1.0.2")] [assembly: AssemblyProduct("BatterUpgradeUI")] [assembly: AssemblyTitle("BatterUpgradeUI")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.2.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace BatterUpgradeUI { public class MemoryConfigEntry { public T Value { get; set; } public string Section { get; } public string Key { get; } public string Description { get; } public MemoryConfigEntry(string section, string key, T defaultValue, string description = "") { Section = section; Key = key; Value = defaultValue; Description = description; } } [BepInPlugin("BatterUpgradeUI", "BatterUpgradeUI", "1.0.2")] public class Plugin : BaseUnityPlugin { internal static ManualLogSource Logger; public static MemoryConfigEntry EnableDebug = new MemoryConfigEntry("General", "EnableDebug", defaultValue: false, "Enable debug mode."); private void Awake() { //IL_002a: Unknown result type (might be due to invalid IL or missing references) EnableDebug.Value = false; Logger = ((BaseUnityPlugin)this).Logger; Logger.LogInfo((object)"Plugin BatterUpgradeUI is loaded!"); new Harmony("BatterUpgradeUI").PatchAll(); } } [HarmonyPatch(typeof(StatsUI), "Fetch")] public static class StatsUIPatchMod { private static readonly Dictionary TextReplacements = new Dictionary { { "Health", "×生命" }, { "Stamina", "×耐力" }, { "Strength", "×力量" }, { "Range", "×抓取范围" }, { "Sprint Speed", "×冲刺速度" }, { "Crouch Rest", "×下蹲休息" }, { "Extra Jump", "×额外跳跃" }, { "Tumble Launch", "×翻滚速度" }, { "Tumble Wings", "×翻滚翅膀" }, { "Tumble Climb", "×翻滚攀爬" }, { "Death Head Battery", "×死亡之首电池" }, { "Map Player Count", "×地图玩家数量" } }; private static bool _enableTextReplacement = true; private static bool _enableFontSizeAdjustment = true; private static float _defaultFontSizeText; private static float _defaultFontSizeNumber; private static bool _defaultFontSizeInitialized; public static void Postfix(StatsUI __instance) { //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Expected O, but got Unknown //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Expected O, but got Unknown FieldInfo fieldInfo = AccessTools.Field(typeof(StatsUI), "Text"); FieldInfo fieldInfo2 = AccessTools.Field(typeof(StatsUI), "textNumbers"); FieldInfo fieldInfo3 = AccessTools.Field(typeof(StatsUI), "playerUpgrades"); if (fieldInfo == null || fieldInfo2 == null || fieldInfo3 == null) { return; } TextMeshProUGUI val = (TextMeshProUGUI)fieldInfo.GetValue(__instance); TextMeshProUGUI val2 = (TextMeshProUGUI)fieldInfo2.GetValue(__instance); Dictionary dictionary = (Dictionary)fieldInfo3.GetValue(__instance); if (!((Object)(object)val == (Object)null) && !((Object)(object)val2 == (Object)null) && dictionary != null) { if (_enableTextReplacement) { ApplyTextReplacement(val, val2, dictionary); } if (_enableFontSizeAdjustment) { ApplyFontSizeAdjustment(val, val2, dictionary); } } } private static void ApplyTextReplacement(TextMeshProUGUI statsText, TextMeshProUGUI statsNumbers, Dictionary playerUpgrades) { try { string text = ((TMP_Text)statsText).text; _ = ((TMP_Text)statsNumbers).text; string text2 = ReplaceTextContent(text); if (text2 != text) { ((TMP_Text)statsText).text = text2; if (Plugin.EnableDebug.Value) { Plugin.Logger.LogInfo((object)"[StatsUIPatch] 文本替换完成"); } LogReplacementStatistics(text, text2); } } catch (Exception ex) { if (Plugin.EnableDebug.Value) { Plugin.Logger.LogError((object)("[StatsUIPatch] 文本替换失败: " + ex.Message)); } } } private static void ApplyFontSizeAdjustment(TextMeshProUGUI statsText, TextMeshProUGUI statsNumbers, Dictionary playerUpgrades) { int num = CalculateAndLogUpgradeCount(playerUpgrades); if (!_defaultFontSizeInitialized) { _defaultFontSizeText = ((TMP_Text)statsText).fontSize; _defaultFontSizeNumber = ((TMP_Text)statsNumbers).fontSize; _defaultFontSizeInitialized = true; if (Plugin.EnableDebug.Value) { Plugin.Logger.LogInfo((object)$"[StatsUIPatch] 默认字体大小: {_defaultFontSizeText} ({_defaultFontSizeNumber})"); } } float fontSizeMultiplier = GetFontSizeMultiplier(num); float num2 = _defaultFontSizeText * (fontSizeMultiplier - 0.15f); float num3 = _defaultFontSizeNumber * fontSizeMultiplier; ((TMP_Text)statsText).fontSize = num2; ((TMP_Text)statsNumbers).fontSize = num3; if (Plugin.EnableDebug.Value) { Plugin.Logger.LogInfo((object)$"[StatsUIPatch] 字体调整: 升级数量 {num}, 比例 {fontSizeMultiplier}, 新大小 {num2} ({num3})"); } } private static string ReplaceTextContent(string originalText) { if (string.IsNullOrEmpty(originalText)) { return originalText; } string text = originalText; int num = 0; foreach (KeyValuePair textReplacement in TextReplacements) { if (text.Contains(textReplacement.Key)) { text = text.Replace(textReplacement.Key, textReplacement.Value); num++; if (Plugin.EnableDebug.Value) { Plugin.Logger.LogDebug((object)("[StatsUIPatch] 替换: " + textReplacement.Key + " -> " + textReplacement.Value)); } } } if (num > 0 && Plugin.EnableDebug.Value) { Plugin.Logger.LogDebug((object)$"[StatsUIPatch] 共完成 {num} 处文本替换"); } return text; } private static void LogReplacementStatistics(string originalText, string replacedText) { if (originalText == replacedText) { return; } int length = originalText.Length; int length2 = replacedText.Length; int num = 0; foreach (KeyValuePair textReplacement in TextReplacements) { if (originalText.Contains(textReplacement.Key)) { num++; } } if (Plugin.EnableDebug.Value) { Plugin.Logger.LogInfo((object)($"[StatsUIPatch] 替换统计: 进行了 {num} 处替换, " + $"原长度 {length}, 新长度 {length2}")); } } private static int CalculateAndLogUpgradeCount(Dictionary playerUpgrades) { if (playerUpgrades == null || playerUpgrades.Count == 0) { if (Plugin.EnableDebug.Value) { Plugin.Logger.LogInfo((object)"[StatsUIPatch] 没有找到玩家升级数据"); } return 0; } List> list = playerUpgrades.Where((KeyValuePair kvp) => kvp.Value > 0).ToList(); int count = list.Count; if (Plugin.EnableDebug.Value) { Plugin.Logger.LogInfo((object)$"[StatsUIPatch] 总升级项: {playerUpgrades.Count}, 有效升级项: {count}"); } foreach (KeyValuePair item in playerUpgrades.OrderBy((KeyValuePair kvp) => kvp.Key)) { string arg = ApplyReplacementToKey(item.Key); if (Plugin.EnableDebug.Value) { string arg2 = ((item.Value > 0) ? "激活" : "未激活"); Plugin.Logger.LogInfo((object)$"[StatsUIPatch] {arg}: 等级 {item.Value} ({arg2})"); } } if (list.Any()) { string text = string.Join(", ", list.Select((KeyValuePair kvp) => $"{ApplyReplacementToKey(kvp.Key)}({kvp.Value})")); if (Plugin.EnableDebug.Value) { Plugin.Logger.LogInfo((object)("[StatsUIPatch] 激活的升级: " + text)); } } else if (Plugin.EnableDebug.Value) { Plugin.Logger.LogInfo((object)"[StatsUIPatch] 没有激活的升级项"); } return count; } private static string ApplyReplacementToKey(string key) { if (TextReplacements.ContainsKey(key)) { return TextReplacements[key]; } return key; } private static float GetFontSizeMultiplier(int upgradeCount) { if (upgradeCount >= 20) { return 0.5f; } if (upgradeCount >= 18) { return 0.6f; } if (upgradeCount >= 16) { return 0.7f; } if (upgradeCount >= 14) { return 0.8f; } if (upgradeCount >= 12) { return 0.9f; } return 1f; } public static void SetTextReplacementEnabled(bool enabled) { _enableTextReplacement = enabled; if (Plugin.EnableDebug.Value) { Plugin.Logger.LogInfo((object)("[StatsUIPatch] 文本替换功能: " + (enabled ? "启用" : "禁用"))); } } public static void SetFontSizeAdjustmentEnabled(bool enabled) { _enableFontSizeAdjustment = enabled; if (Plugin.EnableDebug.Value) { Plugin.Logger.LogInfo((object)("[StatsUIPatch] 字体大小调整功能: " + (enabled ? "启用" : "禁用"))); } } } public static class MyPluginInfo { public const string PLUGIN_GUID = "BatterUpgradeUI"; public const string PLUGIN_NAME = "BatterUpgradeUI"; public const string PLUGIN_VERSION = "1.0.2"; } }