Decompiled source of LoLItems zh v1.0.1

plugins/LoLItems_zh/LoLItems_zh.dll

Decompiled 17 hours ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using HarmonyLib;
using On.RoR2;
using R2API.Utils;
using RoR2;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace LoLItemsZh;

public sealed class Entry
{
	public readonly string ClassName;

	public readonly string Token;

	public readonly string English;

	public readonly string Chinese;

	internal readonly Regex Pattern;

	internal readonly bool Dynamic;

	private static readonly Regex Placeholder = new Regex("\\{(\\d+)\\}");

	public Entry(string owner, string token, string english, string chinese)
	{
		ClassName = owner;
		Token = token;
		English = english;
		Chinese = chinese;
		Dynamic = Placeholder.IsMatch(english);
		if (!Dynamic)
		{
			return;
		}
		StringBuilder stringBuilder = new StringBuilder("\\A");
		int num = 0;
		foreach (Match item in Placeholder.Matches(english))
		{
			stringBuilder.Append(Regex.Escape(english.Substring(num, item.Index - num)));
			stringBuilder.Append("(?<v" + item.Groups[1].Value + ">[-+]?\\d[\\d.,]*(?:[eE][-+]?\\d+)?)");
			num = item.Index + item.Length;
		}
		stringBuilder.Append(Regex.Escape(english.Substring(num))).Append("\\z");
		Pattern = new Regex(stringBuilder.ToString(), RegexOptions.CultureInvariant, TimeSpan.FromMilliseconds(30.0));
	}
}
public static class Translation
{
	private static readonly Dictionary<string, Entry> Entries = GeneratedData.Entries.ToDictionary<Entry, string>((Entry e) => e.Token, StringComparer.Ordinal);

	private static readonly Regex Placeholder = new Regex("\\{(\\d+)\\}");

	private static readonly Regex Han = new Regex("[\\u3400-\\u9fff]");

	private static readonly Regex Tags = new Regex("<[^>]*>");

	private static readonly Regex Numbers = new Regex("[-+]?\\d+(?:[.,]\\d+)*(?:[eE][-+]?\\d+)?");

	private static readonly KeyValuePair<string, string>[] Labels = new KeyValuePair<string, string>[11]
	{
		new KeyValuePair<string, string>("Bonus damage dealt: ", "累计额外伤害:"),
		new KeyValuePair<string, string>("Damage dealt: ", "累计造成伤害:"),
		new KeyValuePair<string, string>("Bonus crit chance: ", "额外暴击几率:"),
		new KeyValuePair<string, string>("Bonus crit damage: ", "额外暴击伤害:"),
		new KeyValuePair<string, string>("Total gold gained: ", "累计获得金币:"),
		new KeyValuePair<string, string>("Cooldown reduction: ", "冷却缩减:"),
		new KeyValuePair<string, string>("Extra procCoef: ", "额外触发系数:"),
		new KeyValuePair<string, string>("Times activated: ", "累计触发次数:"),
		new KeyValuePair<string, string>("Health gained: ", "累计获得生命:"),
		new KeyValuePair<string, string>("Barrier given: ", "累计提供屏障:"),
		new KeyValuePair<string, string>("Healing: ", "累计治疗量:")
	};

	public static IEnumerable<Entry> All => GeneratedData.Entries;

	public static string Translate(string token, string original)
	{
		if (string.IsNullOrEmpty(token) || string.IsNullOrEmpty(original) || Han.IsMatch(original) || !Entries.TryGetValue(token, out var value))
		{
			return original;
		}
		if (!value.Dynamic)
		{
			if (!(original == value.English))
			{
				return original;
			}
			return value.Chinese;
		}
		Match match = value.Pattern.Match(original);
		if (!match.Success)
		{
			return original;
		}
		string text = Placeholder.Replace(value.Chinese, (Match p) => match.Groups["v" + p.Groups[1].Value].Value);
		if (!(from Match m in Tags.Matches(original)
			select m.Value).OrderBy<string, string>((string x) => x, StringComparer.Ordinal).SequenceEqual((from Match m in Tags.Matches(text)
			select m.Value).OrderBy<string, string>((string x) => x, StringComparer.Ordinal)))
		{
			return original;
		}
		if (!(from Match m in Numbers.Matches(original)
			select m.Value).OrderBy<string, string>((string x) => x, StringComparer.Ordinal).SequenceEqual((from Match m in Numbers.Matches(text)
			select m.Value).OrderBy<string, string>((string x) => x, StringComparer.Ordinal)))
		{
			return original;
		}
		return text;
	}

