using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ULTRAFONT")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ULTRAFONT")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ba5bebd7-bf01-4342-9173-7a8e393d1c88")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace com.unyki.ultrakill.ultrafont;
[BepInPlugin("com.unyki.ultrakill.ultrafont", "ULTRAFONT", "1.1.7")]
public class FontChanger : BaseUnityPlugin
{
[CompilerGenerated]
private sealed class <InitializeFontSystem>d__7 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public FontChanger <>4__this;
private TMP_Text <defaultText>5__1;
private IEnumerator<string> <>s__2;
private string <file>5__3;
private string <fontName>5__4;
private Font <font>5__5;
private TMP_FontAsset <fontAsset>5__6;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <InitializeFontSystem>d__7(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
int num = <>1__state;
if (num == -3 || num == 2)
{
try
{
}
finally
{
<>m__Finally1();
}
}
<defaultText>5__1 = null;
<>s__2 = null;
<file>5__3 = null;
<fontName>5__4 = null;
<font>5__5 = null;
<fontAsset>5__6 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Expected O, but got Unknown
//IL_0289: Unknown result type (might be due to invalid IL or missing references)
//IL_0293: Expected O, but got Unknown
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
//IL_0142: Expected O, but got Unknown
//IL_018e: Unknown result type (might be due to invalid IL or missing references)
//IL_0198: Expected O, but got Unknown
try
{
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForSeconds(1f);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
<defaultText>5__1 = Resources.FindObjectsOfTypeAll<TMP_Text>().FirstOrDefault();
if ((Object)(object)<defaultText>5__1 != (Object)null)
{
<>4__this.LoadedFonts["Default"] = <defaultText>5__1.font;
}
<>s__2 = (from f in Directory.GetFiles(<>4__this.fontsFolderPath, "*.*", SearchOption.AllDirectories)
where f.ToLower().EndsWith(".ttf") || f.ToLower().EndsWith(".otf")
select f).GetEnumerator();
<>1__state = -3;
break;
case 2:
<>1__state = -3;
<file>5__3 = null;
break;
}
if (<>s__2.MoveNext())
{
<file>5__3 = <>s__2.Current;
try
{
<fontName>5__4 = Path.GetFileNameWithoutExtension(<file>5__3);
if (!<>4__this.LoadedFonts.ContainsKey(<fontName>5__4))
{
<font>5__5 = new Font(<file>5__3);
<fontAsset>5__6 = TMP_FontAsset.CreateFontAsset(<font>5__5);
((Object)<fontAsset>5__6).name = <fontName>5__4;
if ((Object)(object)<defaultText>5__1 != (Object)null)
{
((TMP_Asset)<fontAsset>5__6).material = new Material(((TMP_Asset)<defaultText>5__1.font).material);
((TMP_Asset)<fontAsset>5__6).material.mainTexture = (Texture)(object)<fontAsset>5__6.atlasTexture;
}
<>4__this.LoadedFonts.Add(<fontName>5__4, <fontAsset>5__6);
<>4__this.availableFonts.Add(<fontName>5__4);
<font>5__5 = null;
<fontAsset>5__6 = null;
}
<fontName>5__4 = null;
}
catch
{
}
<>2__current = null;
<>1__state = 2;
return true;
}
<>m__Finally1();
<>s__2 = null;
<>4__this.selectedFontConfig = ((BaseUnityPlugin)<>4__this).Config.Bind<string>("General", "SelectedFont", "Default", new ConfigDescription("Font to use for all text", (AcceptableValueBase)(object)new AcceptableValueList<string>(<>4__this.availableFonts.ToArray()), Array.Empty<object>()));
<>4__this.selectedFontConfig.SettingChanged += <>4__this.OnFontSettingChanged;
<>4__this.ApplyFont();
return false;
}
catch
{
//try-fault
((IDisposable)this).Dispose();
throw;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
private void <>m__Finally1()
{
<>1__state = -1;
if (<>s__2 != null)
{
<>s__2.Dispose();
}
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
private static FontChanger Instance;
private static TMP_FontAsset currentFontAsset;
private string fontsFolderPath;
private readonly List<string> availableFonts = new List<string> { "Default" };
private readonly Dictionary<string, TMP_FontAsset> LoadedFonts = new Dictionary<string, TMP_FontAsset>();
private ConfigEntry<string> selectedFontConfig;
private void Awake()
{
Instance = this;
fontsFolderPath = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "fonts");
if (!Directory.Exists(fontsFolderPath))
{
Directory.CreateDirectory(fontsFolderPath);
}
((MonoBehaviour)this).StartCoroutine(InitializeFontSystem());
SceneManager.sceneLoaded += OnSceneLoaded;
}
[IteratorStateMachine(typeof(<InitializeFontSystem>d__7))]
private IEnumerator InitializeFontSystem()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <InitializeFontSystem>d__7(0)
{
<>4__this = this
};
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
ApplyFont();
}
private void OnFontSettingChanged(object sender, EventArgs e)
{
ApplyFont();
}
private void ApplyFont()
{
if (!LoadedFonts.TryGetValue(selectedFontConfig.Value, out var value))
{
return;
}
currentFontAsset = value;
TMP_Text[] array = Resources.FindObjectsOfTypeAll<TMP_Text>();
foreach (TMP_Text val in array)
{
try
{
if ((Object)(object)val != (Object)null && (Object)(object)val.font != (Object)(object)currentFontAsset)
{
val.font = currentFontAsset;
val.text = val.text;
}
}
catch
{
}
}
}
}