using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BoneLib;
using BoneLib.BoneMenu;
using BoneLib.BoneMenu.Elements;
using BoneLib.Notifications;
using LabFusion.Network;
using MelonLoader;
using MelonLoader.Preferences;
using SLZ.Marrow.Pool;
using SLZ.Marrow.Warehouse;
using TheJanitor;
using TheJanitor.Melon;
using TheJanitor.Menu;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("A spawnable cleaner.")]
[assembly: AssemblyDescription("A spawnable cleaner.")]
[assembly: AssemblyCompany("Weather Electric")]
[assembly: AssemblyProduct("TheJanitor")]
[assembly: AssemblyCopyright("Developed by SoulWithMae")]
[assembly: AssemblyTrademark("Weather Electric")]
[assembly: AssemblyFileVersion("1.1.0")]
[assembly: MelonInfo(typeof(Main), "TheJanitor", "1.1.0", "SoulWithMae", "https://bonelab.thunderstore.io/package/SoulWithMae/TheJanitor/")]
[assembly: MelonColor(ConsoleColor.Yellow)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: MelonOptionalDependencies(new string[] { "LabFusion", "labfusion" })]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.1.0.0")]
namespace TheJanitor
{
public class Main : MelonMod
{
internal const string Name = "TheJanitor";
internal const string Description = "A spawnable cleaner.";
internal const string Author = "SoulWithMae";
internal const string Company = "Weather Electric";
internal const string Version = "1.1.0";
internal const string DownloadLink = "https://bonelab.thunderstore.io/package/SoulWithMae/TheJanitor/";
internal static bool FusionInstalled { get; private set; }
public override void OnInitializeMelon()
{
ModConsole.Setup(((MelonBase)this).LoggerInstance);
Preferences.Setup();
BoneMenu.Setup();
FusionInstalled = HelperMethods.CheckIfAssemblyLoaded("labfusion");
}
}
internal static class Janitor
{
internal enum ClearType
{
Everything,
Npcs,
Guns,
Melee,
Props,
Decals
}
private static ClearType _clearType = ClearType.Everything;
private static Notification EverythingCleared { get; } = new Notification
{
Title = NotificationText.op_Implicit("The Janitor"),
Message = NotificationText.op_Implicit("Cleared every spawnable!"),
Type = (NotificationType)3,
PopupLength = 1f,
ShowTitleOnPopup = true
};
private static Notification NpcsCleared { get; } = new Notification
{
Title = NotificationText.op_Implicit("The Janitor"),
Message = NotificationText.op_Implicit("Cleared all NPCs!"),
Type = (NotificationType)3,
PopupLength = 1f,
ShowTitleOnPopup = true
};
private static Notification GunsCleared { get; } = new Notification
{
Title = NotificationText.op_Implicit("The Janitor"),
Message = NotificationText.op_Implicit("Cleared all guns!"),
Type = (NotificationType)3,
PopupLength = 1f,
ShowTitleOnPopup = true
};
private static Notification MeleeCleared { get; } = new Notification
{
Title = NotificationText.op_Implicit("The Janitor"),
Message = NotificationText.op_Implicit("Cleared all melee!"),
Type = (NotificationType)3,
PopupLength = 1f,
ShowTitleOnPopup = true
};
private static Notification PropsCleared { get; } = new Notification
{
Title = NotificationText.op_Implicit("The Janitor"),
Message = NotificationText.op_Implicit("Cleared all props!"),
Type = (NotificationType)3,
PopupLength = 1f,
ShowTitleOnPopup = true
};
private static Notification DecalsCleared { get; } = new Notification
{
Title = NotificationText.op_Implicit("The Janitor"),
Message = NotificationText.op_Implicit("Cleared all decals!"),
Type = (NotificationType)3,
PopupLength = 1f,
ShowTitleOnPopup = true
};
private static Notification InFusionServer { get; } = new Notification
{
Title = NotificationText.op_Implicit("The Janitor"),
Message = NotificationText.op_Implicit("You are in a fusion server! This would cause desync. Not doing it."),
Type = (NotificationType)2,
PopupLength = 1f,
ShowTitleOnPopup = true
};
public static void UpdateType(ClearType clearType)
{
_clearType = clearType;
}
public static void Clear()
{
if (Main.FusionInstalled && !Preferences.OverrideFusionCheck.Value && (NetworkInfo.IsClient || NetworkInfo.IsServer) && _clearType != ClearType.Decals)
{
Notifier.Send(InFusionServer);
return;
}
switch (_clearType)
{
case ClearType.Everything:
ClearEverything();
break;
case ClearType.Npcs:
ClearNPCs();
break;
case ClearType.Guns:
ClearGuns();
break;
case ClearType.Melee:
ClearMelee();
break;
case ClearType.Props:
ClearProps();
break;
case ClearType.Decals:
ClearDecals();
break;
default:
ModConsole.Error("Invalid clear type!");
break;
}
}
private static void ClearEverything()
{
foreach (AssetPoolee item in Object.FindObjectsOfType<AssetPoolee>())
{
if (Barcode.op_Implicit(((Scannable)item.spawnableCrate).Barcode) == "SLZ.BONELAB.Core.DefaultPlayerRig")
{
return;
}
item.Despawn();
}
Notifier.Send(EverythingCleared);
}
private static void ClearNPCs()
{
foreach (AssetPoolee item in Object.FindObjectsOfType<AssetPoolee>())
{
if (((Crate)item.spawnableCrate).Tags.Contains("NPC"))
{
item.Despawn();
}
}
Notifier.Send(NpcsCleared);
}
private static void ClearGuns()
{
foreach (AssetPoolee item in Object.FindObjectsOfType<AssetPoolee>())
{
if (((Crate)item.spawnableCrate).Tags.Contains("Gun"))
{
item.Despawn();
}
}
Notifier.Send(GunsCleared);
}
private static void ClearMelee()
{
foreach (AssetPoolee item in Object.FindObjectsOfType<AssetPoolee>())
{
if (((Crate)item.spawnableCrate).Tags.Contains("Melee"))
{
item.Despawn();
}
}
Notifier.Send(MeleeCleared);
}
private static void ClearProps()
{
foreach (AssetPoolee item in Object.FindObjectsOfType<AssetPoolee>())
{
if (((Crate)item.spawnableCrate).Tags.Contains("Prop"))
{
item.Despawn();
}
}
Notifier.Send(PropsCleared);
}
private static void ClearDecals()
{
foreach (AssetPoolee item in Object.FindObjectsOfType<AssetPoolee>())
{
if (((Crate)item.spawnableCrate).Tags.Contains("Decal"))
{
item.Despawn();
}
}
Notifier.Send(DecalsCleared);
}
}
}
namespace TheJanitor.Melon
{
internal static class ModConsole
{
private static Instance _logger;
public static void Setup(Instance loggerInstance)
{
_logger = loggerInstance;
}
public static void Msg(object obj, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? $"[DEBUG] {obj}" : obj.ToString());
ConsoleColor consoleColor = ((loggingMode == 1) ? ConsoleColor.Yellow : ConsoleColor.Gray);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Msg(consoleColor, text);
}
}
public static void Msg(string txt, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
ConsoleColor consoleColor = ((loggingMode == 1) ? ConsoleColor.Yellow : ConsoleColor.Gray);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Msg(consoleColor, text);
}
}
public static void Msg(ConsoleColor txtcolor, object obj, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? $"[DEBUG] {obj}" : obj.ToString());
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Msg(txtcolor, text);
}
}
public static void Msg(ConsoleColor txtcolor, string txt, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Msg(txtcolor, text);
}
}
public static void Msg(string txt, int loggingMode = 0, params object[] args)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
ConsoleColor consoleColor = ((loggingMode == 1) ? ConsoleColor.Yellow : ConsoleColor.Gray);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Msg(consoleColor, text, args);
}
}
public static void Msg(ConsoleColor txtcolor, string txt, int loggingMode = 0, params object[] args)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Msg(txtcolor, text, args);
}
}
public static void Error(object obj, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? $"[DEBUG] {obj}" : obj.ToString());
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Error(text);
}
}
public static void Error(string txt, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Error(text);
}
}
public static void Error(string txt, int loggingMode = 0, params object[] args)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Error(text, args);
}
}
public static void Warning(object obj, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? $"[DEBUG] {obj}" : obj.ToString());
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Warning(text);
}
}
public static void Warning(string txt, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Warning(text);
}
}
public static void Warning(string txt, int loggingMode = 0, params object[] args)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Warning(text, args);
}
}
}
internal static class Preferences
{
public static readonly MelonPreferences_Category GlobalCategory = MelonPreferences.CreateCategory("Global");
public static readonly MelonPreferences_Category OwnCategory = MelonPreferences.CreateCategory("TheJanitor");
public static MelonPreferences_Entry<int> LoggingMode { get; set; }
public static MelonPreferences_Entry<bool> OverrideFusionCheck { get; set; }
public static void Setup()
{
LoggingMode = GlobalCategory.GetEntry<int>("LoggingMode") ?? GlobalCategory.CreateEntry<int>("LoggingMode", 0, "Logging Mode", "The level of logging to use. 0 = Important Only, 1 = All", false, false, (ValueValidator)null, (string)null);
GlobalCategory.SetFilePath(MelonUtils.UserDataDirectory + "/WeatherElectric.cfg");
GlobalCategory.SaveToFile(false);
OverrideFusionCheck = OwnCategory.GetEntry<bool>("OverrideFusionCheck") ?? OwnCategory.CreateEntry<bool>("OverrideFusionCheck", false, "Override Fusion Check", "Whether or not to override the Fusion check. This is not recommended, as it causes desync.", false, false, (ValueValidator)null, (string)null);
OwnCategory.SetFilePath(MelonUtils.UserDataDirectory + "/WeatherElectric.cfg");
OwnCategory.SaveToFile(false);
ModConsole.Msg("Finished preferences setup for TheJanitor", 1);
}
}
}
namespace TheJanitor.Menu
{
internal static class BoneMenu
{
public static void Setup()
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: 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_005e: Unknown result type (might be due to invalid IL or missing references)
MenuCategory obj = MenuManager.CreateCategory("Weather Electric", "#6FBDFF").CreateCategory("The Janitor", Color.blue);
obj.CreateEnumElement<Janitor.ClearType>("Clear Type", Color.white, Janitor.ClearType.Everything, (Action<Janitor.ClearType>)Janitor.UpdateType);
obj.CreateFunctionElement("Clear", Color.white, (Action)Janitor.Clear);
obj.CreateBoolPreference("Override Fusion Check", Color.red, Preferences.OverrideFusionCheck, Preferences.OwnCategory);
}
}
internal static class BoneMenuExtensions
{
public static BoolElement CreateBoolPreference(this MenuCategory category, string name, Color color, MelonPreferences_Entry<bool> pref, MelonPreferences_Category prefCategory, bool autoSave = true)
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
return category.CreateBoolElement(name, color, pref.Value, (Action<bool>)delegate(bool v)
{
pref.Value = v;
if (autoSave)
{
prefCategory.SaveToFile(false);
}
});
}
public static BoolElement CreateBoolPreference(this MenuCategory category, string name, string hexColor, MelonPreferences_Entry<bool> pref, MelonPreferences_Category prefCategory, bool autoSave = true)
{
return category.CreateBoolElement(name, hexColor, pref.Value, (Action<bool>)delegate(bool v)
{
pref.Value = v;
if (autoSave)
{
prefCategory.SaveToFile(false);
}
});
}
public static BoolElement CreateBoolPreference(this SubPanelElement category, string name, Color color, MelonPreferences_Entry<bool> pref, MelonPreferences_Category prefCategory, bool autoSave = true)
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
return category.CreateBoolElement(name, color, pref.Value, (Action<bool>)delegate(bool v)
{
pref.Value = v;
if (autoSave)
{
prefCategory.SaveToFile(false);
}
});
}
public static BoolElement CreateBoolPreference(this SubPanelElement category, string name, string hexColor, MelonPreferences_Entry<bool> pref, MelonPreferences_Category prefCategory, bool autoSave = true)
{
return category.CreateBoolElement(name, hexColor, pref.Value, (Action<bool>)delegate(bool v)
{
pref.Value = v;
if (autoSave)
{
prefCategory.SaveToFile(false);
}
});
}
public static FloatElement CreateFloatPreference(this MenuCategory category, string name, Color color, float increment, float min, float max, MelonPreferences_Entry<float> pref, MelonPreferences_Category prefCategory, bool autoSave = true)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
return category.CreateFloatElement(name, color, pref.Value, increment, min, max, (Action<float>)delegate(float v)
{
pref.Value = v;
if (autoSave)
{
prefCategory.SaveToFile(false);
}
});
}
public static FloatElement CreateFloatPreference(this MenuCategory category, string name, string hexColor, float increment, float min, float max, MelonPreferences_Entry<float> pref, MelonPreferences_Category prefCategory, bool autoSave = true)
{
return category.CreateFloatElement(name, hexColor, pref.Value, increment, min, max, (Action<float>)delegate(float v)
{
pref.Value = v;
if (autoSave)
{
prefCategory.SaveToFile(false);
}
});
}
public static FloatElement CreateFloatPreference(this SubPanelElement category, string name, Color color, float increment, float min, float max, MelonPreferences_Entry<float> pref, MelonPreferences_Category prefCategory, bool autoSave = true)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
return category.CreateFloatElement(name, color, pref.Value, increment, min, max, (Action<float>)delegate(float v)
{
pref.Value = v;
if (autoSave)
{
prefCategory.SaveToFile(false);
}
});
}
public static FloatElement CreateFloatPreference(this SubPanelElement category, string name, string hexColor, float increment, float min, float max, MelonPreferences_Entry<float> pref, MelonPreferences_Category prefCategory, bool autoSave = true)
{
return category.CreateFloatElement(name, hexColor, pref.Value, increment, min, max, (Action<float>)delegate(float v)
{
pref.Value = v;
if (autoSave)
{
prefCategory.SaveToFile(false);
}
});
}
public static IntElement CreateIntPreference(this MenuCategory category, string name, Color color, int increment, int min, int max, MelonPreferences_Entry<int> pref, MelonPreferences_Category prefCategory, bool autoSave = true)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
return category.CreateIntElement(name, color, pref.Value, increment, min, max, (Action<int>)delegate(int v)
{
pref.Value = v;
if (autoSave)
{
prefCategory.SaveToFile(false);
}
});
}
public static IntElement CreateIntPreference(this MenuCategory category, string name, string hexColor, int increment, int min, int max, MelonPreferences_Entry<int> pref, MelonPreferences_Category prefCategory, bool autoSave = true)
{
return category.CreateIntElement(name, hexColor, pref.Value, increment, min, max, (Action<int>)delegate(int v)
{
pref.Value = v;
if (autoSave)
{
prefCategory.SaveToFile(false);
}
});
}
public static IntElement CreateIntPreference(this SubPanelElement category, string name, Color color, int increment, int min, int max, MelonPreferences_Entry<int> pref, MelonPreferences_Category prefCategory, bool autoSave = true)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
return category.CreateIntElement(name, color, pref.Value, increment, min, max, (Action<int>)delegate(int v)
{
pref.Value = v;
if (autoSave)
{
prefCategory.SaveToFile(false);
}
});
}
public static IntElement CreateIntPreference(this SubPanelElement category, string name, string hexColor, int increment, int min, int max, MelonPreferences_Entry<int> pref, MelonPreferences_Category prefCategory, bool autoSave = true)
{
return category.CreateIntElement(name, hexColor, pref.Value, increment, min, max, (Action<int>)delegate(int v)
{
pref.Value = v;
if (autoSave)
{
prefCategory.SaveToFile(false);
}
});
}
public static EnumElement<TEnum> CreateEnumPreference<TEnum>(this MenuCategory category, string name, Color color, MelonPreferences_Entry<TEnum> pref, MelonPreferences_Category prefCategory, bool autoSave = true) where TEnum : Enum
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
return category.CreateEnumElement<TEnum>(name, color, pref.Value, (Action<TEnum>)delegate(TEnum v)
{
pref.Value = v;
if (autoSave)
{
prefCategory.SaveToFile(false);
}
});
}
public static EnumElement<TEnum> CreateEnumPreference<TEnum>(this MenuCategory category, string name, string hexColor, MelonPreferences_Entry<TEnum> pref, MelonPreferences_Category prefCategory, bool autoSave = true) where TEnum : Enum
{
return category.CreateEnumElement<TEnum>(name, hexColor, pref.Value, (Action<TEnum>)delegate(TEnum v)
{
pref.Value = v;
if (autoSave)
{
prefCategory.SaveToFile(false);
}
});
}
public static EnumElement<TEnum> CreateEnumPreference<TEnum>(this SubPanelElement category, string name, Color color, MelonPreferences_Entry<TEnum> pref, MelonPreferences_Category prefCategory, bool autoSave = true) where TEnum : Enum
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
return category.CreateEnumElement<TEnum>(name, color, pref.Value, (Action<TEnum>)delegate(TEnum v)
{
pref.Value = v;
if (autoSave)
{
prefCategory.SaveToFile(false);
}
});
}
public static EnumElement<TEnum> CreateEnumPreference<TEnum>(this SubPanelElement category, string name, string hexColor, MelonPreferences_Entry<TEnum> pref, MelonPreferences_Category prefCategory, bool autoSave = true) where TEnum : Enum
{
return category.CreateEnumElement<TEnum>(name, hexColor, pref.Value, (Action<TEnum>)delegate(TEnum v)
{
pref.Value = v;
if (autoSave)
{
prefCategory.SaveToFile(false);
}
});
}
}
}