Subversion Repositories eduke32

Rev

Rev 879 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5 Plagman 1
//-------------------------------------------------------------------------
2
/*
484 terminx 3
Copyright (C) 1996, 2003 - 3D Realms Entertainment
4
Copyright (C) 2000, 2003 - Matt Saettler (EDuke Enhancements)
5
Copyright (C) 2004, 2007 - EDuke32 developers
6
 
5 Plagman 7
This file is part of EDuke32
8
 
9
EDuke32 is free software; you can redistribute it and/or
10
modify it under the terms of the GNU General Public License version 2
11
as published by the Free Software Foundation.
12
 
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
 
17
See the GNU General Public License for more details.
18
 
19
You should have received a copy of the GNU General Public License
20
along with this program; if not, write to the Free Software
21
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
*/
23
//-------------------------------------------------------------------------
24
 
434 Plagman 25
#include "compat.h"
5 Plagman 26
#include "osdcmds.h"
27
#include "osd.h"
28
#include "baselayer.h"
29
#include "duke3d.h"
30
#include "crc32.h"
31
#include <ctype.h>
841 terminx 32
#include <limits.h>
5 Plagman 33
 
821 terminx 34
extern int voting, doquicksave;
5 Plagman 35
struct osdcmd_cheatsinfo osdcmd_cheatsinfo_stat;
36
 
416 terminx 37
static inline int osdcmd_quit(const osdfuncparm_t *parm)
5 Plagman 38
{
654 terminx 39
    UNREFERENCED_PARAMETER(parm);
77 terminx 40
    sendquit();
5 Plagman 41
    return OSDCMD_OK;
42
}
43
 
416 terminx 44
static int osdcmd_echo(const osdfuncparm_t *parm)
5 Plagman 45
{
46
    int i;
335 terminx 47
    for (i = 0; i < parm->numparms; i++)
48
    {
5 Plagman 49
        if (i > 0) OSD_Printf(" ");
50
        OSD_Printf("%s", parm->parms[i]);
51
    }
52
    OSD_Printf("\n");
53
 
54
    return OSDCMD_OK;
55
}
56
 
416 terminx 57
static int osdcmd_changelevel(const osdfuncparm_t *parm)
5 Plagman 58
{
91 terminx 59
    int volume=0,level;
5 Plagman 60
    char *p;
61
 
335 terminx 62
    if (!VOLUMEONE)
63
    {
5 Plagman 64
        if (parm->numparms != 2) return OSDCMD_SHOWHELP;
65
 
66
        volume = strtol(parm->parms[0], &p, 10) - 1;
67
        if (p[0]) return OSDCMD_SHOWHELP;
68
        level = strtol(parm->parms[1], &p, 10) - 1;
69
        if (p[0]) return OSDCMD_SHOWHELP;
335 terminx 70
    }
71
    else
72
    {
5 Plagman 73
        if (parm->numparms != 1) return OSDCMD_SHOWHELP;
74
 
75
        level = strtol(parm->parms[0], &p, 10) - 1;
76
        if (p[0]) return OSDCMD_SHOWHELP;
77
    }
78
 
79
    if (volume < 0) return OSDCMD_SHOWHELP;
80
    if (level < 0) return OSDCMD_SHOWHELP;
81
 
335 terminx 82
    if (!VOLUMEONE)
83
    {
84
        if (volume > num_volumes)
85
        {
584 terminx 86
            OSD_Printf("changelevel: invalid volume number (range 1-%d)\n",num_volumes);
5 Plagman 87
            return OSDCMD_OK;
88
        }
89
    }
90
 
564 terminx 91
    if (level > MAXLEVELS || map[volume*MAXLEVELS+level].filename == NULL)
335 terminx 92
    {
564 terminx 93
        OSD_Printf("changelevel: invalid level number\n");
94
        return OSDCMD_SHOWHELP;
335 terminx 95
    }
5 Plagman 96
 
413 terminx 97
    if (numplayers > 1)
98
    {
99
        if (myconnectindex == connecthead && networkmode == 0)
414 terminx 100
            mpchangemap(volume,level);
413 terminx 101
        else if (voting == -1)
102
        {
103
            ud.m_volume_number = volume;
104
            ud.m_level_number = level;
472 terminx 105
 
564 terminx 106
            if (g_player[myconnectindex].ps->i)
413 terminx 107
            {
108
                int i;
472 terminx 109
 
564 terminx 110
                for (i=0;i<MAXPLAYERS;i++)
111
                {
112
                    g_player[i].vote = 0;
113
                    g_player[i].gotvote = 0;
114
                }
115
 
116
                g_player[myconnectindex].vote = g_player[myconnectindex].gotvote = 1;
117
 
413 terminx 118
                voting = myconnectindex;
119
 
120
                tempbuf[0] = 18;
121
                tempbuf[1] = 1;
122
                tempbuf[2] = myconnectindex;
123
                tempbuf[3] = ud.m_volume_number;
124
                tempbuf[4] = ud.m_level_number;
125
 
126
                for (i=connecthead;i>=0;i=connectpoint2[i])
127
                {
128
                    if (i != myconnectindex) sendpacket(i,tempbuf,5);
129
                    if ((!networkmode) && (myconnectindex != connecthead)) break; //slaves in M/S mode only send to master
130
                }
131
            }
132
            if ((gametype_flags[ud.m_coop] & GAMETYPE_FLAG_PLAYERSFRIENDLY) && !(gametype_flags[ud.m_coop] & GAMETYPE_FLAG_TDM))
133
                ud.m_noexits = 0;
134
 
564 terminx 135
            g_player[myconnectindex].ps->gm |= MODE_MENU;
413 terminx 136
            cmenu(603);
137
        }
138
        return OSDCMD_OK;
139
    }
564 terminx 140
    if (g_player[myconnectindex].ps->gm & MODE_GAME)
335 terminx 141
    {
5 Plagman 142
        // in-game behave like a cheat
143
        osdcmd_cheatsinfo_stat.cheatnum = 2;
144
        osdcmd_cheatsinfo_stat.volume   = volume;
145
        osdcmd_cheatsinfo_stat.level    = level;
335 terminx 146
    }
147
    else
148
    {
5 Plagman 149
        // out-of-game behave like a menu command
150
        osdcmd_cheatsinfo_stat.cheatnum = -1;
151
 
152
        ud.m_volume_number = volume;
153
        ud.m_level_number = level;
154
 
155
        ud.m_monsters_off = ud.monsters_off = 0;
156
 
157
        ud.m_respawn_items = 0;
158
        ud.m_respawn_inventory = 0;
159
 
160
        ud.multimode = 1;
161
 
162
        newgame(ud.m_volume_number,ud.m_level_number,ud.m_player_skill);
163
        if (enterlevel(MODE_GAME)) backtomenu();
164
    }
165
 
166
    return OSDCMD_OK;
167
}
168
 
