Subversion Repositories eduke32

Rev

Rev 8685 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5196 hendricks2 1
//-------------------------------------------------------------------------
2
/*
3
Copyright (C) 1997, 2005 - 3D Realms Entertainment
4
 
5
This file is part of Shadow Warrior version 1.2
6
 
7
Shadow Warrior is free software; you can redistribute it and/or
8
modify it under the terms of the GNU General Public License
9
as published by the Free Software Foundation; either version 2
10
of the License, or (at your option) any later version.
11
 
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
 
16
See the GNU General Public License for more details.
17
 
18
You should have received a copy of the GNU General Public License
19
along with this program; if not, write to the Free Software
20
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21
 
22
Original Source: 1997 - Frank Maddin and Jim Norwood
23
Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
24
*/
25
//-------------------------------------------------------------------------
26
#include "build.h"
27
 
28
#include "keys.h"
29
#include "names2.h"
30
#include "panel.h"
31
#include "game.h"
32
#include "mytypes.h"
33
#include "text.h"
34
 
35
#include "control.h"
36
#include "function.h"
37
//#include "inv.h"
38
 
39
 
5198 hendricks2 40
SWBOOL CheatInputMode = FALSE;
5196 hendricks2 41
char CheatInputString[256];
5198 hendricks2 42
SWBOOL EveryCheat = FALSE;
43
SWBOOL ResCheat = FALSE;
5196 hendricks2 44
 
5198 hendricks2 45
void ResCheatOn(PLAYERp UNUSED(pp), char *UNUSED(cheat_string))
5196 hendricks2 46
{
47
    ResCheat = TRUE;
48
}
49
 
5198 hendricks2 50
void VoxCheat(PLAYERp UNUSED(pp), char *UNUSED(cheat_string))
5196 hendricks2 51
{
52
    //gs.Voxel ^= 1;
53
}
54
 
5198 hendricks2 55
void RestartCheat(PLAYERp UNUSED(pp), char *UNUSED(cheat_string))
5196 hendricks2 56
{
57
    ExitLevel = TRUE;
58
}
59
 
5198 hendricks2 60
void RoomCheat(PLAYERp UNUSED(pp), char *UNUSED(cheat_string))
5196 hendricks2 61
{
5198 hendricks2 62
    extern SWBOOL FAF_DebugView;
5196 hendricks2 63
    FAF_DebugView ^= 1;
64
}
65
 
5198 hendricks2 66
void SecretCheat(PLAYERp UNUSED(pp), char *UNUSED(cheat_string))
5196 hendricks2 67
{
68
    gs.Stats = !gs.Stats;
69
}
70
 
5198 hendricks2 71
void NextCheat(PLAYERp UNUSED(pp), char *UNUSED(cheat_string))
5196 hendricks2 72
{
73
    Level++;
74
    ExitLevel = TRUE;
75
}
76
 
5198 hendricks2 77
void PrevCheat(PLAYERp UNUSED(pp), char *UNUSED(cheat_string))
5196 hendricks2 78
{
79
    Level--;
80
    ExitLevel = TRUE;
81
}
82
 
5207 hendricks2 83
static int32_t showallmap;
84
 
5198 hendricks2 85
void MapCheat(PLAYERp pp, char *UNUSED(cheat_string))
5196 hendricks2 86
{
5207 hendricks2 87
    showallmap ^= 1;
5196 hendricks2 88
 
5207 hendricks2 89
    if (showallmap)
5196 hendricks2 90
        MapSetAll2D(0);
91
    else
92
        MapSetAll2D(0xFF);
93
 
5207 hendricks2 94
    sprintf(ds, "SHOWALLMAP %s", showallmap ? "ON" : "OFF");
5196 hendricks2 95
    PutStringInfo(pp, ds);
96
}
97
 
98
 
5198 hendricks2 99
void LocCheat(PLAYERp UNUSED(pp), char *UNUSED(cheat_string))
5196 hendricks2 100
{
5198 hendricks2 101
    extern SWBOOL LocationInfo;
5196 hendricks2 102
    LocationInfo++;
103
    if (LocationInfo > 2)
104
        LocationInfo = 0;
105
}
106
 
107
 
