Decompiled source of ChineseFontPatch v1.0.2

BepInEx/plugins/ChineseFontPatch.dll

Decompiled 7 months ago
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("ChineseFontPatch")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ChineseFontPatch")]
[assembly: AssemblyTitle("ChineseFontPatch")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ChineseFontPatch;

[BepInPlugin("ChineseFontPatch", "Chinese Font Patch", "1.0")]
public class ChineseFontPatch : BaseUnityPlugin
{
	public static TMP_FontAsset s_font;

	public static float c_outline;

	private void Awake()
	{
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		string text = Path.Combine(Paths.PluginPath, ((BaseUnityPlugin)this).Config.Bind<string>("General", "Font Asset", "FontAsset-SIMYOU", "The font asset located in plugins folder.").Value);
		AssetBundle val = AssetBundle.LoadFromFile(text);
		if ((Object)(object)val == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Missing AssetBundle: " + text));
		}
		else
		{
			s_font = val.LoadAsset<TMP_FontAsset>(((BaseUnityPlugin)this).Config.Bind<string>("General", "Font Name", "Arial SDF", "The name of font included in font asset.").Value);
			((BaseUnityPlugin)this).Logger.LogDebug((object)("AssetBundle loaded: " + text + "\nFont loaded: " + ((Object)s_font).name));
		}
		c_outline = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Font Outline", 0.1f, "The outline width of font.").Value;
		new Harmony("ChineseFontPatch").PatchAll(typeof(TextMeshProUGUIPatch));
	}
}
internal class TextMeshProUGUIPatch
{
	[HarmonyPatch(typeof(TextMeshProUGUI), "SetLayoutDirty")]
	[HarmonyPostfix]
	private static void TMPEnablePatch(TextMeshProUGUI __instance, CanvasRenderer ___m_canvasRenderer)
	{
		if ((Object)(object)__instance != (Object)null && (Object)(object)ChineseFontPatch.s_font != (Object)null)
		{
			if (!((TMP_Text)__instance).font.fallbackFontAssetTable.Contains(ChineseFontPatch.s_font))
			{
				((TMP_Text)__instance).font.fallbackFontAssetTable.Add(ChineseFontPatch.s_font);
			}
			if ((Object)(object)___m_canvasRenderer != (Object)null)
			{
				((TMP_Text)__instance).outlineWidth = ChineseFontPatch.c_outline;
			}
		}
	}
}