Subversion Repositories eduke32

Rev

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