Decompiled source of hOShOS v1.0.0

DantorsMentalHospitalDunGen/MentalHospital.dll

Decompiled 10 months 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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using DunGen;
using DunGen.Graph;
using HarmonyLib;
using LethalLevelLoader;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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("MentalHospital")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MentalHospital")]
[assembly: AssemblyTitle("MentalHospital")]
[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 MentalHospital
{
	[BepInPlugin("MentalHospital", "MentalHospital", "1.0.0")]
	public class MentalHospitalDunGen : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(RoundManager))]
		internal class RoundManagerPatch
		{
			[HarmonyPatch("SpawnScrapInLevel")]
			[HarmonyPrefix]
			private static bool SetItemSpawnPoints(ref RuntimeDungeon ___dungeonGenerator)
			{
				if (((Object)___dungeonGenerator.Generator.DungeonFlow).name != "HospitalFlow")
				{
					return true;
				}
				StartOfRound instance = StartOfRound.Instance;
				if ((Object)(object)instance == (Object)null)
				{
					Instance.mls.LogError((object)"Failed to get start of round instance. Scrap spawns may not work correctly.");
					return true;
				}
				Item val = instance.allItemsList.itemsList.Find((Item x) => x.itemName == "Bottles");
				if ((Object)(object)val == (Object)null)
				{
					Instance.mls.LogError((object)"Failed to find bottle bin item for reference snatching; scrap spawn may be significantly lower than expected.");
					return true;
				}
				Item val2 = instance.allItemsList.itemsList.Find((Item x) => x.itemName == "Golden cup");
				int num = 0;
				int num2 = 0;
				int num3 = 0;
				ItemGroup spawnableItems = val.spawnPositionTypes.Find((ItemGroup x) => ((Object)x).name == "GeneralItemClass");
				ItemGroup val3 = val.spawnPositionTypes.Find((ItemGroup x) => ((Object)x).name == "TabletopItems");
				ItemGroup spawnableItems2 = (ItemGroup)(((Object)(object)val2 == (Object)null) ? ((object)val3) : ((object)val2.spawnPositionTypes.Find((ItemGroup x) => ((Object)x).name == "SmallItems")));
				RandomScrapSpawn[] array = Object.FindObjectsOfType<RandomScrapSpawn>();
				RandomScrapSpawn[] array2 = array;
				foreach (RandomScrapSpawn val4 in array2)
				{
					switch (((Object)val4.spawnableItems).name)
					{
					case "GeneralItemClassDUMMY":
						val4.spawnableItems = spawnableItems;
						num++;
						break;
					case "TabletopItemsDUMMY":
						val4.spawnableItems = val3;
						num2++;
						break;
					case "SmallItemsDUMMY":
						val4.spawnableItems = spawnableItems2;
						num3++;
						break;
					}
				}
				Instance.mls.LogInfo((object)$"Totals for scrap replacement: General: {num}, Tabletop: {num2}, Small: {num3}");
				if (num + num2 + num3 < 10)
				{
					Instance.mls.LogWarning((object)"Unusually low scrap spawn count; scrap may be sparse.");
				}
				return true;
			}
		}

		private const string modGUID = "DantorMentalHospital";

		private const string modName = "Dantor's Mental Hospital";

		private const string modVersion = "1.0.0";

		private static MentalHospitalDunGen Instance;

		private readonly Harmony harmony = new Harmony("Dantor's Mental Hospital");

		private ConfigEntry<int> configSCPRarity;

		private ConfigEntry<string> configMoons;

		private ConfigEntry<bool> configGuaranteedSCP;

		private ConfigEntry<int> configLengthOverride;

		internal ManualLogSource mls;

		public static AssetBundle Assets;

		private void Awake()
		{
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Expected O, but got Unknown
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Expected O, but got Unknown
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Expected O, but got Unknown
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Expected O, but got Unknown
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Expected O, but got Unknown
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Expected O, but got Unknown
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Expected O, but got Unknown
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Expected O, but got Unknown
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0367: Expected O, but got Unknown
			//IL_0433: Unknown result type (might be due to invalid IL or missing references)
			//IL_043d: Expected O, but got Unknown
			//IL_04c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cd: Expected O, but got Unknown
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods;
				foreach (MethodInfo methodInfo in array2)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
			mls = Logger.CreateLogSource("MentalHospital");
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			Assets = AssetBundle.LoadFromFile(Path.Combine(directoryName, "hospitalbundle"));
			if ((Object)(object)Assets == (Object)null)
			{
				mls.LogError((object)"Failed to load DantorsMentalHospital assets.");
				return;
			}
			DungeonFlow val = Assets.LoadAsset<DungeonFlow>("Assets/Abandoned_Psychiatric_Hospitals/DunGen Data/HospitalFlow.asset");
			if ((Object)(object)val == (Object)null)
			{
				mls.LogError((object)"Failed to load DantorsMentalHospital Dungeon Flow.");
				return;
			}
			configSCPRarity = ((BaseUnityPlugin)this).Config.Bind<int>("General", "HospitalRarity", 100, new ConfigDescription("How rare it is for the mental hospital to be chosen. Higher values increases the chance of spawning the mental hospital. Vanillas' main dungeons use a value of 300. Google Weighted Random if you don't know how it works, as that's how Lethal Company rarities function.", (AcceptableValueBase)null, Array.Empty<object>()));
			configMoons = ((BaseUnityPlugin)this).Config.Bind<string>("General", "HospitalMoonsList", "vanilla", new ConfigDescription("The moon(s) that the hospital can spawn on, in the form of a comma separated list of selectable level names and optionally a weight value by using an '@' and weight value after it (e.g. \"Titan@300,Dine,Rend@10,Secret Labs@9999\")\nThe name matching is lenient and should pick it up if you use the terminal name or internal mod name. If no rarity is specified, the HospitalRarity parameter is used.\nThe following strings: \"all\", \"vanilla\", \"modded\", \"paid\", \"free\" are dynamic presets which add the dungeon to that specified group (string must only contain one of these, or a manual moon name list).\n", (AcceptableValueBase)null, Array.Empty<object>()));
			configGuaranteedSCP = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "HospitalGuaranteed", false, new ConfigDescription("\nIt should work but if it doesn't use a weight of something like '99999'", (AcceptableValueBase)null, Array.Empty<object>()));
			ExtendedDungeonFlow val2 = ScriptableObject.CreateInstance<ExtendedDungeonFlow>();
			val2.contentSourceName = "Dantors Mental Hospital";
			val2.dungeonFlow = val;
			val2.dungeonDefaultRarity = 0;
			int num = (configGuaranteedSCP.Value ? 99999 : configSCPRarity.Value);
			switch (configMoons.Value.ToLower())
			{
			case "all":
				val2.dynamicLevelTagsList.Add(new StringWithRarity("Vanilla", num));
				val2.dynamicLevelTagsList.Add(new StringWithRarity("Custom", num));
				mls.LogInfo((object)"Registered DantorsMentalHospital dungeon for all moons.");
				break;
			case "vanilla":
				val2.manualContentSourceNameReferenceList.Add(new StringWithRarity("Lethal Company", num));
				mls.LogInfo((object)"Registered DantorsMentalHospital dungeon for all vanilla moons.");
				break;
			case "modded":
				val2.manualContentSourceNameReferenceList.Add(new StringWithRarity("Custom", num));
				mls.LogInfo((object)"Registered DantorsMentalHospital dungeon for all modded moons.");
				break;
			case "paid":
				val2.dynamicRoutePricesList.Add(new Vector2WithRarity(new Vector2(1f, 9999f), num));
				mls.LogInfo((object)"Registered DantorsMentalHospital dungeon for all paid moons.");
				break;
			case "free":
				val2.dynamicRoutePricesList.Add(new Vector2WithRarity(new Vector2(0f, 0f), num));
				mls.LogInfo((object)"Registered DantorsMentalHospital dungeon for all free moons.");
				break;
			default:
			{
				mls.LogInfo((object)"Registering DantorsMentalHospital dungeon for predefined moon list.");
				string[] array3 = configMoons.Value.Split(',', StringSplitOptions.RemoveEmptyEntries);
				List<StringWithRarity> list = new List<StringWithRarity>();
				for (int k = 0; k < array3.Length; k++)
				{
					string[] array4 = array3[k].Split('@', StringSplitOptions.RemoveEmptyEntries);
					int num2 = array4.Length;
					int result;
					if (num2 > 2)
					{
						mls.LogError((object)("Invalid setup for moon rarity config: " + array3[k] + ". Skipping."));
					}
					else if (num2 == 1)
					{
						mls.LogInfo((object)$"Registering DantorsMentalHospital dungeon for moon {array3[k]} at default rarity {num}");
						list.Add(new StringWithRarity(array3[k], num));
					}
					else if (!int.TryParse(array4[1], out result))
					{
						mls.LogError((object)("Failed to parse rarity value for moon " + array4[0] + ": " + array4[1] + ". Skipping."));
					}
					else
					{
						mls.LogInfo((object)$"Registering DantorsMentalHospital dungeon for moon {array3[k]} at rarity {result}");
						list.Add(new StringWithRarity(array4[0], result));
					}
				}
				val2.manualPlanetNameReferenceList = list;
				break;
			}
			}
			val2.dungeonSizeMin = 0.5f;
			val2.dungeonSizeMax = 0.65f;
			val2.dungeonSizeLerpPercentage = 0.8f;
			val2.enableDynamicDungeonSizeRestriction = true;
			PatchedContent.RegisterExtendedDungeonFlow(val2);
			harmony.PatchAll(typeof(MentalHospitalDunGen));
			harmony.PatchAll(typeof(RoundManagerPatch));
			mls.LogInfo((object)"DantorsMentalHospital DunGen for Lethal Company [Version 1.0.0] successfully loaded.");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin MentalHospital is loaded!");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "MentalHospital";

		public const string PLUGIN_NAME = "MentalHospital";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}