Decompiled source of Lethal Company Lobotomy v1.0.0

BepInEx/plugins/LCLobotomy/LCLobotomyFireInTheHole.dll

Decompiled 9 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using LCLobotomyFireInTheHole.Patches;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("LCLobotomyFireInTheHole")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LCLobotomyFireInTheHole")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("6ba09646-f0eb-4a47-beb4-bc6e8f09c497")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
public static class DictionaryExtensions
{
	public static bool HasNullKeys<TKey, TValue>(this Dictionary<TKey, TValue> dictionary) where TKey : Object
	{
		foreach (TKey key in dictionary.Keys)
		{
			if ((Object)(object)key == (Object)null)
			{
				return true;
			}
		}
		return false;
	}

	public static void RemoveNullKeys<TKey, TValue>(this Dictionary<TKey, TValue> dictionary) where TKey : Object
	{
		if (!dictionary.HasNullKeys())
		{
			return;
		}
		TKey[] array = dictionary.Keys.ToArray();
		foreach (TKey val in array)
		{
			if ((Object)(object)val == (Object)null)
			{
				dictionary.Remove(val);
			}
		}
	}
}
namespace LCLobotomyFireInTheHole
{
	[BepInPlugin("z33r0x.lclobotomy", "Lethal Company Lobotomy", "1.0.0.0")]
	public class LobotomyModBase : BaseUnityPlugin
	{
		private const string modGUID = "z33r0x.lclobotomy";

		private const string modName = "Lethal Company Lobotomy";

		private const string modVersion = "1.0.0.0";

		private readonly Harmony harmony = new Harmony("z33r0x.lclobotomy");

		private static LobotomyModBase Instance;

		internal static AudioClip[] demonSFX;

		internal static AudioClip normalSFX;

		internal static ManualLogSource mls;

		internal static Dictionary<GameObject, long> lastNormalSFX = new Dictionary<GameObject, long>();

		internal static Dictionary<GameObject, int> nextDelays = new Dictionary<GameObject, int>();

		internal static Texture2D normalTexture;

		internal static Texture2D demonTexture;

		internal static Sprite normalSprite;

		internal static Sprite demonSprite;

		internal static GameObject billboardPrefab;

		internal static Dictionary<AudioSource, GameObject> currentObjects = new Dictionary<AudioSource, GameObject>();

		private const string dllName = "LCLobotomyFireInTheHole.dll";

		private void Awake()
		{
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("z33r0x.lclobotomy");
			mls.LogInfo((object)"Lethal Company Lobotomy has awaken");
			string text = ((BaseUnityPlugin)Instance).Info.Location.TrimEnd("LCLobotomyFireInTheHole.dll".ToCharArray());
			AssetBundle val = AssetBundle.LoadFromFile(text + "fireinthehole");
			AssetBundle val2 = AssetBundle.LoadFromFile(text + "highpitchfireinthehole");
			AssetBundle val3 = AssetBundle.LoadFromFile(text + "normalface");
			AssetBundle val4 = AssetBundle.LoadFromFile(text + "demonface");
			AssetBundle val5 = AssetBundle.LoadFromFile(text + "billboardbundle");
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				mls.LogError((object)"failed to load assets!");
				return;
			}
			demonSFX = val.LoadAllAssets<AudioClip>();
			normalSFX = val2.LoadAllAssets<AudioClip>()[0];
			normalTexture = val3.LoadAllAssets<Texture2D>()[0];
			demonTexture = val4.LoadAllAssets<Texture2D>()[0];
			billboardPrefab = val5.LoadAllAssets<GameObject>()[0];
			demonSprite = Sprite.Create(demonTexture, new Rect(0f, 0f, (float)((Texture)demonTexture).width, (float)((Texture)demonTexture).height), new Vector2(0.5f, 0.5f), 100f);
			normalSprite = Sprite.Create(normalTexture, new Rect(0f, 0f, (float)((Texture)normalTexture).width, (float)((Texture)normalTexture).height), new Vector2(0.5f, 0.5f), 100f);
			mls.LogInfo((object)normalSFX);
			harmony.PatchAll(typeof(CrawlerAIPatch));
			mls.LogInfo((object)"Loaded Lobotomy mod!");
		}
	}
}
namespace LCLobotomyFireInTheHole.Patches
{
	[HarmonyPatch(typeof(CrawlerAI))]
	internal class CrawlerAIPatch
	{
		[HarmonyPatch("MakeScreech")]
		[HarmonyPrefix]
		private static void MakeScreechPatch(ref AudioClip[] ___longRoarSFX)
		{
			AudioClip[] demonSFX = LobotomyModBase.demonSFX;
			___longRoarSFX = demonSFX;
			LobotomyModBase.mls.LogInfo((object)"Replaced longRoarSFX");
		}

