Subversion Repositories eduke32

Rev

Rev 7499 | Rev 8343 | 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
 
120
        // ALL WEAPONS
121
        if (!SW_SHAREWARE)
122
            p->WpnFlags = 0xFFFFFFFF;
123
        else
124
            p->WpnFlags = 0x0000207F;  // Disallows high weapon cheat in shareware
125
 
126
        for (i = 0; i < SIZ(p->WpnAmmo); i++)
127
        {
128
            p->WpnAmmo[i] = DamageData[i].max_ammo;
129
        }
130
 
131
        PlayerUpdateWeapon(p, u->WeaponNum);
132
    }
133
}
134
 
135
 
5198 hendricks2 136
void GodCheat(PLAYERp pp, char *UNUSED(cheat_string))
5196 hendricks2 137
{
138
    //
139
    // GOD mode
140
    //
141
    GodMode ^= 1;
142
 
143
    sprintf(ds, "GOD MODE %s", GodMode ? "ON" : "OFF");
144
    PutStringInfo(pp, ds);
145
}
146
 
5198 hendricks2 147
void ClipCheat(PLAYERp pp, char *UNUSED(cheat_string))
5196 hendricks2 148
{
149
    FLIP(pp->Flags, PF_CLIP_CHEAT);
150
 
151
    sprintf(ds, "NO CLIP MODE %s", TEST(pp->Flags, PF_CLIP_CHEAT) ? "ON" : "OFF");
152
    PutStringInfo(pp, ds);
153
}
154
 
5198 hendricks2 155
void WarpCheat(PLAYERp pp, char *cheat_string)
5196 hendricks2 156
{
157
    char *cp = cheat_string;
158
    int episode_num;
159
    int level_num;
160
 
161
    cp += sizeof("swtrek")-1;
162
    level_num = atol(cp);
163
 
164
    //DSPRINTF(ds,"ep %d, lev %d",episode_num, level_num);
165
    //MONO_PRINT(ds);
166
 
167
    if (!SW_SHAREWARE)
168
    {
169
        if (level_num > 28 || level_num < 1)
170
            return;
171
    }
172
    else
173
    {
174
        if (level_num > 4 || level_num < 1)
175
            return;
176
    }
177
 
178
    Level = level_num;
179
    ExitLevel = TRUE;
180
 
181
    sprintf(ds, "ENTERING %1d", Level);
182
    PutStringInfo(pp, ds);
183
}
184
 
5198 hendricks2 185
void ItemCheat(PLAYERp pp, char *cheat_string)
5196 hendricks2 186
{
187
    //
188
    // Get all ITEMS
189
    //
190
    PLAYERp p;
191
    short pnum;
192
    short inv;
193
    int i;
194
 
195
    PutStringInfo(pp, "ITEMS");
196
 
197
    TRAVERSE_CONNECT(pnum)
198
    {
199
        p = &Player[pnum];
200
        memset(p->HasKey, TRUE, sizeof(p->HasKey));
201
 
202
        if (p->Wpn[WPN_UZI] && p->CurWpn == p->Wpn[WPN_UZI])
203
        {
204
            SET(p->Flags, PF_TWO_UZI);
205
            SET(p->Flags, PF_PICKED_UP_AN_UZI);
206
            InitWeaponUzi(p);
207
        }
208
 
209
        p->WpnShotgunAuto = 50;
210
        p->WpnRocketHeat = 5;
211
        p->WpnRocketNuke = 1;
212
        p->Armor = 100;
213
 
214
        for (inv = 0; inv < MAX_INVENTORY; inv++)
215
        {
216
            p->InventoryPercent[inv] = 100;
217
            //p->InventoryAmount[inv] = 1;
218
            p->InventoryAmount[inv] = InventoryData[inv].MaxInv;
219
            //PlayerUpdateInventory(p, inv);
220
        }
221
 
222
        PlayerUpdateInventory(p, p->InventoryNum);
223
        //p->InventoryNum = 0;
224
    }
225
 
226
    for (i=0; i<numsectors; i++)
227
    {
228
        if (SectUser[i] && SectUser[i]->stag == SECT_LOCK_DOOR)
229
            SectUser[i]->number = 0;  // unlock all doors of this type
230
    }
231
 
232
    WeaponCheat(pp, cheat_string);
233
    PlayerUpdateKeys(pp);
234
}
235
 
