Decompiled source of AugaJpnPatch v0.2.0

AugaJpnPatch.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("AugaJpnPatch")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AugaJpnPatch")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("14a631e7-8e8e-455a-9580-121e85a9c051")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace AugaJpnPatch;

[BepInPlugin("Nakia.augajpnpatch", "Auga JPN Patch", "0.2.0")]
public class Plugin : BaseUnityPlugin
{
	private sealed class OriginalFont
	{
		public TMP_Text Text;

		public TMP_FontAsset Font;
	}

	private const string TargetFontName = "NotoSansJP-Regular SDF";

	private const float ScanInterval = 0.5f;

	private static readonly string[] AugaUiRoots = new string[8] { "Auga", "EnchantingUI", "InventoryGui", "StoreGui", "Compendium", "Crafting", "Settings", "Inventory_screen" };

	private const string KeyboardPath = "panel/Tabs/KeyboardMouse/AugaContent/ItemListBkg/Mask/ItemList/KeyBindings";

	private TMP_FontAsset _japaneseFont;

	private float _nextScan;

	private Harmony _harmony;

	private static Plugin _instance;

	private bool _isApplying;

	private int _backupWarningId;

	private bool _backupPositioned;

	private Transform _settingsRoot;

	private Transform _lastActiveSettingsPage;

	private readonly HashSet<int> _upgradeTitleAdjusted = new HashSet<int>();

	private readonly Dictionary<int, OriginalFont> _changed = new Dictionary<int, OriginalFont>();

	private void Awake()
	{
		_instance = this;
		((BaseUnityPlugin)this).Logger.LogInfo((object)"[AUGA JPN PATCH] Started v0.2.0");
		TMPro_EventManager.TEXT_CHANGED_EVENT.Add((Action<Object>)OnTextChanged);
		InstallEarlyFontPatches();
		InstallSettingsPatches();
	}

	private void LateUpdate()
	{
		Transform settingsRoot = _settingsRoot;
		if ((Object)(object)settingsRoot == (Object)null || !((Component)settingsRoot).gameObject.activeInHierarchy)
		{
			_lastActiveSettingsPage = null;
			return;
		}
		try
		{
			Transform val = settingsRoot.Find("panel/Tabs/KeyboardMouse");
			if ((Object)(object)val == (Object)null || !((Component)val).gameObject.activeInHierarchy)
			{
				val = settingsRoot.Find("panel/Tabs/Graphics");
				if ((Object)(object)val == (Object)null || !((Component)val).gameObject.activeInHierarchy)
				{
					val = settingsRoot.Find("panel/Tabs/Gameplay");
				}
			}
			if ((Object)(object)val == (Object)null || !((Component)val).gameObject.activeInHierarchy)
			{
				val = null;
			}
			if (!((Object)(object)val == (Object)(object)_lastActiveSettingsPage))
			{
				_lastActiveSettingsPage = val;
				if (!((Object)(object)val == (Object)null))
				{
					FixKeyboardSettings(settingsRoot);
					FixGraphicsSettings(settingsRoot);
					FixBackupWarning(settingsRoot);
				}
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("[AUGA JPN SETTINGS] Tab change error: " + ex));
		}
	}

	private void Update()
	{
		if (Time.unscaledTime < _nextScan)
		{
			return;
		}
		_nextScan = Time.unscaledTime + 0.5f;
		try
		{
			UpdateSettings();
			FindJapaneseFont();
			if (!((Object)(object)_japaneseFont == (Object)null))
			{
				CleanupDestroyedObjects();
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("[AUGA JPN PATCH] Error: " + ex));
		}
	}

	private void OnTextChanged(Object obj)
	{
		TMP_Text val = (TMP_Text)(object)((obj is TMP_Text) ? obj : null);
		if ((Object)(object)val == (Object)null || _isApplying)
		{
			return;
		}
		try
		{
			RememberSettingsRoot(val.transform);
			FindJapaneseFont();
			if ((Object)(object)_japaneseFont != (Object)null)
			{
				ProcessText(val);
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("[AUGA JPN PATCH] Text change error: " + ex));
		}
	}

