Decompiled source of Risk of Rain 2 Ukrainian v1.4.7

plugins/Risk_of_Rain_2_Ukrainian.dll

Decompiled 2 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 BepInEx;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using MonoMod.RuntimeDetour;
using On.RoR2;
using On.RoR2.UI;
using RoR2;
using RoR2.UI;
using TMPro;
using UnityEngine;

[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("Risk_of_Rain_2_Ukrainian")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Adds UA localization to Risk of Rain 2 and mods")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+3be9312624a1301550407e68d5df62a7ef219d5b")]
[assembly: AssemblyProduct("Risk_of_Rain_2_Ukrainian")]
[assembly: AssemblyTitle("Risk_of_Rain_2_Ukrainian")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 Risk_of_Rain_2_Ukrainian
{
	public class FontManager
	{
		public static AssetBundle assetBundle = AssetBundle.LoadFromStream(Assembly.GetExecutingAssembly().GetManifestResourceStream("Risk_of_Rain_2_Ukrainian.ukrainianfont"));

		public static TMP_FontAsset fontBomb;

		public static TMP_FontAsset fontBombDefault;

		public static TMP_FontAsset fontDamage;

		public static TMP_FontAsset fontDamageDefault;

		public FontManager()
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			fontBomb = assetBundle.LoadAsset<TMP_FontAsset>("Assets/BOMBARD+Ukrainian.asset");
			fontBombDefault = Resources.Load<TMP_FontAsset>("TmpFonts/Bombardier/tmpBombDropShadow");
			fontDamageDefault = ((TMP_Text)((Component)Resources.Load<GameObject>("Prefabs/Effects/BearProc").transform.Find("TextCamScaler/TextRiser/TextMeshPro")).gameObject.GetComponent<TextMeshPro>()).font;
			HGTextMeshProUGUI.OnCurrentLanguageChanged += new hook_OnCurrentLanguageChanged(HGTextMeshProUGUI_OnCurrentLanguageChanged);
			new Hook((MethodBase)typeof(TextMeshProUGUI).GetMethod("LoadFontAsset", (BindingFlags)(-1)), (Delegate)(Action<Action<TextMeshProUGUI>, TextMeshProUGUI>)delegate(Action<TextMeshProUGUI> orig, TextMeshProUGUI self)
			{
				orig(self);
				if ((Object)(object)((TMP_Text)self).font == (Object)(object)fontBombDefault)
				{
					((TMP_Text)self).font = fontBomb;
				}
			});
		}

		public void HGTextMeshProUGUI_OnCurrentLanguageChanged(orig_OnCurrentLanguageChanged orig)
		{
			orig.Invoke();
			if (Object.op_Implicit((Object)(object)fontBomb))
			{
				HGTextMeshProUGUI.defaultLanguageFont = fontBomb;
			}
		}
	}
	public class GrammaticalGenderManager
	{
		public const string FemaleGenderToken = "<жр>";

		public const string UaLangName = "uk";

		public HashSet<string> FemaleGenderTokensCollection = new HashSet<string>();

		public GrammaticalGenderManager()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			Language.LoadAllTokensFromFolder += new hook_LoadAllTokensFromFolder(LanguageOnLoadAllTokensFromFolder);
			Util.GetBestBodyName += new hook_GetBestBodyName(UtilOnGetBestBodyName);
		}

		private void LanguageOnLoadAllTokensFromFolder(orig_LoadAllTokensFromFolder orig, string folder, List<KeyValuePair<string, string>> output)
		{
			if (!folder.StartsWith(RiskOfRain2UaPlugin.LocationDir))
			{
				orig.Invoke(folder, output);
				return;
			}
			List<KeyValuePair<string, string>> list = new List<KeyValuePair<string, string>>(3500);
			orig.Invoke(folder, list);
			for (int i = 0; i < list.Count; i++)
			{
				KeyValuePair<string, string> keyValuePair = list[i];
				if (keyValuePair.Value.StartsWith("<жр>"))
				{
					list[i] = new KeyValuePair<string, string>(keyValuePair.Key, keyValuePair.Value.Substring("<жр>".Length));
					FemaleGenderTokensCollection.Add(keyValuePair.Key);
				}
			}
			RiskOfRain2UaPlugin.Log.LogInfo((object)$"Found {FemaleGenderTokensCollection.Count} grammatical female gender tokens.");
			output.AddRange(list);
		}

		private string UtilOnGetBestBodyName(orig_GetBestBodyName orig, GameObject bodyObject)
		{
			if (!Language.currentLanguage.name.Equals("uk", StringComparison.OrdinalIgnoreCase))
			{
				return orig.Invoke(bodyObject);
			}
			return CustomGetBestBodyNameImpl(bodyObject);
		}

		private string CustomGetBestBodyNameImpl(GameObject bodyObject)
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			CharacterBody val = null;
			string text = "???";
			bool isGrammaticallyFemale = false;
			if (Object.op_Implicit((Object)(object)bodyObject))
			{
				val = bodyObject.GetComponent<CharacterBody>();
			}
			if (Object.op_Implicit((Object)(object)val))
			{
				text = val.GetUserName();
				if (FemaleGenderTokensCollection.Contains(val.baseNameToken))
				{
					isGrammaticallyFemale = true;
				}
			}
			else
			{
				IDisplayNameProvider component = bodyObject.GetComponent<IDisplayNameProvider>();
				if (component != null)
				{
					text = component.GetDisplayName();
				}
			}
			string text2 = text;
			if (Object.op_Implicit((Object)(object)val))
			{
				if (val.isElite)
				{
					BuffIndex[] eliteBuffIndices = BuffCatalog.eliteBuffIndices;
					foreach (BuffIndex val2 in eliteBuffIndices)
					{
						if (val.HasBuff(val2))
						{
							string modifierToken = BuffCatalog.GetBuffDef(val2).eliteDef.modifierToken;
							text2 = GetStringFormatted(modifierToken, isGrammaticallyFemale, text2);
						}
					}
				}
				if (Object.op_Implicit((Object)(object)val.inventory))
				{
					if (val.inventory.GetItemCount(Items.InvadingDoppelganger) > 0)
					{
						text2 = GetStringFormatted("BODY_MODIFIER_DOPPELGANGER", isGrammaticallyFemale, text2);
					}
					if (val.inventory.GetItemCount(Items.GummyCloneIdentifier) > 0)
					{
						text2 = GetStringFormatted("BODY_MODIFIER_GUMMYCLONE", isGrammaticallyFemale, text2);
					}
				}
			}
			return text2;
		}

		private string GetStringFormatted(string token, bool isGrammaticallyFemale, params object[] args)
		{
			if (isGrammaticallyFemale)
			{
				string text = token + "__F";
				if (Language.currentLanguage.TokenIsRegistered(text))
				{
					token = text;
				}
			}
			return Language.GetStringFormatted(token, args);
		}
	}
	[BepInPlugin("Risk_of_Rain_2_Ukrainian", "Risk_of_Rain_2_Ukrainian", "1.0.0")]
	public class RiskOfRain2UaPlugin : BaseUnityPlugin
	{
		public static RiskOfRain2UaPlugin Instance;

		public static string LocationDir;

		public GrammaticalGenderManager GrammaticalGenderManager;

		public FontManager FontManager;

		public static ManualLogSource Log => ((BaseUnityPlugin)Instance).Logger;

		private void Awake()
		{
			Instance = this;
			LocationDir = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			Language.collectLanguageRootFolders += LanguageOnCollectLanguageRootFolders;
			GrammaticalGenderManager = new GrammaticalGenderManager();
			FontManager = new FontManager();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Risk_of_Rain_2_Ukrainian is loaded!");
		}

		private void LanguageOnCollectLanguageRootFolders(List<string> folders)
		{
			folders.Add(Path.Combine(LocationDir, "Localization"));
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Risk_of_Rain_2_Ukrainian";

		public const string PLUGIN_NAME = "Risk_of_Rain_2_Ukrainian";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}