m_cheat.c (877B)
1 #include "m_cheat.h" 2 3 4 5 6 7 static int firsttime = 1; 8 static unsigned char cheat_xlate_table[256]; 9 10 11 12 13 14 15 int 16 cht_CheckCheat 17 ( cheatseq_t* cht, 18 char key ) 19 { 20 int i; 21 int rc = 0; 22 23 if (firsttime) 24 { 25 firsttime = 0; 26 for (i=0;i<256;i++) cheat_xlate_table[i] = SCRAMBLE(i); 27 } 28 29 if (!cht->p) 30 cht->p = cht->sequence; 31 32 if (*cht->p == 0) 33 *(cht->p++) = key; 34 else if 35 (cheat_xlate_table[(unsigned char)key] == *cht->p) cht->p++; 36 else 37 cht->p = cht->sequence; 38 39 if (*cht->p == 1) 40 cht->p++; 41 else if (*cht->p == 0xff) 42 { 43 cht->p = cht->sequence; 44 rc = 1; 45 } 46 47 return rc; 48 } 49 50 void 51 cht_GetParam 52 ( cheatseq_t* cht, 53 char* buffer ) 54 { 55 56 unsigned char *p, c; 57 58 p = cht->sequence; 59 while (*(p++) != 1); 60 61 do 62 { 63 c = *p; 64 *(buffer++) = c; 65 *(p++) = 0; 66 } 67 while (c && *p!=0xff ); 68 69 if (*p==0xff) 70 *buffer = 0; 71 72 } 73 74