Decompiled source of LetMeJoin v0.1.0

ZTz.LetMeJoin.dll

Decompiled a year 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.Logging;
using HarmonyLib;
using LetMeJoin.Patches;
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(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyCompany("ZTz.LetMeJoin")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Lets players join your game even while your ship is chilling in orbit")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("LetMeJoin")]
[assembly: AssemblyTitle("ZTz.LetMeJoin")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.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 LetMeJoin
{
	[BepInPlugin("ZTz.LetMeJoin", "LetMeJoin", "0.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		private Harmony _harmony;

		private static Plugin Instance { get; set; }

		private static ManualLogSource LogSource { get; set; }

		public static bool LobbyOpen { get; private set; } = true;


		private void Awake()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			Instance = this;
			LogSource = Logger.CreateLogSource("ZTz.LetMeJoin");
			_harmony = new Harmony("ZTz.LetMeJoin");
			_harmony.PatchAll(typeof(Plugin));
			_harmony.PatchAll(typeof(GameNetworkManagerPatch));
			_harmony.PatchAll(typeof(QuickMenuManagerPatch));
			_harmony.PatchAll(typeof(StartOfRoundPatch));
		}

		public static void LogInfo(string message)
		{
			LogSource.LogInfo((object)message);
		}

		public static void LogError(string message)
		{
			LogSource.LogError((object)message);
		}

		public static void SetLobbyOpen(bool openLobby)
		{
			LobbyOpen = openLobby;
			GameNetworkManager.Instance.SetLobbyJoinable(openLobby);
			QuickMenuManager val = Object.FindObjectOfType<QuickMenuManager>();
			if (Object.op_Implicit((Object)(object)val))
			{
				val.inviteFriendsTextAlpha.alpha = (openLobby ? 1f : 0.2f);
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "ZTz.LetMeJoin";

		public const string PLUGIN_NAME = "LetMeJoin";

		public const string PLUGIN_VERSION = "0.1.0";
	}
}
namespace LetMeJoin.Patches
{
	[HarmonyPatch(typeof(GameNetworkManager))]
	public class GameNetworkManagerPatch
	{
		[HarmonyPatch("LeaveLobbyAtGameStart")]
		[HarmonyPrefix]
		private static bool LeaveLobbyAtGameStartPrefix()
		{
			return false;
		}

		[HarmonyPatch(typeof(GameNetworkManager), "ConnectionApproval")]
		[HarmonyPostfix]
		public static void ConnectionApprovalPostfix(ConnectionApprovalRequest request, ConnectionApprovalResponse response)
		{
			if (GameNetworkManager.Instance.gameHasStarted && Plugin.LobbyOpen)
			{
				response.Reason = "";
				response.Approved = true;
			}
		}
	}
	[HarmonyPatch(typeof(QuickMenuManager))]
	public class QuickMenuManagerPatch
	{
		[HarmonyPatch("DisableInviteFriendsButton")]
		[HarmonyPrefix]
		public static bool DisableInviteFriendsButtonPrefix()
		{
			return false;
		}

		[HarmonyPatch("InviteFriendsButton")]
		[HarmonyPrefix]
		public static bool InviteFriendsButtonPrefix()
		{
			if (!Plugin.LobbyOpen)
			{
				return false;
			}
			GameNetworkManager.Instance.InviteFriendsUI();
			return false;
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	public class StartOfRoundPatch
	{
		[HarmonyPatch("OnPlayerDC")]
		public static void OnPlayerDCPostfix()
		{
			if (StartOfRound.Instance.inShipPhase)
			{
				Plugin.SetLobbyOpen(openLobby: true);
			}
		}

		[HarmonyPatch("StartGame")]
		[HarmonyPrefix]
		public static void StartGamePrefix()
		{
			Plugin.SetLobbyOpen(openLobby: false);
		}

		[HarmonyPatch("SetShipReadyToLand")]
		[HarmonyPrefix]
		public static void SetShipReadyToLandPrefix()
		{
			if (StartOfRound.Instance.connectedPlayersAmount + 1 < StartOfRound.Instance.allPlayerScripts.Length)
			{
				Plugin.SetLobbyOpen(openLobby: true);
			}
		}
	}
}