Decompiled source of Goku Chinese Package v1.3.0

GokuChinesePackage.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using R2API;
using RoR2;
using RoR2.Skills;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace NormalAIPeople.GokuChinesePackage
{
	[BepInPlugin("normalaipeople.goku.chinese.package", "Goku Chinese Package", "1.3.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class GokuChinesePackagePlugin : BaseUnityPlugin
	{
		private sealed class Translation
		{
			public readonly string Name;

			public readonly string Description;

			public Translation(string name, string description)
			{
				Name = name;
				Description = description;
			}
		}

		public const string PluginGuid = "normalaipeople.goku.chinese.package";

		public const string PluginName = "Goku Chinese Package";

		public const string PluginVersion = "1.3.0";

		private const string TokenPrefix = "NORMALAIPEOPLE_GOKU_";

		private readonly HashSet<string> registeredTokens = new HashSet<string>();

		private bool translationsApplied;

		private static readonly Dictionary<string, string> UiText = new Dictionary<string, string>(StringComparer.Ordinal)
		{
			{ "Transformations", "变身" },
			{ "Transformation", "变身形态" },
			{ "Overview", "概览" },
			{ "TRANSFORMATION", "变身形态" },
			{ "SKILL", "技能" },
			{ "LOADOUT", "装配" },
			{ "Power Level: ", "战斗力:" },
			{ "Total Mastery Levels Required: ", "所需总精通等级:" },
			{ "Ki Drain: ", "气消耗:" },
			{ " Per Second", "/秒" },
			{ "Charge Power: ", "蓄力威力:" },
			{ "Ultimate Skill", "终极技能" },
			{ "REMOVE", "移除" },
			{ "TOGGLE EXTRA", "切换额外形态" },
			{ "Damage", "伤害" },
			{ "Armor", "护甲" },
			{ "Attack Speed", "攻击速度" },
			{ "Movement Speed", "移动速度" },
			{ "Base Form", "常态" },
			{ "Super Saiyan", "超级赛亚人" },
			{ "Super Saiyan 2", "超级赛亚人2" },
			{ "Super Saiyan 3", "超级赛亚人3" },
			{ "Super Saiyan 4", "超级赛亚人4" },
			{ "Super Saiyan 5", "超级赛亚人5" },
			{ "Super Saiyan God", "超级赛亚人之神" },
			{ "Super Saiyan God 3", "超级赛亚人之神3" },
			{ "Super Saiyan Blue", "超级赛亚人蓝" },
			{ "Super Saiyan Blue 3", "超级赛亚人蓝3" },
			{ "Super Saiyan Rose", "超级赛亚人桃红" },
			{ "Ultra Instinct", "自在极意功" },
			{ "Kaioken", "界王拳" },
			{ "Kaioken x3", "界王拳·3倍" },
			{ "Kaioken x10", "界王拳·10倍" },
			{ "Kaioken x20", "界王拳·20倍" },
			{ "Kaioken None", "未启用界王拳" },
			{ "All Forms unlocked", "全部形态已解锁" },
			{ "All Kaioken Forms unlocked", "全部界王拳形态已解锁" },
			{ "Mastered", "已精通" },
			{ " until next unlock", "后解锁下一形态" },
			{ " Mastery level", "级精通等级" },
			{ "Saiyan Blood", "赛亚人血统" },
			{ "Main Transformation", "主变身" },
			{ "Kaioken Transformation", "界王拳变身" },
			{ "Power down", "解除变身" },
			{ "Fly", "飞行" },
			{ "Jump", "跳跃" },
			{ "Ki", "气" },
			{ "All skills have no cooldowns; A ", "所有技能均无冷却时间;改为使用" },
			{ " resource is used instead!.\nPerform a ", "资源。\n轻按" },
			{ " (View Transformations Tab for more info).\nPerform a ", "(更多信息请见“变身”页)。\n按住" },
			{ " by tapping ", "以" },
			{ " by holding ", "以" },
			{ "Teleports instead if ", "若已激活" },
			{ " is active!", ",则改为瞬间移动攻击!" },
			{ "Unleashes a trio of kicks! \nDealing ", "施展三段踢击!每一击造成" },
			{ " each!\nGain ", "伤害!\n每次命中回复" },
			{ "% Ki", "%气" },
			{ " Per Hit!", "!" },
			{ "\nFire off a speedy Ki Blast! \n", "\n快速发射气弹!\n" },
			{ "Holding this skill fires an additional blast ", "按住技能会额外发射气弹" },
			{ "\nRapidly unleash a barrage of strikes! \nDealing ", "\n快速施展连续打击!每一击造成" },
			{ "\nCharge and unleash a Kamehameha, Dealing ", "\n蓄力并释放龟派气功,造成" },
			{ " per second whilst the blast is active! \nConsume additional Ki and increase damage by ", "每秒伤害。光束持续期间消耗额外气,并使伤害每秒提高" },
			{ " per second of charging!\n", "!\n" },
			{ "Ki consumption gradually increases the longer you charge!", "蓄力越久,气的消耗越高!" },
			{ "\nCharge and unleash a Spirit Bomb, Dealing ", "\n蓄力并释放元气弹,造成" },
			{ " seconds to enemies within it! \nConsume additional Ki and increase overall damage by ", "秒内对范围敌人造成伤害!消耗额外气,并使总伤害每秒提高" },
			{ "If the Spirit Bomb collides with a boss or the ground, it will explode, Dealing ", "元气弹撞到首领或地面时会爆炸,造成" },
			{ "Gain Bonus Armor whilst standing still.", "静止时获得额外护甲。" },
			{ "Whilst moving the Spirit Bomb will not charge!", "移动时元气弹无法蓄力!" },
			{ "\nUnleash an Angry Kamehameha, Dealing ", "\n释放愤怒龟派气功,造成" },
			{ "\nCharge and unleash a godly Black Kamehameha, Dealing ", "\n蓄力并释放神圣的黑色龟派气功,造成" },
			{ "\nCharge forward and unleash a Fiery Dragon Fist, Dealing ", "\n向前突进并施展烈焰龙拳,造成" },
			{ " to every enemy hit!\n", "伤害给每个命中的敌人!\n" },
			{ "Deals bonus damage to low health targets!", "对低生命值目标造成额外伤害!" },
			{ "\nChannel the Saiyan God's power and deal ", "\n引导赛亚人之神的力量,造成" },
			{ " and stun per pulse!\n", "伤害并在每次脉冲时眩晕敌人!\n" },
			{ "Extend the duration at the cost of ", "消耗" },
			{ " Ki per second!", "气每秒以延长持续时间!" },
			{ "\nCharge and Unleash a God Kamehameha, Dealing ", "\n蓄力并释放神之龟派气功,造成" },
			{ " per second whilst the blast is active! \nThen continuing with a God Fist, Dealing ", "每秒伤害;随后接续神之拳,造成" },
			{ "\nrapidly teleport and strike all nearby enemies dealing ", "\n快速瞬移并攻击附近所有敌人,造成" },
			{ "!\nFinishes off with a powerful roar dealing ", "!\n最后以强力咆哮收尾,造成" },
			{ " to all nearby enemies!\n", "伤害给附近所有敌人!\n" },
			{ "The number of strikes increases based on attack speed", "攻击次数会随攻击速度提高。" },
			{ "\nCharge and unleash a powerful Kamehameha x10, Dealing ", "\n蓄力并释放强力十倍龟派气功,造成" },
			{ "\nUnleash an Barrage of Ki Blasts, Dealing ", "\n释放一阵气弹,造成" },
			{ " with each one!", "伤害/发!" },
			{ "Mitigates strain, allowing for extended Kaioken usage.", "减轻负担,使界王拳能够维持更久。" },
			{ "\nFocus on your target and teleport!\n", "\n锁定目标后瞬间移动!\n" },
			{ "Distance is limited if there is no target", "没有目标时移动距离有限。" },
			{ "None", "无" }
		};

		private static readonly Dictionary<string, Translation> Translations = new Dictionary<string, Translation>(StringComparer.Ordinal)
		{
			{
				"Melee Strike",
				new Translation("近战打击", "以近战连击攻击敌人。激活<style=cIsUtility>界王拳</style>时会改为瞬间移动攻击。")
			},
			{
				"Triple Kick (Legacy)",
				new Translation("三重踢(旧版)", "连续踢击三次,每次造成伤害并回复<style=cIsHealing>气</style>。")
			},
			{
				"Instant Transmission",
				new Translation("瞬间移动", "锁定目标后瞬间移动至其附近;没有目标时移动距离受限。")
			},
			{
				"Ki Charge",
				new Translation("气力充能", "凝聚气以补充<style=cIsHealing>气</style>,并缓解负担以延长界王拳的持续时间。")
			},
			{
				"Kamehameha",
				new Translation("龟派气功", "蓄力后释放龟派气功。持续蓄力会消耗更多<style=cIsHealing>气</style>并提高伤害。")
			},
			{
				"Spirit Bomb",
				new Translation("元气弹", "蓄力后释放元气弹,对范围内敌人造成伤害。蓄力会提高威力并消耗更多<style=cIsHealing>气</style>;静止时获得护甲,移动时无法蓄力。")
			},
			{
				"Angry Kamehameha",
				new Translation("愤怒龟派气功", "释放愤怒龟派气功,对路径上的敌人造成持续伤害。")
			},
			{
				"Ki Blast Barrage",
				new Translation("气弹连射", "释放大量气弹,每发造成伤害。")
			},
			{
				"Dragon Fist",
				new Translation("龙拳", "以强力的龙形一击突进并粉碎敌人。")
			},
			{
				"God Bind",
				new Translation("神之束缚", "运用赛亚人之神的力量束缚并眩晕敌人。可消耗<style=cIsHealing>气</style>延长持续时间。")
			},
			{
				"Godly Display",
				new Translation("神之制裁", "快速瞬间移动并打击附近敌人,最后以强力咆哮收尾;攻击次数受攻击速度影响。")
			},
			{
				"Kamehameha x10",
				new Translation("十倍龟派气功", "蓄力后释放强力十倍龟派气功。蓄力会提高伤害并消耗更多<style=cIsHealing>气</style>。")
			},
			{
				"Black Kamehameha",
				new Translation("黑色龟派气功", "蓄力后释放神圣的黑色龟派气功;蓄力会提高伤害并消耗更多<style=cIsHealing>气</style>。")
			},
			{
				"White Dragon Fist",
				new Translation("白龙拳", "以白龙之力发动强力近战终结一击。")
			},
			{
				"Ki Blast",
				new Translation("气弹", "快速发射气弹;按住可连续发射并消耗气。")
			},
			{
				"Meteor Crash",
				new Translation("流星冲击", "快速施展连续攻击;按住会持续消耗气。")
			},
			{
				"God Kamehameha",
				new Translation("神之龟派气功", "蓄力后释放神之龟派气功,并接续神之拳。")
			},
			{
				"Super Kamehameha",
				new Translation("超级龟派气功", "蓄力后释放强力龟派气功。")
			},
			{
				"Saiyan Blood",
				new Translation("赛亚人血统", "所有技能无冷却时间,改为消耗气;可进行变身、解除变身与飞行。")
			}
		};

		private void Start()
		{
			InstallUiPatches();
			RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(ApplyTranslationsOnce));
		}

		private void OnDestroy()
		{
			RoR2Application.onLoad = (Action)Delegate.Remove(RoR2Application.onLoad, new Action(ApplyTranslationsOnce));
		}

		private void ApplyTranslationsOnce()
		{
			if (!translationsApplied)
			{
				translationsApplied = true;
				ApplyTranslations();
			}
		}

		private void InstallUiPatches()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			Harmony harmony = new Harmony("normalaipeople.goku.chinese.package");
			Patch(harmony, "NS_KingModUtilities.TrainingMenuUI", "OnCharacterSelected");
			Patch(harmony, "NS_KingModUtilities.UI_TransformationsMenu", "OnExtraTransformationButtonClicked");
			Patch(harmony, "NS_KingModUtilities.UI_TransformationDisplay", "DrawElement");
			Patch(harmony, "NS_KingModUtilities.UI_TransformationDisplay", "CreateTransformationInfoText");
			Patch(harmony, "NS_KingModUtilities.UI_TransformationDisplay", "CreateMasteryText");
			Patch(harmony, "NS_KingModUtilities.BONUS_STAT_NAMES", "ConvertStatNameToDisplayName");
			Patch(harmony, "NS_KingModUtilities.TransformationHandler", "CheckTransformationsAvailable");
			Patch(harmony, "NS_KingModUtilities.TransformationHandler", "CheckKaiokenTransformationsAvailable");
			Patch(harmony, "NS_Goku.GokuTransformationData", "GetTransformationSkillName");
			Patch(harmony, "NS_Goku.GokuTransformationHandler", "OnTransformedFirstTime");
			Patch(harmony, "NS_Goku.UI_Kaioken", "DrawElement");
			string[] array = new string[15]
			{
				"NS_KingModUtilities.TSuperSaiyan", "NS_KingModUtilities.TSuperSaiyan2", "NS_KingModUtilities.TSuperSaiyan3", "NS_KingModUtilities.TSuperSaiyan4", "NS_KingModUtilities.TSuperSaiyan5", "NS_KingModUtilities.TSuperSaiyanGod", "NS_KingModUtilities.TSuperSaiyanGod3", "NS_KingModUtilities.TSuperSaiyanBlue", "NS_KingModUtilities.TSuperSaiyanBlue3", "NS_KingModUtilities.TSuperSaiyanRose",
				"NS_KingModUtilities.TUltraInstinct", "NS_KingModUtilities.TKaioken", "NS_KingModUtilities.TKaiokenx3", "NS_KingModUtilities.TKaiokenx10", "NS_KingModUtilities.TKaiokenx20"
			};
			foreach (string typeName in array)
			{
				Patch(harmony, typeName, "InitTransformation");
			}
		}

		private static void Patch(Harmony harmony, string typeName, string methodName)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			Type type = AccessTools.TypeByName(typeName);
			if (type == null)
			{
				return;
			}
			MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (MethodInfo methodInfo in methods)
			{
				if (methodInfo.Name == methodName)
				{
					harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(GokuChinesePackagePlugin), "LocalizeStringLiterals", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null);
				}
			}
		}

		private static IEnumerable<CodeInstruction> LocalizeStringLiterals(IEnumerable<CodeInstruction> instructions)
		{
			foreach (CodeInstruction instruction in instructions)
			{
				if (instruction.opcode == OpCodes.Ldstr && instruction.operand is string && UiText.TryGetValue((string)instruction.operand, out var value))
				{
					instruction.operand = value;
				}
				yield return instruction;
			}
		}

		private void ApplyTranslations()
		{
			SkillDef[] array = Resources.FindObjectsOfTypeAll<SkillDef>();
			foreach (SkillDef val in array)
			{
				if (!((Object)(object)val == (Object)null) && !string.IsNullOrEmpty(val.skillName) && Translations.TryGetValue(val.skillName, out var value))
				{
					string text = "NORMALAIPEOPLE_GOKU_" + ToTokenSegment(val.skillName);
					AddToken(text + "_NAME", value.Name);
					AddToken(text + "_DESCRIPTION", value.Description);
					val.skillNameToken = text + "_NAME";
					val.skillDescriptionToken = text + "_DESCRIPTION";
				}
			}
		}

		private void AddToken(string token, string chinese)
		{
			if (registeredTokens.Add(token))
			{
				LanguageAPI.Add(token, chinese, "zh-CN");
			}
		}

		private static string ToTokenSegment(string value)
		{
			char[] array = new char[value.Length];
			for (int i = 0; i < value.Length; i++)
			{
				char c = value[i];
				array[i] = (char.IsLetterOrDigit(c) ? char.ToUpperInvariant(c) : '_');
			}
			return new string(array);
		}
	}
}