Decompiled source of MoreTranslations German SoU v0.8.5

MoreTranslations.dll

Decompiled 11 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("MoreTranslations")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("MoreTranslations")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1")]
[assembly: AssemblyProduct("MoreTranslations")]
[assembly: AssemblyTitle("MoreTranslations")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.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 MoreTranslations
{
	[BepInPlugin("MoreTranslations_DontTouchFranky", "MoreTranslations", "1.1.1")]
	public class Plugin : BaseUnityPlugin
	{
		private static Dictionary<string, Dictionary<string, string>> TextStrings;

		private static Dictionary<string, Dictionary<string, string>> TextKeynotes;

		private static TMP_Dropdown languagesDropdown = null;

		private static string selectedLanguage = null;

		private static List<string> languages = new List<string>();

		private static List<string> tips = new List<string>();

		private static TMP_FontAsset alternativeFont = null;

		private void Awake()
		{
			Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
		}

		[HarmonyPatch(typeof(TextMeshPro), "OnEnable")]
		[HarmonyPostfix]
		public static void FontPatchTMPText(TextMeshPro __instance)
		{
			if ((Object)(object)alternativeFont != (Object)null)
			{
				((TMP_Text)__instance).font.fallbackFontAssetTable = new List<TMP_FontAsset> { alternativeFont };
			}
		}

		[HarmonyPatch(typeof(GameManager), "Start")]
		[HarmonyPrefix]
		private static void Start()
		{
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Expected O, but got Unknown
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Expected O, but got Unknown
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Expected O, but got Unknown
			string pluginPath = Paths.PluginPath;
			selectedLanguage = PlayerPrefs.GetString("linguaSelezionata");
			string text = pluginPath;
			text = ((!(selectedLanguage.ToLower() == "jp") && !(selectedLanguage.ToLower() == "japanese") && !(selectedLanguage.ToLower() == "russian") && !(selectedLanguage.ToLower() == "ru")) ? (text + "/CantoraOne-Regular Fix.ttf") : (text + "/NotoSerifJP-Regular.otf"));
			if (File.Exists(text))
			{
				Font val = new Font(text);
				TMP_FontAsset val2 = TMP_FontAsset.CreateFontAsset(val);
				if ((Object)(object)val2 != (Object)null)
				{
					alternativeFont = val2;
				}
			}
			TextStrings = new Dictionary<string, Dictionary<string, string>>(StringComparer.OrdinalIgnoreCase);
			TextKeynotes = new Dictionary<string, Dictionary<string, string>>(StringComparer.OrdinalIgnoreCase);
			if (selectedLanguage != "")
			{
				Debug.Log((object)("MoreTranslations | Selected -> " + selectedLanguage));
				TextStrings[selectedLanguage] = new Dictionary<string, string>();
				TextKeynotes[selectedLanguage] = new Dictionary<string, string>();
			}
			else
			{
				Debug.Log((object)"MoreTranslations | Selected -> Default");
			}
			CreateLanguageDropdown();
			GetTranslationLanguages();
			if (selectedLanguage != "" && !languages.Contains(selectedLanguage))
			{
				selectedLanguage = "";
				PlayerPrefs.SetString("linguaSelezionata", selectedLanguage);
			}
			languagesDropdown.options.Add(new OptionData("Default"));
			foreach (string language in languages)
			{
				languagesDropdown.options.Add(new OptionData(Capitalize(language.ToLower())));
			}
			if (selectedLanguage == "")
			{
				languagesDropdown.value = 0;
			}
			else
			{
				languagesDropdown.value = languagesDropdown.options.FindIndex((OptionData x) => x.text.ToLower() == selectedLanguage.ToLower());
			}
			((UnityEvent<int>)(object)languagesDropdown.onValueChanged).AddListener((UnityAction<int>)delegate(int value)
			{
				string text2 = languagesDropdown.options[value].text;
				if (text2 == "Default")
				{
					text2 = "";
				}
				PlayerPrefs.SetString("linguaSelezionata", text2.ToLower());
				AlertManager.Instance.AlertConfirm(Texts.Instance.GetText("selectLanguageChanged", ""), "");
			});
		}

		private static void CreateLanguageDropdown()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			TMP_Dropdown languageDropdown = SettingsManager.Instance.languageDropdown;
			TMP_Dropdown val = Object.Instantiate<TMP_Dropdown>(languageDropdown, ((Component)languageDropdown).transform.parent);
			((Component)val).transform.SetSiblingIndex(((Component)languageDropdown).transform.GetSiblingIndex() + 1);
			((Object)val).name = "languageDropdown2";
			((UnityEventBase)val.onValueChanged).RemoveAllListeners();
			val.onValueChanged = new DropdownEvent();
			RectTransform component = ((Component)val).GetComponent<RectTransform>();
			Rect rect = component.rect;
			double num = ((Rect)(ref rect)).width;
			component.anchoredPosition = new Vector2((float)((double)component.anchoredPosition.x + num + 10.0), component.anchoredPosition.y);
			val.ClearOptions();
			languagesDropdown = val;
		}

		private static void GetTranslationLanguages()
		{
			string[] directories = Directory.GetDirectories(Paths.PluginPath);
			string[] array = directories;
			foreach (string path in array)
			{
				string path2 = Path.Combine(path, "moretranslations.txt");
				if (!File.Exists(path2))
				{
					continue;
				}
				string[] array2 = File.ReadAllLines(path2);
				string[] array3 = array2;
				foreach (string text in array3)
				{
					if (!text.StartsWith("#"))
					{
						string item = text.Trim().ToLower();
						if (!languages.Contains(item))
						{
							languages.Add(item);
						}
					}
				}
			}
			if (languages.Count > 0)
			{
				Debug.Log((object)"MoreTranslations | Languages found:");
				{
					foreach (string language in languages)
					{
						Debug.Log((object)("MoreTranslations | - " + language));
					}
					return;
				}
			}
			Debug.LogWarning((object)"MoreTranslations | No languages found. Please install a language pack to use this plugin.");
		}

		private static string Capitalize(string str)
		{
			if (str == null || str.Length < 1)
			{
				return str;
			}
			return char.ToUpper(str[0]) + str.Substring(1);
		}

		[HarmonyPatch(typeof(Texts), "GetText")]
		[HarmonyPrefix]
		private static bool GetTextPrefix(string _id, string _type, ref string __result)
		{
			__result = "";
			if ((Object)(object)Globals.Instance == (Object)null || !GameManager.Instance.PrefsLoaded)
			{
				__result = "";
				return false;
			}
			string text = _id.Replace(" ", "").ToLower();
			if (!(text != ""))
			{
				__result = "";
				return false;
			}
			if (TextStrings != null && TextStrings.ContainsKey(selectedLanguage))
			{
				if (_type != "")
				{
					text = _type.ToLower() + "_" + text.ToLower();
				}
				if (TextStrings[selectedLanguage].ContainsKey(text))
				{
					string text2 = TextStrings[selectedLanguage][text];
					if (text2 != "")
					{
						__result = text2;
						return false;
					}
				}
			}
			return true;
		}

		[HarmonyPatch(typeof(Texts), "LoadTranslationText")]
		[HarmonyPostfix]
		private static void LoadTranslationTextPostfix(string type)
		{
			if (tips.Count > 0)
			{
				Texts.Instance.TipsList.Clear();
				Texts.Instance.TipsList.AddRange(tips);
			}
		}

		[HarmonyPatch(typeof(Texts), "LoadTranslationText")]
		[HarmonyPrefix]
		private static void LoadTranslationTextPrefix(string type)
		{
			if (!(selectedLanguage != ""))
			{
				return;
			}
			string pluginPath = Paths.PluginPath;
			string text = "";
			string[] directories = Directory.GetDirectories(pluginPath);
			string[] array = directories;
			foreach (string text2 in array)
			{
				string path = text2 + "/moretranslations.txt";
				if (!File.Exists(path))
				{
					continue;
				}
				string[] array2 = File.ReadAllLines(path);
				string[] array3 = array2;
				foreach (string text3 in array3)
				{
					if (!text3.StartsWith("#"))
					{
						string text4 = text3.Trim().ToLower();
						if (text4 == selectedLanguage)
						{
							text = text2 + "/";
						}
					}
				}
			}
			if (!(text != ""))
			{
				return;
			}
			string text5 = "";
			string[] array4 = null;
			type = type.ToLower();
			switch (type)
			{
			case "":
				text5 = text + "/" + selectedLanguage + ".txt";
				if (File.Exists(text5))
				{
					array4 = File.ReadAllLines(text5);
				}
				break;
			case "keynotes":
				text5 = text + "/" + selectedLanguage + "_keynotes.txt";
				if (File.Exists(text5))
				{
					array4 = File.ReadAllLines(text5);
				}
				break;
			case "traits":
				text5 = text + "/" + selectedLanguage + "_traits.txt";
				if (File.Exists(text5))
				{
					array4 = File.ReadAllLines(text5);
				}
				break;
			case "auracurse":
				text5 = text + "/" + selectedLanguage + "_auracurse.txt";
				if (File.Exists(text5))
				{
					array4 = File.ReadAllLines(text5);
				}
				break;
			case "events":
				text5 = text + "/" + selectedLanguage + "_events.txt";
				if (File.Exists(text5))
				{
					array4 = File.ReadAllLines(text5);
				}
				break;
			case "nodes":
				text5 = text + "/" + selectedLanguage + "_nodes.txt";
				if (File.Exists(text5))
				{
					array4 = File.ReadAllLines(text5);
				}
				break;
			case "cards":
				text5 = text + "/" + selectedLanguage + "_cards.txt";
				if (File.Exists(text5))
				{
					array4 = File.ReadAllLines(text5);
				}
				break;
			case "fluff":
				text5 = text + "/" + selectedLanguage + "_cardsfluff.txt";
				if (File.Exists(text5))
				{
					array4 = File.ReadAllLines(text5);
				}
				break;
			case "class":
				text5 = text + "/" + selectedLanguage + "_class.txt";
				if (File.Exists(text5))
				{
					array4 = File.ReadAllLines(text5);
				}
				break;
			case "monsters":
				text5 = text + "/" + selectedLanguage + "_monsters.txt";
				if (File.Exists(text5))
				{
					array4 = File.ReadAllLines(text5);
				}
				break;
			case "requirements":
				text5 = text + "/" + selectedLanguage + "_requirements.txt";
				if (File.Exists(text5))
				{
					array4 = File.ReadAllLines(text5);
				}
				break;
			case "tips":
				text5 = text + "/" + selectedLanguage + "_tips.txt";
				if (File.Exists(text5))
				{
					array4 = File.ReadAllLines(text5);
				}
				break;
			}
			if (array4 == null)
			{
				return;
			}
			List<string> list = new List<string>(array4);
			int num = 0;
			StringBuilder stringBuilder = new StringBuilder();
			StringBuilder stringBuilder2 = new StringBuilder();
			for (int k = 0; k < list.Count; k++)
			{
				string text6 = list[k];
				if (text6 == "" || text6[0] == '#')
				{
					continue;
				}
				string[] array5 = text6.Trim().Split(new char[1] { '=' }, 2);
				if (array5 == null || array5.Length < 2)
				{
					continue;
				}
				array5[0] = array5[0].Trim().ToLower();
				array5[1] = Functions.SplitString("//", array5[1])[0].Trim();
				switch (type)
				{
				case "keynotes":
					stringBuilder.Append("keynotes_");
					break;
				case "traits":
					stringBuilder.Append("traits_");
					break;
				case "auracurse":
					stringBuilder.Append("auracurse_");
					break;
				case "events":
					stringBuilder.Append("events_");
					break;
				case "nodes":
					stringBuilder.Append("nodes_");
					break;
				case "cards":
				case "fluff":
					stringBuilder.Append("cards_");
					break;
				case "class":
					stringBuilder.Append("class_");
					break;
				case "monsters":
					stringBuilder.Append("monsters_");
					break;
				case "requirements":
					stringBuilder.Append("requirements_");
					break;
				case "tips":
					stringBuilder.Append("tips_");
					break;
				}
				stringBuilder.Append(array5[0]);
				if (TextStrings[selectedLanguage].ContainsKey(stringBuilder.ToString()))
				{
					TextStrings[selectedLanguage][stringBuilder.ToString()] = array5[1];
				}
				else
				{
					TextStrings[selectedLanguage].Add(stringBuilder.ToString(), array5[1]);
				}
				if (type == "tips")
				{
					tips.Add(array5[1]);
				}
				bool flag = true;
				switch (type)
				{
				case "":
					if (array5[1].StartsWith("rptd_", StringComparison.OrdinalIgnoreCase))
					{
						stringBuilder2.Append(array5[1].Substring(5).ToLower());
						TextStrings[selectedLanguage][stringBuilder.ToString()] = TextStrings[selectedLanguage][stringBuilder2.ToString()];
						flag = false;
						stringBuilder2.Clear();
					}
					break;
				case "events":
					if (array5[1].StartsWith("rptd_", StringComparison.OrdinalIgnoreCase))
					{
						stringBuilder2.Append("events_");
						stringBuilder2.Append(array5[1].Substring(5).ToLower());
						TextStrings[selectedLanguage][stringBuilder.ToString()] = TextStrings[selectedLanguage][stringBuilder2.ToString()];
						flag = false;
						stringBuilder2.Clear();
					}
					break;
				case "cards":
					if (array5[1].StartsWith("rptd_", StringComparison.OrdinalIgnoreCase))
					{
						stringBuilder2.Append("cards_");
						stringBuilder2.Append(array5[1].Substring(5).ToLower());
						TextStrings[selectedLanguage][stringBuilder.ToString()] = TextStrings[selectedLanguage][stringBuilder2.ToString()];
						flag = false;
						stringBuilder2.Clear();
					}
					break;
				case "monsters":
					if (array5[1].StartsWith("rptd_", StringComparison.OrdinalIgnoreCase))
					{
						stringBuilder2.Append("monsters_");
						stringBuilder2.Append(array5[1].Substring(5).ToLower());
						TextStrings[selectedLanguage][stringBuilder.ToString()] = TextStrings[selectedLanguage][stringBuilder2.ToString()];
						flag = false;
						stringBuilder2.Clear();
					}
					break;
				}
				if (flag)
				{
					string text7 = Regex.Replace(Regex.Replace(array5[1], "<(.*?)>", ""), "\\s+", " ");
					num += text7.Split(' ').Length;
				}
				stringBuilder.Clear();
			}
		}

		public static void ExportEnglishTextForTranslation()
		{
			ActualExport("en");
			ActualExport("en_keynotes");
			ActualExport("en_traits");
			ActualExport("en_auracurse");
			ActualExport("en_events");
			ActualExport("en_nodes");
			ActualExport("en_cards");
			ActualExport("en_cardsfluff");
			ActualExport("en_class");
			ActualExport("en_monsters");
			ActualExport("en_requirements");
			ActualExport("en_tips");
			File.WriteAllText(Path.Combine(Paths.PluginPath, "MoreTranslations_Export", "moretranslations.txt"), "English");
		}

		public static void ActualExport(string fileName)
		{
			Debug.Log((object)("Exporting " + fileName));
			Object obj = Resources.Load("Lang/" + fileName);
			TextAsset val = (TextAsset)(object)((obj is TextAsset) ? obj : null);
			DirectoryInfo directoryInfo = new DirectoryInfo(Path.Combine(Paths.PluginPath, "MoreTranslations_Export"));
			if (!directoryInfo.Exists)
			{
				directoryInfo.Create();
			}
			File.WriteAllText(Path.Combine(Paths.PluginPath, "MoreTranslations_Export", ((fileName == "en") ? "English" : fileName.Replace("en_", "English_")) + ".txt"), ((object)val).ToString());
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "MoreTranslations";

		public const string PLUGIN_NAME = "MoreTranslations";

		public const string PLUGIN_VERSION = "1.1.1";
	}
}