-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatches.cs
More file actions
243 lines (224 loc) · 10.6 KB
/
Copy pathPatches.cs
File metadata and controls
243 lines (224 loc) · 10.6 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
// Decompiled with JetBrains decompiler
// Type: BetterAdvancedTablet.Patches
// Assembly: betteradvancedtablet, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 043CAA08-4B98-4619-92DB-15D678E3DFFF
// Assembly location: C:\Program Files (x86)\Steam\steamapps\common\Stationeers\BepInEx\plugins\BetterAdvancedTabletFixed\BetterAdvancedTabletFixed.dll
using Assets.Scripts;
using Assets.Scripts.Inventory;
using Assets.Scripts.Objects;
using Assets.Scripts.Objects.Items;
using BetterAdvancedTabletFixed;
using Cysharp.Threading.Tasks;
using HarmonyLib;
using JetBrains.Annotations;
using System;
using System.Threading.Tasks;
using UnityEngine;
#nullable disable
namespace BetterAdvancedTablet
{
public class Patches
{
public static int hasRun;
public static void AdvancedTabletPrefabPatch()
{
if (Patches.hasRun != 0)
return;
int num = 0;
if (BetterAdvancedTabletPlugin.DebugMode)
Debug.Log((object)"Better Advanced Tablet: looking up ItemAdvancedTablet");
Thing thing = Prefab.Find("ItemAdvancedTablet");
if ((UnityEngine.Object)thing == (UnityEngine.Object)null)
{
if (!BetterAdvancedTabletPlugin.DebugMode)
return;
Debug.Log((object)"Better Advanced Tablet: Failed to find ItemAdvancedTablet");
}
else if (thing.Slots == null)
{
if (!BetterAdvancedTabletPlugin.DebugMode)
return;
Debug.Log((object)"Better Advanced Tablet ItemAdvancedTablet.Slots is null");
}
else
{
if (BetterAdvancedTabletPlugin.DebugMode)
Debug.Log((object)string.Format("{0} ItemAdvancedTablet.Slots.count: {1}", (object)"Better Advanced Tablet", (object)thing.Slots.Count));
Slot slot1 = thing.Slots[1];
for (int index = 0; index < BetterAdvancedTabletPlugin.TabletSlots; ++index)
{
if (index > 5)
return;
thing.Slots.Add(new Slot()
{
Type = slot1.Type,
IsHiddenInSeat = slot1.IsHiddenInSeat,
HidesOccupant = slot1.HidesOccupant,
Interactable = slot1.Interactable,
IsInteractable = slot1.IsInteractable,
IsSwappable = slot1.IsSwappable,
OccupantCastsShadows = slot1.OccupantCastsShadows
});
}
(thing as AdvancedTablet).AllowSelfUse = true;
Patches.hasRun = 1;
if (!BetterAdvancedTabletPlugin.DebugMode)
return;
foreach (Slot slot2 in thing.Slots)
{
if (slot2 == null)
{
Debug.Log((object)string.Format("{0} slot({1}) is null", (object)"Better Advanced Tablet", (object)num));
}
else
{
Debug.Log((object)string.Format("{0} slot({1}): {2}", (object)"Better Advanced Tablet", (object)num, (object)slot2.Type));
++num;
}
}
}
}
[HarmonyPatch(typeof(AdvancedTablet))]
public class AdvancedTabletPatches
{
[HarmonyPostfix]
[HarmonyPatch("DeserializeSave", new Type[] { typeof(ThingSaveData) })]
public static void DeserializeSavePatch(AdvancedTablet __instance)
{
Traverse.Create((object)__instance).Method("GetCartridge", Array.Empty<object>()).GetValue();
}
[HarmonyPrefix]
[HarmonyPatch("InteractWith")]
public static bool InteractWithPatch(
AdvancedTablet __instance,
ref Thing.DelayedActionInstance __result,
ref int ___currentCartSlot,
Interactable interactable,
Interaction interaction,
bool doAction = true)
{
if (!doAction)
return true;
if (interactable.Action == InteractableType.Button1)
{
if (BetterAdvancedTabletPlugin.DebugMode)
Debug.Log((object)"Better Advanced Tablet:InteractWithPatch InteractableType.Button1");
int num = ___currentCartSlot;
for (int index1 = ___currentCartSlot; index1 <= ___currentCartSlot + __instance.CartridgeSlots.Count - 1; ++index1)
{
int index2 = (index1 + 1) % __instance.CartridgeSlots.Count;
if (BetterAdvancedTabletPlugin.DebugMode)
Debug.Log((object)string.Format("{0}:InteractWithPatch next cartridge slot index = {1}", (object)"Better Advanced Tablet", (object)index2));
if (__instance.CartridgeSlots[index2].Get() != null)
{
if (BetterAdvancedTabletPlugin.DebugMode)
Debug.Log((object)"Better Advanced Tablet:InteractWithPatch next cartridge slot is not empty.");
return true;
}
___currentCartSlot = index2;
}
}
if (interactable.Action == InteractableType.Button2)
{
if (BetterAdvancedTabletPlugin.DebugMode)
Debug.Log((object)"Better Advanced Tablet:InteractWithPatch InteractableType.Button2");
int num = ___currentCartSlot;
for (int index3 = ___currentCartSlot; index3 >= ___currentCartSlot - __instance.CartridgeSlots.Count + 1; --index3)
{
int index4 = (index3 - 1) % __instance.CartridgeSlots.Count;
if (index4 < 0)
index4 = __instance.CartridgeSlots.Count + index4;
if (BetterAdvancedTabletPlugin.DebugMode)
Debug.Log((object)string.Format("{0}:InteractWithPatch next cartridge slot index = {1}", (object)"Better Advanced Tablet", (object)index4));
if (__instance.CartridgeSlots[index4].Get() != null)
{
if (BetterAdvancedTabletPlugin.DebugMode)
Debug.Log((object)"Better Advanced Tablet:InteractWithPatch next cartridge slot is not empty.");
return true;
}
___currentCartSlot = index4;
}
}
return true;
}
}
[HarmonyPatch(typeof(World), "NewOrContinue")]
public class MainMenuWindowManagerPatches
{
public static void Prefix() => Patches.AdvancedTabletPrefabPatch();
}
[HarmonyPatch(typeof(NetworkClient), "ProcessJoinData")]
public class NetworkClientProcessJoinDataPatches
{
public static void Prefix() => Patches.AdvancedTabletPrefabPatch();
}
public class AsyncMethods
{
public static bool MouseDown;
public static async void NextCartridge(AdvancedTablet advancedTablet)
{
if (BetterAdvancedTabletPlugin.DebugMode)
Debug.Log((object)"Better Advanced Tablet:NextCartridge mouse down");
Interaction interaction;
if (MouseDown)
{
interaction = new Interaction();
return;
}
try
{
MouseDown = true;
interaction = new Interaction(
(Thing)InventoryManager.Parent,
InventoryManager.ActiveHandSlot,
CursorManager.CursorThing,
KeyManager.GetButton(KeyMap.QuantityModifier)
);
if (KeyManager.GetButton(KeyMap.QuantityModifier))
advancedTablet.InteractWith(advancedTablet.InteractButton2, interaction, true);
else
advancedTablet.InteractWith(advancedTablet.InteractButton1, interaction, true);
// Use a simple while loop with a small delay instead of async waiting
while (KeyManager.GetMouse("Primary") && !KeyManager.GetButton(KeyMap.SwapHands) && advancedTablet.OnOff && advancedTablet.Powered)
{
await Task.Delay(16); // Approximately one frame at 60 FPS
}
}
finally
{
MouseDown = false;
if (BetterAdvancedTabletPlugin.DebugMode)
Debug.Log((object)"Better Advanced Tablet:NextCartridge mouse up");
}
}
}
[UsedImplicitly]
[HarmonyPatch(typeof(Item), "OnUsePrimary")]
public class OnUsePrimaryPatch
{
public static bool Prefix(
Item __instance,
Vector3 targetLocation,
Quaternion targetRotation,
ulong steamId,
bool authoringMode)
{
if (BetterAdvancedTabletPlugin.DebugMode)
Debug.Log((object)"Better Advanced Tablet:OnUsePrimaryPatch called Item.OnUsePrimary");
AdvancedTablet advancedTablet = __instance as AdvancedTablet;
if (!(bool)(UnityEngine.Object)advancedTablet)
{
if (BetterAdvancedTabletPlugin.DebugMode)
Debug.Log((object)"Better Advanced Tablet:OnUsePrimaryPatch __instance is not AdvancedTablet");
return true;
}
if (!advancedTablet.OnOff || !advancedTablet.Powered)
return true;
if (BetterAdvancedTabletPlugin.DebugMode)
Debug.Log((object)"Better Advanced Tablet: calling NextCartridge");
AsyncMethods.NextCartridge(advancedTablet);
return false;
}
}
}
}