using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using UnityEngine.UI.Youthcat;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("TextBoost")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: AssemblyInformationalVersion("0.0.1")]
[assembly: AssemblyProduct("TextBoost")]
[assembly: AssemblyTitle("TextBoost")]
[assembly: AssemblyVersion("0.0.1.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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 TextBoost
{
internal static class BoostPolicy
{
internal const int MaxPixels = 12;
internal const int MaxSize = 96;
internal static bool Candidate(Control f)
{
if (f == null)
{
return false;
}
string key = f.Key;
string section = f.Section;
if (key.IndexOf("Input", StringComparison.Ordinal) < 0 && key.IndexOf("Placeholder", StringComparison.Ordinal) < 0)
{
switch (key)
{
case "ShareCode":
case "SavePath":
case "FolderPath":
case "Search":
case "Memo":
case "Breadcrumb":
case "PathSeparator":
break;
default:
if (section.StartsWith("Blueprint.", StringComparison.Ordinal))
{
switch (key)
{
case "Description":
case "NameDisplay":
case "FieldValueDisplay":
case "FolderDescription":
case "Name":
case "DescriptionDisplay":
case "FolderDescriptionDisplay":
case "Author":
case "AuthorDisplay":
case "Version":
case "VersionDisplay":
case "FieldName":
case "FieldNameDisplay":
case "FieldValue":
return false;
}
}
if (section == "Logistics.Station")
{
switch (key)
{
case "Power":
case "State":
case "CurrentCount":
case "OrderedCount":
case "SlotLabel":
case "SlotSpeed":
case "Energy":
case "MaxCount":
case "SlotSliderLimit":
return false;
}
}
if ((section == "Starmap.Planet" || section == "Starmap.Star") && (key == "ResourceName" || key == "ResourceValue"))
{
return false;
}
if (section == "Tooltip.Item" && (key == "Property" || key == "Value"))
{
return false;
}
return true;
}
}
return false;
}
}
internal sealed class Control
{
internal readonly string Section;
internal readonly string Key;
internal string Id => Section + "/" + Key;
internal Control(string section, string key)
{
Section = section;
Key = key;
}
}
internal static class Paths
{
private static readonly char[] Escapes = new char[5] { '%', '/', '\t', '\r', '\n' };
internal static string Segment(string name)
{
while (name.EndsWith("(Clone)", StringComparison.Ordinal))
{
name = name.Substring(0, name.Length - "(Clone)".Length);
}
if (name.IndexOfAny(Escapes) >= 0)
{
return name.Replace("%", "%25").Replace("/", "%2F").Replace("\t", "%09")
.Replace("\r", "%0D")
.Replace("\n", "%0A");
}
return name;
}
internal static string Validate(string path, bool absolute)
{
if (string.IsNullOrWhiteSpace(path) || path.Length > 4096 || path[0] == '/' != absolute)
{
throw new FormatException("Expected " + (absolute ? "full" : "suffix") + " hierarchy path: " + path);
}
string[] array = (absolute ? path.Substring(1) : path).Split('/');
if (array.Length < 2 || array.Length > 128)
{
throw new FormatException("Expected at least owner and control: " + path);
}
for (int i = 0; i < array.Length; i++)
{
if (string.IsNullOrWhiteSpace(array[i]) || array[i] == "." || array[i] == ".." || array[i].IndexOfAny(new char[3] { '\t', '\r', '\n' }) >= 0)
{
throw new FormatException("Invalid hierarchy path: " + path);
}
while (array[i].EndsWith("(Clone)", StringComparison.Ordinal))
{
array[i] = array[i].Substring(0, array[i].Length - 7);
}
if (array[i].Length == 0)
{
throw new FormatException("Empty object name: " + path);
}
}
return (absolute ? "/" : "") + string.Join("/", array);
}
}
internal sealed class Catalog
{
private sealed class Node
{
internal readonly Dictionary<string, Node> Next = new Dictionary<string, Node>(StringComparer.Ordinal);
internal Control Hit;
}
internal readonly SortedSet<string> Sections = new SortedSet<string>(StringComparer.Ordinal);
internal readonly Dictionary<string, Control> Suffixes = new Dictionary<string, Control>(StringComparer.Ordinal);
private readonly Node root = new Node();
internal static Catalog Read(TextReader reader)
{
Catalog catalog = new Catalog();
int num = 0;
string text;
while ((text = reader.ReadLine()) != null)
{
num++;
if (text.Length == 0 || text[0] == '#')
{
continue;
}
string[] array = text.Split('\t');
if (array.Length != 6 || !IdPart(array[0]) || !IdPart(array[1]) || string.IsNullOrWhiteSpace(array[2]) || string.IsNullOrWhiteSpace(array[3]) || !int.TryParse(array[4], NumberStyles.None, CultureInfo.InvariantCulture, out var result) || result < 0 || result > 300)
{
throw new FormatException("Invalid control row " + num);
}
string text2 = Paths.Validate(array[5], absolute: false);
if (catalog.Suffixes.ContainsKey(text2))
{
throw new FormatException("Duplicate path: " + text2);
}
Control control = new Control(array[0], array[1]);
string[] array2 = text2.Split('/');
Node node = catalog.root;
for (int num2 = array2.Length - 1; num2 >= 0; num2--)
{
if (!node.Next.TryGetValue(array2[num2], out var value))
{
node.Next.Add(array2[num2], value = new Node());
}
node = value;
}
if (node.Hit != null)
{
throw new FormatException("Ambiguous path: " + text2);
}
node.Hit = control;
catalog.Suffixes.Add(text2, control);
catalog.Sections.Add(array[0]);
}
if (catalog.Suffixes.Count == 0)
{
throw new FormatException("Empty control catalog");
}
return catalog;
}
private static bool IdPart(string s)
{
if (string.IsNullOrEmpty(s))
{
return false;
}
foreach (char c in s)
{
if ((c < 'A' || c > 'Z') && (c < 'a' || c > 'z') && (c < '0' || c > '9') && c != '.' && c != '_' && c != '-')
{
return false;
}
}
return true;
}
internal Control Match(string full)
{
Node node = root;
Control result = null;
string[] array = full.Split('/');
int num = array.Length - 1;
Node value;
while (num >= 0 && array[num].Length != 0 && node.Next.TryGetValue(array[num], out value))
{
node = value;
if (node.Hit != null)
{
result = node.Hit;
}
num--;
}
return result;
}
}
internal static class Display
{
private sealed class Binding
{
internal string Path;
internal Control Control;
internal VisibilityPolicy.Role Role;
internal bool ContextReady;
internal bool Clipped;
internal InputField Input;
}
internal readonly struct MeasureFrame
{
internal readonly bool Entered;
internal readonly Text Previous;
internal MeasureFrame(Text owner)
{
Entered = true;
Previous = owner;
}
}
private static Catalog catalog;
private static int boost;
private static ConditionalWeakTable<Text, Binding> cache = new ConditionalWeakTable<Text, Binding>();
private static readonly ConditionalWeakTable<Text, Binding>.CreateValueCallback create = MakeBinding;
[ThreadStatic]
private static Text measuring;
internal static bool Active => boost > 0;
internal static int Boost => boost;
private static bool NeedMeasure => Active;
internal static void Initialize(Catalog c)
{
catalog = c;
}
internal static void SetBoost(int pixels)
{
pixels = Math.Max(0, Math.Min(12, pixels));
if (pixels == boost)
{
return;
}
boost = pixels;
cache = new ConditionalWeakTable<Text, Binding>();
Text[] array = Object.FindObjectsOfType<Text>();
foreach (Text val in array)
{
if (!((Object)(object)val == (Object)null) && ((Behaviour)val).isActiveAndEnabled && BoostPolicy.Candidate(BindingOf(val).Control))
{
val.SetDirty();
}
}
}
internal static void Dispose()
{
boost = 0;
catalog = null;
measuring = null;
cache = new ConditionalWeakTable<Text, Binding>();
}
internal static string PathOf(Transform t)
{
List<string> list = new List<string>(16);
while ((Object)(object)t != (Object)null)
{
list.Add(Paths.Segment(((Object)t).name));
t = t.parent;
}
list.Reverse();
return "/" + string.Join("/", list);
}
private static Binding MakeBinding(Text text)
{
string text2 = PathOf(((Component)text).transform);
Control control = catalog.Match(text2);
return new Binding
{
Path = text2,
Control = control,
Role = VisibilityPolicy.Classify(control)
};
}
private static Binding BindingOf(Text t)
{
return cache.GetValue(t, create);
}
internal static int Target(Text t, int original)
{
if (original <= 0 || !Active || (Object)(object)t == (Object)null)
{
return 0;
}
if (!BoostPolicy.Candidate(BindingOf(t).Control))
{
return 0;
}
float num = CanvasScale(t);
if (num <= 0f)
{
return 0;
}
int num2 = (int)Math.Round((float)boost / num, MidpointRounding.AwayFromZero);
if (num2 < 1)
{
num2 = 1;
}
return (int)Math.Min(96L, (long)original + (long)num2);
}
internal static float CanvasScale(Text t)
{
Canvas val = (((Object)(object)t != (Object)null) ? ((Graphic)t).canvas : null);
Canvas val2 = (((Object)(object)val != (Object)null) ? val.rootCanvas : null);
float num = (((Object)(object)val2 != (Object)null) ? val2.scaleFactor : 0f);
if (!(num > 0f) || float.IsNaN(num) || float.IsInfinity(num))
{
return 0f;
}
return num;
}
internal static int Effective(Text t)
{
if ((Object)(object)t == (Object)null)
{
return 0;
}
int num = Target(t, t.fontSize);
if (num != 0)
{
return num;
}
return t.fontSize;
}
internal static void ForgetText(Text __instance)
{
if (Active)
{
cache.Remove(__instance);
}
}
internal static void ForgetGraphic(Graphic __instance)
{
if (Active)
{
Text val = (Text)(object)((__instance is Text) ? __instance : null);
if (val != null)
{
cache.Remove(val);
}
}
}
private static void ContextOf(Text t, Binding b)
{
if (!b.ContextReady)
{
b.Input = ((Component)t).GetComponentInParent<InputField>(true);
b.Clipped = (Object)(object)((Component)t).GetComponentInParent<Mask>(true) != (Object)null || (Object)(object)((Component)t).GetComponentInParent<RectMask2D>(true) != (Object)null || (Object)(object)((Component)t).GetComponentInParent<ScrollRect>(true) != (Object)null;
b.ContextReady = true;
}
}
internal static void BeginTextMeasure(Text __instance, out MeasureFrame __state)
{
__state = default(MeasureFrame);
if (NeedMeasure)
{
__state = new MeasureFrame(measuring);
measuring = __instance;
}
}
internal static void BeginInputMeasure(InputField __instance, out MeasureFrame __state)
{
__state = default(MeasureFrame);
if (NeedMeasure)
{
__state = new MeasureFrame(measuring);
measuring = __instance.textComponent;
}
}
internal static void EndMeasure(MeasureFrame __state)
{
if (__state.Entered)
{
measuring = __state.Previous;
}
}
private static VisibilityPolicy.Result Choose(Text t, Font font, int original, int requested, Vector2 box, bool wraps, bool truncates, bool fit)
{
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
if (requested == 0 || requested == original)
{
return default(VisibilityPolicy.Result);
}
Binding binding = BindingOf(t);
ContextOf(t, binding);
int num = 0;
int num2 = 0;
if (fit)
{
num = t.resizeTextMinSize;
num2 = t.resizeTextMaxSize;
if (t.useMeshGenerator)
{
num = Math.Max(num, 3);
num2 = Math.Min(num2, t.fontSize * 2);
}
}
return VisibilityPolicy.Plan(binding.Role, original, requested, box.x, box.y, VisibilityPolicy.LineEm(font.lineHeight, font.fontSize), t.text, (Object)(object)binding.Input != (Object)null, (Object)(object)binding.Input != (Object)null && binding.Input.multiLine, binding.Clipped, wraps, truncates, fit, num, num2, t == measuring);
}
internal static void Mesh(Text __instance, ref TextGenerationSettings __result)
{
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Invalid comparison between Unknown and I4
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Invalid comparison between Unknown and I4
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
if (!Active || (Object)(object)__result.font == (Object)null)
{
return;
}
bool dynamic = __result.font.dynamic;
int num = (dynamic ? __result.fontSize : __instance.fontSize);
VisibilityPolicy.Result result = Choose(__instance, __result.font, num, Target(__instance, num), __result.generationExtents, (int)__result.horizontalOverflow == 0, (int)__result.verticalOverflow == 0, __result.resizeTextForBestFit);
if (result.Size > 0)
{
if (dynamic)
{
__result.fontSize = result.Size;
}
__result.resizeTextForBestFit = false;
if (result.OpenWidth)
{
__result.horizontalOverflow = (HorizontalWrapMode)1;
}
if (result.OpenHeight)
{
__result.verticalOverflow = (VerticalWrapMode)1;
}
if (dynamic && result.Size > num && __result.use2xTexture && VisibilityPolicy.AvoidExtraSampling(result.Size, __instance.pixelsPerUnit))
{
__result.use2xTexture = false;
}
}
}
internal static void Tiny(Text __instance, ref TextGenerationMinimalSettings __result)
{
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
if (!Active || (Object)(object)__result.font == (Object)null || !__result.font.dynamic)
{
return;
}
int fontSize = __result.fontSize;
VisibilityPolicy.Result result = Choose(__instance, __result.font, fontSize, Target(__instance, fontSize), __result.generationExtents, wraps: false, truncates: false, fit: false);
if (result.Size > 0)
{
__result.fontSize = result.Size;
if (result.Size > fontSize && __result.use2xTexture && VisibilityPolicy.AvoidExtraSampling(result.Size, __instance.pixelsPerUnit))
{
__result.use2xTexture = false;
}
}
}
internal static void Legacy(Text __instance, ref TextGenerationSettings __result)
{
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Invalid comparison between Unknown and I4
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Invalid comparison between Unknown and I4
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
if (!Active || (Object)(object)__result.font == (Object)null)
{
return;
}
bool dynamic = __result.font.dynamic;
int original = (dynamic ? __result.fontSize : __instance.fontSize);
VisibilityPolicy.Result result = Choose(__instance, __result.font, original, Target(__instance, original), __result.generationExtents, (int)__result.horizontalOverflow == 0, (int)__result.verticalOverflow == 0, __result.resizeTextForBestFit);
if (result.Size > 0)
{
if (dynamic)
{
__result.fontSize = result.Size;
}
__result.resizeTextForBestFit = false;
if (result.OpenWidth)
{
__result.horizontalOverflow = (HorizontalWrapMode)1;
}
if (result.OpenHeight)
{
__result.verticalOverflow = (VerticalWrapMode)1;
}
}
}
internal static void Pixels(Text __instance, ref float __result)
{
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Invalid comparison between Unknown and I4
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Invalid comparison between Unknown and I4
if (!Active)
{
return;
}
Font font = __instance.font;
if (!((Object)(object)font == (Object)null) && !font.dynamic && font.fontSize > 0)
{
int fontSize = __instance.fontSize;
Rect rect = ((Graphic)__instance).rectTransform.rect;
VisibilityPolicy.Result result = Choose(__instance, font, fontSize, Target(__instance, fontSize), ((Rect)(ref rect)).size, (int)__instance.horizontalOverflow == 0, (int)__instance.verticalOverflow == 0, __instance.resizeTextForBestFit);
if (result.Size > 0)
{
__result = __result * (float)fontSize / (float)result.Size;
}
}
}
internal static void Install(Harmony h)
{
Hook(h, typeof(Text), "GetMeshGenerationSettings", "Mesh");
Hook(h, typeof(Text), "GetMeshGenerationMinimalSettings", "Tiny");
Hook(h, typeof(Text), "GetGenerationSettings", "Legacy");
Hook(h, typeof(Text), "get_pixelsPerUnit", "Pixels");
MeasureHook(h, typeof(Text), "get_preferredWidth", "BeginTextMeasure");
MeasureHook(h, typeof(Text), "get_preferredHeight", "BeginTextMeasure");
MeasureHook(h, typeof(InputField), "get_preferredWidth", "BeginInputMeasure");
MeasureHook(h, typeof(InputField), "get_preferredHeight", "BeginInputMeasure");
Hook(h, typeof(Text), "OnEnable", "ForgetText", before: true);
Hook(h, typeof(Graphic), "OnTransformParentChanged", "ForgetGraphic", before: true);
Hook(h, typeof(Graphic), "OnCanvasHierarchyChanged", "ForgetGraphic", before: true);
}
private static void MeasureHook(Harmony h, Type t, string getter, string enter)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Expected O, but got Unknown
//IL_0069: Expected O, but got Unknown
MethodInfo methodInfo = AccessTools.DeclaredMethod(t, getter, (Type[])null, (Type[])null) ?? throw new MissingMethodException(t.FullName, getter);
h.Patch((MethodBase)methodInfo, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Display), enter, (Type[])null, (Type[])null))
{
priority = 800
}, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Display), "EndMeasure", (Type[])null, (Type[])null))
{
priority = 0
}, (HarmonyMethod)null);
}
private static void Hook(Harmony h, Type t, string original, string patch, bool before = false)
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Expected O, but got Unknown
MethodInfo methodInfo = AccessTools.DeclaredMethod(t, original, (Type[])null, (Type[])null) ?? throw new MissingMethodException(t.FullName, original);
HarmonyMethod val = new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Display), patch, (Type[])null, (Type[])null));
if (before)
{
h.Patch((MethodBase)methodInfo, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
else
{
h.Patch((MethodBase)methodInfo, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
}
}
internal static class GameOptionRow
{
private const string RowName = "text-size-boost";
private static readonly int[] Pixels = new int[7] { 0, 2, 4, 6, 8, 10, 12 };
private static bool warned;
internal static void Install(Harmony harmony)
{
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Expected O, but got Unknown
MethodInfo methodInfo = AccessTools.DeclaredMethod(typeof(UIOptionWindow), "TempOptionToUI", (Type[])null, (Type[])null);
if (methodInfo == null)
{
Warn("The options window refresh was not found; the text-size slider is not added.");
return;
}
MethodInfo methodInfo2 = AccessTools.DeclaredMethod(typeof(GameOptionRow), "AfterRefresh", (Type[])null, (Type[])null);
harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
private static void AfterRefresh(UIOptionWindow __instance)
{
try
{
Ensure(__instance);
}
catch (Exception ex)
{
Warn("The text-size slider could not be added: " + ex.Message);
}
}
private static void Ensure(UIOptionWindow window)
{
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_0193: Unknown result type (might be due to invalid IL or missing references)
//IL_019f: Unknown result type (might be due to invalid IL or missing references)
//IL_01af: Unknown result type (might be due to invalid IL or missing references)
//IL_0161: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_0173: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
Slider val = (((Object)(object)window != (Object)null) ? window.uiLayoutHeightComp : null);
if ((Object)(object)val == (Object)null)
{
return;
}
Transform parent = ((Component)val).transform.parent;
Transform val2 = (((Object)(object)parent != (Object)null) ? parent.parent : null);
if ((Object)(object)parent == (Object)null || (Object)(object)val2 == (Object)null)
{
return;
}
Transform val3 = val2.Find("text-size-boost");
if ((Object)(object)val3 != (Object)null)
{
Sync(val3);
return;
}
RectTransform component = ((Component)parent).GetComponent<RectTransform>();
GameObject val4 = Object.Instantiate<GameObject>(((Component)parent).gameObject, val2, false);
((Object)val4).name = "text-size-boost";
val4.SetActive(false);
RectTransform component2 = val4.GetComponent<RectTransform>();
float num = (((Object)(object)component != (Object)null) ? component.anchoredPosition.y : 0f);
for (int i = 0; i < val2.childCount; i++)
{
Transform child = val2.GetChild(i);
RectTransform val5 = (RectTransform)(object)((child is RectTransform) ? child : null);
if (!((Object)(object)val5 == (Object)null) && !((Object)(object)val5 == (Object)(object)component2) && !((Object)(object)val5 == (Object)(object)component) && val5.anchoredPosition.y < num - 10f)
{
val5.anchoredPosition = new Vector2(val5.anchoredPosition.x, val5.anchoredPosition.y - 40f);
}
}
if ((Object)(object)component2 != (Object)null)
{
component2.anchoredPosition = new Vector2(((Object)(object)component != (Object)null) ? component.anchoredPosition.x : 0f, num - 40f);
}
RectTransform val6 = (RectTransform)(object)((val2 is RectTransform) ? val2 : null);
if ((Object)(object)val6 != (Object)null)
{
val6.sizeDelta = new Vector2(val6.sizeDelta.x, val6.sizeDelta.y + 40f);
}
Build(val4);
val4.SetActive(true);
Sync(val4.transform);
}
private static void Build(GameObject clone)
{
StripLocalizers(clone);
Text component = clone.GetComponent<Text>();
if ((Object)(object)component != (Object)null)
{
component.text = Language.Pick("文本字号放大", "Text size boost");
component.alignment = (TextAnchor)3;
}
Transform val = clone.transform.Find("Text");
if ((Object)(object)val != (Object)null)
{
Text component2 = ((Component)val).GetComponent<Text>();
if ((Object)(object)component2 != (Object)null)
{
component2.text = Notice();
component2.alignment = (TextAnchor)3;
component2.horizontalOverflow = (HorizontalWrapMode)1;
component2.verticalOverflow = (VerticalWrapMode)1;
}
}
Slider slider = clone.GetComponentInChildren<Slider>(true);
if ((Object)(object)slider != (Object)null)
{
slider.minValue = 0f;
slider.maxValue = Pixels.Length - 1;
slider.wholeNumbers = true;
((UnityEventBase)slider.onValueChanged).RemoveAllListeners();
((UnityEvent<float>)(object)slider.onValueChanged).AddListener((UnityAction<float>)delegate
{
OnSlide(slider);
});
}
}
private static string Notice()
{
return Language.Pick("【注意:字号放大仅针对部分可放大文本有效,且放大后可能会出现文本重叠】", "[Note] Font scaling only applies to some scalable text, and enlarged text may overlap.");
}
private static void Sync(Transform row)
{
Text component = ((Component)row).GetComponent<Text>();
if ((Object)(object)component != (Object)null)
{
component.text = Language.Pick("文本字号放大", "Text size boost");
}
Transform val = row.Find("Text");
Text val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<Text>() : null);
if ((Object)(object)val2 != (Object)null && val2.text != Notice())
{
val2.text = Notice();
}
Slider slider = ((Component)row).GetComponentInChildren<Slider>(true);
if (!((Object)(object)slider == (Object)null))
{
int num = Index(Mathf.Clamp(Display.Boost, 0, 12));
((UnityEventBase)slider.onValueChanged).RemoveAllListeners();
slider.value = num;
((UnityEvent<float>)(object)slider.onValueChanged).AddListener((UnityAction<float>)delegate
{
OnSlide(slider);
});
UpdateValueText(row, num);
}
}
private static void OnSlide(Slider slider)
{
int num = Mathf.Clamp(Mathf.RoundToInt(slider.value), 0, Pixels.Length - 1);
Plugin.ApplyBoost(Pixels[num]);
UpdateValueText(((Component)slider).transform.parent, num);
}
private static void UpdateValueText(Transform row, int index)
{
Transform val = row.Find("Slider/Handle Slide Area/Handle/Text");
Text val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<Text>() : null);
if (!((Object)(object)val2 == (Object)null))
{
val2.text = ((Pixels[index] == 0) ? Language.Pick("关闭", "Off") : ("+" + Pixels[index]));
}
}
private static int Index(int pixels)
{
for (int i = 0; i < Pixels.Length; i++)
{
if (Pixels[i] == pixels)
{
return i;
}
}
return 0;
}
private static void StripLocalizers(GameObject target)
{
Component[] componentsInChildren = target.GetComponentsInChildren<Component>(true);
foreach (Component val in componentsInChildren)
{
if (!((Object)(object)val == (Object)null))
{
string name = ((object)val).GetType().Name;
if (name.IndexOf("Localiz", StringComparison.Ordinal) >= 0 || name.IndexOf("Translate", StringComparison.Ordinal) >= 0)
{
Object.Destroy((Object)(object)val);
}
}
}
}
private static void Warn(string message)
{
if (!warned)
{
warned = true;
ManualLogSource logSource = Plugin.LogSource;
if (logSource != null)
{
logSource.LogWarning((object)message);
}
}
}
}
internal static class Language
{
internal static Func<bool> IsChinese = () => false;
internal static string Pick(string zh, string en)
{
if (!IsChinese())
{
return en;
}
return zh;
}
}
[BepInPlugin("TTenYX.TextBoost", "TextBoost", "0.0.1")]
[BepInProcess("DSPGAME.exe")]
public sealed class Plugin : BaseUnityPlugin
{
internal const string Guid = "TTenYX.TextBoost";
internal const string Version = "0.0.1";
internal static ManualLogSource LogSource;
private static Plugin instance;
private static string store;
private static int boost;
private Harmony patches;
private void Awake()
{
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Expected O, but got Unknown
LogSource = ((BaseUnityPlugin)this).Logger;
instance = this;
Language.IsChinese = () => (Localization.CurrentLanguageLCID & 0x3FF) == 4;
Catalog catalog = LoadCatalog();
Display.Initialize(catalog);
store = Path.Combine(Paths.ConfigPath, "TTenYX.TextBoost.txt");
boost = ReadStored();
Display.SetBoost(boost);
try
{
patches = new Harmony("TTenYX.TextBoost");
Display.Install(patches);
GameOptionRow.Install(patches);
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)("TextBoost could not install its patches: " + ex));
}
((BaseUnityPlugin)this).Logger.LogInfo((object)("TextBoost ready | v0.0.1 | boost=" + boost + "px | sections=" + catalog.Sections.Count + " | state=" + store));
}
internal static void ApplyBoost(int pixels)
{
pixels = Math.Max(0, Math.Min(12, pixels));
if (pixels == boost)
{
return;
}
boost = pixels;
Display.SetBoost(boost);
try
{
File.WriteAllText(store, boost.ToString(CultureInfo.InvariantCulture));
}
catch (Exception ex)
{
ManualLogSource logSource = LogSource;
if (logSource != null)
{
logSource.LogWarning((object)("Could not save the text size boost: " + ex.Message));
}
}
}
private static int ReadStored()
{
try
{
if (!File.Exists(store))
{
return 0;
}
if (int.TryParse(File.ReadAllText(store).Trim(), NumberStyles.Integer, CultureInfo.InvariantCulture, out var result))
{
return Math.Max(0, Math.Min(12, result));
}
}
catch (Exception ex)
{
ManualLogSource logSource = LogSource;
if (logSource != null)
{
logSource.LogWarning((object)("Could not read the saved text size boost: " + ex.Message));
}
}
return 0;
}
private static Catalog LoadCatalog()
{
using Stream stream = typeof(Plugin).Assembly.GetManifestResourceStream("TextBoost.Controls") ?? throw new InvalidOperationException("Embedded control catalog is missing.");
using StreamReader reader = new StreamReader(stream);
return Catalog.Read(reader);
}
private void OnDestroy()
{
try
{
Display.SetBoost(0);
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)ex.Message);
}
try
{
Harmony obj = patches;
if (obj != null)
{
obj.UnpatchSelf();
}
}
finally
{
Display.Dispose();
LogSource = null;
instance = null;
}
}
}
internal static class VisibilityPolicy
{
internal readonly struct Result
{
internal readonly int Size;
internal readonly bool OpenWidth;
internal readonly bool OpenHeight;
internal Result(int size, bool width = false, bool height = false)
{
Size = size;
OpenWidth = width;
OpenHeight = height;
}
}
internal enum Role
{
Ordinary,
Readout,
Flow,
Vein
}
internal static Role Classify(Control c)
{
if (c == null)
{
return Role.Ordinary;
}
string key = c.Key;
if (c.Section == "World.Veins")
{
return Role.Vein;
}
if (c.Section == "Tooltip.Item" || c.Section == "Tooltip.Button" || key.IndexOf("Description", StringComparison.Ordinal) >= 0 || key.IndexOf("Hint", StringComparison.Ordinal) >= 0 || key.IndexOf("ShareCode", StringComparison.Ordinal) >= 0 || key == "History" || key == "Unlock")
{
return Role.Flow;
}
if (!key.EndsWith("Count", StringComparison.Ordinal) && !key.EndsWith("Amount", StringComparison.Ordinal) && !key.EndsWith("Value", StringComparison.Ordinal))
{
switch (key)
{
default:
if (!key.StartsWith("Reading", StringComparison.Ordinal))
{
return Role.Ordinary;
}
break;
case "Power":
case "Speed":
case "SlotLabel":
break;
}
}
return Role.Readout;
}
private static bool Positive(float n)
{
if (n > 0f)
{
return !float.IsInfinity(n);
}
return false;
}
private static float ShortAdvance(string s)
{
if (s == null || s.Length == 0)
{
return 0f;
}
if (s.Length > 40)
{
return -1f;
}
int i = 0;
int num;
for (num = s.Length; i < num && s[i] == ' '; i++)
{
}
while (num > i && s[num - 1] == ' ')
{
num--;
}
float num2 = 0f;
for (int j = i; j < num; j++)
{
char c = s[j];
if (c == '\r' || c == '\n' || c == '\t' || c == '<' || c == '>' || c == '\u2028' || c == '\u2029' || char.IsSurrogate(c))
{
return -1f;
}
num2 = ((c != ' ' && c != '\u00a0' && c != '\u202f') ? ((c < '⺀') ? ((c >= '\u0080' || (!char.IsPunctuation(c) && c != '|')) ? (num2 + ((c >= 'A' && c <= 'Z') ? 0.69f : 0.56f)) : (num2 + 0.4f)) : (num2 + 1f)) : (num2 + 0.32f));
}
return num2;
}
internal static float LineEm(int height, int imported)
{
if (height <= 0 || imported <= 0)
{
return 1.5f;
}
return Math.Min(3f, Math.Max(0.8f, (float)height / (float)imported));
}
private static int Limit(float room, float cost, int current)
{
if (!Positive(room) || !Positive(cost))
{
return current;
}
float num = room / cost;
if (!(num >= (float)current))
{
return Math.Max(1, (int)Math.Floor(num));
}
return current;
}
internal static Result Plan(Role role, int native, int target, float width, float height, float lineEm, string text, bool input, bool multilineInput, bool masked, bool wraps, bool truncates, bool nativeFit, int minFit, int maxFit, bool natural)
{
if (native < 1 || target < 1 || target == native)
{
return default(Result);
}
if (target < native)
{
if (nativeFit && truncates && maxFit > minFit && target >= minFit && Positive(width) && Positive(height) && !natural)
{
float num = ShortAdvance(text);
if ((float)target * lineEm > height + 1f || (wraps && num > 0f && num * (float)target > width * (float)Math.Max(1, (int)(height / (lineEm * (float)target)))))
{
return default(Result);
}
}
return new Result(target);
}
if (role == Role.Vein && !input && !masked)
{
return new Result(target, width: true, height: true);
}
if (!Positive(height) || !Positive(width))
{
return new Result(target);
}
float num2 = ShortAdvance(text);
bool flag = role == Role.Readout && num2 >= 0f;
bool flag2 = !input && role != Role.Flow && num2 >= 0f && (flag || height <= (float)native * lineEm * 1.9f);
bool flag3 = input || masked;
if (!flag2 && ((!truncates && !input) || (natural && wraps && (role == Role.Flow || multilineInput || !input))))
{
return new Result(target);
}
int num3 = Limit(height * ((flag2 && !flag3) ? 1.6f : 1f), lineEm, target);
if (flag2 && !nativeFit && num2 > 0f)
{
num3 = Limit(width * (flag3 ? 1f : 1.35f), num2, num3);
}
bool flag4 = num2 > 0f && width > 0f && (float)target * num2 > width;
if (nativeFit && truncates && maxFit > minFit && maxFit > 0 && maxFit <= target && (num3 <= maxFit || (wraps && (num2 < 0f || num2 * (float)num3 > width * (float)Math.Max(1, (int)(height / ((float)num3 * lineEm)))))))
{
return default(Result);
}
if (flag3 && num3 <= native && target > native)
{
return default(Result);
}
num3 = Math.Max(native, num3);
bool flag5 = flag2 && !flag3;
bool width2 = flag5 && (flag || (wraps && flag4 && text != null && text.Length <= 24));
return new Result(num3, width2, flag5);
}
internal static bool AvoidExtraSampling(int size, float pixelsPerUnit)
{
if (size < 1 || !Positive(pixelsPerUnit))
{
return false;
}
float num = 1f / pixelsPerUnit;
float num2 = Math.Max(0.25f, (num > 1f) ? (num * 0.5f) : Math.Min(num, 0.5f));
float num3 = Math.Max(0.25f, num);
if (num2 < num3)
{
return (float)size / num2 > 128.4999f;
}
return false;
}
}
}