m_cheat.cpp (3229B)
1 /* 2 =========================================================================== 3 4 Doom 3 BFG Edition GPL Source Code 5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 6 7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). 8 9 Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation, either version 3 of the License, or 12 (at your option) any later version. 13 14 Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>. 21 22 In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below. 23 24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. 25 26 =========================================================================== 27 */ 28 29 #include "Precompiled.h" 30 #include "globaldata.h" 31 32 #include "m_cheat.h" 33 34 // 35 // CHEAT SEQUENCE PACKAGE 36 // 37 38 39 40 // 41 // Called in st_stuff module, which handles the input. 42 // Returns a 1 if the cheat was successful, 0 if failed. 43 // 44 int 45 cht_CheckCheat 46 ( cheatseq_t* cht, 47 char key ) 48 { 49 return 0; // ALAN : Checking the cheats CRASHES?? 50 int i; 51 int rc = 0; 52 53 if (::g->firsttime) 54 { 55 ::g->firsttime = 0; 56 for (i=0;i<256;i++) ::g->cheat_xlate_table[i] = SCRAMBLE(i); 57 } 58 59 if (!cht->p) 60 { 61 cht->p = ::g->cheatbuffer + ::g->usedcheatbuffer; 62 int isize = 0; 63 while(cht->sequence[isize] != 0xff) cht->p[isize] = cht->sequence[isize]; 64 cht->p[isize] = 0xff; 65 ::g->usedcheatbuffer += isize; 66 ::g->usedcheatbuffer ++; 67 } 68 69 if (*cht->p == 0) 70 *(cht->p++) = key; 71 else if 72 (::g->cheat_xlate_table[(unsigned char)key] == *cht->p) cht->p++; 73 else 74 { 75 int isize = 0; 76 while(cht->sequence[isize] != 0xff) cht->p[isize] = cht->sequence[isize]; 77 cht->p[isize] = 0xff; 78 } 79 80 if (*cht->p == 1) 81 cht->p++; 82 else if (*cht->p == 0xff) // end of sequence character 83 { 84 int isize = 0; 85 while(cht->sequence[isize] != 0xff) cht->p[isize] = cht->sequence[isize]; 86 cht->p[isize] = 0xff; 87 rc = 1; 88 } 89 90 return rc; 91 } 92 93 void 94 cht_GetParam 95 ( cheatseq_t* cht, 96 char* buffer ) 97 { 98 99 100 unsigned char pb[16]; 101 unsigned char *p; 102 unsigned char c; 103 104 int isize = 0; 105 106 while(cht->sequence[isize] != 0xff) pb[isize] = cht->sequence[isize]; 107 pb[isize] = 0xff; 108 p = &pb[0]; 109 110 while (*(p++) != 1); 111 112 do 113 { 114 c = *p; 115 *(buffer++) = c; 116 *(p++) = 0; 117 } 118 while (c && *p!=0xff ); 119 120 if (*p==0xff) 121 *buffer = 0; 122 123 124 } 125 126 127