-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPIRMPatcher.cs
More file actions
378 lines (328 loc) · 13.3 KB
/
Copy pathPIRMPatcher.cs
File metadata and controls
378 lines (328 loc) · 13.3 KB
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using SPT.Reflection.Patching;
using Diz.LanguageExtensions;
using EFT.InventoryLogic;
using EFT.UI;
using EFT.UI.DragAndDrop;
using HarmonyLib;
namespace PIRM
{
public class PIRMMethod17Patch : ModulePatch
{
protected override MethodBase GetTargetMethod() => AccessTools.Method(typeof(ItemSpecificationPanel), "method_17");
[PatchPrefix]
public static bool PatchPrefix(ref KeyValuePair<EModLockedState, ModSlotView.GStruct398> __result, Slot slot)
{
string itemName = slot.ContainedItem != null ? slot.ContainedItem.Name.Localized() : string.Empty;
ModSlotView.GStruct398 structValue = new ModSlotView.GStruct398
{
ItemName = itemName,
Error = string.Empty
};
__result = new KeyValuePair<EModLockedState, ModSlotView.GStruct398>(EModLockedState.Unlocked, structValue);
return false;
}
}
public class InteractionsHandlerPatch : ModulePatch
{
protected override MethodBase GetTargetMethod() => AccessTools.Method(typeof(InteractionsHandlerClass), "smethod_1");
[PatchPrefix]
public static bool Prefix(Item item, ItemAddress to, TraderControllerClass itemController, ref GStruct416<GClass3372> __result)
{
if (GClass1864.InRaid)
{
__result = GClass3372._;
return false;
}
return true;
}
}
public class ItemCheckAction : ModulePatch
{
protected override MethodBase GetTargetMethod() => AccessTools.Method(typeof(EFT.InventoryLogic.Item), "CheckAction");
[PatchPrefix]
public static bool Prefix(ItemAddress location, ref bool __result)
{
__result = true;
return false;
}
}
//need this one
public class EFTInventoryLogicModPatch : ModulePatch
{
protected override MethodBase GetTargetMethod() => AccessTools.Method(typeof(EFT.InventoryLogic.Mod), "CanBeMoved");
[PatchPrefix]
public static bool Prefix(IContainer toContainer, ref GStruct416<bool> __result)
{
__result = true;
return false;
}
}
public class CanAcceptRaidPatch : ModulePatch
{
protected override MethodBase GetTargetMethod() => AccessTools.Method(typeof(GClass2525), (nameof(GClass2525.CanAcceptRaid)));
[PatchPostfix]
public static void Postfix(ref bool __result, ref InventoryError error)
{
__result = true;
error = null;
}
}
//Gets rid of the compatibility check (even when ui highlights the slot as incompatible)
public class SlotMethod4Patch : ModulePatch
{
protected override MethodBase GetTargetMethod() => AccessTools.Method(typeof(Slot), (nameof(Slot.method_4)));
[PatchPrefix]
public static bool Prefix(Item item, bool ignoreRestrictions, bool ignoreMalfunction, ref GStruct416<bool> __result, Slot __instance)
{
if (__instance.ContainedItem != null)
{
__result = new Slot.GClass3339(item, __instance);
return false;
}
if (ignoreRestrictions)
{
__result = true;
return false;
}
if (__instance.Locked)
{
__result = new Slot.GClass3332(__instance);
return false;
}
InventoryError inventoryError;
if (!__instance.CanAcceptRaid(out inventoryError))
{
__result = inventoryError;
return false;
}
if (!__instance.Examined(item) && !(item is BulletClass))
{
__result = new Slot.GClass3336(item, __instance);
return false;
}
if (__instance.BlockerSlots.Count > 0)
{
__result = new Slot.GClass3333(item, __instance);
return false;
}
GStruct416<bool> gstruct = __instance.method_3(item);
if (gstruct.Failed)
{
__result = gstruct.Error;
return false;
}
if (item.IsSpecialSlotOnly && !__instance.IsSpecial)
{
__result = new Slot.GClass3340(item, __instance);
return false;
}
if (__instance.ConflictingSlots != null)
{
using (IEnumerator<Slot> enumerator = __instance.method_2(item).GetEnumerator())
{
while (enumerator.MoveNext())
{
Slot slot = enumerator.Current;
if (slot.ContainedItem != null)
{
__result = new Slot.GClass3334(item, __instance, slot);
return false;
}
}
}
}
//check at parent level if we are dealing with armor by checking for ArmorHolderComponent
var armorHolderComponent = __instance.ParentItem.GetItemComponent<ArmorHolderComponent>();
#if DEBUG
bool isArmorHolderComponentBool = armorHolderComponent != null;
//Logger.LogWarning("Checking Slot Compatibility: " + __instance.Name + " ArmorHolderComponent: " + isArmorHolderComponentBool + " Item: " + item.Name.Localized() + " IsArmorMod: " + item.IsArmorMod());
#endif
if (armorHolderComponent == null)
{
if (!__instance.CheckCompatibility(item))
{
__result = new Slot.GClass3340(item, __instance);
return false;
}
}
else
{
//we know it has armor holder component so we need to deal with child mod slots logic to make sure it can be placed in the slot
//if the currently checked slot has colliders then it is an armor slot
bool isArmorSlot = __instance.ArmorColliders.Length > 0;
//we want to check if its acceptable for slot only if PIRMPlugin.AllowSwapAnyArmorPlate is false
#if DEBUG
Logger.LogError("ArmorSlot: " + isArmorSlot + " IsArmorMod: " + item.IsArmorMod() + " IsModSuitable: " + armorHolderComponent.IsModSuitable(item));
#endif
if (isArmorSlot && armorHolderComponent.IsModSuitable(item))
{
//if no other item is there return true since we don't need to check weapons
if (__instance.ContainedItem == null)
{
__result = true;
return false;
}
}
else
{
if (!__instance.CheckCompatibility(item))
{
__result = new Slot.GClass3340(item, __instance);
return false;
}
}
}
Weapon weapon;
if (!ignoreMalfunction && (weapon = __instance.ParentItem.GetRootItem() as Weapon) != null && weapon.IncompatibleByMalfunction(item))
{
__result = new InteractionsHandlerClass.GClass3352(item, weapon);
return false;
}
Weapon weapon2;
if ((weapon2 = item as Weapon) != null && __instance.Id != "BuildSlot")
{
List<Slot> list = weapon2.MissingVitalParts.ToList<Slot>();
if (list.Any<Slot>())
{
__result = new Slot.GClass3338(weapon2, __instance, list);
return false;
}
}
__result = true;
return false;
}
}
public class IsModSuitablePatch : ModulePatch
{
protected override MethodBase GetTargetMethod() => AccessTools.Method(typeof(ArmorHolderComponent), (nameof(ArmorHolderComponent.IsModSuitable)));
[PatchPrefix]
public static bool Prefix(Item item, ArmorHolderComponent __instance, ref bool __result, LootItemClass ___lootItemClass)
{
//if armormod and PIRMPlugin.AllowSwapAnyArmorPlate is true then assume its suitable
if (item.IsArmorMod() && PIRMPlugin.AllowSwapAnyArmorPlate.Value)
{
__result = true;
return false;
}
//return true to check the original logic
return true;
}
}
public class SlotRemoveItemPatch : ModulePatch
{
protected override MethodBase GetTargetMethod() => AccessTools.Method(typeof(Slot), nameof(Slot.RemoveItem));
[PatchPrefix]
public static bool Prefix(ref GStruct416<bool> __result, Slot __instance)
{
//display parent of item for logging purposes
/* if (__instance.ContainedItem != null)
{
UnityEngine.Debug.LogWarning($"Parent of item: {__instance.ContainedItem.Parent}");
}*/
//Seems if its unlocked then we can't restore the default when toggled. decided not to use dictionary to restore since slots for every item? too much shit
if (PIRMPlugin.AllowSwapAnyArmorPlate.Value)
{
if (__instance.Locked)
{
__instance.Locked = false;
}
}
return true;
}
}
public class LootItemApplyPatch : ModulePatch
{
protected override MethodBase GetTargetMethod() => AccessTools.Method(typeof(LootItemClass), "Apply");
[PatchPrefix]
private static bool Prefix(ref LootItemClass __instance, ref GStruct413 __result, TraderControllerClass itemController, Item item, int count, bool simulate)
{
if (!item.ParentRecursiveCheck(__instance))
{
__result = new GClass3324(item, __instance);
return false;
}
//bool inRaid = GClass1849.InRaid;
bool inRaid = false;
Error error = null;
Error error2 = null;
Mod mod = item as Mod;
Slot[] array = ((mod != null && inRaid) ? __instance.VitalParts.ToArray<Slot>() : null);
Slot.GClass3338 gclass;
if (inRaid && mod != null && !mod.RaidModdable)
{
error2 = new GClass3321(mod);
}
else if (!InteractionsHandlerClass.CheckMissingParts(mod, __instance.CurrentAddress, itemController, out gclass))
{
error2 = gclass;
}
bool flag = false;
foreach (Slot slot in __instance.AllSlots)
{
if ((error2 == null || !flag) && slot.CanAccept(item))
{
if (error2 != null)
{
Slot.GClass3338 gclass2;
if ((gclass2 = error2 as Slot.GClass3338) != null)
{
error2 = new Slot.GClass3338(gclass2.Item, slot, gclass2.MissingParts);
}
flag = true;
}
else if (array != null && array.Contains(slot))
{
error = new GClass3322(mod);
}
else
{
GClass2783 gclass3 = new GClass2783(slot);
GStruct414<GClass2802> gstruct = InteractionsHandlerClass.Move(item, gclass3, itemController, simulate);
if (gstruct.Succeeded)
{
__result = gstruct;
return false;
}
GStruct414<GClass2811> gstruct2 = InteractionsHandlerClass.SplitMax(item, int.MaxValue, gclass3, itemController, itemController, simulate);
if (gstruct2.Succeeded)
{
__result = gstruct2;
return false;
}
error = gstruct.Error;
if (!GClass748.DisabledForNow && GClass2791.CanSwap(item, slot))
{
__result = null;
return false;
}
}
}
}
if (!flag)
{
error2 = null;
}
GStruct414<GInterface339> gstruct3 = InteractionsHandlerClass.QuickFindAppropriatePlace(item, itemController, __instance.ToEnumerable<LootItemClass>(), InteractionsHandlerClass.EMoveItemOrder.Apply, simulate);
if (gstruct3.Succeeded)
{
__result = gstruct3;
return false;
}
if (!(gstruct3.Error is GClass3317))
{
error = gstruct3.Error;
}
Error error3;
if ((error3 = error2) == null)
{
error3 = error ?? new GClass3324(item, __instance);
}
__result = error3;
return false;
}
}
}