summaryrefslogtreecommitdiff
path: root/src/m_cheat.c
diff options
context:
space:
mode:
authorSimon Howard2005-10-04 21:41:42 +0000
committerSimon Howard2005-10-04 21:41:42 +0000
commita077c664121f6368a117a2d26688361ce00606f7 (patch)
tree1968bfbf4713ce05ae3e5928d6055da2b4c9c1da /src/m_cheat.c
parente98e86a672d7f1548c57a1b3351b1aacb60d9e03 (diff)
downloadchocolate-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
Diffstat (limited to 'src/m_cheat.c')
-rw-r--r--src/m_cheat.c86
1 files changed, 42 insertions, 44 deletions
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);
}