Decompiled source of BetterBrackenModel v1.2.4

ModelRequestA.dll

Decompiled 10 months ago
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 ModelRequestA.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("ModelRequestA")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ModelRequestA")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("26e8af3b-a7ab-4053-8f6a-5765624c5aeb")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ModelRequestA
{
	[BepInPlugin("Jori.BetterBrackenModel", "Jori BetterBrackenModel Replacement Mod", "1.0.0")]
	public class BrackenRequestBase : BaseUnityPlugin
	{
		private const string modGUID = "Jori.BetterBrackenModel";

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

		private const string modVersion = "1.0.0";

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

		private static BrackenRequestBase Instance;

		internal ManualLogSource mls;

		public static GameObject BrackenModel;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("Jori.BetterBrackenModel");
			mls.LogInfo((object)"Bracken Replacement mod has initiated");
			string location = ((BaseUnityPlugin)Instance).Info.Location;
			string text = "ModelRequestA.dll";
			string text2 = location.TrimEnd(text.ToCharArray());
			string text3 = text2 + "brackenassets";
			AssetBundle val = AssetBundle.LoadFromFile(text3);
			if ((Object)(object)val == (Object)null)
			{
				mls.LogError((object)"Failed to load assets!");
				return;
			}
			BrackenModel = val.LoadAsset<GameObject>("Assets/NewBrackIK.prefab");
			SkinnedMeshRenderer[] componentsInChildren = BrackenModel.GetComponentsInChildren<SkinnedMeshRenderer>(true);
			SkinnedMeshRenderer[] array = componentsInChildren;
			foreach (SkinnedMeshRenderer val2 in array)
			{
				((Component)val2).gameObject.layer = LayerMask.NameToLayer("Enemies");
			}
			harmony.PatchAll(typeof(BrackenRequestBase));
			harmony.PatchAll(typeof(BrackenPatch));
			mls.LogInfo((object)"Bracken Replacer Has Loaded!");
		}
	}
}
namespace ModelRequestA.Patches
{
	[HarmonyPatch(typeof(FlowermanAI))]
	internal class BrackenPatch : MonoBehaviour
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void DioPreLoadPatch(FlowermanAI __instance)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ((Component)__instance).transform.Find("FlowermanModel");
			SkinnedMeshRenderer val2 = ((val != null) ? ((Component)val.Find("LOD1")).GetComponent<SkinnedMeshRenderer>() : null);
			object obj;
			if (val == null)
			{
				obj = null;
			}
			else
			{
				Transform obj2 = val.Find("AnimContainer");
				obj = ((obj2 != null) ? obj2.Find("metarig") : null);
			}
			Transform val3 = (Transform)obj;
			Debug.Log((object)("Bracken Instance " + (object)val3));
			if (!((Object)(object)val2 == (Object)null) && ((Renderer)val2).enabled)
			{
				((Renderer)val2).enabled = false;
				Renderer[] componentsInChildren = ((Component)val3).gameObject.GetComponentsInChildren<Renderer>();
				Renderer[] array = componentsInChildren;
				foreach (Renderer val4 in array)
				{
					Debug.Log((object)val4);
					Debug.Log((object)val2);
					val4.enabled = false;
				}
				GameObject val5 = Object.Instantiate<GameObject>(BrackenRequestBase.BrackenModel);
				val5.transform.SetParent(val);
				val5.transform.localPosition = Vector3.zero;
				val5.transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
				val5.transform.localScale = Vector3.one;
				Debug.Log((object)("Bracken Instance " + (object)val5));
				Transform val6 = val5.transform.Find("mesh_bracken");
				Debug.Log((object)("Bracken Instance " + (object)val6));
				Transform val7 = val5.transform.Find("Container/metarig");
				Debug.Log((object)("Bracken Instance " + (object)val7));
				val7.SetParent(val3.parent, true);
				((Component)val7).transform.localScale = ((Component)val3).transform.localScale;
				((Component)val7).transform.localRotation = ((Component)val3).transform.localRotation;
				((Component)val7).transform.localPosition = ((Component)val3).transform.localPosition;
				SkinnedMeshRenderer component = ((Component)val6).GetComponent<SkinnedMeshRenderer>();
				component.rootBone = val7;
				Debug.Log((object)("Bracken Instance " + (object)component.rootBone));
				((Object)val3).name = "old-metarig";
				__instance.rightHandGrip = val7.Find("Torso1").Find("Torso2").Find("Torso3")
					.Find("Arm1.R")
					.Find("Arm2.R")
					.Find("Arm3.R")
					.Find("Hand1.R")
					.Find("HandGripPosition");
			}
		}
	}
}