5198 hendricks2 108
void WeaponCheat(PLAYERp UNUSED(pp), char *UNUSED(cheat_string))
5196 hendricks2 109
{
110
    PLAYERp p;
111
    short pnum;
112
    unsigned int i;
113
    USERp u;
114
 
115
    TRAVERSE_CONNECT(pnum)
116
    {
117
        p = &Player[pnum];
118
        u = User[p->PlayerSprite];
119
 
8343 hendricks2 120
        if (!TEST(p->Flags, PF_TWO_UZI))
121
        {
122
            SET(p->Flags, PF_TWO_UZI);
123
            SET(p->Flags, PF_PICKED_UP_AN_UZI);
124
        }
125
 
5196 hendricks2 126
        // ALL WEAPONS
127
        if (!SW_SHAREWARE)
128
            p->WpnFlags = 0xFFFFFFFF;
129
        else
130
            p->WpnFlags = 0x0000207F;  // Disallows high weapon cheat in shareware
131
 
132
        for (i = 0; i < SIZ(p->WpnAmmo); i++)
133
        {
134
            p->WpnAmmo[i] = DamageData[i].max_ammo;
135
        }
136
 
137
        PlayerUpdateWeapon(p, u->WeaponNum);
138
    }
139
}
140
 
141
 
5198 hendricks2 142
void GodCheat(PLAYERp pp, char *UNUSED(cheat_string))
5196 hendricks2 143
{
144
    //
145
    // GOD mode
146
    //
147
    GodMode ^= 1;
148
 
149
    sprintf(ds, "GOD MODE %s", GodMode ? "ON" : "OFF");
150
    PutStringInfo(pp, ds);
151
}
152
 
5198 hendricks2 153
void ClipCheat(PLAYERp pp, char *UNUSED(cheat_string))
5196 hendricks2 154
{
155
    FLIP(pp->Flags, PF_CLIP_CHEAT);
156
 
157
    sprintf(ds, "NO CLIP MODE %s", TEST(pp->Flags, PF_CLIP_CHEAT) ? "ON" : "OFF");
158
    PutStringInfo(pp, ds);
159
}
160
 
5198 hendricks2 161
void WarpCheat(PLAYERp pp, char *cheat_string)
5196 hendricks2 162
{
163
    char *cp = cheat_string;
164
    int level_num;
165
 
166
    cp += sizeof("swtrek")-1;
167
    level_num = atol(cp);
168
 
8686 ny00123 169
    //int episode_num;
5196 hendricks2 170
    //DSPRINTF(ds,"ep %d, lev %d",episode_num, level_num);
171
    //MONO_PRINT(ds);
172
 
173
    if (!SW_SHAREWARE)
174
    {
175
        if (level_num > 28 || level_num < 1)
176
            return;
177
    }
178
    else
179
    {
180
        if (level_num > 4 || level_num < 1)
181
            return;
182
    }
183
 
184
    Level = level_num;
185
    ExitLevel = TRUE;
186
 
187
    sprintf(ds, "ENTERING %1d", Level);
188
    PutStringInfo(pp, ds);
189
}
190
 
5198 hendricks2 191
void ItemCheat(PLAYERp pp, char *cheat_string)
5196 hendricks2 192
{
193
    //
194
    // Get all ITEMS
195
    //
196
    PLAYERp p;
197
    short pnum;
198
    short inv;
199
    int i;
200
 
201
    PutStringInfo(pp, "ITEMS");
202
 
203
    TRAVERSE_CONNECT(pnum)
204
    {
205
        p = &Player[pnum];
206
        memset(p->HasKey, TRUE, sizeof(p->HasKey));
207
 
208
        p->WpnShotgunAuto = 50;
209
        p->WpnRocketHeat = 5;
210
        p->WpnRocketNuke = 1;
211
        p->Armor = 100;
212
 
213
        for (inv = 0; inv < MAX_INVENTORY; inv++)
214
        {
215
            p->InventoryPercent[inv] = 100;
216
            //p->InventoryAmount[inv] = 1;
217
            p->InventoryAmount[inv] = InventoryData[inv].MaxInv;
218
            //PlayerUpdateInventory(p, inv);
219
        }
220
 
221
        PlayerUpdateInventory(p, p->InventoryNum);
222
        //p->InventoryNum = 0;
223
    }
224
 
225
    for (i=0; i<numsectors; i++)
226
    {
227
        if (SectUser[i] && SectUser[i]->stag == SECT_LOCK_DOOR)
228
            SectUser[i]->number = 0;  // unlock all doors of this type
229
    }
230
 
231
    WeaponCheat(pp, cheat_string);
232
    PlayerUpdateKeys(pp);
233
}
234
 
