@ -10,11 +10,20 @@
# define ENABLE_NETWORK
# endif
// ** scriptfile handling ** //
static FILE * _script_file ;
static bool _script_running ;
// ** console command / variable defines ** //
# define DEF_CONSOLE_CMD(yyyy) static _iconsole_var * yyyy(byte argc, byte* argv[], byte argt[])
# define DEF_CONSOLE_CMD_HOOK(yyyy) static bool yyyy(_iconsole_cmd * hookcmd)
# define DEF_CONSOLE_VAR_HOOK(yyyy) static bool yyyy(_iconsole_var * hookvar)
// ** supporting functions ** //
static int32 GetArgumentInteger ( byte * arg )
{
int32 result ;
@ -125,10 +134,68 @@ DEF_CONSOLE_CMD(ConNetworkConnect)
# endif
/* ******************************** */
/* script file console commands */
/* ******************************** */
DEF_CONSOLE_CMD ( ConExec )
{
char cmd [ 1024 ] ;
bool doerror ;
if ( argc < 2 ) return NULL ;
doerror = true ;
_script_file = fopen ( argv [ 1 ] , " rb " ) ;
if ( _script_file = = NULL ) {
if ( argc > 2 ) if ( atoi ( argv [ 2 ] ) = = 0 ) doerror = false ;
if ( doerror ) IConsoleError ( " script file not found " ) ;
return NULL ;
}
_script_running = true ;
while ( ! feof ( _script_file ) & & _script_running ) {
fgets ( ( char * ) & cmd , 1024 , _script_file ) ;
IConsoleCmdExec ( ( byte * ) & cmd ) ;
}
_script_running = false ;
fclose ( _script_file ) ;
return NULL ;
}
DEF_CONSOLE_CMD ( ConReturn )
{
_script_running = false ;
return NULL ;
}
/* **************************** */
/* default console commands */
/* **************************** */
DEF_CONSOLE_CMD ( ConScript )
{
extern FILE * _iconsole_output_file ;
if ( _iconsole_output_file ! = NULL ) {
if ( argc < 2 ) return NULL ;
IConsolePrintF ( _iconsole_color_default , " file output complete " ) ;
fclose ( _iconsole_output_file ) ;
} else {
IConsolePrintF ( _iconsole_color_default , " file output started to: %s " , argv [ 1 ] ) ;
_iconsole_output_file = fopen ( argv [ 1 ] , " ab " ) ;
if ( _iconsole_output_file = = NULL ) IConsoleError ( " could not open file " ) ;
}
return NULL ;
}
DEF_CONSOLE_CMD ( ConEcho )
{
if ( argc < 2 ) return NULL ;
@ -184,35 +251,35 @@ DEF_CONSOLE_CMD(ConInfoVar)
IConsolePrintF ( _iconsole_color_default , " var_name: %s " , item - > name ) ;
IConsolePrintF ( _iconsole_color_default , " var_type: %i " , item - > type ) ;
IConsolePrintF ( _iconsole_color_default , " var_addr: %i " , item - > addr ) ;
if ( item - > _malloc ) IConsolePrintF ( _iconsole_color_default , " var_malloc: internal " ) ;
else IConsolePrintF ( _iconsole_color_default , " var_malloc: external " ) ;
if ( item - > hook_access ) IConsoleWarning ( " var_access hooked " ) ;
if ( item - > hook_before_change ) IConsoleWarning ( " var_before_change hooked " ) ;
if ( item - > _malloc ) IConsolePrintF ( _iconsole_color_default , " var_malloc: internal " ) ;
else IConsolePrintF ( _iconsole_color_default , " var_malloc: external " ) ;
if ( item - > hook_access ) IConsoleWarning ( " var_access hooked " ) ;
if ( item - > hook_before_change ) IConsoleWarning ( " var_before_change hooked " ) ;
if ( item - > hook_after_change ) IConsoleWarning ( " var_after_change hooked " ) ;
}
return NULL ;
}
DEF_CONSOLE_CMD ( ConInfoCmd )
{
if ( argc < 2 ) return NULL ;
if ( argt [ 1 ] ! = ICONSOLE_VAR_UNKNOWN ) {
IConsoleError ( " first argument has to be a command name " ) ;
} else {
_iconsole_cmd * item ;
item = IConsoleCmdGet ( argv [ 1 ] ) ;
if ( item = = NULL ) {
IConsoleError ( " the given command was not found " ) ;
return NULL ;
}
IConsolePrintF ( _iconsole_color_default , " cmd_name: %s " , item - > name ) ;
IConsolePrintF ( _iconsole_color_default , " cmd_addr: %i " , item - > addr ) ;
if ( item - > hook_access ) IConsoleWarning ( " cmd_access hooked " ) ;
if ( item - > hook_before_exec ) IConsoleWarning ( " cmd_before_exec hooked " ) ;
if ( item - > hook_after_exec ) IConsoleWarning ( " cmd_after_exec hooked " ) ;
}
return NULL ;
}
DEF_CONSOLE_CMD ( ConInfoCmd )
{
if ( argc < 2 ) return NULL ;
if ( argt [ 1 ] ! = ICONSOLE_VAR_UNKNOWN ) {
IConsoleError ( " first argument has to be a command name " ) ;
} else {
_iconsole_cmd * item ;
item = IConsoleCmdGet ( argv [ 1 ] ) ;
if ( item = = NULL ) {
IConsoleError ( " the given command was not found " ) ;
return NULL ;
}
IConsolePrintF ( _iconsole_color_default , " cmd_name: %s " , item - > name ) ;
IConsolePrintF ( _iconsole_color_default , " cmd_addr: %i " , item - > addr ) ;
if ( item - > hook_access ) IConsoleWarning ( " cmd_access hooked " ) ;
if ( item - > hook_before_exec ) IConsoleWarning ( " cmd_before_exec hooked " ) ;
if ( item - > hook_after_exec ) IConsoleWarning ( " cmd_after_exec hooked " ) ;
}
return NULL ;
}
DEF_CONSOLE_CMD ( ConDebugLevel )
@ -335,6 +402,10 @@ DEF_CONSOLE_CMD(ConListDumpVariables)
void IConsoleDebugLibRegister ( )
{
// stdlib
extern bool _stdlib_con_developer ;
IConsoleVarRegister ( " con_developer " , ( void * ) & _stdlib_con_developer , ICONSOLE_VAR_BOOLEAN ) ;
IConsoleVarMemRegister ( " temp_bool " , ICONSOLE_VAR_BOOLEAN ) ;
IConsoleVarMemRegister ( " temp_int16 " , ICONSOLE_VAR_INT16 ) ;
IConsoleVarMemRegister ( " temp_int32 " , ICONSOLE_VAR_INT32 ) ;
@ -356,7 +427,6 @@ void IConsoleStdLibRegister()
{
// stdlib
extern byte _stdlib_developer ;
extern bool _stdlib_con_developer ;
# ifdef _DEBUG
IConsoleDebugLibRegister ( ) ;
@ -364,32 +434,34 @@ void IConsoleStdLibRegister()
( void ) ConResetTile ; // Silence warning, this is only used in _DEBUG
# endif
// functions [please add them alphabeticaly]
// functions [please add them alphabeticaly]
# ifdef ENABLE_NETWORK
IConsoleCmdRegister ( " connect " , ConNetworkConnect ) ;
IConsoleCmdHook ( " connect " , ICONSOLE_HOOK_ACCESS , ConCmdHookNoNetwork ) ;
# endif
# endif
IConsoleCmdRegister ( " debug_level " , ConDebugLevel ) ;
IConsoleCmdRegister ( " dump_vars " , ConListDumpVariables ) ;
IConsoleCmdRegister ( " echo " , ConEcho ) ;
IConsoleCmdRegister ( " echoc " , ConEchoC ) ;
IConsoleCmdRegister ( " exec " , ConExec ) ;
IConsoleCmdRegister ( " exit " , ConExit ) ;
IConsoleCmdRegister ( " help " , ConHelp ) ;
IConsoleCmdRegister ( " info_cmd " , ConInfoCmd ) ;
IConsoleCmdRegister ( " help " , ConHelp ) ;
IConsoleCmdRegister ( " info_cmd " , ConInfoCmd ) ;
IConsoleCmdRegister ( " info_var " , ConInfoVar ) ;
IConsoleCmdRegister ( " list_cmds " , ConListCommands ) ;
IConsoleCmdRegister ( " list_vars " , ConListVariables ) ;
IConsoleCmdRegister ( " list_cmds " , ConListCommands ) ;
IConsoleCmdRegister ( " list_vars " , ConListVariables ) ;
IConsoleCmdRegister ( " printf " , ConPrintF ) ;
IConsoleCmdRegister ( " printfc " , ConPrintFC ) ;
IConsoleCmdRegister ( " quit " , ConExit ) ;
IConsoleCmdRegister ( " random " , ConRandom ) ;
IConsoleCmdRegister ( " resetengines " , ConResetEngines ) ;
IConsoleCmdHook ( " resetengines " , ICONSOLE_HOOK_ACCESS , ConCmdHookNoNetwork ) ;
IConsoleCmdRegister ( " return " , ConReturn ) ;
IConsoleCmdRegister ( " screenshot " , ConScreenShot ) ;
IConsoleCmdRegister ( " script " , ConScript ) ;
IConsoleCmdRegister ( " scrollto " , ConScrollToTile ) ;
// variables [please add them alphabeticaly]
IConsoleVarRegister ( " con_developer " , ( void * ) & _stdlib_con_developer , ICONSOLE_VAR_BOOLEAN ) ;
IConsoleVarRegister ( " developer " , ( void * ) & _stdlib_developer , ICONSOLE_VAR_BYTE ) ;
# ifdef ENABLE_NETWORK
IConsoleVarRegister ( " net_client_timeout " , & _network_client_timeout , ICONSOLE_VAR_UINT16 ) ;