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.Configuration;
using BepInEx.Logging;
using JaggyFontFix;
using Microsoft.CodeAnalysis;
using On.RoR2;
using On.RoR2.UI;
using RoR2;
using RoR2.UI;
using TMPro;
using UnityEngine;
using UnityEngine.TextCore;
using UnityEngine.TextCore.LowLevel;
[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("JaggyFontFix")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+fa65383ba8b7def0e029b386951773974abd70a4")]
[assembly: AssemblyProduct("JaggyFontFix")]
[assembly: AssemblyTitle("JaggyFontFix")]
[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;
}
}
}
public static class FontAssets
{
public static AssetBundle mainBundle;
public const string bundleName = "zh_font";
public static string AssetBundlePath => Path.Combine(Path.GetDirectoryName(global::JaggyFontFix.JaggyFontFix.PInfo.Location), "zh_font");
public static void Init()
{
mainBundle = AssetBundle.LoadFromFile(AssetBundlePath);
Log.Info(((Object)mainBundle).name + " bundle loaded.");
}
}
namespace JaggyFontFix
{
[BepInPlugin("xykle.JaggyFontFix", "JaggyFontFix", "1.3.0")]
public class JaggyFontFix : BaseUnityPlugin
{
public const string PluginGUID = "xykle.JaggyFontFix";
public const string PluginAuthor = "xykle";
public const string PluginName = "JaggyFontFix";
public const string PluginVersion = "1.3.0";
private TMP_FontAsset fontAsset;
public static PluginInfo PInfo { get; private set; }
public static ConfigEntry<bool> KeepEnglishFont { get; set; }
public static ConfigEntry<UseFontName> UseFontNameConfig { get; set; }
public static ConfigEntry<string> CustomFontFileNameConfig { get; set; }
public static ConfigEntry<int> FontPointSize { get; set; }
public static ConfigEntry<float> FontSizeScale { get; set; }
public static ConfigEntry<float> EnglishFontSizeScale { get; set; }
private void Init()
{
PInfo = ((BaseUnityPlugin)this).Info;
Log.Init(((BaseUnityPlugin)this).Logger);
FontAssets.Init();
ConfigurationInit();
}
private void ConfigurationInit()
{
UseFontNameConfig = ((BaseUnityPlugin)this).Config.Bind<UseFontName>("Font Settings", "Font Name", UseFontName.NotoSans, "Set which font will use in game. If you want use custom font, set this to \"Custom\".");
CustomFontFileNameConfig = ((BaseUnityPlugin)this).Config.Bind<string>("Font Settings", "Custom Font File Name", "font.ttf", "Set custom font file name that you wanna use in game. Only work when \"Font Name\" set to \"Custom\".\nYou NEED to put your font file under this plugin folder, path to font file is not supported.\nFile extension is optional.");
KeepEnglishFont = ((BaseUnityPlugin)this).Config.Bind<bool>("Font Settings(Advanced)", "Keep English Font", false, "Set vanilla English font (Bombardier) as primary font. Might cause inconsistent font sizes.");
FontPointSize = ((BaseUnityPlugin)this).Config.Bind<int>("Font Settings(Advanced)", "Font Sampling Point Size", 90, "The size that characters in font texture.\nGreater will be less jaggier, but might cause missing character and increase file size.");
FontSizeScale = ((BaseUnityPlugin)this).Config.Bind<float>("Font Settings(Advanced)", "Font Size Scale", 1f, "Set font scale size.");
EnglishFontSizeScale = ((BaseUnityPlugin)this).Config.Bind<float>("Font Settings(Advanced)", "English Font Size Scale", 1f, "Set vanilla English font (Bombardier) scale size.");
}
public void Awake()
{
Init();
SetFontAsset();
SubcribeEvents();
}
private void OnDestory()
{
UnSubcribeEvents();
}
private void SubcribeEvents()
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Expected O, but got Unknown
HGTextMeshProUGUI.Awake += new hook_Awake(ReplaceHGTextFont);
LanguageTextMeshController.CacheComponents += new hook_CacheComponents(ReplaceTmpControllerFont);
Run.InstantiateUi += new hook_InstantiateUi(ReplaceFontOnStageBegin);
}
private void UnSubcribeEvents()
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Expected O, but got Unknown
HGTextMeshProUGUI.Awake -= new hook_Awake(ReplaceHGTextFont);
LanguageTextMeshController.CacheComponents -= new hook_CacheComponents(ReplaceTmpControllerFont);
Run.InstantiateUi -= new hook_InstantiateUi(ReplaceFontOnStageBegin);
}
private Font LoadFont(UseFontName fontName)
{
Font val = null;
return (Font)(fontName switch
{
UseFontName.TaipeiSans => FontAssets.mainBundle.LoadAsset<Font>("TaipeiSansTCBeta-Regular"),
UseFontName.Cubic11 => FontAssets.mainBundle.LoadAsset<Font>("Cubic_11"),
UseFontName.Custom => FontFromFile(CustomFontFileNameConfig.Value),
UseFontName.Bombardier => FontAssets.mainBundle.LoadAsset<Font>("Bombardier-Regular"),
_ => FontAssets.mainBundle.LoadAsset<Font>("NotoSansCJKsc-Regular"),
});
}
private Font FontFromFile(string fileName)
{
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Expected O, but got Unknown
string text = Path.Combine(Path.GetDirectoryName(PInfo.Location), fileName);
if (!fileName.Contains(".ttf") && !fileName.Contains(".otf"))
{
if (File.Exists(text + ".ttf"))
{
text += ".ttf";
}
else
{
if (!File.Exists(text + ".otf"))
{
Log.Warning("Custom font file not found! Is there any typo or not support format? (Only .ttf and .otf are supported.) Input name: " + fileName);
return FontAssets.mainBundle.LoadAsset<Font>("NotoSansCJKsc-Regular");
}
text += ".otf";
}
}
if (!File.Exists(text))
{
Log.Warning("Custom font file not found! Is there any typo? Input name: " + fileName);
return FontAssets.mainBundle.LoadAsset<Font>("NotoSansCJKsc-Regular");
}
Font result = new Font(text);
Log.Info("Loading \"" + text + "\".");
return result;
}
private GameObject ReplaceFontOnStageBegin(orig_InstantiateUi orig, Run self, Transform uiRoot)
{
GameObject result = orig.Invoke(self, uiRoot);
int num = ReplaceAllFont();
Log.Info($"New stage begun, replace {num} font(s) on scene.");
return result;
}
private void ReplaceTmpControllerFont(orig_CacheComponents orig, LanguageTextMeshController self)
{
orig.Invoke(self);
if (!((Object)(object)self.textMeshPro == (Object)null))
{
self.textMeshPro.font = fontAsset;
}
}
private void ReplaceHGTextFont(orig_Awake orig, HGTextMeshProUGUI self)
{
orig.Invoke(self);
((TMP_Text)self).font = fontAsset;
((TextMeshProUGUI)self).UpdateFontAsset();
}
private int ReplaceAllFont()
{
TMP_Text[] array = Object.FindObjectsByType<TMP_Text>((FindObjectsInactive)1, (FindObjectsSortMode)0);
int num = 0;
TMP_Text[] array2 = array;
foreach (TMP_Text val in array2)
{
if (!((Object)(object)val.font == (Object)(object)fontAsset))
{
val.font = fontAsset;
num++;
}
}
return num;
}
private TMP_FontAsset GenerateFontAsset(UseFontName fontName)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
TMP_FontAsset val = new TMP_FontAsset();
Font val2 = LoadFont(fontName);
Log.Info(((Object)val2).name + " is loaded.");
val = TMP_FontAsset.CreateFontAsset(val2, FontPointSize.Value, 9, (GlyphRenderMode)4165, 4096, 2048, (AtlasPopulationMode)1, true);
FaceInfo faceInfo = val.faceInfo;
((FaceInfo)(ref faceInfo)).scale = ((fontName == UseFontName.Bombardier) ? EnglishFontSizeScale.Value : FontSizeScale.Value);
val.faceInfo = faceInfo;
Material material = ((TMP_Asset)val).material;
material.SetColor("_GlowColor", new Color(1f, 1f, 1f, 0.28627452f));
material.SetFloat("_GlowInner", 0f);
material.SetFloat("_GlowOffset", -0.89f);
material.SetFloat("_GlowOuter", 1f);
material.SetFloat("_GlowPower", 0.186f);
material.EnableKeyword("GLOW_ON");
material.SetColor("_UnderlayColor", new Color(0f, 0f, 0f, 0.6627451f));
material.SetFloat("_UnderlayOffsetX", 1f);
material.SetFloat("_UnderlayOffsetY", -1f);
material.SetFloat("_UnderlayDilate", 1f);
material.SetFloat("_UnderlaySoftness", 0f);
material.EnableKeyword("UNDERLAY_ON");
((TMP_Asset)val).material = material;
return val;
}
private void SetFontAsset()
{
TMP_FontAsset val = GenerateFontAsset(UseFontNameConfig.Value);
List<TMP_FontAsset> list = new List<TMP_FontAsset>();
if (KeepEnglishFont.Value)
{
TMP_FontAsset val2 = GenerateFontAsset(UseFontName.Bombardier);
list.Add(val);
val2.fallbackFontAssetTable = list;
val = val2;
Log.Info("Add font asset to english fallback.");
}
list.Add(GenerateFontAsset(UseFontName.NotoSans));
val.fallbackFontAssetTable = list;
fontAsset = val;
}
}
public enum UseFontName
{
Bombardier = -1,
NotoSans,
TaipeiSans,
Cubic11,
Custom
}
internal static class Log
{
private static ManualLogSource _logSource;
internal static void Init(ManualLogSource logSource)
{
_logSource = logSource;
}
internal static void Debug(object data)
{
_logSource.LogDebug(data);
}
internal static void Error(object data)
{
_logSource.LogError(data);
}
internal static void Fatal(object data)
{
_logSource.LogFatal(data);
}
internal static void Info(object data)
{
_logSource.LogInfo(data);
}
internal static void Message(object data)
{
_logSource.LogMessage(data);
}
internal static void Warning(object data)
{
_logSource.LogWarning(data);
}
}
}