5198 hendricks2 236
void EveryCheatToggle(PLAYERp pp, char *cheat_string)
5196 hendricks2 237
{
238
    EveryCheat ^= 1;
239
 
240
    WeaponCheat(pp, cheat_string);
241
    GodCheat(pp, cheat_string);
242
    ItemCheat(pp, cheat_string);
243
 
244
    sprintf(ds, "EVERY CHEAT %s", EveryCheat ? "ON" : "OFF");
245
    PutStringInfo(pp, ds);
246
}
247
 
5198 hendricks2 248
void SaveCheat(PLAYERp pp, char *UNUSED(cheat_string))
5196 hendricks2 249
{
5201 hendricks2 250
    saveboard("swsave.map", (vec3_t *)pp,
251
              pp->pang, pp->cursectnum);
5196 hendricks2 252
}
253
 
5198 hendricks2 254
void GeorgeFunc(PLAYERp pp, char *UNUSED(cheat_string))
5196 hendricks2 255
{
256
    PlayerSound(DIGI_TAUNTAI9,&pp->posx,&pp->posy,&pp->posz,v3df_dontpan|v3df_doppler|v3df_follow,pp);
257
}
258
 
5198 hendricks2 259
void BlackburnFunc(PLAYERp pp, char *UNUSED(cheat_string))
5196 hendricks2 260
{
261
    PlayerSound(DIGI_TAUNTAI3,&pp->posx,&pp->posy,&pp->posz,v3df_dontpan|v3df_doppler|v3df_follow,pp);
262
}
263
 
7499 hendricks2 264
int cheatcmp(const char *str1, const char *str2, int len)
5196 hendricks2 265
{
7499 hendricks2 266
    const char *cp1 = str1;
267
    const char *cp2 = str2;
5196 hendricks2 268
 
269
    do
270
    {
271
        if (*cp1 != *cp2)
272
        {
273
            if (!((*cp1 == '#' && isdigit(*cp2)) || (*cp2 == '#' && isdigit(*cp1))))
274
                return -1;
275
        }
276
 
277
        cp1++;
278
        cp2++;
279
    }
280
    while (--len);
281
 
282
    return 0;
283
}
284
 
285
 
286
#define CF_ALL    BIT(0)
287
#define CF_NOTSW  BIT(1)
288
 
289
typedef struct
290
{
7499 hendricks2 291
    const char *CheatInputCode;
5196 hendricks2 292
    void (*CheatInputFunc)(PLAYERp, char *);
293
    char flags;
294
} CHEAT_INFO, *CHEAT_INFOp;
295
 
296
 
297
CHEAT_INFO ci[] =
298
{
299
    {"swchan",      GodCheat, 0},
300
    {"swgimme",     ItemCheat, 0},
301
    {"swtrek##",    WarpCheat, 0},
302
    {"swgreed",     EveryCheatToggle, 0},
303
    {"swghost",      ClipCheat, 0},
304
 
305
    {"swstart",     RestartCheat, 0},
306
 
307
    {"swres",       ResCheatOn, 0},
308
    {"swloc",       LocCheat, 0},
309
    {"swmap",       MapCheat, 0},
310
    {"swsave",      SaveCheat, CF_ALL},
311
    {"swroom",      RoomCheat, CF_NOTSW}, // Room above room dbug
312
#if DEBUG
313
    {"swsecret",    SecretCheat, CF_ALL},
314
#endif
315
};
316
 
317
 
