Decompiled source of FreminetButlerMod v1.0.4

FreminetButler.dll

Decompiled 8 months ago
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using LCSoundTool;
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("FreminetButler")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FreminetButler")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("965165e6-32a4-4610-8b74-1b17e406293b")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace FreminetButler;

[BepInPlugin("FreminetButler", "GoblinKingShmeesFreminetButler", "1.0.0")]
public class FremModBase : BaseUnityPlugin
{
	public class PenguinFacingDirection : MonoBehaviour
	{
		public ButlerBeesEnemyAI butlerBeesEnemyAI;

		public Vector3 prevPosition;

		private void Update()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Component)butlerBeesEnemyAI).transform.position - prevPosition;
			val.y = 0f;
			if (val != Vector3.zero)
			{
				Quaternion rotation = Quaternion.LookRotation(val);
				PenguinObject.transform.rotation = rotation;
			}
			prevPosition = ((Component)butlerBeesEnemyAI).transform.position;
		}
	}

	private readonly Harmony harmony = new Harmony("FremButler");

	private static FremModBase Instance;

	public static ManualLogSource mls;

	public static GameObject FremPrefab;

	public static GameObject FremObject;

	public static GameObject PenguinPrefab;

	public static GameObject PenguinObject;

	private AudioClip soundFremBalloonsTowerDefenseSix;

	public static AudioClip soundFremBuzzingAmbience;

	public static AudioClip soundFremIdleAmbience;

	public static AudioClip soundFremMurderTheme;

	public static AudioClip soundFremPersWalking;

	public static AssetBundle FremAssetBundle;

	private void Awake()
	{
		if ((Object)(object)Instance == (Object)null)
		{
			Instance = this;
		}
		mls = ((BaseUnityPlugin)this).Logger;
		mls.LogInfo((object)"--=== FREM MOD LOADED ===--");
		harmony.PatchAll(typeof(FremModBase));
		string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "frem");
		mls.LogDebug((object)text);
		FremAssetBundle = AssetBundle.LoadFromFile(text);
		if ((Object)(object)FremAssetBundle == (Object)null)
		{
			mls.LogError((object)"-Could not find klee Assets-");
		}
		FremPrefab = FremAssetBundle.LoadAsset<GameObject>("Assets/PrefabInstance/Frem.prefab");
		PenguinPrefab = FremAssetBundle.LoadAsset<GameObject>("Assets/PrefabInstance/Penguin.prefab");
		SkinnedMeshRenderer[] componentsInChildren = FremPrefab.GetComponentsInChildren<SkinnedMeshRenderer>(true);
		SkinnedMeshRenderer[] array = componentsInChildren;
		foreach (SkinnedMeshRenderer val in array)
		{
			((Component)val).gameObject.layer = LayerMask.NameToLayer("Enemies");
		}
	}

	private void Start()
	{
		soundFremBalloonsTowerDefenseSix = FremAssetBundle.LoadAsset<AudioClip>("Assets/AudioClip/FremBalloonsTowerDefenseSix.ogg");
		soundFremBuzzingAmbience = FremAssetBundle.LoadAsset<AudioClip>("Assets/AudioClip/FremBuzzingAmbience.ogg");
		soundFremIdleAmbience = FremAssetBundle.LoadAsset<AudioClip>("Assets/AudioClip/FremIdleAmbience.ogg");
		soundFremMurderTheme = FremAssetBundle.LoadAsset<AudioClip>("Assets/AudioClip/FremMurderTheme.ogg");
		soundFremPersWalking = FremAssetBundle.LoadAsset<AudioClip>("Assets/AudioClip/FremPersWalking.ogg");
		SoundTool.ReplaceAudioClip("ButlerBuzzingAmbience", soundFremBuzzingAmbience);
		SoundTool.ReplaceAudioClip("ButlerIdleAmbience", soundFremIdleAmbience);
		SoundTool.ReplaceAudioClip("ButlerMurderTheme", soundFremMurderTheme);
		SoundTool.ReplaceAudioClip("BalloonPop", soundFremBalloonsTowerDefenseSix);
	}

	[HarmonyPatch(typeof(ButlerEnemyAI), "Start")]
	[HarmonyPostfix]
	public static void PluginDetectButler(ButlerEnemyAI __instance)
	{
		//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
		__instance.ambience1.clip = soundFremIdleAmbience;
		__instance.ambience2.clip = soundFremMurderTheme;
		__instance.buzzingAmbience.clip = soundFremBuzzingAmbience;
		Transform parent = ((Component)__instance).transform.Find("MeshContainer");
		((Renderer)((Component)((Component)__instance).gameObject.transform.Find("MeshContainer").Find("Rig 1").Find("Arms")
			.Find("RightArm")
			.Find("upperRightArmContainer")
			.Find("upper_arm.R_target")
			.Find("Knife")).gameObject.GetComponent<MeshRenderer>()).enabled = false;
		((Renderer)((Component)((Component)__instance).gameObject.transform.Find("MeshContainer").Find("BodyLOD0")).gameObject.GetComponent<SkinnedMeshRenderer>()).enabled = false;
		((Renderer)((Component)((Component)__instance).gameObject.transform.Find("MeshContainer").Find("BodyLOD1")).gameObject.GetComponent<SkinnedMeshRenderer>()).enabled = false;
		((Renderer)((Component)((Component)__instance).gameObject.transform.Find("MeshContainer").Find("BodyLOD2")).gameObject.GetComponent<SkinnedMeshRenderer>()).enabled = false;
		((Renderer)((Component)((Component)__instance).gameObject.transform.Find("MeshContainer").Find("metarig").Find("spine")
			.Find("Broom")).gameObject.GetComponent<MeshRenderer>()).enabled = false;
		((Renderer)((Component)((Component)__instance).gameObject.transform.Find("MeshContainer").Find("metarig").Find("spine")
			.Find("spine.001")
			.Find("NeckContainer")
			.Find("spine.004")
			.Find("face")
			.Find("Hair")).gameObject.GetComponent<MeshRenderer>()).enabled = false;
		((Renderer)((Component)((Component)__instance).gameObject.transform.Find("MeshContainer").Find("metarig").Find("spine")
			.Find("spine.001")
			.Find("NeckContainer")
			.Find("spine.004")
			.Find("face")
			.Find("Teeth")).gameObject.GetComponent<MeshRenderer>()).enabled = false;
		((Component)((Component)__instance).gameObject.transform.Find("ScanNode")).gameObject.GetComponent<ScanNodeProperties>().headerText = "Freminet";
		FremObject = Object.Instantiate<GameObject>(FremPrefab);
		FremObject.transform.SetParent(parent);
		FremObject.transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
		FremObject.transform.localPosition = Vector3.zero;
		((EnemyAI)__instance).creatureAnimator = ((Component)FremObject.transform).GetComponent<Animator>();
	}

	[HarmonyPatch(typeof(ButlerEnemyAI), "CalculateAnimationDirection")]
	[HarmonyPostfix]
	public static void OnCalculateAnimationDirection(ButlerEnemyAI __instance, float maxSpeed, ref float ___velX, ref float ___velZ)
	{
		Animator component = ((Component)((Component)__instance).gameObject.transform.Find("MeshContainer")).gameObject.GetComponent<Animator>();
		if (!((Object)(object)component == (Object)null))
		{
			component.SetFloat("VelocityX", Mathf.Clamp(___velX, 0f - maxSpeed, maxSpeed));
			component.SetFloat("VelocityZ", Mathf.Clamp(___velZ, 0f - maxSpeed, maxSpeed));
		}
	}

	[HarmonyPatch(typeof(ButlerEnemyAI), "KillEnemy")]
	[HarmonyPostfix]
	public static void OnDeath(ButlerEnemyAI __instance)
	{
		((EnemyAI)__instance).creatureSFX.volume = 0.01f;
	}

	[HarmonyPatch(typeof(ButlerBeesEnemyAI), "Start")]
	[HarmonyPostfix]
	public static void Pengin(ButlerBeesEnemyAI __instance)
	{
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		__instance.buzzing.clip = soundFremPersWalking;
		__instance.buzzing.Play();
		Transform parent = ((Component)__instance).transform.Find("ScanNode");
		Object.Destroy((Object)(object)((Component)((Component)__instance).gameObject.transform.Find("BugSwarmParticle")).gameObject);
		Object.Destroy((Object)(object)((Component)((Component)__instance).gameObject.transform.Find("BugSwarmParticle").Find("Target")).gameObject.GetComponent<MeshRenderer>());
		PenguinObject = Object.Instantiate<GameObject>(PenguinPrefab);
		((Component)((Component)__instance).gameObject.transform.Find("ScanNode")).gameObject.GetComponent<ScanNodeProperties>().headerText = "Pers";
		PenguinObject.transform.SetParent(parent);
		PenguinObject.transform.localRotation = Quaternion.identity;
		PenguinObject.transform.localPosition = new Vector3(0f, -2f, 0f);
		Vector3 position = ((Component)__instance).transform.position;
		PenguinFacingDirection penguinFacingDirection = PenguinObject.AddComponent<PenguinFacingDirection>();
		penguinFacingDirection.butlerBeesEnemyAI = __instance;
		penguinFacingDirection.prevPosition = position;
		((EnemyAI)__instance).creatureAnimator = ((Component)PenguinObject.transform).GetComponent<Animator>();
	}

	[HarmonyPatch(typeof(ButlerBeesEnemyAI), "DoAIInterval")]
	[HarmonyPostfix]
	public static void Movement(ButlerBeesEnemyAI __instance)
	{
		Animator creatureAnimator = ((EnemyAI)__instance).creatureAnimator;
		((Behaviour)((EnemyAI)__instance).creatureAnimator).enabled = true;
		((Behaviour)creatureAnimator).enabled = true;
		creatureAnimator.SetBool("moving", true);
	}
}