Decompiled source of PEAK Russian Translation v2.0.1

BepInEx/plugins/RTLC Font Replacer/FontReplacer_PEAK.dll

Decompiled a week ago
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.TextCore;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("FontReplacer_PEAK")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FontReplacer_PEAK")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e7c7e0e7-7bf0-4a45-9778-1961b5bd7f51")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("ru.RTLC.fontreplacer", "FontReplacer", "1.0.0")]
public class FontReplacer : BaseUnityPlugin
{
	public static TMP_FontAsset newFontTextMeshPro;

	private void Awake()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)"FontReplacer запущен!");
		LoadFontFromAssetBundle();
		Harmony.CreateAndPatchAll(typeof(FontReplacer), (string)null);
	}

	private void LoadFontFromAssetBundle()
	{
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
		string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "peakbundle");
		if (!File.Exists(text))
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Bundle не найден: " + text));
			return;
		}
		AssetBundle val = AssetBundle.LoadFromFile(text);
		if ((Object)(object)val == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"Ошибка загрузки AssetBundle!");
			return;
		}
		Font val2 = null;
		Font[] array = val.LoadAllAssets<Font>();
		int num = 0;
		if (num < array.Length)
		{
			Font val3 = array[num];
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Нашли Font: " + ((Object)val3).name));
			val2 = val3;
		}
		if ((Object)(object)val2 == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"Font не найден в bundle!");
			return;
		}
		newFontTextMeshPro = TMP_FontAsset.CreateFontAsset(val2);
		FaceInfo faceInfo = ((TMP_Asset)newFontTextMeshPro).faceInfo;
		((FaceInfo)(ref faceInfo)).familyName = "DarumaDropOne";
		((FaceInfo)(ref faceInfo)).styleName = "Regular";
		((FaceInfo)(ref faceInfo)).pointSize = 56f;
		((FaceInfo)(ref faceInfo)).scale = 0.95f;
		((FaceInfo)(ref faceInfo)).lineHeight = 56.65f;
		((FaceInfo)(ref faceInfo)).ascentLine = 55.2f;
		((FaceInfo)(ref faceInfo)).capLine = 39.06f;
		((FaceInfo)(ref faceInfo)).meanLine = 30.32f;
		((FaceInfo)(ref faceInfo)).baseline = 0f;
		((FaceInfo)(ref faceInfo)).descentLine = -13.12f;
		((FaceInfo)(ref faceInfo)).superscriptOffset = 56.65f;
		((FaceInfo)(ref faceInfo)).subscriptOffset = -6.8f;
		((FaceInfo)(ref faceInfo)).underlineOffset = -7.8f;
		((FaceInfo)(ref faceInfo)).underlineThickness = 3.19f;
		((FaceInfo)(ref faceInfo)).strikethroughOffset = 13.6f;
		((FaceInfo)(ref faceInfo)).strikethroughThickness = 2.24f;
		((FaceInfo)(ref faceInfo)).tabWidth = 15f;
		((TMP_Asset)newFontTextMeshPro).faceInfo = faceInfo;
		((BaseUnityPlugin)this).Logger.LogInfo((object)("TMP_FontAsset создан из Font: " + ((Object)val2).name));
		val.Unload(false);
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(TextMeshProUGUI), "OnEnable")]
	public static void OV_TextMeshProUGUI_OnEnable(TextMeshProUGUI __instance)
	{
		if ((Object)(object)newFontTextMeshPro != (Object)null && (Object)(object)((TMP_Text)__instance).font != (Object)(object)newFontTextMeshPro)
		{
			((TMP_Text)__instance).font = newFontTextMeshPro;
			((TMP_Text)__instance).lineSpacing = ((TMP_Text)__instance).lineSpacing + 24f;
		}
	}
}