Subversion Repositories eduke32

Rev

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