416 terminx 169
static int osdcmd_map(const osdfuncparm_t *parm)
5 Plagman 170
{
171
    int i;
172
    char filename[256];
173
 
174
    if (parm->numparms != 1) return OSDCMD_SHOWHELP;
175
 
413 terminx 176
#if 0
379 terminx 177
    if (numplayers > 1)
178
    {
179
        OSD_Printf("Command not allowed in multiplayer\n");
180
        return OSDCMD_OK;
181
    }
413 terminx 182
#endif
183
 
184
    strcpy(filename,parm->parms[0]);
333 terminx 185
    if (strchr(filename,'.') == 0)
5 Plagman 186
        strcat(filename,".map");
187
 
335 terminx 188
    if ((i = kopen4load(filename,0)) < 0)
189
    {
5 Plagman 190
        OSD_Printf("map: file \"%s\" not found.\n", filename);
191
        return OSDCMD_OK;
192
    }
193
    kclose(i);
194
 
413 terminx 195
    boardfilename[0] = '/';
196
    boardfilename[1] = 0;
197
    strcat(boardfilename, filename);
5 Plagman 198
 
413 terminx 199
    if (numplayers > 1)
200
    {
201
        if (myconnectindex == connecthead && networkmode == 0)
202
        {
203
            sendboardname();
472 terminx 204
            mpchangemap(0,7);
413 terminx 205
        }
206
        else if (voting == -1)
207
        {
208
            sendboardname();
472 terminx 209
 
413 terminx 210
            ud.m_volume_number = 0;
211
            ud.m_level_number = 7;
472 terminx 212
 
564 terminx 213
            if (g_player[myconnectindex].ps->i)
413 terminx 214
            {
215
                int i;
472 terminx 216
 
564 terminx 217
                for (i=0;i<MAXPLAYERS;i++)
218
                {
219
                    g_player[i].vote = 0;
220
                    g_player[i].gotvote = 0;
221
                }
222
 
223
                g_player[myconnectindex].vote = g_player[myconnectindex].gotvote = 1;
413 terminx 224
                voting = myconnectindex;
225
 
226
                tempbuf[0] = 18;
227
                tempbuf[1] = 1;
228
                tempbuf[2] = myconnectindex;
229
                tempbuf[3] = ud.m_volume_number;
230
                tempbuf[4] = ud.m_level_number;
231
 
232
                for (i=connecthead;i>=0;i=connectpoint2[i])
233
                {
234
                    if (i != myconnectindex) sendpacket(i,tempbuf,5);
235
                    if ((!networkmode) && (myconnectindex != connecthead)) break; //slaves in M/S mode only send to master
236
                }
237
            }
238
            if ((gametype_flags[ud.m_coop] & GAMETYPE_FLAG_PLAYERSFRIENDLY) && !(gametype_flags[ud.m_coop] & GAMETYPE_FLAG_TDM))
239
                ud.m_noexits = 0;
240
 
564 terminx 241
            g_player[myconnectindex].ps->gm |= MODE_MENU;
413 terminx 242
            cmenu(603);
243
        }
244
        return OSDCMD_OK;
245
    }
246
 
472 terminx 247
    osdcmd_cheatsinfo_stat.cheatnum = -1;
248
    ud.m_volume_number = 0;
249
    ud.m_level_number = 7;
413 terminx 250
 
472 terminx 251
    ud.m_monsters_off = ud.monsters_off = 0;
5 Plagman 252
 
472 terminx 253
    ud.m_respawn_items = 0;
254
    ud.m_respawn_inventory = 0;
5 Plagman 255
 
472 terminx 256
    ud.multimode = 1;
5 Plagman 257
 
472 terminx 258
    newgame(ud.m_volume_number,ud.m_level_number,ud.m_player_skill);
259
    if (enterlevel(MODE_GAME)) backtomenu();
5 Plagman 260
 
261
    return OSDCMD_OK;
262
}
263
 
416 terminx 264
static int osdcmd_god(const osdfuncparm_t *parm)
5 Plagman 265
{
654 terminx 266
    UNREFERENCED_PARAMETER(parm);
564 terminx 267
    if (numplayers == 1 && g_player[myconnectindex].ps->gm & MODE_GAME)
335 terminx 268
    {
5 Plagman 269
        osdcmd_cheatsinfo_stat.cheatnum = 0;
335 terminx 270
    }
271
    else
272
    {
5 Plagman 273
        OSD_Printf("god: Not in a single-player game.\n");
274
    }
275
 
276
    return OSDCMD_OK;
277
}
278
 
416 terminx 279
static int osdcmd_noclip(const osdfuncparm_t *parm)
5 Plagman 280
{
654 terminx 281
    UNREFERENCED_PARAMETER(parm);
564 terminx 282
    if (numplayers == 1 && g_player[myconnectindex].ps->gm & MODE_GAME)
335 terminx 283
    {
5 Plagman 284
        osdcmd_cheatsinfo_stat.cheatnum = 20;
335 terminx 285
    }
286
    else
287
    {
5 Plagman 288
        OSD_Printf("noclip: Not in a single-player game.\n");
289
    }
290
 
291
    return OSDCMD_OK;
292
}
293
 
416 terminx 294
static int osdcmd_fileinfo(const osdfuncparm_t *parm)
5 Plagman 295
{
584 terminx 296
    unsigned int crc, length;
5 Plagman 297
    int i,j;
298
    char buf[256];
299
 
300
    if (parm->numparms != 1) return OSDCMD_SHOWHELP;
301
 
335 terminx 302
    if ((i = kopen4load((char *)parm->parms[0],0)) < 0)
303
    {
5 Plagman 304
        OSD_Printf("fileinfo: File \"%s\" not found.\n", parm->parms[0]);
305
        return OSDCMD_OK;
306
    }
307
 
308
    length = kfilelength(i);
309
 
310
    crc32init(&crc);
335 terminx 311
    do
312
    {
5 Plagman 313
        j = kread(i,buf,256);
344 terminx 314
        crc32block(&crc,(unsigned char *)buf,j);
335 terminx 315
    }
316
    while (j == 256);
5 Plagman 317
    crc32finish(&crc);
318
 
319
    kclose(i);
320
 
321
    OSD_Printf("fileinfo: %s\n"
322
               "  File size: %d\n"
323
               "  CRC-32:    %08X\n",
324
               parm->parms[0], length, crc);
325
 
326
    return OSDCMD_OK;
327
}
328
 
470 terminx 329
static int osdcmd_rate(const osdfuncparm_t *parm)
330
{
331
    int i;
472 terminx 332
 
470 terminx 333
    if (parm->numparms == 0)
334
    {
335
        OSD_Printf("\"rate\" is \"%d\"\n", packetrate);
336
        return OSDCMD_SHOWHELP;
337
    }
338
    else if (parm->numparms != 1) return OSDCMD_SHOWHELP;
339
 
340
    i = Batol(parm->parms[0]);
341
 
342
    if (i >= 40 && i <= 1000)
343
    {
344
        packetrate = i;
345
        OSD_Printf("rate %d\n", packetrate);
346
    }
347
    else OSD_Printf("rate: value out of range\n");
348
    return OSDCMD_OK;
349
}
350
 
472 terminx 351
static int osdcmd_restartsound(const osdfuncparm_t *parm)
352
{
654 terminx 353
    UNREFERENCED_PARAMETER(parm);
472 terminx 354
    SoundShutdown();
355
    MusicShutdown();
356
 
848 terminx 357
    initprintf("Initializing music...\n");
472 terminx 358
    MusicStartup();
848 terminx 359
    initprintf("Initializing sound...\n");
472 terminx 360
    SoundStartup();
361
 
362
    FX_StopAllSounds();
363
    clearsoundlocks();
364
 
563 terminx 365
    if (ud.config.MusicToggle == 1)
491 terminx 366
    {
564 terminx 367
        if (ud.recstat != 2 && g_player[myconnectindex].ps->gm&MODE_GAME)
491 terminx 368
        {
562 terminx 369
            if (map[(unsigned char)music_select].musicfn != NULL)
680 terminx 370
                playmusic(&map[(unsigned char)music_select].musicfn[0],music_select);
491 terminx 371
        }
680 terminx 372
        else playmusic(&env_music_fn[0][0],MAXVOLUMES*MAXLEVELS);
491 terminx 373
    }
374
 
472 terminx 375
    return OSDCMD_OK;
376
}
377
 
5 Plagman 378
static int osdcmd_restartvid(const osdfuncparm_t *parm)
379
{
654 terminx 380
    UNREFERENCED_PARAMETER(parm);
5 Plagman 381
    resetvideomode();
563 terminx 382
    if (setgamemode(ud.config.ScreenMode,ud.config.ScreenWidth,ud.config.ScreenHeight,ud.config.ScreenBPP))
5 Plagman 383
        gameexit("restartvid: Reset failed...\n");
563 terminx 384
    onvideomodechange(ud.config.ScreenBPP>8);
5 Plagman 385
    vscrn();
386
 
387
    return OSDCMD_OK;
388
}
389
 
390
static int osdcmd_vidmode(const osdfuncparm_t *parm)
391
{
563 terminx 392
    int newbpp = ud.config.ScreenBPP, newwidth = ud.config.ScreenWidth,
393
                 newheight = ud.config.ScreenHeight, newfs = ud.config.ScreenMode;
5 Plagman 394
    if (parm->numparms < 1 || parm->numparms > 4) return OSDCMD_SHOWHELP;
395
 
335 terminx 396
    switch (parm->numparms)
397
    {
337 terminx 398
    case 1: // bpp switch
399
        newbpp = Batol(parm->parms[0]);
400
        break;
401
    case 2: // res switch
402
        newwidth = Batol(parm->parms[0]);
403
        newheight = Batol(parm->parms[1]);
404
        break;
405
    case 3: // res & bpp switch
406
    case 4:
407
        newwidth = Batol(parm->parms[0]);
408
        newheight = Batol(parm->parms[1]);
409
        newbpp = Batol(parm->parms[2]);
410
        if (parm->numparms == 4)
411
            newfs = (Batol(parm->parms[3]) != 0);
412
        break;
5 Plagman 413
    }
414
 
335 terminx 415
    if (setgamemode(newfs,newwidth,newheight,newbpp))
416
    {
5 Plagman 417
        initprintf("vidmode: Mode change failed!\n");
563 terminx 418
        if (setgamemode(ud.config.ScreenMode, ud.config.ScreenWidth, ud.config.ScreenHeight, ud.config.ScreenBPP))
5 Plagman 419
            gameexit("vidmode: Reset failed!\n");
420
    }
563 terminx 421
    ud.config.ScreenBPP = newbpp;
422
    ud.config.ScreenWidth = newwidth;
423
    ud.config.ScreenHeight = newheight;
424
    ud.config.ScreenMode = newfs;
425
    onvideomodechange(ud.config.ScreenBPP>8);
5 Plagman 426
    vscrn();
427
    return OSDCMD_OK;
428
}
429
 
