Decompiled source of ModelReplacementFix v1.0.0

ModelReplacementFix.dll

Decompiled 8 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("ModelReplacementFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ModelReplacementFix")]
[assembly: AssemblyTitle("ModelReplacementFix")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ModelReplacementFix;

[BepInPlugin("com.yourname.modelreplacementfix", "ModelReplacement Fix", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	internal static ManualLogSource Log;

	private readonly Harmony harmony = new Harmony("com.yourname.modelreplacementfix");

	private void Awake()
	{
		Log = ((BaseUnityPlugin)this).Logger;
		harmony.PatchAll();
		Log.LogInfo((object)"ModelReplacement Fix loaded — UpdateItemTransform patch applied.");
	}
}
[HarmonyPatch]
public class UpdateItemTransformPatch
{
	private static bool _hasWarned;

	private static MethodBase TargetMethod()
	{
		Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
		foreach (Assembly assembly in assemblies)
		{
			if (!(assembly.GetName().Name == "ModelReplacementAPI"))
			{
				continue;
			}
			Type type = assembly.GetType("ModelReplacement.BodyReplacementBase");
			if (type != null)
			{
				MethodInfo method = type.GetMethod("UpdateItemTransform", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (method != null)
				{
					Plugin.Log.LogInfo((object)"ModelReplacement Fix: Successfully found UpdateItemTransform to patch.");
					return method;
				}
			}
		}
		Plugin.Log.LogWarning((object)"ModelReplacement Fix: Could not find UpdateItemTransform — patch not applied.");
		return null;
	}

	private static Exception Finalizer(Exception __exception)
	{
		if (__exception is IndexOutOfRangeException)
		{
			if (!_hasWarned)
			{
				Plugin.Log.LogWarning((object)"ModelReplacement Fix: Suppressed IndexOutOfRangeException in UpdateItemTransform. This is likely caused by the new utility slot (e.g. torch) in the latest Lethal Company update. This message will only appear once.");
				_hasWarned = true;
			}
			return null;
		}
		return __exception;
	}
}