Decompiled source of realistic coilhead v1.0.1

replacecoilhead.dll

Decompiled 10 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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("replacecoilhead")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+332b0dcc3befb067b84d2dd4398331b58fb3a7ee")]
[assembly: AssemblyProduct("replacecoilhead")]
[assembly: AssemblyTitle("replacecoilhead")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace realisticcoilhead
{
	[BepInPlugin("realisticcoilhead", "realisticcoildhead", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static GameObject Visuals;

		public static Harmony harmonyInstance;

		private void Awake()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin realistic coil is loaded!");
			harmonyInstance = new Harmony("realisticcoilhead");
			harmonyInstance.PatchAll(Assembly.GetExecutingAssembly());
			string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "coil");
			AssetBundle val = AssetBundle.LoadFromFile(text);
			if ((Object)(object)val == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Failed to load AssetBundle from: " + text));
				return;
			}
			Visuals = val.LoadAsset<GameObject>("Assets/coil.prefab");
			if ((Object)(object)Visuals == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load 'coil.prefab' from AssetBundle.");
				return;
			}
			Renderer[] componentsInChildren = Visuals.GetComponentsInChildren<Renderer>(true);
			Renderer[] array = componentsInChildren;
			foreach (Renderer val2 in array)
			{
				((Component)val2).gameObject.layer = LayerMask.NameToLayer("Enemies");
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "realisticcoilhead";

		public const string PLUGIN_NAME = "realisticcoilhead";

		public const string PLUGIN_VERSION = "1.0.0";
	}
	[HarmonyPatch(typeof(SpringManAI), "Update")]
	internal class SpringManPatch
	{
		private static bool isModelReplaced;

		private static void Postfix(SpringManAI __instance)
		{
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			if (isModelReplaced)
			{
				return;
			}
			if ((Object)(object)Plugin.Visuals == (Object)null)
			{
				Debug.LogError((object)"Visuals GameObject is null.");
				return;
			}
			Transform val = ((Component)__instance).transform.Find("SpringManModel");
			if ((Object)(object)val == (Object)null)
			{
				Debug.LogError((object)"SpringManModel Transform not found.");
				return;
			}
			Transform obj = val.Find("Body");
			SkinnedMeshRenderer val2 = ((obj != null) ? ((Component)obj).GetComponent<SkinnedMeshRenderer>() : null);
			Transform obj2 = val.Find("Head");
			MeshRenderer val3 = ((obj2 != null) ? ((Component)obj2).GetComponent<MeshRenderer>() : null);
			if ((Object)(object)val2 != (Object)null)
			{
				((Renderer)val2).enabled = false;
			}
			if ((Object)(object)val3 != (Object)null)
			{
				((Renderer)val3).enabled = false;
			}
			GameObject val4 = Object.Instantiate<GameObject>(Plugin.Visuals);
			val4.transform.SetParent(val);
			val4.transform.localPosition = Vector3.zero;
			val4.transform.localRotation = Quaternion.identity;
			val4.transform.localScale = Vector3.one;
			Transform val5 = val4.transform.Find("Coilhead/Armature");
			Transform val6 = val4.transform.Find("Coilhead/mesh_coilhead");
			if ((Object)(object)val5 == (Object)null)
			{
				Debug.LogError((object)"Coilhead Armature Transform not found in the new model.");
			}
			if ((Object)(object)val6 == (Object)null)
			{
				Debug.LogError((object)"Mesh Coilhead Transform not found in the new model.");
			}
			Transform val7 = val.Find("AnimContainer/metarig");
			if ((Object)(object)val7 != (Object)null && (Object)(object)val5 != (Object)null)
			{
				val5.SetParent(val7.parent, false);
				val5.localScale = val7.localScale;
				val5.localRotation = val7.localRotation;
				val5.localPosition = val7.localPosition;
				((Object)val7).name = "old-metarig";
			}
			if ((Object)(object)val6 != (Object)null)
			{
				SkinnedMeshRenderer component = ((Component)val6).GetComponent<SkinnedMeshRenderer>();
				if ((Object)(object)component != (Object)null)
				{
					component.rootBone = val5;
				}
				else
				{
					Debug.LogError((object)"SkinnedMeshRenderer on new model not found.");
				}
			}
			isModelReplaced = true;
		}
	}
}