Decompiled source of FootballZhTW v1.1.1

plugins/FootballZhTW.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using BepInEx;
using HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace FootballZhTW;

[BepInPlugin("com.cutyimodo.footballzhtw", "Football 繁體中文", "1.1.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	private Harmony harmony;

	private static readonly Dictionary<string, string[]> Translations = new Dictionary<string, string[]>
	{
		{
			"SS_START",
			new string[2] { "來玩乖乖聽話", "她說什麼就做什麼 不然你就死定了" }
		},
		{
			"SS_INTRO",
			new string[2] { "乖乖聽話說", "" }
		},
		{
			"SS_INTRO_FAKE",
			new string[2] { "", "" }
		},
		{
			"SS_END_WINNER",
			new string[2] { "你贏了 算你厲害", "" }
		},
		{
			"SS_END_LOSER",
			new string[2] { "你輸了", "" }
		},
		{
			"SS_GIGGLE",
			new string[2] { "", "" }
		},
		{
			"SS_ACT_JUMP",
			new string[2] { "跳", "跳起來" }
		},
		{
			"SS_ACT_CROUCH",
			new string[2] { "蹲下", "蹲下來" }
		},
		{
			"SS_ACT_DANCE",
			new string[2] { "跳舞", "按表情鍵跳舞" }
		},
		{
			"SS_ACT_POINT",
			new string[2] { "比", "對著某個方向比" }
		},
		{
			"SS_ACT_LOOK_UP",
			new string[2] { "往上看", "抬頭看上面" }
		},
		{
			"SS_ACT_DONT_MOVE",
			new string[2] { "不准動", "站在原地不要動 {0}秒" }
		},
		{
			"SS_ACT_DONT_SPEAK",
			new string[2] { "閉嘴", "不准說話 {0}秒" }
		},
		{
			"SS_ACT_DONT_STOP_RUNNING",
			new string[2] { "不准停下來", "一直跑 不准停 {0}秒" }
		},
		{
			"SS_ACT_SPIN",
			new string[2] { "轉圈", "原地轉一圈" }
		},
		{
			"SS_ACT_PULL_SHIP_LEVER",
			new string[2] { "拉船桿", "去拉飛船的起飛桿" }
		},
		{
			"SS_ACT_HIT_PLAYER",
			new string[2] { "打人", "用鏟子打另一個玩家" }
		},
		{
			"SS_ACT_KILL_PLAYER",
			new string[2] { "殺人", "殺死另一個玩家" }
		},
		{
			"SS_ACT_FIND_ME",
			new string[2] { "來找我", "走到我身邊" }
		}
	};

	private void Awake()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Expected O, but got Unknown
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Expected O, but got Unknown
		harmony = new Harmony("com.cutyimodo.footballzhtw");
		Type type = null;
		Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
		foreach (Assembly assembly in assemblies)
		{
			type = assembly.GetType("Kittenji.FootballEntity.Language.Lang");
			if (type != null)
			{
				break;
			}
		}
		if (type == null)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"Football Language type not found.");
			return;
		}
		MethodInfo method = type.GetMethod("Get", new Type[1] { typeof(string) });
		if (method != null)
		{
			harmony.Patch((MethodBase)method, (HarmonyMethod)null, new HarmonyMethod(typeof(LangPatch).GetMethod("PostfixGet", BindingFlags.Static | BindingFlags.Public)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
		MethodInfo method2 = type.GetMethod("Get", new Type[2]
		{
			typeof(string),
			typeof(string)
		});
		if (method2 != null)
		{
			harmony.Patch((MethodBase)method2, (HarmonyMethod)null, new HarmonyMethod(typeof(LangPatch).GetMethod("PostfixGet2", BindingFlags.Static | BindingFlags.Public)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Football 繁體中文 v1.1.1 loaded — 19 keys patched");
	}

	private void OnDestroy()
	{
		Harmony obj = harmony;
		if (obj != null)
		{
			obj.UnpatchSelf();
		}
	}

	public static Dictionary<string, string[]> GetTranslations()
	{
		return Translations;
	}
}
public static class LangPatch
{
	public static void PostfixGet(string key, object __result)
	{
		Apply(key, __result);
	}

	public static void PostfixGet2(string key, object __result)
	{
		Apply(key, __result);
	}

	private static void Apply(string key, object token)
	{
		if (token == null || string.IsNullOrEmpty(key))
		{
			return;
		}
		Dictionary<string, string[]> translations = Plugin.GetTranslations();
		if (!translations.ContainsKey(key))
		{
			return;
		}
		string[] array = translations[key];
		Type type = token.GetType();
		BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public;
		if (!string.IsNullOrEmpty(array[0]))
		{
			MemberInfo memberInfo = (MemberInfo)(((object)type.GetField("Text", bindingAttr)) ?? ((object)type.GetProperty("Text", bindingAttr)));
			if (memberInfo is FieldInfo fieldInfo)
			{
				fieldInfo.SetValue(token, array[0]);
			}
			else if (memberInfo is PropertyInfo propertyInfo)
			{
				propertyInfo.SetValue(token, array[0]);
			}
		}
		if (array.Length <= 1 || string.IsNullOrEmpty(array[1]))
		{
			return;
		}
		MemberInfo memberInfo2 = (MemberInfo)(((object)type.GetField("Info", bindingAttr)) ?? ((object)type.GetProperty("Info", bindingAttr)));
		if (!(memberInfo2 != null))
		{
			return;
		}
		string text = array[1];
		if (text.Contains("{0}"))
		{
			string text2 = null;
			if (memberInfo2 is FieldInfo fieldInfo2)
			{
				text2 = fieldInfo2.GetValue(token) as string;
			}
			else if (memberInfo2 is PropertyInfo propertyInfo2)
			{
				text2 = propertyInfo2.GetValue(token) as string;
			}
			if (!string.IsNullOrEmpty(text2))
			{
				Match match = Regex.Match(text2, "\\d+");
				if (match.Success)
				{
					text = text.Replace("{0}", match.Value);
				}
			}
		}
		if (memberInfo2 is FieldInfo fieldInfo3)
		{
			fieldInfo3.SetValue(token, text);
		}
		else if (memberInfo2 is PropertyInfo propertyInfo3)
		{
			propertyInfo3.SetValue(token, text);
		}
	}
}