using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyVersion("0.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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; } } } namespace LegacyFontLoadFix { [BepInPlugin("repo.compat.legacyfontloadfix", "LegacyFontLoadFix", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { internal static ManualLogSource Log; private static HashSet _legacyAssets; private static Dictionary _cache; private static MethodInfo _normalizeName; private static MethodInfo _findGameAssetOpen; private void Awake() { //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; try { Type type = Type.GetType("REPOLib.Patches.FontAssetMaterialPatch, REPOLib", throwOnError: false); if (type == null) { Log.LogWarning((object)"REPOLib FontAssetMaterialPatch not found; nothing to do."); return; } _legacyAssets = type.GetField("_legacyAssets", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(null) as HashSet; _cache = type.GetField("_gameAssetCache", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(null) as Dictionary; _normalizeName = type.GetMethod("NormalizeName", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); _findGameAssetOpen = type.GetMethod("FindGameAsset", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); MethodInfo method = type.GetMethod("ReplaceLegacyAssets", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (_legacyAssets == null || _cache == null || _normalizeName == null || _findGameAssetOpen == null || method == null) { Log.LogWarning((object)"REPOLib internals changed (this fix targets REPOLib 4.3.0); not applying."); return; } new Harmony("repo.compat.legacyfontloadfix").Patch((MethodBase)method, new HarmonyMethod(typeof(Plugin).GetMethod("Prefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); Log.LogInfo((object)"Patched REPOLib legacy TMP asset lookup (skips full Resources.LoadAll scan)."); } catch (Exception ex) { Log.LogError((object)("Failed to apply: " + ex)); } } private static void Prefix(TMP_Text __0) { try { if ((Object)(object)__0 == (Object)null || _legacyAssets.Count == 0) { return; } TMP_FontAsset font = __0.font; if ((Object)(object)font != (Object)null && _legacyAssets.Contains((Object)(object)font)) { Seed(((Object)font).name, SafePath(() => TMP_Settings.defaultFontAssetPath)); } TMP_SpriteAsset spriteAsset = __0.spriteAsset; if ((Object)(object)spriteAsset != (Object)null && _legacyAssets.Contains((Object)(object)spriteAsset)) { Seed(((Object)spriteAsset).name, SafePath(() => TMP_Settings.defaultSpriteAssetPath)); } } catch (Exception ex) { Log.LogError((object)("Prefix error (REPOLib will fall back to its own lookup): " + ex.Message)); } } private static string SafePath(Func f) { try { return f(); } catch { return null; } } private static void Seed(string assetName, string tmpResourcesPath) where T : Object { string text = (string)_normalizeName.Invoke(null, new object[1] { assetName }); string key = typeof(T).Name + ":" + text; if (!_cache.ContainsKey(key)) { MethodInfo methodInfo = _findGameAssetOpen.MakeGenericMethod(typeof(T)); T val = (T)methodInfo.Invoke(null, new object[2] { Resources.FindObjectsOfTypeAll(), text }); if ((Object)(object)val == (Object)null && !string.IsNullOrEmpty(tmpResourcesPath)) { val = (T)methodInfo.Invoke(null, new object[2] { Resources.LoadAll(tmpResourcesPath), text }); } _cache[key] = (Object)(object)val; if ((Object)(object)val != (Object)null) { Log.LogInfo((object)("Resolved legacy " + typeof(T).Name + " \"" + assetName + "\" -> \"" + ((Object)val).name + "\" without a full Resources scan.")); } else { Log.LogInfo((object)("No game " + typeof(T).Name + " matches legacy \"" + assetName + "\"; skipped the full Resources.LoadAll scan (avoids a long freeze).")); } } } } }