-
Notifications
You must be signed in to change notification settings - Fork 4
/
ModFeatures.cs
272 lines (241 loc) · 9.4 KB
/
ModFeatures.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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
using Il2Cpp;
using System.Text;
using UnityEngine;
using HarmonyLib;
using PVZ_Hyper_Fusion.AssetStore;
namespace PVZ_Hyper_Fusion
{
public static class ModFeatures
{
public enum ModType
{
UnlimitedSun,
NoCooldown,
NoTakeDamagePlant,
ColumnPlant,
DeveloperMode,
ReloadStrings,
ReloadTextures,
Help,
}
private class ModFeature
{
public string Name { get; private set; }
public ModType ModType { get; private set; }
public KeyCode KeyCode { get; private set; }
public bool IsActive { get; set; }
public ModFeature(string Name, ModType ModType, KeyCode KeyCode, bool defaultValue = false)
{
this.Name = Name;
this.ModType = ModType;
this.KeyCode = KeyCode;
this.IsActive = defaultValue;
}
public void ToggleFeature()
{
#if USE_TRANSLATE
if (this.ModType == ModType.ReloadStrings)
{
StringStore.Reload();
Core.ShowToast("Translation String Reloaded!");
return;
}
#endif
#if USE_TEXTURE
if (this.ModType == ModType.ReloadTextures)
{
TextureStore.Reload();
Core.ShowToast("Texture Reloaded!");
return;
}
#endif
IsActive = !IsActive;
if (this.ModType == ModType.Help)
return;
Core.ShowToast(string.Format("{0} [{1}]", this.Name, IsActive ? "ON" : "OFF"));
}
public override string ToString()
{
if(this.ModType == ModType.ReloadStrings || this.ModType == ModType.ReloadTextures || this.ModType == ModType.Help )
return string.Format("[{0}]{1}", this.KeyCode.ToString(), this.Name);
return string.Format("[{0}]{1} [{2}]", this.KeyCode.ToString(), this.Name, IsActive ? "ON" : "OFF");
}
}
private static Dictionary<ModType, ModFeature> featureLists = new Dictionary<ModType, ModFeature>()
{
#if USE_MOD
{ModType.UnlimitedSun,new ModFeature("Unlimited Sun",ModType.UnlimitedSun,KeyCode.F1)},
{ModType.NoCooldown,new ModFeature("No Cooldown",ModType.NoCooldown,KeyCode.F2)},
{ModType.NoTakeDamagePlant,new ModFeature("No Take Damage",ModType.NoTakeDamagePlant,KeyCode.F3)},
{ModType.ColumnPlant,new ModFeature("Column Plant",ModType.ColumnPlant,KeyCode.F4)},
{ModType.DeveloperMode,new ModFeature("Developer Mode",ModType.DeveloperMode,KeyCode.F5)},
#endif
#if USE_TRANSLATE
{ModType.ReloadStrings,new ModFeature("Reload Translation String",ModType.ReloadStrings,KeyCode.Home, true)},
{ModType.ReloadTextures,new ModFeature("Reload Texture",ModType.ReloadTextures,KeyCode.End, true)},
#endif
{ModType.Help,new ModFeature("Feature Lists",ModType.Help,KeyCode.Insert, false)},
};
public static string GetFeatures()
{
StringBuilder status = new StringBuilder();
status.AppendLine("Features: ");
foreach (var feature in featureLists.Values)
{
status.AppendLine(feature.ToString());
}
return status.ToString();
}
public static void ToggleFeature(ModType ModType)
{
if (!featureLists.ContainsKey(ModType))
return;
featureLists[ModType].ToggleFeature();
}
public static bool GetActive(ModType ModType)
{
if (!featureLists.ContainsKey(ModType))
return false;
return featureLists[ModType].IsActive;
}
public static void SetActive(ModType ModType, bool value)
{
if (!featureLists.ContainsKey(ModType))
return;
featureLists[ModType].IsActive = value;
}
public static void OnLateUpdate()
{
foreach (var (type, feature) in featureLists)
{
if (feature.KeyCode != KeyCode.None && Enum.IsDefined(typeof(KeyCode), feature.KeyCode))
{
if (Input.GetKeyDown(feature.KeyCode))
{
feature.ToggleFeature();
}
}
}
}
#if USE_MOD
private static class PatchClasses
{
[HarmonyPatch(typeof(CardUI))]
public static class CardUI_Patch
{
[HarmonyPostfix]
[HarmonyPatch("Update")]
private static void Update(CardUI __instance)
{
if (ModFeatures.GetActive(ModFeatures.ModType.NoCooldown))
{
__instance.CD = __instance.fullCD;
__instance.isAvailable = true;
}
}
}
[HarmonyPatch(typeof(GloveMgr))]
public static class GloveMgr_Patch
{
[HarmonyPrefix]
[HarmonyPatch("CDUpdate")]
private static void CDUpdate(GloveMgr __instance)
{
if (ModFeatures.GetActive(ModFeatures.ModType.NoCooldown))
{
__instance.CD = __instance.fullCD;
__instance.avaliable = true;
}
}
}
[HarmonyPatch(typeof(HammerMgr))]
public static class HammerMgr_Patch
{
[HarmonyPrefix]
[HarmonyPatch("CDUpdate")]
private static void CDUpdate(HammerMgr __instance)
{
if (ModFeatures.GetActive(ModFeatures.ModType.NoCooldown))
{
__instance.CD = __instance.fullCD;
__instance.avaliable = true;
}
}
}
[HarmonyPatch(typeof(Board))]
public static class Board_Patch
{
[HarmonyPostfix]
[HarmonyPatch("Update")]
private static void Update(Board __instance)
{
if (ModFeatures.GetActive(ModFeatures.ModType.UnlimitedSun))
{
__instance.theSun = 10000;
}
__instance.freeCD = ModFeatures.GetActive(ModFeatures.ModType.DeveloperMode);
if (ModFeatures.GetActive(ModFeatures.ModType.ColumnPlant))
{
Board.BoardTag newTag = __instance.boardTag;
newTag.isColumn = true;
__instance.boardTag = newTag;
}
}
}
[HarmonyPatch(typeof(Plant))]
public static class Plant_Patch
{
[HarmonyPrefix]
[HarmonyPatch("TakeDamage", new Type[] { typeof(int), typeof(int) })]
static bool TakeDamage(Plant __instance)
{
if (ModFeatures.GetActive(ModFeatures.ModType.NoTakeDamagePlant))
{
__instance.isCrashed = false;
__instance.dying = false;
__instance.thePlantHealth = __instance.thePlantMaxHealth;
return false;
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch("Crashed")]
static bool Crashed(Plant __instance)
{
if (ModFeatures.GetActive(ModFeatures.ModType.NoTakeDamagePlant))
{
__instance.isCrashed = false;
__instance.dying = false;
__instance.thePlantHealth = __instance.thePlantMaxHealth;
return false;
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch("Die")]
static bool Die(Plant __instance)
{
if (ModFeatures.GetActive(ModFeatures.ModType.NoTakeDamagePlant))
{
__instance.isCrashed = false;
__instance.dying = false;
__instance.thePlantHealth = __instance.thePlantMaxHealth;
return false;
}
return true;
}
}
[HarmonyPatch(typeof(GameAPP))]
public static class GameAPP_Patch
{
[HarmonyPrefix]
[HarmonyPatch("Update")]
private static void Update()
{
GameAPP.developerMode = ModFeatures.GetActive(ModFeatures.ModType.DeveloperMode);
}
}
}
#endif
}
}