	private void InstallEarlyFontPatches()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		_harmony = new Harmony("Nakia.augajpnpatch.earlyfont");
		MethodInfo method = typeof(Plugin).GetMethod("BeforeTextMesh", BindingFlags.Static | BindingFlags.NonPublic);
		MethodInfo method2 = typeof(Plugin).GetMethod("AfterTextAssigned", BindingFlags.Static | BindingFlags.NonPublic);
		TryPatch(typeof(TextMeshProUGUI), "OnPreRenderCanvas", method, null);
		TryPatch(typeof(TextMeshProUGUI), "GenerateTextMesh", method, null);
		TryPatch(typeof(TextMeshPro), "GenerateTextMesh", method, null);
		TryPatch(typeof(TMP_Text), "set_text", null, method2);
	}

	private void TryPatch(Type type, string name, MethodInfo prefix, MethodInfo postfix)
	{
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			MethodInfo methodInfo = AccessTools.Method(type, name, (Type[])null, (Type[])null);
			if (methodInfo == null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("[AUGA JPN EARLY] Not found: " + type.Name + "." + name));
			}
			else
			{
				_harmony.Patch((MethodBase)methodInfo, (prefix == null) ? ((HarmonyMethod)null) : new HarmonyMethod(prefix), (postfix == null) ? ((HarmonyMethod)null) : new HarmonyMethod(postfix), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("[AUGA JPN EARLY] Patch failed: " + type.Name + "." + name + " | " + ex));
		}
	}

	private static void BeforeTextMesh(TMP_Text __instance)
	{
		if ((Object)(object)_instance != (Object)null)
		{
			_instance.TryProcessEarly(__instance);
		}
	}

	private static void AfterTextAssigned(TMP_Text __instance)
	{
		if ((Object)(object)_instance != (Object)null)
		{
			_instance.TryProcessEarly(__instance);
		}
	}

	private void TryProcessEarly(TMP_Text text)
	{
		if (_isApplying || (Object)(object)text == (Object)null)
		{
			return;
		}
		try
		{
			FindJapaneseFont();
			if ((Object)(object)_japaneseFont != (Object)null)
			{
				ProcessText(text);
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("[AUGA JPN EARLY] Apply error: " + ex));
		}
	}

	private void ScanTexts()
	{
		TMP_Text[] array = Resources.FindObjectsOfTypeAll<TMP_Text>();
		TMP_Text[] array2 = array;
		foreach (TMP_Text text in array2)
		{
			ProcessText(text);
		}
	}

	private void ProcessText(TMP_Text text)
	{
		if ((Object)(object)text == (Object)null || !((Component)text).gameObject.activeInHierarchy || (Object)(object)_japaneseFont == (Object)null || _isApplying)
		{
			return;
		}
		_isApplying = true;
		try
		{
			if (FixWorldSelectionTab(text))
			{
				return;
			}
			FixWorldDifficulty(text);
			if (IsAugaUiText(text) && IsCurrentPlayerName(text))
			{
				int instanceID = ((Object)text).GetInstanceID();
				if (_changed.TryGetValue(instanceID, out var value))
				{
					if ((Object)(object)value.Font != (Object)null)
					{
						text.font = value.Font;
					}
					_changed.Remove(instanceID);
				}
			}
			else
			{
				if (IsDungeonTitle(text) || IsMiniMapBiome(text))
				{
					ApplyJapaneseFont(text);
				}
				if (ContainsJapanese(text.text ?? "") && (IsAugaUiText(text) || IsCraftWorkbenchName(text)))
				{
					ApplyJapaneseFont(text);
					AdjustUpgradeTitleOnce(text);
				}
			}
		}
		finally
		{
			_isApplying = false;
		}
	}

	private static bool IsCurrentPlayerName(TMP_Text text)
	{
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null || (Object)(object)text == (Object)null)
		{
			return false;
		}
		string playerName = localPlayer.GetPlayerName();
		return !string.IsNullOrEmpty(playerName) && string.Equals((text.text ?? "").Trim(), playerName.Trim(), StringComparison.Ordinal);
	}

	private static bool IsDungeonTitle(TMP_Text text)
	{
		if (((Object)((Component)text).gameObject).name != "Title")
		{
			return false;
		}
		string text2 = (text.text ?? "").Trim();
		return text2 == "吠える洞くつ" || text2 == "埋葬室";
	}

	private static bool IsMiniMapBiome(TMP_Text text)
	{
		if (((Object)((Component)text).gameObject).name != "Content")
		{
			return false;
		}
		Transform transform = text.transform;
		if ((Object)(object)transform.parent == (Object)null || ((Object)transform.parent).name != "biome")
		{
			return false;
		}
		transform = transform.parent;
		if ((Object)(object)transform.parent == (Object)null || ((Object)transform.parent).name != "small")
		{
			return false;
		}
		transform = transform.parent;
		return (Object)(object)transform.parent != (Object)null && ((Object)transform.parent).name == "MiniMap";
	}

	private static bool IsAugaUiText(TMP_Text text)
	{
		Transform val = text.transform;
		while ((Object)(object)val != (Object)null)
		{
			string name = ((Object)val).name;
			for (int i = 0; i < AugaUiRoots.Length; i++)
			{
				if (name.StartsWith(AugaUiRoots[i], StringComparison.OrdinalIgnoreCase))
				{
					return true;
				}
			}
			val = val.parent;
		}
		return false;
	}

	private static bool IsCraftWorkbenchName(TMP_Text text)
	{
		if (((Object)((Component)text).gameObject).name != "WorkbenchName")
		{
			return false;
		}
		Transform parent = text.transform.parent;
		while ((Object)(object)parent != (Object)null)
		{
			if (((Object)parent).name.StartsWith("InventoryGui", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			parent = parent.parent;
		}
		return false;
	}

	private void AdjustUpgradeTitleOnce(TMP_Text text)
	{
		if (!(((Object)((Component)text).gameObject).name != "Title") && !((Object)(object)text.transform.parent == (Object)null) && !(((Object)text.transform.parent).name != "UpgradeContent") && !(text.text != "付呪机のアップグレード"))
		{
			int instanceID = ((Object)text).GetInstanceID();
			if (_upgradeTitleAdjusted.Add(instanceID))
			{
				float fontSize = text.fontSize;
				text.enableAutoSizing = true;
				text.fontSizeMin = 14f;
				text.fontSizeMax = fontSize;
				text.overflowMode = (TextOverflowModes)3;
			}
		}
	}

	private void ApplyJapaneseFont(TMP_Text text)
	{
		if (!((Object)(object)text.font == (Object)(object)_japaneseFont))
		{
			int instanceID = ((Object)text).GetInstanceID();
			if (!_changed.ContainsKey(instanceID))
			{
				_changed[instanceID] = new OriginalFont
				{
					Text = text,
					Font = text.font
				};
			}
			text.font = _japaneseFont;
		}
	}

	private static bool ContainsJapanese(string value)
	{
		foreach (char c in value)
		{
			if ((c >= '\u3040' && c <= 'ヿ') || (c >= '㐀' && c <= '鿿') || (c >= '豈' && c <= '\ufaff'))
			{
				return true;
			}
		}
		return false;
	}

	private void FindJapaneseFont()
	{
		if ((Object)(object)_japaneseFont != (Object)null)
		{
			return;
		}
		TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
		foreach (TMP_FontAsset val in array)
		{
			if ((Object)(object)val != (Object)null && ((Object)val).name == "NotoSansJP-Regular SDF")
			{
				_japaneseFont = val;
				((BaseUnityPlugin)this).Logger.LogInfo((object)("[AUGA JPN PATCH] Found vanilla font: " + ((Object)val).name));
				break;
			}
		}
	}

	private void CleanupDestroyedObjects()
	{
		List<int> list = new List<int>();
		foreach (KeyValuePair<int, OriginalFont> item in _changed)
		{
			if ((Object)(object)item.Value.Text == (Object)null)
			{
				list.Add(item.Key);
			}
		}
		foreach (int item2 in list)
		{
			_changed.Remove(item2);
			_upgradeTitleAdjusted.Remove(item2);
		}
	}

	private static bool FixWorldSelectionTab(TMP_Text text)
	{
		if ((Object)(object)text == (Object)null)
		{
			return false;
		}
		Transform val = text.transform;
		Transform val2 = null;
		while ((Object)(object)val != (Object)null && (Object)(object)val.parent != (Object)null)
		{
			if ((((Object)val).name == "StartGame" || ((Object)val).name == "JoinGame") && ((Object)val.parent).name == "Tabs" && (Object)(object)val.parent.parent != (Object)null && ((Object)val.parent.parent).name == "Panel")
			{
				val2 = val.parent;
				break;
			}
			val = val.parent;
		}
		if ((Object)(object)val2 == (Object)null)
		{
			return false;
		}
		Transform val3 = val2.parent.Find("WorldPanel/ManageSaves/Label");
		if ((Object)(object)val3 == (Object)null)
		{
			return false;
		}
		TMP_Text component = ((Component)val3).GetComponent<TMP_Text>();
		if ((Object)(object)component == (Object)null || (Object)(object)component.font == (Object)null)
		{
			return false;
		}
		text.font = component.font;
		text.fontSize = 24f;
		text.enableAutoSizing = false;
		text.overflowMode = (TextOverflowModes)0;
		text.ForceMeshUpdate(false, false);
		return true;
	}

	private static void FixWorldDifficulty(TMP_Text text)
	{
		if (!((Object)(object)text == (Object)null) && !(((Object)((Component)text).gameObject).name != "modifiers"))
		{
			Transform parent = text.transform.parent;
			if (!((Object)(object)parent == (Object)null) && ((Object)parent).name.StartsWith("WorldListElement", StringComparison.Ordinal))
			{
				text.fontSize = 18f;
				text.fontStyle = (FontStyles)1;
				text.enableAutoSizing = false;
			}
		}
	}

	private void InstallSettingsPatches()
	{
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Expected O, but got Unknown
		Type type = AccessTools.TypeByName("Auga.AugaSettingsBuilder");
		MethodInfo methodInfo = ((type != null) ? AccessTools.Method(type, "CreateWidget", (Type[])null, (Type[])null) : null);
		MethodInfo methodInfo2 = AccessTools.Method(typeof(Plugin), "CreateWidgetPostfix", (Type[])null, (Type[])null);
		if (methodInfo == null || methodInfo2 == null)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"[AUGA JPN SETTINGS] CreateWidget not found");
			return;
		}
		try
		{
			_harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"[AUGA JPN SETTINGS] CreateWidget patched");
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("[AUGA JPN SETTINGS] Patch failed: " + ex));
		}
	}

	private static void CreateWidgetPostfix(object __result)
	{
		if (__result == null)
		{
			return;
		}
		try
		{
			Type type = __result.GetType();
			FieldInfo fieldInfo = AccessTools.Field(type, "Label");
			TMP_Text val = (TMP_Text)((fieldInfo != null) ? /*isinst with value type is only supported in some contexts*/: null);
			if ((Object)(object)val == (Object)null)
			{
				FieldInfo fieldInfo2 = AccessTools.Field(type, "Root");
				Transform val2 = (Transform)((fieldInfo2 != null) ? /*isinst with value type is only supported in some contexts*/: null);
				if ((Object)(object)val2 != (Object)null)
				{
					val = ((Component)val2).GetComponentInChildren<TMP_Text>(true);
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				SetSettingsOverflow(val);
				if ((Object)(object)_instance != (Object)null)
				{
					_instance.RememberSettingsRoot(val.transform);
				}
			}
			FieldInfo fieldInfo3 = AccessTools.Field(type, "Root");
			if (fieldInfo3 != null && (Object)(object)_instance != (Object)null)
			{
				object? value = fieldInfo3.GetValue(__result);
				Transform val3 = (Transform)((value is Transform) ? value : null);
				if ((Object)(object)val3 != (Object)null)
				{
					_instance.RememberSettingsRoot(val3);
				}
			}
		}
		catch (Exception ex)
		{
			if ((Object)(object)_instance != (Object)null)
			{
				((BaseUnityPlugin)_instance).Logger.LogWarning((object)("[AUGA JPN SETTINGS] Widget error: " + ex));
			}
		}
	}

	private static void SetSettingsOverflow(TMP_Text label)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Invalid comparison between Unknown and I4
		if (!((Object)(object)label == (Object)null) && (int)label.overflowMode == 3)
		{
			label.overflowMode = (TextOverflowModes)0;
			((Graphic)label).SetVerticesDirty();
			((Graphic)label).SetLayoutDirty();
			((Graphic)label).SetMaterialDirty();
		}
	}

	private void RememberSettingsRoot(Transform source)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		Transform val = source;
		while ((Object)(object)val != (Object)null)
		{
			if (((Object)val).name.StartsWith("AugaSettings(Clone)", StringComparison.Ordinal))
			{
				Scene scene = ((Component)val).gameObject.scene;
				if (((Scene)(ref scene)).IsValid())
				{
					if ((Object)(object)_settingsRoot != (Object)(object)val)
					{
						_settingsRoot = val;
						_lastActiveSettingsPage = null;
						ResetBackupState();
						((BaseUnityPlugin)this).Logger.LogInfo((object)"[AUGA JPN SETTINGS] Cached settings root");
					}
					break;
				}
			}
			val = val.parent;
		}
	}

	private void UpdateSettings()
	{
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		Transform settingsRoot = _settingsRoot;
		if ((Object)(object)settingsRoot == (Object)null)
		{
			if ((Object)(object)_settingsRoot != (Object)null)
			{
				_settingsRoot = null;
			}
			ResetBackupState();
			return;
		}
		Scene scene = ((Component)settingsRoot).gameObject.scene;
		if (!((Scene)(ref scene)).IsValid() || !((Component)settingsRoot).gameObject.activeInHierarchy)
		{
			ResetBackupState();
			return;
		}
		FixKeyboardSettings(settingsRoot);
		FixGraphicsSettings(settingsRoot);
		FixBackupWarning(settingsRoot);
	}

	private void FixKeyboardSettings(Transform root)
	{
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Expected O, but got Unknown
		Transform val = root.Find("panel/Tabs/KeyboardMouse");
		if ((Object)(object)val == (Object)null || !((Component)val).gameObject.activeInHierarchy)
		{
			return;
		}
		Transform val2 = root.Find("panel/Tabs/KeyboardMouse/AugaContent/ItemListBkg/Mask/ItemList/KeyBindings");
		if ((Object)(object)val2 == (Object)null)
		{
			return;
		}
		foreach (Transform item in val2)
		{
			Transform val3 = item;
			Transform val4 = val3.Find("TMP Label");
			if (!((Object)(object)val4 == (Object)null))
			{
				TMP_Text component = ((Component)val4).GetComponent<TMP_Text>();
				SetSettingsOverflow(component);
			}
		}
	}

	private void FixGraphicsSettings(Transform root)
	{
		Transform val = root.Find("panel/Tabs/Graphics");
		if ((Object)(object)val == (Object)null || !((Component)val).gameObject.activeInHierarchy)
		{
			return;
		}
		TMP_Text[] componentsInChildren = ((Component)val).GetComponentsInChildren<TMP_Text>(true);
		TMP_Text[] array = componentsInChildren;
		foreach (TMP_Text val2 in array)
		{
			if (!((Object)(object)val2 == (Object)null) && ((Component)val2).gameObject.activeInHierarchy && ((Behaviour)val2).enabled && !string.IsNullOrEmpty(val2.text))
			{
				SetSettingsOverflow(val2);
			}
		}
	}

	private void FixBackupWarning(Transform root)
	{
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01df: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0209: Unknown result type (might be due to invalid IL or missing references)
		//IL_0220: Unknown result type (might be due to invalid IL or missing references)
		//IL_0230: Unknown result type (might be due to invalid IL or missing references)
		//IL_0235: Unknown result type (might be due to invalid IL or missing references)
		//IL_0254: Unknown result type (might be due to invalid IL or missing references)
		//IL_025d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0262: Unknown result type (might be due to invalid IL or missing references)
		//IL_026c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0275: Unknown result type (might be due to invalid IL or missing references)
		//IL_027a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0284: Unknown result type (might be due to invalid IL or missing references)
		Transform val = root.Find("panel/Tabs/Gameplay");
		if ((Object)(object)val == (Object)null || !((Component)val).gameObject.activeInHierarchy)
		{
			ResetBackupState();
			return;
		}
		Transform val2 = val.Find("AugaContent");
		if ((Object)(object)val2 == (Object)null)
		{
			return;
		}
		Transform val3 = val2.Find("FirstColumnWidgets");
		Transform val4 = val2.Find("SecondColumnWidgets");
		if ((Object)(object)val3 == (Object)null || (Object)(object)val4 == (Object)null)
		{
			return;
		}
		Transform obj = val3.Find("AutoBackups");
		RectTransform val5 = (RectTransform)(object)((obj is RectTransform) ? obj : null);
		if ((Object)(object)val5 == (Object)null)
		{
			return;
		}
		Transform obj2 = ((Transform)val5).Find("CloudStorageWarning");
		RectTransform val6 = (RectTransform)(object)((obj2 is RectTransform) ? obj2 : null);
		RectTransform val7 = (RectTransform)(object)((val4 is RectTransform) ? val4 : null);
		if ((Object)(object)val6 == (Object)null || (Object)(object)val7 == (Object)null)
		{
			return;
		}
		int instanceID = ((Object)val6).GetInstanceID();
		if (_backupWarningId != instanceID)
		{
			_backupWarningId = instanceID;
			_backupPositioned = false;
		}
		if (_backupPositioned)
		{
			return;
		}
		Transform parent = ((Transform)val6).parent;
		RectTransform val8 = (RectTransform)(object)((parent is RectTransform) ? parent : null);
		if ((Object)(object)val8 == (Object)null)
		{
			return;
		}
		Rect rect = val7.rect;
		if (((Rect)(ref rect)).width < 100f)
		{
			return;
		}
		rect = val7.rect;
		if (!(((Rect)(ref rect)).width > 600f))
		{
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			Vector3[] array2 = (Vector3[])(object)new Vector3[4];
			val5.GetWorldCorners(array);
			val7.GetWorldCorners(array2);
			Vector3 val9 = default(Vector3);
			((Vector3)(ref val9))..ctor(array2[1].x, array[1].y, array[1].z);
			Vector3 val10 = ((Transform)val8).InverseTransformPoint(val9);
			val6.anchorMin = new Vector2(0f, 1f);
			val6.anchorMax = new Vector2(0f, 1f);
			val6.pivot = new Vector2(0f, 1f);
			rect = val7.rect;
			val6.SetSizeWithCurrentAnchors((Axis)0, ((Rect)(ref rect)).width);
			val6.SetSizeWithCurrentAnchors((Axis)1, 70f);
			float x = val10.x;
			rect = val8.rect;
			float num = x - ((Rect)(ref rect)).xMin;
			float y = val10.y;
			rect = val8.rect;
			val6.anchoredPosition = new Vector2(num, y - ((Rect)(ref rect)).yMax);
			TMP_Text component = ((Component)val6).GetComponent<TMP_Text>();
			if ((Object)(object)component != (Object)null)
			{
				component.alignment = (TextAlignmentOptions)257;
				component.enableWordWrapping = true;
				component.overflowMode = (TextOverflowModes)0;
				((Graphic)component).SetVerticesDirty();
				((Graphic)component).SetLayoutDirty();
				((Graphic)component).SetMaterialDirty();
			}
			_backupPositioned = true;
		}
	}

	private void ResetBackupState()
	{
		_backupWarningId = 0;
		_backupPositioned = false;
	}

	private void OnDestroy()
	{
		TMPro_EventManager.TEXT_CHANGED_EVENT.Remove((Action<Object>)OnTextChanged);
		if (_harmony != null)
		{
			_harmony.UnpatchSelf();
		}
		if ((Object)(object)_instance == (Object)(object)this)
		{
			_instance = null;
		}
		foreach (OriginalFont value in _changed.Values)
		{
			if ((Object)(object)value.Text != (Object)null && (Object)(object)value.Font != (Object)null)
			{
				value.Text.font = value.Font;
			}
		}
		_settingsRoot = null;
		_changed.Clear();
		_upgradeTitleAdjusted.Clear();
	}
}