Decompiled source of YapYap FontAPI v1.0.0

Jettcodey.FontAPI.dll

Decompiled 6 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
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.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Jettcodey.FontAPI")]
[assembly: AssemblyDescription("Mod for Replacing the Vanilla Font for YAPYAP! Developed by Jettcodey.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Jettcodey")]
[assembly: AssemblyProduct("Jettcodey.FontAPI")]
[assembly: AssemblyCopyright("Copyright © Jettcodey 2026")]
[assembly: ComVisible(false)]
[assembly: Guid("935163b2-93b4-4176-88a7-29ca6775c875")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 Jettcodey.FontAPI
{
	[BepInPlugin("Jettcodey.FontAPI", "FontAPI", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private Harmony _harmony;

		public static Plugin Instance { get; private set; }

		internal static ManualLogSource? Logger { get; private set; }

		private void Awake()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Object.DontDestroyOnLoad((Object)((Component)this).gameObject);
			Logger = ((BaseUnityPlugin)this).Logger;
			_harmony = new Harmony("Jettcodey.FontAPI");
			_harmony.PatchAll(typeof(FontPatches));
			Logger.LogInfo((object)"Plugin FontAPI v1.0.0 loaded successfully.");
			Logger.LogInfo((object)"FontAPI Loaded. Waiting for mods to register fonts...");
		}
	}
	public static class FontAPI
	{
		internal static Shader? ValidGameShader;

		internal static TMP_FontAsset? CurrentReplacement { get; private set; }

		public static void SetFont(TMP_FontAsset font)
		{
			if ((Object)(object)font == (Object)null)
			{
				Plugin.Logger.LogError((object)"You can not set 'Null' as Font.");
				return;
			}
			Object.DontDestroyOnLoad((Object)(object)font);
			CurrentReplacement = font;
			if ((Object)(object)ValidGameShader != (Object)null)
			{
				ApplyShaderFix(CurrentReplacement);
			}
			Plugin.Logger.LogInfo((object)("Active font set to " + ((Object)font).name));
		}

		public static void LoadAssetAndSet(AssetBundle bundle, string assetName)
		{
			if (!((Object)(object)bundle == (Object)null))
			{
				TMP_FontAsset val = bundle.LoadAsset<TMP_FontAsset>(assetName);
				if ((Object)(object)val != (Object)null)
				{
					SetFont(val);
				}
			}
		}

		internal static void ApplyShaderFix(TMP_FontAsset font)
		{
			if (!((Object)(object)ValidGameShader == (Object)null) && !((Object)(object)font == (Object)null) && !((Object)(object)((TMP_Asset)font).material == (Object)null) && (Object)(object)((TMP_Asset)font).material.shader != (Object)(object)ValidGameShader)
			{
				((TMP_Asset)font).material.shader = ValidGameShader;
				((TMP_Asset)font).material.mainTexture = (Texture)(object)font.atlasTexture;
			}
		}
	}
	public static class FontPatches
	{
		[HarmonyPatch(typeof(TextMeshProUGUI), "OnEnable")]
		[HarmonyPostfix]
		public static void PatchUI(TextMeshProUGUI __instance)
		{
			ApplyReplacement((TMP_Text)(object)__instance);
		}

		[HarmonyPatch(typeof(TextMeshPro), "OnEnable")]
		[HarmonyPostfix]
		public static void PatchWorld(TextMeshPro __instance)
		{
			ApplyReplacement((TMP_Text)(object)__instance);
		}

		private static void ApplyReplacement(TMP_Text textObj)
		{
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Expected O, but got Unknown
			TMP_FontAsset currentReplacement = FontAPI.CurrentReplacement;
			if ((Object)(object)currentReplacement == (Object)null || (Object)(object)textObj == (Object)null)
			{
				return;
			}
			if ((Object)(object)FontAPI.ValidGameShader == (Object)null && (Object)(object)textObj.font != (Object)null && (Object)(object)textObj.font != (Object)(object)currentReplacement && (Object)(object)((TMP_Asset)textObj.font).material != (Object)null)
			{
				FontAPI.ValidGameShader = ((TMP_Asset)textObj.font).material.shader;
				Plugin.Logger.LogInfo((object)("Harvested valid shader: " + ((Object)FontAPI.ValidGameShader).name));
				FontAPI.ApplyShaderFix(currentReplacement);
			}
			if ((Object)(object)((TMP_Asset)currentReplacement).material == (Object)null && (Object)(object)textObj.font != (Object)null && (Object)(object)((TMP_Asset)textObj.font).material != (Object)null)
			{
				Material val = new Material(((TMP_Asset)textObj.font).material);
				val.mainTexture = (Texture)(object)currentReplacement.atlasTexture;
				((TMP_Asset)currentReplacement).material = val;
				FontAPI.ValidGameShader = val.shader;
			}
			if ((Object)(object)textObj.font != (Object)(object)currentReplacement)
			{
				textObj.font = currentReplacement;
				if ((Object)(object)((TMP_Asset)currentReplacement).material != (Object)null)
				{
					textObj.fontMaterial = ((TMP_Asset)currentReplacement).material;
				}
				((Graphic)textObj).SetAllDirty();
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Jettcodey.FontAPI";

		public const string PLUGIN_NAME = "FontAPI";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}