-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHotbarChecksCanSearchInventory.cs
More file actions
159 lines (149 loc) · 5.9 KB
/
Copy pathHotbarChecksCanSearchInventory.cs
File metadata and controls
159 lines (149 loc) · 5.9 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
using HarmonyLib;
using System.Collections.Generic;
using BepInEx;
namespace LoserCheatMod
{
class InventoryHelperMethods
{
public static bool _hasOwnedTopicByTag(Inventory inventory, tags tag) {
dictionary_Tag dict = inventory.getDictTag(tag);
// Mods.Log.LogInfo($"Looking in the inventory for tag {tag.name}. Associated dict has {dict.TopicsWithTag.Count} items.");
// foreach (topics topic in dict.TopicsWithTag) {
// Mods.Log.LogInfo($"Dict has topic {topic.Name} {topic.ID}.");
// }
foreach (owned_topic owned_topic in inventory.TransientTopics)
{
// Mods.Log.LogInfo($"Looking for topic {owned_topic.Topic_id} in there...");
if (dict.TopicsWithTag.Contains(inventory.getTopic(owned_topic.Topic_id)))
{
return true;
}
}
foreach (owned_topic owned_topic2 in inventory.ItemTopics)
{
// Mods.Log.LogInfo($"Looking for item {owned_topic2.Topic_id} in there...");
if (dict.TopicsWithTag.Contains(inventory.getTopic(owned_topic2.Topic_id)))
{
return true;
}
}
return false;
}
}
[HarmonyPatch(typeof(Reqs.topicReq), "processByTag")]
class processByTag
{
static void Postfix(Reqs.topicReq __instance, Inventory inv, Reqs.requirements reqs, ref bool __result)
{
if (__result)
{
return;
}
if (ModConfig.Instance.IsToggleHotbarChecksCanSearchInventory() && !__instance.invert)
{
__result = InventoryHelperMethods._hasOwnedTopicByTag(inv, __instance.tag);
}
}
}
// hasHotbarTopicWithTag and hasItembarTopicWithTag currently return an int instead of a bool,
// with the intent of destroying whatever they find afterward. The patched versions have to return
// *some* non-neg1 int to be considered truthy, so I'm returning -2 and attempting to stop
// any consequence of downstream code blowing up using that value in methods such as
// removeTopicFromBarByTags by stubbing those methods too (in this case, to return false)
// This has the consequence that more to
[HarmonyPatch(typeof(Inventory))]
[HarmonyPatch(nameof(Inventory.hasHotbarTopicWithTag))]
class hasHotbarTopicWithTag
{
static void Postfix(Inventory __instance, tags tag, ref int __result)
{
if (__result != -1) {
return;
}
if (ModConfig.Instance.IsToggleHotbarChecksCanSearchInventory()) {
__result = InventoryHelperMethods._hasOwnedTopicByTag(__instance, tag) ? -2 : -1;
}
}
}
[HarmonyPatch(typeof(Inventory))]
[HarmonyPatch(nameof(Inventory.hasItembarTopicWithTag))]
class hasItembarTopicWithTag
{
static void Postfix(Inventory __instance, tags tag, ref int __result)
{
if (__result != -1) {
return;
}
if (ModConfig.Instance.IsToggleHotbarChecksCanSearchInventory()) {
__result = InventoryHelperMethods._hasOwnedTopicByTag(__instance, tag) ? -2 : -1;
}
}
}
[HarmonyPatch(typeof(Inventory))]
[HarmonyPatch(nameof(Inventory.removeTopicFromBarByTags))]
class removeTopicFromBarByTags
{
static bool Prefix(List<tags> _tags, topics.InventoryModReason Reason)
{
if (ModConfig.Instance.IsToggleHotbarChecksCanSearchInventory())
{
return false;
}
return true;
}
}
[HarmonyPatch(typeof(Inventory))]
[HarmonyPatch(nameof(Inventory.removeTopicFromBarByTag))]
class removeTopicFromBarByTag
{
static bool Prefix(tags tag, topics.InventoryModReason Reason)
{
if (ModConfig.Instance.IsToggleHotbarChecksCanSearchInventory())
{
return false;
}
return true;
}
}
[HarmonyPatch(typeof(Inventory))]
[HarmonyPatch(nameof(Inventory.hasHotbarTopic))]
class hasHotbarTopic
{
static void Postfix(Inventory __instance, int topic, ref bool __result)
{
if (__result == true) {
return;
}
if (ModConfig.Instance.IsToggleHotbarChecksCanSearchInventory()) {
// Mods.Log.LogInfo($"Looking in the inventory for {topic} {__instance.TopicIDReference[topic].Name}.");
__result = __instance.hasTransientTopic(topic) || __instance.hasPermTopic(topic);
}
}
}
[HarmonyPatch(typeof(Inventory))]
[HarmonyPatch(nameof(Inventory.hasItembarTopic))]
class hasItembarTopic
{
static void Postfix(Inventory __instance, int topic, ref bool __result)
{
if (__result == true) {
return;
}
if (ModConfig.Instance.IsToggleHotbarChecksCanSearchInventory()) {
// Outfits are meant to be removed from the inventory forever
// once given. It would be tough to patch everything to ensure
// that outfits get removed when they aren't in the itembar,
// so the workaround is to just require outfits to be in the itembar.
foreach (topics outfit_topic in __instance.Outfit_TopicList)
{
// Mods.Log.LogInfo($"Checking whether topic {topic} {__instance.TopicIDReference[topic].Name} is outfit {outfit_topic.ID} {__instance.TopicIDReference[outfit_topic.ID].Name}");
if (outfit_topic.ID == topic) {
__result = false;
return;
}
}
__result = __instance.hasItemTopic(topic);
}
}
}
}