Decompiled source of UndergroundOnly v0.0.2

BepInEx/plugins/UndergroundOnly.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("UndergroundOnly")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UndergroundOnly")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("00285deb-c447-4346-91e7-2f37a37ab8a9")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace UndergroundOnly
{
	internal class UndergroundConfig
	{
		public static ConfigEntry<bool> Enabled;

		public static ConfigEntry<string> AllowedPortalIDsRaw;

		public static ConfigEntry<int> TreehouseGrowState;

		public static HashSet<PortalID> AllowedPortals { get; private set; }

		public static void Bind(ConfigFile config)
		{
			Enabled = config.Bind<bool>("General", "Enabled", true, (ConfigDescription)null);
			AllowedPortalIDsRaw = config.Bind<string>("General", "AllowedPortalIDs", "CUSTOMA,CUSTOMB,CUSTOMC,CUSTOMD,BLANKLEVEL", "Comma-separated list of allowed PortalIDs.");
			TreehouseGrowState = config.Bind<int>("General", "TreehouseGrowState", 2, "Size of the Treehouse. ((-1)-20)");
			AllowedPortals = (from s in AllowedPortalIDsRaw.Value.Split(new char[1] { ',' })
				select s.Trim() into s
				where Enum.TryParse<PortalID>(s, out PortalID _)
				select s).Select((Func<string, PortalID>)((string s) => (PortalID)Enum.Parse(typeof(PortalID), s))).ToHashSet();
		}
	}
	[BepInPlugin("UndergroundOnly", "UndergroundOnly", "0.0.1")]
	public class UndergroundOnlyMod : BaseUnityPlugin
	{
		private static Harmony harmony = new Harmony("UndergroundOnly");

		public void Awake()
		{
			UndergroundConfig.Bind(((BaseUnityPlugin)this).Config);
			harmony.PatchAll();
		}
	}
}
namespace UndergroundOnly.Patches
{
	[HarmonyPatch(typeof(LevelSelectController))]
	internal class LevelSelectControllerPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		public static void StartPatched(LevelSelectController __instance)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)__instance).hasAuthority || !UndergroundConfig.Enabled.Value)
			{
				return;
			}
			LevelPortal[] portals = __instance.portals;
			foreach (LevelPortal val in portals)
			{
				if (!UndergroundConfig.AllowedPortals.Contains(val.PortalID))
				{
					NetworkServer.Destroy(((Component)val).gameObject);
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("SetupLobbyAfterWait")]
		public static void SetupLobbyAfterWaitPatched(LevelSelectController __instance)
		{
			if (((NetworkBehaviour)__instance).hasAuthority && UndergroundConfig.Enabled.Value)
			{
				__instance.CallCmdSetTreehouseGrowState(UndergroundConfig.TreehouseGrowState.Value);
			}
		}
	}
}