1 // Emacs style mode select -*- C++ -*-
2 //-----------------------------------------------------------------------------
4 // Copyright(C) 2005 Simon Howard
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 //-----------------------------------------------------------------------------
23 // Parses "Cheat" sections in dehacked files
25 //-----------------------------------------------------------------------------
42 static deh_cheat_t allcheats
[] =
44 {"Change music", &cheat_mus
},
45 {"Chainsaw", &cheat_choppers
},
46 {"God mode", &cheat_god
},
47 {"Ammo & Keys", &cheat_ammo
},
48 {"Ammo", &cheat_ammonokey
},
49 {"No Clipping 1", &cheat_noclip
},
50 {"No Clipping 2", &cheat_commercial_noclip
},
51 {"Invincibility", &cheat_powerup
[0] },
52 {"Berserk", &cheat_powerup
[1] },
53 {"Invisibility", &cheat_powerup
[2] },
54 {"Radiation Suit", &cheat_powerup
[3] },
55 {"Auto-map", &cheat_powerup
[4] },
56 {"Lite-Amp Goggles", &cheat_powerup
[5] },
57 {"BEHOLD menu", &cheat_powerup
[6] },
58 {"Level Warp", &cheat_clev
},
59 {"Player Position", &cheat_mypos
},
60 {"Map cheat", &cheat_amap
},
63 static deh_cheat_t
*FindCheatByName(char *name
)
67 for (i
=0; i
<arrlen(allcheats
); ++i
)
69 if (!strcasecmp(allcheats
[i
].name
, name
))
76 static void *DEH_CheatStart(deh_context_t
*context
, char *line
)
81 static void DEH_CheatParseLine(deh_context_t
*context
, char *line
, void *tag
)
86 unsigned char *unsvalue
;
89 if (!DEH_ParseAssignment(line
, &variable_name
, &value
))
93 DEH_Warning(context
, "Failed to parse assignment");
97 unsvalue
= (unsigned char *) value
;
99 cheat
= FindCheatByName(variable_name
);
103 DEH_Warning(context
, "Unknown cheat '%s'", variable_name
);
107 // write the value into the cheat sequence
111 while (unsvalue
[i
] != 0 && unsvalue
[i
] != 0xff)
113 // If the cheat length exceeds the Vanilla limit, stop. This
114 // does not apply if we have the limit turned off.
116 if (!deh_allow_long_cheats
&& i
>= cheat
->seq
->sequence_len
)
118 DEH_Warning(context
, "Cheat sequence longer than supported by "
123 if (deh_apply_cheats
)
125 cheat
->seq
->sequence
[i
] = unsvalue
[i
];
129 // Absolute limit - don't exceed
131 if (i
>= MAX_CHEAT_LEN
- cheat
->seq
->parameter_chars
)
133 DEH_Error(context
, "Cheat sequence too long!");
138 if (deh_apply_cheats
)
140 cheat
->seq
->sequence
[i
] = '\0';
144 deh_section_t deh_section_cheat
=