		[HarmonyPatch("HitPlayerClientRpc")]
		[HarmonyPrefix]
		private static void HitPlayerPatch(ref AudioClip ___bitePlayerSFX)
		{
			AudioClip val = LobotomyModBase.demonSFX[0];
			___bitePlayerSFX = val;
			LobotomyModBase.mls.LogInfo((object)"Replaced bitePlayerSFX");
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void UpdatePatch(ref bool ___hasEnteredChaseMode, ref AudioSource ___creatureVoice, CrawlerAI __instance)
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Expected O, but got Unknown
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			if (!LobotomyModBase.lastNormalSFX.ContainsKey(((Component)___creatureVoice).gameObject))
			{
				LobotomyModBase.lastNormalSFX.Add(((Component)___creatureVoice).gameObject, 0L);
			}
			if (!LobotomyModBase.nextDelays.ContainsKey(((Component)___creatureVoice).gameObject))
			{
				LobotomyModBase.nextDelays.Add(((Component)___creatureVoice).gameObject, Random.Range(1, 4));
			}
			Transform transform = ((Component)__instance).transform;
			GameObject gameObject = ((Component)transform).gameObject;
			bool flag = false;
			foreach (Transform item in transform)
			{
				Transform val = item;
				if (((Object)val).name == "billboard")
				{
					flag = true;
					Vector3 forward = ((Component)StartOfRound.Instance.activeCamera).gameObject.transform.forward;
					val.forward = forward;
					SpriteRenderer component = ((Component)val).GetComponent<SpriteRenderer>();
					if (___hasEnteredChaseMode && (Object)(object)component.sprite != (Object)(object)LobotomyModBase.demonSprite)
					{
						component.sprite = LobotomyModBase.demonSprite;
					}
					else if (!___hasEnteredChaseMode && (Object)(object)component.sprite != (Object)(object)LobotomyModBase.normalSprite)
					{
						component.sprite = LobotomyModBase.normalSprite;
					}
					break;
				}
			}
			if (!flag)
			{
				SkinnedMeshRenderer[] componentsInChildren = gameObject.GetComponentsInChildren<SkinnedMeshRenderer>();
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					((Renderer)componentsInChildren[i]).enabled = false;
					LobotomyModBase.mls.LogInfo((object)"disabled meshrenderer");
				}
				GameObject obj = Object.Instantiate<GameObject>(LobotomyModBase.billboardPrefab);
				((Object)obj).name = "billboard";
				obj.transform.SetParent(transform, false);
				obj.transform.localPosition = new Vector3(0f, 1f, 0f);
			}
			LobotomyModBase.nextDelays.RemoveNullKeys<GameObject, int>();
			LobotomyModBase.lastNormalSFX.RemoveNullKeys<GameObject, long>();
			long num = LobotomyModBase.lastNormalSFX[((Component)___creatureVoice).gameObject];
			long num2 = DateTimeOffset.Now.ToUnixTimeSeconds();
			if (num2 - num > LobotomyModBase.nextDelays[((Component)___creatureVoice).gameObject])
			{
				LobotomyModBase.nextDelays[((Component)___creatureVoice).gameObject] = Random.Range(1, 4);
				LobotomyModBase.lastNormalSFX[((Component)___creatureVoice).gameObject] = num2;
				if (___hasEnteredChaseMode)
				{
					___creatureVoice.PlayOneShot(LobotomyModBase.demonSFX[0]);
					LobotomyModBase.mls.LogInfo((object)"Played Demon SFX");
				}
				else
				{
					___creatureVoice.PlayOneShot(LobotomyModBase.normalSFX);
					LobotomyModBase.mls.LogInfo((object)"Played Normal SFX");
				}
			}
		}
	}
}