430
static int osdcmd_setstatusbarscale(const osdfuncparm_t *parm)
431
{
335 terminx 432
    if (parm->numparms == 0)
433
    {
129 terminx 434
        OSD_Printf("\"cl_statusbarscale\" is \"%d\"\n", ud.statusbarscale);
435
        return OSDCMD_SHOWHELP;
335 terminx 436
    }
437
    else if (parm->numparms != 1) return OSDCMD_SHOWHELP;
5 Plagman 438
 
439
    setstatusbarscale(Batol(parm->parms[0]));
129 terminx 440
    OSD_Printf("cl_statusbarscale %d\n", ud.statusbarscale);
5 Plagman 441
    return OSDCMD_OK;
442
}
443
 
444
static int osdcmd_spawn(const osdfuncparm_t *parm)
445
{
584 terminx 446
    int x=0,y=0,z=0;
5 Plagman 447
    unsigned short cstat=0,picnum=0;
448
    unsigned char pal=0;
449
    short ang=0;
450
    short set=0, idx;
451
 
564 terminx 452
    if (numplayers > 1 || !(g_player[myconnectindex].ps->gm & MODE_GAME))
335 terminx 453
    {
5 Plagman 454
        OSD_Printf("spawn: Can't spawn sprites in multiplayer games or demos\n");
455
        return OSDCMD_OK;
456
    }
457
 
335 terminx 458
    switch (parm->numparms)
459
    {
337 terminx 460
    case 7: // x,y,z
461
        x = Batol(parm->parms[4]);
462
        y = Batol(parm->parms[5]);
463
        z = Batol(parm->parms[6]);
464
        set |= 8;
465
    case 4: // ang
466
        ang = Batol(parm->parms[3]) & 2047;
467
        set |= 4;
468
    case 3: // cstat
469
        cstat = (unsigned short)Batol(parm->parms[2]);
470
        set |= 2;
471
    case 2: // pal
472
        pal = (unsigned char)Batol(parm->parms[1]);
473
        set |= 1;
474
    case 1: // tile number
475
        if (isdigit(parm->parms[0][0]))
476
        {
477
            picnum = (unsigned short)Batol(parm->parms[0]);
478
        }
479
        else
480
        {
481
            int i,j;
482
            for (j=0; j<2; j++)
335 terminx 483
            {
337 terminx 484
                for (i=0; i<labelcnt; i++)
335 terminx 485
                {
337 terminx 486
                    if (
487
                        (j == 0 && !Bstrcmp(label+(i<<6),     parm->parms[0])) ||
488
                        (j == 1 && !Bstrcasecmp(label+(i<<6), parm->parms[0]))
489
                    )
335 terminx 490
                    {
337 terminx 491
                        picnum = (unsigned short)labelcode[i];
492
                        break;
5 Plagman 493
                    }
494
                }
337 terminx 495
                if (i<labelcnt) break;
5 Plagman 496
            }
337 terminx 497
            if (i==labelcnt)
335 terminx 498
            {
337 terminx 499
                OSD_Printf("spawn: Invalid tile label given\n");
5 Plagman 500
                return OSDCMD_OK;
501
            }
337 terminx 502
        }
503
 
504
        if (picnum >= MAXTILES)
505
        {
506
            OSD_Printf("spawn: Invalid tile number\n");
507
            return OSDCMD_OK;
508
        }
509
        break;
510
    default:
511
        return OSDCMD_SHOWHELP;
5 Plagman 512
    }
513
 
564 terminx 514
    idx = spawn(g_player[myconnectindex].ps->i, (short)picnum);
5 Plagman 515
    if (set & 1) sprite[idx].pal = (char)pal;
516
    if (set & 2) sprite[idx].cstat = (short)cstat;
517
    if (set & 4) sprite[idx].ang = ang;
335 terminx 518
    if (set & 8)
519
    {
520
        if (setsprite(idx, x,y,z) < 0)
521
        {
5 Plagman 522
            OSD_Printf("spawn: Sprite can't be spawned into null space\n");
523
            deletesprite(idx);
524
        }
525
    }
526
 
527
    return OSDCMD_OK;
528
}
529
 
416 terminx 530
static int osdcmd_setvar(const osdfuncparm_t *parm)
5 Plagman 531
{
532
    int i, varval;
533
    char varname[256];
534
 
535
    if (parm->numparms != 2) return OSDCMD_SHOWHELP;
536
 
379 terminx 537
    if (numplayers > 1)
5 Plagman 538
    {
539
        OSD_Printf("Command not allowed in multiplayer\n");
540
        return OSDCMD_OK;
541
    }
542
 
587 terminx 543
    strcpy(varname,parm->parms[1]);
544
    varval = Batol(varname);
545
    for (i=0;i<iGameVarCount;i++)
546
        if (aGameVars[i].szLabel != NULL)
547
            if (Bstrcmp(varname, aGameVars[i].szLabel) == 0)
548
                varval=GetGameVarID(i, g_player[myconnectindex].ps->i, myconnectindex);
549
 
5 Plagman 550
    strcpy(varname,parm->parms[0]);
331 terminx 551
    for (i=0;i<iGameVarCount;i++)
552
        if (aGameVars[i].szLabel != NULL)
553
            if (Bstrcmp(varname, aGameVars[i].szLabel) == 0)
564 terminx 554
                SetGameVarID(i, varval, g_player[myconnectindex].ps->i, myconnectindex);
11 terminx 555
    return OSDCMD_OK;
29 terminx 556
}
11 terminx 557
 
587 terminx 558
static int osdcmd_setactorvar(const osdfuncparm_t *parm)
559
{
560
    int i, varval, ID;
561
    char varname[256];
562
 
563
    if (parm->numparms != 3) return OSDCMD_SHOWHELP;
564
 
565
    if (numplayers > 1)
566
    {
567
        OSD_Printf("Command not allowed in multiplayer\n");
568
        return OSDCMD_OK;
569
    }
570
 
571
    ID=Batol(parm->parms[0]);
572
    if (ID>=MAXSPRITES)
573
    {
574
        OSD_Printf("Invalid sprite ID\n");
575
        return OSDCMD_OK;
576
    }
577
 
578
    varval = Batol(parm->parms[2]);
579
    strcpy(varname,parm->parms[2]);
580
    varval = Batol(varname);
581
    for (i=0;i<iGameVarCount;i++)
582
        if (aGameVars[i].szLabel != NULL)
583
            if (Bstrcmp(varname, aGameVars[i].szLabel) == 0)
584
                varval=GetGameVarID(i, g_player[myconnectindex].ps->i, myconnectindex);
585
 
586
    strcpy(varname,parm->parms[1]);
587
    for (i=0;i<iGameVarCount;i++)
588
        if (aGameVars[i].szLabel != NULL)
589
            if (Bstrcmp(varname, aGameVars[i].szLabel) == 0)
590
                SetGameVarID(i, varval, ID, -1);
591
    return OSDCMD_OK;
592
}
593
 
416 terminx 594
static int osdcmd_addpath(const osdfuncparm_t *parm)
11 terminx 595
{
596
    char pathname[BMAX_PATH];
597
 
598
    if (parm->numparms != 1) return OSDCMD_SHOWHELP;
599
 
600
    strcpy(pathname,parm->parms[0]);
601
    addsearchpath(pathname);
5 Plagman 602
    return OSDCMD_OK;
603
}
604
 
416 terminx 605
static int osdcmd_initgroupfile(const osdfuncparm_t *parm)
182 terminx 606
{
607
    char file[BMAX_PATH];
608
 
609
    if (parm->numparms != 1) return OSDCMD_SHOWHELP;
610
 
611
    strcpy(file,parm->parms[0]);
612
    initgroupfile(file);
613
    return OSDCMD_OK;
614
}
615
 
