-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mod.cs
58 lines (46 loc) · 2 KB
/
Mod.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Nautilus.Handlers;
using QuickSlotsPlus.Patches;
namespace QuickSlotsPlus
{
[BepInPlugin(myGUID, pluginName, versionString)]
[BepInDependency("com.snmodding.nautilus")]
public class Mod : BaseUnityPlugin
{
internal static StandardConfig Options { get; } = OptionsPanelHandler.RegisterModOptions<StandardConfig>();
private const string myGUID = "com.celvro.subnautica.quickslotsplus";
private const string pluginName = "Quick Slots Plus";
private const string versionString = "2.1.1";
private static readonly Harmony harmony = new Harmony(myGUID);
public static ManualLogSource logger = BepInEx.Logging.Logger.CreateLogSource("QuickSlots+");
private void Awake()
{
Options.Load();
harmony.PatchAll();
logger.LogInfo(pluginName + " " + versionString + " " + "loaded.");
}
/*
* Redraw QuickSlot items while game is currently running. Also destroys and redraws HotKey labels if enabled.
*/
public static void RedrawQuickSlots()
{
if (Inventory.main == null) return;
// Saving the binding allows us to restore QuickSlot items
var oldSlots = Inventory.main.quickSlots;
var oldBinding = oldSlots.binding;
// In case QuickSlot size is reduced and held item no longer fits on bar
oldSlots.DeselectImmediate();
// Destroy and then redraw Quickslots (including HotKey labels)
Inventory_Awake_Patch.Postfix(Inventory.main);
// Restore QuickSlot selections so items don't get cleared off the bar
InventoryItem[] newBinding = new InventoryItem[Options.slotCount];
for (var i = 0; i < oldBinding.Length && i < Options.slotCount; i++)
{
newBinding[i] = oldBinding[i];
}
Inventory.main.quickSlots.binding = newBinding;
}
}
}