Decompiled source of GlobalNotifsDashboard v1.3.0

Mods/GlobalNotifsDashboard.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BoneLib.BoneMenu;
using BoneLib.Notifications;
using GlobalNotifs;
using HarmonyLib;
using LabFusion.Network;
using LabFusion.Network.Serialization;
using LabFusion.Player;
using LabFusion.SDK.Modules;
using MelonLoader;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Main), "GlobalNotifsdashboard", "1.3.0", "Grozny", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: MelonOptionalDependencies(new string[] { "LabFusion" })]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("global_notifs")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("global_notifs")]
[assembly: AssemblyTitle("global_notifs")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 GlobalNotifs
{
	public class Main : MelonMod
	{
		public static Page ModPage;

		public static StringElement MessageBox;

		public static Page DirectPage;

		public static Page PlayersPage;

		public static StringElement DirectMessageBox;

		public static StringElement TargetIdBox;

		public static FunctionElement TargetLabel;

		public static ulong SelectedTargetId = 0uL;

		public static string SelectedTargetName = "None";

		private const string DefaultMessageText = "Type your message here...";

		private const string DefaultIdText = "Paste Steam ID here...";

		public static Page WhitelistPage;

		public static Page WhitelistListPage;

		public static StringElement WhitelistIdBox;

		private static bool FusionLoaded => MelonBase.FindMelon("LabFusion", "Lakatrazz") != null;

		public override void OnInitializeMelon()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			ModPage = Page.Root.CreatePage("Global Notifs", Color.cyan, 0, true);
			MessageBox = ModPage.CreateString("Message", Color.white, "Type your message here...", (Action<string>)null);
			ModPage.CreateFunction("Send to Lobby", Color.green, (Action)delegate
			{
				string value = MessageBox.Value;
				if (!string.IsNullOrWhiteSpace(value) && !(value == "Type your message here..."))
				{
					SendGlobalNotification("Lobby Message", value, (NotificationType)0);
				}
			});
			ModPage.CreateFunction("Clear Text", Color.gray, (Action)delegate
			{
				MessageBox.Value = "";
			});
			BuildDirectMessageMenu();
			BuildDebugMenu();
			ModPage.CreateBool("Spawn Logger", Color.white, true, (Action<bool>)delegate(bool value)
			{
				SpawnLogger.Enabled = value;
			});
			Whitelist.Load();
			BuildWhitelistMenu();
			if (FusionLoaded)
			{
				ModuleManager.RegisterModule<NotificationModule>();
				SpawnLogger.Init(((MelonBase)this).HarmonyInstance);
				WhitelistGuard.Init();
			}
		}

		private static void BuildDirectMessageMenu()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			DirectPage = ModPage.CreatePage("Send to Player", Color.yellow, 0, true);
			TargetLabel = DirectPage.CreateFunction("Target: None", Color.white, (Action)delegate
			{
			});
			DirectPage.CreateFunction("Show My Steam ID", Color.cyan, (Action)ShowMySteamId);
			PlayersPage = DirectPage.CreatePage("Select Player", Color.cyan, 0, true);
			PlayersPage.CreateFunction("Refresh Players", Color.green, (Action)RefreshPlayers);
			TargetIdBox = DirectPage.CreateString("Steam ID", Color.white, "Paste Steam ID here...", (Action<string>)null);
			DirectPage.CreateFunction("Use Typed Steam ID", Color.white, (Action)UseTypedId);
			DirectMessageBox = DirectPage.CreateString("Message", Color.white, "Type your message here...", (Action<string>)null);
			DirectPage.CreateFunction("Send to Target", Color.green, (Action)SendToTarget);
			DirectPage.CreateFunction("Clear Target", Color.gray, (Action)ClearTarget);
		}

		private static void BuildWhitelistMenu()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			WhitelistPage = ModPage.CreatePage("Whitelist", Color.magenta, 0, true);
			WhitelistPage.CreateBool("Whitelist Enabled", Color.white, false, (Action<bool>)delegate(bool value)
			{
				Whitelist.Enabled = value;
				if (value)
				{
					LocalNotify("Whitelist ON", $"{Whitelist.Count} ID(s). New joiners not on the list get kicked.", (NotificationType)1);
				}
				else
				{
					LocalNotify("Whitelist OFF", "Anyone can join.", (NotificationType)0);
				}
			});
			WhitelistIdBox = WhitelistPage.CreateString("Steam ID", Color.white, "Paste Steam ID here...", (Action<string>)null);
			WhitelistPage.CreateFunction("Add Typed ID", Color.green, (Action)AddTypedWhitelistId);
			WhitelistPage.CreateFunction("Remove Typed ID", Color.red, (Action)RemoveTypedWhitelistId);
			WhitelistPage.CreateFunction("Add Everyone In Lobby", Color.cyan, (Action)AddLobbyToWhitelist);
			WhitelistListPage = WhitelistPage.CreatePage("View List", Color.white, 0, true);
			WhitelistListPage.CreateFunction("Refresh List", Color.green, (Action)RefreshWhitelistList);
		}

		private static bool TryReadWhitelistId(out ulong id)
		{
			if (!ulong.TryParse(WhitelistIdBox.Value?.Trim(), out id) || id == 0)
			{
				LocalNotify("Invalid ID", "Enter the numeric Steam ID (SteamID64).", (NotificationType)1);
				return false;
			}
			return true;
		}

		private static void AddTypedWhitelistId()
		{
			if (TryReadWhitelistId(out var id))
			{
				if (Whitelist.Add(id))
				{
					LocalNotify("Whitelist", $"Added {id}. Total: {Whitelist.Count}", (NotificationType)0);
				}
				else
				{
					LocalNotify("Whitelist", $"{id} is already on the list.", (NotificationType)0);
				}
			}
		}

		private static void RemoveTypedWhitelistId()
		{
			if (TryReadWhitelistId(out var id))
			{
				if (Whitelist.Remove(id))
				{
					LocalNotify("Whitelist", $"Removed {id}. Total: {Whitelist.Count}", (NotificationType)0);
				}
				else
				{
					LocalNotify("Whitelist", $"{id} wasn't on the list.", (NotificationType)0);
				}
			}
		}

		private static void AddLobbyToWhitelist()
		{
			if (!FusionLoaded)
			{
				LocalNotify("Whitelist", "Fusion isn't installed.", (NotificationType)1);
				return;
			}
			int num = 0;
			if (Whitelist.Add(FusionHelper.LocalId))
			{
				num++;
			}
			foreach (FusionHelper.PlayerEntry otherPlayer in FusionHelper.GetOtherPlayers())
			{
				if (Whitelist.Add(otherPlayer.Id))
				{
					num++;
				}
			}
			LocalNotify("Whitelist", $"Added {num} player(s). Total: {Whitelist.Count}", (NotificationType)0);
		}

		private static void RefreshWhitelistList()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			WhitelistListPage.RemoveAll();
			WhitelistListPage.CreateFunction("Refresh List", Color.green, (Action)RefreshWhitelistList);
			List<ulong> list = Whitelist.All();
			if (list.Count == 0)
			{
				WhitelistListPage.CreateFunction("List is empty", Color.gray, (Action)delegate
				{
				});
				return;
			}
			foreach (ulong item in list)
			{
				ulong captured = item;
				WhitelistListPage.CreateFunction($"{captured} (tap to remove)", Color.white, (Action)delegate
				{
					Whitelist.Remove(captured);
					RefreshWhitelistList();
				});
			}
		}

		private static void BuildDebugMenu()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			Page val = ModPage.CreatePage("Debug", Color.gray, 0, true);
			val.CreateFunction("Log Fusion Spawn Types", Color.white, (Action)delegate
			{
				if (!FusionLoaded)
				{
					LocalNotify("Debug", "Fusion isn't installed.", (NotificationType)1);
				}
				else
				{
					FusionHelper.DumpSpawnTypes();
					LocalNotify("Debug", "Written to the MelonLoader log.", (NotificationType)0);
				}
			});
			val.CreateFunction("Check Kick Method", Color.white, (Action)delegate
			{
				if (!FusionLoaded)
				{
					LocalNotify("Debug", "Fusion isn't installed.", (NotificationType)1);
				}
				else
				{
					WhitelistGuard.LogKickLookup();
					LocalNotify("Debug", "Written to the MelonLoader log.", (NotificationType)0);
				}
			});
		}

		private static void ShowMySteamId()
		{
			if (!FusionLoaded)
			{
				LocalNotify("Steam ID", "Fusion isn't installed, so no ID is available.", (NotificationType)1);
			}
			else
			{
				LocalNotify("Your Steam ID", FusionHelper.LocalId.ToString(), (NotificationType)0);
			}
		}

		private static void RefreshPlayers()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			PlayersPage.RemoveAll();
			PlayersPage.CreateFunction("Refresh Players", Color.green, (Action)RefreshPlayers);
			if (!FusionLoaded)
			{
				PlayersPage.CreateFunction("Fusion not installed", Color.gray, (Action)delegate
				{
				});
				return;
			}
			List<FusionHelper.PlayerEntry> otherPlayers = FusionHelper.GetOtherPlayers();
			if (otherPlayers.Count == 0)
			{
				PlayersPage.CreateFunction("No other players in lobby", Color.gray, (Action)delegate
				{
				});
				return;
			}
			foreach (FusionHelper.PlayerEntry item in otherPlayers)
			{
				string name = item.Name;
				ulong id = item.Id;
				PlayersPage.CreateFunction($"{name} ({id})", Color.white, (Action)delegate
				{
					SelectTarget(name, id);
				});
			}
		}

		private static void SelectTarget(string name, ulong id)
		{
			SelectedTargetId = id;
			SelectedTargetName = name;
			((Element)TargetLabel).ElementName = "Target: " + name;
			LocalNotify("Target set", $"{name} ({id})", (NotificationType)0);
		}

		private static void UseTypedId()
		{
			if (!ulong.TryParse(TargetIdBox.Value?.Trim(), out var result) || result == 0)
			{
				LocalNotify("Invalid ID", "Enter the numeric Steam ID (SteamID64).", (NotificationType)1);
			}
			else
			{
				SelectTarget("Custom ID", result);
			}
		}

		private static void ClearTarget()
		{
			SelectedTargetId = 0uL;
			SelectedTargetName = "None";
			((Element)TargetLabel).ElementName = "Target: None";
		}

		private static void SendToTarget()
		{
			if (SelectedTargetId == 0)
			{
				LocalNotify("No target", "Pick a player or enter a Steam ID first.", (NotificationType)1);
				return;
			}
			string value = DirectMessageBox.Value;
			if (!string.IsNullOrWhiteSpace(value) && !(value == "Type your message here..."))
			{
				SendNotification("Direct Message", value, (NotificationType)0, SelectedTargetId);
			}
		}

		public static void SendGlobalNotification(string title, string message, NotificationType type = (NotificationType)0)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			SendNotification(title, message, type, 0uL);
		}

		public static void SendNotification(string title, string message, NotificationType type, ulong targetId)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected I4, but got Unknown
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			if (targetId == 0)
			{
				LocalNotify(title, message, type);
			}
			else
			{
				if (FusionLoaded && targetId == FusionHelper.LocalId)
				{
					LocalNotify(title, message, type);
					return;
				}
				LocalNotify("Sent", "Message sent to " + SelectedTargetName + ".", (NotificationType)0);
			}
			if (FusionLoaded)
			{
				NotificationData notificationData = new NotificationData
				{
					Title = title,
					Message = message,
					Type = (int)type,
					TargetId = targetId
				};
				MessageRelay.RelayModule<GlobalNotificationMessage, NotificationData>(notificationData, new MessageRoute((RelayType)3, (NetworkChannel)0));
			}
		}

		public static void LocalNotify(string title, string message, NotificationType type = (NotificationType)0)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: 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)
			//IL_001e: 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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			Notification val = new Notification
			{
				Title = NotificationText.op_Implicit(title),
				Message = NotificationText.op_Implicit(message),
				Type = type,
				ShowTitleOnPopup = true,
				PopupLength = 3.5f
			};
			Notifier.Send(val);
		}
	}
	public static class FusionHelper
	{
		public class PlayerEntry
		{
			public string Name;

			public ulong Id;
		}

		private const BindingFlags AnyInstance = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

		private static readonly HashSet<string> LoggedOnce = new HashSet<string>();

		public static ulong LocalId => PlayerIDManager.LocalPlatformID;

		public static List<PlayerEntry> GetOtherPlayers()
		{
			List<PlayerEntry> list = new List<PlayerEntry>();
			if (!NetworkInfo.HasServer)
			{
				return list;
			}
			foreach (PlayerID playerID in PlayerIDManager.PlayerIDs)
			{
				if (!playerID.IsMe)
				{
					list.Add(new PlayerEntry
					{
						Name = GetName(playerID),
						Id = playerID.PlatformID
					});
				}
			}
			return list;
		}

		public static void DumpSpawnTypes()
		{
			Type[] array;
			try
			{
				array = typeof(PlayerID).Assembly.GetTypes();
			}
			catch (ReflectionTypeLoadException ex)
			{
				List<Type> list = new List<Type>();
				Type[] types = ex.Types;
				foreach (Type type in types)
				{
					if (type != null)
					{
						list.Add(type);
					}
				}
				array = list.ToArray();
			}
			Type[] array2 = array;
			foreach (Type type2 in array2)
			{
				string text = type2.FullName ?? type2.Name;
				bool flag = text.IndexOf("Spawn", StringComparison.OrdinalIgnoreCase) >= 0;
				bool flag2 = text.IndexOf("Hooking", StringComparison.OrdinalIgnoreCase) >= 0;
				if (!flag && !flag2)
				{
					continue;
				}
				List<string> list2 = new List<string>();
				try
				{
					MemberInfo[] members = type2.GetMembers(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					foreach (MemberInfo memberInfo in members)
					{
						if ((!flag2 || memberInfo.MemberType == MemberTypes.Event) && (memberInfo.MemberType != MemberTypes.Method || !((MethodInfo)memberInfo).IsSpecialName) && (memberInfo.MemberType == MemberTypes.Property || memberInfo.MemberType == MemberTypes.Field || memberInfo.MemberType == MemberTypes.Method || memberInfo.MemberType == MemberTypes.Event))
						{
							list2.Add(memberInfo.Name);
						}
					}
				}
				catch
				{
				}
				MelonLogger.Msg("[GlobalNotifs][SpawnDump] " + text + ": " + string.Join(", ", list2));
			}
			MelonLogger.Msg("[GlobalNotifs][SpawnDump] done");
		}

		public static string DescribePlayer(object owner)
		{
			if (owner == null)
			{
				return "Unknown player";
			}
			PlayerID val = null;
			PlayerID val2 = (PlayerID)((owner is PlayerID) ? owner : null);
			if (val2 != null)
			{
				val = val2;
			}
			else
			{
				try
				{
					int num = Convert.ToInt32(owner);
					foreach (PlayerID playerID in PlayerIDManager.PlayerIDs)
					{
						if (Convert.ToInt32(playerID.SmallID) == num)
						{
							val = playerID;
							break;
						}
					}
				}
				catch
				{
				}
			}
			if (val != null)
			{
				return $"{GetName(val)} ({val.PlatformID})";
			}
			return $"Unknown player ({owner})";
		}

		private static string GetName(PlayerID player)
		{
			object target = null;
			try
			{
				target = player.Metadata;
			}
			catch (Exception ex)
			{
				LogOnce("metadata", "Reading player.Metadata threw: " + (ex.InnerException ?? ex).Message);
			}
			object obj = ReadMember(target, "Nickname");
			object obj2 = ReadMember(target, "Username");
			string text = Unwrap(obj, 0);
			if (string.IsNullOrWhiteSpace(text))
			{
				text = Unwrap(obj2, 0);
			}
			if (!string.IsNullOrWhiteSpace(text))
			{
				return text;
			}
			DescribeOnce("Nickname", obj);
			DescribeOnce("Username", obj2);
			return $"Player {player.SmallID}";
		}

		public static object ReadMember(object target, string memberName)
		{
			if (target == null)
			{
				return null;
			}
			try
			{
				Type type = target.GetType();
				PropertyInfo property = type.GetProperty(memberName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (property != null)
				{
					return property.GetValue(target);
				}
				FieldInfo field = type.GetField(memberName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (field != null)
				{
					return field.GetValue(target);
				}
			}
			catch (Exception ex)
			{
				LogOnce("read-" + memberName, "Reading " + memberName + " threw: " + (ex.InnerException ?? ex).Message);
			}
			return null;
		}

		public static string Unwrap(object value, int depth)
		{
			if (value == null || depth > 2)
			{
				return null;
			}
			if (value is string result)
			{
				return result;
			}
			Type type = value.GetType();
			PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (PropertyInfo propertyInfo in properties)
			{
				if (propertyInfo.PropertyType != typeof(string) || !propertyInfo.CanRead || propertyInfo.GetIndexParameters().Length != 0 || propertyInfo.Name.IndexOf("Key", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					continue;
				}
				try
				{
					string text = propertyInfo.GetValue(value) as string;
					if (!string.IsNullOrEmpty(text))
					{
						return text;
					}
				}
				catch
				{
				}
			}
			MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (MethodInfo methodInfo in methods)
			{
				if (methodInfo.IsSpecialName || methodInfo.IsGenericMethodDefinition || methodInfo.ReturnType != typeof(string) || methodInfo.GetParameters().Length != 0 || methodInfo.Name == "ToString" || methodInfo.Name.IndexOf("Key", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					continue;
				}
				try
				{
					string text2 = methodInfo.Invoke(value, null) as string;
					if (!string.IsNullOrEmpty(text2))
					{
						return text2;
					}
				}
				catch
				{
				}
			}
			MethodInfo[] methods2 = type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (MethodInfo methodInfo2 in methods2)
			{
				if (!methodInfo2.IsGenericMethodDefinition || methodInfo2.GetGenericArguments().Length != 1 || methodInfo2.GetParameters().Length != 0 || !methodInfo2.Name.StartsWith("Get", StringComparison.Ordinal) || methodInfo2.Name.IndexOf("Key", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					continue;
				}
				try
				{
					string text3 = methodInfo2.MakeGenericMethod(typeof(string)).Invoke(value, null) as string;
					if (!string.IsNullOrEmpty(text3))
					{
						return text3;
					}
				}
				catch
				{
				}
			}
			return null;
		}

		private static void DescribeOnce(string label, object obj)
		{
			if (obj == null)
			{
				LogOnce("describe-" + label, label + " value was null");
				return;
			}
			List<string> list = new List<string>();
			MemberInfo[] members = obj.GetType().GetMembers(BindingFlags.Instance | BindingFlags.Public);
			foreach (MemberInfo memberInfo in members)
			{
				if (memberInfo.MemberType == MemberTypes.Property || memberInfo.MemberType == MemberTypes.Field || memberInfo.MemberType == MemberTypes.Method)
				{
					list.Add(memberInfo.Name);
				}
			}
			LogOnce("describe-" + label, $"{label} is type {obj.GetType().FullName}, members: {string.Join(", ", list)}");
		}

		private static void LogOnce(string key, string message)
		{
			if (LoggedOnce.Add(key))
			{
				MelonLogger.Msg("[GlobalNotifs] " + message);
			}
		}
	}
	public static class Whitelist
	{
		public static bool Enabled = false;

		private static readonly HashSet<ulong> Ids = new HashSet<ulong>();

		private static string _path;

		public static int Count => Ids.Count;

		public static bool Contains(ulong id)
		{
			return Ids.Contains(id);
		}

		public static List<ulong> All()
		{
			return new List<ulong>(Ids);
		}

		public static void Load()
		{
			try
			{
				string fullPath = Path.GetFullPath(Path.Combine(Application.dataPath, "..", "UserData"));
				Directory.CreateDirectory(fullPath);
				_path = Path.Combine(fullPath, "GlobalNotifs_Whitelist.txt");
				if (!File.Exists(_path))
				{
					return;
				}
				string[] array = File.ReadAllLines(_path);
				foreach (string text in array)
				{
					if (ulong.TryParse(text.Trim(), out var result) && result != 0)
					{
						Ids.Add(result);
					}
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("[GlobalNotifs] Couldn't load whitelist: " + ex.Message);
			}
		}

		public static bool Add(ulong id)
		{
			if (!Ids.Add(id))
			{
				return false;
			}
			Save();
			return true;
		}

		public static bool Remove(ulong id)
		{
			if (!Ids.Remove(id))
			{
				return false;
			}
			Save();
			return true;
		}

		private static void Save()
		{
			try
			{
				if (_path == null)
				{
					return;
				}
				List<string> list = new List<string>();
				foreach (ulong id in Ids)
				{
					list.Add(id.ToString());
				}
				File.WriteAllLines(_path, list);
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("[GlobalNotifs] Couldn't save whitelist: " + ex.Message);
			}
		}
	}
	public static class WhitelistGuard
	{
		private const BindingFlags AllStatic = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

		private static MethodInfo _kickMethod;

		private static bool _searched;

		public static void Init()
		{
			try
			{
				EventInfo eventInfo = typeof(PlayerID).Assembly.GetType("LabFusion.Utilities.MultiplayerHooking")?.GetEvent("OnPlayerJoined", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				MethodInfo method = typeof(WhitelistGuard).GetMethod("OnPlayerJoined", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				if (eventInfo == null || method == null)
				{
					MelonLogger.Warning("[GlobalNotifs] Whitelist: couldn't find MultiplayerHooking.OnPlayerJoined");
					return;
				}
				Delegate obj = Delegate.CreateDelegate(eventInfo.EventHandlerType, method, throwOnBindFailure: false);
				if ((object)obj == null)
				{
					MelonLogger.Warning("[GlobalNotifs] Whitelist: OnPlayerJoined has an unexpected signature: " + eventInfo.EventHandlerType);
					return;
				}
				eventInfo.AddEventHandler(null, obj);
				MelonLogger.Msg("[GlobalNotifs] Whitelist guard active");
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("[GlobalNotifs] Whitelist failed to start: " + ex.Message);
			}
		}

		private static void OnPlayerJoined(PlayerID player)
		{
			try
			{
				if (Whitelist.Enabled && !player.IsMe)
				{
					ulong platformID = player.PlatformID;
					if (platformID != 0L && !Whitelist.Contains(platformID))
					{
						MelonCoroutines.Start(KickAfterDelay(player, platformID));
					}
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("[GlobalNotifs] Whitelist join check failed: " + ex.Message);
			}
		}

		private static IEnumerator KickAfterDelay(PlayerID player, ulong id)
		{
			yield return (object)new WaitForSeconds(2f);
			if (Whitelist.Enabled && !Whitelist.Contains(id))
			{
				string who = FusionHelper.DescribePlayer(player);
				string detail;
				if (IsHost() == false)
				{
					MelonLogger.Msg("[GlobalNotifs] Whitelist: " + who + " isn't whitelisted, but you aren't the host so can't kick.");
				}
				else if (TryKick(player, out detail))
				{
					MelonLogger.Msg($"[GlobalNotifs] Whitelist: kicked {who} ({detail})");
					Main.LocalNotify("Whitelist", "Kicked " + who, (NotificationType)1);
				}
				else
				{
					MelonLogger.Warning("[GlobalNotifs] Whitelist: couldn't kick " + who + ": " + detail);
					Main.LocalNotify("Whitelist", who + " isn't whitelisted, but the kick failed (see log).", (NotificationType)2);
				}
			}
		}

		private static bool? IsHost()
		{
			try
			{
				Type type = typeof(PlayerID).Assembly.GetType("LabFusion.Network.NetworkInfo");
				PropertyInfo propertyInfo = type?.GetProperty("IsHost", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				if (propertyInfo != null)
				{
					return (bool)propertyInfo.GetValue(null);
				}
				FieldInfo fieldInfo = type?.GetField("IsHost", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				if (fieldInfo != null)
				{
					return (bool)fieldInfo.GetValue(null);
				}
			}
			catch
			{
			}
			return null;
		}

		private static bool TryKick(PlayerID player, out string detail)
		{
			if (!_searched)
			{
				_searched = true;
				_kickMethod = FindKickMethod();
			}
			if (_kickMethod == null)
			{
				detail = "no kick method found";
				return false;
			}
			try
			{
				_kickMethod.Invoke(null, new object[1] { player });
				detail = _kickMethod.DeclaringType.Name + "." + _kickMethod.Name;
				return true;
			}
			catch (Exception ex)
			{
				detail = (ex.InnerException ?? ex).Message;
				return false;
			}
		}

		public static void LogKickLookup()
		{
			_searched = true;
			_kickMethod = FindKickMethod();
			if (_kickMethod != null)
			{
				MelonLogger.Msg("[GlobalNotifs] Kick method in use: " + _kickMethod.DeclaringType.FullName + "." + _kickMethod.Name);
			}
		}

		private static MethodInfo FindKickMethod()
		{
			Type[] array;
			try
			{
				array = typeof(PlayerID).Assembly.GetTypes();
			}
			catch (ReflectionTypeLoadException ex)
			{
				List<Type> list = new List<Type>();
				Type[] types = ex.Types;
				foreach (Type type in types)
				{
					if (type != null)
					{
						list.Add(type);
					}
				}
				array = list.ToArray();
			}
			string[] array2 = new string[3] { "KickUser", "KickPlayer", "Kick" };
			MethodInfo methodInfo = null;
			int num = int.MaxValue;
			Type[] array3 = array;
			foreach (Type type2 in array3)
			{
				MethodInfo[] methods = type2.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (MethodInfo methodInfo2 in methods)
				{
					if (methodInfo2.Name.IndexOf("Kick", StringComparison.OrdinalIgnoreCase) < 0 && methodInfo2.Name.IndexOf("Ban", StringComparison.OrdinalIgnoreCase) < 0)
					{
						continue;
					}
					List<string> list2 = new List<string>();
					ParameterInfo[] parameters = methodInfo2.GetParameters();
					foreach (ParameterInfo parameterInfo in parameters)
					{
						list2.Add(parameterInfo.ParameterType.Name);
					}
					string value = (methodInfo2.IsStatic ? "static" : "instance");
					MelonLogger.Msg($"[GlobalNotifs][KickLookup] {value} {type2.FullName}.{methodInfo2.Name}({string.Join(", ", list2)})");
					ParameterInfo[] parameters2 = methodInfo2.GetParameters();
					if (methodInfo2.IsStatic && parameters2.Length == 1 && !(parameters2[0].ParameterType != typeof(PlayerID)))
					{
						int num2 = Array.IndexOf(array2, methodInfo2.Name);
						if (num2 >= 0 && num2 < num)
						{
							methodInfo = methodInfo2;
							num = num2;
						}
					}
				}
			}
			if (methodInfo == null)
			{
				MelonLogger.Warning("[GlobalNotifs][KickLookup] no static Kick*(PlayerID) method found; see the lines above for what exists");
			}
			return methodInfo;
		}
	}
	public static class SpawnLogger
	{
		public static bool Enabled = true;

		private static string _filePath;

		public static void Init(Harmony harmony)
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			try
			{
				MethodInfo methodInfo = typeof(PlayerID).Assembly.GetType("LabFusion.Network.SpawnResponseMessage")?.GetMethod("OnHandleMessage", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				MethodInfo method = typeof(SpawnLogger).GetMethod("Postfix", BindingFlags.Static | BindingFlags.NonPublic);
				if (methodInfo == null || method == null)
				{
					MelonLogger.Warning("[GlobalNotifs] Spawn logger: couldn't find SpawnResponseMessage.OnHandleMessage");
					return;
				}
				harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(method), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				string fullPath = Path.GetFullPath(Path.Combine(Application.dataPath, "..", "UserData"));
				Directory.CreateDirectory(fullPath);
				_filePath = Path.Combine(fullPath, "GlobalNotifs_Spawns.txt");
				MelonLogger.Msg("[GlobalNotifs] Spawn logger active");
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("[GlobalNotifs] Spawn logger failed to start: " + ex.Message);
			}
		}

		private static void Postfix(ReceivedMessage __0)
		{
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			if (!Enabled)
			{
				return;
			}
			try
			{
				Type type = typeof(PlayerID).Assembly.GetType("LabFusion.Network.SpawnResponseData");
				if (type == null)
				{
					return;
				}
				object obj = null;
				MethodInfo[] methods = typeof(ReceivedMessage).GetMethods();
				foreach (MethodInfo methodInfo in methods)
				{
					if (methodInfo.Name == "ReadData" && methodInfo.IsGenericMethodDefinition && methodInfo.GetParameters().Length == 0)
					{
						obj = methodInfo.MakeGenericMethod(type).Invoke(__0, null);
						break;
					}
				}
				if (obj != null)
				{
					object owner = FusionHelper.ReadMember(obj, "OwnerID");
					object target = FusionHelper.ReadMember(obj, "SpawnData");
					object obj2 = FusionHelper.ReadMember(target, "Barcode");
					object obj3 = FusionHelper.ReadMember(target, "SpawnSource");
					string value = FusionHelper.DescribePlayer(owner);
					string value2 = FusionHelper.Unwrap(obj2, 0) ?? obj2?.ToString() ?? "unknown item";
					string value3 = ((obj3 != null) ? $" via {obj3}" : "");
					string text = $"[Spawn] {value} spawned {value2}{value3}";
					MelonLogger.Msg("[GlobalNotifs] " + text);
					if (_filePath != null)
					{
						File.AppendAllText(_filePath, $"{DateTime.Now:yyyy-MM-dd HH:mm:ss} {text}{Environment.NewLine}");
					}
				}
			}
			catch (Exception ex)
			{
				Exception ex2 = ex.InnerException ?? ex;
				MelonLogger.Warning("[GlobalNotifs] Spawn logger error: " + ex2.Message);
			}
		}
	}
	public class NotificationData : INetSerializable
	{
		public string Title;

		public string Message;

		public int Type;

		public ulong TargetId;

		public int? GetSize()
		{
			return SizeExtensions.GetSize(Title) + SizeExtensions.GetSize(Message) + 4 + 8;
		}

		public void Serialize(INetSerializer serializer)
		{
			serializer.SerializeValue(ref Title);
			serializer.SerializeValue(ref Message);
			serializer.SerializeValue(ref Type);
			serializer.SerializeValue(ref TargetId);
		}
	}
	public class GlobalNotificationMessage : ModuleMessageHandler
	{
		protected override void OnHandleMessage(ReceivedMessage received)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			NotificationData notificationData = ((ReceivedMessage)(ref received)).ReadData<NotificationData>();
			if (notificationData.TargetId == 0L || notificationData.TargetId == PlayerIDManager.LocalPlatformID)
			{
				Notification val = new Notification
				{
					Title = NotificationText.op_Implicit(notificationData.Title),
					Message = NotificationText.op_Implicit(notificationData.Message),
					Type = (NotificationType)notificationData.Type,
					ShowTitleOnPopup = true,
					PopupLength = 3.5f
				};
				Notifier.Send(val);
			}
		}
	}
	public class NotificationModule : Module
	{
		public override string Name => "GlobalNotifdashboard";

		public override string Author => "grozny";

		public override Version Version => new Version(1, 3, 0);

		public override ConsoleColor Color => ConsoleColor.Cyan;

		protected override void OnModuleRegistered()
		{
			ModuleMessageManager.RegisterHandler<GlobalNotificationMessage>();
		}
	}
}

Mods/GlobalNotifsReciever.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BoneLib.Notifications;
using GlobalNotifsReceiver;
using LabFusion.Network;
using LabFusion.Network.Serialization;
using LabFusion.Player;
using LabFusion.SDK.Modules;
using MelonLoader;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Main), "Global Notifs Receiver", "1.1.0", "grozny", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: MelonOptionalDependencies(new string[] { "LabFusion" })]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("GlobalNotifsReciever")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("GlobalNotifsReciever")]
[assembly: AssemblyTitle("GlobalNotifsReciever")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 GlobalNotifsReceiver
{
	public class Main : MelonMod
	{
		public override void OnInitializeMelon()
		{
			if (MelonBase.FindMelon("LabFusion", "Lakatrazz") != null)
			{
				ModuleManager.RegisterModule<NotificationModule>();
			}
		}
	}
	public class NotificationData : INetSerializable
	{
		public string Title;

		public string Message;

		public int Type;

		public ulong TargetId;

		public int? GetSize()
		{
			return SizeExtensions.GetSize(Title) + SizeExtensions.GetSize(Message) + 4 + 8;
		}

		public void Serialize(INetSerializer serializer)
		{
			serializer.SerializeValue(ref Title);
			serializer.SerializeValue(ref Message);
			serializer.SerializeValue(ref Type);
			serializer.SerializeValue(ref TargetId);
		}
	}
	public class GlobalNotificationMessage : ModuleMessageHandler
	{
		protected override void OnHandleMessage(ReceivedMessage received)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			NotificationData notificationData = ((ReceivedMessage)(ref received)).ReadData<NotificationData>();
			if (notificationData.TargetId == 0L || notificationData.TargetId == PlayerIDManager.LocalPlatformID)
			{
				Notification val = new Notification
				{
					Title = NotificationText.op_Implicit(notificationData.Title),
					Message = NotificationText.op_Implicit(notificationData.Message),
					Type = (NotificationType)notificationData.Type,
					ShowTitleOnPopup = true,
					PopupLength = 3.5f
				};
				Notifier.Send(val);
			}
		}
	}
	public class NotificationModule : Module
	{
		public override string Name => "Global Notifications Receiver";

		public override string Author => "YourName";

		public override Version Version => new Version(1, 1, 0);

		public override ConsoleColor Color => ConsoleColor.Cyan;

		protected override void OnModuleRegistered()
		{
			ModuleMessageManager.RegisterHandler<GlobalNotificationMessage>();
		}
	}
}