|
| 1 | +using MelonLoader; |
| 2 | +using BoneLib; |
| 3 | +using BoneLib.BoneMenu; |
| 4 | +using UnityEngine; |
| 5 | +using Il2CppSLZ.Marrow; |
| 6 | +using Il2CppSLZ.Marrow.Warehouse; |
| 7 | +using Il2CppSLZ.Marrow.Pool; |
| 8 | + |
| 9 | +[assembly: MelonInfo(typeof(global::HAHOOS.KeepInventory.Main), "Keep Inventory", "1.0.0", "HAHOOS")] |
| 10 | +[assembly: MelonGame("Stress Level Zero", "BONELAB")] |
| 11 | +[assembly: MelonAuthorColor(0,255,165,0)] |
| 12 | +[assembly: MelonColor(0, 255, 72, 59)] |
| 13 | + |
| 14 | +namespace HAHOOS.KeepInventory |
| 15 | +{ |
| 16 | + public class Main : MelonMod |
| 17 | + { |
| 18 | + |
| 19 | + public Dictionary<string, Barcode> slots = new Dictionary<string, Barcode>(); |
| 20 | + private bool IsDebug = true; |
| 21 | + |
| 22 | + public override void OnInitializeMelon() |
| 23 | + { |
| 24 | + LoggerInstance.Msg("Setting up KeepInventory"); |
| 25 | + SetupMenu(); |
| 26 | + |
| 27 | + Hooking.OnLevelLoaded += LevelLoadedEvent; |
| 28 | + Hooking.OnLevelUnloaded += LevelUnloadedEvent; |
| 29 | + |
| 30 | + } |
| 31 | + |
| 32 | + private void LevelUnloadedEvent() |
| 33 | + { |
| 34 | + if (Settings.Enabled) |
| 35 | + { |
| 36 | + slots.Clear(); |
| 37 | + LoggerInstance.Msg("Saving inventory..."); |
| 38 | + if (Player.RigManager == null) |
| 39 | + { |
| 40 | + LoggerInstance.Msg("RigManager does not exist"); |
| 41 | + return; |
| 42 | + } |
| 43 | + if (Player.RigManager.inventory == null) |
| 44 | + { |
| 45 | + LoggerInstance.Msg("Inventory does not exist"); |
| 46 | + return; |
| 47 | + } |
| 48 | + foreach (var item in Player.RigManager.inventory.bodySlots) |
| 49 | + { |
| 50 | + if (item.inventorySlotReceiver != null) |
| 51 | + { |
| 52 | + if (item.inventorySlotReceiver._weaponHost != null) |
| 53 | + { |
| 54 | + var poolee = item.inventorySlotReceiver._weaponHost.GetTransform().GetComponent<Poolee>(); |
| 55 | + if (poolee != null) |
| 56 | + { |
| 57 | + var barcode = poolee.SpawnableCrate.Barcode; |
| 58 | + slots.Add(item.name, barcode); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + } |
| 63 | + } |
| 64 | + if (IsDebug) LoggerInstance.Msg("Successfully saved inventory"); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + private void LevelLoadedEvent(LevelInfo obj) |
| 69 | + { |
| 70 | + if (Settings.Enabled) |
| 71 | + { |
| 72 | + LoggerInstance.Msg("Loading inventory..."); |
| 73 | + if (slots.Count >= 1) |
| 74 | + { |
| 75 | + var list = Player.RigManager.inventory.bodySlots.ToList(); |
| 76 | + foreach (var item in slots) |
| 77 | + { |
| 78 | + var slot = list.Find((slot) => slot.name == item.Key); |
| 79 | + if (slot != null){ |
| 80 | + if(slot.inventorySlotReceiver != null) |
| 81 | + { |
| 82 | + slot.inventorySlotReceiver.SpawnInSlotAsync(item.Value); |
| 83 | + } |
| 84 | + } |
| 85 | + } |
| 86 | + LoggerInstance.Msg(" Loaded inventory"); |
| 87 | + } |
| 88 | + else |
| 89 | + { |
| 90 | + LoggerInstance.Msg("Saved Inventory not found"); |
| 91 | + } |
| 92 | + } |
| 93 | + else |
| 94 | + { |
| 95 | + if (IsDebug) LoggerInstance.Msg("[DEBUG] Saving/Loading Inventory has been disabled, check the mod settings to enable again"); |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + public void SetupMenu() |
| 100 | + { |
| 101 | + var mainPage = Page.Root.CreatePage("HAHOOS", Color.white); |
| 102 | + var modPage = mainPage.CreatePage("KeepInventory", new Color(255, 72, 59)); |
| 103 | + modPage.CreateBool("Enabled", Color.green, Settings.Enabled, (value)=>Settings.Enabled=value); |
| 104 | + } |
| 105 | + } |
| 106 | +} |
0 commit comments