416 terminx 616
static int osdcmd_cmenu(const osdfuncparm_t *parm)
5 Plagman 617
{
618
    if (parm->numparms != 1) return OSDCMD_SHOWHELP;
335 terminx 619
    if (numplayers > 1)
620
    {
5 Plagman 621
        OSD_Printf("cmenu: disallowed in multiplayer\n");
622
        return OSDCMD_OK;
335 terminx 623
    }
624
    else
625
    {
5 Plagman 626
        cmenu(Batol(parm->parms[0]));
627
    }
628
 
629
    return OSDCMD_OK;
630
}
631
 
820 terminx 632
cvarmappings cvar[] =
559 terminx 633
{
881 terminx 634
    { "crosshair", "crosshair: enable/disable crosshair", (void*)&ud.crosshair, CVAR_BOOL, 0, 0, 1 },
150 terminx 635
 
820 terminx 636
    { "cl_autoaim", "cl_autoaim: enable/disable weapon autoaim", (void*)&ud.config.AutoAim, CVAR_INT|CVAR_MULTI, 0, 0, 2 },
559 terminx 637
    { "cl_automsg", "cl_automsg: enable/disable automatically sending messages to all players", (void*)&ud.automsg, CVAR_BOOL, 0, 0, 1 },
820 terminx 638
    { "cl_autovote", "cl_autovote: enable/disable automatic voting", (void*)&ud.autovote, CVAR_INT|CVAR_MULTI, 0, 0, 2 },
150 terminx 639
 
529 terminx 640
 
559 terminx 641
    { "cl_deathmessages", "cl_deathmessages: enable/disable multiplayer death messages", (void*)&ud.deathmsgs, CVAR_BOOL, 0, 0, 1 },
642
    { "cl_democams", "cl_democams: enable/disable demo playback cameras", (void*)&ud.democams, CVAR_BOOL, 0, 0, 1 },
150 terminx 643
 
559 terminx 644
    { "cl_idplayers", "cl_idplayers: enable/disable name display when aiming at opponents", (void*)&ud.idplayers, CVAR_BOOL, 0, 0, 1 },
152 terminx 645
 
559 terminx 646
    { "cl_messagetime", "cl_messagetime: length of time to display multiplayer chat messages\n", (void*)&ud.msgdisptime, CVAR_INT, 0, 0, 3600 },
150 terminx 647
 
559 terminx 648
    { "cl_showcoords", "cl_showcoords: show your position in the game world", (void*)&ud.coords, CVAR_BOOL, 0, 0, 1 },
508 terminx 649
 
559 terminx 650
    { "cl_viewbob", "cl_viewbob: enable/disable player head bobbing\n", (void*)&ud.viewbob, CVAR_BOOL, 0, 0, 1 },
150 terminx 651
 
559 terminx 652
    { "cl_weaponsway", "cl_weaponsway: enable/disable player weapon swaying\n", (void*)&ud.weaponsway, CVAR_BOOL, 0, 0, 1 },
820 terminx 653
    { "cl_weaponswitch", "cl_weaponswitch: enable/disable auto weapon switching", (void*)&ud.weaponswitch, CVAR_INT|CVAR_MULTI, 0, 0, 3 },
559 terminx 654
    { "cl_angleinterpolation", "cl_angleinterpolation: enable/disable angle interpolation", (void*)&ud.angleinterpolation, CVAR_INT, 0, 0, 256 },
832 terminx 655
 
656
    { "in_mousebias", "in_mousebias: emulates the original mouse code's weighting of input towards whichever axis is moving the most at any given time\n", (void*)&ud.config.MouseBias, CVAR_INT, 0, 0, 32 },
657
    { "in_mousefilter", "in_mousefilter: amount of mouse movement to filter out\n", (void*)&ud.config.MouseFilter, CVAR_INT, 0, 0, 512 },
658
    { "in_smoothinput", "in_smoothinput: enable/disable input smoothing\n", (void*)&ud.config.SmoothInput, CVAR_BOOL, 0, 0, 1 },
659
 
180 terminx 660
#if defined(POLYMOST) && defined(USE_OPENGL)
559 terminx 661
    { "r_anamorphic", "r_anamorphic: enable/disable widescreen mode", (void*)&glwidescreen, CVAR_BOOL, 0, 0, 1 },
662
    { "r_projectionhack", "r_projectionhack: enable/disable projection hack", (void*)&glprojectionhacks, CVAR_BOOL, 0, 0, 1 },
723 terminx 663
# ifdef POLYMER
559 terminx 664
    // polymer cvars
686 plagman 665
    { "pr_occlusionculling", "pr_occlusionculling: insert description that noone will ever read", (void*)&pr_occlusionculling, CVAR_INT, 0, 0, 512 },
559 terminx 666
    { "pr_fov", "pr_fov: sets the field of vision in build angle", (void*)&pr_fov, CVAR_INT, 0, 0, 1023},
692 plagman 667
    { "pr_billboardingmode", "pr_billboardingmode: face sprite display method. 0: classic mode; 1: polymost mode", (void*)&pr_billboardingmode, CVAR_INT, 0, 0, 1 },
559 terminx 668
    { "pr_verbosity", "pr_verbosity: verbosity level of the polymer renderer", (void*)&pr_verbosity, CVAR_INT, 0, 0, 3 },
669
    { "pr_wireframe", "pr_wireframe: toggles wireframe mode", (void*)&pr_wireframe, CVAR_INT, 0, 0, 1 },
741 plagman 670
    { "pr_vbos", "pr_vbos: contols Vertex Buffer Object usage. 0: no VBOs. 1: VBOs for map data. 2: VBOs for model data.", (void*)&pr_vbos, CVAR_INT, 0, 0, 2 },
775 plagman 671
    { "pr_gpusmoothing", "pr_gpusmoothing: toggles model animation interpolation", (void*)&pr_gpusmoothing, CVAR_INT, 0, 0, 1 },
180 terminx 672
#endif
723 terminx 673
#endif
833 terminx 674
    { "r_drawweapon", "r_drawweapon: enable/disable weapon drawing", (void*)&ud.drawweapon, CVAR_INT, 0, 0, 2 },
675
    { "r_showfps", "r_showfps: show the frame rate counter", (void*)&ud.tickrate, CVAR_BOOL, 0, 0, 1 },
563 terminx 676
    { "r_precache", "r_precache: enable/disable the pre-level caching routine", (void*)&ud.config.useprecache, CVAR_BOOL, 0, 0, 1 },
841 terminx 677
    { "r_visibility", "r_visibility: sets the global map visibility", (void*)&ud.const_visibility, CVAR_INT|128, 0, INT_MIN, INT_MAX },
472 terminx 678
 
563 terminx 679
    { "snd_ambience", "snd_ambience: enables/disables ambient sounds", (void*)&ud.config.AmbienceToggle, CVAR_BOOL, 0, 0, 1 },
680
    { "snd_duketalk", "snd_duketalk: enables/disables Duke's speech", (void*)&ud.config.VoiceToggle, CVAR_INT, 0, 0, 2 },
681
    { "snd_fxvolume", "snd_fxvolume: volume of sound effects", (void*)&ud.config.FXVolume, CVAR_INT, 0, 0, 255 },
682
    { "snd_mixrate", "snd_mixrate: sound mixing rate", (void*)&ud.config.MixRate, CVAR_INT, 0, 0, 48000 },
683
    { "snd_musvolume", "snd_musvolume: volume of midi music", (void*)&ud.config.MusicVolume, CVAR_INT, 0, 0, 255 },
684
    { "snd_numbits", "snd_numbits: sound bits", (void*)&ud.config.NumBits, CVAR_INT, 0, 8, 16 },
685
    { "snd_numchannels", "snd_numchannels: the number of sound channels", (void*)&ud.config.NumChannels, CVAR_INT, 0, 0, 2 },
686
    { "snd_numvoices", "snd_numvoices: the number of concurrent sounds", (void*)&ud.config.NumVoices, CVAR_INT, 0, 0, 32 },
687
    { "snd_reversestereo", "snd_reversestereo: reverses the stereo channels", (void*)&ud.config.ReverseStereo, CVAR_BOOL, 0, 0, 16 },
559 terminx 688
};
484 terminx 689
 
