-
Notifications
You must be signed in to change notification settings - Fork 1
/
Inventory_Patch.cs
171 lines (151 loc) · 6.33 KB
/
Inventory_Patch.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
using HarmonyLib;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using static ErrorMessage;
namespace Tweaks_Fixes
{
internal class Inventory_Patch
{
static InventoryItem selectedItem;
public static GameInput.Button transferAllItemsButton;
public static GameInput.Button transferSameItemsButton;
private static readonly Type[] componentsToRemoveFromDeadCreature = new Type[]
{
typeof(CollectShiny),
typeof(CreatureFlinch),
typeof(CreatureDeath),
typeof(SwimInSchool),
typeof(SwimRandom),
typeof(StayAtLeashPosition),
typeof(Breach),
typeof(AvoidObstacles),
typeof(AvoidEscapePod),
typeof(AvoidTerrain),
typeof(FleeOnDamage),
typeof(FleeWhenScared),
typeof(MoveTowardsTarget),
typeof(SwimToVent),
typeof(SwimToHeroPeeper),
typeof(SwimToMeat),
typeof(SwimToTarget),
typeof(Scareable),
typeof(CreatureFear),
typeof(SwimBehaviour),
typeof(SplineFollowing),
typeof(Locomotion),
};
public static bool MoveAllItems(InventoryItem item)
{
//AddDebug("MoveAllItems ");
if (item == null)
return false;
ItemsContainer container = (ItemsContainer)item.container;
IItemsContainer oppositeContainer = Inventory.main.GetOppositeContainer(item);
List<InventoryItem> itemsToTransfer = new List<InventoryItem>();
foreach (TechType itemType in container.GetItemTypes())
container.GetItems(itemType, itemsToTransfer);
bool swapped = false;
foreach (InventoryItem ii in itemsToTransfer)
{
//AddDebug("itemsToTransfer " + ii.item.name);
if (Inventory.AddOrSwap(ii, oppositeContainer))
swapped = true;
}
return swapped;
}
public static bool MoveSameItems(InventoryItem item)
{
//AddDebug("MoveSameItems " );
if (item == null)
return false;
ItemsContainer container = (ItemsContainer)item.container;
IItemsContainer oppositeContainer = Inventory.main.GetOppositeContainer(item);
List<InventoryItem> itemsToTransfer = new List<InventoryItem>();
container.GetItems(item.techType, itemsToTransfer);
bool swapped = false;
foreach (InventoryItem ii in itemsToTransfer)
{
//AddDebug("itemsToTransfer " + ii.item.name);
if (Inventory.AddOrSwap(ii, oppositeContainer))
swapped = true;
}
return swapped;
}
private static void RemoveComponentsFromDeadCreature(GameObject go)
{
LiveMixin liveMixin = go.GetComponent<LiveMixin>();
if (liveMixin == null || liveMixin.IsAlive())
return;
// removing CreatureDeath fixes equipped dead fish moving up
foreach (Type componentType in componentsToRemoveFromDeadCreature)
{
Component component = go.GetComponent(componentType);
if (component != null)
UnityEngine.Object.Destroy(component);
}
}
[HarmonyPatch(typeof(Inventory))]
class Inventory_Patch_
{
[HarmonyPostfix]
[HarmonyPatch("OnAddItem")]
public static void OnAddItemPostfix(Inventory __instance, InventoryItem item)
{
if (!Main.gameLoaded && item.item.GetComponent<Creature>())
RemoveComponentsFromDeadCreature(item.item.gameObject);
//Creature creature = item.item.GetComponent<Creature>();
//FixPeeperLOD(Creature peeper, bool alive = false)
}
[HarmonyPrefix]
[HarmonyPatch("ExecuteItemAction", new Type[] { typeof(ItemAction), typeof(InventoryItem) })]
public static bool ExecuteItemActionPrefix(Inventory __instance, InventoryItem item, ItemAction action)
{
//AddDebug("ExecuteItemAction " + item.techType);
//AddDebug("ExecuteItemAction action " + action);
IItemsContainer oppositeContainer = __instance.GetOppositeContainer(item);
if (Main.advancedInventoryLoaded || action != ItemAction.Switch || oppositeContainer == null || item.container is Equipment || oppositeContainer is Equipment)
return true;
if (GameInput.lastDevice == GameInput.Device.Keyboard)
{
if (Input.GetKey(ConfigMenu.transferSameItemsButton.Value))
return !MoveSameItems(item);
if (Input.GetKey(ConfigMenu.transferAllItemsButton.Value))
return !MoveAllItems(item);
}
return true;
}
}
[HarmonyPatch(typeof(GamepadInputModule))]
class GamepadInputModule_Patch
{
[HarmonyPostfix]
[HarmonyPatch("OnUpdate")]
public static void OnUpdatePostfix(GamepadInputModule __instance)
{
if (Input.GetKeyDown(ConfigMenu.transferAllItemsButton.Value) || GameInput.GetButtonDown(transferAllItemsButton))
{
MoveAllItems(selectedItem);
}
else if (Input.GetKeyDown(ConfigMenu.transferSameItemsButton.Value) || GameInput.GetButtonDown(transferSameItemsButton))
{
MoveSameItems(selectedItem);
}
}
}
[HarmonyPatch(typeof(uGUI_ItemsContainer))]
class uGUI_ItemsContainer_Patch
{
[HarmonyPostfix]
[HarmonyPatch("SelectItem")]
static void Prefix(uGUI_ItemsContainer __instance, object item)
{
uGUI_ItemIcon key = item as uGUI_ItemIcon;
if (key == null || !__instance.icons.TryGetValue(key, out selectedItem))
return;
//AddDebug("uGUI_ItemsContainer SelectItem " + selectedItem.techType);
}
}
}
}