Decompiled source of Vegeta Chinese Package v1.3.0

VegetaChinesePackage.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.VegetaChinesePackage
{
	[BepInPlugin("normalaipeople.vegeta.chinese.package", "Vegeta Chinese Package", "1.3.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class VegetaChinesePackagePlugin : 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.vegeta.chinese.package";

		public const string PluginName = "Vegeta Chinese Package";

		public const string PluginVersion = "1.3.0";

		private const string TokenPrefix = "NORMALAIPEOPLE_VEGETA_";

		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", "超级赛亚人" },
			{ "Ascended Super Saiyan", "超越超级赛亚人" },
			{ "Super Saiyan 2", "超级赛亚人2" },
			{ "Super Saiyan 3", "超级赛亚人3" },
			{ "Super Saiyan 4", "超级赛亚人4" },
			{ "Super Saiyan God", "超级赛亚人之神" },
			{ "Super Saiyan God 3", "超级赛亚人之神3" },
			{ "Super Saiyan Blue", "超级赛亚人蓝" },
			{ "Super Saiyan Blue 3", "超级赛亚人蓝3" },
			{ "Super Saiyan Blue Evolved", "超级赛亚人蓝进化" },
			{ "Super Saiyan Blue Evolved 3", "超级赛亚人蓝进化3" },
			{ "Kaioken None", "未启用界王拳" },
			{ "All Forms unlocked", "全部形态已解锁" },
			{ "Mastered", "已精通" },
			{ " until next unlock", "后解锁下一形态" },
			{ " Mastery level", "级精通等级" },
			{ "Saiyan Blood", "赛亚人血统" },
			{ "Main 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).\n", "(更多信息请见“变身”页)。\n" },
			{ " by tapping ", "以" },
			{ " by holding ", "以" },
			{ "\nConcentrate and rapidly fire Ki Blasts, Dealing ", "\n凝聚并快速发射气弹,造成" },
			{ " with each one!\n", "伤害/发!\n" },
			{ "Holding this skill drains ", "按住技能会每秒消耗" },
			{ " Ki ", "气" },
			{ "per second.", "。" },
			{ "\nStrike and launch enemies upwards, dealing ", "\n上挑并击飞敌人,造成" },
			{ "!\nHolding the button follows-up with an additional downward strike, knocking-down enemies and dealing ", "!\n按住按钮会接续下砸,击倒敌人并造成" },
			{ "\nGenerate immense power to fire an energy wave upwards, dealing ", "\n积蓄庞大能量并向上发射能量波,造成" },
			{ " per second whilst the blast is active!\nConsume additional Ki and increase damage by ", "每秒伤害。光束持续期间消耗额外气,并使伤害每秒提高" },
			{ " and size per second of charging!\n", "及范围!\n" },
			{ "Ki consumption gradually increases the longer you charge!", "蓄力越久,气的消耗越高!" },
			{ "\nCharge and unleash a Galick Gun, Dealing ", "\n蓄力并释放伽力克炮,造成" },
			{ " per second whilst the blast is active! \nConsume additional Ki and increase damage by ", "每秒伤害。光束持续期间消耗额外气,并使伤害每秒提高" },
			{ " per second of charging!\n", "!\n" },
			{ "\nUnleash an explosive ball of energy! \nExplodes on hit, Dealing ", "\n释放爆炸性能源球!命中时爆炸,造成" },
			{ "\nRelease a massively expanding explosion, Dealing ", "\n释放急速扩张的大爆炸,造成" },
			{ " and\ndraining ", "伤害,并消耗" },
			{ "% of Max Ki", "%最大气" },
			{ " per second!\n", "每秒!\n" },
			{ "Once Ki reaches 0, Health is drained instead, Can be fatal...", "气耗尽后将改为消耗生命,可能致命……" },
			{ "\nCharge up and unleash a devastating Final Flash, Dealing ", "\n蓄力并释放毁灭性的终极闪光,造成" },
			{ "\nUnleash a powerful Final Shine Attack, Dealing ", "\n释放强力终极闪光炮,造成" },
			{ "Once Ki reaches 0, Health is drained instead, this version won't kill you...", "气耗尽后将改为消耗生命,但此版本不会致死……" },
			{ "\nPower up and unleash a insanely fast barrage of strikes! \nDealing ", "\n强化后施展极速连击!每一击造成" },
			{ " for each one!\nFinishing it off with a powerful blow, Dealing ", "伤害!最后以强力一击收尾,造成" },
			{ "\nCharge up and unleash a devastating God-level Prominence Flash, Dealing ", "\n蓄力并释放神级闪耀冲击,造成" },
			{ "\nCharge and unleash a Super Galick Gun, Dealing ", "\n蓄力并释放超级伽力克炮,造成" },
			{ "None", "无" }
		};

		private static readonly Dictionary<string, Translation> Translations = new Dictionary<string, Translation>(StringComparer.Ordinal)
		{
			{
				"Melee Strike",
				new Translation("近战打击", "以近战连击攻击敌人。")
			},
			{
				"Continuous Energy Blast",
				new Translation("连续能量弹", "凝聚并快速发射气弹,每发造成伤害。按住技能会持续消耗<style=cIsHealing>气</style>。")
			},
			{
				"Rising Sledgehammer",
				new Translation("升龙重锤", "上挑并击飞敌人;按住按钮可接续下砸,将敌人击倒。")
			},
			{
				"Empowered Ki Charge",
				new Translation("强化气力充能", "凝聚<style=cIsHealing>气</style>并获得强化状态。")
			},
			{
				"Galick Gun",
				new Translation("伽力克炮", "蓄力后释放伽力克炮。持续蓄力会消耗更多<style=cIsHealing>气</style>并提高伤害。")
			},
			{
				"Galaxy Breaker",
				new Translation("银河破坏者", "积蓄庞大能量后向上发射能量波。蓄力会提高伤害和范围,并持续消耗<style=cIsHealing>气</style>。")
			},
			{
				"Final Flash",
				new Translation("终极闪光", "蓄力后释放毁灭性的终极闪光,对路径上的敌人造成持续伤害。")
			},
			{
				"Prominence Flash",
				new Translation("闪耀冲击", "蓄力后释放神级闪耀冲击,对路径上的敌人造成持续伤害。")
			},
			{
				"Final Shine Attack",
				new Translation("终极闪光炮", "释放强力终极闪光炮,对路径上的敌人造成持续伤害。")
			},
			{
				"Big Bang Attack",
				new Translation("大爆炸攻击", "释放爆炸性能源球,命中时爆炸。")
			},
			{
				"Final Explosion",
				new Translation("终极爆炸", "释放不断扩张的爆炸,持续消耗气;气耗尽后会消耗生命。")
			},
			{
				"Full Power Final Explosion",
				new Translation("全力终极爆炸", "释放更强的终极爆炸;气耗尽后会改为消耗生命,但不会致死。")
			},
			{
				"Niagra Pummel",
				new Translation("尼亚加拉连打", "施展极速连续打击,最后以强力一击收尾。")
			},
			{
				"Niagara Pummel",
				new Translation("尼亚加拉连打", "施展极速连续打击,最后以强力一击收尾。")
			},
			{
				"Super Galick Gun",
				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.vegeta.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_Vegeta.VegetaTransformationData", "GetTransformationSkillName");
			Patch(harmony, "NS_Vegeta.VegetaTransformationHandler", "OnTransformedFirstTime");
			Patch(harmony, "NS_Vegeta.UI_Majin", "DrawElement");
			string[] array = new string[11]
			{
				"NS_KingModUtilities.TSuperSaiyan", "NS_KingModUtilities.TAscendedSuperSaiyan", "NS_KingModUtilities.TSuperSaiyan2", "NS_KingModUtilities.TSuperSaiyan3", "NS_KingModUtilities.TSuperSaiyan4", "NS_KingModUtilities.TSuperSaiyanGod", "NS_KingModUtilities.TSuperSaiyanGod3", "NS_KingModUtilities.TSuperSaiyanBlue", "NS_KingModUtilities.TSuperSaiyanBlue3", "NS_KingModUtilities.TSuperSaiyanBlueEvolved",
				"NS_KingModUtilities.TSuperSaiyanBlueEvolved3"
			};
			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(VegetaChinesePackagePlugin), "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_VEGETA_" + 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);
		}
	}
}