416 terminx 690
static int osdcmd_cvar_set(const osdfuncparm_t *parm)
5 Plagman 691
{
692
    int showval = (parm->numparms == 0);
693
    unsigned int i;
694
 
820 terminx 695
    for (i = 0; i < sizeof(cvar)/sizeof(cvarmappings); i++)
335 terminx 696
    {
697
        if (!Bstrcasecmp(parm->name, cvar[i].name))
698
        {
820 terminx 699
            if ((cvar[i].type & CVAR_NOMULTI) && numplayers > 1)
335 terminx 700
            {
5 Plagman 701
                // sound the alarm
702
                OSD_Printf("Cvar \"%s\" locked in multiplayer.\n",cvar[i].name);
703
                return OSDCMD_OK;
335 terminx 704
            }
705
            else
706
                switch (cvar[i].type&0x7f)
331 terminx 707
                {
337 terminx 708
                case CVAR_INT:
709
                case CVAR_UNSIGNEDINT:
710
                case CVAR_BOOL:
711
                {
712
                    int val;
713
                    if (showval)
335 terminx 714
                    {
337 terminx 715
                        OSD_Printf("\"%s\" is \"%d\"\n%s\n",cvar[i].name,*(int*)cvar[i].var,(char*)cvar[i].helpstr);
716
                        return OSDCMD_OK;
717
                    }
5 Plagman 718
 
337 terminx 719
                    val = atoi(parm->parms[0]);
720
                    if (cvar[i].type == CVAR_BOOL) val = val != 0;
60 terminx 721
 
337 terminx 722
                    if (val < cvar[i].min || val > cvar[i].max)
723
                    {
724
                        OSD_Printf("%s value out of range\n",cvar[i].name);
725
                        return OSDCMD_OK;
331 terminx 726
                    }
337 terminx 727
                    *(int*)cvar[i].var = val;
728
                    OSD_Printf("%s %d",cvar[i].name,val);
729
                }
730
                break;
731
                case CVAR_STRING:
732
                {
733
                    if (showval)
335 terminx 734
                    {
337 terminx 735
                        OSD_Printf("\"%s\" is \"%s\"\n%s\n",cvar[i].name,(char*)cvar[i].var,(char*)cvar[i].helpstr);
736
                        return OSDCMD_OK;
331 terminx 737
                    }
337 terminx 738
                    else
739
                    {
740
                        Bstrncpy((char*)cvar[i].var, parm->parms[0], cvar[i].extra-1);
741
                        ((char*)cvar[i].var)[cvar[i].extra-1] = 0;
742
                        OSD_Printf("%s %s",cvar[i].name,(char*)cvar[i].var);
743
                    }
744
                }
745
                break;
746
                default:
331 terminx 747
                    break;
5 Plagman 748
                }
820 terminx 749
            if (cvar[i].type&CVAR_MULTI)
371 terminx 750
                updateplayer();
5 Plagman 751
        }
752
    }
753
    OSD_Printf("\n");
754
    return OSDCMD_OK;
755
}
756
 
416 terminx 757
static int osdcmd_sensitivity(const osdfuncparm_t *parm)
5 Plagman 758
{
335 terminx 759
    if (parm->numparms != 1)
760
    {
129 terminx 761
        OSD_Printf("\"sensitivity\" is \"%d\"\n",CONTROL_GetMouseSensitivity());
762
        return OSDCMD_SHOWHELP;
5 Plagman 763
    }
127 terminx 764
    CONTROL_SetMouseSensitivity(atoi(parm->parms[0]));
765
    OSD_Printf("sensitivity %d\n",CONTROL_GetMouseSensitivity());
5 Plagman 766
    return OSDCMD_OK;
767
}
768
 
870 terminx 769
static int osdcmd_setbrightness(const osdfuncparm_t *parm)
5 Plagman 770
{
335 terminx 771
    if (parm->numparms != 1)
772
    {
870 terminx 773
//        OSD_Printf("\"setbri\" \"%d\"\n",ud.brightness>>2);
129 terminx 774
        return OSDCMD_SHOWHELP;
5 Plagman 775
    }
776
    ud.brightness = atoi(parm->parms[0])<<2;
564 terminx 777
    setbrightness(ud.brightness>>2,&g_player[screenpeek].ps->palette[0],0);
870 terminx 778
    OSD_Printf("setbrightness %d\n",ud.brightness>>2);
5 Plagman 779
    return OSDCMD_OK;
780
}
781
 
416 terminx 782
static int osdcmd_give(const osdfuncparm_t *parm)
5 Plagman 783
{
784
    int i;
785
 
564 terminx 786
    if (numplayers == 1 && g_player[myconnectindex].ps->gm & MODE_GAME)
335 terminx 787
    {
564 terminx 788
        if (g_player[myconnectindex].ps->dead_flag != 0)
335 terminx 789
        {
247 terminx 790
            OSD_Printf("give: Cannot give while dead.\n");
791
            return OSDCMD_OK;
792
        }
335 terminx 793
 
5 Plagman 794
        if (parm->numparms != 1) return OSDCMD_SHOWHELP;
335 terminx 795
 
796
        if (!Bstrcasecmp(parm->parms[0], "all"))
797
        {
5 Plagman 798
            osdcmd_cheatsinfo_stat.cheatnum = 1;
799
            return OSDCMD_OK;
800
        }
335 terminx 801
        else if (!Bstrcasecmp(parm->parms[0], "health"))
802
        {
566 terminx 803
            sprite[g_player[myconnectindex].ps->i].extra = g_player[myconnectindex].ps->max_player_health<<1;
5 Plagman 804
            return OSDCMD_OK;
805
        }
335 terminx 806
        else if (!Bstrcasecmp(parm->parms[0], "weapons"))
807
        {
5 Plagman 808
            osdcmd_cheatsinfo_stat.cheatnum = 21;
809
            return OSDCMD_OK;
810
        }
335 terminx 811
        else if (!Bstrcasecmp(parm->parms[0], "ammo"))
812
        {
5 Plagman 813
            for (i=PISTOL_WEAPON;i<MAX_WEAPONS-(VOLUMEONE?6:1);i++)
814
            {
566 terminx 815
                addammo(i,g_player[myconnectindex].ps,g_player[myconnectindex].ps->max_ammo_amount[i]);
5 Plagman 816
            }
817
            return OSDCMD_OK;
818
        }
335 terminx 819
        else if (!Bstrcasecmp(parm->parms[0], "armor"))
820
        {
564 terminx 821
            g_player[myconnectindex].ps->shield_amount = 100;
5 Plagman 822
            return OSDCMD_OK;
823
        }
335 terminx 824
        else if (!Bstrcasecmp(parm->parms[0], "keys"))
825
        {
5 Plagman 826
            osdcmd_cheatsinfo_stat.cheatnum = 23;
827
            return OSDCMD_OK;
828
        }
335 terminx 829
        else if (!Bstrcasecmp(parm->parms[0], "inventory"))
830
        {
5 Plagman 831
            osdcmd_cheatsinfo_stat.cheatnum = 22;
832
            return OSDCMD_OK;
833
        }
335 terminx 834
    }
835
    else
836
    {
5 Plagman 837
        OSD_Printf("give: Not in a single-player game.\n");
838
        return OSDCMD_OK;
839
    }
840
    return OSDCMD_SHOWHELP;
841
}
842
 
843
void onvideomodechange(int newmode)
844
{
845
    char *pal;
846
 
335 terminx 847
    if (newmode)
848
    {
564 terminx 849
        if (g_player[screenpeek].ps->palette == palette ||
850
                g_player[screenpeek].ps->palette == waterpal ||
851
                g_player[screenpeek].ps->palette == titlepal ||
852
                g_player[screenpeek].ps->palette == animpal ||
853
                g_player[screenpeek].ps->palette == endingpal ||
854
                g_player[screenpeek].ps->palette == drealms ||
855
                g_player[screenpeek].ps->palette == slimepal)
856
            pal = g_player[screenpeek].ps->palette;
384 terminx 857
        else
5 Plagman 858
            pal = palette;
335 terminx 859
    }
860
    else
861
    {
564 terminx 862
        pal = g_player[screenpeek].ps->palette;
5 Plagman 863
    }
864
 
865
    setbrightness(ud.brightness>>2, pal, 0);
866
    restorepalette = 1;
867
}
868
 
