Decompiled source of Herbert Bracken v1.0.0

plugins/HerbertBraken_V3.dll

Decompiled 8 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using HerbertBracken.Core;
using HerbertBracken.Patches;
using HerbertBraken.Scripts;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("HerbertBracken")]
[assembly: AssemblyDescription("A mod for Lethal Company that replaces the bracken's model with a model of Herbert the pervert from Family Guy. \"Herbert The Pervert\" (https://skfb.ly/6YDzP) by jumpymonkeymad is licensed under Creative Commons Attribution (http://creativecommons.org/licenses/by/4.0/).")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("SpruceAcrobat18")]
[assembly: AssemblyProduct("HerbertBracken")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("50feedfa-5dd6-4358-936e-87945c1a8cae")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.5.9.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;
		}
	}
}
public static class Assets
{
	public static string mainAssetBundleName = "newherb";

	public static AssetBundle MainAssetBundle = null;

	private static string GetAssemblyName()
	{
		return Assembly.GetExecutingAssembly().GetName().Name.Replace(" ", "_");
	}

	public static void PopulateAssets()
	{
		if ((Object)(object)MainAssetBundle == (Object)null)
		{
			Console.WriteLine(GetAssemblyName() + "." + mainAssetBundleName);
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(GetAssemblyName() + "." + mainAssetBundleName);
			MainAssetBundle = AssetBundle.LoadFromStream(stream);
		}
	}
}
namespace HerbertBraken_V3
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "HerbertBraken_V3";

		public const string PLUGIN_NAME = "A mod to replace the braken with Herbet from family guy";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace HerbertBraken.Scripts
{
	public class HerbertController : MonoBehaviour
	{
		private FlowermanAI flowermanAI;

		private GameObject baseHerbertObject;

		private bool isAttacking;

		private bool isDead;

		private void Start()
		{
			flowermanAI = ((Component)this).GetComponent<FlowermanAI>();
			if ((Object)(object)flowermanAI == (Object)null)
			{
				Logger.LogError("FlowermanAI component not found!");
				return;
			}
			HideFlowermanModel();
			CreateHerbertModelHDRP();
			UpdateScanNodeData();
		}

		private void CreateHerbertModelHDRP()
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			GameObject asset = HerbertBracken.Core.Assets.GetAsset<GameObject>("Herbert The Pervert V2");
			if ((Object)(object)asset == (Object)null)
			{
				Logger.LogError("Herbert asset not found in the bundle!");
				return;
			}
			baseHerbertObject = Object.Instantiate<GameObject>(asset, ((Component)this).transform);
			if ((Object)(object)baseHerbertObject != (Object)null)
			{
				baseHerbertObject.transform.localPosition = new Vector3(0f, 0f, 2f);
				baseHerbertObject.transform.localRotation = Quaternion.identity;
				baseHerbertObject.transform.localScale = new Vector3(2f, 2f, 2f);
				Logger.LogInfo("Herbert model instantiated and attached.");
				Material asset2 = HerbertBracken.Core.Assets.GetAsset<Material>("herb");
				Material asset3 = HerbertBracken.Core.Assets.GetAsset<Material>("eye");
				if ((Object)(object)asset2 == (Object)null || (Object)(object)asset3 == (Object)null)
				{
					Logger.LogError("Failed to load Herbert's materials from the asset bundle!");
					return;
				}
				Shader val = Shader.Find("Unlit/Texture");
				if ((Object)(object)val == (Object)null)
				{
					Logger.LogError("Lit/Texture shader not found!");
					return;
				}
				baseHerbertObject.layer = LayerMask.NameToLayer("Enemies");
				SkinnedMeshRenderer[] componentsInChildren = baseHerbertObject.GetComponentsInChildren<SkinnedMeshRenderer>();
				SkinnedMeshRenderer[] array = componentsInChildren;
				foreach (SkinnedMeshRenderer val2 in array)
				{
					if ((Object)(object)val2.sharedMesh == (Object)null)
					{
						Logger.LogError("SkinnedMeshRenderer on " + ((Object)val2).name + " has no mesh assigned!");
						continue;
					}
					((Renderer)val2).enabled = true;
					asset3.shader = val;
					asset2.shader = val;
					if (((Object)val2).name.Contains("Head"))
					{
						((Renderer)val2).materials = (Material[])(object)new Material[2] { asset2, asset3 };
						Logger.LogInfo("Assigned 'herb' and 'eye' materials to " + ((Object)val2).name + ".");
					}
					else
					{
						((Renderer)val2).material = asset2;
						Logger.LogInfo("Assigned body material to " + ((Object)val2).name + ".");
					}
				}
			}
			else
			{
				Logger.LogError("Failed to instantiate Herbert model!");
			}
		}

		private void HideFlowermanModel()
		{
			Renderer[] componentsInChildren = ((Component)flowermanAI).GetComponentsInChildren<Renderer>();
			Renderer[] array = componentsInChildren;
			foreach (Renderer val in array)
			{
				val.enabled = false;
			}
			Logger.LogInfo("Flowerman model hidden.");
		}

		private void UpdateScanNodeData()
		{
			ScanNodeProperties componentInChildren = ((Component)flowermanAI).GetComponentInChildren<ScanNodeProperties>();
			if ((Object)(object)componentInChildren != (Object)null)
			{
				componentInChildren.headerText = "Herbert The Pervert";
				((Component)componentInChildren).gameObject.SetActive(true);
				Logger.LogInfo("Updated scan node data to show Herbert's name.");
			}
			else
			{
				Logger.LogError("Failed to find ScanNodeProperties on Flowerman.");
			}
		}

		private void Update()
		{
			if (((EnemyAI)flowermanAI).movingTowardsTargetPlayer && !isAttacking)
			{
				EnterAttackState();
			}
			else if (!((EnemyAI)flowermanAI).movingTowardsTargetPlayer && isAttacking)
			{
				ExitAttackState();
			}
			if (((EnemyAI)flowermanAI).isEnemyDead && !isDead)
			{
				KillHerbert();
			}
		}

		private void EnterAttackState()
		{
			Logger.LogInfo("Herbert is attacking!");
			if ((Object)(object)baseHerbertObject != (Object)null)
			{
				isAttacking = true;
				baseHerbertObject.SetActive(true);
			}
			else
			{
				Logger.LogError("baseHerbertObject is null! Cannot enter attack state.");
			}
		}

		private void ExitAttackState()
		{
			Logger.LogInfo("Herbert stopped attacking.");
			if ((Object)(object)baseHerbertObject != (Object)null)
			{
				isAttacking = false;
				baseHerbertObject.SetActive(true);
			}
			else
			{
				Logger.LogError("baseHerbertObject is null! Cannot exit attack state.");
			}
		}

		private void KillHerbert()
		{
			Logger.LogInfo("Herbert is killed!");
			if ((Object)(object)baseHerbertObject != (Object)null)
			{
				isDead = true;
				baseHerbertObject.SetActive(true);
			}
			else
			{
				Logger.LogError("baseHerbertObject is null! Cannot kill Herbert.");
			}
		}
	}
}
namespace HerbertBracken.Patches
{
	[HarmonyPatch]
	internal class EnemyPatches
	{
		[HarmonyPatch(typeof(FlowermanAI), "Start")]
		[HarmonyPostfix]
		public static void CreateHerbertModel(FlowermanAI __instance)
		{
			((Component)__instance).gameObject.AddComponent<HerbertController>();
		}
	}
	[HarmonyPatch]
	internal class RoundManagementPatches
	{
		private static Transform CardObject { get; set; }

