using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
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("I18NFont4UnityGame")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("I18NFont4UnityGame")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("908ca800-1e6c-4956-a429-5abed633f5f1")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.1", FrameworkDisplayName = ".NET Framework 4.7.1")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace xiaoye97;
[BepInPlugin("xiaoye97.I18NFont4UnityGame", "I18NFont4UnityGame", "1.0")]
public class I18NFont4UnityGame : BaseUnityPlugin
{
public static I18NFont4UnityGame Inst;
public static Font TranslateFont;
public static TMP_FontAsset TMPTranslateFont;
public static ConfigEntry<string> FontName;
private void Start()
{
Inst = this;
FontName = ((BaseUnityPlugin)this).Config.Bind<string>("config", "FontName", "unifont", "put font package to <GameName>/BepInEx/plugins/Sallys_Workshop-I18NFont4UnityGame");
LoadFont(FontName.Value);
Harmony.CreateAndPatchAll(typeof(I18NFont4UnityGame), (string)null);
((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded I18NFont4UnityGame Plugin.");
}
public void LoadFont(string fontName)
{
try
{
string text = Paths.PluginPath + "/Sallys_Workshop-I18NFont4UnityGame/" + fontName;
if (File.Exists(text))
{
AssetBundle val = AssetBundle.LoadFromFile(text);
TranslateFont = val.LoadAsset<Font>(fontName);
TMPTranslateFont = val.LoadAsset<TMP_FontAsset>(fontName + " SDF");
if ((Object)(object)TranslateFont != (Object)null && (Object)(object)TMPTranslateFont != (Object)null)
{
((BaseUnityPlugin)this).Logger.LogInfo((object)("Loaded " + fontName + "."));
}
else
{
((BaseUnityPlugin)this).Logger.LogError((object)"The font file is damaged. Please check the file.");
}
val.Unload(false);
}
else
{
((BaseUnityPlugin)this).Logger.LogError((object)("Font " + fontName + " not found, Please check the path: " + text));
}
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)("Load font exception:" + ex.Message + "\n" + ex.StackTrace));
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Text), "OnEnable")]
public static void FontPatch(Text __instance)
{
if (((Object)__instance.font).name != ((Object)TranslateFont).name)
{
__instance.font = TranslateFont;
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(TextMeshProUGUI), "OnEnable")]
public static void TMPFontPatch(TextMeshProUGUI __instance)
{
if (((Object)((TMP_Text)__instance).font).name != ((Object)TMPTranslateFont).name)
{
((TMP_Text)__instance).font = TMPTranslateFont;
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(TextMeshProUGUI), "InternalUpdate")]
public static void TMPFontPatch2(TextMeshProUGUI __instance)
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Invalid comparison between Unknown and I4
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)((TMP_Text)__instance).font == (Object)(object)TMPTranslateFont && (int)((TMP_Text)__instance).overflowMode > 0 && ((TMP_Text)__instance).preferredWidth > 1f)
{
Bounds bounds = ((TMP_Text)__instance).bounds;
if (((Bounds)(ref bounds)).extents == Vector3.zero)
{
((TMP_Text)__instance).overflowMode = (TextOverflowModes)0;
}
}
}
}