Decompiled source of Omni Bracken v1.0.3

OmniBrackenMod.dll

Decompiled a year ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Video;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("OmniBrackenMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A template for Lethal Company")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("OmniBrackenMod")]
[assembly: AssemblyTitle("OmniBrackenMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace OmniBrackenMod
{
	public static class ConfigSettings
	{
		public static ConfigEntry<float> AudioDistance;

		public static ConfigEntry<float> Speed;

		public static ConfigEntry<float> StandupTime;

		public static ConfigEntry<float> StalkAudioIntervalMin;

		public static ConfigEntry<float> StalkAudioIntervalMax;

		public static void BindConfigSettings()
		{
			AudioDistance = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<float>("OmniBrackenMod", "Custom Audio Distance", 30f, "Distance Omni-Man's audio travels. (Vanilla is ~20)");
			Speed = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<float>("OmniBrackenMod", "Chase Speed", 22f, "The speed at which Omni-Man chases you when provoked. (Vanilla is 9)");
			StandupTime = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<float>("OmniBrackenMod", "Standup Time", 0.5f, "The time it takes Omni-Man to stand back up when you catch him stalking.");
			StalkAudioIntervalMin = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<float>("OmniBrackenMod", "Stalk Audio Interval Min", 5f, "The minimum time Omni-Man will wait to let you know he's stalking you.");
			StalkAudioIntervalMax = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<float>("OmniBrackenMod", "Stalk Audio Interval Max", 13f, "The maximum time Omni-Man will wait to let you know he's stalking you.");
		}
	}
	[BepInPlugin("OmniBrackenMod", "OmniBrackenMod", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static AudioClip AngerVoice;

		public static AudioClip CaughtVoice;

		public static AudioClip CrackNeckAudio;

		public static AudioClip StunSFX;

		public static GameObject StalkAudio;

		public static GameObject StandPrefab;

		public static GameObject MadPrefab;

		public static VideoClip TerminalVideo;

		public static TextAsset TerminalText;

		public static Plugin Instance;

		private Harmony _harmonyMain;

		private void Awake()
		{
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Expected O, but got Unknown
			AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "omnibracken"));
			AngerVoice = val.LoadAsset<AudioClip>("assets/Anger Voice.mp3");
			MadPrefab = val.LoadAsset<GameObject>("assets/OmniMadBracken.prefab");
			StandPrefab = val.LoadAsset<GameObject>("assets/OmniNormalBracken.prefab");
			TerminalText = val.LoadAsset<TextAsset>("assets/OmniManDescription.txt");
			TerminalVideo = val.LoadAsset<VideoClip>("assets/Terminal Video.mp4");
			StalkAudio = val.LoadAsset<GameObject>("assets/StalkSource.prefab");
			CaughtVoice = val.LoadAsset<AudioClip>("assets/VineBoom.mp3");
			StunSFX = val.LoadAsset<AudioClip>("assets/Stun.mp3");
			CrackNeckAudio = val.LoadAsset<AudioClip>("assets/Jumpscare.mp3");
			Instance = this;
			ConfigSettings.BindConfigSettings();
			_harmonyMain = new Harmony("OmniBrackenMod");
			_harmonyMain.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin OmniBrackenMod is loaded!");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "OmniBrackenMod";

		public const string PLUGIN_NAME = "OmniBrackenMod";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace OmniBrackenMod.Patches
{
	[HarmonyPatch(typeof(EnemyAI))]
	public class EnemyAIPatches
	{
		[HarmonyPatch("SwitchToBehaviourStateOnLocalClient")]
		[HarmonyPostfix]
		public static void SwitchToBehaviorStateOnLocalClientPatch(EnemyAI __instance, int stateIndex)
		{
			FlowermanAI val = (FlowermanAI)(object)((__instance is FlowermanAI) ? __instance : null);
			if (val != null)
			{
				switch (stateIndex)
				{
				case 0:
					((MonoBehaviour)val).StopAllCoroutines();
					((MonoBehaviour)val).StartCoroutine(FlowermanAIPatches.Stalk(val));
					FlowermanAIPatches.Anger(val);
					break;
				case 1:
					FlowermanAIPatches.Mute(val);
					((MonoBehaviour)val).StopAllCoroutines();
					((MonoBehaviour)val).StartCoroutine(FlowermanAIPatches.Stand(val));
					break;
				case 2:
					FlowermanAIPatches.Mute(val);
					((MonoBehaviour)val).StopAllCoroutines();
					FlowermanAIPatches.Anger(val);
					break;
				}
			}
		}
	}
	[HarmonyPatch(typeof(FlowermanAI))]
	public class FlowermanAIPatches
	{
		private class FlowermanExtras
		{
			public GameObject Model;

			public AudioSource StalkAudioSource;

			public FlowermanExtras(GameObject newModel, AudioSource newStalkAudioSource)
			{
				Model = newModel;
				StalkAudioSource = newStalkAudioSource;
			}
		}

		private static Dictionary<FlowermanAI, FlowermanExtras> _omniManMap = new Dictionary<FlowermanAI, FlowermanExtras>();

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void StartPatch(FlowermanAI __instance)
		{
			_omniManMap.Add(__instance, new FlowermanExtras(null, Object.Instantiate<GameObject>(Plugin.StalkAudio, ((Component)__instance).gameObject.transform).GetComponent<AudioSource>()));
			__instance.creatureAngerVoice.clip = Plugin.AngerVoice;
			__instance.crackNeckSFX = Plugin.CrackNeckAudio;
			__instance.crackNeckAudio.clip = Plugin.CrackNeckAudio;
			((EnemyAI)__instance).enemyType.stunSFX = Plugin.StunSFX;
			((EnemyAI)__instance).enemyBehaviourStates[1].VoiceClip = Plugin.CaughtVoice;
			__instance.creatureAngerVoice.maxDistance = ConfigSettings.AudioDistance.Value;
			__instance.crackNeckAudio.maxDistance = ConfigSettings.AudioDistance.Value;
			((EnemyAI)__instance).creatureSFX.maxDistance = ConfigSettings.AudioDistance.Value;
			((EnemyAI)__instance).creatureVoice.maxDistance = ConfigSettings.AudioDistance.Value;
			((Component)((Component)__instance).gameObject.transform.Find("ScanNode")).GetComponent<ScanNodeProperties>().headerText = "Omni-Man";
			Object.Destroy((Object)(object)((Component)((Component)__instance).gameObject.transform.Find("FlowermanModel").Find("LOD1")).gameObject.GetComponent<SkinnedMeshRenderer>());
			Object.Destroy((Object)(object)((Component)((Component)__instance).gameObject.transform.Find("FlowermanModel").Find("AnimContainer").Find("metarig")).gameObject);
			__instance.EnterAngerModeServerRpc(0f);
			__instance.EnterAngerModeClientRpc(0f);
			((MonoBehaviour)__instance).StartCoroutine(Stand(__instance));
		}

		[HarmonyPatch("EnterAngerModeClientRpc")]
		[HarmonyPostfix]
		public static void EnterAngerModeClientRPCPatch(FlowermanAI __instance)
		{
			((EnemyAI)__instance).agent.speed = ConfigSettings.Speed.Value;
		}

		[HarmonyPatch("KillEnemy")]
		[HarmonyPostfix]
		public static void KillEnemyPatch(FlowermanAI __instance)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			Mute(__instance);
			((MonoBehaviour)__instance).StopAllCoroutines();
			_omniManMap[__instance].Model.transform.eulerAngles = new Vector3(90f, 0f, 0f);
			Transform transform = _omniManMap[__instance].Model.transform;
			transform.localPosition += new Vector3(0f, -1.45f, 0f);
		}

		[HarmonyPatch("KillPlayerAnimationClientRpc")]
		[HarmonyPostfix]
		public static void KillPlayerAnimationClientRpcPatch(FlowermanAI __instance, int playerObjectId)
		{
			((Component)StartOfRound.Instance.allPlayerScripts[playerObjectId].gameplayCamera).transform.LookAt(((Component)__instance).transform);
		}

		public static void Anger(FlowermanAI __instance)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(Plugin.MadPrefab, ((Component)__instance).gameObject.transform);
			val.transform.localPosition = new Vector3(0f, 1.5f, 0f);
			if (Object.op_Implicit((Object)(object)_omniManMap[__instance].Model))
			{
				Object.Destroy((Object)(object)_omniManMap[__instance].Model);
			}
			_omniManMap[__instance].Model = val;
		}

		public static IEnumerator Stand(FlowermanAI __instance)
		{
			yield return (object)new WaitForSeconds(ConfigSettings.StandupTime.Value);
			GameObject newOmniMan = Object.Instantiate<GameObject>(Plugin.StandPrefab, ((Component)__instance).gameObject.transform);
			newOmniMan.transform.localPosition = new Vector3(0f, 1.5f, 0f);
			if (Object.op_Implicit((Object)(object)_omniManMap[__instance].Model))
			{
				Object.Destroy((Object)(object)_omniManMap[__instance].Model);
			}
			_omniManMap[__instance].Model = newOmniMan;
		}

		public static IEnumerator Stalk(FlowermanAI __instance)
		{
			AudioSource stalkAudio = _omniManMap[__instance].StalkAudioSource;
			while (true)
			{
				stalkAudio.Play();
				yield return (object)new WaitForSeconds(stalkAudio.clip.length + (float)new Random().NextDouble() * (ConfigSettings.StalkAudioIntervalMax.Value - ConfigSettings.StalkAudioIntervalMin.Value) + ConfigSettings.StalkAudioIntervalMin.Value);
			}
		}

		public static void Mute(FlowermanAI __instance)
		{
			_omniManMap[__instance].StalkAudioSource.Stop();
		}
	}
	[HarmonyPatch(typeof(Terminal))]
	public class TerminalPatches
	{
		[HarmonyPatch("BeginUsingTerminal")]
		[HarmonyPostfix]
		public static void BeginUsingTerminalPatch(Terminal __instance)
		{
			__instance.terminalNodes.allKeywords[36].word = "omni-man";
			__instance.enemyFiles[1].creatureName = "Omni-Man";
			__instance.enemyFiles[1].displayVideo = Plugin.TerminalVideo;
			__instance.enemyFiles[1].displayText = Plugin.TerminalText.text;
		}
	}
}