using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using HarmonyLib; using TMPro; using TextUpgradesUIScale.Patches; using UnityEngine; [assembly: AssemblyCompany("DarkSpider")] [assembly: AssemblyProduct("TextUpgradesUIScale")] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = "")] [assembly: AssemblyTitle("TextUpgradesUIScale")] [assembly: AssemblyDescription("Resizes the R.E.P.O. upgrades UI text for large upgrade lists.")] [assembly: AssemblyConfiguration("")] [assembly: ComVisible(false)] [assembly: AssemblyCopyright("")] [assembly: AssemblyTrademark("")] [assembly: AssemblyFileVersion("1.1.0.0")] [assembly: CompilationRelaxations(8)] [assembly: Guid("a27adabc-310b-43d6-8584-f2e1ec7a34cb")] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyVersion("1.1.0.0")] namespace DSStatsUIFontMod { [BepInPlugin("DSModUI.StatsUIFontMod", "DarkSpiderStatsUIFontMod", "1.1.0")] public class StatsUIFontMod : BaseUnityPlugin { private const string modGUID = "DSModUI.StatsUIFontMod"; private const string modName = "DarkSpiderStatsUIFontMod"; private const string modVersion = "1.1.0"; private readonly Harmony harmony = new Harmony("DSModUI.StatsUIFontMod"); private static StatsUIFontMod Instance; internal ManualLogSource mls; private void Awake() { if ((Object)(object)Instance == (Object)null) { Instance = this; } mls = Logger.CreateLogSource("DSModUI.StatsUIFontMod"); mls.LogInfo((object)"Loaded TextUpgradesUIScale for R.E.P.O. v0.4.0 UI."); harmony.PatchAll(typeof(StatsUIFontMod)); harmony.PatchAll(typeof(StatsUIPatchMod)); } } } namespace TextUpgradesUIScale.Patches { [HarmonyPatch(typeof(StatsUI), "Fetch")] public static class StatsUIPatchMod { private static readonly FieldInfo TextField = AccessTools.Field(typeof(StatsUI), "Text"); private static readonly FieldInfo NumbersTextField = AccessTools.Field(typeof(StatsUI), "textNumbers"); private static readonly FieldInfo PlayerUpgradesField = AccessTools.Field(typeof(StatsUI), "playerUpgrades"); private static float _defaultFontSize; private static float _defaultNumbersFontSize; private static bool _defaultAutoSizing; private static bool _defaultNumbersAutoSizing; private static bool _defaultWordWrapping; private static bool _defaultNumbersWordWrapping; private static TextOverflowModes _defaultOverflowMode; private static TextOverflowModes _defaultNumbersOverflowMode; private static bool _defaultFontSizeInitialized; public static void Postfix(StatsUI __instance) { //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) try { TextMeshProUGUI val = (TextMeshProUGUI)((TextField == null) ? null : /*isinst with value type is only supported in some contexts*/); TextMeshProUGUI val2 = (TextMeshProUGUI)((NumbersTextField == null) ? null : /*isinst with value type is only supported in some contexts*/); Dictionary dictionary = ((PlayerUpgradesField == null) ? null : (PlayerUpgradesField.GetValue(__instance) as Dictionary)); if (!((Object)(object)val == (Object)null) && !((Object)(object)val2 == (Object)null) && dictionary != null) { int num = dictionary.Count((KeyValuePair kvp) => kvp.Value > 0); if (!_defaultFontSizeInitialized) { _defaultFontSize = ((TMP_Text)val).fontSize; _defaultNumbersFontSize = ((TMP_Text)val2).fontSize; _defaultAutoSizing = ((TMP_Text)val).enableAutoSizing; _defaultNumbersAutoSizing = ((TMP_Text)val2).enableAutoSizing; _defaultWordWrapping = ((TMP_Text)val).enableWordWrapping; _defaultNumbersWordWrapping = ((TMP_Text)val2).enableWordWrapping; _defaultOverflowMode = ((TMP_Text)val).overflowMode; _defaultNumbersOverflowMode = ((TMP_Text)val2).overflowMode; _defaultFontSizeInitialized = true; } if (num <= 10) { RestoreTextColumn(val, _defaultFontSize, _defaultAutoSizing, _defaultWordWrapping, _defaultOverflowMode); RestoreTextColumn(val2, _defaultNumbersFontSize, _defaultNumbersAutoSizing, _defaultNumbersWordWrapping, _defaultNumbersOverflowMode); return; } ConfigureTextColumn(val); ConfigureTextColumn(val2); float scaleForUpgradeCount = GetScaleForUpgradeCount(num); float fontSize = _defaultFontSize * scaleForUpgradeCount; float fontSize2 = _defaultNumbersFontSize * scaleForUpgradeCount; ((TMP_Text)val).fontSize = fontSize; ((TMP_Text)val2).fontSize = fontSize2; } } catch (Exception ex) { Debug.LogWarning((object)("[TextUpgradesUIScale] Failed to resize StatsUI text: " + ex.Message)); } } private static void ConfigureTextColumn(TextMeshProUGUI text) { ((TMP_Text)text).enableAutoSizing = false; ((TMP_Text)text).enableWordWrapping = false; ((TMP_Text)text).overflowMode = (TextOverflowModes)0; } private static void RestoreTextColumn(TextMeshProUGUI text, float fontSize, bool autoSizing, bool wordWrapping, TextOverflowModes overflowMode) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) ((TMP_Text)text).fontSize = fontSize; ((TMP_Text)text).enableAutoSizing = autoSizing; ((TMP_Text)text).enableWordWrapping = wordWrapping; ((TMP_Text)text).overflowMode = overflowMode; } private static float GetScaleForUpgradeCount(int activeUpgradesCount) { if (activeUpgradesCount >= 19) { return 0.5f; } if (activeUpgradesCount >= 17) { return 0.6f; } if (activeUpgradesCount >= 15) { return 0.7f; } if (activeUpgradesCount >= 13) { return 0.8f; } if (activeUpgradesCount >= 11) { return 0.9f; } return 1f; } } }