diff options
author | Simon Howard | 2005-10-04 21:41:42 +0000 |
---|---|---|
committer | Simon Howard | 2005-10-04 21:41:42 +0000 |
commit | a077c664121f6368a117a2d26688361ce00606f7 (patch) | |
tree | 1968bfbf4713ce05ae3e5928d6055da2b4c9c1da | |
parent | e98e86a672d7f1548c57a1b3351b1aacb60d9e03 (diff) | |
download | chocolate-doom-a077c664121f6368a117a2d26688361ce00606f7.tar.gz chocolate-doom-a077c664121f6368a117a2d26688361ce00606f7.tar.bz2 chocolate-doom-a077c664121f6368a117a2d26688361ce00606f7.zip |
Rewrite cheats code. Add dehacked cheat replacement.
Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 162
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/am_map.c | 10 | ||||
-rw-r--r-- | src/am_map.h | 10 | ||||
-rw-r--r-- | src/deh_cheat.c | 134 | ||||
-rw-r--r-- | src/deh_main.c | 8 | ||||
-rw-r--r-- | src/m_cheat.c | 86 | ||||
-rw-r--r-- | src/m_cheat.h | 29 | ||||
-rw-r--r-- | src/st_stuff.c | 111 | ||||
-rw-r--r-- | src/st_stuff.h | 17 |
9 files changed, 259 insertions, 149 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index ab7a7026..523fed90 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -29,7 +29,8 @@ dstrings.c i_sound.h p_ceilng.c p_spec.h r_sky.h z_zone.h \ dstrings.h i_system.c p_doors.c p_switch.c r_state.h mmus2mid.c \ d_textur.h i_system.h p_enemy.c p_telept.c r_things.c mmus2mid.h \ deh_defs.h deh_frame.c deh_main.c deh_ptr.c deh_text.c deh_thing.c \ -deh_io.c deh_io.h deh_ammo.c deh_weapon.c deh_mapping.c deh_mapping.h +deh_io.c deh_io.h deh_ammo.c deh_cheat.c deh_weapon.c \ +deh_mapping.c deh_mapping.h if HAVE_WINDRES diff --git a/src/am_map.c b/src/am_map.c index 9e6b1ab8..ead062ab 100644 --- a/src/am_map.c +++ b/src/am_map.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: am_map.c 160 2005-10-03 21:39:39Z fraggle $ +// $Id: am_map.c 162 2005-10-04 21:41:42Z fraggle $ // // Copyright(C) 1993-1996 Id Software, Inc. // Copyright(C) 2005 Simon Howard @@ -23,6 +23,9 @@ // // // $Log$ +// Revision 1.7 2005/10/04 21:41:42 fraggle +// Rewrite cheats code. Add dehacked cheat replacement. +// // Revision 1.6 2005/10/03 21:39:39 fraggle // Dehacked text substitutions // @@ -46,7 +49,7 @@ // //----------------------------------------------------------------------------- -static const char rcsid[] = "$Id: am_map.c 160 2005-10-03 21:39:39Z fraggle $"; +static const char rcsid[] = "$Id: am_map.c 162 2005-10-04 21:41:42Z fraggle $"; #include <stdio.h> @@ -310,8 +313,7 @@ static int markpointnum = 0; // next point to be assigned static int followplayer = 1; // specifies whether to follow the player around -static unsigned char cheat_amap_seq[] = { 0xb2, 0x26, 0x26, 0x2e, 0xff }; -static cheatseq_t cheat_amap = { cheat_amap_seq, 0 }; +cheatseq_t cheat_amap = CHEAT("iddt", 0); static boolean stopped = true; diff --git a/src/am_map.h b/src/am_map.h index 1d722c3f..1ef0785a 100644 --- a/src/am_map.h +++ b/src/am_map.h @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: am_map.h 8 2005-07-23 16:44:57Z fraggle $ +// $Id: am_map.h 162 2005-10-04 21:41:42Z fraggle $ // // Copyright(C) 1993-1996 Id Software, Inc. // Copyright(C) 2005 Simon Howard @@ -29,6 +29,9 @@ #ifndef __AMMAP_H__ #define __AMMAP_H__ +#include "d_event.h" +#include "m_cheat.h" + // Used by ST StatusBar stuff. #define AM_MSGHEADER (('a'<<24)+('m'<<16)) #define AM_MSGENTERED (AM_MSGHEADER | ('e'<<8)) @@ -50,11 +53,16 @@ void AM_Drawer (void); void AM_Stop (void); +extern cheatseq_t cheat_amap; + #endif //----------------------------------------------------------------------------- // // $Log$ +// Revision 1.3 2005/10/04 21:41:42 fraggle +// Rewrite cheats code. Add dehacked cheat replacement. +// // Revision 1.2 2005/07/23 16:44:55 fraggle // Update copyright to GNU GPL // diff --git a/src/deh_cheat.c b/src/deh_cheat.c new file mode 100644 index 00000000..0fd8cd2a --- /dev/null +++ b/src/deh_cheat.c @@ -0,0 +1,134 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// $Id: deh_cheat.c 162 2005-10-04 21:41:42Z fraggle $ +// +// Copyright(C) 2005 Simon Howard +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. +// +// $Log$ +// Revision 1.1 2005/10/04 21:41:42 fraggle +// Rewrite cheats code. Add dehacked cheat replacement. +// +// Revision 1.2 2005/10/03 11:08:16 fraggle +// Replace end of section functions with NULLs as they arent currently being +// used for anything. +// +// Revision 1.1 2005/10/02 23:49:01 fraggle +// The beginnings of dehacked support +// +// +//----------------------------------------------------------------------------- +// +// Parses "Cheat" sections in dehacked files +// +//----------------------------------------------------------------------------- + +#include "doomdef.h" +#include "doomtype.h" +#include "deh_defs.h" +#include "deh_main.h" +#include "am_map.h" +#include "st_stuff.h" + +typedef struct +{ + char *name; + cheatseq_t *seq; +} deh_cheat_t; + +static deh_cheat_t allcheats[] = +{ + {"Change music", &cheat_mus }, + {"Chainsaw", &cheat_choppers }, + {"God mode", &cheat_god }, + {"Ammo & Keys", &cheat_ammo }, + {"Ammo", &cheat_ammonokey }, + {"No Clipping 1", &cheat_noclip }, + {"No Clipping 2", &cheat_commercial_noclip }, + {"Invincibility", &cheat_powerup[0] }, + {"Berserk", &cheat_powerup[1] }, + {"Invisibility", &cheat_powerup[2] }, + {"Radiation Suit", &cheat_powerup[3] }, + {"Auto-map", &cheat_powerup[4] }, + {"Lite-Amp Goggles", &cheat_powerup[5] }, + {"BEHOLD menu", &cheat_powerup[6] }, + {"Level Warp", &cheat_clev }, + {"Player Position", &cheat_mypos }, + {"Map cheat", &cheat_amap }, +}; + +static deh_cheat_t *FindCheatByName(char *name) +{ + int i; + + for (i=0; i<sizeof(allcheats) / sizeof(*allcheats); ++i) + { + if (!strcasecmp(allcheats[i].name, name)) + return &allcheats[i]; + } + + return NULL; +} + +static void *DEH_CheatStart(deh_context_t *context, char *line) +{ + return NULL; +} + +static void DEH_CheatParseLine(deh_context_t *context, char *line, void *tag) +{ + deh_cheat_t *cheat; + char *variable_name; + unsigned char *value; + int i; + + if (!DEH_ParseAssignment(line, &variable_name, (char *) &value)) + { + // Failed to parse + + return; + } + + cheat = FindCheatByName(variable_name); + + if (cheat == NULL) + { + fprintf(stderr, "DEH_ParseCheatLine: Unknown cheat '%s'\n", + variable_name); + return; + } + + // write the value into the cheat sequence + + for (i=0; + i<cheat->seq->sequence_len && value[i] != 0 && value[i] != 0xff; + ++i) + cheat->seq->sequence[i] = value[i]; + + cheat->seq->sequence[i] = '\0'; +} + +deh_section_t deh_section_cheat = +{ + "Cheat", + NULL, + DEH_CheatStart, + DEH_CheatParseLine, + NULL, +}; + diff --git a/src/deh_main.c b/src/deh_main.c index 2c773de7..e65aceef 100644 --- a/src/deh_main.c +++ b/src/deh_main.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: deh_main.c 157 2005-10-03 11:08:16Z fraggle $ +// $Id: deh_main.c 162 2005-10-04 21:41:42Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -21,6 +21,9 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.3 2005/10/04 21:41:42 fraggle +// Rewrite cheats code. Add dehacked cheat replacement. +// // Revision 1.2 2005/10/03 11:08:16 fraggle // Replace end of section functions with NULLs as they arent currently being // used for anything. @@ -47,6 +50,8 @@ // deh_ammo.c: extern deh_section_t deh_section_ammo; +// deh_cheat.c: +extern deh_section_t deh_section_cheat; // deh_frame.c: extern deh_section_t deh_section_frame; // deh_pointer.c: @@ -65,6 +70,7 @@ extern deh_section_t deh_section_weapon; static deh_section_t *section_types[] = { &deh_section_ammo, + &deh_section_cheat, &deh_section_frame, &deh_section_pointer, &deh_section_text, diff --git a/src/m_cheat.c b/src/m_cheat.c index 6b6a1003..bf5ad639 100644 --- a/src/m_cheat.c +++ b/src/m_cheat.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: m_cheat.c 8 2005-07-23 16:44:57Z fraggle $ +// $Id: m_cheat.c 162 2005-10-04 21:41:42Z fraggle $ // // Copyright(C) 1993-1996 Id Software, Inc. // Copyright(C) 2005 Simon Howard @@ -22,6 +22,9 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.3 2005/10/04 21:41:42 fraggle +// Rewrite cheats code. Add dehacked cheat replacement. +// // Revision 1.2 2005/07/23 16:44:55 fraggle // Update copyright to GNU GPL // @@ -36,18 +39,17 @@ static const char -rcsid[] = "$Id: m_cheat.c 8 2005-07-23 16:44:57Z fraggle $"; +rcsid[] = "$Id: m_cheat.c 162 2005-10-04 21:41:42Z fraggle $"; + +#include <string.h> +#include "doomtype.h" #include "m_cheat.h" // // CHEAT SEQUENCE PACKAGE // -static int firsttime = 1; -static unsigned char cheat_xlate_table[256]; - - // // Called in st_stuff module, which handles the input. // Returns a 1 if the cheat was successful, 0 if failed. @@ -57,34 +59,46 @@ cht_CheckCheat ( cheatseq_t* cht, char key ) { - int i; - int rc = 0; + // if we make a short sequence on a cheat with parameters, this + // will not work in vanilla doom. behave the same. - if (firsttime) + if (cht->parameter_chars > 0 && strlen(cht->sequence) < cht->sequence_len) + return false; + + if (cht->chars_read < strlen(cht->sequence)) { - firsttime = 0; - for (i=0;i<256;i++) cheat_xlate_table[i] = SCRAMBLE(i); + // still reading characters from the cheat code + // and verifying. reset back to the beginning + // if a key is wrong + + if (key == cht->sequence[cht->chars_read]) + ++cht->chars_read; + else + cht->chars_read = 0; + + cht->param_chars_read = 0; + } + else if (cht->param_chars_read < cht->parameter_chars) + { + // we have passed the end of the cheat sequence and are + // entering parameters now + + cht->parameter_buf[cht->param_chars_read] = key; + + ++cht->param_chars_read; } - if (!cht->p) - cht->p = cht->sequence; // initialize if first time - - if (*cht->p == 0) - *(cht->p++) = key; - else if - (cheat_xlate_table[(unsigned char)key] == *cht->p) cht->p++; - else - cht->p = cht->sequence; - - if (*cht->p == 1) - cht->p++; - else if (*cht->p == 0xff) // end of sequence character + if (cht->chars_read >= strlen(cht->sequence) + && cht->param_chars_read >= cht->parameter_chars) { - cht->p = cht->sequence; - rc = 1; + cht->chars_read = cht->param_chars_read = 0; + + return true; } + + // cheat not matched yet - return rc; + return false; } void @@ -92,23 +106,7 @@ cht_GetParam ( cheatseq_t* cht, char* buffer ) { - - unsigned char *p, c; - - p = cht->sequence; - while (*(p++) != 1); - - do - { - c = *p; - *(buffer++) = c; - *(p++) = 0; - } - while (c && *p!=0xff ); - - if (*p==0xff) - *buffer = 0; - + memcpy(buffer, cht->parameter_buf, cht->parameter_chars); } diff --git a/src/m_cheat.h b/src/m_cheat.h index 84703b30..158dc6e4 100644 --- a/src/m_cheat.h +++ b/src/m_cheat.h @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: m_cheat.h 8 2005-07-23 16:44:57Z fraggle $ +// $Id: m_cheat.h 162 2005-10-04 21:41:42Z fraggle $ // // Copyright(C) 1993-1996 Id Software, Inc. // Copyright(C) 2005 Simon Howard @@ -34,15 +34,27 @@ // CHEAT SEQUENCE PACKAGE // -#define SCRAMBLE(a) \ -((((a)&1)<<7) + (((a)&2)<<5) + ((a)&4) + (((a)&8)<<1) \ - + (((a)&16)>>1) + ((a)&32) + (((a)&64)>>5) + (((a)&128)>>7)) +// declaring a cheat + +#define CHEAT(value, parameters) \ + { value, sizeof(value) - 1, parameters, 0, 0 } + +#define MAX_CHEAT_LEN 15 +#define MAX_CHEAT_PARAMS 5 typedef struct { - unsigned char* sequence; - unsigned char* p; - + // settings for this cheat + + char sequence[MAX_CHEAT_LEN]; + int sequence_len; + int parameter_chars; + + // state used during the game + + int chars_read; + int param_chars_read; + char parameter_buf[MAX_CHEAT_PARAMS]; } cheatseq_t; int @@ -61,6 +73,9 @@ cht_GetParam //----------------------------------------------------------------------------- // // $Log$ +// Revision 1.3 2005/10/04 21:41:42 fraggle +// Rewrite cheats code. Add dehacked cheat replacement. +// // Revision 1.2 2005/07/23 16:44:55 fraggle // Update copyright to GNU GPL // diff --git a/src/st_stuff.c b/src/st_stuff.c index 27b9cd79..0e3fc4cf 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: st_stuff.c 160 2005-10-03 21:39:39Z fraggle $ +// $Id: st_stuff.c 162 2005-10-04 21:41:42Z fraggle $ // // Copyright(C) 1993-1996 Id Software, Inc. // Copyright(C) 2005 Simon Howard @@ -22,6 +22,9 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.6 2005/10/04 21:41:42 fraggle +// Rewrite cheats code. Add dehacked cheat replacement. +// // Revision 1.5 2005/10/03 21:39:39 fraggle // Dehacked text substitutions // @@ -46,7 +49,7 @@ //----------------------------------------------------------------------------- static const char -rcsid[] = "$Id: st_stuff.c 160 2005-10-03 21:39:39Z fraggle $"; +rcsid[] = "$Id: st_stuff.c 162 2005-10-04 21:41:42Z fraggle $"; #include <stdio.h> @@ -415,99 +418,27 @@ static int keyboxes[3]; // a random number per tick static int st_randomnumber; - - -// Massive bunches of cheat shit -// to keep it from being easy to figure them out. -// Yeah, right... -unsigned char cheat_mus_seq[] = -{ - 0xb2, 0x26, 0xb6, 0xae, 0xea, 1, 0, 0, 0xff -}; - -unsigned char cheat_choppers_seq[] = -{ - 0xb2, 0x26, 0xe2, 0x32, 0xf6, 0x2a, 0x2a, 0xa6, 0x6a, 0xea, 0xff // id... -}; - -unsigned char cheat_god_seq[] = -{ - 0xb2, 0x26, 0x26, 0xaa, 0x26, 0xff // iddqd -}; - -unsigned char cheat_ammo_seq[] = -{ - 0xb2, 0x26, 0xf2, 0x66, 0xa2, 0xff // idkfa -}; - -unsigned char cheat_ammonokey_seq[] = -{ - 0xb2, 0x26, 0x66, 0xa2, 0xff // idfa -}; - - -// Smashing Pumpkins Into Samml Piles Of Putried Debris. -unsigned char cheat_noclip_seq[] = -{ - 0xb2, 0x26, 0xea, 0x2a, 0xb2, // idspispopd - 0xea, 0x2a, 0xf6, 0x2a, 0x26, 0xff -}; - -// -unsigned char cheat_commercial_noclip_seq[] = -{ - 0xb2, 0x26, 0xe2, 0x36, 0xb2, 0x2a, 0xff // idclip -}; - - - -unsigned char cheat_powerup_seq[7][10] = -{ - { 0xb2, 0x26, 0x62, 0xa6, 0x32, 0xf6, 0x36, 0x26, 0x6e, 0xff }, // beholdv - { 0xb2, 0x26, 0x62, 0xa6, 0x32, 0xf6, 0x36, 0x26, 0xea, 0xff }, // beholds - { 0xb2, 0x26, 0x62, 0xa6, 0x32, 0xf6, 0x36, 0x26, 0xb2, 0xff }, // beholdi - { 0xb2, 0x26, 0x62, 0xa6, 0x32, 0xf6, 0x36, 0x26, 0x6a, 0xff }, // beholdr - { 0xb2, 0x26, 0x62, 0xa6, 0x32, 0xf6, 0x36, 0x26, 0xa2, 0xff }, // beholda - { 0xb2, 0x26, 0x62, 0xa6, 0x32, 0xf6, 0x36, 0x26, 0x36, 0xff }, // beholdl - { 0xb2, 0x26, 0x62, 0xa6, 0x32, 0xf6, 0x36, 0x26, 0xff } // behold -}; - - -unsigned char cheat_clev_seq[] = -{ - 0xb2, 0x26, 0xe2, 0x36, 0xa6, 0x6e, 1, 0, 0, 0xff // idclev -}; - - -// my position cheat -unsigned char cheat_mypos_seq[] = -{ - 0xb2, 0x26, 0xb6, 0xba, 0x2a, 0xf6, 0xea, 0xff // idmypos -}; - - -// Now what? -cheatseq_t cheat_mus = { cheat_mus_seq, 0 }; -cheatseq_t cheat_god = { cheat_god_seq, 0 }; -cheatseq_t cheat_ammo = { cheat_ammo_seq, 0 }; -cheatseq_t cheat_ammonokey = { cheat_ammonokey_seq, 0 }; -cheatseq_t cheat_noclip = { cheat_noclip_seq, 0 }; -cheatseq_t cheat_commercial_noclip = { cheat_commercial_noclip_seq, 0 }; +cheatseq_t cheat_mus = CHEAT("idmus", 2); +cheatseq_t cheat_god = CHEAT("iddqd", 0); +cheatseq_t cheat_ammo = CHEAT("idkfa", 0); +cheatseq_t cheat_ammonokey = CHEAT("idfa", 0); +cheatseq_t cheat_noclip = CHEAT("idspispopd", 0); +cheatseq_t cheat_commercial_noclip = CHEAT("idclip", 0); cheatseq_t cheat_powerup[7] = { - { cheat_powerup_seq[0], 0 }, - { cheat_powerup_seq[1], 0 }, - { cheat_powerup_seq[2], 0 }, - { cheat_powerup_seq[3], 0 }, - { cheat_powerup_seq[4], 0 }, - { cheat_powerup_seq[5], 0 }, - { cheat_powerup_seq[6], 0 } + CHEAT("idbeholdv", 0), + CHEAT("idbeholds", 0), + CHEAT("idbeholdi", 0), + CHEAT("idbeholdr", 0), + CHEAT("idbeholda", 0), + CHEAT("idbeholdl", 0), + CHEAT("idbehold", 0), }; -cheatseq_t cheat_choppers = { cheat_choppers_seq, 0 }; -cheatseq_t cheat_clev = { cheat_clev_seq, 0 }; -cheatseq_t cheat_mypos = { cheat_mypos_seq, 0 }; +cheatseq_t cheat_choppers = CHEAT("idchoppers", 0); +cheatseq_t cheat_clev = CHEAT("idclev", 2); +cheatseq_t cheat_mypos = CHEAT("idmypos", 0); // diff --git a/src/st_stuff.h b/src/st_stuff.h index 130f0424..f4385a59 100644 --- a/src/st_stuff.h +++ b/src/st_stuff.h @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: st_stuff.h 8 2005-07-23 16:44:57Z fraggle $ +// $Id: st_stuff.h 162 2005-10-04 21:41:42Z fraggle $ // // Copyright(C) 1993-1996 Id Software, Inc. // Copyright(C) 2005 Simon Howard @@ -33,6 +33,7 @@ #include "doomtype.h" #include "d_event.h" +#include "m_cheat.h" // Size of statusbar. // Now sensitive for scaling. @@ -83,12 +84,25 @@ typedef enum boolean ST_Responder(event_t* ev); +extern cheatseq_t cheat_mus; +extern cheatseq_t cheat_god; +extern cheatseq_t cheat_ammo; +extern cheatseq_t cheat_ammonokey; +extern cheatseq_t cheat_noclip; +extern cheatseq_t cheat_commercial_noclip; +extern cheatseq_t cheat_powerup[7]; +extern cheatseq_t cheat_choppers; +extern cheatseq_t cheat_clev; +extern cheatseq_t cheat_mypos; #endif //----------------------------------------------------------------------------- // // $Log$ +// Revision 1.3 2005/10/04 21:41:42 fraggle +// Rewrite cheats code. Add dehacked cheat replacement. +// // Revision 1.2 2005/07/23 16:44:57 fraggle // Update copyright to GNU GPL // @@ -97,3 +111,4 @@ boolean ST_Responder(event_t* ev); // // //----------------------------------------------------------------------------- + |