2006-04-13 20:47:06 +00:00
//-------------------------------------------------------------------------
/*
2010-05-25 10:56:00 +00:00
Copyright ( C ) 2010 EDuke32 developers and contributors
2007-02-08 04:19:39 +00:00
2010-05-25 10:56:00 +00:00
This file is part of EDuke32 .
2006-04-13 20:47:06 +00:00
EDuke32 is free software ; you can redistribute it and / or
modify it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE .
See the GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
2014-07-20 08:55:56 +00:00
Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
2006-04-13 20:47:06 +00:00
*/
//-------------------------------------------------------------------------
2019-09-21 18:59:54 +00:00
# include "ns.h" // Must come before everything else!
2019-10-19 23:46:58 +00:00
# include "osdcmds.h"
2018-11-18 19:03:40 +00:00
# include "cheats.h"
# include "cmdline.h"
# include "demo.h" // g_firstDemoFile[]
2006-04-13 20:47:06 +00:00
# include "duke3d.h"
2010-08-02 08:13:51 +00:00
# include "menus.h"
2018-03-08 03:55:41 +00:00
# include "savegame.h"
2018-11-18 19:03:40 +00:00
# include "sbar.h"
2019-12-09 23:01:45 +00:00
# include "mapinfo.h"
2006-04-13 20:47:06 +00:00
2019-09-21 20:53:00 +00:00
BEGIN_DUKE_NS
2019-11-03 11:46:53 +00:00
struct osdcmd_cheatsinfo osdcmd_cheatsinfo_stat = { - 1 , 0 , 0 } ;
2006-04-13 20:47:06 +00:00
2018-11-18 18:06:15 +00:00
static int osdcmd_map ( osdcmdptr_t parm )
2006-04-13 20:47:06 +00:00
{
2012-03-28 19:42:16 +00:00
char filename [ BMAX_PATH ] ;
2006-04-13 20:47:06 +00:00
2012-09-08 22:18:31 +00:00
const int32_t wildcardp = parm - > numparms = = 1 & &
( Bstrchr ( parm - > parms [ 0 ] , ' * ' ) ! = NULL ) ;
if ( parm - > numparms ! = 1 | | wildcardp )
2008-08-17 11:07:28 +00:00
{
return OSDCMD_SHOWHELP ;
}
2006-04-13 20:47:06 +00:00
2012-09-08 22:18:31 +00:00
maybe_append_ext ( filename , sizeof ( filename ) , parm - > parms [ 0 ] , " .map " ) ;
2006-04-13 20:47:06 +00:00
2019-12-07 09:31:27 +00:00
if ( ! fileSystem . FileExists ( filename ) )
2006-11-15 01:16:55 +00:00
{
2008-07-27 01:22:17 +00:00
OSD_Printf ( OSD_ERROR " map: file \" %s \" not found. \n " , filename ) ;
2006-04-13 20:47:06 +00:00
return OSDCMD_OK ;
}
2006-12-12 08:33:11 +00:00
boardfilename [ 0 ] = ' / ' ;
boardfilename [ 1 ] = 0 ;
strcat ( boardfilename , filename ) ;
if ( numplayers > 1 )
{
return OSDCMD_OK ;
}
2006-04-13 20:47:06 +00:00
2007-01-26 05:16:10 +00:00
osdcmd_cheatsinfo_stat . cheatnum = - 1 ;
ud . m_volume_number = 0 ;
2019-11-09 18:15:03 +00:00
m_level_number = 7 ;
2006-12-12 07:25:01 +00:00
2007-01-26 05:16:10 +00:00
ud . m_monsters_off = ud . monsters_off = 0 ;
2006-04-13 20:47:06 +00:00
2007-01-26 05:16:10 +00:00
ud . m_respawn_items = 0 ;
ud . m_respawn_inventory = 0 ;
2006-04-13 20:47:06 +00:00
2007-01-26 05:16:10 +00:00
ud . multimode = 1 ;
2006-04-13 20:47:06 +00:00
2018-11-18 18:12:06 +00:00
if ( g_player [ myconnectindex ] . ps - > gm & MODE_GAME )
{
2019-11-09 18:15:03 +00:00
G_NewGame ( ud . m_volume_number , m_level_number , ud . m_player_skill ) ;
2018-11-18 18:12:06 +00:00
g_player [ myconnectindex ] . ps - > gm = MODE_RESTART ;
}
else G_NewGame_EnterLevel ( ) ;
2006-04-13 20:47:06 +00:00
return OSDCMD_OK ;
}
2012-09-15 15:28:26 +00:00
// demo <demonum or demofn> [<prof>]
//
// To profile a demo ("timedemo mode"), <prof> can be given in the range 0-8,
// which will start to replay it as fast as possible, rendering <prof> frames
// for each gametic.
//
// Notes:
// * The demos should be recorded with demorec_diffs set to 0, so that the
// game state updates are actually computed.
2012-09-15 15:28:30 +00:00
// * Currently, the profiling can only be aborted on SDL 1.2 builds by
// pressing any key.
2012-09-15 15:28:26 +00:00
// * With <prof> greater than 1, interpolation should be calculated properly,
// though this has not been verified by looking at the frames.
// * When testing whether a change in the source has an effect on performance,
// the variance of the run times MUST be taken into account (that is, the
// replaying must be performed multiple times for the old and new versions,
// etc.)
2018-11-18 18:06:15 +00:00
static int osdcmd_demo ( osdcmdptr_t parm )
2012-09-08 22:18:37 +00:00
{
if ( numplayers > 1 )
{
OSD_Printf ( " Command not allowed in multiplayer \n " ) ;
return OSDCMD_OK ;
}
if ( g_player [ myconnectindex ] . ps - > gm & MODE_GAME )
{
OSD_Printf ( " demo: Must not be in a game. \n " ) ;
return OSDCMD_OK ;
}
2012-09-15 15:28:26 +00:00
if ( parm - > numparms ! = 1 & & parm - > numparms ! = 2 )
2012-09-08 22:18:37 +00:00
return OSDCMD_SHOWHELP ;
{
2012-09-15 15:28:26 +00:00
int32_t prof = parm - > numparms = = 2 ? Batoi ( parm - > parms [ 1 ] ) : - 1 ;
2012-09-08 22:18:37 +00:00
2012-10-01 17:52:40 +00:00
Demo_SetFirst ( parm - > parms [ 0 ] ) ;
2012-09-24 21:09:27 +00:00
Demo_PlayFirst ( clamp ( prof , - 1 , 8 ) + 1 , 0 ) ;
2012-09-08 22:18:37 +00:00
}
return OSDCMD_OK ;
}
2018-11-18 18:06:15 +00:00
static int osdcmd_activatecheat ( osdcmdptr_t parm )
2017-07-05 05:38:08 +00:00
{
if ( parm - > numparms ! = 1 )
return OSDCMD_SHOWHELP ;
if ( numplayers = = 1 & & g_player [ myconnectindex ] . ps - > gm & MODE_GAME )
osdcmd_cheatsinfo_stat . cheatnum = Batoi ( parm - > parms [ 0 ] ) ;
else
OSD_Printf ( " activatecheat: Not in a single-player game. \n " ) ;
return OSDCMD_OK ;
}
2018-11-18 18:06:15 +00:00
static int osdcmd_god ( osdcmdptr_t UNUSED ( parm ) )
2006-04-13 20:47:06 +00:00
{
2017-06-27 02:24:14 +00:00
UNREFERENCED_CONST_PARAMETER ( parm ) ;
2007-08-27 06:46:31 +00:00
if ( numplayers = = 1 & & g_player [ myconnectindex ] . ps - > gm & MODE_GAME )
2012-09-08 22:18:34 +00:00
osdcmd_cheatsinfo_stat . cheatnum = CHEAT_CORNHOLIO ;
2006-11-15 01:16:55 +00:00
else
2006-04-13 20:47:06 +00:00
OSD_Printf ( " god: Not in a single-player game. \n " ) ;
return OSDCMD_OK ;
}
2018-11-18 18:06:15 +00:00
static int osdcmd_noclip ( osdcmdptr_t UNUSED ( parm ) )
2006-04-13 20:47:06 +00:00
{
2017-06-27 02:24:14 +00:00
UNREFERENCED_CONST_PARAMETER ( parm ) ;
2012-09-08 22:18:37 +00:00
2007-08-27 06:46:31 +00:00
if ( numplayers = = 1 & & g_player [ myconnectindex ] . ps - > gm & MODE_GAME )
2006-11-15 01:16:55 +00:00
{
2012-09-08 22:18:34 +00:00
osdcmd_cheatsinfo_stat . cheatnum = CHEAT_CLIP ;
2006-11-15 01:16:55 +00:00
}
else
{
2006-04-13 20:47:06 +00:00
OSD_Printf ( " noclip: Not in a single-player game. \n " ) ;
}
return OSDCMD_OK ;
}
2018-11-18 18:06:15 +00:00
int osdcmd_restartmap ( osdcmdptr_t UNUSED ( parm ) )
2015-12-23 04:05:55 +00:00
{
2017-06-27 02:24:14 +00:00
UNREFERENCED_CONST_PARAMETER ( parm ) ;
2015-12-23 04:05:55 +00:00
if ( g_player [ myconnectindex ] . ps - > gm & MODE_GAME & & ud . multimode = = 1 )
g_player [ myconnectindex ] . ps - > gm = MODE_RESTART ;
return OSDCMD_OK ;
}
2018-11-18 18:06:15 +00:00
static int osdcmd_spawn ( osdcmdptr_t parm )
2006-04-13 20:47:06 +00:00
{
2014-03-15 14:10:45 +00:00
int32_t picnum = 0 ;
uint16_t cstat = 0 ;
2009-01-09 09:29:17 +00:00
char pal = 0 ;
int16_t ang = 0 ;
int16_t set = 0 , idx ;
2009-01-13 12:23:18 +00:00
vec3_t vect ;
2006-04-13 20:47:06 +00:00
2007-08-27 06:46:31 +00:00
if ( numplayers > 1 | | ! ( g_player [ myconnectindex ] . ps - > gm & MODE_GAME ) )
2006-11-15 01:16:55 +00:00
{
2006-04-13 20:47:06 +00:00
OSD_Printf ( " spawn: Can't spawn sprites in multiplayer games or demos \n " ) ;
return OSDCMD_OK ;
}
2006-11-15 01:16:55 +00:00
switch ( parm - > numparms )
{
2006-11-16 03:02:42 +00:00
case 7 : // x,y,z
2009-01-13 12:23:18 +00:00
vect . x = Batol ( parm - > parms [ 4 ] ) ;
vect . y = Batol ( parm - > parms [ 5 ] ) ;
vect . z = Batol ( parm - > parms [ 6 ] ) ;
2006-11-16 03:02:42 +00:00
set | = 8 ;
2017-07-18 20:53:41 +00:00
fallthrough__ ;
2006-11-16 03:02:42 +00:00
case 4 : // ang
ang = Batol ( parm - > parms [ 3 ] ) & 2047 ;
set | = 4 ;
2017-07-18 20:53:41 +00:00
fallthrough__ ;
2006-11-16 03:02:42 +00:00
case 3 : // cstat
2009-01-09 09:29:17 +00:00
cstat = ( uint16_t ) Batol ( parm - > parms [ 2 ] ) ;
2006-11-16 03:02:42 +00:00
set | = 2 ;
2017-07-18 20:53:41 +00:00
fallthrough__ ;
2006-11-16 03:02:42 +00:00
case 2 : // pal
2009-01-09 09:29:17 +00:00
pal = ( uint8_t ) Batol ( parm - > parms [ 1 ] ) ;
2006-11-16 03:02:42 +00:00
set | = 1 ;
2017-07-18 20:53:41 +00:00
fallthrough__ ;
2006-11-16 03:02:42 +00:00
case 1 : // tile number
if ( isdigit ( parm - > parms [ 0 ] [ 0 ] ) )
{
2014-03-15 14:10:45 +00:00
picnum = Batol ( parm - > parms [ 0 ] ) ;
2006-11-16 03:02:42 +00:00
}
else
{
2014-03-15 14:10:45 +00:00
int32_t i ;
int32_t j ;
2006-11-16 03:02:42 +00:00
for ( j = 0 ; j < 2 ; j + + )
2006-11-15 01:16:55 +00:00
{
2016-08-27 01:42:01 +00:00
for ( i = 0 ; i < g_labelCnt ; i + + )
2006-11-15 01:16:55 +00:00
{
2014-03-15 14:10:45 +00:00
if ( ( j = = 0 & & ! Bstrcmp ( label + ( i < < 6 ) , parm - > parms [ 0 ] ) ) | |
( j = = 1 & & ! Bstrcasecmp ( label + ( i < < 6 ) , parm - > parms [ 0 ] ) ) )
2006-11-15 01:16:55 +00:00
{
2014-03-15 14:10:45 +00:00
picnum = labelcode [ i ] ;
2006-11-16 03:02:42 +00:00
break ;
2006-04-13 20:47:06 +00:00
}
}
2014-03-15 14:10:45 +00:00
2016-08-27 01:42:01 +00:00
if ( i < g_labelCnt )
2014-03-15 14:10:45 +00:00
break ;
2006-04-13 20:47:06 +00:00
}
2016-08-27 01:42:01 +00:00
if ( i = = g_labelCnt )
2006-11-15 01:16:55 +00:00
{
2006-11-16 03:02:42 +00:00
OSD_Printf ( " spawn: Invalid tile label given \n " ) ;
2006-04-13 20:47:06 +00:00
return OSDCMD_OK ;
}
2006-11-16 03:02:42 +00:00
}
2014-03-15 14:10:45 +00:00
if ( ( uint32_t ) picnum > = MAXUSERTILES )
2006-11-16 03:02:42 +00:00
{
OSD_Printf ( " spawn: Invalid tile number \n " ) ;
return OSDCMD_OK ;
}
break ;
2014-03-15 14:10:45 +00:00
2006-11-16 03:02:42 +00:00
default :
return OSDCMD_SHOWHELP ;
2006-04-13 20:47:06 +00:00
}
2014-03-15 14:10:45 +00:00
idx = A_Spawn ( g_player [ myconnectindex ] . ps - > i , picnum ) ;
2009-01-09 09:29:17 +00:00
if ( set & 1 ) sprite [ idx ] . pal = ( uint8_t ) pal ;
if ( set & 2 ) sprite [ idx ] . cstat = ( int16_t ) cstat ;
2006-04-13 20:47:06 +00:00
if ( set & 4 ) sprite [ idx ] . ang = ang ;
2006-11-15 01:16:55 +00:00
if ( set & 8 )
{
2009-01-13 12:23:18 +00:00
if ( setsprite ( idx , & vect ) < 0 )
2006-11-15 01:16:55 +00:00
{
2006-04-13 20:47:06 +00:00
OSD_Printf ( " spawn: Sprite can't be spawned into null space \n " ) ;
2012-03-11 17:38:13 +00:00
A_DeleteSprite ( idx ) ;
2006-04-13 20:47:06 +00:00
}
}
return OSDCMD_OK ;
}
2018-11-18 18:06:15 +00:00
static int osdcmd_setvar ( osdcmdptr_t parm )
2006-04-13 20:47:06 +00:00
{
2006-12-04 04:08:14 +00:00
if ( numplayers > 1 )
2006-04-13 20:47:06 +00:00
{
OSD_Printf ( " Command not allowed in multiplayer \n " ) ;
return OSDCMD_OK ;
}
2019-08-04 02:52:18 +00:00
if ( parm - > numparms ! = 2 )
return OSDCMD_SHOWHELP ;
2018-11-18 18:06:07 +00:00
int i = hash_find ( & h_gamevars , parm - > parms [ 1 ] ) ;
2018-12-15 01:37:34 +00:00
int const newValue = ( i = = - 1 ) ? Batol ( parm - > parms [ 1 ] ) : Gv_GetVar ( i , g_player [ myconnectindex ] . ps - > i , myconnectindex ) ;
2018-11-18 18:06:07 +00:00
if ( ( i = hash_find ( & h_gamevars , parm - > parms [ 0 ] ) ) > = 0 )
2019-08-04 02:52:18 +00:00
{
2018-12-15 01:37:34 +00:00
Gv_SetVar ( i , newValue , g_player [ myconnectindex ] . ps - > i , myconnectindex ) ;
2006-04-13 20:47:06 +00:00
2019-08-04 02:52:18 +00:00
OSD_Printf ( " Variable \" %s \" now has value %d (input: %d) \n " , aGameVars [ i ] . szLabel ,
Gv_GetVar ( i , g_player [ myconnectindex ] . ps - > i , myconnectindex ) , newValue ) ;
}
else
{
OSD_Printf ( " setvar: \" %s \" is not a game variable! \n " , parm - > parms [ 0 ] ) ;
return OSDCMD_SHOWHELP ;
}
2006-04-15 03:12:08 +00:00
return OSDCMD_OK ;
2006-04-16 03:42:36 +00:00
}
2006-04-15 03:12:08 +00:00
2018-11-18 18:06:15 +00:00
static int osdcmd_addlogvar ( osdcmdptr_t parm )
2008-07-23 20:09:22 +00:00
{
if ( numplayers > 1 )
{
OSD_Printf ( " Command not allowed in multiplayer \n " ) ;
return OSDCMD_OK ;
}
2019-08-04 02:52:18 +00:00
if ( parm - > numparms ! = 1 )
return OSDCMD_SHOWHELP ;
2018-11-18 18:06:07 +00:00
int const i = hash_find ( & h_gamevars , parm - > parms [ 0 ] ) ;
2008-08-25 10:43:24 +00:00
if ( i > = 0 )
2018-12-15 01:37:34 +00:00
OSD_Printf ( " Variable \" %s \" has value %d, default %d \n " , parm - > parms [ 0 ] , Gv_GetVar ( i , g_player [ screenpeek ] . ps - > i , screenpeek ) , ( int ) aGameVars [ i ] . defaultValue ) ;
2019-08-04 02:52:18 +00:00
else
{
OSD_Printf ( " addlogvar: %s is not a game variable! \n " , parm - > parms [ 0 ] ) ;
return OSDCMD_SHOWHELP ;
}
2018-11-18 18:06:07 +00:00
2008-07-23 20:09:22 +00:00
return OSDCMD_OK ;
}
2018-11-18 18:06:15 +00:00
static int osdcmd_setactorvar ( osdcmdptr_t parm )
2007-12-20 19:14:38 +00:00
{
if ( numplayers > 1 )
{
OSD_Printf ( " Command not allowed in multiplayer \n " ) ;
return OSDCMD_OK ;
}
2019-08-04 02:52:18 +00:00
if ( parm - > numparms ! = 3 )
return OSDCMD_SHOWHELP ;
2018-11-18 18:06:07 +00:00
int16_t const spriteNum = Batol ( parm - > parms [ 0 ] ) ;
2018-10-07 05:23:05 +00:00
if ( ( unsigned ) spriteNum > = MAXSPRITES )
2007-12-20 19:14:38 +00:00
{
2019-08-04 02:52:18 +00:00
OSD_Printf ( " setactorvar: Invalid sprite number! \n " ) ;
2007-12-20 19:14:38 +00:00
return OSDCMD_OK ;
}
2018-10-07 05:23:05 +00:00
// get value to set
2018-11-18 18:06:07 +00:00
int i = hash_find ( & h_gamevars , parm - > parms [ 2 ] ) ;
2018-12-15 01:37:34 +00:00
int const newValue = ( i > = 0 ) ? Gv_GetVar ( i , g_player [ myconnectindex ] . ps - > i , myconnectindex ) : Batol ( parm - > parms [ 2 ] ) ;
2007-12-20 19:14:38 +00:00
2018-11-18 18:06:07 +00:00
if ( ( i = hash_find ( & h_gamevars , parm - > parms [ 1 ] ) ) > = 0 )
2019-08-04 02:52:18 +00:00
{
2018-12-15 01:37:34 +00:00
Gv_SetVar ( i , newValue , spriteNum , myconnectindex ) ;
2018-10-07 05:23:05 +00:00
2019-08-04 02:52:18 +00:00
OSD_Printf ( " Variable \" %s \" for sprite %d value is now %d (input: %d) \n " , aGameVars [ i ] . szLabel , spriteNum ,
Gv_GetVar ( i , g_player [ myconnectindex ] . ps - > i , myconnectindex ) , newValue ) ;
}
else
{
OSD_Printf ( " setactorvar: %s is not a game variable! \n " , parm - > parms [ 1 ] ) ;
return OSDCMD_SHOWHELP ;
}
2007-12-20 19:14:38 +00:00
return OSDCMD_OK ;
}
2006-04-13 20:47:06 +00:00
2018-10-16 06:08:36 +00:00
2006-11-16 03:02:42 +00:00
2018-11-18 18:06:15 +00:00
static int osdcmd_crosshaircolor ( osdcmdptr_t parm )
2009-04-29 06:20:07 +00:00
{
if ( parm - > numparms ! = 3 )
{
OSD_Printf ( " crosshaircolor: r:%d g:%d b:%d \n " , CrosshairColors . r , CrosshairColors . g , CrosshairColors . b ) ;
return OSDCMD_SHOWHELP ;
2006-04-13 20:47:06 +00:00
}
2018-11-18 18:06:07 +00:00
uint8_t const r = Batol ( parm - > parms [ 0 ] ) ;
uint8_t const g = Batol ( parm - > parms [ 1 ] ) ;
uint8_t const b = Batol ( parm - > parms [ 2 ] ) ;
2009-04-29 06:20:07 +00:00
G_SetCrosshairColor ( r , g , b ) ;
2015-10-20 07:15:01 +00:00
2019-11-05 19:16:53 +00:00
OSD_Printf ( " %s \n " , parm - > raw ) ;
2015-10-20 07:15:01 +00:00
2006-04-13 20:47:06 +00:00
return OSDCMD_OK ;
}
2018-11-18 18:06:15 +00:00
static int osdcmd_give ( osdcmdptr_t parm )
2006-04-13 20:47:06 +00:00
{
2009-01-09 09:29:17 +00:00
int32_t i ;
2006-04-13 20:47:06 +00:00
2008-08-12 12:50:20 +00:00
if ( numplayers ! = 1 | | ( g_player [ myconnectindex ] . ps - > gm & MODE_GAME ) = = 0 | |
2008-08-19 11:05:21 +00:00
g_player [ myconnectindex ] . ps - > dead_flag ! = 0 )
2006-11-15 01:16:55 +00:00
{
2008-08-12 12:50:20 +00:00
OSD_Printf ( " give: Cannot give while dead or not in a single-player game. \n " ) ;
return OSDCMD_OK ;
}
2006-11-15 01:16:55 +00:00
2008-08-12 12:50:20 +00:00
if ( parm - > numparms ! = 1 ) return OSDCMD_SHOWHELP ;
2006-11-15 01:16:55 +00:00
2008-08-12 12:50:20 +00:00
if ( ! Bstrcasecmp ( parm - > parms [ 0 ] , " all " ) )
{
2012-09-08 22:18:34 +00:00
osdcmd_cheatsinfo_stat . cheatnum = CHEAT_STUFF ;
2008-08-12 12:50:20 +00:00
return OSDCMD_OK ;
2006-11-15 01:16:55 +00:00
}
2008-08-12 12:50:20 +00:00
else if ( ! Bstrcasecmp ( parm - > parms [ 0 ] , " health " ) )
{
sprite [ g_player [ myconnectindex ] . ps - > i ] . extra = g_player [ myconnectindex ] . ps - > max_player_health < < 1 ;
return OSDCMD_OK ;
}
else if ( ! Bstrcasecmp ( parm - > parms [ 0 ] , " weapons " ) )
{
2012-09-08 22:18:34 +00:00
osdcmd_cheatsinfo_stat . cheatnum = CHEAT_WEAPONS ;
2008-08-12 12:50:20 +00:00
return OSDCMD_OK ;
}
else if ( ! Bstrcasecmp ( parm - > parms [ 0 ] , " ammo " ) )
{
2009-02-19 16:47:54 +00:00
for ( i = MAX_WEAPONS - ( VOLUMEONE ? 6 : 1 ) - 1 ; i > = PISTOL_WEAPON ; i - - )
2016-08-27 01:40:46 +00:00
P_AddAmmo ( g_player [ myconnectindex ] . ps , i , g_player [ myconnectindex ] . ps - > max_ammo_amount [ i ] ) ;
2008-08-12 12:50:20 +00:00
return OSDCMD_OK ;
}
else if ( ! Bstrcasecmp ( parm - > parms [ 0 ] , " armor " ) )
{
2009-12-15 05:53:15 +00:00
g_player [ myconnectindex ] . ps - > inv_amount [ GET_SHIELD ] = 100 ;
2008-08-12 12:50:20 +00:00
return OSDCMD_OK ;
}
else if ( ! Bstrcasecmp ( parm - > parms [ 0 ] , " keys " ) )
{
2012-09-08 22:18:34 +00:00
osdcmd_cheatsinfo_stat . cheatnum = CHEAT_KEYS ;
2008-08-12 12:50:20 +00:00
return OSDCMD_OK ;
}
else if ( ! Bstrcasecmp ( parm - > parms [ 0 ] , " inventory " ) )
2006-11-15 01:16:55 +00:00
{
2012-09-08 22:18:34 +00:00
osdcmd_cheatsinfo_stat . cheatnum = CHEAT_INVENTORY ;
2006-04-13 20:47:06 +00:00
return OSDCMD_OK ;
}
return OSDCMD_SHOWHELP ;
}
2009-01-09 09:29:17 +00:00
void onvideomodechange ( int32_t newmode )
2006-04-13 20:47:06 +00:00
{
2011-01-17 03:49:34 +00:00
uint8_t palid ;
2006-04-13 20:47:06 +00:00
2012-11-06 23:06:44 +00:00
// XXX?
if ( ! newmode | | g_player [ screenpeek ] . ps - > palette < BASEPALCOUNT )
2011-01-17 03:49:34 +00:00
palid = g_player [ screenpeek ] . ps - > palette ;
2012-11-06 23:06:44 +00:00
else
palid = BASEPAL ;
2006-04-13 20:47:06 +00:00
2009-06-06 22:30:53 +00:00
# ifdef POLYMER
2018-04-12 21:03:12 +00:00
if ( videoGetRenderMode ( ) = = REND_POLYMER )
2009-06-06 22:30:53 +00:00
{
int32_t i = 0 ;
while ( i < MAXSPRITES )
{
2010-05-02 23:27:30 +00:00
if ( actor [ i ] . lightptr )
2009-06-06 22:30:53 +00:00
{
2010-05-02 23:27:30 +00:00
polymer_deletelight ( actor [ i ] . lightId ) ;
actor [ i ] . lightptr = NULL ;
actor [ i ] . lightId = - 1 ;
2009-06-06 22:30:53 +00:00
}
i + + ;
}
}
# endif
2019-10-27 12:40:24 +00:00
videoSetPalette ( 0 , palid , 0 ) ;
2012-02-02 17:34:16 +00:00
g_restorePalette = - 1 ;
2016-12-26 06:01:24 +00:00
g_crosshairSum = - 1 ;
2006-04-13 20:47:06 +00:00
}
2019-03-21 09:27:43 +00:00
2019-03-21 09:27:53 +00:00
static int osdcmd_dumpmapstate ( osdfuncparm_t const * const )
2019-03-21 09:27:43 +00:00
{
// this command takes no parameters
DumpMapStateHistory ( ) ;
return OSDCMD_OK ;
}
2019-03-21 09:27:53 +00:00
static int osdcmd_playerinfo ( osdfuncparm_t const * const )
2019-03-21 09:27:43 +00:00
{
OSD_Printf ( " Your player index is %d. \n " , myconnectindex ) ;
for ( int32_t playerIndex = 0 ; playerIndex < MAXPLAYERS ; playerIndex + + )
{
if ( g_player [ playerIndex ] . ps = = nullptr )
{
OSD_Printf ( " g_player[%d]: ps unallocated. \n " , playerIndex ) ;
}
else
{
OSD_Printf ( " g_player[%d]: ps->i is %d. \n " , playerIndex , g_player [ playerIndex ] . ps - > i ) ;
}
}
return OSDCMD_OK ;
}
2018-11-18 18:06:15 +00:00
static int osdcmd_disconnect ( osdcmdptr_t UNUSED ( parm ) )
2009-12-14 05:23:29 +00:00
{
2017-06-27 02:24:14 +00:00
UNREFERENCED_CONST_PARAMETER ( parm ) ;
2009-12-14 09:54:11 +00:00
g_netDisconnect = 1 ;
2009-12-14 05:23:29 +00:00
return OSDCMD_OK ;
}
2018-11-18 18:06:15 +00:00
static int osdcmd_connect ( osdcmdptr_t parm )
2009-12-14 05:23:29 +00:00
{
if ( parm - > numparms ! = 1 )
return OSDCMD_SHOWHELP ;
Net_Connect ( parm - > parms [ 0 ] ) ;
G_BackToMenu ( ) ;
return OSDCMD_OK ;
}
2018-11-18 18:06:15 +00:00
static int osdcmd_password ( osdcmdptr_t parm )
2009-12-14 20:14:12 +00:00
{
if ( parm - > numparms < 1 )
{
2010-01-16 23:08:17 +00:00
Bmemset ( g_netPassword , 0 , sizeof ( g_netPassword ) ) ;
2009-12-14 20:14:12 +00:00
return OSDCMD_OK ;
}
2016-01-11 05:05:25 +00:00
Bstrncpy ( g_netPassword , ( parm - > raw ) + 9 , sizeof ( g_netPassword ) - 1 ) ;
2009-12-14 20:14:12 +00:00
return OSDCMD_OK ;
}
2018-11-18 18:06:15 +00:00
static int osdcmd_listplayers ( osdcmdptr_t parm )
2009-12-15 05:53:15 +00:00
{
2010-08-02 08:13:51 +00:00
ENetPeer * currentPeer ;
2009-12-17 11:17:48 +00:00
char ipaddr [ 32 ] ;
2009-12-15 05:53:15 +00:00
2011-02-25 21:50:19 +00:00
if ( parm & & parm - > numparms ! = 0 )
2009-12-15 05:53:15 +00:00
return OSDCMD_SHOWHELP ;
2010-01-16 23:08:17 +00:00
if ( ! g_netServer )
2009-12-15 05:53:15 +00:00
{
initprintf ( " You are not the server. \n " ) ;
return OSDCMD_OK ;
}
2011-02-25 21:50:19 +00:00
initprintf ( " Connected clients: \n " ) ;
2010-01-16 23:08:17 +00:00
for ( currentPeer = g_netServer - > peers ;
2010-01-23 22:12:02 +00:00
currentPeer < & g_netServer - > peers [ g_netServer - > peerCount ] ;
+ + currentPeer )
2009-12-15 05:53:15 +00:00
{
if ( currentPeer - > state ! = ENET_PEER_STATE_CONNECTED )
continue ;
2009-12-17 11:17:48 +00:00
enet_address_get_host_ip ( & currentPeer - > address , ipaddr , sizeof ( ipaddr ) ) ;
initprintf ( " %x %s %s \n " , currentPeer - > address . host , ipaddr ,
2010-01-23 22:12:02 +00:00
g_player [ ( intptr_t ) currentPeer - > data ] . user_name ) ;
2009-12-15 05:53:15 +00:00
}
2013-12-31 11:51:54 +00:00
2009-12-15 05:53:15 +00:00
return OSDCMD_OK ;
}
2019-10-19 23:44:15 +00:00
#if 0
2018-11-18 18:06:15 +00:00
static int osdcmd_kick ( osdcmdptr_t parm )
2009-12-17 11:17:48 +00:00
{
2010-08-02 08:13:51 +00:00
ENetPeer * currentPeer ;
2009-12-17 11:17:48 +00:00
uint32_t hexaddr ;
if ( parm - > numparms ! = 1 )
return OSDCMD_SHOWHELP ;
2010-01-16 23:08:17 +00:00
if ( ! g_netServer )
2009-12-17 11:17:48 +00:00
{
initprintf ( " You are not the server. \n " ) ;
return OSDCMD_OK ;
}
2010-01-16 23:08:17 +00:00
for ( currentPeer = g_netServer - > peers ;
2010-01-23 22:12:02 +00:00
currentPeer < & g_netServer - > peers [ g_netServer - > peerCount ] ;
+ + currentPeer )
2009-12-17 11:17:48 +00:00
{
if ( currentPeer - > state ! = ENET_PEER_STATE_CONNECTED )
continue ;
2011-02-12 13:25:24 +00:00
sscanf ( parm - > parms [ 0 ] , " % " SCNx32 " " , & hexaddr ) ;
2009-12-17 11:17:48 +00:00
if ( currentPeer - > address . host = = hexaddr )
{
initprintf ( " Kicking %x (%s) \n " , currentPeer - > address . host ,
2010-01-23 22:12:02 +00:00
g_player [ ( intptr_t ) currentPeer - > data ] . user_name ) ;
enet_peer_disconnect ( currentPeer , DISC_KICKED ) ;
2009-12-17 11:17:48 +00:00
return OSDCMD_OK ;
}
}
initprintf ( " Player %s not found! \n " , parm - > parms [ 0 ] ) ;
2011-02-25 21:50:19 +00:00
osdcmd_listplayers ( NULL ) ;
2013-12-31 11:51:54 +00:00
2009-12-17 11:17:48 +00:00
return OSDCMD_OK ;
}
2018-11-18 18:06:15 +00:00
static int osdcmd_kickban ( osdcmdptr_t parm )
2009-12-17 11:17:48 +00:00
{
2010-08-02 08:13:51 +00:00
ENetPeer * currentPeer ;
2009-12-17 11:17:48 +00:00
uint32_t hexaddr ;
if ( parm - > numparms ! = 1 )
return OSDCMD_SHOWHELP ;
2010-01-16 23:08:17 +00:00
if ( ! g_netServer )
2009-12-17 11:17:48 +00:00
{
initprintf ( " You are not the server. \n " ) ;
return OSDCMD_OK ;
}
2010-01-16 23:08:17 +00:00
for ( currentPeer = g_netServer - > peers ;
2010-01-23 22:12:02 +00:00
currentPeer < & g_netServer - > peers [ g_netServer - > peerCount ] ;
+ + currentPeer )
2009-12-17 11:17:48 +00:00
{
if ( currentPeer - > state ! = ENET_PEER_STATE_CONNECTED )
continue ;
2011-02-12 13:25:24 +00:00
sscanf ( parm - > parms [ 0 ] , " % " SCNx32 " " , & hexaddr ) ;
2010-08-02 08:13:51 +00:00
2010-05-07 20:45:40 +00:00
// TODO: implement banning logic
2009-12-17 11:17:48 +00:00
if ( currentPeer - > address . host = = hexaddr )
{
char ipaddr [ 32 ] ;
enet_address_get_host_ip ( & currentPeer - > address , ipaddr , sizeof ( ipaddr ) ) ;
initprintf ( " Host %s is now banned. \n " , ipaddr ) ;
initprintf ( " Kicking %x (%s) \n " , currentPeer - > address . host ,
2010-01-23 22:12:02 +00:00
g_player [ ( intptr_t ) currentPeer - > data ] . user_name ) ;
enet_peer_disconnect ( currentPeer , DISC_BANNED ) ;
2009-12-17 11:17:48 +00:00
return OSDCMD_OK ;
}
}
initprintf ( " Player %s not found! \n " , parm - > parms [ 0 ] ) ;
2011-02-25 21:50:19 +00:00
osdcmd_listplayers ( NULL ) ;
2013-12-31 11:51:54 +00:00
2009-12-17 11:17:48 +00:00
return OSDCMD_OK ;
}
2013-12-31 11:51:54 +00:00
# endif
2009-12-17 11:17:48 +00:00
2018-03-08 03:55:41 +00:00
2018-11-18 18:06:15 +00:00
static int osdcmd_printtimes ( osdcmdptr_t UNUSED ( parm ) )
2018-03-08 00:29:41 +00:00
{
UNREFERENCED_CONST_PARAMETER ( parm ) ;
char buf [ 32 ] ;
int32_t maxlen = 0 ;
int32_t haveev = 0 , haveac = 0 ;
2018-11-18 18:06:07 +00:00
static char const s_event_ [ ] = " EVENT_ " ;
int constexpr strlen_event_ = ARRAY_SIZE ( s_event_ ) - 1 ;
2018-03-08 00:29:41 +00:00
2018-11-18 18:06:07 +00:00
for ( auto & EventName : EventNames )
2018-03-08 00:29:41 +00:00
{
2018-11-18 18:06:07 +00:00
int const len = Bstrlen ( EventName + strlen_event_ ) ;
2018-11-18 18:07:15 +00:00
Bassert ( len < ARRAY_SSIZE ( buf ) ) ;
2018-03-08 00:29:41 +00:00
maxlen = max ( len , maxlen ) ;
}
for ( int i = 0 ; i < MAXEVENTS ; i + + )
if ( g_eventCalls [ i ] )
{
2018-11-18 18:06:07 +00:00
int32_t n = Bsprintf ( buf , " %s " , EventNames [ i ] + strlen_event_ ) ;
2018-03-08 00:29:41 +00:00
if ( ! haveev )
{
haveev = 1 ;
2018-03-08 05:15:05 +00:00
OSD_Printf ( " \n event times: event, total calls, total time [ms], mean time/call [us] \n " ) ;
2018-03-08 00:29:41 +00:00
}
2018-03-08 02:39:21 +00:00
buf [ n ] = 0 ;
2018-03-08 00:29:41 +00:00
2018-03-08 05:15:05 +00:00
OSD_Printf ( " %17s, %8d, %10.3f, %10.3f, \n " ,
2018-03-08 00:29:41 +00:00
buf , g_eventCalls [ i ] , g_eventTotalMs [ i ] ,
1000 * g_eventTotalMs [ i ] / g_eventCalls [ i ] ) ;
}
for ( int i = 0 ; i < MAXTILES ; i + + )
if ( g_actorCalls [ i ] )
{
if ( ! haveac )
{
haveac = 1 ;
2018-03-08 05:15:05 +00:00
OSD_Printf ( " \n actor times: tile, total calls, total time [ms], {min,mean,max} time/call [us] \n " ) ;
2018-03-08 00:29:41 +00:00
}
buf [ 0 ] = 0 ;
for ( int ii = 0 ; ii < g_labelCnt ; ii + + )
{
2018-03-08 02:39:21 +00:00
if ( labelcode [ ii ] = = i & & labeltype [ ii ] & LABEL_ACTOR )
2018-03-08 00:29:41 +00:00
{
Bstrcpy ( buf , label + ( ii < < 6 ) ) ;
break ;
}
}
2018-03-08 02:39:21 +00:00
if ( ! buf [ 0 ] ) Bsprintf ( buf , " %d " , i ) ;
2018-03-08 00:29:41 +00:00
2018-03-08 05:15:05 +00:00
OSD_Printf ( " %17s, %8d, %9.3f, %9.3f, %9.3f, %9.3f, \n " ,
2018-03-08 00:29:41 +00:00
buf , g_actorCalls [ i ] , g_actorTotalMs [ i ] ,
1000 * g_actorMinMs [ i ] ,
1000 * g_actorTotalMs [ i ] / g_actorCalls [ i ] ,
1000 * g_actorMaxMs [ i ] ) ;
}
return OSDCMD_OK ;
}
2009-04-29 19:43:51 +00:00
2009-01-09 09:29:17 +00:00
int32_t registerosdcommands ( void )
2006-04-13 20:47:06 +00:00
{
2019-03-21 09:27:43 +00:00
# if !defined NETCODE_DISABLE
OSD_RegisterFunction ( " connect " , " connect: connects to a multiplayer game " , osdcmd_connect ) ;
OSD_RegisterFunction ( " disconnect " , " disconnect: disconnects from the local multiplayer game " , osdcmd_disconnect ) ;
OSD_RegisterFunction ( " dumpmapstates " , " Dumps current snapshots to CL/Srv_MapStates.bin " , osdcmd_dumpmapstate ) ;
2019-10-19 23:44:15 +00:00
#if 0
2019-03-21 09:27:43 +00:00
OSD_RegisterFunction ( " kick " , " kick <id>: kicks a multiplayer client. See listplayers. " , osdcmd_kick ) ;
OSD_RegisterFunction ( " kickban " , " kickban <id>: kicks a multiplayer client and prevents them from reconnecting. See listplayers. " , osdcmd_kickban ) ;
2019-10-19 23:44:15 +00:00
# endif
2019-03-21 09:27:43 +00:00
OSD_RegisterFunction ( " listplayers " , " listplayers: lists currently connected multiplayer clients " , osdcmd_listplayers ) ;
OSD_RegisterFunction ( " password " , " password: sets multiplayer game password " , osdcmd_password ) ;
OSD_RegisterFunction ( " playerinfo " , " Prints information about the current player " , osdcmd_playerinfo ) ;
# endif
2019-12-10 16:25:45 +00:00
if ( ! VOLUMEONE )
2006-11-15 01:16:55 +00:00
{
2008-10-23 20:19:30 +00:00
OSD_RegisterFunction ( " map " , " map <mapfile>: loads the given user map " , osdcmd_map ) ;
2012-09-08 22:18:37 +00:00
OSD_RegisterFunction ( " demo " , " demo <demofile or demonum>: starts the given demo " , osdcmd_demo ) ;
2006-04-13 20:47:06 +00:00
}
2006-05-23 23:43:18 +00:00
2009-04-29 19:43:51 +00:00
OSD_RegisterFunction ( " crosshaircolor " , " crosshaircolor: changes the crosshair color " , osdcmd_crosshaircolor ) ;
2006-04-13 20:47:06 +00:00
OSD_RegisterFunction ( " give " , " give <all|health|weapons|ammo|armor|keys|inventory>: gives requested item " , osdcmd_give ) ;
2006-05-23 23:43:18 +00:00
OSD_RegisterFunction ( " god " , " god: toggles god mode " , osdcmd_god ) ;
2017-07-05 05:38:08 +00:00
OSD_RegisterFunction ( " activatecheat " , " activatecheat <id>: activates a cheat code " , osdcmd_activatecheat ) ;
2006-05-23 23:43:18 +00:00
2006-04-13 20:47:06 +00:00
OSD_RegisterFunction ( " noclip " , " noclip: toggles clipping mode " , osdcmd_noclip ) ;
2018-03-08 00:29:41 +00:00
OSD_RegisterFunction ( " printtimes " , " printtimes: prints VM timing statistics " , osdcmd_printtimes ) ;
2009-12-14 20:14:12 +00:00
2015-12-23 04:05:55 +00:00
OSD_RegisterFunction ( " restartmap " , " restartmap: restarts the current map " , osdcmd_restartmap ) ;
2019-11-05 19:16:53 +00:00
OSD_RegisterFunction ( " addlogvar " , " addlogvar <gamevar>: prints the value of a gamevar " , osdcmd_addlogvar ) ;
2006-05-23 23:43:18 +00:00
OSD_RegisterFunction ( " setvar " , " setvar <gamevar> <value>: sets the value of a gamevar " , osdcmd_setvar ) ;
2008-10-23 20:19:30 +00:00
OSD_RegisterFunction ( " setvarvar " , " setvarvar <gamevar1> <gamevar2>: sets the value of <gamevar1> to <gamevar2> " , osdcmd_setvar ) ;
OSD_RegisterFunction ( " setactorvar " , " setactorvar <actor#> <gamevar> <value>: sets the value of <actor#>'s <gamevar> to <value> " , osdcmd_setactorvar ) ;
2008-07-03 07:37:41 +00:00
2006-05-23 23:43:18 +00:00
OSD_RegisterFunction ( " spawn " , " spawn <picnum> [palnum] [cstat] [ang] [x y z]: spawns a sprite with the given properties " , osdcmd_spawn ) ;
2006-04-13 20:47:06 +00:00
return 0 ;
}
2019-09-21 20:53:00 +00:00
END_DUKE_NS