Decompiled source of HAOButler v1.0.0

TShine.HAObutler.dll

Decompiled 7 months ago
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using ButlerAnim.Patches;
using ButlerAudio.Patches;
using HarmonyLib;
using LCSoundTool;
using MAIN;
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(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace MAIN
{
	[BepInPlugin("TShine.HAMUbutler", "HAMU butler", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private const string modGUID = "TShine.HAMUbutler";

		private const string modName = "HAMU butler";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("TShine.HAMUbutler");

		public static Plugin Instance;

		internal static AssetBundle MyAssetBundle;

		public static AudioClip die;

		public static AudioClip boom;

		public static AudioClip zhuisha;

		public static AudioClip gongji1;

		public static AudioClip gongji2;

		public static AudioClip sharenla;

		public static AudioClip nadao;

		public static AudioClip spawn;

		public static AudioClip sing1;

		public static AudioClip sing2;

		public static AudioClip sing3;

		public static AudioClip stab1;

		public static AudioClip stab2;

		public static AudioClip stab3;

		public static AudioClip stab4;

		public static AudioClip stab5;

		public static AudioClip stab6;

		public static AnimationClip customAnimationClip;

		private void Awake()
		{
			if ((Object)(object)Instance != (Object)null && (Object)(object)Instance != (Object)(object)this)
			{
				Object.Destroy((Object)(object)this);
			}
			else
			{
				Instance = this;
			}
			Debug.Log((object)"HAObutler Mod loaded 你的郝管家~~~");
			string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "hao");
			MyAssetBundle = AssetBundle.LoadFromFile(text);
			if ((Object)(object)MyAssetBundle == (Object)null)
			{
				Debug.LogError((object)"加载资源失败!!!");
				return;
			}
			customAnimationClip = MyAssetBundle.LoadAsset<AnimationClip>("dongzuo");
			die = MyAssetBundle.LoadAsset<AudioClip>("Assets/yinpin/die.ogg");
			boom = MyAssetBundle.LoadAsset<AudioClip>("Assets/yinpin/boom.ogg");
			zhuisha = MyAssetBundle.LoadAsset<AudioClip>("Assets/yinpin/zhuisha.ogg");
			gongji1 = MyAssetBundle.LoadAsset<AudioClip>("Assets/yinpin/gongji1.ogg");
			gongji2 = MyAssetBundle.LoadAsset<AudioClip>("Assets/yinpin/gongji2.ogg");
			sharenla = MyAssetBundle.LoadAsset<AudioClip>("Assets/yinpin/sharenla.ogg");
			nadao = MyAssetBundle.LoadAsset<AudioClip>("Assets/yinpin/nadao.ogg");
			spawn = MyAssetBundle.LoadAsset<AudioClip>("Assets/yinpin/spawn.ogg");
			sing1 = MyAssetBundle.LoadAsset<AudioClip>("Assets/yinpin/sing1.ogg");
			sing2 = MyAssetBundle.LoadAsset<AudioClip>("Assets/yinpin/sing2.ogg");
			sing3 = MyAssetBundle.LoadAsset<AudioClip>("Assets/yinpin/sing3.ogg");
			SoundTool.ReplaceAudioClip("ButlerBlowUp", die);
			SoundTool.ReplaceAudioClip("BalloonPop", boom);
			SoundTool.ReplaceAudioClip("BalloonPopReverb", boom);
			SoundTool.ReplaceAudioClip("ButlerMurderTheme", zhuisha);
			SoundTool.ReplaceAudioClip("ButlerStab1", gongji1, 0.5f);
			SoundTool.ReplaceAudioClip("ButlerStab1", gongji2, 0.5f);
			SoundTool.ReplaceAudioClip("SwingKnife", sing1);
			SoundTool.ReplaceAudioClip("SwingKnife2", sing2);
			SoundTool.ReplaceAudioClip("SwingKnife3", sing3);
			SoundTool.ReplaceAudioClip("KnifeStab1", stab1, 0.333f);
			SoundTool.ReplaceAudioClip("KnifeStab1", stab2, 0.333f);
			SoundTool.ReplaceAudioClip("KnifeStab1", stab3, 0.333f);
			SoundTool.ReplaceAudioClip("KnifeStab2", stab4, 0.333f);
			SoundTool.ReplaceAudioClip("KnifeStab2", stab5, 0.333f);
			SoundTool.ReplaceAudioClip("KnifeStab2", stab6, 0.333f);
			harmony.PatchAll(typeof(ButlerAnimPatch));
			harmony.PatchAll(typeof(ButlerAudioPatch));
			harmony.PatchAll();
		}
	}
}
namespace ButlerAnim.Patches
{
	internal class ButlerAnimPatch
	{
		[HarmonyPatch(typeof(ButlerEnemyAI), "Start")]
		public class ButlerEnemyPatch
		{
			private static void Postfix(ButlerEnemyAI __instance)
			{
				//IL_0037: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Expected O, but got Unknown
				Transform val = ((Component)__instance).transform.Find("MeshContainer");
				if ((Object)(object)val != (Object)null)
				{
					Animator component = ((Component)val).GetComponent<Animator>();
					if ((Object)(object)component != (Object)null)
					{
						AnimatorOverrideController val2 = new AnimatorOverrideController(component.runtimeAnimatorController);
						val2["ButlerKnifeIdle"] = Plugin.customAnimationClip;
						component.runtimeAnimatorController = (RuntimeAnimatorController)(object)val2;
					}
				}
			}
		}
	}
}
namespace ButlerAudio.Patches
{
	internal class ButlerAudioPatch
	{
		[HarmonyPatch(typeof(ButlerEnemyAI), "Start")]
		private static void Postfix(ButlerEnemyAI __instance)
		{
			Transform val = ((Component)__instance).transform.Find("Ambience");
			Transform val2 = ((Component)__instance).transform.Find("Ambience2");
			if ((Object)(object)val != (Object)null)
			{
				AudioSource component = ((Component)val).GetComponent<AudioSource>();
				if ((Object)(object)component != (Object)null)
				{
					component.clip = Plugin.spawn;
				}
			}
			if ((Object)(object)val2 != (Object)null)
			{
				AudioSource component2 = ((Component)val).GetComponent<AudioSource>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.clip = Plugin.nadao;
				}
			}
		}
	}
}