318
// !JIM! My simplified version of CheatInput which simply processes MessageInputString
319
void CheatInput(void)
320
{
5198 hendricks2 321
    static SWBOOL cur_show;
5196 hendricks2 322
    int ret;
5198 hendricks2 323
    SWBOOL match = FALSE;
5196 hendricks2 324
    unsigned int i;
325
 
326
    //if (CommEnabled)
327
    //    return;
328
 
329
    strcpy(CheatInputString,MessageInputString);
330
 
331
    // make sure string is lower cased
332
    Bstrlwr(CheatInputString);
333
 
334
    // check for at least one single match
335
    for (i = 0; i < SIZ(ci); i++)
336
    {
337
        // compare without the NULL
338
        if (cheatcmp(CheatInputString, ci[i].CheatInputCode, strlen(CheatInputString)) == 0)
339
        {
340
 
341
            // if they are equal in length then its a complet match
342
            if (strlen(CheatInputString) == strlen(ci[i].CheatInputCode))
343
            {
344
                match = TRUE;
345
                CheatInputMode = FALSE;
346
 
347
                if (TEST(ci[i].flags, CF_NOTSW) && SW_SHAREWARE)
348
                    return;
349
 
350
                if (!TEST(ci[i].flags, CF_ALL))
351
                {
352
                    if (CommEnabled)
353
                        return;
354
 
355
                    if (Skill >= 3)
356
                    {
357
                        PutStringInfo(Player, "You're too skillful to cheat\n");
358
                        return;
359
                    }
360
                }
361
 
362
                if (ci[i].CheatInputFunc)
363
                    (*ci[i].CheatInputFunc)(Player, CheatInputString);
364
 
365
                return;
366
            }
367
            else
368
            {
369
                match = TRUE;
370
                break;
371
            }
372
        }
373
    }
374
 
375
    if (!match)
376
    {
377
        ////DSPRINTF(ds,"Lost A Match %s", CheatInputString);
378
        //MONO_PRINT(ds);
379
 
380
        CheatInputMode = FALSE;
381
    }
382
}
383
 
384
/*    OLD CODE
385
void CheatInput(void)
386
    {
5198 hendricks2 387
    static SWBOOL cur_show;
5196 hendricks2 388
    signed char MNU_InputString(char *, short);
389
    int ret;
5198 hendricks2 390
    SWBOOL match = FALSE;
5196 hendricks2 391
    short i;
392
 
393
    // don't use InputMode here - its set for CheatInputMode
394
    if (MessageInputMode || MenuInputMode)
395
        return;
396
 
397
    if (!CheatInputMode)
398
        {
399
        if (KEY_PRESSED(KEYSC_S))
400
            {
401
            //KEY_PRESSED(KEYSC_S) = FALSE;
402
            CheatInputMode = TRUE;
403
            strcpy(CheatInputString,"s");
404
            }
405
        }
406
 
407
    if (CheatInputMode)
408
        {
409
        // get new chars
410
        ret = MNU_InputString(CheatInputString, 320-20);
411
 
412
        // quick check input
413
        switch (ret)
414
            {
415
            case FALSE: // Input finished (RETURN)
416
            case -1: // Cancel Input (pressed ESC) or Err
417
                CheatInputMode = FALSE;
418
                KB_FlushKeyboardQueue();
419
                return;
420
 
421
            case TRUE: // Got input
422
                break;
423
            }
424
 
425
        // make sure string is lower cased
8283 hendricks2 426
        Bstrlwr(CheatInputString);
5196 hendricks2 427
 
428
        // check for at least one single match
429
        for (i = 0; i < SIZ(ci); i++)
430
            {
431
            // compare without the NULL
432
            if (cheatcmp(CheatInputString, ci[i].CheatInputCode, strlen(CheatInputString)) == 0)
433
                {
434
                ////DSPRINTF(ds,"%s",CheatInputString);
435
                //MONO_PRINT(ds);
436
 
437
                // if they are equal in length then its a complet match
438
                if (strlen(CheatInputString) == strlen(ci[i].CheatInputCode))
439
                    {
440
                    ////DSPRINTF(ds,"Found A Match %s", CheatInputString);
441
                    //MONO_PRINT(ds);
442
 
443
                    match = TRUE;
444
 
445
                    CheatInputMode = FALSE;
446
                    KB_FlushKeyboardQueue();
447
 
448
                    if (ci[i].CheatInputFunc)
449
                        (*ci[i].CheatInputFunc)(Player, CheatInputString);
450
 
451
                    return;
452
                    }
453
                else
454
                    {
455
                    match = TRUE;
456
                    break;
457
                    }
458
                }
459
            }
460
 
461
        if (!match)
462
            {
463
            ////DSPRINTF(ds,"Lost A Match %s", CheatInputString);
464
            //MONO_PRINT(ds);
465
 
466
            CheatInputMode = FALSE;
467
            KB_FlushKeyboardQueue();
468
            }
469
        }
470
    }
471
 
472
*/