		[HarmonyPatch(typeof(RoundManager), "GenerateNewLevelClientRpc")]
		[HarmonyPostfix]
		public static void GameStart(RoundManager __instance, int randomSeed, int levelID)
		{
		}

		[HarmonyPatch(typeof(StartOfRound), "EndOfGame")]
		[HarmonyPostfix]
		public static void GameEnd(StartOfRound __instance)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			if ((Object)CardObject != (Object)null)
			{
				Object.Destroy((Object)((Component)CardObject).gameObject);
			}
		}
	}
	[HarmonyPatch]
	internal class TerminalPatches
	{
		[HarmonyPatch(typeof(Terminal), "Start")]
		[HarmonyPostfix]
		public static void EditTerminal(Terminal __instance)
		{
			int index = __instance.enemyFiles.FindIndex((TerminalNode e) => ((Object)e).name == "BrackenFile");
			int num = __instance.terminalNodes.allKeywords.ToList().FindIndex((TerminalKeyword e) => ((Object)e).name == "Bracken");
			__instance.enemyFiles[index].creatureName = "Herbert The Pervert";
			__instance.enemyFiles[index].displayText = "Hey Chris...\n Want a lolipop?\n";
			__instance.terminalNodes.allKeywords[num].word = "Herbert";
		}
	}
	public class CreateSphere : MonoBehaviour
	{
		private void Start()
		{
			//IL_001d: 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_0044: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)0);
			val.transform.position = new Vector3(0f, 0f, 0f);
			Renderer component = val.GetComponent<Renderer>();
			component.material = new Material(Shader.Find("Standard"));
			component.material.color = Color.red;
		}
	}
}
namespace HerbertBracken.Core
{
	public static class Assets
	{
		public static AssetBundle AssetBundle { get; private set; }

