source: Daodan/src/Patches/Cheater.c@ 1091

Last change on this file since 1091 was 1017, checked in by alloc, 10 years ago

Daodan 4.0: Added Input module, cheats bindable to keys

File size: 11.4 KB
Line 
1#include <string.h>
2#include "stdint.h"
3#include <math.h>
4
5#include "../Oni/Oni.h"
6
7#include "../_Version.h"
8
9#include "../Daodan.h"
10#include "../Daodan_Config.h"
11#include "Cheater.h"
12#include "Input.h"
13#include "Utility.h"
14
15union MSVC_EVIL_FLOAT_HACK
16{
17 unsigned __int8 Bytes[4];
18 float Value;
19};
20static union MSVC_EVIL_FLOAT_HACK INFINITY_HACK = {{0x00, 0x00, 0x80, 0x7F}};
21#define DD_INFINITY (INFINITY_HACK.Value)
22
23oniCheatCode DDr_CheatTable[] = {
24 { "shapeshifter", "Change Characters Enabled", "Change Characters Disabled", cheat_shapeshifter },
25 { "liveforever", "Invincibility Enabled", "Invincibility Disabled", cheat_liveforever },
26 { "touchofdeath", "Omnipotence Enabled", "Omnipotence Disabled", cheat_touchofdeath },
27 { "canttouchthis", "Unstoppable Enabled", "Unstoppable Disabled", cheat_canttouchthis },
28 { "fatloot", "Fat Loot Received", NULL, cheat_fatloot },
29 { "glassworld", "Glass Furniture Enabled", "Glass Furniture Disabled", cheat_glassworld },
30 { "winlevel", "Instantly Win Level", NULL, cheat_winlevel },
31 { "loselevel", "Instantly Lose Level", NULL, cheat_loselevel },
32 { "bighead", "Big Head Enabled", "Big Head Disabled", cheat_bighead },
33 { "minime", "Mini Mode Enabled", "Mini Mode Disabled", cheat_minime },
34 { "superammo", "Super Ammo Mode Enabled", "Super Ammo Mode Disabled", cheat_superammo },
35 { "thedayismine", "Developer Access Enabled", "Developer Access Disabled", cheat_thedayismine },
36 { "reservoirdogs", "Last Man Standing Enabled", "Last Man Standing Disabled", cheat_reservoirdogs },
37 { "roughjustice", "Gatling Guns Enabled", "Gatling Guns Disabled", cheat_roughjustice },
38 { "chenille", "Daodan Power Enabled", "Daodan Power Disabled", cheat_chenille },
39 { "behemoth", "Godzilla Mode Enabled", "Godzilla Mode Disabled", cheat_behemoth },
40 { "elderrune", "Regeneration Enabled", "Regeneration Disabled", cheat_elderrune },
41 { "moonshadow", "Phase Cloak Enabled", "Phase Cloak Disabled", cheat_moonshadow },
42 { "munitionfrenzy", "Weapons Locker Created", NULL, cheat_munitionfrenzy },
43 { "fistsoflegend", "Fists Of Legend Enabled", "Fists Of Legend Disabled", cheat_fistsoflegend },
44 { "killmequick", "Ultra Mode Enabled", "Ultra Mode Disabled", cheat_killmequick },
45 { "carousel", "Slow Motion Enabled", "Slow Motion Disabled", cheat_carousel },
46 { "bigbadboss", "Boss Shield Enabled", "Boss Shield Disabled", cheat_bigbadboss },
47 { "bulletproof", "Force Field Enabled", "Force Field Disabled", cheat_bulletproof },
48 { "kangaroo", "Kangaroo Jump Enabled", "Kangaroo Jump Disabled", cheat_kangaroo },
49 { "marypoppins", "Jet Pack Mode Enabled", "Jet Pack Mode Disabled", cheat_marypoppins },
50 { "buddha", "Unkillable Enabled", "Unkillable Disabled", cheat_buddha },
51 { "shinobi", "Ninja Mode Enabled (good luck!)", "Ninja Mode Disabled", cheat_shinobi },
52 { "x", "Developer Access Enabled", "Developer Access Disabled", cheat_x },
53 { "testcheat", "Testing...", "", cheat_testcheat },
54 { "tellmetheversion", "Daodan v."DAODAN_VERSION_STRING"", "", cheat_tellmetheversion },
55 {0, 0, 0, 0}
56};
57
58
59
60// Just copied all these defines from the old daodan, they were originaly from SFeLi's code.
61
62#define GSA_camera (0x00000080)
63#define GSA_player (0x000000AC)
64#define GSA_carousel (0x00000104) /* char */
65#define GSA_slowmotimer (0x00000108)
66#define GSA_splashscreen (0x00000118) /* char */
67
68#define CHR_flags (0x00000004)
69#define CHR_flags2 (0x00000008)
70#define CHR_oncc (0x0000000C)
71#define CHR_team (0x00000012) /* short */
72#define CHR_name (0x00000014) /* char[32] */
73#define CHR_scalemodel (0x00000034)
74#define CHR_weapon1 (0x00000194)
75#define CHR_weapon2 (0x00000198)
76#define CHR_weapon3 (0x0000019C)
77#define CHR_shield_curr (0x000001B6) /* short */
78#define CHR_shield (0x000001B8) /* short */
79#define CHR_phasecloak (0x000001BA) /* short */
80#define CHR_stats_kills (0x00001670)
81#define CHR_stats_damage (0x00001674)
82
83#define ONCC_jet_accel (0x00000010) /* float */
84#define ONCC_jet_timer (0x00000016) /* short */
85#define ONCC_height1 (0x00000018) /* float */
86#define ONCC_height2 (0x0000001C) /* float */
87#define ONCC_bodysize_min (0x00000C58) /* float */
88#define ONCC_bodysize_max (0x00000C8C) /* float */
89
90#define kangaroo_h (short)(60)
91#define kangaroo_jp (float)(0.06)
92#define marypoppins_jp (float)(0.14)
93
94uint16_t cheat_oldshield = 0;
95int32_t cheat_oldhealth = 1;
96int32_t cheat_oldmaxhealth = 1;
97float cheat_oldjet_accel = 0.03f;
98uint16_t cheat_oldjet_timer = 20;
99float cheat_oldheight1 = 45;
100float cheat_oldheight2 = 135;
101bool inc_fallingframes = true;
102
103uint8_t ONICALL DDrCheater(uint32_t cheat)
104{
105 switch (cheat)
106 {
107 case cheat_bigbadboss:
108 {
109 Character* player = ONgGameState->PlayerCharacter;
110 //char* player = *((char**)(ONgGameState + GSA_player));
111 if (player->Flags & chr_bossshield)
112 {
113 player->Flags = player->Flags & ~chr_bossshield;
114 return 0;
115 }
116 else
117 {
118 player->Flags = player->Flags | chr_bossshield;
119 return 1;
120 }
121 }
122 case cheat_bulletproof:
123 {
124 Character* player = ONgGameState->PlayerCharacter;
125 if (player->Flags & chr_weaponimmune)
126 {
127 player->Flags = player->Flags & ~chr_weaponimmune;
128 player->Inventory.ShieldUsed = cheat_oldshield;
129 return 0;
130 }
131 else
132 {
133 player->Flags |= chr_weaponimmune;
134 cheat_oldshield = player->Inventory.ShieldUsed;
135 player->Inventory.ShieldUsed = 100;
136 return 1;
137 }
138 }
139 case cheat_kangaroo:
140 {
141 Character* player = ONgGameState->PlayerCharacter;
142 //char* oncc = *(char**)(player + CHR_oncc);
143 if (!inc_fallingframes)
144 inc_fallingframes = true;
145 if (player->ONCC->JetpackTimer == kangaroo_h)
146 {
147 player->ONCC->JumpAcceleration = cheat_oldjet_accel;
148 player->ONCC->JetpackTimer = cheat_oldjet_timer;
149 player->ONCC->MaxFallingHeightWithoutDamage = cheat_oldheight1;
150 player->ONCC->MaxFallingHeightWithDamage = cheat_oldheight2;
151 return 0;
152 }
153 else if ((unsigned short)player->ONCC->JetpackTimer == 0xFFFF)
154 {
155 player->ONCC->JumpAcceleration = kangaroo_jp;
156 player->ONCC->JetpackTimer = kangaroo_h;
157 player->ONCC->MaxFallingHeightWithoutDamage = DD_INFINITY;
158 player->ONCC->MaxFallingHeightWithDamage = DD_INFINITY;
159 return 1;
160 }
161 else
162 {
163 cheat_oldjet_accel = player->ONCC->JumpAcceleration;
164 cheat_oldjet_timer = player->ONCC->JetpackTimer;
165 cheat_oldheight1 = player->ONCC->MaxFallingHeightWithoutDamage ;
166 cheat_oldheight2 = player->ONCC->MaxFallingHeightWithDamage;
167 player->ONCC->JumpAcceleration = kangaroo_jp;
168 player->ONCC->JetpackTimer = kangaroo_h;
169 player->ONCC->MaxFallingHeightWithoutDamage = DD_INFINITY;
170 player->ONCC->MaxFallingHeightWithDamage = DD_INFINITY;
171 return 1;
172 }
173 }
174 case cheat_marypoppins:
175 {
176 Character* player = ONgGameState->PlayerCharacter;
177 if (!inc_fallingframes)
178 {
179 inc_fallingframes = true;
180 if ((unsigned short)player->ONCC->JetpackTimer == 0xFFFF)
181 {
182 player->ONCC->JumpAcceleration = cheat_oldjet_accel;
183 player->ONCC->JetpackTimer = cheat_oldjet_timer;
184 player->ONCC->MaxFallingHeightWithoutDamage = cheat_oldheight1;
185 player->ONCC->MaxFallingHeightWithDamage = cheat_oldheight2;
186 }
187 return 0;
188 }
189 else if (player->ONCC->JetpackTimer == kangaroo_h)
190 {
191 player->ONCC->JumpAcceleration = marypoppins_jp;
192 player->ONCC->JetpackTimer = 0xFFFF;
193 player->ONCC->MaxFallingHeightWithoutDamage = 0x7f800000;
194 player->ONCC->MaxFallingHeightWithDamage = 0x7f800000;
195 inc_fallingframes = false;
196 return 1;
197 }
198 else
199 {
200 cheat_oldjet_accel = player->ONCC->JumpAcceleration;
201 cheat_oldjet_timer = player->ONCC->JetpackTimer;
202 cheat_oldheight1 = player->ONCC->MaxFallingHeightWithoutDamage;
203 cheat_oldheight2 = player->ONCC->MaxFallingHeightWithDamage ;
204 player->ONCC->JumpAcceleration = marypoppins_jp;
205 player->ONCC->JetpackTimer = 0xFFFF;
206 player->ONCC->MaxFallingHeightWithoutDamage = 0x7f800000;
207 player->ONCC->MaxFallingHeightWithDamage = 0x7f800000;
208 inc_fallingframes = false;
209 return 1;
210 }
211 }
212 case cheat_buddha:
213 {
214 Character* player = ONgGameState->PlayerCharacter;
215 if (player->Flags& chr_unkillable)
216 {
217 player->Flags= player->Flags& ~chr_unkillable;
218 return 0;
219 }
220 else
221 {
222 player->Flags= player->Flags| chr_unkillable;
223 return 1;
224 }
225 }
226 case cheat_shinobi:
227 {
228 Character* player = ONgGameState->PlayerCharacter;
229 if (player->MaxHealth == 1)
230 {
231 player->Health = cheat_oldhealth;
232 player->MaxHealth = cheat_oldmaxhealth;
233 player->Flags = player->Flags & ~(chr_bossshield | chr_weaponimmune);
234 ai2_deaf = 0;
235 return 0;
236 }
237 else
238 {
239 cheat_oldhealth = player->Health;
240 cheat_oldmaxhealth = player->MaxHealth;
241 player->Health = 1;
242 player->MaxHealth = 1;
243 player->Flags = player->Flags | chr_bossshield | chr_weaponimmune;
244 ai2_deaf = 1;
245 return 1;
246 }
247
248 }
249 case cheat_testcheat:
250 {
251 Character* player = ONgGameState->PlayerCharacter;
252 player->Flags = player->Flags | chr_noncombatant;
253 return 1;
254 }
255 case cheat_elderrune:
256 {
257 if (DDrConfig_GetOptOfType("modding.d_regen", C_BOOL)->value.intBoolVal)
258 {
259 int* Regeneration = &ONgGameState->PlayerCharacter->RegenHax;
260 if(*Regeneration)
261 {
262 *Regeneration = 0;
263 return 0;
264 }
265 else
266 {
267 *Regeneration = 1;
268 return 1;
269 }
270 }
271 else
272 {
273 return ONrCheater(cheat_elderrune);
274 }
275 }
276
277 case cheat_tellmetheversion:
278 return 1;
279 case cheat_x:
280 return ONrCheater(cheat_thedayismine);
281 default:
282 return ONrCheater(cheat);
283 }
284}
285
286void ONICALL DDrCheater_LevelLoad()
287{
288 inc_fallingframes = true;
289}
290
291// Biggest hack in the entire thing ^_^
292void __stdcall FallingFrames(void* Ebp)
293{
294 if (inc_fallingframes)
295 ++*((unsigned int*)((char*)Ebp + 0xf6));
296}
297
298
299static void BindableCheatCallback (CustomActionCallbackArgument cheatnum) {
300 uint8_t res = DDrCheater (cheatnum);
301 if (res)
302 COrMessage_Print(DDr_CheatTable[cheatnum].message_on, 0, 240);
303 else
304 COrMessage_Print(DDr_CheatTable[cheatnum].message_off, 0, 240);
305}
306
307void InitBindableCheats() {
308 oniCheatCode* cur;
309 for (cur = DDr_CheatTable; cur->name != 0; cur++) {
310// char* val = malloc(20);
311// sprintf(val, "cheat_%s", cur->name);
312 Input_RegisterCustomAction (cur->name, EVENT_KEYPRESS, 0, BindableCheatCallback, cur->func);
313 }
314}
315
Note: See TracBrowser for help on using the repository browser.