	public static bool IsStatsLiteral(string text)
	{
		if (!string.IsNullOrEmpty(text) && text.Contains("<br>"))
		{
			return Labels.Any((KeyValuePair<string, string> pair) => text.Contains(pair.Key));
		}
		return false;
	}

	public static string StatsLiteral(string text)
	{
		if (!IsStatsLiteral(text))
		{
			return text;
		}
		KeyValuePair<string, string>[] labels = Labels;
		for (int i = 0; i < labels.Length; i++)
		{
			KeyValuePair<string, string> keyValuePair = labels[i];
			text = text.Replace(keyValuePair.Key, "<style=cStack>" + keyValuePair.Value + "</style> ");
		}
		return text;
	}
}
internal static class GeneratedData
{
	internal static readonly Entry[] Entries = new Entry[66]
	{
		new Entry("BannerOfCommand", "BannerOfCommand", "Banner of Command", "号令之旗"),
		new Entry("BannerOfCommand", "BannerOfCommandItem", "Increase allied minion damage.", "提高友方仆从的伤害。"),
		new Entry("BannerOfCommand", "BannerOfCommandDesc", "Increase the damage of allied minions by <style=cIsUtility>{0}%</style> <style=cStack>(+{1}%)</style>.", "友方仆从造成的伤害提高 <style=cIsUtility>{0}%</style><style=cStack>(每层+{1}%)</style>。"),
		new Entry("BannerOfCommand", "BannerOfCommandLore", "Split pushing is boring.", "分推真无聊。"),
		new Entry("Bork", "Bork", "Blade of the Ruined King", "破败王者之刃"),
		new Entry("Bork", "BorkItem", "Increases attack speed. Every {0} hits do damage and heal, and has a cooldown. Corrupts <style=cIsVoid>Syringes</style> and <style=cIsVoid>Leaching Seeds</style>.", "提高攻击速度。每命中 {0} 次造成额外伤害并治疗自身,效果有冷却时间。腐化所有<style=cIsVoid>士兵的注射器</style>和<style=cIsVoid>吸血种子</style>。"),
		new Entry("Bork", "BorkDesc", "Gives <style=cIsDamage>{0}%</style> <style=cStack>(+{1}%)</style> attack speed. Deals <style=cIsDamage>{2}%</style> <style=cStack>(+{3}%)</style> current enemy hp every third hit, and heal for <style=cIsHealing>{4}%</style> of that damage on a {5} second cooldown. Corrupts <style=cIsVoid>Syringes</style> and <style=cIsVoid>Leaching Seeds</style>.", "攻击速度提高 <style=cIsDamage>{0}%</style><style=cStack>(每层+{1}%)</style>。每第三次命中造成相当于敌人当前生命值 <style=cIsDamage>{2}%</style><style=cStack>(每层+{3}%)</style>的伤害,并将该次伤害的 <style=cIsHealing>{4}%</style>用于治疗自身,冷却时间为 {5} 秒。腐化所有<style=cIsVoid>士兵的注射器</style>和<style=cIsVoid>吸血种子</style>。"),
		new Entry("Bork", "BorkLore", "Viego is a plague to everything he touches.", "佛耶戈所到之处,皆受灾殃。"),
		new Entry("Cull", "Cull", "Cull", "萃取"),
		new Entry("Cull", "CullItem", "Gives gold when killing enemies. Turns into White Scrap when <style=cIsUtility>{0}</style> enemies are killed.", "击杀敌人时获得金币。击杀 <style=cIsUtility>{0}</style> 名敌人后转化为白色废料。"),
		new Entry("Cull", "CullDesc", "Gives <style=cIsUtility>{0}</style> <style=cStack>(+{1})</style> gold when killing an enemy. Upon killing <style=cIsUtility>{2}</style> enemies, turns into White Scrap.", "每击杀一名敌人获得 <style=cIsUtility>{0}</style><style=cStack>(每层+{1})</style> 金币。击杀 <style=cIsUtility>{2}</style> 名敌人后,转化为白色废料。"),
		new Entry("Cull", "CullLore", "I personally like Doran's Blade more.", "我个人更喜欢多兰之刃。"),
		new Entry("Cull", "CullBuff", "Gold gained", "已获得的金币"),
		new Entry("ExperimentalHexplate", "ExperimentalHexplate", "Experimental Hexplate", "海克斯注力刚壁"),
		new Entry("ExperimentalHexplate", "ExperimentalHexplateItem", "Using your Special skill temporarily increases your attack speed and movespeed.", "使用特殊技能后,暂时提高攻击速度和移动速度。"),
		new Entry("ExperimentalHexplate", "ExperimentalHexplateDesc", "Using your Special skill increases your attack speed by <style=cIsDamage>{0}%</style> <style=cStack>(+ {1}%)</style> and your movespeed by <style=cIsUtility>{2}%</style> <style=cStack>(+ {3}%)</style> for {4} seconds.", "使用特殊技能后,攻击速度提高 <style=cIsDamage>{0}%</style><style=cStack>(每层+ {1}%)</style>,移动速度提高 <style=cIsUtility>{2}%</style><style=cStack>(每层+ {3}%)</style>,持续 {4} 秒。"),
		new Entry("ExperimentalHexplate", "ExperimentalHexplateLore", "Was it wise to put on something this experimental? <br><br>Probably.", "穿上这么有实验性质的东西,真的明智吗?<br><br>大概吧。"),
		new Entry("ExperimentalHexplate", "ExperimentalHexplateBuff", "Experimental Hexplate", "海克斯注力刚壁"),
		new Entry("GargoyleStoneplate", "GargoyleStoneplate", "Gargoyle Stoneplate", "石像鬼石板甲"),
		new Entry("GargoyleStoneplate", "GargoyleStoneplateItem", "Temporarily gain armor and a barrier based on your maximum health.", "暂时获得护甲和基于最大生命值的屏障。"),
		new Entry("GargoyleStoneplate", "GargoyleStoneplateDesc", "Temporarily gain <style=cIsHealing>{0}</style> armor for <style=cIsUtility>{1}s</style> and a barrier for <style=cIsHealing>{2}%</style> of your maximum health.", "暂时获得 <style=cIsHealing>{0}</style> 点护甲,持续 <style=cIsUtility>{1}秒</style>,并获得相当于最大生命值 <style=cIsHealing>{2}%</style>的屏障。"),
		new Entry("GargoyleStoneplate", "GargoyleStoneplateLore", "Whoever thought of breaking this off of a gargoyle's body and strapping it onto their own body was a genius.", "能想到从石像鬼身上掰下这东西再绑到自己身上的人,真是个天才。"),
		new Entry("GuardiansBlade", "GuardiansBlade", "Guardian's Blade", "守护者之刃"),
		new Entry("GuardiansBlade", "GuardiansBladeItem", "Reduce the cooldown on secondary and utility skills.", "缩短次要技能和辅助技能的冷却时间。"),
		new Entry("GuardiansBlade", "GuardiansBladeDesc", "Reduce the cooldown on your secondary and utility skills by <style=cIsUtility>{0}%</style> <style=cStack>(+{1})</style>. Scales hyperbolically, just like tougher times.", "次要技能和辅助技能的冷却时间缩短 <style=cIsUtility>{0}%</style><style=cStack>(每层+{1})</style>。与艰难时光一样,采用双曲线叠加。"),
		new Entry("GuardiansBlade", "GuardiansBladeLore", "Awesome refund And movement.", "出色的返还与机动能力。"),
		new Entry("GuinsoosRageblade", "GuinsoosRageblade", "Guinsoo's Rageblade", "鬼索的狂暴之刃"),
		new Entry("GuinsoosRageblade", "GuinsoosRagebladeItem", "Increase proc coefficient of everything.", "提高所有效果的触发系数。"),
		new Entry("GuinsoosRageblade", "GuinsoosRagebladeDesc", "Gives <style=cIsUtility>{0}</style> <style=cStack>(+{1})</style> proc coefficient to everything.", "所有效果的触发系数增加 <style=cIsUtility>{0}</style><style=cStack>(每层+{1})</style>。"),
		new Entry("GuinsoosRageblade", "GuinsoosRagebladeLore", "Procs go brrrrrrr.", "触发效果突突突突突。"),
		new Entry("Heartsteel", "Heartsteel", "Heartsteel", "心之钢"),
		new Entry("Heartsteel", "HeartsteelItem", "Gain permanent health on kill with no cap. Every few seconds deal a portion of your health as extra damage on hit.", "击杀永久提高生命值,没有上限。每隔几秒,命中时附加基于自身生命值的伤害。"),
		new Entry("Heartsteel", "HeartsteelDesc", "Adds <style=cIsHealth>{0}</style> <style=cStack>(+{1})</style> base health per kill with no cap. Every <style=cIsUtility>{2}</style> seconds deal <style=cIsDamage>{3}%</style> of your max health as damage on hit.", "每次击杀永久增加 <style=cIsHealth>{0}</style><style=cStack>(每层+{1})</style> 点基础生命值,没有上限。每隔 <style=cIsUtility>{2}</style> 秒,命中时附加相当于自身最大生命值 <style=cIsDamage>{3}%</style>的伤害。"),
		new Entry("Heartsteel", "HeartsteelLore", "Lore was meant to go here, but Sion trampled it.", "这里本该放一段背景故事,但塞恩把它踩烂了。"),
		new Entry("ImmortalShieldbow", "ImmortalShieldbow", "Immortal Shieldbow", "不朽盾弓"),
		new Entry("ImmortalShieldbow", "ImmortalShieldbowItem", "Gives a barrier when low on health.", "生命值较低时获得屏障。"),
		new Entry("ImmortalShieldbow", "ImmortalShieldbowDesc", "Gives a barrier for <style=cIsHealth>{0}%</style> <style=cStack>(+{1}%)</style> of your max health when dropping below <style=cIsHealth>{2}%</style> max health. On a <style=cIsUtility>{3}</style> second cooldown.", "生命值降至最大生命值的 <style=cIsHealth>{2}%</style>以下时,获得相当于最大生命值 <style=cIsHealth>{0}%</style><style=cStack>(每层+{1}%)</style>的屏障。冷却时间为 <style=cIsUtility>{3}</style> 秒。"),
		new Entry("ImmortalShieldbow", "ImmortalShieldbowLore", "Here to save you for when you mess up.", "在你失手时救你一命。"),
		new Entry("ImmortalShieldbow", "ImmortalShieldbowBuff", "Immortal Shieldbow is recharging.", "不朽盾弓正在充能。"),
		new Entry("ImperialMandate", "ImperialMandate", "Imperial Mandate", "帝国指令"),
		new Entry("ImperialMandate", "ImperialMandateItem", "Do more damage to enemies for each debuff. Corrupts <style=cIsVoid>Death Mark</style>.", "敌人每有一种减益效果,你对其造成的伤害就会提高。腐化所有<style=cIsVoid>死亡标记</style>。"),
		new Entry("ImperialMandate", "ImperialMandateDesc", "Do <style=cIsDamage>{0}%</style> <style=cStack>(+{1}%)</style> more damage to enemies for each debuff. Corrupts <style=cIsVoid>Death Mark</style>.", "敌人每有一种减益效果,你对其造成的伤害提高 <style=cIsDamage>{0}%</style><style=cStack>(每层+{1}%)</style>。腐化所有<style=cIsVoid>死亡标记</style>。"),
		new Entry("ImperialMandate", "ImperialMandateLore", "Hunt your prey.", "猎杀你的猎物。"),
		new Entry("InfinityEdge", "InfinityEdge", "Infinity Edge", "无尽之刃"),
		new Entry("InfinityEdge", "InfinityEdgeItem", "Gain crit chance and crit damage.", "提高暴击几率和暴击伤害。"),
		new Entry("InfinityEdge", "InfinityEdgeDesc", "Gain <style=cIsUtility>{0}%</style> <style=cStack>(+{1})</style> crit chance and <style=cIsDamage>{2}%</style> <style=cStack>(+{3})</style> crit damage.", "暴击几率提高 <style=cIsUtility>{0}%</style><style=cStack>(每层+{1})</style>,暴击伤害提高 <style=cIsDamage>{2}%</style><style=cStack>(每层+{3})</style>。"),
		new Entry("InfinityEdge", "InfinityEdgeLore", "For when enemies need to die.", "当你需要让敌人倒下时。"),
		new Entry("KrakenSlayer", "KrakenSlayer", "Kraken Slayer", "海妖杀手"),
		new Entry("KrakenSlayer", "KrakenSlayerItem", "Every {0} hits do bonus damage.", "每命中 {0} 次造成额外伤害。"),
		new Entry("KrakenSlayer", "KrakenSlayerDesc", "Every {0} hits do an extra <style=cIsDamage>{1}%</style> <style=cStack>(+{2}%)</style> base damage.", "每命中 {0} 次,额外造成 <style=cIsDamage>{1}%</style><style=cStack>(每层+{2}%)</style>基础伤害。"),
		new Entry("KrakenSlayer", "KrakenSlayerLore", "Legend has it that this item is no longer mythical.", "传说,这件物品已经不再是神话。"),
		new Entry("Liandrys", "Liandrys", "Liandry's Anguish", "兰德里的苦楚"),
		new Entry("Liandrys", "LiandrysItem", "Burn enemies on hit for a % of their max health.", "命中时灼烧敌人,造成基于敌人最大生命值的百分比伤害。"),
		new Entry("Liandrys", "LiandrysDesc", "On hit burn enemies for <style=cIsDamage>{0}%</style> <style=cStack>(+{1}%)</style> max health over {2} seconds.", "命中时灼烧敌人,在 {2} 秒内造成相当于敌人最大生命值 <style=cIsDamage>{0}%</style><style=cStack>(每层+{1}%)</style>的伤害。"),
		new Entry("Liandrys", "LiandrysLore", "A crying mask is a great halloween costume.", "一张哭泣的面具是很棒的万圣节装扮。"),
		new Entry("Liandrys", "LiandrysBuff", "Liandry's Anguish is burning this unit.", "该单位正受到兰德里的苦楚的灼烧。"),
		new Entry("MejaisSoulstealer", "MejaisSoulstealer", "Mejai's Soulstealer", "梅贾的窃魂卷"),
		new Entry("MejaisSoulstealer", "MejaisSoulstealerItem", "Killing enemies grants more damage for a short time.", "击杀敌人后,短暂提高造成的伤害。"),
		new Entry("MejaisSoulstealer", "MejaisSoulstealerDesc", "Killing an enemy grants a stack which gives <style=cIsDamage>{0}%</style> bonus damage. Max <style=cIsUtility>{1}</style> stacks, buff lasts for <style=cIsUtility>{2}</style> <style=cStack>(+{3})</style> seconds. Get <style=cIsUtility>{4}%</style> movement speed when at max stacks.", "击杀敌人获得一层增益,每层使伤害提高 <style=cIsDamage>{0}%</style>。最多 <style=cIsUtility>{1}</style> 层,增益持续 <style=cIsUtility>{2}</style><style=cStack>(每层+{3})</style> 秒。叠满时获得 <style=cIsUtility>{4}%</style>移动速度。"),
		new Entry("MejaisSoulstealer", "MejaisSoulstealerLore", "Your death note.", "你的死亡笔记。"),
		new Entry("MejaisSoulstealer", "MejaisSoulstealerBuff", "Mejai's Soulstealer stacks.", "梅贾的窃魂卷层数。"),
		new Entry("MejaisSoulstealer", "MejaisSoulstealerBuffDuration", "Mejai's Soulstealer duration remaining.", "梅贾的窃魂卷剩余持续时间。"),
		new Entry("Rabadons", "RabadonsDeathcap", "Rabadon's Deathcap", "灭世者的死亡之帽"),
		new Entry("Rabadons", "RabadonsDeathcapItem", "Hat makes them go splat.", "一顶让敌人稀巴烂的帽子。"),
		new Entry("Rabadons", "RabadonsDeathcapDesc", "Do <style=cIsUtility>{0}%</style> <style=cStack>(+{1}%)</style> more damage.", "造成的伤害提高 <style=cIsUtility>{0}%</style><style=cStack>(每层+{1}%)</style>。"),
		new Entry("Rabadons", "RabadonsDeathcapLore", "Makes you feel like a wizard.", "让你感觉自己像个巫师。")
	};
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
[BepInPlugin("local.lolitems.zh", "LoLItems_zh", "1.0.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public sealed class Plugin : BaseUnityPlugin
{
	public const string Guid = "local.lolitems.zh";

	private static Plugin instance;

	private ConfigEntry<bool> enabledSetting;

	private Harmony harmony;

	private bool languageHooked;

	private readonly HashSet<string> activeTokens = new HashSet<string>(StringComparer.Ordinal);

	private readonly HashSet<string> activeClasses = new HashSet<string>(StringComparer.Ordinal);

	private readonly HashSet<string> warned = new HashSet<string>(StringComparer.Ordinal);

	private static bool Chinese
	{
		get
		{
			if ((Object)(object)instance != (Object)null && instance.enabledSetting.Value && Language.currentLanguage != null)
			{
				return Language.currentLanguage.name == "zh-CN";
			}
			return false;
		}
	}

	private void Awake()
	{
		//IL_0297: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a1: Expected O, but got Unknown
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Expected O, but got Unknown
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Expected O, but got Unknown
		//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f0: Expected O, but got Unknown
		instance = this;
		enabledSetting = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "启用 LoLItems 简体中文翻译。仅影响文本,不改变装备机制。");
		try
		{
			Assembly assembly = ((object)Chainloader.PluginInfos["Debo.LoLItems"].Instance).GetType().Assembly;
			foreach (IGrouping<string, Entry> item in from e in Translation.All
				group e by e.ClassName)
			{
				Type type = assembly.GetType("LoLItems." + item.Key, throwOnError: false);
				if (type == null)
				{
					continue;
				}
				FieldInfo fieldInfo = AccessTools.Field(type, "myItemDef") ?? AccessTools.Field(type, "myEquipmentDef");
				if (fieldInfo == null || fieldInfo.GetValue(null) == null)
				{
					continue;
				}
				activeClasses.Add(item.Key);
				foreach (Entry item2 in item)
				{
					activeTokens.Add(item2.Token);
				}
			}
			harmony = new Harmony("local.lolitems.zh");
			Language.GetLocalizedStringByToken += new hook_GetLocalizedStringByToken(Lookup);
			languageHooked = true;
			RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(AfterGameLoad));
			int num = 0;
			foreach (string activeClass in activeClasses)
			{
				Type type2 = assembly.GetType("LoLItems." + activeClass, throwOnError: false);
				MethodInfo methodInfo = AccessTools.Method(type2, "GetDisplayInformation", (Type[])null, (Type[])null);
				if (!(methodInfo == null))
				{
					harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "StatsTranspiler", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null);
					num++;
				}
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)("LoLItems_zh ready: " + activeClasses.Count + " registered item/equipment definitions, " + activeTokens.Count + " text tokens, " + num + " statistics methods. No item registrations or gameplay changes."));
		}
		catch (Exception ex)
		{
			if (languageHooked)
			{
				Language.GetLocalizedStringByToken -= new hook_GetLocalizedStringByToken(Lookup);
				languageHooked = false;
			}
			RoR2Application.onLoad = (Action)Delegate.Remove(RoR2Application.onLoad, new Action(AfterGameLoad));
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			activeTokens.Clear();
			activeClasses.Clear();
			((BaseUnityPlugin)this).Logger.LogError((object)("LoLItems_zh disabled after initialization error: " + ex));
		}
	}

	private static string Lookup(orig_GetLocalizedStringByToken orig, Language self, string token)
	{
		string __result = orig.Invoke(self, token);
		LanguagePostfix(self, token, ref __result);
		return __result;
	}

	private void AfterGameLoad()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		Language.GetLocalizedStringByToken -= new hook_GetLocalizedStringByToken(Lookup);
		Language.GetLocalizedStringByToken += new hook_GetLocalizedStringByToken(Lookup);
		if (!Chinese)
		{
			return;
		}
		int num = 0;
		foreach (string activeToken in activeTokens)
		{
			string localizedStringByToken = Language.currentLanguage.GetLocalizedStringByToken(activeToken);
			if (Regex.IsMatch(localizedStringByToken ?? "", "[\\u3400-\\u9fff]"))
			{
				num++;
			}
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)("Language chain check: " + num + "/" + activeTokens.Count + " active tokens display Chinese; Heartsteel=" + Language.currentLanguage.GetLocalizedStringByToken("Heartsteel")));
	}

	private static void LanguagePostfix(Language __instance, string __0, ref string __result)
	{
		if (!Chinese || __instance == null || __instance.name != "zh-CN" || !instance.activeTokens.Contains(__0))
		{
			return;
		}
		try
		{
			string text = ((Language.english != null && Language.english != __instance) ? Language.english.GetLocalizedStringByToken(__0) : __result);
			if (!string.IsNullOrEmpty(text))
			{
				string text2 = Translation.Translate(__0, text);
				if (text2 != text)
				{
					__result = text2;
				}
				if (text2 == text && !Regex.IsMatch(text, "[\\u3400-\\u9fff]") && text != __0 && instance.warned.Count < 100 && instance.warned.Add(__0))
				{
					((BaseUnityPlugin)instance).Logger.LogWarning((object)("Unrecognized English text retained for token " + __0 + ". This mod may require an update for that LoLItems version."));
				}
			}
		}
		catch (Exception ex)
		{
			if (instance.warned.Add(__0))
			{
				((BaseUnityPlugin)instance).Logger.LogWarning((object)("Translation skipped for " + __0 + ": " + ex.Message));
			}
		}
	}

	private static IEnumerable<CodeInstruction> StatsTranspiler(IEnumerable<CodeInstruction> instructions)
	{
		MethodInfo helper = AccessTools.Method(typeof(Plugin), "LocalizeStatsLiteral", (Type[])null, (Type[])null);
		foreach (CodeInstruction code in instructions)
		{
			yield return code;
			if (code.opcode == OpCodes.Ldstr && Translation.IsStatsLiteral(code.operand as string))
			{
				yield return new CodeInstruction(OpCodes.Call, (object)helper);
			}
		}
	}

	public static string LocalizeStatsLiteral(string original)
	{
		if (!Chinese)
		{
			return original;
		}
		return Translation.StatsLiteral(original);
	}

	private void OnDestroy()
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Expected O, but got Unknown
		if (languageHooked)
		{
			Language.GetLocalizedStringByToken -= new hook_GetLocalizedStringByToken(Lookup);
		}
		RoR2Application.onLoad = (Action)Delegate.Remove(RoR2Application.onLoad, new Action(AfterGameLoad));
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
		if ((Object)(object)instance == (Object)(object)this)
		{
			instance = null;
		}
	}
}