Decompiled source of DioBracken v2.0.0

DioBracken.dll

Decompiled 11 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 DioBracken.Patches;
using HarmonyLib;
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("DioBracken")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DioBracken")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3adc118a-ab2f-410c-a1c5-f47855cae290")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace DioBracken
{
	[BepInPlugin("Ex.DioBrackenMod", "Ex Dio Bracken Replacement Mod", "1.0.0")]
	public class DioBrackenBase : BaseUnityPlugin
	{
		private const string modGUID = "Ex.DioBrackenMod";

		private const string modName = "Ex Dio Bracken Replacement Mod";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("Ex.DioBrackenMod");

		private static DioBrackenBase Instance;

		internal ManualLogSource mls;

		public static GameObject DioPrefab2;

		public static AudioClip DioApproach;

		public static AudioClip ItMeDio;

		public static AudioClip Timestop;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("Ex.DioBrackenMod");
			mls.LogInfo((object)"Dio Bracken Replacement mod has initiated");
			string location = ((BaseUnityPlugin)Instance).Info.Location;
			string text = "DioBracken.dll";
			string text2 = location.TrimEnd(text.ToCharArray());
			string text3 = text2 + "dioassets";
			string text4 = text2 + "dioanim";
			AssetBundle val = AssetBundle.LoadFromFile(text3);
			AssetBundle val2 = AssetBundle.LoadFromFile(text4);
			if ((Object)(object)val == (Object)null)
			{
				mls.LogError((object)"Failed to load assets!");
				return;
			}
			DioApproach = val.LoadAsset<AudioClip>("Assets/DioApproach.mp3");
			ItMeDio = val.LoadAsset<AudioClip>("Assets/KonoDioDa.mp3");
			Timestop = val.LoadAsset<AudioClip>("Assets/Timestop.mp3");
			DioPrefab2 = val2.LoadAsset<GameObject>("Assets/DioFlowerman.prefab");
			SkinnedMeshRenderer[] componentsInChildren = DioPrefab2.GetComponentsInChildren<SkinnedMeshRenderer>(true);
			SkinnedMeshRenderer[] array = componentsInChildren;
			foreach (SkinnedMeshRenderer val3 in array)
			{
				((Component)val3).gameObject.layer = LayerMask.NameToLayer("Enemies");
			}
			harmony.PatchAll(typeof(DioBrackenBase));
			harmony.PatchAll(typeof(DioPatch));
			mls.LogInfo((object)"Kono Dio da!");
		}
	}
}
namespace DioBracken.Patches
{
	[HarmonyPatch(typeof(FlowermanAI))]
	internal class DioPatch : 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)("Dio 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>(DioBrackenBase.DioPrefab2);
				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)("Dio Instance " + (object)val5));
				Transform val6 = val5.transform.Find("_3dio01t0_body_");
				Debug.Log((object)("Dio Instance " + (object)val6));
				Transform val7 = val5.transform.Find("Armature/Container/metarig");
				Debug.Log((object)("Dio 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)("Dio Instance " + (object)component.rootBone));
				((Object)val3).name = "old-metarig";
				__instance.creatureAngerVoice.clip = DioBrackenBase.DioApproach;
				__instance.crackNeckSFX = DioBrackenBase.ItMeDio;
			}
		}

		[HarmonyPatch("KillEnemy")]
		[HarmonyPostfix]
		public static void DioCleanup(FlowermanAI __instance)
		{
			((EnemyAI)__instance).dieSFX = DioBrackenBase.Timestop;
			((EnemyAI)__instance).creatureVoice.PlayOneShot(((EnemyAI)__instance).dieSFX);
		}
	}
}