-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlugin.cs
257 lines (233 loc) · 10.4 KB
/
Plugin.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
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
using System;
using System.Linq;
using System.Collections.Generic;
using System.Reflection.Emit;
using HarmonyLib;
using UnityEngine.InputSystem;
using UnityEngine;
namespace DebugCheats
{
public class Plugin : Mod
{
public static ModLogger L;
public static ConfigEntry<bool> Enabled;
public static ConfigEntry<bool> DebugKeysEnabled;
public static ConfigEntry<int> OverrideMaxCards;
public static ConfigEntry<bool> DisableEating;
public static ConfigEntry<bool> InfiniteMonths;
public static ConfigEntry<bool> DisableGameOver;
public static ConfigEntry<string> DebugKey;
public static Key DebugHotkey = Key.F1;
public static ConfigFile ConfigFile;
private ConfigEntry<T> CreateConfig<T>(string name, T defaultValue, string description)
{
return Config.GetEntry<T>(name, defaultValue, new ConfigUI { Tooltip = description });
}
private void Awake()
{
L = Logger;
Enabled = CreateConfig("Enabled", true, "Can be used to disable the whole mod");
DebugKey = CreateConfig("Debug Menu Shortcut", "F1", "Key to toggle the debug menu.");
SetDebugHotkey(DebugKey.Value);
DebugKey.OnChanged += SetDebugHotkey;
DebugKeysEnabled = CreateConfig("Debug Keys Enabled", true, "Enable additional debugging shortcuts");
OverrideMaxCards = CreateConfig(
"Override Max Cards",
999,
"Override maximum number of cards. Set to -1 to use the game's default calculation."
);
DisableEating = CreateConfig(
"Disable Eating",
true,
"Same as the option in the game's debug menu but stored persistently."
);
InfiniteMonths = CreateConfig(
"Infinite Months",
true,
"Same as the option in the game's debug menu but stored persistently."
);
DisableGameOver = CreateConfig(
"Disable Game Over",
true,
"Prevents game over when all villagers are dead."
);
Harmony.PatchAll(typeof(Plugin));
ConfigFile = Config;
}
private static void SetDebugHotkey(string newValue)
{
Key? maybeKey = Keyboard.current.allKeys.FirstOrDefault(x => x.displayName == newValue)?.keyCode;
if (maybeKey is Key key)
{
DebugHotkey = key;
}
else
L.LogWarning($"Invalid hotkey: {newValue}");
}
private static bool HoldingShift()
{
return InputController.instance.GetKey(Key.LeftShift) || InputController.instance.GetKey(Key.RightShift);
}
[HarmonyPatch(typeof(DebugScreen), nameof(DebugScreen.ToggleEndlessMoon))]
[HarmonyPostfix]
private static void SyncEndlessMoon()
{
InfiniteMonths.Value = WorldManager.instance.DebugEndlessMoonEnabled;
ConfigFile.Save();
}
[HarmonyPatch(typeof(DebugScreen), nameof(DebugScreen.ToggleNoFood))]
[HarmonyPostfix]
private static void SyncToggleNoFood()
{
DisableEating.Value = WorldManager.instance.DebugNoFoodEnabled;
ConfigFile.Save();
}
[HarmonyPatch(typeof(WorldManager), nameof(WorldManager.Update))]
[HarmonyPrefix]
private static void WorldManager__Update(ref WorldManager __instance)
{
if (!Enabled.Value)
return;
__instance.DebugNoFoodEnabled = DisableEating.Value;
__instance.DebugEndlessMoonEnabled = InfiniteMonths.Value;
if (!DebugKeysEnabled.Value)
return;
var card = __instance.HoveredCard;
if (
(
InputController.instance.GetKeyDown(Key.Delete)
|| (
(InputController.instance.GetKey(Key.R) || InputController.instance.GetKey(Key.Delete))
&& HoldingShift()
)
)
)
{
if (card != null)
{
if (card.CardData is Combatable c && c.MyConflict != null)
c.MyConflict.LeaveConflict(c);
if (card.Parent != null)
{
card.Parent.Child = null;
card.Parent = null;
}
__instance.DestroyStack(card);
}
else if (__instance.HoveredDraggable != null && __instance.HoveredDraggable is Boosterpack b)
UnityEngine.Object.Destroy(b.gameObject);
}
if (InputController.instance.GetKeyDown(DebugHotkey))
{
GameScreen.instance.DebugScreen.gameObject.SetActive(
!GameScreen.instance.DebugScreen.gameObject.activeInHierarchy
);
WorldManager.instance.DebugScreenOpened = true;
}
if (InputController.instance.GetKeyDown(Key.F2))
{
var currency = __instance.CurrentBoard.Id == "main" ? "gold" : "shell";
__instance.CreateCardStack(__instance.MiddleOfBoard(), 5, currency);
}
if (InputController.instance.GetKeyDown(Key.C) && card != null)
{
if (HoldingShift())
{
var pos = card.transform.position;
var cards = new List<string>();
do
{
cards.Add(card.CardData.Id);
card = card.Child;
} while (card != null);
var parent = __instance.CreateCard(pos, cards[0]).MyGameCard;
foreach (var id in cards.GetRange(1, cards.Count - 1))
{
var child = __instance.CreateCard(pos, id, checkAddToStack: false).MyGameCard;
parent.Child = child;
child.Parent = parent;
parent = child;
}
}
else
{
var newCard = __instance.CreateCard(card.transform.position, card.CardData.Id);
if (newCard is Combatable c)
{
foreach (var equip in card.CardData.GetAllEquipables())
c.CreateAndEquipCard(equip.Id, false);
c.HealthPoints = (card.CardData as Combatable).HealthPoints;
}
}
}
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(WorldManager), nameof(WorldManager.CheckDebugInput))]
public static IEnumerable<CodeInstruction> BlockVanillaDebugCopy(IEnumerable<CodeInstruction> instructions)
{
return new CodeMatcher(instructions)
.MatchForward(
true,
new CodeMatch(OpCodes.Ldc_I4_S, (sbyte)17),
new CodeMatch(
OpCodes.Callvirt,
AccessTools.Method(typeof(InputController), nameof(InputController.GetKeyDown))
),
new CodeMatch(OpCodes.Brfalse)
)
.ThrowIfInvalid("Didn't find vanilla debug copy")
.Insert(
Transpilers.EmitDelegate<Func<bool>>(() => !Enabled.Value || !DebugKeysEnabled.Value),
new CodeInstruction(OpCodes.And)
)
.InstructionEnumeration();
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Equipable), nameof(Equipable.CanBeDragged), MethodType.Getter)]
[HarmonyPatch(typeof(StrangePortal), nameof(StrangePortal.CanBeDragged), MethodType.Getter)]
[HarmonyPatch(typeof(PirateBoat), nameof(PirateBoat.CanBeDragged), MethodType.Getter)]
[HarmonyPatch(typeof(Mob), nameof(PirateBoat.CanBeDragged), MethodType.Getter)]
public static void AllowDraggingEverything(out bool __runOriginal, out bool __result)
{
__runOriginal = !Enabled.Value;
__result = true;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Mob), nameof(Mob.CanHaveCard))]
public static void AllowEquippingEnemies(CardData otherCard, out bool __runOriginal, out bool __result)
{
__result = true;
__runOriginal = !Enabled.Value || otherCard is not Equipable;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(WorldManager), "GetMaxCardCount")]
[HarmonyPatch(new Type[0])]
[HarmonyPatch(new Type[] { typeof(GameBoard) })]
private static void MaxCards(ref bool __runOriginal, ref int __result)
{
if (!Enabled.Value || OverrideMaxCards.Value < 0)
return;
__runOriginal = false;
__result = OverrideMaxCards.Value;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(WorldManager), nameof(WorldManager.CheckAllVillagersDead))]
public static void PreventGameOver(out bool __runOriginal, out bool __result)
{
__result = false;
__runOriginal = !Enabled.Value || !DisableGameOver.Value;
}
[HarmonyPatch(typeof(DebugScreen), nameof(DebugScreen.InitializeDebugScreen))]
[HarmonyPostfix]
public static void FixDebugScreenTabs(DebugScreen __instance)
{
((RectTransform)__instance.transform).offsetMax = new Vector2(-10, -70);
((RectTransform)__instance.transform.Find("Titles")).anchoredPosition = new Vector2(0, -10);
((RectTransform)__instance.transform.Find("Titles2")).anchoredPosition = new Vector2(0, -55);
var tabs = (RectTransform)__instance.transform.Find("Tabs");
tabs.offsetMax = new Vector2(-10, -100);
tabs.offsetMin = new Vector2(10, 10);
((RectTransform)tabs.Find("CardsTab")).anchoredPosition = new Vector2(0, -25);
}
}
}