Decompiled source of ClaySurgeonOverhaul v1.2.7

ClaySurgeonMod.dll

Decompiled 4 hours ago
using System;
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 BarberFixes;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ClaySurgeonMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A different take on the Barber")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+a3fddae5fa6bc101f3e16d5992c63ced15ec74db")]
[assembly: AssemblyProduct("ClaySurgeonMod")]
[assembly: AssemblyTitle("ClaySurgeonMod")]
[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 ClaySurgeonMod
{
	[BepInPlugin("dopadream.lethalcompany.ClaySurgeonMod", "Clay Surgeon", "1.2.6")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch]
		private class ClaySurgeonPatches
		{
			[HarmonyPatch(typeof(RoundManager), "RefreshEnemiesList")]
			[HarmonyPostfix]
			private static void RoundManagerPostRefresh(RoundManager __instance, ref int ___enemyRushIndex)
			{
				//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
				DateTime dateTime = new DateTime(DateTime.Now.Year, 10, 31);
				bool num = DateTime.Today == dateTime;
				Random random = new Random(StartOfRound.Instance.randomMapSeed + 5781);
				if (((!num || random.Next(0, 210) >= 3) && random.Next(0, 1000) >= 15 && !configKlayWorld.Value) || ___enemyRushIndex != -1 || !configInfestations.Value)
				{
					return;
				}
				for (int i = 0; i < __instance.currentLevel.Enemies.Count; i++)
				{
					if (__instance.currentLevel.Enemies[i].enemyType.enemyName == "Clay Surgeon" && __instance.currentLevel.Enemies[i].enemyType.MaxCount > 1)
					{
						Logger.LogDebug((object)"Clay infestation started!");
						((Component)__instance.indoorFog).gameObject.SetActive(random.Next(0, 100) < 20);
						___enemyRushIndex = i;
						__instance.currentMaxInsidePower = __instance.currentLevel.Enemies[i].enemyType.PowerLevel * (float)__instance.currentLevel.Enemies[i].enemyType.MaxCount;
						break;
					}
				}
			}

			[HarmonyPatch(typeof(QuickMenuManager), "Start")]
			[HarmonyPostfix]
			private static void QuickMenuManagerPostStart(QuickMenuManager __instance)
			{
				allEnemiesList.Clear();
				List<SpawnableEnemyWithRarity>[] array = new List<SpawnableEnemyWithRarity>[1] { __instance.testAllEnemiesLevel.Enemies };
				if (!configSpawnOverride.Value)
				{
					return;
				}
				List<SpawnableEnemyWithRarity>[] array2 = array;
				for (int i = 0; i < array2.Length; i++)
				{
					foreach (SpawnableEnemyWithRarity item in array2[i])
					{
						if (allEnemiesList.ContainsKey(((Object)item.enemyType).name))
						{
							if ((Object)(object)allEnemiesList[((Object)item.enemyType).name] == (Object)(object)item.enemyType)
							{
								Logger.LogWarning((object)("allEnemiesList: Tried to cache reference to \"" + ((Object)item.enemyType).name + "\" more than once"));
							}
							else
							{
								Logger.LogWarning((object)("allEnemiesList: Tried to cache two different enemies by same name (" + ((Object)item.enemyType).name + ")"));
							}
						}
						else if (item.enemyType.enemyName == "Clay Surgeon")
						{
							item.enemyType.spawnInGroupsOf = configSpawnInGroupsOf.Value;
							item.enemyType.MaxCount = configMaxCount.Value;
							item.enemyType.PowerLevel = configPowerLevel.Value;
							item.enemyType.probabilityCurve = dummyType.probabilityCurve;
							item.enemyType.numberSpawnedFalloff = dummyType.numberSpawnedFalloff;
							item.enemyType.useNumberSpawnedFalloff = true;
							Logger.LogDebug((object)"Barber spawn settings overriden!");
							return;
						}
					}
				}
			}

			[HarmonyPatch(typeof(ClaySurgeonAI), "Awake")]
			[HarmonyPostfix]
			private static void ClaySurgeonAIPostWake(ClaySurgeonAI __instance)
			{
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				Object.Destroy((Object)(object)((Component)((EnemyAI)__instance).creatureAnimator).gameObject);
				Transform transform = Object.Instantiate<GameObject>(clayPrefab, ((Component)__instance).transform.position, ((Component)__instance).transform.rotation, ((Component)__instance).transform.Find("MeshContainer")).transform;
				((EnemyAI)__instance).creatureAnimator = ((Component)transform).GetComponentInChildren<Animator>();
				__instance.skin = ((Component)transform).GetComponentInChildren<SkinnedMeshRenderer>();
				((Component)__instance).gameObject.GetComponentInChildren<ScanNodeProperties>().headerText = "Clay Surgeon";
				((EnemyAI)__instance).skinnedMeshRenderers = ((Component)transform).gameObject.GetComponentsInChildren<SkinnedMeshRenderer>();
				((EnemyAI)__instance).meshRenderers = ((Component)transform).gameObject.GetComponentsInChildren<MeshRenderer>();
				((Component)transform).GetComponentInChildren<EnemyAnimationEvent>().mainScript = ((Component)__instance).gameObject.GetComponentInChildren<EnemyAnimationEvent>().mainScript;
			}

			[HarmonyPatch(typeof(ClaySurgeonAI), "Start")]
			[HarmonyPostfix]
			private static void ClaySurgeonAIPostStart(ClaySurgeonAI __instance)
			{
				Material[] array = (Material[])(object)new Material[((Renderer)__instance.skin).sharedMaterials.Length];
				for (int i = 0; i < array.Length; i++)
				{
					array[i] = ((Renderer)__instance.skin).materials[i];
				}
				((Renderer)__instance.skin).sharedMaterials = array;
			}

			[HarmonyPatch(typeof(ClaySurgeonAI), "Update")]
			[HarmonyPostfix]
			private static void ClaySurgeonAIPostUpdate(ClaySurgeonAI __instance)
			{
				AudioSource[] componentsInChildren = ((Component)__instance).gameObject.GetComponentsInChildren<AudioSource>();
				foreach (AudioSource val in componentsInChildren)
				{
					if (((Object)val.clip).name == "ClaySurgeonAmbience")
					{
						val.volume = configAmbience.Value;
						break;
					}
				}
			}

			[HarmonyPatch(typeof(ClaySurgeonAI), "SetVisibility")]
			[HarmonyPostfix]
			private static void ClaySurgeonAIPostSetVis(ClaySurgeonAI __instance)
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: 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_002e: Unknown result type (might be due to invalid IL or missing references)
				float num = Vector3.Distance(((Component)StartOfRound.Instance.audioListener).transform.position, ((Component)__instance).transform.position + Vector3.up * 0.7f);
				__instance.minDistance = configMinVisibility.Value;
				__instance.maxDistance = configMaxVisibility.Value;
				Material[] sharedMaterials = ((Renderer)__instance.skin).sharedMaterials;
				Material[] array = sharedMaterials;
				for (int i = 0; i < array.Length; i++)
				{
					array[i].SetFloat("_AlphaCutoff", (num - __instance.minDistance) / (__instance.maxDistance - __instance.minDistance));
				}
				((Renderer)__instance.skin).material.SetFloat("_IridescenceMask", configIridescence.Value);
				((Renderer)__instance.skin).sharedMaterials = sharedMaterials;
			}

			[HarmonyPatch(typeof(DanceClock), "Tick")]
			[HarmonyPrefix]
			private static bool DanceClockPreTick()
			{
				if (configCurve.Value)
				{
					float currentInterval = Mathf.Clamp(curveDummyType.probabilityCurve.Evaluate((float)TimeOfDay.Instance.hour / (float)TimeOfDay.Instance.numberOfHours), 1.25f, 2.75f);
					ClaySurgeonAI[] array = Object.FindObjectsOfType<ClaySurgeonAI>();
					for (int i = 0; i < array.Length; i++)
					{
						array[i].currentInterval = currentInterval;
					}
					return false;
				}
				return true;
			}

			[HarmonyPatch(typeof(Terminal), "Awake")]
			[HarmonyPostfix]
			private static void TerminalPostWake(Terminal __instance)
			{
				TerminalKeyword[] allKeywords = __instance.terminalNodes.allKeywords;
				foreach (TerminalNode enemyFile in __instance.enemyFiles)
				{
					if (enemyFile.creatureFileID != 24)
					{
						continue;
					}
					enemyFile.displayVideo = clayNode.displayVideo;
					enemyFile.displayText = clayNode.displayText;
					enemyFile.creatureName = clayNode.creatureName;
					TerminalKeyword[] array = allKeywords;
					foreach (TerminalKeyword val in array)
					{
						if (val.word == "barber")
						{
							val.word = "clay surgeon";
							return;
						}
					}
					Logger.LogDebug((object)"Barber bestiary entry replaced!");
					break;
				}
			}
		}

		private const string PLUGIN_GUID = "dopadream.lethalcompany.ClaySurgeonMod";

		private const string PLUGIN_NAME = "Clay Surgeon";

		private const string PLUGIN_VERSION = "1.2.6";

		private const string LETHAL_CONFIG = "ainavt.lc.lethalconfig";

		internal static ManualLogSource Logger;

		internal static GameObject clayPrefab;

		internal static TerminalNode clayNode;

		internal static EnemyType dummyType;

		internal static EnemyType curveDummyType;

		internal static Dictionary<string, EnemyType> allEnemiesList = new Dictionary<string, EnemyType>();

		internal static ConfigEntry<bool> configSpawnOverride;

		internal static ConfigEntry<bool> configInfestations;

		internal static ConfigEntry<bool> configCurve;

		internal static ConfigEntry<bool> configKlayWorld;

		internal static ConfigEntry<int> configMaxCount;

		internal static ConfigEntry<int> configPowerLevel;

		internal static ConfigEntry<int> configSpawnInGroupsOf;

		internal static ConfigEntry<float> configAmbience;

		internal static ConfigEntry<float> configIridescence;

		internal static ConfigEntry<float> configMinVisibility;

		internal static ConfigEntry<float> configMaxVisibility;

		protected const string anchorPath = "MeshContainer";

		protected const string animPath = "MeshContainer/AnimContainer";

		internal void initLethalConfig()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Expected O, but got Unknown
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Expected O, but got Unknown
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Expected O, but got Unknown
			LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(configSpawnOverride, false));
			LethalConfigManager.AddConfigItem((BaseConfigItem)new IntInputFieldConfigItem(configMaxCount, false));
			LethalConfigManager.AddConfigItem((BaseConfigItem)new IntInputFieldConfigItem(configSpawnInGroupsOf, false));
			LethalConfigManager.AddConfigItem((BaseConfigItem)new IntInputFieldConfigItem(configPowerLevel, false));
			LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatSliderConfigItem(configMinVisibility, false));
			LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatSliderConfigItem(configMaxVisibility, false));
			LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(configInfestations, false));
			LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(configCurve, false));
			LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatSliderConfigItem(configAmbience, false));
			LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatSliderConfigItem(configIridescence, false));
			LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(configKlayWorld, false));
			LethalConfigManager.SkipAutoGen();
		}

		private void Awake()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Expected O, but got Unknown
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Expected O, but got Unknown
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Expected O, but got Unknown
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Expected O, but got Unknown
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Expected O, but got Unknown
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Expected O, but got Unknown
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Expected O, but got Unknown
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Expected O, but got Unknown
			//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			configSpawnOverride = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Override Spawn Settings", true, new ConfigDescription("Overrides spawning logic of Clay Surgeons (Barbers). With this enabled, they will spawn in pairs and be more common. Disable if you want to customize their spawning yourself through plugins such as LethalQuantities.", (AcceptableValueBase)null, Array.Empty<object>()));
			configMaxCount = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Max Spawn Count", 6, new ConfigDescription("Defines the max spawn count of Clay Surgeons. Override Spawn Settings must be turned on.", (AcceptableValueBase)null, Array.Empty<object>()));
			configSpawnInGroupsOf = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Spawn Group Count", 2, new ConfigDescription("Defines how many Clay Surgeons spawn in one vent. Override Spawn Settings must be turned on.", (AcceptableValueBase)null, Array.Empty<object>()));
			configPowerLevel = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Power Level", 2, new ConfigDescription("Defines the power level of Clay Surgeons. Override Spawn Settings must be turned on.", (AcceptableValueBase)null, Array.Empty<object>()));
			configMinVisibility = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Minimum Visibility Distance", 5f, new ConfigDescription("Controls the distance at which the Clay Surgeon is fully visible.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 15f), Array.Empty<object>()));
			configMaxVisibility = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Maximum Visibility Distance", 15f, new ConfigDescription("Controls the distance at which the Clay Surgeon is fully invisible.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(7f, 15f), Array.Empty<object>()));
			configInfestations = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Clay Infestations", true, new ConfigDescription("Adds a chance for Hoarding bug/Nutcracker infestations to be Clay Surgeon Infestations instead.", (AcceptableValueBase)null, Array.Empty<object>()));
			configCurve = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Curved Acceleration", true, new ConfigDescription("Makes the Clay Surgeon accelerate at a curve rather than a flat rate per hour.", (AcceptableValueBase)null, Array.Empty<object>()));
			configAmbience = ((BaseUnityPlugin)this).Config.Bind<float>("Aesthetics", "Proximity Ambience Volume", 0.35f, new ConfigDescription("Controls the volume of the Clay Surgeon's proximity ambience.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			configIridescence = ((BaseUnityPlugin)this).Config.Bind<float>("Aesthetics", "Iridescence", 0.25f, new ConfigDescription("Controls the iridescence of the Clay Surgeon's clay material.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			configKlayWorld = ((BaseUnityPlugin)this).Config.Bind<bool>("Fun", "Klay World", false, new ConfigDescription("Guarantees clay infestations when possible. Clay infestations must be turned on!", (AcceptableValueBase)null, Array.Empty<object>()));
			if (Chainloader.PluginInfos.ContainsKey("ainavt.lc.lethalconfig"))
			{
				initLethalConfig();
			}
			try
			{
				AssetBundle obj = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "claysurgeonmod"));
				Object obj2 = obj.LoadAsset("ClaySurgeonNew", typeof(GameObject));
				clayPrefab = (GameObject)(object)((obj2 is GameObject) ? obj2 : null);
				Object obj3 = obj.LoadAsset("ClaySurgeonFile", typeof(TerminalNode));
				clayNode = (TerminalNode)(object)((obj3 is TerminalNode) ? obj3 : null);
				Object obj4 = obj.LoadAsset("DummyEnemyType", typeof(EnemyType));
				dummyType = (EnemyType)(object)((obj4 is EnemyType) ? obj4 : null);
				Object obj5 = obj.LoadAsset("CurveDummyType", typeof(EnemyType));
				curveDummyType = (EnemyType)(object)((obj5 is EnemyType) ? obj5 : null);
			}
			catch
			{
				Logger.LogError((object)"Encountered some error loading asset bundle. Did you install the plugin correctly?");
				return;
			}
			new Harmony("dopadream.lethalcompany.ClaySurgeonMod").PatchAll();
			Logger.LogInfo((object)"Clay Surgeon v1.2.6 loaded");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "ClaySurgeonMod";

		public const string PLUGIN_NAME = "ClaySurgeonMod";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}