Decompiled source of FontFixer v1.0.0

FontFixer.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 BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("EliteMasterEric")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Replaces the in-game font with an expanded version with support for more characters.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FontFixer")]
[assembly: AssemblyTitle("FontFixer")]
[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 FontFixer
{
	public static class PluginInfo
	{
		public const string PLUGIN_ID = "FontFixer";

		public const string PLUGIN_NAME = "FontFixer";

		public const string PLUGIN_VERSION = "1.0.0";

		public const string PLUGIN_GUID = "com.elitemastereric.fontfixer";
	}
	[BepInPlugin("com.elitemastereric.fontfixer", "FontFixer", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string IBM_3270_FONT_NAME = "IBM 3270";

		private const string IBM_3270_TMP_PATH = "assets/_Custom/FontFix/IBM 3270.asset";

		private const string IBM_3270_OTF_PATH = "assets/_Custom/FontFix/IBM 3270.otf";

		private const string UNIFONT_TMP_PATH = "assets/_Custom/FontFix/Unifont.asset";

		private const string UNIFONT_OTF_PATH = "assets/_Custom/FontFix/Unifont.otf";

		public ManualLogSource PluginLogger;

		public AssetBundle assetBundle;

		private TMP_FontAsset font_IBM3270;

		private TMP_FontAsset font_Unifont;

		public static Plugin Instance { get; private set; }

		private void Awake()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			Instance = this;
			PluginLogger = ((BaseUnityPlugin)this).Logger;
			Harmony val = new Harmony("com.elitemastereric.fontfixer");
			val.PatchAll();
			PluginLogger.LogInfo((object)"Plugin FontFixer (com.elitemastereric.fontfixer) is loaded!");
			LoadAssetBundle();
			ApplyFallbackFont();
		}

		private void LoadAssetBundle()
		{
			string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "fontfixer.bundle");
			assetBundle = AssetBundle.LoadFromFile(text);
		}

		private void ApplyFallbackFont()
		{
			TMP_FontAsset globalFallbackFont = GetGlobalFallbackFont();
			if ((Object)(object)globalFallbackFont != (Object)null)
			{
				TMP_Settings.fallbackFontAssets.Add(globalFallbackFont);
			}
		}

		public TMP_FontAsset GetGlobalFallbackFont()
		{
			if ((Object)(object)font_Unifont != (Object)null)
			{
				return font_Unifont;
			}
			if ((Object)(object)assetBundle == (Object)null)
			{
				PluginLogger.LogError((object)"Could not retrieve global fallback font, asset bundle is null");
				return null;
			}
			font_Unifont = assetBundle.LoadAsset<TMP_FontAsset>("assets/_Custom/FontFix/Unifont.asset");
			if ((Object)(object)font_Unifont == (Object)null)
			{
				PluginLogger.LogError((object)"Could not retrieve global fallback font, font asset is null");
				return null;
			}
			return font_Unifont;
		}

		public TMP_FontAsset GetFont_IBM3270()
		{
			if ((Object)(object)font_IBM3270 != (Object)null)
			{
				return font_IBM3270;
			}
			if ((Object)(object)assetBundle == (Object)null)
			{
				PluginLogger.LogError((object)"Could not retrieve IBM 3270 font, asset bundle is null");
				return null;
			}
			font_IBM3270 = assetBundle.LoadAsset<TMP_FontAsset>("assets/_Custom/FontFix/IBM 3270.asset");
			if ((Object)(object)font_IBM3270 == (Object)null)
			{
				PluginLogger.LogError((object)"Could not retrieve IBM 3270 font, font asset is null");
				return null;
			}
			return font_IBM3270;
		}
	}
}
namespace FontFixer.Patch
{
	[HarmonyPatch(typeof(TextMeshProUGUI), "Awake")]
	internal class LagScanPatch
	{
		[HarmonyPostfix]
		public static void Postfix(TextMeshProUGUI __instance)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			FaceInfo faceInfo = ((TMP_Text)__instance).font.faceInfo;
			if (((FaceInfo)(ref faceInfo)).familyName == "IBM 3270")
			{
				Plugin.Instance.PluginLogger.LogInfo((object)("Applying custom font to " + ((Object)__instance).name + "."));
				TMP_FontAsset font_IBM = Plugin.Instance.GetFont_IBM3270();
				((TMP_Text)__instance).font = font_IBM;
				return;
			}
			TMP_FontAsset globalFallbackFont = Plugin.Instance.GetGlobalFallbackFont();
			Plugin.Instance.PluginLogger.LogInfo((object)("Injecting fallback font to " + ((Object)__instance).name + "."));
			if (((TMP_Text)__instance).font.fallbackFontAssetTable == null)
			{
				((TMP_Text)__instance).font.fallbackFontAssetTable = new List<TMP_FontAsset> { globalFallbackFont };
			}
			else if (!((TMP_Text)__instance).font.fallbackFontAssetTable.Contains(globalFallbackFont))
			{
				((TMP_Text)__instance).font.fallbackFontAssetTable.Add(globalFallbackFont);
			}
		}
	}
}