using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BoneLib.BoneMenu;
using FusionSilenceJoinLeave;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(MainMod), "FusionSilenceJoinLeave", "1.0.0", "AI", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: MelonOptionalDependencies(new string[] { "BoneLib", "LabFusion" })]
[assembly: MelonColor(255, 64, 180, 255)]
[assembly: MelonAuthorColor(255, 120, 220, 255)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("FusionSilenceJoinLeave")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FusionSilenceJoinLeave")]
[assembly: AssemblyTitle("FusionSilenceJoinLeave")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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]
[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]
[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 FusionSilenceJoinLeave
{
internal static class BoneMenuIntegration
{
[MethodImpl(MethodImplOptions.NoInlining)]
internal static void SetupMenu()
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
Page obj = Page.Root.CreatePage("Fusion Silence", Color.cyan, 0, true);
obj.CreateBool("Block Player Joined", Color.white, MainMod.MutePlayerJoined.Value, (Action<bool>)delegate(bool val)
{
MainMod.MutePlayerJoined.Value = val;
MainMod.PrefCategory.SaveToFile(true);
});
obj.CreateBool("Block Player Left", Color.white, MainMod.MutePlayerLeft.Value, (Action<bool>)delegate(bool val)
{
MainMod.MutePlayerLeft.Value = val;
MainMod.PrefCategory.SaveToFile(true);
});
obj.CreateBool("Block Server Joined", Color.white, MainMod.MuteServerJoined.Value, (Action<bool>)delegate(bool val)
{
MainMod.MuteServerJoined.Value = val;
MainMod.PrefCategory.SaveToFile(true);
});
obj.CreateBool("Block Server Disconnect", Color.white, MainMod.MuteServerDisconnected.Value, (Action<bool>)delegate(bool val)
{
MainMod.MuteServerDisconnected.Value = val;
MainMod.PrefCategory.SaveToFile(true);
});
}
}
public class MainMod : MelonMod
{
public static MelonPreferences_Category PrefCategory { get; private set; }
public static MelonPreferences_Entry<bool> MutePlayerJoined { get; private set; }
public static MelonPreferences_Entry<bool> MutePlayerLeft { get; private set; }
public static MelonPreferences_Entry<bool> MuteServerJoined { get; private set; }
public static MelonPreferences_Entry<bool> MuteServerDisconnected { get; private set; }
public override void OnInitializeMelon()
{
PrefCategory = MelonPreferences.CreateCategory("FusionSilenceJoinLeave", "Fusion Silence Notifications");
MutePlayerJoined = PrefCategory.CreateEntry<bool>("MutePlayerJoined", true, "Mute Player Joined", "Mute popups when players join the server", false, false, (ValueValidator)null, (string)null);
MutePlayerLeft = PrefCategory.CreateEntry<bool>("MutePlayerLeft", true, "Mute Player Left", "Mute popups when players leave the server", false, false, (ValueValidator)null, (string)null);
MuteServerJoined = PrefCategory.CreateEntry<bool>("MuteServerJoined", false, "Mute Server Joined", "Mute popup when joining a server", false, false, (ValueValidator)null, (string)null);
MuteServerDisconnected = PrefCategory.CreateEntry<bool>("MuteServerDisconnected", false, "Mute Server Disconnected", "Mute popup when disconnected from a server", false, false, (ValueValidator)null, (string)null);
MelonLogger.Msg("Preferences initialized.");
}
public override void OnLateInitializeMelon()
{
ApplyPatches();
TryInitBoneMenu();
}
private void ApplyPatches()
{
try
{
Type type = AccessTools.TypeByName("LabFusion.Network.NetworkNotifications");
if (type != null)
{
PatchMethod(type, "SendPlayerJoinedNotification", "Prefix_PlayerJoined", new Type[1] { typeof(string) });
PatchMethod(type, "SendPlayerLeftNotification", "Prefix_PlayerLeft", new Type[1] { typeof(string) });
PatchMethod(type, "SendJoinedServerNotification", "Prefix_ServerJoined", Type.EmptyTypes);
PatchMethod(type, "SendDisconnectedNotification", "Prefix_ServerDisconnected_NoArg", Type.EmptyTypes);
PatchMethod(type, "SendDisconnectedNotification", "Prefix_ServerDisconnected_Reason", new Type[1] { typeof(string) });
MelonLogger.Msg("LabFusion notification hooks applied successfully!");
}
else
{
MelonLogger.Warning("LabFusion not found! Notifications cannot be hooked.");
}
}
catch (Exception value)
{
MelonLogger.Error($"Error while hooking LabFusion: {value}");
}
}
private void PatchMethod(Type targetType, string methodName, string patchMethodName, Type[]? parameters)
{
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Expected O, but got Unknown
try
{
MethodInfo methodInfo = ((parameters != null) ? AccessTools.Method(targetType, methodName, parameters, (Type[])null) : AccessTools.Method(targetType, methodName, (Type[])null, (Type[])null));
if (methodInfo == null)
{
MelonLogger.Warning($"Target method '{methodName}' not found on {targetType.FullName}.");
}
else
{
HarmonyMethod val = new HarmonyMethod(typeof(Patches).GetMethod(patchMethodName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic));
((MelonBase)this).HarmonyInstance.Patch((MethodBase)methodInfo, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
MelonLogger.Msg($"Hooked: {targetType.Name}.{methodName} -> {patchMethodName}");
}
}
catch (Exception value)
{
MelonLogger.Error($"Failed to patch {methodName}: {value}");
}
}
private void TryInitBoneMenu()
{
try
{
if (AppDomain.CurrentDomain.GetAssemblies().Any((Assembly a) => a.GetName().Name == "BoneLib"))
{
BoneMenuIntegration.SetupMenu();
MelonLogger.Msg("BoneMenu integration initialized successfully!");
}
}
catch (Exception ex)
{
MelonLogger.Warning("BoneMenu integration could not be loaded: " + ex.Message);
}
}
}
public static class Patches
{
public static bool Prefix_PlayerJoined(string name)
{
if (MainMod.MutePlayerJoined != null && MainMod.MutePlayerJoined.Value)
{
return false;
}
return true;
}
public static bool Prefix_PlayerLeft(string name)
{
if (MainMod.MutePlayerLeft != null && MainMod.MutePlayerLeft.Value)
{
return false;
}
return true;
}
public static bool Prefix_ServerJoined()
{
if (MainMod.MuteServerJoined != null && MainMod.MuteServerJoined.Value)
{
return false;
}
return true;
}
public static bool Prefix_ServerDisconnected_NoArg()
{
if (MainMod.MuteServerDisconnected != null && MainMod.MuteServerDisconnected.Value)
{
return false;
}
return true;
}
public static bool Prefix_ServerDisconnected_Reason(string reason)
{
if (MainMod.MuteServerDisconnected != null && MainMod.MuteServerDisconnected.Value)
{
return false;
}
return true;
}
}
}