5198 hendricks2 235
void EveryCheatToggle(PLAYERp pp, char *cheat_string)
5196 hendricks2 236
{
237
    EveryCheat ^= 1;
238
 
239
    WeaponCheat(pp, cheat_string);
240
    GodCheat(pp, cheat_string);
241
    ItemCheat(pp, cheat_string);
242
 
243
    sprintf(ds, "EVERY CHEAT %s", EveryCheat ? "ON" : "OFF");
244
    PutStringInfo(pp, ds);
245
}
246
 
5198 hendricks2 247
void SaveCheat(PLAYERp pp, char *UNUSED(cheat_string))
5196 hendricks2 248
{
5201 hendricks2 249
    saveboard("swsave.map", (vec3_t *)pp,
250
              pp->pang, pp->cursectnum);
5196 hendricks2 251
}
252
 
5198 hendricks2 253
void GeorgeFunc(PLAYERp pp, char *UNUSED(cheat_string))
5196 hendricks2 254
{
255
    PlayerSound(DIGI_TAUNTAI9,&pp->posx,&pp->posy,&pp->posz,v3df_dontpan|v3df_doppler|v3df_follow,pp);
256
}
257
 
5198 hendricks2 258
void BlackburnFunc(PLAYERp pp, char *UNUSED(cheat_string))
5196 hendricks2 259
{
260
    PlayerSound(DIGI_TAUNTAI3,&pp->posx,&pp->posy,&pp->posz,v3df_dontpan|v3df_doppler|v3df_follow,pp);
261
}
262
 
7499 hendricks2 263
int cheatcmp(const char *str1, const char *str2, int len)
5196 hendricks2 264
{
7499 hendricks2 265
    const char *cp1 = str1;
266
    const char *cp2 = str2;
5196 hendricks2 267
 
268
    do
269
    {
270
        if (*cp1 != *cp2)
271
        {
272
            if (!((*cp1 == '#' && isdigit(*cp2)) || (*cp2 == '#' && isdigit(*cp1))))
273
                return -1;
274
        }
275
 
276
        cp1++;
277
        cp2++;
278
    }
279
    while (--len);
280
 
281
    return 0;
282
}
283
 
284
 
285
#define CF_ALL    BIT(0)
286
#define CF_NOTSW  BIT(1)
287
 
288
typedef struct
289
{
7499 hendricks2 290
    const char *CheatInputCode;
5196 hendricks2 291
    void (*CheatInputFunc)(PLAYERp, char *);
292
    char flags;
293
} CHEAT_INFO, *CHEAT_INFOp;
294
 
295
 
296
CHEAT_INFO ci[] =
297
{
298
    {"swchan",      GodCheat, 0},
299
    {"swgimme",     ItemCheat, 0},
300
    {"swtrek##",    WarpCheat, 0},
301
    {"swgreed",     EveryCheatToggle, 0},
302
    {"swghost",      ClipCheat, 0},
303
 
304
    {"swstart",     RestartCheat, 0},
305
 
306
    {"swres",       ResCheatOn, 0},
307
    {"swloc",       LocCheat, 0},
308
    {"swmap",       MapCheat, 0},
309
    {"swsave",      SaveCheat, CF_ALL},
310
    {"swroom",      RoomCheat, CF_NOTSW}, // Room above room dbug
311
#if DEBUG
312
    {"swsecret",    SecretCheat, CF_ALL},
313
#endif
314
};
315
 
316
 
