using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.Json;
using BoneLib;
using BoneLib.BoneMenu;
using BoneLib.Notifications;
using FavoriteSwapper;
using Il2CppSLZ.Bonelab.SaveData;
using Il2CppSLZ.Marrow.SaveData;
using Il2CppSLZ.Marrow.Warehouse;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using MelonLoader.Utils;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyDescription("Hot swapper for spawn gun favorites")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyCopyright("Developed by doge15567")]
[assembly: AssemblyTrademark("")]
[assembly: MelonInfo(typeof(Main), "Favorite Swapper", "1.0.0", "doge15567", "https://thunderstore.io/c/bonelab/p/doge15567/FavoriteSwapper")]
[assembly: MelonColor(255, 255, 222, 145)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace FavoriteSwapper;
internal class Bonemenu
{
private static Page _mainCategory;
private static Page _presetCategory;
public static PresetManager _presetManager = new PresetManager();
public static Color maincolor = Color32.op_Implicit(new Color32(byte.MaxValue, (byte)222, (byte)145, byte.MaxValue));
public static void BonemenuSetup()
{
//IL_0014: 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_0063: Unknown result type (might be due to invalid IL or missing references)
_presetManager.OnStart();
_mainCategory = Page.Root.CreatePage("Favorite Swapper", maincolor, 0, true);
_mainCategory.CreateFunction("Reload Presets from File", Color.yellow, (Action)delegate
{
_presetManager.LoadPresets();
RebuildBonemenu();
});
_presetCategory = _mainCategory.CreatePage("Presets", Color.white, 0, true);
}
public static void BoneMenuNotif(NotificationType type, string content)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: 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_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Expected O, but got Unknown
Notifier.Send(new Notification
{
Title = NotificationText.op_Implicit("Favorite Swapper"),
Message = NotificationText.op_Implicit(content),
Type = type,
PopupLength = 3f,
ShowTitleOnPopup = true
});
}
public static void RebuildBonemenu()
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
if (_presetCategory != null)
{
_presetCategory.RemoveAll();
}
_presetManager.CheckForDefaultPreset();
_presetCategory.CreateFunction("Create New Preset", Color.green, (Action)delegate
{
string presetName = "Preset " + _presetManager.GetNumberOfPresets();
_presetManager.LoadPresets();
if (_presetManager.CreateNewPreset(presetName))
{
CreatePresetCatagory(_presetCategory, presetName);
}
});
foreach (KeyValuePair<string, List<string>> preset in _presetManager.presets)
{
CreatePresetCatagory(_presetCategory, preset.Key);
}
}
public static void CreatePresetCatagory(Page category, string presetName)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: 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_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: 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)
Page val = category.CreatePage(presetName, Color.white, 0, true);
List<string> presetData = _presetManager.GetPresetData(presetName);
val.CreateFunction(presetName, Color.white, (Action)delegate
{
});
string newnamestring = presetName;
if (presetName != "DEFAULT")
{
val.CreateString("Rename Preset", Color.white, presetName, (Action<string>)delegate(string s)
{
newnamestring = s;
});
val.CreateFunction("Apply New Name", Color.white, (Action)delegate
{
if (newnamestring != null && !(newnamestring == ""))
{
Menu.DisplayDialog("Rename Preset", "Are you sure you want to rename this preset?", (Texture2D)null, (Action)delegate
{
if (!_presetManager.presets.ContainsKey(newnamestring))
{
_presetManager.RemovePreset(presetName);
_presetManager.presets.Add(newnamestring, presetData);
_presetManager.SavePresets();
RebuildBonemenu();
Menu.OpenPage(_presetCategory);
}
else
{
BoneMenuNotif((NotificationType)2, $"Error renaming preset {presetName} to {newnamestring}, as a preset of name {newnamestring} already exists!");
}
}, (Action)null);
}
});
}
val.CreateFunction("Apply Preset", Color.cyan, (Action)delegate
{
Menu.DisplayDialog("Apply Preset", "Are you sure you want to overwrite your favorited spawnables with this preset?", (Texture2D)null, (Action)delegate
{
_presetManager.LoadPresets();
Main.SetFavoriteSpawnables(_presetManager.GetPresetData(presetName).ToArray());
}, (Action)null);
});
if (presetName != "DEFAULT")
{
val.CreateFunction("Remove Preset", Color.red, (Action)delegate
{
Menu.DisplayDialog("Remove Preset", "Are you sure you want to delete this preset?", (Texture2D)null, (Action)delegate
{
_presetManager.RemovePreset(presetName);
_presetManager.SavePresets();
RebuildBonemenu();
Menu.OpenPage(_presetCategory);
}, (Action)null);
});
}
val.CreateFunction("Set Preset Content", Color.white, (Action)delegate
{
Menu.DisplayDialog("Apply Preset", "Are you sure you want to overwrite this preset with your favorited spawnables?", (Texture2D)null, (Action)delegate
{
List<string> currentFavorites = Main.GetCurrentFavorites();
_presetManager.presets[presetName] = Main.IL2CppListToList<string>(currentFavorites);
_presetManager.SavePresets();
RebuildBonemenu();
Menu.OpenPage(_presetCategory);
}, (Action)null);
});
foreach (string presetDatum in _presetManager.GetPresetData(presetName))
{
CreatePBarcodeCatagory(val, presetDatum);
}
}
public static void CreatePBarcodeCatagory(Page category, string Barcode)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected O, but got Unknown
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
Crate val = default(Crate);
string text = (AssetWarehouse.Instance.TryGetCrate(new Barcode
{
ID = Barcode
}, ref val) ? ((Scannable)val).Title : Barcode);
Page val2 = category.CreatePage(text, Color.white, 0, false);
category.CreatePageLink(val2);
val2.CreateFunction(text, Color.white, (Action)delegate
{
});
val2.CreateFunction(Barcode, Color.white, (Action)delegate
{
});
}
}
internal class Main : MelonMod
{
internal const string Name = "Favorite Swapper";
internal const string Description = "Hot swapper for spawn gun favorites";
internal const string Author = "doge15567";
internal const string Company = "";
internal const string Version = "1.0.0";
internal const string DownloadLink = "https://thunderstore.io/c/bonelab/p/doge15567/FavoriteSwapper";
internal static Instance MelonLog;
public static PresetManager _presetManager = new PresetManager();
public override void OnInitializeMelon()
{
MelonLog = ((MelonBase)this).LoggerInstance;
MelonLog.Msg("Initalised Mod");
_presetManager.OnStart();
Bonemenu.BonemenuSetup();
Hooking.OnMarrowGameStarted += OnMarrowGameStartedHook;
}
public static void OnMarrowGameStartedHook()
{
Bonemenu.RebuildBonemenu();
SetFavoriteSpawnables(Bonemenu._presetManager.presets["DEFAULT"].ToArray());
}
public static void SetCheatMenuItems(string[] BarcodeStrArray)
{
}
public static void SetFavoriteSpawnables(string[] BarcodeStrArray)
{
DataManager.ActiveSave._PlayerSettings_k__BackingField._FavoriteSpawnables_k__BackingField = ListToIL2CppList(BarcodeStrArray.ToList());
DataManager.TrySaveActiveSave((SaveFlags)0);
}
public static List<string> GetCurrentFavorites()
{
return DataManager.ActiveSave._PlayerSettings_k__BackingField._FavoriteSpawnables_k__BackingField;
}
public static List<T> ListToIL2CppList<T>(List<T> inList)
{
List<T> val = new List<T>();
foreach (T @in in inList)
{
val.Add(@in);
}
return val;
}
public static List<T> IL2CppListToList<T>(List<T> inList)
{
List<T> list = new List<T>();
Enumerator<T> enumerator = inList.GetEnumerator();
while (enumerator.MoveNext())
{
T current = enumerator.Current;
list.Add(current);
}
return list;
}
}
public class PresetManager
{
public Dictionary<string, List<string>> presets;
private string filePath = MelonEnvironment.UserDataDirectory + "/FavoriteSwapper.json";
public readonly Dictionary<string, List<string>> DefaultJsonDict = new Dictionary<string, List<string>> {
{
"DEFAULT",
new List<string> { "c1534c5a-5747-42a2-bd08-ab3b47616467", "c1534c5a-6b38-438a-a324-d7e147616467", "c1534c5a-3813-49d6-a98c-f595436f6e73", "c1534c5a-c6a8-45d0-aaa2-2c954465764d" }
} };
private JsonSerializerOptions prettyPrint = new JsonSerializerOptions
{
WriteIndented = true
};
public void OnStart()
{
LoadPresets();
SavePresets();
}
public void LoadPresets()
{
if (File.Exists(filePath))
{
string json = File.ReadAllText(filePath);
presets = JsonSerializer.Deserialize<Dictionary<string, List<string>>>(json);
}
else
{
presets = DefaultJsonDict;
SavePresets();
}
}
public void SavePresets()
{
string contents = JsonSerializer.Serialize(presets, prettyPrint);
File.WriteAllText(filePath, contents);
}
public void CheckForDefaultPreset()
{
if (!presets.ContainsKey("DEFAULT"))
{
presets.Add("DEFAULT", Main.IL2CppListToList<string>(Main.GetCurrentFavorites()));
SavePresets();
}
}
public void AddBarcodeToPreset(string presetName, string barcode)
{
if (presets.ContainsKey(presetName))
{
presets[presetName].Add(barcode);
SavePresets();
}
else
{
Main.MelonLog.Error("Function AddBarcodeToPreset: Attempted to add a barcode to a preset that doesnt exist. (?????????)");
}
}
public void RemoveBarcodeFromPreset(string presetName, string barcode)
{
if (presets.ContainsKey(presetName))
{
presets[presetName].Remove(barcode);
SavePresets();
}
else
{
Main.MelonLog.Error("Function RemoveBarcodeToPreset: Attempted to remove a barcode to a preset that doesnt exist. (???).");
}
}
public bool CreateNewPreset(string presetName)
{
if (!presets.ContainsKey(presetName))
{
presets.Add(presetName, new List<string> { "c1534c5a-5747-42a2-bd08-ab3b47616467", "c1534c5a-6b38-438a-a324-d7e147616467", "c1534c5a-3813-49d6-a98c-f595436f6e73", "c1534c5a-c6a8-45d0-aaa2-2c954465764d" });
SavePresets();
return true;
}
Main.MelonLog.Msg("Function CreateNewPreset: Attempted to create a new preset with a pre-existing name.");
return false;
}
public void RemovePreset(string presetName)
{
if (presets.ContainsKey(presetName))
{
presets.Remove(presetName);
SavePresets();
}
else
{
Main.MelonLog.Msg("RemovePreset: Preset not found.");
}
}
public List<string> GetPresetData(string presetName)
{
if (presets.ContainsKey(presetName))
{
return presets[presetName];
}
Main.MelonLog.Msg("GetPresetData: Preset not found.");
return null;
}
public int GetNumberOfPresets()
{
return presets.Count;
}
}