Decompiled source of KZT Currency v1.0.2

kztCurrency.dll

Decompiled 17 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[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("kossnikita")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("kztCurrency")]
[assembly: AssemblyTitle("kztCurrency")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 kztCurrency
{
	public static class CurrencyFormatter
	{
		private const string Nbsp = "\u00a0";

		private static readonly NumberFormatInfo NbspNumberFormat = new NumberFormatInfo
		{
			NumberGroupSeparator = "\u00a0",
			NumberDecimalSeparator = ".",
			NumberGroupSizes = new int[1] { 3 }
		};

		private static string ApplyTemplate(string template, string formattedValue)
		{
			if (string.IsNullOrEmpty(template))
			{
				return formattedValue;
			}
			return template.Replace("{value}", formattedValue);
		}

		public static string FormatPlayerUI(string value)
		{
			Plugin.TemplateInfo templateInfo = Plugin.Template_PlayerUI ?? new Plugin.TemplateInfo("{value}K\u00a0₸", multiplyBy1000: false);
			if (templateInfo.MultiplyBy1000 && TryParseDigitsToLong(value, out var value2))
			{
				string text = (Regex.IsMatch(value ?? "", "[ \u00a0\\.,]") ? Math.Max(0L, value2) : (Math.Max(0L, value2) * 1000)).ToString("N0", NbspNumberFormat);
				return ApplyTemplate((text == "0") ? (Plugin.TemplateZero_PlayerUI ?? templateInfo.Template) : templateInfo.Template, text);
			}
			string text2 = FormatNumber(value);
			return ApplyTemplate((text2 == "0") ? (Plugin.TemplateZero_PlayerUI ?? templateInfo.Template) : templateInfo.Template, text2);
		}

		public static string FormatPlayerUICurrency(string value)
		{
			Plugin.TemplateInfo templateInfo = Plugin.Template_PlayerUI ?? new Plugin.TemplateInfo("{value}K\u00a0₸", multiplyBy1000: false);
			bool flag = !string.IsNullOrEmpty(value) && value.Contains('.');
			bool flag2 = Regex.IsMatch(value ?? "", "[ \u00a0\\u202F,\\u2009]");
			if (templateInfo.MultiplyBy1000 && (flag || flag2))
			{
				if (long.TryParse(Regex.Replace(value ?? "", "[^0-9]", ""), out var result))
				{
					string text = Math.Max(0L, result).ToString("N0", NbspNumberFormat);
					return ApplyTemplate((text == "0") ? (Plugin.TemplateZero_PlayerUI ?? templateInfo.Template) : templateInfo.Template, text);
				}
				string text2 = (value ?? string.Empty).Replace('.', '\u00a0');
				return ApplyTemplate((text2 == "0") ? (Plugin.TemplateZero_PlayerUI ?? templateInfo.Template) : templateInfo.Template, text2);
			}
			string text3 = FormatNumber(value);
			return ApplyTemplate((text3 == "0") ? (Plugin.TemplateZero_PlayerUI ?? templateInfo.Template) : templateInfo.Template, text3);
		}

		public static string FormatShopCost(string value)
		{
			Plugin.TemplateInfo templateInfo = Plugin.Template_ItemCost ?? new Plugin.TemplateInfo("{value}K\u00a0KZT", multiplyBy1000: false);
			if (templateInfo.MultiplyBy1000 && TryParseDigitsToLong(value, out var value2))
			{
				string text = (Regex.IsMatch(value ?? "", "[ \u00a0\\.,]") ? Math.Max(0L, value2) : (Math.Max(0L, value2) * 1000)).ToString("N0", NbspNumberFormat);
				return ApplyTemplate((text == "0") ? (Plugin.TemplateZero_ItemCost ?? templateInfo.Template) : templateInfo.Template, text);
			}
			string text2 = FormatNumber(value);
			return ApplyTemplate((text2 == "0") ? (Plugin.TemplateZero_ItemCost ?? templateInfo.Template) : templateInfo.Template, text2);
		}

		public static string FormatItemCost(string value)
		{
			Plugin.TemplateInfo templateInfo = Plugin.Template_ItemCost ?? new Plugin.TemplateInfo("{value}K\u00a0KZT", multiplyBy1000: false);
			if (templateInfo.MultiplyBy1000 && TryParseDigitsToLong(value, out var value2))
			{
				string text = (Regex.IsMatch(value ?? "", "[ \u00a0\\.,]") ? Math.Max(0L, value2) : (Math.Max(0L, value2) * 1000)).ToString("N0", NbspNumberFormat);
				return ApplyTemplate((text == "0") ? (Plugin.TemplateZero_ItemCost ?? templateInfo.Template) : templateInfo.Template, text);
			}
			string text2 = FormatNumber(value);
			return ApplyTemplate((text2 == "0") ? (Plugin.TemplateZero_ItemCost ?? templateInfo.Template) : templateInfo.Template, text2);
		}

		public static string FormatItemCost(int thousands)
		{
			Plugin.TemplateInfo templateInfo = Plugin.Template_ItemCost ?? new Plugin.TemplateInfo("{value}K\u00a0₸", multiplyBy1000: false);
			if (templateInfo.MultiplyBy1000)
			{
				int num = thousands * 1000;
				return templateInfo.Template.Replace("{value}", num.ToString("N0", NbspNumberFormat));
			}
			return ((thousands == 0) ? (Plugin.TemplateZero_ItemCost ?? templateInfo.Template) : templateInfo.Template).Replace("{value}", thousands.ToString());
		}

		public static string FormatItemValue(string value)
		{
			Plugin.TemplateInfo templateInfo = Plugin.Template_ItemCost ?? new Plugin.TemplateInfo("{value}\u00a0тыс.\u00a0₸", multiplyBy1000: false);
			if (templateInfo.MultiplyBy1000 && TryParseDigitsToLong(value, out var value2))
			{
				string text = (Regex.IsMatch(value ?? "", "[ \u00a0\\.,]") ? Math.Max(0L, value2) : (Math.Max(0L, value2) * 1000)).ToString("N0", NbspNumberFormat);
				return ApplyTemplate((text == "0") ? (Plugin.TemplateZero_ItemPickup ?? templateInfo.Template) : templateInfo.Template, text);
			}
			string text2 = FormatNumber(value);
			return ApplyTemplate((text2 == "0") ? (Plugin.TemplateZero_ItemPickup ?? templateInfo.Template) : templateInfo.Template, text2);
		}

		public static string FormatItemValue(int units)
		{
			Plugin.TemplateInfo templateInfo = Plugin.Template_ItemCost ?? new Plugin.TemplateInfo("{value}\u00a0тыс.\u00a0₸", multiplyBy1000: false);
			if (units < 1000)
			{
				return units + "\u00a0₸";
			}
			if (templateInfo.MultiplyBy1000)
			{
				return templateInfo.Template.Replace("{value}", units.ToString("N0", NbspNumberFormat));
			}
			int num = units / 1000;
			return templateInfo.Template.Replace("{value}", num.ToString());
		}

		public static string FormatHaulUI(string value)
		{
			Plugin.TemplateInfo templateInfo = Plugin.Template_HaulUI ?? new Plugin.TemplateInfo("{value}\u00a0тыс.\u00a0₸", multiplyBy1000: false);
			if (templateInfo.MultiplyBy1000 && TryParseDigitsToLong(value, out var value2))
			{
				string text = (Math.Max(0L, value2) * 1000).ToString("N0", NbspNumberFormat);
				return ApplyTemplate((text == "0") ? (Plugin.TemplateZero_HaulUI ?? templateInfo.Template) : templateInfo.Template, text);
			}
			string text2 = FormatNumber(value);
			return ApplyTemplate((text2 == "0") ? (Plugin.TemplateZero_HaulUI ?? templateInfo.Template) : templateInfo.Template, text2);
		}

		public static string FormatHaulUI(int units)
		{
			Plugin.TemplateInfo templateInfo = Plugin.Template_HaulUI ?? new Plugin.TemplateInfo("{value}\u00a0тыс.\u00a0₸", multiplyBy1000: false);
			string text = Math.Max(0, units).ToString("N0", NbspNumberFormat);
			return ApplyTemplate((text == "0") ? (Plugin.TemplateZero_HaulUI ?? templateInfo.Template) : templateInfo.Template, text);
		}

		public static string FormatHaul(string value)
		{
			Plugin.TemplateInfo templateInfo = Plugin.Template_Haul ?? new Plugin.TemplateInfo("{value}K\u00a0₸", multiplyBy1000: false);
			if (templateInfo.MultiplyBy1000 && TryParseDigitsToLong(value, out var value2))
			{
				string text = (Math.Max(0L, value2) * 1000).ToString("N0", NbspNumberFormat);
				return ApplyTemplate((text == "0") ? (Plugin.TemplateZero_Haul ?? templateInfo.Template) : templateInfo.Template, text);
			}
			string text2 = FormatNumber(value);
			return ApplyTemplate((text2 == "0") ? (Plugin.TemplateZero_Haul ?? templateInfo.Template) : templateInfo.Template, text2);
		}

		public static string FormatHaul(int units)
		{
			Plugin.TemplateInfo templateInfo = Plugin.Template_Haul ?? new Plugin.TemplateInfo("{value}K\u00a0₸", multiplyBy1000: false);
			string text = Math.Max(0, units).ToString("N0", NbspNumberFormat);
			return ApplyTemplate((text == "0") ? (Plugin.TemplateZero_Haul ?? templateInfo.Template) : templateInfo.Template, text);
		}

		public static string FormatCartHaulUI(string value)
		{
			Plugin.TemplateInfo templateInfo = Plugin.Template_CartHaulUI ?? new Plugin.TemplateInfo("{value}\u00a0тыс.\u00a0₸", multiplyBy1000: false);
			if (templateInfo.MultiplyBy1000 && TryParseDigitsToLong(value, out var value2))
			{
				string text = (Regex.IsMatch(value ?? "", "[ \u00a0\\.,]") ? Math.Max(0L, value2) : (Math.Max(0L, value2) * 1000)).ToString("N0", NbspNumberFormat);
				return ApplyTemplate((text == "0") ? (Plugin.TemplateZero_CartHaulUI ?? templateInfo.Template) : templateInfo.Template, text);
			}
			string text2 = FormatNumber(value);
			return ApplyTemplate((text2 == "0") ? (Plugin.TemplateZero_CartHaulUI ?? templateInfo.Template) : templateInfo.Template, text2);
		}

		private static bool TryParseDigitsToLong(string raw, out long value)
		{
			value = 0L;
			if (string.IsNullOrWhiteSpace(raw))
			{
				return false;
			}
			string text = Regex.Replace(raw, "[^0-9-]", "");
			if (string.IsNullOrEmpty(text))
			{
				return false;
			}
			return long.TryParse(text, out value);
		}

		private static string FormatNumber(string raw)
		{
			if (string.IsNullOrWhiteSpace(raw))
			{
				return raw ?? string.Empty;
			}
			string text = raw.Trim();
			text = text.Replace("\u00a0", "");
			text = text.Replace(" ", "");
			if (long.TryParse(text, NumberStyles.Integer, NbspNumberFormat, out var result))
			{
				return result.ToString("N0", NbspNumberFormat);
			}
			if (decimal.TryParse(text, NumberStyles.Number, NbspNumberFormat, out var result2))
			{
				return result2.ToString("N2", NbspNumberFormat).TrimEnd('0').TrimEnd('.');
			}
			return raw;
		}
	}
	[HarmonyPatch(typeof(CurrencyUI), "Update")]
	public class CurrencyUIPatch
	{
		[HarmonyPostfix]
		public static void UpdatePostfix(CurrencyUI __instance, TextMeshProUGUI ___Text, ref float ___showTimer)
		{
			if (!(___showTimer > 0f) || !((Object)(object)___Text != (Object)null))
			{
				return;
			}
			string text = ((TMP_Text)___Text).text;
			if (text.StartsWith("$") && text.EndsWith("K"))
			{
				string value = text.Substring(1, text.Length - 2);
				TMP_FontAsset tengeFallbackFont = TengeSymbolSupport.GetTengeFallbackFont();
				if ((Object)(object)((TMP_Text)___Text).font != (Object)(object)tengeFallbackFont)
				{
					TengeSymbolSupport.SetPrimaryFont(___Text);
				}
				string text2 = CurrencyFormatter.FormatPlayerUICurrency(value);
				((TMP_Text)___Text).text = text2;
			}
		}
	}
	[HarmonyPatch(typeof(CurrencyUI), "FetchCurrency")]
	public class CurrencyUIFetchCurrencyPatch
	{
		[HarmonyPostfix]
		public static void FetchCurrencyPostfix(CurrencyUI __instance, TextMeshProUGUI ___Text)
		{
			if ((Object)(object)___Text != (Object)null)
			{
				string text = ((TMP_Text)___Text).text;
				if (text.StartsWith("$") && text.EndsWith("K"))
				{
					string value = text.Substring(1, text.Length - 2);
					TengeSymbolSupport.EnsureFallbackFont(___Text);
					((TMP_Text)___Text).text = CurrencyFormatter.FormatPlayerUICurrency(value);
				}
			}
		}
	}
	[HarmonyPatch(typeof(ExtractionPoint))]
	internal class ExtractionPointPatch
	{
		[HarmonyPatch("SetHaulText")]
		[HarmonyPostfix]
		private static void SetHaulTextPostfix(ExtractionPoint __instance)
		{
			if (!((Object)(object)__instance.haulGoalScreen == (Object)null))
			{
				string text = ((TMP_Text)__instance.haulGoalScreen).text;
				if (!string.IsNullOrEmpty(text) && TryParseFormattedNumber(text, out var value))
				{
					string text2 = CurrencyFormatter.FormatHaul(Math.Max(0, value));
					((TMP_Text)__instance.haulGoalScreen).text = text2;
				}
			}
		}

		[HarmonyPatch("StateSuccess")]
		[HarmonyPostfix]
		private static void StateSuccessPostfix(ExtractionPoint __instance)
		{
			if (!((Object)(object)__instance.haulGoalScreen == (Object)null))
			{
				string text = ((TMP_Text)__instance.haulGoalScreen).text;
				if (!string.IsNullOrEmpty(text) && TryParseFormattedNumber(text, out var value))
				{
					string text2 = CurrencyFormatter.FormatHaul(Math.Max(0, value));
					((TMP_Text)__instance.haulGoalScreen).text = text2;
				}
			}
		}

		[HarmonyPatch("StateSurplus")]
		[HarmonyPostfix]
		private static void StateSurplusPostfix(ExtractionPoint __instance)
		{
			if ((Object)(object)__instance.haulGoalScreen == (Object)null)
			{
				return;
			}
			string text = ((TMP_Text)__instance.haulGoalScreen).text;
			if (!string.IsNullOrEmpty(text))
			{
				bool flag = text.TrimStart().StartsWith("+");
				if (TryParseFormattedNumber(text, out var value))
				{
					string text2 = CurrencyFormatter.FormatHaul(Math.Max(0, value));
					((TMP_Text)__instance.haulGoalScreen).text = (flag ? "+" : "") + text2;
				}
			}
		}

		private static bool TryParseFormattedNumber(string text, out int value)
		{
			value = 0;
			if (string.IsNullOrEmpty(text))
			{
				return false;
			}
			string text2 = Regex.Replace(text, "<.*?>", "");
			text2 = text2.Replace('\u00a0', ' ').Replace('\u202f', ' ').Replace('\u2009', ' ')
				.Trim();
			string pattern = "(?:(?:\\d{1,3}(?:[ \\u00A0\\u202F,\\u2009\\.]\\d{3})+)|\\d+)";
			MatchCollection matchCollection = Regex.Matches(text2, pattern);
			if (matchCollection.Count == 0)
			{
				return false;
			}
			Match match = matchCollection[matchCollection.Count - 1];
			if (!int.TryParse(Regex.Replace(match.Value, "[^0-9]", ""), out var result))
			{
				return false;
			}
			int num = 1;
			int num2 = match.Index + match.Length;
			if (num2 < text2.Length)
			{
				string text3 = text2.Substring(num2, Math.Min(6, text2.Length - num2)).ToLowerInvariant();
				if (text3.Contains("k") || text3.Contains("тыс"))
				{
					num = 1000;
				}
			}
			try
			{
				long num3 = (long)result * (long)num;
				if (num3 > int.MaxValue)
				{
					value = int.MaxValue;
				}
				else
				{
					value = (int)num3;
				}
				return true;
			}
			catch
			{
				return false;
			}
		}
	}
	[HarmonyPatch(typeof(HaulUI), "Update")]
	public class HaulUIPatch
	{
		private static string _lastOriginalText = null;

		private static string _lastProcessedText = null;

		private static readonly Regex DollarPattern = new Regex("<color=#558B2F>\\$</color>(.*?)(?=<color|$)", RegexOptions.Compiled);

		private static readonly Regex TagRemovalPattern = new Regex("<[^>]+>", RegexOptions.Compiled);

		[HarmonyPostfix]
		public static void UpdatePostfix(HaulUI __instance, TextMeshProUGUI ___Text)
		{
			if ((Object)(object)___Text == (Object)null)
			{
				return;
			}
			string text = ((TMP_Text)___Text).text;
			if (string.IsNullOrEmpty(text) || text == _lastProcessedText)
			{
				return;
			}
			try
			{
				int units = (((Object)(object)RoundDirector.instance != (Object)null) ? RoundDirector.instance.currentHaul : 0);
				int units2 = (((Object)(object)RoundDirector.instance != (Object)null) ? RoundDirector.instance.extractionHaulGoal : 0);
				string text2 = CurrencyFormatter.FormatHaulUI(units);
				string text3 = CurrencyFormatter.FormatHaulUI(units2);
				string text4 = "<size=30>" + text2 + "<color=#616161> <size=45>/</size> </color>" + text3;
				_lastOriginalText = text;
				_lastProcessedText = text4;
				((TMP_Text)___Text).text = text4;
			}
			catch
			{
			}
		}
	}
	[HarmonyPatch(typeof(PhysGrabCart), "SetHaulText")]
	internal class PhysGrabCartHaulTextPatch
	{
		[HarmonyPostfix]
		private static void SetHaulTextPostfix(PhysGrabCart __instance)
		{
			if (!((Object)(object)__instance.displayText == (Object)null))
			{
				TengeSymbolSupport.EnsureFallbackFont(__instance.displayText);
				FieldInfo field = typeof(PhysGrabCart).GetField("haulCurrent", BindingFlags.Instance | BindingFlags.NonPublic);
				if (!(field == null))
				{
					int val = (int)field.GetValue(__instance);
					string text = CurrencyFormatter.FormatCartHaulUI(SemiFunc.DollarGetString(Math.Max(0, val)));
					((TMP_Text)__instance.displayText).text = text;
				}
			}
		}
	}
	[BepInPlugin("kztCurrency", "kztCurrency", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal class TemplateInfo
		{
			public string Template { get; set; }

			public bool MultiplyBy1000 { get; set; }

			public TemplateInfo(string template, bool multiplyBy1000)
			{
				Template = template;
				MultiplyBy1000 = multiplyBy1000;
			}
		}

		internal static ManualLogSource Logger;

		private static readonly Dictionary<string, TemplateInfo> ExampleToTemplate_PlayerUI = new Dictionary<string, TemplateInfo>
		{
			{
				"100K тг",
				new TemplateInfo("{value}K\u00a0тг", multiplyBy1000: false)
			},
			{
				"100K ₸",
				new TemplateInfo("{value}K\u00a0₸", multiplyBy1000: false)
			},
			{
				"100K KZT",
				new TemplateInfo("{value}K\u00a0KZT", multiplyBy1000: false)
			},
			{
				"100к тг",
				new TemplateInfo("{value}к\u00a0тг", multiplyBy1000: false)
			},
			{
				"100к ₸",
				new TemplateInfo("{value}к\u00a0₸", multiplyBy1000: false)
			},
			{
				"100к KZT",
				new TemplateInfo("{value}к\u00a0KZT", multiplyBy1000: false)
			},
			{
				"100 тыс. тг",
				new TemplateInfo("{value}\u00a0тыс.\u00a0тг", multiplyBy1000: false)
			},
			{
				"100 000 тг",
				new TemplateInfo("{value}\u00a0тг", multiplyBy1000: true)
			},
			{
				"100 000 ₸",
				new TemplateInfo("{value}\u00a0₸", multiplyBy1000: true)
			},
			{
				"100 000 KZT",
				new TemplateInfo("{value}\u00a0KZT", multiplyBy1000: true)
			}
		};

		private static readonly Dictionary<string, TemplateInfo> ExampleToTemplate_ItemCost = new Dictionary<string, TemplateInfo>
		{
			{
				"100K тг",
				new TemplateInfo("{value}K\u00a0тг", multiplyBy1000: false)
			},
			{
				"100K ₸",
				new TemplateInfo("{value}K\u00a0₸", multiplyBy1000: false)
			},
			{
				"100K KZT",
				new TemplateInfo("{value}K\u00a0KZT", multiplyBy1000: false)
			},
			{
				"100 тыс. тг",
				new TemplateInfo("{value}\u00a0тыс.\u00a0тг", multiplyBy1000: false)
			},
			{
				"100 тыс. ₸",
				new TemplateInfo("{value}\u00a0тыс.\u00a0₸", multiplyBy1000: false)
			},
			{
				"100 тыс. KZT",
				new TemplateInfo("{value}\u00a0тыс.\u00a0KZT", multiplyBy1000: false)
			},
			{
				"100 000 тг",
				new TemplateInfo("{value}\u00a0тг", multiplyBy1000: true)
			},
			{
				"100 000 ₸",
				new TemplateInfo("{value}\u00a0₸", multiplyBy1000: true)
			},
			{
				"100 000 KZT",
				new TemplateInfo("{value}\u00a0KZT", multiplyBy1000: true)
			}
		};

		private static readonly Dictionary<string, TemplateInfo> ExampleToTemplate_HaulUI = new Dictionary<string, TemplateInfo>
		{
			{
				"100K тг",
				new TemplateInfo("{value}K\u00a0<color=#558B2F>тг</color>", multiplyBy1000: false)
			},
			{
				"100K ₸",
				new TemplateInfo("{value}K\u00a0<color=#558B2F>₸</color>", multiplyBy1000: false)
			},
			{
				"100K KZT",
				new TemplateInfo("{value}K\u00a0<color=#558B2F>KZT</color>", multiplyBy1000: false)
			},
			{
				"100к тг",
				new TemplateInfo("{value}к\u00a0<color=#558B2F>тг</color>", multiplyBy1000: false)
			},
			{
				"100к ₸",
				new TemplateInfo("{value}к\u00a0<color=#558B2F>₸</color>", multiplyBy1000: false)
			},
			{
				"100к KZT",
				new TemplateInfo("{value}к\u00a0<color=#558B2F>KZT</color>", multiplyBy1000: false)
			},
			{
				"100 000 тг",
				new TemplateInfo("{value}\u00a0<color=#558B2F>тг</color>", multiplyBy1000: true)
			},
			{
				"100 000 ₸",
				new TemplateInfo("{value}\u00a0<color=#558B2F>₸</color>", multiplyBy1000: true)
			},
			{
				"100 000 KZT",
				new TemplateInfo("{value}\u00a0<color=#558B2F>KZT</color>", multiplyBy1000: true)
			}
		};

		private static readonly Dictionary<string, TemplateInfo> ExampleToTemplate_Haul = new Dictionary<string, TemplateInfo>
		{
			{
				"100K тг",
				new TemplateInfo("{value}K\u00a0тг", multiplyBy1000: false)
			},
			{
				"100K ₸",
				new TemplateInfo("{value}K\u00a0₸", multiplyBy1000: false)
			},
			{
				"100K KZT",
				new TemplateInfo("{value}K\u00a0KZT", multiplyBy1000: false)
			},
			{
				"100к тг",
				new TemplateInfo("{value}к\u00a0тг", multiplyBy1000: false)
			},
			{
				"100к ₸",
				new TemplateInfo("{value}к\u00a0₸", multiplyBy1000: false)
			},
			{
				"100 000 тг",
				new TemplateInfo("{value}\u00a0тг", multiplyBy1000: true)
			},
			{
				"100 000 ₸",
				new TemplateInfo("{value}\u00a0₸", multiplyBy1000: true)
			},
			{
				"100 000 KZT",
				new TemplateInfo("{value}\u00a0KZT", multiplyBy1000: true)
			}
		};

		private static readonly Dictionary<string, TemplateInfo> ExampleToTemplate_CartHaulUI = new Dictionary<string, TemplateInfo>
		{
			{
				"100 тыс. тг",
				new TemplateInfo("{value}\u00a0тыс.\u00a0тг", multiplyBy1000: false)
			},
			{
				"100 тыс. ₸",
				new TemplateInfo("{value}\u00a0тыс.\u00a0₸", multiplyBy1000: false)
			},
			{
				"100 тыс. KZT",
				new TemplateInfo("{value}\u00a0тыс.\u00a0KZT", multiplyBy1000: false)
			},
			{
				"100 тг",
				new TemplateInfo("{value}\u00a0тг", multiplyBy1000: false)
			},
			{
				"100 000 тг",
				new TemplateInfo("{value}\u00a0тг", multiplyBy1000: true)
			},
			{
				"100 000 ₸",
				new TemplateInfo("{value}\u00a0₸", multiplyBy1000: true)
			},
			{
				"100 000 KZT",
				new TemplateInfo("{value}\u00a0KZT", multiplyBy1000: true)
			}
		};

		internal static ConfigEntry<string> Format_PlayerUI;

		internal static ConfigEntry<string> Format_ItemCost;

		internal static ConfigEntry<string> Format_ItemPickup;

		internal static ConfigEntry<string> Format_HaulUI;

		internal static ConfigEntry<string> Format_Haul;

		internal static ConfigEntry<string> Format_CartHaulUI;

		internal static ConfigEntry<bool> ReplaceAllFonts;

		internal static TemplateInfo Template_PlayerUI;

		internal static TemplateInfo Template_ItemCost;

		internal static TemplateInfo Template_HaulUI;

		internal static TemplateInfo Template_Haul;

		internal static TemplateInfo Template_CartHaulUI;

		internal static string TemplateZero_PlayerUI;

		internal static string TemplateZero_ItemCost;

		internal static string TemplateZero_ItemPickup;

		internal static string TemplateZero_HaulUI;

		internal static string TemplateZero_Haul;

		internal static string TemplateZero_CartHaulUI;

		private static string MakeZeroFriendlyTemplate(string template)
		{
			if (string.IsNullOrEmpty(template))
			{
				return template;
			}
			template = template.Replace("{value}K", "{value}");
			template = template.Replace("{value}k", "{value}");
			template = template.Replace("{value}к", "{value}");
			template = template.Replace("{value}\u00a0тыс.", "{value}");
			template = template.Replace("{value} тыс.", "{value}");
			template = template.Replace("{value}\u00a0тыс", "{value}");
			template = template.Replace("{value} тыс", "{value}");
			return template;
		}

		private static TemplateInfo ConvertExampleToTemplateInfo(string example, Dictionary<string, TemplateInfo> mapping, string mappingName = "Unknown")
		{
			if (mapping.TryGetValue(example, out var value))
			{
				return value;
			}
			Logger.LogWarning((object)("[Formatting] No mapping found for example '" + example + "' in " + mappingName + " mapper. Using fallback with MultiplyBy1000=false."));
			return new TemplateInfo(example, multiplyBy1000: false);
		}

		internal static TemplateInfo GetFormatTemplateInfo(ConfigEntry<string> configEntry, TemplateInfo defaultTemplateInfo, Dictionary<string, TemplateInfo> mapping, string mappingName = "Unknown")
		{
			if (configEntry == null || configEntry.Value == null)
			{
				return defaultTemplateInfo;
			}
			return ConvertExampleToTemplateInfo(configEntry.Value, mapping, mappingName);
		}

		internal static void RefreshTemplates(string reason)
		{
			try
			{
				string arg = Format_PlayerUI?.Value;
				string arg2 = Format_ItemCost?.Value;
				string arg3 = Format_ItemPickup?.Value;
				string arg4 = Format_HaulUI?.Value;
				string arg5 = Format_CartHaulUI?.Value;
				Template_PlayerUI = GetFormatTemplateInfo(Format_PlayerUI, new TemplateInfo("{value}K\u00a0₸", multiplyBy1000: false), ExampleToTemplate_PlayerUI, "PlayerUI");
				Template_ItemCost = GetFormatTemplateInfo(Format_ItemCost, new TemplateInfo("{value}K\u00a0KZT", multiplyBy1000: false), ExampleToTemplate_ItemCost, "ItemCost");
				Template_HaulUI = GetFormatTemplateInfo(Format_HaulUI, new TemplateInfo("{value}\u00a0тыс.\u00a0₸", multiplyBy1000: false), ExampleToTemplate_HaulUI, "HaulUI");
				Template_Haul = GetFormatTemplateInfo(Format_Haul, new TemplateInfo("{value}K\u00a0₸", multiplyBy1000: false), ExampleToTemplate_Haul, "Haul");
				Template_CartHaulUI = GetFormatTemplateInfo(Format_CartHaulUI, new TemplateInfo("{value}\u00a0тыс.\u00a0₸", multiplyBy1000: false), ExampleToTemplate_CartHaulUI, "CartHaulUI");
				TemplateZero_PlayerUI = MakeZeroFriendlyTemplate(Template_PlayerUI.Template);
				TemplateZero_ItemCost = MakeZeroFriendlyTemplate(Template_ItemCost.Template);
				TemplateZero_ItemPickup = MakeZeroFriendlyTemplate(Template_ItemCost.Template);
				TemplateZero_HaulUI = MakeZeroFriendlyTemplate(Template_HaulUI.Template);
				TemplateZero_Haul = MakeZeroFriendlyTemplate(Template_Haul.Template);
				TemplateZero_CartHaulUI = MakeZeroFriendlyTemplate(Template_CartHaulUI.Template);
				Logger.LogInfo((object)("[Formatting] Refreshed templates (" + reason + ")"));
				Logger.LogInfo((object)$"  PlayerUI:   raw='{arg}' => tpl='{Template_PlayerUI.Template}' x1000={Template_PlayerUI.MultiplyBy1000}");
				Logger.LogInfo((object)$"  ItemCost:     raw='{arg2}' => tpl='{Template_ItemCost.Template}' x1000={Template_ItemCost.MultiplyBy1000}");
				Logger.LogInfo((object)$"  ItemPickup: raw='{arg3}' => tpl='{Template_ItemCost.Template}' x1000={Template_ItemCost.MultiplyBy1000}");
				Logger.LogInfo((object)$"  Haul:     raw='{arg4}' => tpl='{Template_Haul.Template}' x1000={Template_Haul.MultiplyBy1000}");
				Logger.LogInfo((object)$"  HaulUI:     raw='{arg4}' => tpl='{Template_HaulUI.Template}' x1000={Template_HaulUI.MultiplyBy1000}");
				Logger.LogInfo((object)$"  CartHaulUI: raw='{arg5}' => tpl='{Template_CartHaulUI.Template}' x1000={Template_CartHaulUI.MultiplyBy1000}");
			}
			catch (Exception ex)
			{
				Logger.LogWarning((object)("[Formatting] Failed to log templates: " + ex.Message));
			}
		}

		private void Awake()
		{
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Expected O, but got Unknown
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Expected O, but got Unknown
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Expected O, but got Unknown
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Expected O, but got Unknown
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Expected O, but got Unknown
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			Format_PlayerUI = ((BaseUnityPlugin)this).Config.Bind<string>("Formatting", "PlayerUI", "100 000 ₸", new ConfigDescription("Player UI currency format.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[9] { "100K тг", "100K ₸", "100K KZT", "100к тг", "100к ₸", "100 тыс. тг", "100 000 тг", "100 000 ₸", "100 000 KZT" }), Array.Empty<object>()));
			Format_ItemCost = ((BaseUnityPlugin)this).Config.Bind<string>("Formatting", "ItemCost", "100K ₸", new ConfigDescription("Shop/cart UI currency format.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[6] { "100K тг", "100K ₸", "100K KZT", "100 000 тг", "100 000 ₸", "100 000 KZT" }), Array.Empty<object>()));
			Format_ItemPickup = ((BaseUnityPlugin)this).Config.Bind<string>("Formatting", "ItemPickup", "100 000 ₸", new ConfigDescription("Item pickup/value UI currency format. For values >= 1000: uses thousands format; for < 1000: shows units.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[5] { "100 тыс. тг", "100 тыс. ₸", "100 тыс. KZT", "100 000 тг", "100 000 ₸" }), Array.Empty<object>()));
			Format_HaulUI = ((BaseUnityPlugin)this).Config.Bind<string>("Formatting", "HaulUI", "100 000 ₸", new ConfigDescription("Extraction point UI currency format.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[9] { "100K тг", "100K ₸", "100K KZT", "100к тг", "100к ₸", "100к KZT", "100 000 тг", "100 000 ₸", "100 000 KZT" }), Array.Empty<object>()));
			Format_Haul = ((BaseUnityPlugin)this).Config.Bind<string>("Formatting", "Haul", "100 000 ₸", new ConfigDescription("Extraction point (plain) currency format used by extraction point screens.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[8] { "100K тг", "100K ₸", "100K KZT", "100к тг", "100к ₸", "100 000 тг", "100 000 ₸", "100 000 KZT" }), Array.Empty<object>()));
			Format_CartHaulUI = ((BaseUnityPlugin)this).Config.Bind<string>("Formatting", "CartHaulUI", "100 тыс. тг", new ConfigDescription("Cart haul UI currency format.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[6] { "100 тыс. тг", "100 тыс. ₸", "100 тыс. KZT", "100 000 тг", "100 000 ₸", "100 000 KZT" }), Array.Empty<object>()));
			ReplaceAllFonts = ((BaseUnityPlugin)this).Config.Bind<bool>("Fonts", "ReplaceAllFonts", false, "Replace all TMP_Text components with the merged font at scene load. If false, the merged font is only added as a fallback.");
			TengeSymbolSupport.Initialize(ReplaceAllFonts.Value);
			RefreshTemplates("startup");
			((BaseUnityPlugin)this).Config.SettingChanged += delegate(object _, SettingChangedEventArgs args)
			{
				RefreshTemplates("configChanged: " + args.ChangedSetting.Definition.Key);
			};
			new Harmony("kztCurrency").PatchAll();
			Logger.LogInfo((object)"Plugin loaded!");
		}
	}
	[HarmonyPatch(typeof(ShopCostUI), "Update")]
	public class ShopCostUIPatch
	{
		[HarmonyPostfix]
		public static void UpdatePostfix(ShopCostUI __instance, TextMeshProUGUI ___Text)
		{
			if ((Object)(object)___Text != (Object)null && !string.IsNullOrEmpty(((TMP_Text)___Text).text))
			{
				string text = ((TMP_Text)___Text).text;
				if (text.StartsWith("-$") && text.EndsWith("K"))
				{
					string value = text.Substring(2, text.Length - 3);
					((TMP_Text)___Text).text = "-" + CurrencyFormatter.FormatShopCost(value);
				}
				else if (text.StartsWith("+$") && text.EndsWith("K"))
				{
					string value2 = text.Substring(2, text.Length - 3);
					((TMP_Text)___Text).text = "+" + CurrencyFormatter.FormatShopCost(value2);
				}
				TMP_FontAsset tengeFallbackFont = TengeSymbolSupport.GetTengeFallbackFont();
				if ((Object)(object)tengeFallbackFont != (Object)null && (Object)(object)((TMP_Text)___Text).font != (Object)(object)tengeFallbackFont)
				{
					TengeSymbolSupport.SetPrimaryFont(___Text);
				}
			}
		}
	}
	public static class TengeSymbolSupport
	{
		private static TMP_FontAsset tengeFallbackFont;

		private static bool initialized = false;

		private static string displaySymbol = "₸";

		private static bool ApplyPrimaryFont(TMP_Text textComponent)
		{
			if ((Object)(object)textComponent == (Object)null || (Object)(object)tengeFallbackFont == (Object)null)
			{
				return false;
			}
			if (textComponent.font == tengeFallbackFont)
			{
				return false;
			}
			textComponent.font = tengeFallbackFont;
			try
			{
				Material material = ((TMP_Asset)tengeFallbackFont).material;
				if ((Object)(object)material != (Object)null)
				{
					textComponent.fontSharedMaterial = material;
					textComponent.fontMaterial = material;
				}
			}
			catch
			{
			}
			try
			{
				((Graphic)textComponent).SetAllDirty();
				textComponent.ForceMeshUpdate(false, false);
			}
			catch
			{
			}
			return true;
		}

		public static void Initialize()
		{
			Initialize(replaceAllFonts: false);
		}

		public static void Initialize(bool replaceAllFonts)
		{
			if (initialized)
			{
				return;
			}
			try
			{
				CreateTengeFallbackFont();
				if ((Object)(object)tengeFallbackFont == (Object)null)
				{
					Plugin.Logger.LogError((object)"Tenge fallback font asset is null after creation; aborting fallback registration.");
					displaySymbol = "тг";
					return;
				}
				AddFallbackToDefaultFont();
				InjectFallbackIntoAllFonts();
				if (replaceAllFonts)
				{
					ReplaceAllLoadedTextFonts();
				}
				initialized = true;
				Plugin.Logger.LogInfo((object)"Tenge symbol (₸) support initialized successfully with merged font asset");
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogError((object)$"Failed to initialize Tenge symbol support: {arg}");
			}
		}

		public static string GetDisplaySymbol()
		{
			return displaySymbol;
		}

		private static void CreateTengeFallbackFont()
		{
			if (TryLoadUnityGeneratedFontAsset())
			{
				Plugin.Logger.LogInfo((object)"Successfully loaded TMP_FontAsset with Cyrillic + Tenge support");
				displaySymbol = "₸";
			}
			else
			{
				Plugin.Logger.LogInfo((object)"Merged font asset not found; using textual fallback 'тг'");
				displaySymbol = "тг";
				Plugin.Logger.LogInfo((object)"Using textual fallback 'тг' for Tenge currency display");
			}
		}

		private static bool TryLoadUnityGeneratedFontAsset()
		{
			//IL_0258: 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_026a: Expected O, but got Unknown
			try
			{
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				string[] manifestResourceNames = executingAssembly.GetManifestResourceNames();
				Plugin.Logger.LogDebug((object)string.Format("Assembly manifest resources ({0}): {1}", manifestResourceNames.Length, string.Join(", ", manifestResourceNames.Take(10))));
				string[] obj = new string[5] { "teko-cyrillic-tenge.bundle", "teko-merged.bundle", "roboto-light-tenge.bundle", "roboto.bundle", "tengefont.bundle" };
				string text = null;
				string[] array = obj;
				foreach (string bundleName in array)
				{
					text = manifestResourceNames.FirstOrDefault((string r) => r.EndsWith(bundleName, StringComparison.OrdinalIgnoreCase));
					if (text != null)
					{
						break;
					}
				}
				if (text != null)
				{
					Plugin.Logger.LogDebug((object)("Found embedded AssetBundle resource: " + text));
					using Stream stream = executingAssembly.GetManifestResourceStream(text);
					if (stream == null)
					{
						Plugin.Logger.LogError((object)("Failed to open resource stream for " + text));
						return false;
					}
					byte[] array2 = new byte[stream.Length];
					int j;
					int num;
					for (j = 0; j < array2.Length; j += num)
					{
						num = stream.Read(array2, j, array2.Length - j);
						if (num <= 0)
						{
							break;
						}
					}
					if (j != array2.Length)
					{
						Plugin.Logger.LogError((object)$"Failed to read AssetBundle bytes completely ({j}/{array2.Length})");
						return false;
					}
					string text2 = Path.Combine(Path.GetTempPath(), "kztCurrency");
					Directory.CreateDirectory(text2);
					string text3 = Path.Combine(text2, Path.GetFileName(text));
					File.WriteAllBytes(text3, array2);
					Plugin.Logger.LogDebug((object)$"Extracted AssetBundle ({array2.Length} bytes) to: {text3}");
					AssetBundle val = AssetBundle.LoadFromFile(text3);
					if ((Object)(object)val == (Object)null)
					{
						Plugin.Logger.LogError((object)"Failed to load AssetBundle from extracted file");
						return false;
					}
					TMP_FontAsset[] array3 = val.LoadAllAssets<TMP_FontAsset>();
					if (array3 == null || array3.Length == 0)
					{
						Plugin.Logger.LogWarning((object)"No TMP_FontAsset found in bundle");
						val.Unload(false);
						return false;
					}
					tengeFallbackFont = array3[0];
					try
					{
						Shader val2 = Shader.Find("TextMeshPro/Distance Field") ?? Shader.Find("TextMeshPro/Mobile/Distance Field");
						if ((Object)(object)val2 != (Object)null)
						{
							bool flag = false;
							try
							{
								flag = (Object)(object)((TMP_Asset)tengeFallbackFont).material == (Object)null;
							}
							catch
							{
								flag = true;
							}
							if (flag)
							{
								Material val3 = new Material(val2)
								{
									name = "MergedFont_Material"
								};
								try
								{
									if ((Object)(object)tengeFallbackFont.atlasTexture != (Object)null)
									{
										val3.mainTexture = (Texture)(object)tengeFallbackFont.atlasTexture;
									}
								}
								catch
								{
								}
								try
								{
									((TMP_Asset)tengeFallbackFont).material = val3;
								}
								catch
								{
									PropertyInfo property = typeof(TMP_FontAsset).GetProperty("material", BindingFlags.Instance | BindingFlags.Public);
									if (property != null && property.CanWrite)
									{
										property.SetValue(tengeFallbackFont, val3);
									}
									else
									{
										FieldInfo field = typeof(TMP_FontAsset).GetField("m_AtlasMaterials", BindingFlags.Instance | BindingFlags.NonPublic);
										if (field != null)
										{
											field.SetValue(tengeFallbackFont, new Material[1] { val3 });
										}
									}
								}
								Plugin.Logger.LogDebug((object)"Assigned runtime Material to merged TMP_FontAsset");
							}
						}
						else
						{
							Plugin.Logger.LogWarning((object)"TMP shader not found; cannot create material for loaded merged font asset");
						}
					}
					catch (Exception ex)
					{
						Plugin.Logger.LogWarning((object)("Exception while ensuring material on font asset: " + ex.Message));
					}
					Plugin.Logger.LogInfo((object)("Successfully loaded TMP_FontAsset '" + ((Object)tengeFallbackFont).name + "' from AssetBundle (contains Cyrillic + Tenge support)"));
					displaySymbol = "₸";
					return true;
				}
			}
			catch (Exception ex2)
			{
				Plugin.Logger.LogError((object)("Error loading Unity-generated TMP_FontAsset: " + ex2.Message));
			}
			return false;
		}

		private static void AddFallbackToDefaultFont()
		{
			if ((Object)(object)tengeFallbackFont == (Object)null)
			{
				return;
			}
			try
			{
				List<TMP_FontAsset> fallbackFontAssets = TMP_Settings.fallbackFontAssets;
				if (fallbackFontAssets != null)
				{
					TMP_FontAsset val = ((IEnumerable<TMP_FontAsset>)fallbackFontAssets).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset f) => (Object)(object)f != (Object)null && ((Object)f).name.Contains("Arial")));
					if ((Object)(object)val != (Object)null)
					{
						fallbackFontAssets.Remove(val);
						Plugin.Logger.LogDebug((object)"Removed Arial from TMP_Settings fallback list to prevent style mismatch");
					}
					if (!fallbackFontAssets.Contains(tengeFallbackFont))
					{
						fallbackFontAssets.Insert(0, tengeFallbackFont);
						Plugin.Logger.LogDebug((object)"Added merged font to TMP_Settings fallback list (priority position)");
					}
				}
				else
				{
					Plugin.Logger.LogWarning((object)"TMP_Settings.fallbackFontAssets is null; cannot add fallback to global settings");
				}
				TMP_FontAsset defaultFontAsset = TMP_Settings.defaultFontAsset;
				if ((Object)(object)defaultFontAsset == (Object)null)
				{
					Plugin.Logger.LogWarning((object)"TMP_Settings.defaultFontAsset is null; skipping default font fallback table update.");
					return;
				}
				List<TMP_FontAsset> list = defaultFontAsset.fallbackFontAssetTable;
				if (list == null)
				{
					list = (defaultFontAsset.fallbackFontAssetTable = new List<TMP_FontAsset>());
				}
				TMP_FontAsset val2 = ((IEnumerable<TMP_FontAsset>)list).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset f) => (Object)(object)f != (Object)null && ((Object)f).name.Contains("Arial")));
				if ((Object)(object)val2 != (Object)null)
				{
					list.Remove(val2);
					Plugin.Logger.LogDebug((object)"Removed Arial from default font fallback table");
				}
				if (!list.Contains(tengeFallbackFont))
				{
					list.Insert(0, tengeFallbackFont);
					Plugin.Logger.LogDebug((object)"Added merged font to default font fallback table (priority position)");
				}
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogError((object)$"Exception while registering merged fallback fonts: {arg}");
			}
		}

		private static void InjectFallbackIntoAllFonts()
		{
			if ((Object)(object)tengeFallbackFont == (Object)null)
			{
				return;
			}
			try
			{
				TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
				if (array == null || array.Length == 0)
				{
					return;
				}
				TMP_FontAsset[] array2 = array;
				foreach (TMP_FontAsset val in array2)
				{
					if (!((Object)(object)val == (Object)null) && val != tengeFallbackFont)
					{
						List<TMP_FontAsset> list = val.fallbackFontAssetTable;
						if (list == null)
						{
							list = (val.fallbackFontAssetTable = new List<TMP_FontAsset>());
						}
						if (!list.Contains(tengeFallbackFont))
						{
							list.Insert(0, tengeFallbackFont);
						}
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogWarning((object)("Failed to inject fallback into all fonts: " + ex.Message));
			}
		}

		public static void ReplaceAllLoadedTextFonts()
		{
			if ((Object)(object)tengeFallbackFont == (Object)null)
			{
				return;
			}
			try
			{
				TMP_Text[] array = Resources.FindObjectsOfTypeAll<TMP_Text>();
				if (array == null || array.Length == 0)
				{
					return;
				}
				TMP_Text[] array2 = array;
				foreach (TMP_Text val in array2)
				{
					if (!((Object)(object)val == (Object)null) && val.font != tengeFallbackFont)
					{
						ApplyPrimaryFont(val);
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogWarning((object)("Failed to replace loaded text fonts: " + ex.Message));
			}
		}

		public static void EnsureFallbackFont(TextMeshProUGUI textComponent)
		{
			if ((Object)(object)textComponent == (Object)null || (Object)(object)tengeFallbackFont == (Object)null)
			{
				return;
			}
			TMP_FontAsset font = ((TMP_Text)textComponent).font;
			if (!((Object)(object)font == (Object)null))
			{
				List<TMP_FontAsset> list = font.fallbackFontAssetTable;
				if (list == null)
				{
					list = (font.fallbackFontAssetTable = new List<TMP_FontAsset>());
				}
				if (!list.Contains(tengeFallbackFont))
				{
					list.Add(tengeFallbackFont);
				}
			}
		}

		public static void EnsureFallbackFont(TextMeshPro textComponent)
		{
			if ((Object)(object)textComponent == (Object)null || (Object)(object)tengeFallbackFont == (Object)null)
			{
				return;
			}
			TMP_FontAsset font = ((TMP_Text)textComponent).font;
			if (!((Object)(object)font == (Object)null))
			{
				List<TMP_FontAsset> list = font.fallbackFontAssetTable;
				if (list == null)
				{
					list = (font.fallbackFontAssetTable = new List<TMP_FontAsset>());
				}
				if (!list.Contains(tengeFallbackFont))
				{
					list.Add(tengeFallbackFont);
				}
			}
		}

		public static void SetPrimaryFont(TextMeshProUGUI textComponent)
		{
			if ((Object)(object)textComponent == (Object)null)
			{
				Plugin.Logger.LogWarning((object)"SetPrimaryFont called with null textComponent");
			}
			else if ((Object)(object)tengeFallbackFont == (Object)null)
			{
				Plugin.Logger.LogWarning((object)"SetPrimaryFont called but tengeFallbackFont is null");
			}
			else
			{
				ApplyPrimaryFont((TMP_Text)(object)textComponent);
			}
		}

		public static void SetPrimaryFont(TMP_Text textComponent)
		{
			if ((Object)(object)textComponent == (Object)null)
			{
				Plugin.Logger.LogWarning((object)"SetPrimaryFont called with null textComponent");
			}
			else if ((Object)(object)tengeFallbackFont == (Object)null)
			{
				Plugin.Logger.LogWarning((object)"SetPrimaryFont called but tengeFallbackFont is null");
			}
			else
			{
				ApplyPrimaryFont(textComponent);
			}
		}

		public static TMP_FontAsset GetTengeFallbackFont()
		{
			return tengeFallbackFont;
		}
	}
	[HarmonyPatch(typeof(TMP_Text), "set_text")]
	internal static class TMPTextAutoFontPatch
	{
		[HarmonyPrefix]
		private static void Prefix(TMP_Text __instance, ref string value)
		{
			if (!((Object)(object)__instance == (Object)null) && !string.IsNullOrEmpty(value) && ContainsCyrillicOrTenge(value))
			{
				TMP_FontAsset tengeFallbackFont = TengeSymbolSupport.GetTengeFallbackFont();
				if (!((Object)(object)tengeFallbackFont == (Object)null) && !((Object)(object)__instance.font == (Object)(object)tengeFallbackFont))
				{
					TengeSymbolSupport.SetPrimaryFont(__instance);
				}
			}
		}

		private static bool ContainsCyrillicOrTenge(string s)
		{
			foreach (char c in s)
			{
				if ((c >= 'Ѐ' && c <= 'ӿ') || c == '₸')
				{
					return true;
				}
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(WorldSpaceUIValueLost), "Start")]
	public static class WorldSpaceUIValueLostPatch
	{
		[HarmonyPostfix]
		public static void StartPostfix(WorldSpaceUIValueLost __instance, TextMeshProUGUI ___text, int ___value)
		{
			if ((Object)(object)___text == (Object)null)
			{
				return;
			}
			TengeSymbolSupport.SetPrimaryFont(___text);
			try
			{
				((TMP_Text)___text).text = "-" + CurrencyFormatter.FormatItemValue(___value);
			}
			catch
			{
				((TMP_Text)___text).text = "-$" + SemiFunc.DollarGetString(___value);
			}
		}
	}
	[HarmonyPatch(typeof(WorldSpaceUIValue), "Show")]
	public class WorldSpaceUIValuePatch
	{
		[HarmonyPostfix]
		public static void ShowPostfix(WorldSpaceUIValue __instance, PhysGrabObject _grabObject, int _value, bool _cost, TextMeshProUGUI ___text, PhysGrabObject ___currentPhysGrabObject)
		{
			if ((!((Object)(object)___currentPhysGrabObject != (Object)null) || !((Object)(object)___currentPhysGrabObject != (Object)(object)_grabObject)) && !((Object)(object)___text == (Object)null) && !string.IsNullOrEmpty(((TMP_Text)___text).text))
			{
				TengeSymbolSupport.SetPrimaryFont(___text);
				if (_cost)
				{
					((TMP_Text)___text).text = "-" + CurrencyFormatter.FormatItemCost(_value);
				}
				else
				{
					((TMP_Text)___text).text = CurrencyFormatter.FormatItemValue(_value);
				}
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "kztCurrency";

		public const string PLUGIN_NAME = "kztCurrency";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}