416 terminx 869
static int osdcmd_usemousejoy(const osdfuncparm_t *parm)
175 terminx 870
{
871
    int showval = (parm->numparms < 1);
832 terminx 872
    if (!Bstrcasecmp(parm->name, "in_mouse"))
335 terminx 873
    {
874
        if (showval)
875
        {
832 terminx 876
            OSD_Printf("in_mouse is %d\n", ud.config.UseMouse);
335 terminx 877
        }
878
        else
879
        {
563 terminx 880
            ud.config.UseMouse = (atoi(parm->parms[0]) != 0);
881
            CONTROL_MouseEnabled = (ud.config.UseMouse && CONTROL_MousePresent);
175 terminx 882
        }
883
        return OSDCMD_OK;
884
    }
832 terminx 885
    else if (!Bstrcasecmp(parm->name, "in_joystick"))
335 terminx 886
    {
887
        if (showval)
888
        {
832 terminx 889
            OSD_Printf("in_joystick is %d\n", ud.config.UseJoystick);
335 terminx 890
        }
891
        else
892
        {
563 terminx 893
            ud.config.UseJoystick = (atoi(parm->parms[0]) != 0);
894
            CONTROL_JoystickEnabled = (ud.config.UseJoystick && CONTROL_JoyPresent);
175 terminx 895
        }
896
        return OSDCMD_OK;
897
    }
898
    return OSDCMD_SHOWHELP;
899
}
171 terminx 900
 
416 terminx 901
static int osdcmd_name(const osdfuncparm_t *parm)
157 terminx 902
{
903
    if (parm->numparms != 1)
904
    {
905
        OSD_Printf("\"name\" is \"%s\"\n",myname);
906
        return OSDCMD_SHOWHELP;
907
    }
908
 
909
    Bstrcpy(tempbuf,parm->parms[0]);
910
 
400 terminx 911
    while (Bstrlen(stripcolorcodes(tempbuf)) > 10)
157 terminx 912
        tempbuf[Bstrlen(tempbuf)-1] = '\0';
913
 
914
    Bstrncpy(myname,tempbuf,sizeof(myname)-1);
760 terminx 915
    myname[sizeof(myname)-1] = '\0';
157 terminx 916
 
917
    OSD_Printf("name %s\n",myname);
918
 
371 terminx 919
    updateplayer();
157 terminx 920
 
921
    return OSDCMD_OK;
922
}
923
 
808 terminx 924
static int osdcmd_button(const osdfuncparm_t *parm)
925
{
926
    char *p = (char *)parm->name+9;  // skip "gamefunc_"
834 terminx 927
//    if (g_player[myconnectindex].ps->gm == MODE_GAME) // only trigger these if in game
822 terminx 928
    extinput[CONFIG_FunctionNameToNum(p)] = 1; // FIXME
808 terminx 929
    return OSDCMD_OK;
930
}
931
 
836 terminx 932
keydef keynames[]=
933
{
934
    { "Escape", 0x1 },
935
    { "1", 0x2 },
936
    { "2", 0x3 },
937
    { "3", 0x4 },
938
    { "4", 0x5 },
939
    { "5", 0x6 },
940
    { "6", 0x7 },
941
    { "7", 0x8 },
942
    { "8", 0x9 },
943
    { "9", 0xa },
944
    { "0", 0xb },
945
    { "-", 0xc },
946
    { "=", 0xd },
947
    { "BakSpc", 0xe },
948
    { "Tab", 0xf },
949
    { "Q", 0x10 },
950
    { "W", 0x11 },
951
    { "E", 0x12 },
952
    { "R", 0x13 },
953
    { "T", 0x14 },
954
    { "Y", 0x15 },
955
    { "U", 0x16 },
956
    { "I", 0x17 },
957
    { "O", 0x18 },
958
    { "P", 0x19 },
959
    { "[", 0x1a },
960
    { "]", 0x1b },
961
    { "Enter", 0x1c },
962
    { "LCtrl", 0x1d },
963
    { "A", 0x1e },
964
    { "S", 0x1f },
965
    { "D", 0x20 },
966
    { "F", 0x21 },
967
    { "G", 0x22 },
968
    { "H", 0x23 },
969
    { "J", 0x24 },
970
    { "K", 0x25 },
971
    { "L", 0x26 },
972
    { "SemiColon", 0x27 },
973
    { "'", 0x28 },
974
    { "Tilde", 0x29 },
975
    { "LShift", 0x2a },
976
    { "\\", 0x2b },
977
    { "Z", 0x2c },
978
    { "X", 0x2d },
979
    { "C", 0x2e },
980
    { "V", 0x2f },
981
    { "B", 0x30 },
982
    { "N", 0x31 },
983
    { "M", 0x32 },
984
    { ",", 0x33 },
985
    { ".", 0x34 },
986
    { "/", 0x35 },
987
    { "RShift", 0x36 },
988
    { "Kpad*", 0x37 },
989
    { "LAlt", 0x38 },
990
    { "Space", 0x39 },
991
    { "CapLck", 0x3a },
992
    { "F1", 0x3b },
993
    { "F2", 0x3c },
994
    { "F3", 0x3d },
995
    { "F4", 0x3e },
996
    { "F5", 0x3f },
997
    { "F6", 0x40 },
998
    { "F7", 0x41 },
999
    { "F8", 0x42 },
1000
    { "F9", 0x43 },
1001
    { "F10", 0x44 },
1002
    { "NumLck", 0x45 },
1003
    { "ScrLck", 0x46 },
1004
    { "Kpad7", 0x47 },
1005
    { "Kpad8", 0x48 },
1006
    { "Kpad9", 0x49 },
1007
    { "Kpad-", 0x4a },
1008
    { "Kpad4", 0x4b },
1009
    { "Kpad5", 0x4c },
1010
    { "Kpad6", 0x4d },
1011
    { "Kpad+", 0x4e },
1012
    { "Kpad1", 0x4f },
1013
    { "Kpad2", 0x50 },
1014
    { "Kpad3", 0x51 },
1015
    { "Kpad0", 0x52 },
1016
    { "Kpad.", 0x53 },
1017
    { "F11", 0x57 },
1018
    { "F12", 0x58 },
1019
    { "KpdEnt", 0x9c },
1020
    { "RCtrl", 0x9d },
1021
    { "Kpad/", 0xb5 },
1022
    { "RAlt", 0xb8 },
1023
    { "PrtScn", 0xb7 },
1024
    { "Pause", 0xc5 },
1025
    { "Home", 0xc7 },
1026
    { "Up", 0xc8 },
1027
    { "PgUp", 0xc9 },
1028
    { "Left", 0xcb },
1029
    { "Right", 0xcd },
1030
    { "End", 0xcf },
1031
    { "Down", 0xd0 },
1032
    { "PgDn", 0xd1 },
1033
    { "Insert", 0xd2 },
1034
    { "Delete", 0xd3 },
1035
 
1036
    {0,0}
1037
};
1038
 
1039
char *mousenames[] = { "mouse1", "mouse2", "mouse3", "mouse4", "mouse5", "mouse6" };
1040
 
