Subversion Repositories eduke32

Rev

Rev 8283 | 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 episode_num;
165
    int level_num;
166
 
167
    cp += sizeof("swtrek")-1;
168
    level_num = atol(cp);
169
 
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
    static SWBOOL cur_show;
5196 hendricks2 321
    int ret;
5198 hendricks2 322
    SWBOOL match = FALSE;
5196 hendricks2 323
    unsigned int i;
324
 
325
    //if (CommEnabled)
326
    //    return;
327
 
328
    strcpy(CheatInputString,MessageInputString);
329
 
330
    // make sure string is lower cased
331
    Bstrlwr(CheatInputString);
332
 
333
    // check for at least one single match
334
    for (i = 0; i < SIZ(ci); i++)
335
    {
336
        // compare without the NULL
337
        if (cheatcmp(CheatInputString, ci[i].CheatInputCode, strlen(CheatInputString)) == 0)
338
        {
339
 
340
            // if they are equal in length then its a complet match
341
            if (strlen(CheatInputString) == strlen(ci[i].CheatInputCode))
342
            {
343
                match = TRUE;
344
                CheatInputMode = FALSE;
345
 
346
                if (TEST(ci[i].flags, CF_NOTSW) && SW_SHAREWARE)
347
                    return;
348
 
349
                if (!TEST(ci[i].flags, CF_ALL))
350
                {
351
                    if (CommEnabled)
352
                        return;
353
 
354
                    if (Skill >= 3)
355
                    {
356
                        PutStringInfo(Player, "You're too skillful to cheat\n");
357
                        return;
358
                    }
359
                }
360
 
361
                if (ci[i].CheatInputFunc)
362
                    (*ci[i].CheatInputFunc)(Player, CheatInputString);
363
 
364
                return;
365
            }
366
            else
367
            {
368
                match = TRUE;
369
                break;
370
            }
371
        }
372
    }
373
 
374
    if (!match)
375
    {
376
        ////DSPRINTF(ds,"Lost A Match %s", CheatInputString);
377
        //MONO_PRINT(ds);
378
 
379
        CheatInputMode = FALSE;
380
    }
381
}
382
 
383
/*    OLD CODE
384
void CheatInput(void)
385
    {
5198 hendricks2 386
    static SWBOOL cur_show;
5196 hendricks2 387
    signed char MNU_InputString(char *, short);
388
    int ret;
5198 hendricks2 389
    SWBOOL match = FALSE;
5196 hendricks2 390
    short i;
391
 
392
    // don't use InputMode here - its set for CheatInputMode
393
    if (MessageInputMode || MenuInputMode)
394
        return;
395
 
396
    if (!CheatInputMode)
397
        {
398
        if (KEY_PRESSED(KEYSC_S))
399
            {
400
            //KEY_PRESSED(KEYSC_S) = FALSE;
401
            CheatInputMode = TRUE;
402
            strcpy(CheatInputString,"s");
403
            }
404
        }
405
 
406
    if (CheatInputMode)
407
        {
408
        // get new chars
409
        ret = MNU_InputString(CheatInputString, 320-20);
410
 
411
        // quick check input
412
        switch (ret)
413
            {
414
            case FALSE: // Input finished (RETURN)
415
            case -1: // Cancel Input (pressed ESC) or Err
416
                CheatInputMode = FALSE;
417
                KB_FlushKeyboardQueue();
418
                return;
419
 
420
            case TRUE: // Got input
421
                break;
422
            }
423
 
424
        // make sure string is lower cased
8283 hendricks2 425
        Bstrlwr(CheatInputString);
5196 hendricks2 426
 
427
        // check for at least one single match
428
        for (i = 0; i < SIZ(ci); i++)
429
            {
430
            // compare without the NULL
431
            if (cheatcmp(CheatInputString, ci[i].CheatInputCode, strlen(CheatInputString)) == 0)
432
                {
433
                ////DSPRINTF(ds,"%s",CheatInputString);
434
                //MONO_PRINT(ds);
435
 
436
                // if they are equal in length then its a complet match
437
                if (strlen(CheatInputString) == strlen(ci[i].CheatInputCode))
438
                    {
439
                    ////DSPRINTF(ds,"Found A Match %s", CheatInputString);
440
                    //MONO_PRINT(ds);
441
 
442
                    match = TRUE;
443
 
444
                    CheatInputMode = FALSE;
445
                    KB_FlushKeyboardQueue();
446
 
447
                    if (ci[i].CheatInputFunc)
448
                        (*ci[i].CheatInputFunc)(Player, CheatInputString);
449
 
450
                    return;
451
                    }
452
                else
453
                    {
454
                    match = TRUE;
455
                    break;
456
                    }
457
                }
458
            }
459
 
460
        if (!match)
461
            {
462
            ////DSPRINTF(ds,"Lost A Match %s", CheatInputString);
463
            //MONO_PRINT(ds);
464
 
465
            CheatInputMode = FALSE;
466
            KB_FlushKeyboardQueue();
467
            }
468
        }
469
    }
470
 
471
*/