317
// !JIM! My simplified version of CheatInput which simply processes MessageInputString
318
void CheatInput(void)
319
{
5198 hendricks2 320
    SWBOOL match = FALSE;
5196 hendricks2 321
    unsigned int i;
322
 
323
    //if (CommEnabled)
324
    //    return;
325
 
326
    strcpy(CheatInputString,MessageInputString);
327
 
328
    // make sure string is lower cased
329
    Bstrlwr(CheatInputString);
330
 
331
    // check for at least one single match
332
    for (i = 0; i < SIZ(ci); i++)
333
    {
334
        // compare without the NULL
335
        if (cheatcmp(CheatInputString, ci[i].CheatInputCode, strlen(CheatInputString)) == 0)
336
        {
337
 
338
            // if they are equal in length then its a complet match
339
            if (strlen(CheatInputString) == strlen(ci[i].CheatInputCode))
340
            {
341
                match = TRUE;
342
                CheatInputMode = FALSE;
343
 
344
                if (TEST(ci[i].flags, CF_NOTSW) && SW_SHAREWARE)
345
                    return;
346
 
347
                if (!TEST(ci[i].flags, CF_ALL))
348
                {
349
                    if (CommEnabled)
350
                        return;
351
 
352
                    if (Skill >= 3)
353
                    {
354
                        PutStringInfo(Player, "You're too skillful to cheat\n");
355
                        return;
356
                    }
357
                }
358
 
359
                if (ci[i].CheatInputFunc)
360
                    (*ci[i].CheatInputFunc)(Player, CheatInputString);
361
 
362
                return;
363
            }
364
            else
365
            {
366
                match = TRUE;
367
                break;
368
            }
369
        }
370
    }
371
 
372
    if (!match)
373
    {
374
        ////DSPRINTF(ds,"Lost A Match %s", CheatInputString);
375
        //MONO_PRINT(ds);
376
 
377
        CheatInputMode = FALSE;
378
    }
379
}
380
 
381
/*    OLD CODE
382
void CheatInput(void)
383
    {
5198 hendricks2 384
    static SWBOOL cur_show;
5196 hendricks2 385
    signed char MNU_InputString(char *, short);
386
    int ret;
5198 hendricks2 387
    SWBOOL match = FALSE;
5196 hendricks2 388
    short i;
389
 
390
    // don't use InputMode here - its set for CheatInputMode
391
    if (MessageInputMode || MenuInputMode)
392
        return;
393
 
394
    if (!CheatInputMode)
395
        {
396
        if (KEY_PRESSED(KEYSC_S))
397
            {
398
            //KEY_PRESSED(KEYSC_S) = FALSE;
399
            CheatInputMode = TRUE;
400
            strcpy(CheatInputString,"s");
401
            }
402
        }
403
 
404
    if (CheatInputMode)
405
        {
406
        // get new chars
407
        ret = MNU_InputString(CheatInputString, 320-20);
408
 
409
        // quick check input
410
        switch (ret)
411
            {
412
            case FALSE: // Input finished (RETURN)
413
            case -1: // Cancel Input (pressed ESC) or Err
414
                CheatInputMode = FALSE;
415
                KB_FlushKeyboardQueue();
416
                return;
417
 
418
            case TRUE: // Got input
419
                break;
420
            }
421
 
422
        // make sure string is lower cased
8283 hendricks2 423
        Bstrlwr(CheatInputString);
5196 hendricks2 424
 
425
        // check for at least one single match
426
        for (i = 0; i < SIZ(ci); i++)
427
            {
428
            // compare without the NULL
429
            if (cheatcmp(CheatInputString, ci[i].CheatInputCode, strlen(CheatInputString)) == 0)
430
                {
431
                ////DSPRINTF(ds,"%s",CheatInputString);
432
                //MONO_PRINT(ds);
433
 
434
                // if they are equal in length then its a complet match
435
                if (strlen(CheatInputString) == strlen(ci[i].CheatInputCode))
436
                    {
437
                    ////DSPRINTF(ds,"Found A Match %s", CheatInputString);
438
                    //MONO_PRINT(ds);
439
 
440
                    match = TRUE;
441
 
442
                    CheatInputMode = FALSE;
443
                    KB_FlushKeyboardQueue();
444
 
445
                    if (ci[i].CheatInputFunc)
446
                        (*ci[i].CheatInputFunc)(Player, CheatInputString);
447
 
448
                    return;
449
                    }
450
                else
451
                    {
452
                    match = TRUE;
453
                    break;
454
                    }
455
                }
456
            }
457
 
458
        if (!match)
459
            {
460
            ////DSPRINTF(ds,"Lost A Match %s", CheatInputString);
461
            //MONO_PRINT(ds);
462
 
463
            CheatInputMode = FALSE;
464
            KB_FlushKeyboardQueue();
465
            }
466
        }
467
    }
468
 
469
*/