Decompiled source of Font Recycler v1.0.1

FontRecycler.dll

Decompiled 6 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using On.RoR2.UI;
using R2API.Utils;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2.UI;
using TMPro;
using UnityEngine;
using UnityEngine.AddressableAssets;

[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("FontRecycler")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FontRecycler")]
[assembly: AssemblyTitle("FontRecycler")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace FontRecycler;

[BepInDependency("com.bepis.r2api", "5.0.10")]
[BepInPlugin("com.brynzananas.fontrecycler", "Font Recycler", "1.0.1")]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
public class FontRecycler : BaseUnityPlugin
{
	public const string ModGuid = "com.brynzananas.fontrecycler";

	public const string ModName = "Font Recycler";

	public const string ModVer = "1.0.1";

	public static ConfigEntry<int> FontType;

	public static ConfigEntry<bool> MaterialOverride;

	public static ConfigEntry<float> Dilate;

	public static ConfigEntry<Color> TextColor;

	public static ConfigEntry<float> Outline;

	public static ConfigEntry<Color> OutlineColor;

	public static TMP_FontAsset Font1;

	public static TMP_FontAsset Font2;

	public static TMP_FontAsset Font3;

	public static TMP_FontAsset Font4;

	public static TMP_FontAsset Font5;

	public static TMP_FontAsset Font7;

	public static TMP_FontAsset Font8;

	public static TMP_FontAsset Font6;

	public TMP_FontAsset currentFont;

	public Material currentFontMaterial;

	public void Awake()
	{
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: Expected O, but got Unknown
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b8: Expected O, but got Unknown
		//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bd: Expected O, but got Unknown
		//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Expected O, but got Unknown
		//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dd: Expected O, but got Unknown
		//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ed: Expected O, but got Unknown
		//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fd: Expected O, but got Unknown
		//IL_0203: Unknown result type (might be due to invalid IL or missing references)
		//IL_020d: Expected O, but got Unknown
		FontType = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Font", 1, "1: NotoSans\n2: Bombardier\n3: Bazaronite\n4: Risk Of Rain\n5: SquaresBold\n6: Traceroute\n7: LiberationSans\n8: Chronic Expansion");
		MaterialOverride = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Material Override", false, "Enable this to override font material properties");
		Dilate = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Dilate", 0.2f, "Control face dilate");
		TextColor = ((BaseUnityPlugin)this).Config.Bind<Color>("General", "Font Color", Color.white, "Control font text color");
		Outline = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Outline", 0.2f, "Control outline thickness");
		OutlineColor = ((BaseUnityPlugin)this).Config.Bind<Color>("General", "Outline Color", Color.black, "Control outline text color");
		Font1 = Addressables.LoadAssetAsync<TMP_FontAsset>((object)"RoR2/Base/Common/Fonts/Noto/NotoSans-Regular SDF(ROOT Extended ASCII + Turkish).asset").WaitForCompletion();
		Font2 = Addressables.LoadAssetAsync<TMP_FontAsset>((object)"RoR2/Base/Common/Fonts/Bombardier/tmpBombDropshadow.asset").WaitForCompletion();
		Font3 = Addressables.LoadAssetAsync<TMP_FontAsset>((object)"RoR2/Base/Common/Fonts/Bazaronite/tmpBazaroniteSDF.asset").WaitForCompletion();
		Font4 = Addressables.LoadAssetAsync<TMP_FontAsset>((object)"RoR2/Base/Common/Fonts/RiskofRain/tmpRiskofRainFont Bold OutlineSDF.asset").WaitForCompletion();
		Font5 = Addressables.LoadAssetAsync<TMP_FontAsset>((object)"RoR2/Base/Common/Fonts/SquaresBold/tmpSquaresBold.asset").WaitForCompletion();
		Font6 = Addressables.LoadAssetAsync<TMP_FontAsset>((object)"RoR2/Base/Common/Fonts/Traceroute/tmpTRACER__ SDF.asset").WaitForCompletion();
		Font7 = Addressables.LoadAssetAsync<TMP_FontAsset>((object)"TextMesh Pro/FormerResources/Fonts & Materials/LiberationSans SDF - Fallback.asset").WaitForCompletion();
		Font8 = Addressables.LoadAssetAsync<TMP_FontAsset>((object)"RoR2/DLC2/Items/IncreaseDamageOnMultiKill/tmpCounter.asset").WaitForCompletion();
		HGTextMeshProUGUI.Awake += new hook_Awake(HGTextMeshProUGUI_Awake);
		ModSettingsManager.AddOption((BaseOption)new IntSliderOption(FontType, new IntSliderConfig
		{
			min = 1,
			max = 8
		}));
		ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(MaterialOverride));
		ModSettingsManager.AddOption((BaseOption)new FloatFieldOption(Dilate));
		ModSettingsManager.AddOption((BaseOption)new ColorOption(TextColor));
		ModSettingsManager.AddOption((BaseOption)new FloatFieldOption(Outline));
		ModSettingsManager.AddOption((BaseOption)new ColorOption(OutlineColor));
		FontType.SettingChanged += FontType_SettingChanged;
		MaterialOverride.SettingChanged += EXtraChangesLol;
		TextColor.SettingChanged += EXtraChangesLol;
		Outline.SettingChanged += EXtraChangesLol;
		OutlineColor.SettingChanged += EXtraChangesLol;
		Dilate.SettingChanged += EXtraChangesLol;
	}

	private void HGTextMeshProUGUI_Awake(orig_Awake orig, HGTextMeshProUGUI self)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		orig.Invoke(self);
		TMP_FontAsset val = Addressables.LoadAssetAsync<TMP_FontAsset>((object)"RoR2/Base/Common/Fonts/Noto/NotoSans-Regular SDF(ROOT Extended ASCII + Turkish).asset").WaitForCompletion();
		val = (TMP_FontAsset)(FontType.Value switch
		{
			1 => Font1, 
			2 => Font2, 
			3 => Font3, 
			4 => Font4, 
			5 => Font5, 
			6 => Font6, 
			7 => Font7, 
			8 => Font8, 
			_ => Font1, 
		});
		currentFont = Object.Instantiate<TMP_FontAsset>(val);
		currentFontMaterial = Object.Instantiate<Material>(((TMP_Asset)val).material);
		currentFontMaterial.SetColor("_FaceColor", TextColor.Value);
		currentFontMaterial.SetFloat("_OutlineWidth", Outline.Value);
		currentFontMaterial.SetColor("_OutlineColor", OutlineColor.Value);
		currentFontMaterial.SetFloat("_FaceDilate", Dilate.Value);
		if (MaterialOverride.Value)
		{
			((TMP_Asset)currentFont).material = currentFontMaterial;
		}
		((TMP_Text)self).font = currentFont;
		((TextMeshProUGUI)self).UpdateFontAsset();
	}

	private void EXtraChangesLol(object sender, EventArgs e)
	{
		if (FontType.Value < 5)
		{
			ConfigEntry<int> fontType = FontType;
			int value = fontType.Value;
			fontType.Value = value + 1;
			ConfigEntry<int> fontType2 = FontType;
			value = fontType2.Value;
			fontType2.Value = value - 1;
		}
		else
		{
			ConfigEntry<int> fontType3 = FontType;
			int value = fontType3.Value;
			fontType3.Value = value - 1;
			ConfigEntry<int> fontType4 = FontType;
			value = fontType4.Value;
			fontType4.Value = value + 1;
		}
	}

	private void FontType_SettingChanged(object sender, EventArgs e)
	{
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)currentFont != (Object)null)
		{
			Object.Destroy((Object)(object)currentFont);
		}
		if ((Object)(object)currentFontMaterial != (Object)null)
		{
			try
			{
				Object.Destroy((Object)(object)currentFontMaterial);
			}
			catch
			{
			}
		}
		TMP_FontAsset font = Font1;
		font = (TMP_FontAsset)(FontType.Value switch
		{
			1 => Font1, 
			2 => Font2, 
			3 => Font3, 
			4 => Font4, 
			5 => Font5, 
			6 => Font6, 
			7 => Font7, 
			8 => Font8, 
			_ => Font1, 
		});
		currentFont = Object.Instantiate<TMP_FontAsset>(font);
		currentFontMaterial = Object.Instantiate<Material>(((TMP_Asset)font).material);
		currentFontMaterial.SetColor("_FaceColor", TextColor.Value);
		currentFontMaterial.SetFloat("_OutlineWidth", Outline.Value);
		currentFontMaterial.SetColor("_OutlineColor", OutlineColor.Value);
		currentFontMaterial.SetFloat("_FaceDilate", Dilate.Value);
		if (MaterialOverride.Value)
		{
			((TMP_Asset)currentFont).material = currentFontMaterial;
		}
		HGTextMeshProUGUI[] array = Object.FindObjectsOfType<HGTextMeshProUGUI>();
		HGTextMeshProUGUI[] array2 = array;
		foreach (HGTextMeshProUGUI val in array2)
		{
			((TMP_Text)val).font = currentFont;
			((TextMeshProUGUI)val).UpdateFontAsset();
		}
	}
}