Decompiled source of ShipDoorsBeGone v1.2.0

BepInEx/plugins/ShipDoorsBeGone/ShipDoorsBeGone.dll

Decompiled 3 days ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using AntiGrief;
using BepInEx;
using BepInEx.Configuration;
using BepInExPlugin;
using HarmonyLib;
using Steamworks;
using Steamworks.Data;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ShipDoorsBeGone")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ShipDoorsBeGone")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("cb34b092-82ab-40b7-8936-265c216e99a4")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace AntiGrief
{
	[HarmonyPatch(typeof(GameNetworkManager), "LobbyDataIsJoinable")]
	public static class GetServerData
	{
		public static bool clientCollision = ShipDoorsBeGone.collision.Value;

		public static bool clientVisibility = ShipDoorsBeGone.visibility.Value;

		public static void Postfix(Lobby lobby)
		{
			string data = ((Lobby)(ref lobby)).GetData("SDBG");
			if (string.IsNullOrEmpty(data) || data != ShipDoorsBeGone.pluginVersion)
			{
				ShipDoorsBeGone.collision.Value = true;
				ShipDoorsBeGone.visibility.Value = true;
				ShipDoorsBeGone.log("AntiGrief: Preventing use of mod");
			}
			else
			{
				ShipDoorsBeGone.log("AntiGrief: Allowing use of mod");
			}
		}
	}
	[HarmonyPatch(typeof(GameNetworkManager), "SteamMatchmaking_OnLobbyCreated")]
	public static class SetServerData
	{
		public static void Postfix(Result result, Lobby lobby)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			if ((int)result == 1)
			{
				if (ShipDoorsBeGone.clientOverride.Value)
				{
					((Lobby)(ref lobby)).SetData("SDBG", ShipDoorsBeGone.pluginVersion ?? "");
					ShipDoorsBeGone.log("AntiGrief: Allowing clients to use their settings");
				}
				else
				{
					((Lobby)(ref lobby)).SetData("SDBG", "0.0.0");
					ShipDoorsBeGone.log("AntiGrief: Preventing players from modifying values");
				}
			}
			else
			{
				ShipDoorsBeGone.log("AntiGrief: Invalid lobby");
			}
		}
	}
}
namespace Main
{
	[HarmonyPatch(typeof(StartOfRound), "Start")]
	public static class Main
	{
		public static void Postfix()
		{
			modifyCollision();
			modifyVisibility();
			ShipDoorsBeGone.collision.Value = GetServerData.clientCollision;
			ShipDoorsBeGone.visibility.Value = GetServerData.clientVisibility;
		}

		private static string getPath(Transform tran)
		{
			string text = ((Object)tran).name;
			while ((Object)(object)tran.parent != (Object)null)
			{
				tran = tran.parent;
				text = ((Object)tran).name + "/" + text;
			}
			return text;
		}

		public static void modifyCollision()
		{
			if (ShipDoorsBeGone.collision.Value)
			{
				ShipDoorsBeGone.log("Collision: Untouched");
				return;
			}
			GameObject[] array = Object.FindObjectsOfType<GameObject>();
			foreach (GameObject val in array)
			{
				string text = ((Object)val).name.ToLowerInvariant();
				if (!text.Contains("hangardoor") && !text.Contains("shipdoor"))
				{
					continue;
				}
				Collider[] componentsInChildren = val.GetComponentsInChildren<Collider>(true);
				foreach (Collider val2 in componentsInChildren)
				{
					string path = getPath(((Component)val2).transform);
					if (!path.ToLowerInvariant().Contains("hangardoorbuttonpanel") && !val2.isTrigger && (val2 is BoxCollider || val2 is MeshCollider))
					{
						val2.enabled = false;
						ShipDoorsBeGone.log("Disabled collision: " + getPath(((Component)val2).transform) + " (" + ((object)val2).GetType().Name + ")");
					}
				}
			}
		}

		public static void modifyVisibility()
		{
			if (ShipDoorsBeGone.visibility.Value)
			{
				ShipDoorsBeGone.log("Visibility: Untouched");
				return;
			}
			GameObject[] array = Object.FindObjectsOfType<GameObject>();
			foreach (GameObject val in array)
			{
				string text = ((Object)val).name.ToLowerInvariant();
				if (text.Contains("hangardoorleft") || text.Contains("hangardoorright"))
				{
					Renderer[] componentsInChildren = val.GetComponentsInChildren<Renderer>();
					foreach (Renderer val2 in componentsInChildren)
					{
						val2.enabled = false;
					}
					ShipDoorsBeGone.log("Disabled visibility: " + getPath(val.transform));
				}
			}
		}
	}
}
namespace BepInExPlugin
{
	[BepInPlugin("bubba.shipdoorsbegone", "ShipDoorsBeGone", "1.2.0")]
	public class ShipDoorsBeGone : BaseUnityPlugin
	{
		public static ShipDoorsBeGone instance;

		public static string pluginVersion = "1.2.0";

		public static ConfigEntry<bool> collision;

		public static ConfigEntry<bool> visibility;

		public static ConfigEntry<bool> clientOverride;

		public static ConfigEntry<bool> logging;

		private void Awake()
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			instance = this;
			collision = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Collision", false, "Should collision for the ship doors be enabled?");
			visibility = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Visibility", false, "Should visibility for the ship doors be enabled?");
			clientOverride = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Client Override", false, "As the host, should clients be allowed to override and use their own settings?");
			logging = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "Logging", false, "Should logging be enabled?");
			new Harmony("bubba.shipdoorsbegone").PatchAll();
			log($"Loading configs: (Collision {collision.Value}) (Visibility {visibility.Value}) (Client Override {clientOverride.Value}) (Logging {logging.Value})");
		}

		public static void log(string message)
		{
			if (logging.Value)
			{
				Debug.Log((object)("[SDBG] " + message));
			}
		}
	}
}