Decompiled source of ItemBundles and Stronghold Fix v1.0.1

patchers/ItemBundlesCompat.Patcher.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Collections.Generic;

[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 ItemBundlesCompat
{
	public static class Patcher
	{
		private static readonly ManualLogSource Log = Logger.CreateLogSource("ItemBundlesCompat");

		public static IEnumerable<string> TargetDLLs => new string[1] { "Assembly-CSharp.dll" };

		public static void Patch(AssemblyDefinition asm)
		{
			ModuleDefinition module = asm.MainModule;
			int num = 0;
			num += Try("PhysGrabObjectImpactDetector.DestroyObject(bool)", () => AddDestroyObject(module));
			num += Try("InputManager.InputDisplayGet(InputKey, MenuKeybind.KeyType, MovementDirection)", () => AddInputDisplayGet(module));
			num += Try("PhysGrabber.ReleaseObjectRPC(bool, float, int, PhotonMessageInfo)", () => AddReleaseObjectRPC(module));
			Log.LogInfo((object)("Added " + num + "/3 compatibility methods for ItemBundles."));
			int num2 = 0;
			num2 += Try("PlayerHealth.Hurt(int, bool, int)", () => AddPrefixShim(module, "PlayerHealth", "Hurt", new string[3] { "System.Int32", "System.Boolean", "System.Int32" }, null));
			num2 += Try("PlayerController.OverrideSpeed(float, float)", () => AddPrefixShim(module, "PlayerController", "OverrideSpeed", new string[2] { "System.Single", "System.Single" }, null));
			num2 += Try("Sound.PlayLoop(bool, float, float, float)", () => AddPrefixShim(module, "Sound", "PlayLoop", new string[4] { "System.Boolean", "System.Single", "System.Single", "System.Single" }, null));
			num2 += Try("ParticleScriptExplosion.Spawn(Vector3, float, int, int, float, bool, bool, float)", () => AddPrefixShim(module, "ParticleScriptExplosion", "Spawn", new string[8] { "UnityEngine.Vector3", "System.Single", "System.Int32", "System.Int32", "System.Single", "System.Boolean", "System.Boolean", "System.Single" }, null));
			num2 += Try("ChatManager.PossessChat(PossessChatID, string, float, Color, float, bool, int, UnityEvent)", () => AddPrefixShim(module, "ChatManager", "PossessChat", new string[8] { "ChatManager/PossessChatID", "System.String", "System.Single", "UnityEngine.Color", "System.Single", "System.Boolean", "System.Int32", "UnityEngine.Events.UnityEvent" }, null));
			num2 += Try("PhysGrabber.ReleaseObjectRPC(bool, float)", () => AddPrefixShim(module, "PhysGrabber", "ReleaseObjectRPC", new string[2] { "System.Boolean", "System.Single" }, new Dictionary<int, int> { { 2, -1 } }));
			Log.LogInfo((object)("Added " + num2 + "/6 compatibility methods for SillyValuables."));
		}

		private static bool AddPrefixShim(ModuleDefinition module, string typeName, string methodName, string[] oldParams, Dictionary<int, int> intOverrides)
		{
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Expected O, but got Unknown
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Expected O, but got Unknown
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			TypeDefinition type = module.GetType(typeName);
			if (type == null)
			{
				return false;
			}
			if (((IEnumerable<MethodDefinition>)type.Methods).Any((MethodDefinition m) => ((MemberReference)m).Name == methodName && SigMatches(m, oldParams)))
			{
				return false;
			}
			MethodDefinition val = (from m in (IEnumerable<MethodDefinition>)type.Methods
				where ((MemberReference)m).Name == methodName && ((MethodReference)m).Parameters.Count > oldParams.Length && !((MethodReference)m).HasGenericParameters && (from p in ((IEnumerable<ParameterDefinition>)((MethodReference)m).Parameters).Take(oldParams.Length)
					select ((MemberReference)((ParameterReference)p).ParameterType).FullName).SequenceEqual(oldParams)
				orderby ((MethodReference)m).Parameters.Count descending
				select m).FirstOrDefault();
			if (val == null)
			{
				return false;
			}
			MethodDefinition val2 = new MethodDefinition(methodName, (MethodAttributes)(0x86 | (val.IsStatic ? 16 : 0)), ((MethodReference)val).ReturnType);
			for (int num = 0; num < oldParams.Length; num++)
			{
				((MethodReference)val2).Parameters.Add(new ParameterDefinition(((ParameterReference)((MethodReference)val).Parameters[num]).Name, (ParameterAttributes)0, ((ParameterReference)((MethodReference)val).Parameters[num]).ParameterType));
			}
			ILProcessor iLProcessor = val2.Body.GetILProcessor();
			if (!val.IsStatic)
			{
				iLProcessor.Emit(OpCodes.Ldarg_0);
			}
			Enumerator<ParameterDefinition> enumerator = ((MethodReference)val2).Parameters.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					ParameterDefinition current = enumerator.Current;
					iLProcessor.Emit(OpCodes.Ldarg, current);
				}
			}
			finally
			{
				((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
			}
			for (int num2 = oldParams.Length; num2 < ((MethodReference)val).Parameters.Count; num2++)
			{
				ParameterDefinition val3 = ((MethodReference)val).Parameters[num2];
				TypeReference parameterType = ((ParameterReference)val3).ParameterType;
				if (intOverrides != null && intOverrides.TryGetValue(num2, out var value))
				{
					iLProcessor.Emit(OpCodes.Ldc_I4, value);
					continue;
				}
				if (!val3.HasConstant)
				{
					throw new InvalidOperationException("parameter " + ((ParameterReference)val3).Name + " has no default value");
				}
				object constant = val3.Constant;
				switch (((MemberReference)parameterType).FullName)
				{
				case "System.Int32":
					iLProcessor.Emit(OpCodes.Ldc_I4, Convert.ToInt32(constant));
					continue;
				case "System.Boolean":
					iLProcessor.Emit(OpCodes.Ldc_I4, Convert.ToBoolean(constant) ? 1 : 0);
					continue;
				case "System.Single":
					iLProcessor.Emit(OpCodes.Ldc_R4, Convert.ToSingle(constant));
					continue;
				}
				if (constant != null)
				{
					throw new InvalidOperationException("unsupported default for " + ((ParameterReference)val3).Name + " (" + ((MemberReference)parameterType).FullName + ")");
				}
				if (parameterType.IsValueType)
				{
					VariableDefinition val4 = new VariableDefinition(parameterType);
					val2.Body.Variables.Add(val4);
					val2.Body.InitLocals = true;
					iLProcessor.Emit(OpCodes.Ldloca, val4);
					iLProcessor.Emit(OpCodes.Initobj, parameterType);
					iLProcessor.Emit(OpCodes.Ldloc, val4);
				}
				else
				{
					iLProcessor.Emit(OpCodes.Ldnull);
				}
			}
			iLProcessor.Emit(OpCodes.Call, (MethodReference)(object)val);
			iLProcessor.Emit(OpCodes.Ret);
			type.Methods.Add(val2);
			return true;
		}

		private static int Try(string what, Func<bool> f)
		{
			try
			{
				bool flag = f();
				Log.LogInfo((object)((flag ? "Added " : "Skipped (already present or new target missing) ") + what));
				return flag ? 1 : 0;
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Failed to add " + what + ": " + ex));
				return 0;
			}
		}

		private static bool SigMatches(MethodDefinition m, params string[] paramTypeFullNames)
		{
			if (((MethodReference)m).Parameters.Count == paramTypeFullNames.Length)
			{
				return ((IEnumerable<ParameterDefinition>)((MethodReference)m).Parameters).Select((ParameterDefinition p) => ((MemberReference)((ParameterReference)p).ParameterType).FullName).SequenceEqual(paramTypeFullNames);
			}
			return false;
		}

		private static MethodDefinition NewForwarder(string name, TypeReference returnType)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			return new MethodDefinition(name, (MethodAttributes)134, returnType);
		}

		private static bool AddDestroyObject(ModuleDefinition module)
		{
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			//IL_00b2: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			TypeDefinition type = module.GetType("PhysGrabObjectImpactDetector");
			if (type == null)
			{
				return false;
			}
			if (((IEnumerable<MethodDefinition>)type.Methods).Any((MethodDefinition m) => ((MemberReference)m).Name == "DestroyObject" && SigMatches(m, "System.Boolean")))
			{
				return false;
			}
			MethodDefinition val = ((IEnumerable<MethodDefinition>)type.Methods).FirstOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => ((MemberReference)m).Name == "DestroyObject" && SigMatches(m, "System.Boolean", "System.Boolean")));
			if (val == null)
			{
				return false;
			}
			MethodDefinition val2 = NewForwarder("DestroyObject", module.TypeSystem.Void);
			((MethodReference)val2).Parameters.Add(new ParameterDefinition("effects", (ParameterAttributes)0, module.TypeSystem.Boolean));
			ILProcessor iLProcessor = val2.Body.GetILProcessor();
			iLProcessor.Emit(OpCodes.Ldarg_0);
			iLProcessor.Emit(OpCodes.Ldarg_1);
			iLProcessor.Emit(OpCodes.Ldc_I4_0);
			iLProcessor.Emit(OpCodes.Call, (MethodReference)(object)val);
			iLProcessor.Emit(OpCodes.Ret);
			type.Methods.Add(val2);
			return true;
		}

		private static bool AddInputDisplayGet(ModuleDefinition module)
		{
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Expected O, but got Unknown
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Expected O, but got Unknown
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Expected O, but got Unknown
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Expected O, but got Unknown
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Expected O, but got Unknown
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Expected O, but got Unknown
			TypeDefinition type = module.GetType("InputManager");
			TypeDefinition type2 = module.GetType("MenuKeybind");
			TypeDefinition type3 = module.GetType("KeyType");
			if (type == null || type2 == null || type3 == null)
			{
				return false;
			}
			MethodDefinition val = ((IEnumerable<MethodDefinition>)type.Methods).FirstOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => ((MemberReference)m).Name == "InputDisplayGet" && SigMatches(m, "InputKey", "KeyType", "MovementDirection", "System.String", "System.Int32")));
			if (val == null)
			{
				return false;
			}
			TypeDefinition oldKeyType = ((IEnumerable<TypeDefinition>)type2.NestedTypes).FirstOrDefault((Func<TypeDefinition, bool>)((TypeDefinition n) => ((MemberReference)n).Name == "KeyType"));
			if (oldKeyType == null)
			{
				TypeReference fieldType = ((FieldReference)((IEnumerable<FieldDefinition>)type3.Fields).First((FieldDefinition f) => ((MemberReference)f).Name == "value__")).FieldType;
				oldKeyType = new TypeDefinition("", "KeyType", (TypeAttributes)258, type3.BaseType);
				oldKeyType.Fields.Add(new FieldDefinition("value__", (FieldAttributes)1542, fieldType));
				foreach (FieldDefinition item in ((IEnumerable<FieldDefinition>)type3.Fields).Where((FieldDefinition f) => f.IsLiteral))
				{
					FieldDefinition val2 = new FieldDefinition(((MemberReference)item).Name, (FieldAttributes)32854, (TypeReference)(object)oldKeyType);
					val2.Constant = item.Constant;
					oldKeyType.Fields.Add(val2);
				}
				type2.NestedTypes.Add(oldKeyType);
			}
			if (((IEnumerable<MethodDefinition>)type.Methods).Any((MethodDefinition m) => ((MemberReference)m).Name == "InputDisplayGet" && ((MethodReference)m).Parameters.Count == 3 && (object)((ParameterReference)((MethodReference)m).Parameters[1]).ParameterType == oldKeyType))
			{
				return false;
			}
			MethodDefinition val3 = NewForwarder("InputDisplayGet", module.TypeSystem.String);
			((MethodReference)val3).Parameters.Add(new ParameterDefinition("_inputKey", (ParameterAttributes)0, ((ParameterReference)((MethodReference)val).Parameters[0]).ParameterType));
			((MethodReference)val3).Parameters.Add(new ParameterDefinition("_keyType", (ParameterAttributes)0, (TypeReference)(object)oldKeyType));
			((MethodReference)val3).Parameters.Add(new ParameterDefinition("_movementDirection", (ParameterAttributes)0, ((ParameterReference)((MethodReference)val).Parameters[2]).ParameterType));
			ILProcessor iLProcessor = val3.Body.GetILProcessor();
			iLProcessor.Emit(OpCodes.Ldarg_0);
			iLProcessor.Emit(OpCodes.Ldarg_1);
			iLProcessor.Emit(OpCodes.Ldarg_2);
			iLProcessor.Emit(OpCodes.Ldarg_3);
			iLProcessor.Emit(OpCodes.Ldnull);
			iLProcessor.Emit(OpCodes.Ldc_I4_0);
			iLProcessor.Emit(OpCodes.Call, (MethodReference)(object)val);
			iLProcessor.Emit(OpCodes.Ret);
			type.Methods.Add(val3);
			return true;
		}

		private static bool AddReleaseObjectRPC(ModuleDefinition module)
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Expected O, but got Unknown
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Expected O, but got Unknown
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Expected O, but got Unknown
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Expected O, but got Unknown
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: 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_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			TypeDefinition type = module.GetType("PhysGrabber");
			if (type == null)
			{
				return false;
			}
			if (((IEnumerable<MethodDefinition>)type.Methods).Any((MethodDefinition m) => ((MemberReference)m).Name == "ReleaseObjectRPC" && SigMatches(m, "System.Boolean", "System.Single", "System.Int32", "Photon.Pun.PhotonMessageInfo")))
			{
				return false;
			}
			MethodDefinition val = ((IEnumerable<MethodDefinition>)type.Methods).FirstOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => ((MemberReference)m).Name == "ReleaseObjectRPC" && SigMatches(m, "System.Boolean", "System.Single", "System.Int32", "System.Int32", "Photon.Pun.PhotonMessageInfo")));
			if (val == null)
			{
				return false;
			}
			MethodDefinition val2 = NewForwarder("ReleaseObjectRPC", module.TypeSystem.Void);
			((MethodReference)val2).Parameters.Add(new ParameterDefinition("_physGrabEnded", (ParameterAttributes)0, ((ParameterReference)((MethodReference)val).Parameters[0]).ParameterType));
			((MethodReference)val2).Parameters.Add(new ParameterDefinition("_disableTimer", (ParameterAttributes)0, ((ParameterReference)((MethodReference)val).Parameters[1]).ParameterType));
			((MethodReference)val2).Parameters.Add(new ParameterDefinition("_releaseObjectViewID", (ParameterAttributes)0, ((ParameterReference)((MethodReference)val).Parameters[2]).ParameterType));
			((MethodReference)val2).Parameters.Add(new ParameterDefinition("_info", (ParameterAttributes)0, ((ParameterReference)((MethodReference)val).Parameters[4]).ParameterType));
			ILProcessor iLProcessor = val2.Body.GetILProcessor();
			iLProcessor.Emit(OpCodes.Ldarg_0);
			iLProcessor.Emit(OpCodes.Ldarg_1);
			iLProcessor.Emit(OpCodes.Ldarg_2);
			iLProcessor.Emit(OpCodes.Ldarg_3);
			iLProcessor.Emit(OpCodes.Ldc_I4_M1);
			iLProcessor.Emit(OpCodes.Ldarg_S, ((MethodReference)val2).Parameters[3]);
			iLProcessor.Emit(OpCodes.Call, (MethodReference)(object)val);
			iLProcessor.Emit(OpCodes.Ret);
			type.Methods.Add(val2);
			return true;
		}
	}
}

plugins/LegacyFontLoadFix.dll

Decompiled a week ago
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<Object> _legacyAssets;

		private static Dictionary<string, Object> _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<Object>;
				_cache = type.GetField("_gameAssetCache", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(null) as Dictionary<string, Object>;
				_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<TMP_FontAsset>(((Object)font).name, SafePath(() => TMP_Settings.defaultFontAssetPath));
				}
				TMP_SpriteAsset spriteAsset = __0.spriteAsset;
				if ((Object)(object)spriteAsset != (Object)null && _legacyAssets.Contains((Object)(object)spriteAsset))
				{
					Seed<TMP_SpriteAsset>(((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<string> f)
		{
			try
			{
				return f();
			}
			catch
			{
				return null;
			}
		}

		private static void Seed<T>(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<T>(),
					text
				});
				if ((Object)(object)val == (Object)null && !string.IsNullOrEmpty(tmpResourcesPath))
				{
					val = (T)methodInfo.Invoke(null, new object[2]
					{
						Resources.LoadAll<T>(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)."));
				}
			}
		}
	}
}