Decompiled source of Lobby ID Joining HoloCheck v0.1.1

BepInEx/plugins/RepoSteamIdJoin.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Steamworks;
using Steamworks.Data;
using TMPro;
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: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("Autodesk.Fbx")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("FbxBuildTestAssets")]
[assembly: IgnoresAccessChecksTo("Klattersynth")]
[assembly: IgnoresAccessChecksTo("Photon3Unity3D")]
[assembly: IgnoresAccessChecksTo("PhotonChat")]
[assembly: IgnoresAccessChecksTo("PhotonRealtime")]
[assembly: IgnoresAccessChecksTo("PhotonUnityNetworking")]
[assembly: IgnoresAccessChecksTo("PhotonUnityNetworking.Utilities")]
[assembly: IgnoresAccessChecksTo("PhotonVoice.API")]
[assembly: IgnoresAccessChecksTo("PhotonVoice")]
[assembly: IgnoresAccessChecksTo("PhotonVoice.PUN")]
[assembly: IgnoresAccessChecksTo("SingularityGroup.HotReload.Runtime")]
[assembly: IgnoresAccessChecksTo("SingularityGroup.HotReload.Runtime.Public")]
[assembly: IgnoresAccessChecksTo("Sirenix.OdinInspector.Attributes")]
[assembly: IgnoresAccessChecksTo("Sirenix.Serialization.Config")]
[assembly: IgnoresAccessChecksTo("Sirenix.Serialization")]
[assembly: IgnoresAccessChecksTo("Sirenix.Utilities")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Formats.Fbx.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Postprocessing.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Antlr3.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Core")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Flow")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.State")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: IgnoresAccessChecksTo("websocket-sharp")]
[assembly: AssemblyCompany("bricks04")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+ab8ab2e88be1b04f68012a51e8fcd1bb1296a24f")]
[assembly: AssemblyProduct("RepoSteamIdJoin")]
[assembly: AssemblyTitle("RepoSteamIdJoin")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 RepoSteamIdJoin
{
	[HarmonyPatch(typeof(ChatManager))]
	public class ChatManagerPatches
	{
		[HarmonyPatch("MessageSend")]
		[HarmonyPrefix]
		private static bool MessageSendPreFix(ChatManager __instance, bool _possessed)
		{
			if (!_possessed)
			{
				if (__instance.chatMessage == "/c")
				{
					SteamManagerPatches.CopyLobbyId();
					return false;
				}
				if (__instance.chatMessage == "/clear")
				{
					SteamManagerPatches.playerJoinPair = new Dictionary<ulong, int>();
					return false;
				}
				if (__instance.chatMessage == "/track")
				{
					SteamManagerPatches.maxPermittableJoins = 1;
					return false;
				}
				if (__instance.chatMessage == "/notrack")
				{
					SteamManagerPatches.maxPermittableJoins = 0;
					return false;
				}
				if (Regex.IsMatch(__instance.chatMessage, "^\\/joins\\s[0-9]{1,2}$"))
				{
					RepoSteamIdJoin.Logger.LogInfo((object)("Trying to change permittable joins to " + __instance.chatMessage.Substring(7)));
					if (int.TryParse(__instance.chatMessage.Substring(7), out var result))
					{
						SteamManagerPatches.maxPermittableJoins = result;
					}
					else
					{
						RepoSteamIdJoin.Logger.LogWarning((object)"Entered value did not parse correctly!");
					}
					return false;
				}
				if (__instance.chatMessage == "/truth")
				{
					__instance.chatMessage = "Ollie is the cutest!";
					return true;
				}
				if (__instance.chatMessage == "balls")
				{
					return true;
				}
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(MenuManager))]
	public class MenuManagerPatches
	{
		public static MenuManager currentInstance;

		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void AwakePostFix(MenuManager __instance)
		{
			currentInstance = __instance;
			RepoSteamIdJoin.Logger.LogInfo((object)currentInstance);
		}

		[HarmonyPatch("Update")]
		[HarmonyPrefix]
		private static void UpdatePrefix(MenuManager __instance)
		{
			if ((Object)(object)currentInstance != (Object)(object)__instance)
			{
				currentInstance = __instance;
			}
		}

		public static void GeneratePopUp(string headerText, string bodyText, string buttonText)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			currentInstance.PagePopUp(headerText, Color.yellow, bodyText, buttonText);
		}
	}
	[HarmonyPatch(typeof(MenuPageLobby))]
	public class MenuPageLobbyPatches
	{
		private static MenuPageLobby currentInstance;

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPostFix(MenuPageLobby __instance)
		{
			RepoSteamIdJoin.Logger.LogInfo((object)"MenuPageLobbyPatches started!");
			currentInstance = __instance;
			ChangeChatHelpText("Press <u><b>T</b></u> to chat | Chat <u>/c</u> to copy Lobby ID");
		}

		public static void ChangeChatHelpText(string targetText)
		{
			((TMP_Text)currentInstance.chatPromptText).text = targetText;
		}

		[HarmonyPatch("PlayerAdd")]
		[HarmonyPrefix]
		private static void PlayerAddPostFix(MenuPageLobby __instance, PlayerAvatar player)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			if (((Lobby)(ref SteamManager.instance.currentLobby)).IsOwnedBy(SteamClient.SteamId))
			{
				if (ulong.TryParse(player.steamID, out var result) && !SteamManagerPatches.CheckPlayerJoin(result))
				{
					player.playerName = "<color=#d60e54>" + player.playerName + "</color>";
				}
			}
			else
			{
				RepoSteamIdJoin.Logger.LogInfo((object)"I am not the lobby owner, so no pre-processing player names");
			}
		}
	}
	[HarmonyPatch(typeof(MenuPageMain))]
	public class MenuPageMainPatches
	{
		public static AssetBundle HoloCheckUIAssets;

		public static GameObject holoCheckUI;

		public static GameObject instantiatedUI;

		public static GameObject uiTarget;

		private static int easter;

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPostFix()
		{
			RepoSteamIdJoin.Logger.LogInfo((object)"MenuPageMainPatches awoken!");
			RepoSteamIdJoin.Logger.LogInfo((object)"Clipboard contains : ");
			RepoSteamIdJoin.Logger.LogInfo((object)GUIUtility.systemCopyBuffer);
			if (ulong.TryParse(GUIUtility.systemCopyBuffer, out var result))
			{
				RepoSteamIdJoin.Logger.LogInfo((object)result);
				RepoSteamIdJoin.Logger.LogInfo((object)"Parse was successful!");
			}
			else
			{
				RepoSteamIdJoin.Logger.LogWarning((object)"Parse was unsuccessful!");
			}
		}

		[HarmonyPatch("ButtonEventJoinGame")]
		[HarmonyPrefix]
		private static bool ButtonEventJoinGamePreFix()
		{
			RepoSteamIdJoin.Logger.LogInfo((object)"MenuPageMainPatches awoken!");
			RepoSteamIdJoin.Logger.LogInfo((object)"Clipboard contains : ");
			RepoSteamIdJoin.Logger.LogInfo((object)GUIUtility.systemCopyBuffer);
			if (ulong.TryParse(GUIUtility.systemCopyBuffer, out var result))
			{
				RepoSteamIdJoin.Logger.LogInfo((object)result);
				RepoSteamIdJoin.Logger.LogInfo((object)"Parse was successful!");
				SteamManagerPatches.RequestGameLobbyJoin(result);
			}
			else
			{
				RepoSteamIdJoin.Logger.LogWarning((object)"Parse was unsuccessful!");
				easter++;
				if (RandomNumberGenerator.GetInt32(99) > 90)
				{
					MenuManagerPatches.GeneratePopUp("Balls", "Humongous balls", "Ok");
				}
				else
				{
					MenuManagerPatches.GeneratePopUp("ERROR", "Clipboard does not contain a LobbyID", "wait what is this");
				}
			}
			return false;
		}
	}
	[BepInPlugin("bricks04.RepoSteamIdJoin", "RepoSteamIdJoin", "1.0")]
	public class RepoSteamIdJoin : BaseUnityPlugin
	{
		public static string displayedLobbyId = "";

		public static ulong joiningId = 0uL;

		internal static RepoSteamIdJoin Instance { get; private set; } = null;


		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Patch();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
		}

		internal void Patch()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0026: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private void Update()
		{
		}
	}
	[HarmonyPatch(typeof(SteamManager))]
	public class SteamManagerPatches
	{
		public static string currentLobbyId = "";

		public static Dictionary<ulong, int> playerJoinPair = new Dictionary<ulong, int>();

		public static int maxPermittableJoins = 0;

		public static bool CheckPlayerJoin(ulong checkPlayerId)
		{
			if (maxPermittableJoins == 0)
			{
				return true;
			}
			if (playerJoinPair.TryGetValue(checkPlayerId, out var value))
			{
				RepoSteamIdJoin.Logger.LogWarning((object)("User " + checkPlayerId + " has a record in playerJoinPair!"));
				if (value >= maxPermittableJoins)
				{
					RepoSteamIdJoin.Logger.LogWarning((object)("User " + checkPlayerId + " has " + value + " joins, more then the permittable joins!"));
					return false;
				}
				RepoSteamIdJoin.Logger.LogInfo((object)("User " + checkPlayerId + " has " + value + " joins. Adding one."));
				playerJoinPair[checkPlayerId] = value + 1;
			}
			else
			{
				RepoSteamIdJoin.Logger.LogInfo((object)("User " + checkPlayerId + " has no record in playerJoinPair"));
				playerJoinPair.Add(checkPlayerId, 1);
			}
			return true;
		}

		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void AwakePostFix(SteamManager __instance)
		{
			RepoSteamIdJoin.Logger.LogInfo((object)"SteamManager awoken!");
		}

		[HarmonyPatch("OnLobbyMemberJoined")]
		[HarmonyPostfix]
		private static void OnLobbyMemberJoinedPostFix(SteamManager __instance, Lobby _lobby, Friend _friend)
		{
			RepoSteamIdJoin.Logger.LogInfo((object)("Logging a join from id " + ((object)(SteamId)(ref _friend.Id)).ToString()));
		}

		[HarmonyPatch("LeaveLobby")]
		[HarmonyPostfix]
		private static void UpdatePostFix(SteamManager __instance)
		{
		}

		[HarmonyPatch("OnGameLobbyJoinRequested")]
		[HarmonyPrefix]
		private static void Start_Prefix(SteamManager __instance)
		{
			RepoSteamIdJoin.Logger.LogDebug((object)$"{__instance} Start Prefix");
		}

		[HarmonyPatch("OnLobbyCreated")]
		[HarmonyPostfix]
		private static void OnLobbyCreatedPostFix(SteamManager __instance, Result _result, Lobby _lobby)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			RepoSteamIdJoin.Logger.LogInfo((object)"Beginning HostLobby postfix");
			ManualLogSource logger = RepoSteamIdJoin.Logger;
			SteamId id = ((Lobby)(ref _lobby)).Id;
			logger.LogInfo((object)("Your lobby code is : " + ((object)(SteamId)(ref id)).ToString()));
			id = ((Lobby)(ref _lobby)).Id;
			RepoSteamIdJoin.displayedLobbyId = ((object)(SteamId)(ref id)).ToString();
			RepoSteamIdJoin.Logger.LogInfo((object)SteamManager.instance.currentLobby);
			RepoSteamIdJoin.Logger.LogInfo((object)((Lobby)(ref SteamManager.instance.currentLobby)).Id);
			id = ((Lobby)(ref _lobby)).Id;
			currentLobbyId = ((object)(SteamId)(ref id)).ToString();
		}

		[HarmonyPatch("UnlockLobby")]
		[HarmonyPostfix]
		public static void UnlockLobbyPostFix(SteamManager __instance)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			RepoSteamIdJoin.Logger.LogInfo((object)"Beginning UnlockLobby Postfix");
			RepoSteamIdJoin.Logger.LogInfo((object)SteamManager.instance.currentLobby);
			RepoSteamIdJoin.Logger.LogInfo((object)((Lobby)(ref SteamManager.instance.currentLobby)).Id);
		}

		[HarmonyPatch("LeaveLobby")]
		[HarmonyPostfix]
		private static void LeaveLobbyPostFix(SteamManager __instance)
		{
		}

		[HarmonyPatch("HostLobby")]
		[HarmonyPostfix]
		public static void HostLobby()
		{
		}

		public static void CopyLobbyId()
		{
			GUIUtility.systemCopyBuffer = currentLobbyId;
			RepoSteamIdJoin.Logger.LogInfo((object)"Copied the current lobby ID!");
		}

		public static void RequestGameLobbyJoin(ulong lobbyId)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			SteamManager.instance.OnGameLobbyJoinRequested(new Lobby(SteamId.op_Implicit(lobbyId)), default(SteamId));
		}
	}
}