591 plagman 1041
static int osdcmd_bind(const osdfuncparm_t *parm)
1042
{
808 terminx 1043
    int i, j;
591 plagman 1044
 
592 plagman 1045
    if (parm->numparms==1&&!Bstrcasecmp(parm->parms[0],"showkeys"))
591 plagman 1046
    {
723 terminx 1047
        for (i=0;keynames[i].name;i++)OSD_Printf("%s\n",keynames[i].name);
826 terminx 1048
        for (i=0;i<MAXMOUSEBUTTONS;i++)OSD_Printf("%s\n",mousenames[i]);
591 plagman 1049
        return OSDCMD_OK;
1050
    }
811 terminx 1051
 
591 plagman 1052
    if (parm->numparms==0)
1053
    {
833 terminx 1054
        int j=0;
1055
 
1056
        OSD_Printf("Current key bindings:\n");
826 terminx 1057
        for (i=0;i<MAXBOUNDKEYS;i++)
836 terminx 1058
            if (boundkeys[i].cmd[0] && boundkeys[i].key)
833 terminx 1059
            {
1060
                j++;
836 terminx 1061
                OSD_Printf("%-9s %s\"%s\"\n",boundkeys[i].key, boundkeys[i].repeat?"":"norepeat ", boundkeys[i].cmd);
833 terminx 1062
            }
836 terminx 1063
 
826 terminx 1064
        for (i=0;i<MAXMOUSEBUTTONS;i++)
836 terminx 1065
            if (mousebind[i].cmd[0] && mousebind[i].key)
833 terminx 1066
            {
1067
                j++;
836 terminx 1068
                OSD_Printf("%-9s %s\"%s\"\n",mousebind[i].key, mousebind[i].repeat?"":"norepeat ",mousebind[i].cmd);
833 terminx 1069
            }
1070
 
1071
        if (j == 0)
1072
            OSD_Printf("No binds found.\n");
1073
 
591 plagman 1074
        return OSDCMD_OK;
1075
    }
1076
 
810 terminx 1077
    for (i=0;keynames[i].name;i++)
1078
        if (!Bstrcasecmp(parm->parms[0],keynames[i].name))
1079
            break;
591 plagman 1080
 
830 terminx 1081
    if (!keynames[i].name)
826 terminx 1082
    {
1083
        for (i=0;i<MAXMOUSEBUTTONS;i++)
1084
            if (!Bstrcasecmp(parm->parms[0],mousenames[i]))
1085
                break;
1086
        if (i >= MAXMOUSEBUTTONS)
1087
            return OSDCMD_SHOWHELP;
1088
 
1089
        if (parm->numparms < 2)
1090
        {
836 terminx 1091
            OSD_Printf("%-9s %s\"%s\"\n",mousenames[i], mousebind[i].repeat?"":"norepeat ",mousebind[i].cmd);
826 terminx 1092
            return OSDCMD_OK;
1093
        }
1094
 
1095
        j = 1;
834 terminx 1096
 
1097
        mousebind[i].repeat = 1;
826 terminx 1098
        if (parm->numparms >= 2 && !Bstrcasecmp(parm->parms[j],"norepeat"))
1099
        {
1100
            mousebind[i].repeat = 0;
1101
            j++;
1102
        }
834 terminx 1103
 
1104
        Bstrcpy(tempbuf,parm->parms[j++]);
1105
        for (;j<parm->numparms;j++)
1106
        {
1107
            Bstrcat(tempbuf," ");
1108
            Bstrcat(tempbuf,parm->parms[j++]);
1109
        }
1110
        Bstrncpy(mousebind[i].cmd,tempbuf, MAXBINDSTRINGLENGTH-1);
1111
 
826 terminx 1112
        mousebind[i].key=mousenames[i];
843 terminx 1113
        if (!OSD_ParsingScript())
826 terminx 1114
            OSD_Printf("%s\n",parm->raw);
1115
        return OSDCMD_OK;
1116
    }
1117
 
811 terminx 1118
    if (parm->numparms < 2)
1119
    {
836 terminx 1120
        OSD_Printf("%-9s %s\"%s\"\n",keynames[i].name, boundkeys[keynames[i].id].repeat?"":"norepeat ", boundkeys[keynames[i].id].cmd);
811 terminx 1121
        return OSDCMD_OK;
1122
    }
1123
 
808 terminx 1124
    j = 1;
834 terminx 1125
 
1126
    boundkeys[keynames[i].id].repeat = 1;
812 terminx 1127
    if (parm->numparms >= 2 && !Bstrcasecmp(parm->parms[j],"norepeat"))
808 terminx 1128
    {
812 terminx 1129
        boundkeys[keynames[i].id].repeat = 0;
808 terminx 1130
        j++;
1131
    }
834 terminx 1132
 
1133
    Bstrcpy(tempbuf,parm->parms[j++]);
1134
    for (;j<parm->numparms;j++)
1135
    {
1136
        Bstrcat(tempbuf," ");
1137
        Bstrcat(tempbuf,parm->parms[j++]);
1138
    }
1139
    Bstrncpy(boundkeys[keynames[i].id].cmd,tempbuf, MAXBINDSTRINGLENGTH-1);
1140
 
591 plagman 1141
    boundkeys[keynames[i].id].key=keynames[i].name;
843 terminx 1142
    if (!OSD_ParsingScript())
814 terminx 1143
        OSD_Printf("%s\n",parm->raw);
591 plagman 1144
    return OSDCMD_OK;
1145
}
1146
 
821 terminx 1147
static int osdcmd_unbindall(const osdfuncparm_t *parm)
1148
{
1149
    int i;
1150
 
1151
    UNREFERENCED_PARAMETER(parm);
1152
 
826 terminx 1153
    for (i=0;i<MAXBOUNDKEYS;i++)
834 terminx 1154
        if (boundkeys[i].cmd[0])
1155
            boundkeys[i].cmd[0] = 0;
826 terminx 1156
    for (i=0;i<MAXMOUSEBUTTONS;i++)
834 terminx 1157
        if (mousebind[i].cmd[0])
1158
            mousebind[i].cmd[0] = 0;
821 terminx 1159
    OSD_Printf("unbound all keys\n");
1160
    return OSDCMD_OK;
1161
}
1162
 
810 terminx 1163
static int osdcmd_unbind(const osdfuncparm_t *parm)
1164
{
811 terminx 1165
    int i;
810 terminx 1166
 
1167
    if (parm->numparms < 1) return OSDCMD_SHOWHELP;
1168
    for (i=0;keynames[i].name;i++)
1169
        if (!Bstrcasecmp(parm->parms[0],keynames[i].name))
1170
            break;
826 terminx 1171
    if (!keynames[i].name)
1172
    {
1173
        for (i=0;i<MAXMOUSEBUTTONS;i++)
1174
            if (!Bstrcasecmp(parm->parms[0],mousenames[i]))
1175
                break;
1176
        if (i >= MAXMOUSEBUTTONS)
1177
            return OSDCMD_SHOWHELP;
1178
        mousebind[i].repeat = 0;
834 terminx 1179
        mousebind[i].cmd[0] = 0;
829 terminx 1180
        OSD_Printf("unbound %s\n",mousenames[i]);
826 terminx 1181
        return OSDCMD_OK;
1182
    }
810 terminx 1183
    boundkeys[keynames[i].id].repeat = 0;
834 terminx 1184
    boundkeys[keynames[i].id].cmd[0] = 0;
810 terminx 1185
    OSD_Printf("unbound key %s\n",keynames[i].name);
1186
    return OSDCMD_OK;
1187
}
1188
 
821 terminx 1189
static int osdcmd_quicksave(const osdfuncparm_t *parm)
1190
{
1191
    UNREFERENCED_PARAMETER(parm);
1192
    if (!(g_player[myconnectindex].ps->gm & MODE_GAME))
1193
        OSD_Printf("quicksave: not in a game.\n");
1194
    else doquicksave = 1;
1195
    return OSDCMD_OK;
1196
}
1197
 
1198
static int osdcmd_quickload(const osdfuncparm_t *parm)
1199
{
1200
    UNREFERENCED_PARAMETER(parm);
1201
    if (!(g_player[myconnectindex].ps->gm & MODE_GAME))
1202
        OSD_Printf("quickload: not in a game.\n");
1203
    else doquicksave = 2;
1204
    return OSDCMD_OK;
1205
}
1206
 
834 terminx 1207
static int osdcmd_screenshot(const osdfuncparm_t *parm)
1208
{
1209
    UNREFERENCED_PARAMETER(parm);
836 terminx 1210
//    KB_ClearKeysDown();
834 terminx 1211
    screencapture("duke0000.tga",0);
1212
    return OSDCMD_OK;
1213
}
1214
 
859 terminx 1215
extern void savemapstate(mapstate_t *save);
1216
extern void restoremapstate(mapstate_t *save);
1217
 
870 terminx 1218
static int osdcmd_savestate(const osdfuncparm_t *parm)
859 terminx 1219
{
1220
    UNREFERENCED_PARAMETER(parm);
1221
    if (map[ud.volume_number*MAXLEVELS+ud.level_number].savedstate == NULL)
1222
        map[ud.volume_number*MAXLEVELS+ud.level_number].savedstate = Bcalloc(1,sizeof(mapstate_t));
1223
    savemapstate(map[ud.volume_number*MAXLEVELS+ud.level_number].savedstate);
1224
    return OSDCMD_OK;
1225
}
1226
 
870 terminx 1227
static int osdcmd_restorestate(const osdfuncparm_t *parm)
859 terminx 1228
{
1229
    UNREFERENCED_PARAMETER(parm);
1230
    if (map[ud.volume_number*MAXLEVELS+ud.level_number].savedstate)
1231
        restoremapstate(map[ud.volume_number*MAXLEVELS+ud.level_number].savedstate);
1232
    return OSDCMD_OK;
1233
}
1234
 
877 terminx 1235
static int osdcmd_vid_gamma(const osdfuncparm_t *parm)
1236
{
1237
    if (parm->numparms != 1)
1238
    {
1239
        OSD_Printf("\"vid_gamma\" is \"%.1f\"\n",vid_gamma);
1240
        return OSDCMD_SHOWHELP;
1241
    }
1242
    vid_gamma = atof(parm->parms[0]);
1243
    ud.brightness = min(max((float)((vid_gamma-1.0)*10.0),0),15);
1244
    ud.brightness <<= 2;
1245
    OSD_Printf("%s\n",parm->raw);
1246
    setgamma();
1247
    return OSDCMD_OK;
1248
}
1249
 
