Decompiled source of REPO Russian Translation v1.0.6

BepInEx/plugins/Repo Russian Translation/RTLC Font Replacer.dll

Decompiled a month ago
using System;
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 HarmonyLib;
using Microsoft.CodeAnalysis;
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: AssemblyCompany("LeKAKiD")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Replace in-game font with other things")]
[assembly: AssemblyFileVersion("1.2.4.0")]
[assembly: AssemblyInformationalVersion("1.2.4+d5fa67705b60c049a3e31d66d30cc939edaa91fb")]
[assembly: AssemblyProduct("FontPatcher")]
[assembly: AssemblyTitle("FontPatcher")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.4.0")]
[module: UnverifiableCode]
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 A_1)
		{
			Version = A_1;
		}
	}
}
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace RTLC
{
	[HarmonyPatch]
	internal class FontLoader
	{
		private static TMP_FontAsset s_RussianFont;

		public static void Load()
		{
			try
			{
				string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
				string text = Path.Combine(directoryName, "repobundle");
				if (!File.Exists(text))
				{
					Plugin.LogError("Файл шрифтов не найден по пути: " + text);
					return;
				}
				AssetBundle val = AssetBundle.LoadFromFile(text);
				if ((Object)(object)val == (Object)null)
				{
					Plugin.LogError("Не удалось загрузить бандл шрифтов (файл может быть повреждён)");
					return;
				}
				s_RussianFont = val.LoadAsset<TMP_FontAsset>("TekoRus");
				val.Unload(false);
				if ((Object)(object)s_RussianFont == (Object)null)
				{
					Plugin.LogError("Шрифт 'TekoRus' не найден в бандле");
					return;
				}
				((Object)s_RussianFont).name = "RTLC_Russian";
				Plugin.LogInfo("Русский шрифт успешно загружен: " + ((Object)s_RussianFont).name);
			}
			catch (Exception arg)
			{
				Plugin.LogError($"КРИТИЧЕСКАЯ ОШИБКА: {arg}");
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(TMP_FontAsset), "Awake")]
		private static void PatchFontAwake(TMP_FontAsset __instance)
		{
			if (!((Object)(object)__instance == (Object)null) && !((Object)(object)((TMP_Asset)__instance).material == (Object)null) && !((Object)(object)s_RussianFont == (Object)null))
			{
				((TMP_Asset)__instance).material.SetFloat("_UnderlayDilate", 1f);
				((TMP_Asset)__instance).material.SetFloat("_UnderlayOffsetX", 0.1f);
				if (!__instance.fallbackFontAssetTable.Contains(s_RussianFont))
				{
					__instance.fallbackFontAssetTable.Add(s_RussianFont);
					Plugin.LogInfo("Добавлен русский шрифт к резервным шрифтам " + ((Object)__instance).name);
				}
			}
		}
	}
	[BepInPlugin("rtlc.repo.russian", "RTLC Russian Translate", "1.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static Plugin Instance;

		private void Awake()
		{
			Instance = this;
			string text = "\r\n  _____ _____ _      _____ \r\n |  __ \\_   _| |    / ____|\r\n | |__) || | | |   | |     \r\n |  _  / | | | |   | |     \r\n | | \\ \\_| |_| |___| |____ \r\n |_|  \\_\\_____|______\\_____|\r\n            Russian Translate\r\n";
			((BaseUnityPlugin)this).Logger.LogMessage((object)text);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"[RTLC] Инициализация русских шрифтов...");
			try
			{
				FontLoader.Load();
				Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"[RTLC] Шрифты успешно подключены!");
			}
			catch (Exception arg)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)$"[RTLC] Ошибка инициализации: {arg}");
			}
		}

		public static void LogInfo(string msg)
		{
			((BaseUnityPlugin)Instance).Logger.LogInfo((object)msg);
		}

		public static void LogError(string msg)
		{
			((BaseUnityPlugin)Instance).Logger.LogError((object)msg);
		}
	}
}