using 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 System.Text.Json;
using System.Text.Json.Serialization;
using BoneLib;
using BoneLib.BoneMenu;
using ExtraLevelMeta;
using Il2CppSLZ.Marrow;
using Il2CppSLZ.Marrow.Warehouse;
using MelonLoader;
using MelonLoader.Utils;
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.1.0")]
[assembly: MelonInfo(typeof(LevelUtilsMod), "Level Utils", "1.1.0", "FirEmerald", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyVersion("1.1.0.0")]
namespace ExtraLevelMeta;
public class LevelUtilsInfo
{
[JsonInclude]
public bool reloadOnDeath;
[JsonInclude]
public HealthMode mortality = (HealthMode)1;
[JsonInclude]
public List<Waypoint> waypoints = new List<Waypoint>();
}
public class LevelUtilsMod : MelonMod
{
internal static readonly string META_FOLDER = Path.Combine(MelonEnvironment.UserDataDirectory, "LevelUtils");
internal static readonly JsonSerializerOptions JSON_SETTINGS = new JsonSerializerOptions
{
WriteIndented = true
};
private static LevelUtilsMod instance;
private static string metaFile;
private static LevelUtilsInfo levelMeta = new LevelUtilsInfo();
private static Page menu;
private static BoolElement reloadOnDeath;
private static EnumElement healthMode;
private static Page newWaypointMenu;
private static StringElement waypointName;
private static Page waypointsMenu;
public LevelUtilsMod()
{
instance = this;
}
public override void OnInitializeMelon()
{
//IL_000a: 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_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0101: Expected O, but got Unknown
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_0168: 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)
//IL_0186: Unknown result type (might be due to invalid IL or missing references)
//IL_0195: Unknown result type (might be due to invalid IL or missing references)
//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
menu = Page.Root.CreatePage("Level Utils", Color.white, 0, true);
reloadOnDeath = menu.CreateBool("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.CreateEnum("Mortality", Color.red, (Enum)(object)(HealthMode)1, (Action<Enum>)delegate(Enum cur)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Expected I4, but got Unknown
//IL_001b: 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)
((Health)((Component)Player.RigManager).GetComponent<Player_Health>()).SetHealthMode((int)(HealthMode)(object)cur);
levelMeta.mortality = (HealthMode)(object)cur;
SaveMeta();
});
waypointsMenu = menu.CreatePage("Waypoints", Color.white, 0, true);
newWaypointMenu = waypointsMenu.CreatePage("New Waypoint", Color.white, 0, false);
PageLinkElement val = new PageLinkElement(newWaypointMenu.Name, newWaypointMenu.Color, (Action)delegate
{
string text = "New Waypoint";
HashSet<string> hashSet = new HashSet<string>(levelMeta.waypoints.Count);
foreach (Waypoint waypoint in levelMeta.waypoints)
{
hashSet.Add(waypoint.name);
}
int num = 2;
while (hashSet.Contains(text))
{
text = "New Waypoint (" + num + ")";
num++;
}
waypointName.Value = text;
Menu.OpenPage(newWaypointMenu);
});
waypointsMenu.Add((Element)(object)val);
val.AssignPage(newWaypointMenu);
waypointName = newWaypointMenu.CreateString("name", Color.white, "temp", (Action<string>)delegate
{
});
waypointName.Value = "temp";
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);
menu.CreateFunction("Reload meta", Color.white, (Action)LoadMeta);
Hooking.OnLevelLoaded += LevelLoaded;
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.CreateFunction(name, color, (Action)delegate
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
AddWaypoint(color, waypointName.Value);
if (Menu.CurrentPage == newWaypointMenu)
{
Menu.OpenPage(waypointsMenu);
}
});
}
public static void AddWaypoint(Color color, string name)
{
//IL_000b: 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)
Waypoint waypoint;
levelMeta.waypoints.Add(waypoint = new Waypoint(name, color, ((Component)Player.RigManager.animationRig).transform.position));
AddWaypointToMenus(waypoint);
SaveMeta();
}
public static void ResetWaypointsMenus()
{
while (waypointsMenu.ElementCount > 1)
{
waypointsMenu.Remove(waypointsMenu.Elements[1]);
}
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_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
waypoint.elements[0] = (Element)(object)waypointsMenu.CreateString("Waypoint", waypoint.GetColor(), waypoint.name, (Action<string>)delegate(string newName)
{
waypoint.name = newName;
waypoint.elements[1].ElementName = "Teleport to " + waypoint.name;
waypoint.elements[2].ElementName = "Remove " + waypoint.name;
SaveMeta();
});
((StringElement)waypoint.elements[0]).Value = waypoint.name;
waypoint.elements[1] = (Element)(object)waypointsMenu.CreateFunction("Teleport to " + waypoint.name, waypoint.GetColor(), (Action)delegate
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
Player.RigManager.Teleport(waypoint.GetPosition(), true);
});
waypoint.elements[2] = (Element)(object)waypointsMenu.CreateFunction("Remove " + waypoint.name, waypoint.GetColor(), (Action)delegate
{
levelMeta.waypoints.Remove(waypoint);
waypointsMenu.Remove(waypoint.elements);
if (Menu.CurrentPage == waypointsMenu)
{
Menu.OpenPage(waypointsMenu);
}
});
}
internal static void LevelLoaded(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, JsonSerializer.Serialize(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_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Expected I4, but got Unknown
levelMeta.waypoints.Clear();
Player_Health component = ((Component)Player.RigManager).GetComponent<Player_Health>();
reloadOnDeath.Value = (levelMeta.reloadOnDeath = component.reloadLevelOnDeath);
healthMode.Value = (Enum)(object)(levelMeta.mortality = ((Health)component).healthMode);
if (File.Exists(metaFile))
{
Log("Loading level meta from " + metaFile);
levelMeta = JsonSerializer.Deserialize<LevelUtilsInfo>(File.ReadAllText(metaFile), JSON_SETTINGS);
Log("Level meta loaded.");
BoolElement obj = reloadOnDeath;
bool value = (component.reloadLevelOnDeath = levelMeta.reloadOnDeath);
obj.Value = value;
healthMode.Value = (Enum)(object)levelMeta.mortality;
((Health)component).SetHealthMode((int)levelMeta.mortality);
}
ResetWaypointsMenus();
}
internal static void Log(string str)
{
((MelonBase)instance).LoggerInstance.Msg(str);
}
internal static void Log(string str, Exception ex)
{
((MelonBase)instance).LoggerInstance.Msg(str, new object[1] { ex });
}
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(string str, Exception ex)
{
((MelonBase)instance).LoggerInstance.Warning(str, new object[1] { ex });
}
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(string str, Exception ex)
{
((MelonBase)instance).LoggerInstance.Error(str, ex);
}
internal static void Error(object obj)
{
((MelonBase)instance).LoggerInstance.Error(obj?.ToString() ?? "null");
}
}
public class Waypoint
{
[JsonInclude]
public string name;
[JsonInclude]
public WaypointColor color;
[JsonInclude]
public WaypointPosition position;
[JsonIgnore]
public Element[] elements = (Element[])(object)new Element[3];
public Waypoint()
{
name = "unnamed";
color = new WaypointColor();
position = new WaypointPosition();
}
public Waypoint(string name, Color color, Vector3 position)
{
//IL_001a: 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)
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;
[JsonInclude]
public float r
{
get
{
return color.r;
}
set
{
color.r = value;
}
}
[JsonInclude]
public float g
{
get
{
return color.g;
}
set
{
color.g = value;
}
}
[JsonInclude]
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;
[JsonInclude]
public float x
{
get
{
return position.x;
}
set
{
position.x = value;
}
}
[JsonInclude]
public float y
{
get
{
return position.y;
}
set
{
position.y = value;
}
}
[JsonInclude]
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;
}
}