Bonelab mods are targeting MelonLoader version 0.5.7. Newer versions will not work!, so double-check your MelonLoader version if you're having issues.
Decompiled source of LevelUtils v1.0.1
Mods/LevelUtils.dll
Decompiled 2 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BoneLib; using BoneLib.BoneMenu; using BoneLib.BoneMenu.Elements; using ExtraLevelMeta; using MelonLoader; using Newtonsoft.Json; using SLZ.Marrow.Warehouse; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("LevelUtils")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("ExtraLevelMeta")] [assembly: AssemblyCopyright("Copyright © FirEmerald 2023")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("99b28c9d-2776-4173-a30f-7faea36722e4")] [assembly: AssemblyFileVersion("1.0.1.0")] [assembly: MelonInfo(typeof(LevelUtilsMod), "Level Utils", "1.0.1", "FirEmerald", null)] [assembly: MelonGame("Stress Level Zero", "BONELAB")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.1.0")] namespace ExtraLevelMeta; public class LevelUtilsInfo { public bool reloadOnDeath; public HealthMode mortality = (HealthMode)1; public List<Waypoint> waypoints = new List<Waypoint>(); } public class LevelUtilsMod : MelonMod { internal static readonly string META_FOLDER = Path.Combine(MelonUtils.UserDataDirectory + "LevelUtils"); internal static readonly JsonSerializerSettings JSON_SETTINGS = new JsonSerializerSettings { Formatting = (Formatting)1 }; public static LevelUtilsMod instance; public static string metaFile; public static LevelUtilsInfo levelMeta = new LevelUtilsInfo(); public static MenuCategory menu; public static BoolElement reloadOnDeath; public static EnumElement<HealthMode> healthMode; public static MenuCategory newWaypointMenu; public static MenuCategory waypointsMenu; public static FunctionElement reloadMeta; public LevelUtilsMod() { instance = this; } public override void OnInitializeMelon() { //IL_0005: 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_0057: 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_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) menu = MenuManager.CreateCategory("Level Utils", Color.white); reloadOnDeath = menu.CreateBoolElement("Reload on Death", Color.white, true, (Action<bool>)delegate(bool v) { ((Component)Player.rigManager).GetComponent<Player_Health>().reloadLevelOnDeath = v; levelMeta.reloadOnDeath = v; saveMeta(); }); healthMode = menu.CreateEnumElement<HealthMode>("Mortality", Color.red, (HealthMode)1, (Action<HealthMode>)delegate(HealthMode cur) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected I4, but got Unknown //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) ((Health)((Component)Player.rigManager).GetComponent<Player_Health>()).SetHealthMode((int)cur); levelMeta.mortality = cur; saveMeta(); }); waypointsMenu = menu.CreateCategory("Waypoints", Color.white); newWaypointMenu = waypointsMenu.CreateCategory("New Waypoint", Color.white); addNewWaypointColor("white", Color.white); addNewWaypointColor("grey", Color.grey); addNewWaypointColor("black", Color.black); addNewWaypointColor("red", Color.red); addNewWaypointColor("yellow", Color.yellow); addNewWaypointColor("green", Color.green); addNewWaypointColor("cyan", Color.cyan); addNewWaypointColor("blue", Color.blue); addNewWaypointColor("magenta", Color.magenta); reloadMeta = menu.CreateFunctionElement("Reload meta", Color.white, (Action)loadMeta); Hooking.OnLevelInitialized += LevelInitialized; Hooking.OnLevelUnloaded += LevelUnloaded; } public static void addNewWaypointColor(string name, Color color) { //IL_0007: 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_0014: Unknown result type (might be due to invalid IL or missing references) newWaypointMenu.CreateFunctionElement(name, color, (Action)delegate { //IL_0001: Unknown result type (might be due to invalid IL or missing references) addWaypoint(color); if (MenuManager.ActiveCategory == newWaypointMenu) { MenuManager.SelectCategory(waypointsMenu); } }); } public static void addWaypoint(Color color) { //IL_0020: 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) Waypoint waypoint; levelMeta.waypoints.Add(waypoint = new Waypoint(Convert.ToString(levelMeta.waypoints.Count + 1), color, ((Component)Player.rigManager.animationRig).transform.position)); addWaypointToMenus(waypoint); saveMeta(); } public static void resetWaypointsMenus() { waypointsMenu.Elements.Clear(); waypointsMenu.Elements.Add((MenuElement)(object)newWaypointMenu); foreach (Waypoint waypoint in levelMeta.waypoints) { addWaypointToMenus(waypoint); } } internal static void addWaypointToMenus(Waypoint waypoint) { //IL_0029: 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_006f: Unknown result type (might be due to invalid IL or missing references) waypoint.panel = waypointsMenu.CreateSubPanel(waypoint.name, waypoint.GetColor()); waypoint.panel.CreateFunctionElement("Teleport to", Color.white, (Action)delegate { //IL_000b: Unknown result type (might be due to invalid IL or missing references) Player.rigManager.Teleport(waypoint.GetPosition(), true); }); waypoint.panel.CreateFunctionElement("Remove", Color.white, (Action)delegate { levelMeta.waypoints.Remove(waypoint); waypointsMenu.Elements.Remove((MenuElement)(object)waypoint.panel); if (MenuManager.ActiveCategory == waypointsMenu) { MenuManager.SelectCategory(waypointsMenu); } }); } internal static void LevelInitialized(LevelInfo info) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) metaFile = Path.Combine(META_FOLDER, ((Scannable)((Crate)((CrateReferenceT<LevelCrate>)(object)info.levelReference).Crate).Pallet).Title, info.barcode + ".json"); loadMeta(); } internal static void LevelUnloaded() { levelMeta.waypoints.Clear(); } internal static void saveMeta() { Log("Saving level meta to " + metaFile); string directoryName = Path.GetDirectoryName(metaFile); if (!Directory.Exists(directoryName)) { DirectoryInfo directoryInfo = Directory.CreateDirectory(directoryName); Log("Level meta folder did not exist, created at " + directoryInfo.FullName); } File.WriteAllText(metaFile, JsonConvert.SerializeObject((object)levelMeta, JSON_SETTINGS)); Log("Level meta saved."); } internal static void loadMeta() { //IL_0042: 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_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0049: 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) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Expected I4, but got Unknown levelMeta.waypoints.Clear(); Player_Health component = ((Component)Player.rigManager).GetComponent<Player_Health>(); ((GenericElement<bool>)(object)reloadOnDeath).SetValue(levelMeta.reloadOnDeath = component.reloadLevelOnDeath); ((GenericElement<HealthMode>)(object)healthMode).SetValue(levelMeta.mortality = ((Health)component).healthMode); if (File.Exists(metaFile)) { Log("Loading level meta from " + metaFile); JsonConvert.PopulateObject(File.ReadAllText(metaFile), (object)levelMeta, JSON_SETTINGS); Log("Level meta loaded."); BoolElement obj = reloadOnDeath; bool value = (component.reloadLevelOnDeath = levelMeta.reloadOnDeath); ((GenericElement<bool>)(object)obj).SetValue(value); ((GenericElement<HealthMode>)(object)healthMode).SetValue(levelMeta.mortality); ((Health)component).SetHealthMode((int)levelMeta.mortality); } resetWaypointsMenus(); } internal static void Log(string str) { ((MelonBase)instance).LoggerInstance.Msg(str); } internal static void Log(object obj) { ((MelonBase)instance).LoggerInstance.Msg(obj?.ToString() ?? "null"); } internal static void Warn(string str) { ((MelonBase)instance).LoggerInstance.Warning(str); } internal static void Warn(object obj) { ((MelonBase)instance).LoggerInstance.Warning(obj?.ToString() ?? "null"); } internal static void Error(string str) { ((MelonBase)instance).LoggerInstance.Error(str); } internal static void Error(object obj) { ((MelonBase)instance).LoggerInstance.Error(obj?.ToString() ?? "null"); } } public class Waypoint { public string name; public WaypointColor color; public WaypointPosition position; [JsonIgnore] public SubPanelElement panel; public Waypoint() { name = "unnamed"; color = new WaypointColor(); position = new WaypointPosition(); } public Waypoint(string name, Color color, Vector3 position) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) this.name = name; this.color = new WaypointColor(color); this.position = new WaypointPosition(position); } public Color GetColor() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) return color.color; } public Vector3 GetPosition() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) return position.position; } } public class WaypointColor { [JsonIgnore] public Color color; public float r { get { return color.r; } set { color.r = value; } } public float g { get { return color.g; } set { color.g = value; } } public float b { get { return color.b; } set { color.b = value; } } public WaypointColor() { //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) color = Color.white; } public WaypointColor(Color color) { //IL_0007: 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) this.color = color; } } public class WaypointPosition { [JsonIgnore] public Vector3 position; public float x { get { return position.x; } set { position.x = value; } } public float y { get { return position.y; } set { position.y = value; } } public float z { get { return position.z; } set { position.z = value; } } public WaypointPosition() { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) position = new Vector3(0f, 0f, 0f); } public WaypointPosition(Vector3 color) { //IL_0007: 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) position = color; } }