		private static Dictionary<string, Object> AssetList { get; set; }

		private static string AssemblyName => Assembly.GetExecutingAssembly().FullName.Split(new char[1] { ',' })[0];

		public static void PopulateAssets()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Expected O, but got Unknown
			string[] manifestResourceNames = Assembly.GetExecutingAssembly().GetManifestResourceNames();
			if ((Object)AssetBundle != (Object)null)
			{
				Logger.LogWarning("Attempted to load the asset bundle but the bundle was not null!");
				return;
			}
			string text = AssemblyName + ".newherb";
			Logger.LogInfo("Trying to load asset bundle with name: " + text);
			using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(text))
			{
				if (stream == null)
				{
					Logger.LogError("Failed to load asset bundle: " + text);
					return;
				}
				AssetBundle = AssetBundle.LoadFromStream(stream);
			}
			if ((Object)AssetBundle == (Object)null)
			{
				Logger.LogError("Asset bundle at " + AssemblyName + "herbert failed to load!");
			}
			AssetList = new Dictionary<string, Object>();
			Object[] array = AssetBundle.LoadAllAssets();
			Logger.LogInfo($"Loaded {array.Length} assets from the bundle.");
			Object[] array2 = array;
			foreach (Object val in array2)
			{
				Logger.LogInfo("Loaded asset: " + val.name);
				AssetList.Add(val.name, val);
			}
		}

		public static T GetAsset<T>(string name) where T : Object
		{
			if (!AssetList.TryGetValue(name, out var value))
			{
				Logger.LogError("Attempted to load asset of name " + name + " but no asset of that name exists!");
				return default(T);
			}
			Object[] array = AssetBundle.LoadAllAssets();
			Object[] array2 = array;
			foreach (Object val in array2)
			{
				Logger.LogInfo($"Loaded asset: {val.name} of type {((object)val).GetType()}");
			}
			T val2 = (T)(object)((value is T) ? value : null);
			if (val2 != null)
			{
				return val2;
			}
			Logger.LogError($"Asset of name {name} does not match type {typeof(T)}!");
			return default(T);
		}
	}
	internal static class ConfigManager
	{
		public static ConfigEntry<bool> UseVoicelines { get; private set; }

		public static ConfigEntry<bool> UseMusic { get; private set; }

		public static ConfigEntry<bool> UseDeathSound { get; private set; }

		private static ConfigFile Config => HerbertBrackenBase.ModConfig;

		public static void InitializeConfig()
		{
			UseVoicelines = Config.Bind<bool>("Sound", "Use Herbert Voicelines", true, "Controls whether or not to replace the bracken's kill sound with Herbert voicelines");
			UseMusic = Config.Bind<bool>("Sound", "Use FG Music", true, "Controls whether or not to replace the bracken's agressive sound with the Family guy Theme");
			UseDeathSound = Config.Bind<bool>("Sound", "Use Death Sound", true, "Controls whether or not to play a sound on the bracken's death");
		}
	}
	internal static class Logger
	{
		public static void LogInfo(object message)
		{
			HerbertBrackenBase.LogSource.LogInfo(message);
		}

		public static void LogWarning(object message)
		{
			HerbertBrackenBase.LogSource.LogWarning(message);
		}

		public static void LogError(object message)
		{
			HerbertBrackenBase.LogSource.LogError(message);
		}
	}
	[BepInPlugin("Spruce.HerbertBracken", "Herbert Braken", "0.1.0")]
	public class HerbertBrackenBase : BaseUnityPlugin
	{
		public static GameObject Visuals;

		private static HerbertBrackenBase _instance;

		private readonly Harmony Harmony = new Harmony("Spruce.HerbertBracken");

		internal static HerbertBrackenBase Instance
		{
			get
			{
				return _instance;
			}
			set
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Expected O, but got Unknown
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				//IL_002b: Expected O, but got Unknown
				if ((Object)_instance == (Object)null)
				{
					_instance = value;
				}
				else
				{
					Object.Destroy((Object)value);
				}
			}
		}

		public static ManualLogSource LogSource => ((BaseUnityPlugin)Instance).Logger;

		public static ConfigFile ModConfig => ((BaseUnityPlugin)Instance).Config;

		private void Awake()
		{
			Instance = this;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Initializing config...");
			ConfigManager.InitializeConfig();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loading asset bundle...");
			Assets.PopulateAssets();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Heya Chris!");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Do you want a taste of my lolipop?");
			Harmony.PatchAll(typeof(HerbertBrackenBase));
			Harmony.PatchAll(typeof(EnemyPatches));
			Harmony.PatchAll(typeof(TerminalPatches));
			Harmony.PatchAll(typeof(RoundManagementPatches));
		}
	}
	internal static class PluginInfo
	{
		public const string GUID = "Spruce.HerbertBracken";

		public const string NAME = "Herbert Bracken";

		public const string VERSION = "1";

		public const string ASSET_BUNDLE_NAME = "newherb";
	}
}
namespace ModelReplacement
{
	[BepInPlugin("Spruce.HerbertBracken", "Herbert Braken", "0.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public static ConfigFile config;

		private readonly Harmony Harmony = new Harmony("Spruce.HerbertBracken");

		public static ConfigEntry<bool> enableModelForAllSuits { get; private set; }

		public static ConfigEntry<bool> enableModelAsDefault { get; private set; }

		public static ConfigEntry<string> suitNamesToEnableModel { get; private set; }

		private static void InitConfig()
		{
			enableModelForAllSuits = config.Bind<bool>("Suits to Replace Settings", "Enable Model for all Suits", false, "Enable to model replace every suit. Set to false to specify suits");
			enableModelAsDefault = config.Bind<bool>("Suits to Replace Settings", "Enable Model as default", false, "Enable to model replace every suit that hasn't been otherwise registered.");
			suitNamesToEnableModel = config.Bind<string>("Suits to Replace Settings", "Suits to enable Model for", "Default,Orange suit", "Enter a comma separated list of suit names.(Additionally, [Green suit,Pajama suit,Hazard suit])");
		}
	}
}