1250
static int osdcmd_vid_brightness(const osdfuncparm_t *parm)
1251
{
1252
    if (parm->numparms != 1)
1253
    {
1254
        OSD_Printf("\"vid_brightness\" is \"%.1f\"\n",vid_brightness);
1255
        return OSDCMD_SHOWHELP;
1256
    }
1257
    vid_brightness = atof(parm->parms[0]);
1258
    OSD_Printf("%s\n",parm->raw);
1259
    setgamma();
1260
    return OSDCMD_OK;
1261
}
1262
 
1263
static int osdcmd_vid_contrast(const osdfuncparm_t *parm)
1264
{
1265
    if (parm->numparms != 1)
1266
    {
1267
        OSD_Printf("\"vid_contrast\" is \"%.1f\"\n",vid_contrast);
1268
        return OSDCMD_SHOWHELP;
1269
    }
1270
    vid_contrast = atof(parm->parms[0]);
1271
    OSD_Printf("%s\n",parm->raw);
1272
    setgamma();
1273
    return OSDCMD_OK;
1274
}
1275
 
881 terminx 1276
static int osdcmd_setcrosshairscale(const osdfuncparm_t *parm)
1277
{
1278
    if (parm->numparms == 0)
1279
    {
1280
        OSD_Printf("\"cl_crosshairscale\" is \"%d\"\n", ud.crosshairscale);
1281
        return OSDCMD_SHOWHELP;
1282
    }
1283
    else if (parm->numparms != 1) return OSDCMD_SHOWHELP;
1284
 
1285
    ud.crosshairscale = min(100,max(10,Batol(parm->parms[0])));
1286
    OSD_Printf("cl_statusbarscale %d\n", ud.crosshairscale);
1287
    return OSDCMD_OK;
1288
}
1289
 
5 Plagman 1290
int registerosdcommands(void)
1291
{
1292
    unsigned int i;
1293
 
1294
    osdcmd_cheatsinfo_stat.cheatnum = -1;
1295
 
335 terminx 1296
    for (i=0; i<sizeof(cvar)/sizeof(cvar[0]); i++)
1297
    {
5 Plagman 1298
        OSD_RegisterFunction(cvar[i].name, cvar[i].helpstr, osdcmd_cvar_set);
1299
    }
1300
 
335 terminx 1301
    if (VOLUMEONE)
5 Plagman 1302
        OSD_RegisterFunction("changelevel","changelevel <level>: warps to the given level", osdcmd_changelevel);
335 terminx 1303
    else
1304
    {
5 Plagman 1305
        OSD_RegisterFunction("changelevel","changelevel <volume> <level>: warps to the given level", osdcmd_changelevel);
1306
        OSD_RegisterFunction("map","map <mapfile>: loads the given user map", osdcmd_map);
1307
    }
182 terminx 1308
 
1309
    OSD_RegisterFunction("addpath","addpath <path>: adds path to game filesystem", osdcmd_addpath);
1310
 
821 terminx 1311
    OSD_RegisterFunction("bind","bind <key> <string>: associates a keypress with a string of console input. Type \"bind showkeys\" for a list of keys and \"listsymbols\" for a list of valid console commands.", osdcmd_bind);
1312
 
182 terminx 1313
    OSD_RegisterFunction("cl_statusbarscale","cl_statusbarscale: changes the status bar scale", osdcmd_setstatusbarscale);
881 terminx 1314
    OSD_RegisterFunction("cl_crosshairscale","cl_crosshairscale: changes the crosshair scale", osdcmd_setcrosshairscale);
5 Plagman 1315
    OSD_RegisterFunction("cmenu","cmenu <#>: jumps to menu", osdcmd_cmenu);
182 terminx 1316
 
1317
    OSD_RegisterFunction("echo","echo [text]: echoes text to the console", osdcmd_echo);
1318
 
1319
    OSD_RegisterFunction("fileinfo","fileinfo <file>: gets a file's information", osdcmd_fileinfo);
1320
 
837 terminx 1321
    for (i=0;i<NUMGAMEFUNCTIONS-1;i++)
821 terminx 1322
    {
1323
        char *t;
1324
        Bsprintf(tempbuf,"gamefunc_%s",gamefunctions[i]);
1325
        t = Bstrdup(tempbuf);
1326
        Bstrcat(tempbuf,": game button");
1327
        OSD_RegisterFunction(t,Bstrdup(tempbuf),osdcmd_button);
1328
    }
1329
 
879 terminx 1330
    OSD_RegisterFunction("setbrightness","setbrightness <value>: changes brightness (obsolete)", osdcmd_setbrightness);
5 Plagman 1331
    OSD_RegisterFunction("give","give <all|health|weapons|ammo|armor|keys|inventory>: gives requested item", osdcmd_give);
182 terminx 1332
    OSD_RegisterFunction("god","god: toggles god mode", osdcmd_god);
1333
 
832 terminx 1334
    OSD_RegisterFunction("in_joystick","in_joystick: enables input from the joystick if it is present",osdcmd_usemousejoy);
1335
    OSD_RegisterFunction("in_mouse","in_mouse: enables input from the mouse if it is present",osdcmd_usemousejoy);
182 terminx 1336
    OSD_RegisterFunction("initgroupfile","initgroupfile <path>: adds a grp file into the game filesystem", osdcmd_initgroupfile);
1337
 
157 terminx 1338
    OSD_RegisterFunction("name","name: change your multiplayer nickname", osdcmd_name);
5 Plagman 1339
    OSD_RegisterFunction("noclip","noclip: toggles clipping mode", osdcmd_noclip);
1340
 
821 terminx 1341
    OSD_RegisterFunction("quicksave","quicksave: performs a quick save", osdcmd_quicksave);
1342
    OSD_RegisterFunction("quickload","quickload: performs a quick load", osdcmd_quickload);
182 terminx 1343
    OSD_RegisterFunction("quit","quit: exits the game immediately", osdcmd_quit);
841 terminx 1344
    OSD_RegisterFunction("exit","exit: exits the game immediately", osdcmd_quit);
182 terminx 1345
 
471 terminx 1346
    OSD_RegisterFunction("rate","rate: sets the multiplayer packet send rate, in packets/sec",osdcmd_rate);
627 terminx 1347
    OSD_RegisterFunction("restartsound","restartsound: reinitializes the sound system",osdcmd_restartsound);
1348
    OSD_RegisterFunction("restartvid","restartvid: reinitializes the video mode",osdcmd_restartvid);
182 terminx 1349
 
5 Plagman 1350
    OSD_RegisterFunction("sensitivity","sensitivity <value>: changes the mouse sensitivity", osdcmd_sensitivity);
182 terminx 1351
    OSD_RegisterFunction("setvar","setvar <gamevar> <value>: sets the value of a gamevar", osdcmd_setvar);
587 terminx 1352
    OSD_RegisterFunction("setvarvar","setvar <gamevar> <gamevar>: sets the value of a gamevar", osdcmd_setvar);
1353
    OSD_RegisterFunction("setactorvar","setactorvar <actorID> <gamevar> <value>: sets the value of a gamevar", osdcmd_setactorvar);
834 terminx 1354
    OSD_RegisterFunction("screenshot","screenshot: takes a screenshot.  See r_scrcaptureformat.", osdcmd_screenshot);
1355
 
5 Plagman 1356
    OSD_RegisterFunction("spawn","spawn <picnum> [palnum] [cstat] [ang] [x y z]: spawns a sprite with the given properties",osdcmd_spawn);
1357
 
821 terminx 1358
    OSD_RegisterFunction("unbind","unbind <key>: unbinds a key.", osdcmd_unbind);
1359
    OSD_RegisterFunction("unbindall","unbindall: unbinds all keys.", osdcmd_unbindall);
1360
 
877 terminx 1361
    OSD_RegisterFunction("vidmode","vidmode [xdim ydim] [bpp] [fullscreen]: change the video mode",osdcmd_vidmode);
1362
    OSD_RegisterFunction("vid_gamma","vid_gamma <gamma>: adjusts gamma ramp",osdcmd_vid_gamma);
1363
    OSD_RegisterFunction("vid_contrast","vid_contrast <gamma>: adjusts gamma ramp",osdcmd_vid_contrast);
1364
    OSD_RegisterFunction("vid_brightness","vid_brightness <gamma>: adjusts gamma ramp",osdcmd_vid_brightness);
859 terminx 1365
    OSD_RegisterFunction("savestate","",osdcmd_savestate);
1366
    OSD_RegisterFunction("restorestate","",osdcmd_restorestate);
5 Plagman 1367
    //baselayer_onvideomodechange = onvideomodechange;
1368
 
1369
    return 0;
1370
}
1371