Decompiled source of ToggleableInteriors v1.0.0

ToggleableInteriors.dll

Decompiled 5 months ago
using System;
using System.Diagnostics;
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 Unity.Netcode;
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("ToggleableInteriors")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Toggle Mineshafts, Mansions, and Factories via Config")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ToggleableInteriors")]
[assembly: AssemblyTitle("ToggleableInteriors")]
[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 Detologist.ToggleableInteriors
{
	[BepInPlugin("Detologist.ToggleableInteriors", "Toggleable Interiors", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static Plugin Instance;

		public static ConfigEntry<bool> EnableFactory;

		public static ConfigEntry<bool> EnableMansion;

		public static ConfigEntry<bool> EnableMineshaft;

		private void Awake()
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			EnableFactory = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableFactory", true, "Allow Factory.");
			EnableMansion = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableMansion", true, "Allow Mansion.");
			EnableMineshaft = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableMineshaft", true, "Allow Mineshaft.");
			new Harmony("Detologist.ToggleableInteriors").PatchAll();
		}
	}
	[HarmonyPatch(typeof(RoundManager))]
	internal class InteriorPatch
	{
		[HarmonyPatch("StartConfiguringScene")]
		[HarmonyPrefix]
		private static void Prefix(RoundManager __instance)
		{
			((BaseUnityPlugin)Plugin.Instance).Config.Reload();
			if (!NetworkManager.Singleton.IsHost || (Object)(object)__instance.currentLevel == (Object)null || __instance.currentLevel.dungeonFlowTypes == null)
			{
				return;
			}
			IntWithRarity[] dungeonFlowTypes = __instance.currentLevel.dungeonFlowTypes;
			float num = 0f;
			int num2 = -1;
			float num3 = -1f;
			for (int i = 0; i < dungeonFlowTypes.Length; i++)
			{
				IndoorMapType val = __instance.dungeonFlowTypes[dungeonFlowTypes[i].id];
				string text = ((Object)val.dungeonFlow).name.ToLower();
				bool flag = true;
				if (text.Contains("mansion") && !Plugin.EnableMansion.Value)
				{
					flag = false;
				}
				if (text.Contains("mineshaft") && !Plugin.EnableMineshaft.Value)
				{
					flag = false;
				}
				if ((text.Contains("level1") || text.Contains("factory")) && !Plugin.EnableFactory.Value)
				{
					flag = false;
				}
				if (!flag)
				{
					dungeonFlowTypes[i].rarity = 0;
					continue;
				}
				num += (float)dungeonFlowTypes[i].rarity;
				if ((float)dungeonFlowTypes[i].rarity > num3)
				{
					num3 = dungeonFlowTypes[i].rarity;
					num2 = i;
				}
			}
			if (!(num > 0f))
			{
				return;
			}
			float num4 = 100f / num;
			int num5 = 0;
			for (int j = 0; j < dungeonFlowTypes.Length; j++)
			{
				if (dungeonFlowTypes[j].rarity > 0)
				{
					dungeonFlowTypes[j].rarity = (int)Math.Round((float)dungeonFlowTypes[j].rarity * num4);
					num5 += dungeonFlowTypes[j].rarity;
				}
			}
			if (num5 != 100 && num2 != -1)
			{
				IntWithRarity obj = dungeonFlowTypes[num2];
				obj.rarity += 100 - num5;
			}
		}
	}
}