Decompiled source of BetterCoilheadModel v1.1.4

NewCoil.dll

Decompiled 11 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using NewCoil.Patches;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("NewCoil")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NewCoil")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("329dd059-9886-40f3-b20c-9b1d46e0a3e9")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace NewCoil
{
	[BepInPlugin("Jori.BetterCoilModel", "Jori BetterCoilModel Replacement Mod", "1.0.0")]
	public class NewCoilBase : BaseUnityPlugin
	{
		private const string modGUID = "Jori.BetterCoilModel";

		private const string modName = "Jori BetterCoilModel Replacement Mod";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("Jori.BetterCoilModel");

		private static NewCoilBase Instance;

		internal ManualLogSource mls;

		public static GameObject CoilModel;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("Jori.BetterCoilModel");
			mls.LogInfo((object)"Coilhead Replacement mod has initiated");
			string location = ((BaseUnityPlugin)Instance).Info.Location;
			string text = "MNewCoil.dll";
			string text2 = location.TrimEnd(text.ToCharArray());
			string text3 = text2 + "coilassets";
			AssetBundle val = AssetBundle.LoadFromFile(text3);
			if ((Object)(object)val == (Object)null)
			{
				mls.LogError((object)"Failed to load assets!");
				return;
			}
			CoilModel = val.LoadAsset<GameObject>("Assets/NewCoil.prefab");
			SkinnedMeshRenderer[] componentsInChildren = CoilModel.GetComponentsInChildren<SkinnedMeshRenderer>(true);
			SkinnedMeshRenderer[] array = componentsInChildren;
			foreach (SkinnedMeshRenderer val2 in array)
			{
				((Component)val2).gameObject.layer = LayerMask.NameToLayer("Enemies");
			}
			harmony.PatchAll(typeof(NewCoilBase));
			harmony.PatchAll(typeof(NewCoilPatch));
			mls.LogInfo((object)"Coilhead Replacer Has Loaded!");
		}
	}
}
namespace NewCoil.Patches
{
	[HarmonyPatch(typeof(EnemyAI))]
	internal class NewCoilPatch : MonoBehaviour
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void CoilPreLoadPatch(EnemyAI __instance)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			if (!(__instance is SpringManAI))
			{
				return;
			}
			SpringManAI val;
			try
			{
				val = (SpringManAI)__instance;
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("Couldn't resolve EnemyAI instance to SpringManAI: " + ex.Message));
				return;
			}
			Transform val2 = ((Component)val).transform.Find("SpringManModel");
			SkinnedMeshRenderer val3 = ((val2 != null) ? ((Component)val2.Find("Body")).GetComponent<SkinnedMeshRenderer>() : null);
			MeshRenderer val4 = ((val2 != null) ? ((Component)val2.Find("Head")).GetComponent<MeshRenderer>() : null);
			((Renderer)((Component)val4).GetComponent<MeshRenderer>()).enabled = false;
			object obj;
			if (val2 == null)
			{
				obj = null;
			}
			else
			{
				Transform obj2 = val2.Find("AnimContainer");
				obj = ((obj2 != null) ? obj2.Find("metarig") : null);
			}
			Transform val5 = (Transform)obj;
			Debug.Log((object)("Coil Instance " + (object)val5));
			if (!((Object)(object)val3 == (Object)null) && ((Renderer)val3).enabled)
			{
				((Renderer)val3).enabled = false;
				Renderer[] componentsInChildren = ((Component)val5).gameObject.GetComponentsInChildren<Renderer>();
				Renderer[] array = componentsInChildren;
				foreach (Renderer val6 in array)
				{
					Debug.Log((object)val6);
					Debug.Log((object)val3);
					val6.enabled = false;
				}
				GameObject val7 = Object.Instantiate<GameObject>(NewCoilBase.CoilModel);
				val7.transform.SetParent(val2);
				val7.transform.localPosition = Vector3.zero;
				val7.transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
				val7.transform.localScale = Vector3.one;
				Debug.Log((object)("Coil Instance " + (object)val7));
				Transform val8 = val7.transform.Find("mesh_coilhead");
				Debug.Log((object)("Coil Instance " + (object)val8));
				Transform val9 = val7.transform.Find("SpringMan/SpringManModel/AnimContainer/metarig");
				Debug.Log((object)("Coil Instance " + (object)val9));
				val9.SetParent(val5.parent, true);
				((Component)val9).transform.localScale = ((Component)val5).transform.localScale;
				((Component)val9).transform.localRotation = ((Component)val5).transform.localRotation;
				((Component)val9).transform.localPosition = ((Component)val5).transform.localPosition;
				SkinnedMeshRenderer component = ((Component)val8).GetComponent<SkinnedMeshRenderer>();
				Transform rootBone = val7.transform.Find("SpringMan/SpringManModel/AnimContainer/metarig/spine");
				component.rootBone = rootBone;
				Debug.Log((object)("Coil Instance " + (object)component.rootBone));
				((Object)val5).name = "old-metarig";
			}
		}
	}
}