diff options
-rw-r--r-- | console.c | 1718 | ||||
-rw-r--r-- | console.h | 36 | ||||
-rw-r--r-- | console_cmds.c | 387 | ||||
-rw-r--r-- | console_cmds.h | 13 | ||||
-rw-r--r-- | engine.c | 3 | ||||
-rw-r--r-- | network.c | 34 | ||||
-rw-r--r-- | ttd.vcproj | 6 | ||||
-rw-r--r-- | variables.h | 2 |
8 files changed, 1240 insertions, 959 deletions
@@ -9,7 +9,6 @@ #include <stdarg.h> #include "console.h" - // ** main console ** // static bool _iconsole_inited; static byte* _iconsole_buffer[80]; @@ -20,15 +19,19 @@ static byte _iconsole_mode = ICONSOLE_CLOSED; static Window *_iconsole_win = NULL; static byte _iconsole_scroll; -// ** main console cmd buffer ** // sign_de: especialy for Celestar :D -static byte* _iconsole_cmdbuffer[20]; -static byte _iconsole_cmdbufferpos; - // ** console cursor ** // static bool _icursor_state; static byte _icursor_rate; static byte _icursor_counter; +// ** stdlib ** // +byte _stdlib_developer=1; +bool _stdlib_con_developer=false; + +// ** main console cmd buffer ** // sign_de: especialy for Celestar :D +static byte* _iconsole_cmdbuffer[20]; +static byte _iconsole_cmdbufferpos; + // ** console window ** // static void IConsoleWndProc(Window *w, WindowEvent *e); static const Widget _iconsole_window_widgets[] = {{WIDGETS_END}}; @@ -40,15 +43,6 @@ static const WindowDesc _iconsole_window_desc = { IConsoleWndProc, }; -// ** console parser ** // -static _iconsole_cmd * _iconsole_cmds; // list of registred commands -static _iconsole_var * _iconsole_vars; // list of registred vars - -// ** console std lib ** // -static byte _stdlib_developer=1; -static bool _stdlib_con_developer=false; -static void IConsoleStdLibRegister(); - /* *************** */ /* end of header */ /* *************** */ @@ -188,57 +182,58 @@ static void IConsoleWndProc(Window *w, WindowEvent *e) void IConsoleInit() { -int i; -#if defined(WITH_REV) -extern char _openttd_revision[]; -#endif -_iconsole_color_default = 1; -_iconsole_color_error = 3; -_iconsole_color_debug = 5; -_iconsole_color_commands = 2; -_iconsole_scroll=79; -_iconsole_cmdbufferpos=19; -_iconsole_inited=true; -_iconsole_mode=ICONSOLE_CLOSED; -_iconsole_win=NULL; -_icursor_state=false; -_icursor_rate=5; -_icursor_counter=0; -for (i=0;i<20;i++) { - _iconsole_cmdbuffer[i]=NULL; - } -for (i=0;i<80;i++) { - _iconsole_buffer[i]=NULL; - _iconsole_cbuffer[i]=0; - } -IConsoleStdLibRegister(); -#if defined(WITH_REV) -IConsolePrintF(13,"OpenTTD Game Console Revision 3 - %s",_openttd_revision); -#else -IConsolePrint(13,"OpenTTD Game Console Revision 3"); -#endif -IConsolePrint(12,"---------------------------------"); -IConsolePrint(12,"use \"help\" for more info"); -IConsolePrint(12,""); -IConsoleClearCommand(); -IConsoleCmdBufferAdd(""); + int i; + #if defined(WITH_REV) + extern char _openttd_revision[]; + #endif + _iconsole_color_default = 1; + _iconsole_color_error = 3; + _iconsole_color_debug = 5; + _iconsole_color_commands = 2; + _iconsole_scroll=79; + _iconsole_cmdbufferpos=19; + _iconsole_inited=true; + _iconsole_mode=ICONSOLE_CLOSED; + _iconsole_win=NULL; + _icursor_state=false; + _icursor_rate=5; + _icursor_counter=0; + for (i=0;i<20;i++) { + _iconsole_cmdbuffer[i]=NULL; + } + for (i=0;i<80;i++) { + _iconsole_buffer[i]=NULL; + _iconsole_cbuffer[i]=0; + } + IConsoleStdLibRegister(); + #if defined(WITH_REV) + IConsolePrintF(13,"OpenTTD Game Console Revision 3 - %s",_openttd_revision); + #else + IConsolePrint(13,"OpenTTD Game Console Revision 3"); + #endif + IConsolePrint(12,"---------------------------------"); + IConsolePrint(12,"use \"help\" for more info"); + IConsolePrint(12,""); + IConsoleClearCommand(); + IConsoleCmdBufferAdd(""); } void IConsoleClear() { -int i; -for (i=0;i<80;i++) if (_iconsole_buffer[i]!=NULL) { - free(_iconsole_buffer[i]); - } + int i; + for (i=0;i<80;i++) if (_iconsole_buffer[i]!=NULL) { + free(_iconsole_buffer[i]); + } } void IConsoleFree() { -_iconsole_inited=false; -IConsoleClear(); + _iconsole_inited=false; + IConsoleClear(); } -void IConsoleResize() { +void IConsoleResize() +{ if (_iconsole_win!=NULL) { _iconsole_win->height = _screen.height / 3; _iconsole_win->width= _screen.width; @@ -263,80 +258,84 @@ void IConsoleSwitch() _video_driver->make_dirty(0,0,_screen.width,_screen.height); } -void IConsoleClose() { -if (_iconsole_mode==ICONSOLE_OPENED) IConsoleSwitch(); -_iconsole_mode=ICONSOLE_CLOSED; +void IConsoleClose() +{ + if (_iconsole_mode==ICONSOLE_OPENED) IConsoleSwitch(); + _iconsole_mode=ICONSOLE_CLOSED; } -void IConsoleOpen() { -if (_iconsole_mode==ICONSOLE_CLOSED) IConsoleSwitch(); +void IConsoleOpen() +{ + if (_iconsole_mode==ICONSOLE_CLOSED) IConsoleSwitch(); } -void IConsoleCmdBufferAdd(byte * cmd) { -int i; -if (_iconsole_cmdbufferpos != 19) return; -if (_iconsole_cmdbuffer[18]!=NULL) free(_iconsole_cmdbuffer[18]); -for (i=18; i>0; i--) _iconsole_cmdbuffer[i]=_iconsole_cmdbuffer[i-1]; -i=strlen((char *)cmd); -_iconsole_cmdbuffer[0]=malloc(i+1); -memset(((void *)_iconsole_cmdbuffer[0]),0,i+1); -memcpy(((void *)_iconsole_cmdbuffer[0]),(void *)cmd,i); -_iconsole_cmdbuffer[0][i]=0; -_iconsole_cmdbufferpos = 19; +void IConsoleCmdBufferAdd(byte * cmd) +{ + int i; + if (_iconsole_cmdbufferpos != 19) return; + if (_iconsole_cmdbuffer[18]!=NULL) free(_iconsole_cmdbuffer[18]); + for (i=18; i>0; i--) _iconsole_cmdbuffer[i]=_iconsole_cmdbuffer[i-1]; + i=strlen((char *)cmd); + _iconsole_cmdbuffer[0]=malloc(i+1); + memset(((void *)_iconsole_cmdbuffer[0]),0,i+1); + memcpy(((void *)_iconsole_cmdbuffer[0]),(void *)cmd,i); + _iconsole_cmdbuffer[0][i]=0; + _iconsole_cmdbufferpos = 19; } -void IConsoleCmdBufferNavigate(signed char direction) { -int i; -i=_iconsole_cmdbufferpos + direction; -if (i<0) i=19; -if (i>19) i=0; -if (direction>0) while (_iconsole_cmdbuffer[i]==NULL) { - i++; - if (i>19) i=0; - } -if (direction<0) while (_iconsole_cmdbuffer[i]==NULL) { - i--; +void IConsoleCmdBufferNavigate(signed char direction) +{ + int i; + i=_iconsole_cmdbufferpos + direction; if (i<0) i=19; - } -_iconsole_cmdbufferpos = i; -IConsoleClearCommand(); -memcpy((void *)_iconsole_cmdline,(void *)_iconsole_cmdbuffer[i],strlen(_iconsole_cmdbuffer[i])); -_iconsole_cmdpos =strlen(_iconsole_cmdbuffer[i]); + if (i>19) i=0; + if (direction>0) while (_iconsole_cmdbuffer[i]==NULL) { + i++; + if (i>19) i=0; + } + if (direction<0) while (_iconsole_cmdbuffer[i]==NULL) { + i--; + if (i<0) i=19; + } + _iconsole_cmdbufferpos = i; + IConsoleClearCommand(); + memcpy((void *)_iconsole_cmdline,(void *)_iconsole_cmdbuffer[i],strlen(_iconsole_cmdbuffer[i])); + _iconsole_cmdpos =strlen(_iconsole_cmdbuffer[i]); } void IConsolePrint(byte color_code, byte* string) { -byte * _ex; -byte * _new; -byte _exc; -byte _newc; -int i,j; - -if (!_iconsole_inited) return; - -_newc=color_code; -i=strlen((char *)string); -_new=malloc(i+1); -memset(_new,0,i+1); -memcpy(_new,string,i); - -for (j=0;j<i;j++) { - if (_new[j]<0x1F) _new[j]=0x20; - } + byte * _ex; + byte * _new; + byte _exc; + byte _newc; + int i,j; -i=79; -while (i>=0) { - _ex=_iconsole_buffer[i]; - _exc=_iconsole_cbuffer[i]; - _iconsole_buffer[i]=_new; - _iconsole_cbuffer[i]=_newc; - _new=_ex; - _newc=_exc; - i--; - } -if (_ex!=NULL) free(_ex); + if (!_iconsole_inited) return; + + _newc=color_code; + i=strlen((char *)string); + _new=malloc(i+1); + memset(_new,0,i+1); + memcpy(_new,string,i); + + for (j=0;j<i;j++) { + if (_new[j]<0x1F) _new[j]=0x20; + } + + i=79; + while (i>=0) { + _ex=_iconsole_buffer[i]; + _exc=_iconsole_cbuffer[i]; + _iconsole_buffer[i]=_new; + _iconsole_cbuffer[i]=_newc; + _new=_ex; + _newc=_exc; + i--; + } + if (_ex!=NULL) free(_ex); -if (_iconsole_win!=NULL) SetWindowDirty(_iconsole_win); + if (_iconsole_win!=NULL) SetWindowDirty(_iconsole_win); } @@ -350,247 +349,277 @@ void CDECL IConsolePrintF(byte color_code, const char *s, ...) IConsolePrint(color_code, (byte *) &buf); } -void IConsoleDebug(byte* string) { -if (_stdlib_developer>1) IConsolePrintF(_iconsole_color_debug, "DEBUG: %s", string); +void IConsoleDebug(byte* string) +{ + if (_stdlib_developer>1) IConsolePrintF(_iconsole_color_debug, "DEBUG: %s", string); } -void IConsoleError(byte* string) { -if (_stdlib_developer>0) IConsolePrintF(_iconsole_color_error, "ERROR: %s", string); +void IConsoleError(byte* string) +{ + if (_stdlib_developer>0) IConsolePrintF(_iconsole_color_error, "ERROR: %s", string); } -void IConsoleCmdRegister(byte * name, void * addr) { -byte * _new; -_iconsole_cmd * item; -_iconsole_cmd * item_new; -int i; - - i=strlen((char *)name); - _new=malloc(i+1); - memset(_new,0,i+1); - memcpy(_new,name,i); +void IConsoleCmdRegister(byte * name, void * addr) +{ + byte * _new; + _iconsole_cmd * item; + _iconsole_cmd * item_new; + int i; -item_new = malloc(sizeof(_iconsole_cmd)); + i=strlen((char *)name); + _new=malloc(i+1); + memset(_new,0,i+1); + memcpy(_new,name,i); -item_new->_next = NULL; -item_new->addr = addr; -item_new->name = _new; + item_new = malloc(sizeof(_iconsole_cmd)); -item = _iconsole_cmds; -if (item == NULL) { - _iconsole_cmds = item_new; - } else { - while (item->_next != NULL) { item = item->_next; }; - item->_next = item_new; - } -} + item_new->_next = NULL; + item_new->addr = addr; + item_new->name = _new; -void* IConsoleCmdGetAddr(byte * name) { -_iconsole_cmd * item; + item_new->hook_access = NULL; + item_new->hook_after_exec = NULL; + item_new->hook_before_exec = NULL; -item = _iconsole_cmds; -while (item != NULL) { - if (strcmp(item->name,name)==0) return item->addr; - item = item->_next; - } -return NULL; + item = _iconsole_cmds; + if (item == NULL) { + _iconsole_cmds = item_new; + } else { + while (item->_next != NULL) { item = item->_next; }; + item->_next = item_new; + } } -void IConsoleVarRegister(byte * name, void * addr, byte type) { -byte * _new; -_iconsole_var * item; -_iconsole_var * item_new; -int i; - - i=strlen((char *)name)+1; - _new=malloc(i+1); - memset(_new,0,i+1); - _new[0]='*'; - memcpy(_new+1,name,i); +void* IConsoleCmdGet(byte * name) +{ + _iconsole_cmd * item; -item_new = malloc(sizeof(_iconsole_var)); + item = _iconsole_cmds; + while (item != NULL) { + if (strcmp(item->name,name)==0) return item; + item = item->_next; + } + return NULL; +} -item_new->_next = NULL; -item_new->addr = addr; -item_new->name = _new; -item_new->type = type; -item_new->_malloc = false; +void IConsoleVarRegister(byte * name, void * addr, byte type) +{ + byte * _new; + _iconsole_var * item; + _iconsole_var * item_new; + int i; + + i=strlen((char *)name)+1; + _new=malloc(i+1); + memset(_new,0,i+1); + _new[0]='*'; + memcpy(_new+1,name,i); + + item_new = malloc(sizeof(_iconsole_var)); + + item_new->_next = NULL; + item_new->addr = addr; + item_new->name = _new; + item_new->type = type; + item_new->_malloc = false; + + item_new->hook_access = NULL; + item_new->hook_after_change = NULL; + item_new->hook_before_change = NULL; + + item = _iconsole_vars; + if (item == NULL) { + _iconsole_vars = item_new; + } else { + while (item->_next != NULL) { item = item->_next; }; + item->_next = item_new; + } +} -item = _iconsole_vars; -if (item == NULL) { - _iconsole_vars = item_new; - } else { - while (item->_next != NULL) { item = item->_next; }; - item->_next = item_new; - } +void IConsoleVarMemRegister(byte * name, byte type) +{ + _iconsole_var * item; + item = IConsoleVarAlloc(type); + IConsoleVarInsert(item,name); } -void IConsoleVarInsert(_iconsole_var * var, byte * name) { -byte * _new; -_iconsole_var * item; -_iconsole_var * item_new; -int i; -item_new = var; +void IConsoleVarInsert(_iconsole_var * var, byte * name) +{ + byte * _new; + _iconsole_var * item; + _iconsole_var * item_new; + int i; -// dont allow to build variable rings -if (item_new->_next != NULL) return; + item_new = var; - i=strlen((char *)name)+1; - _new=malloc(i+1); - memset(_new,0,i+1); - _new[0]='*'; - memcpy(_new+1,name,i); + // dont allow to build variable rings + if (item_new->_next != NULL) return; -item_new->name = _new; + i=strlen((char *)name)+1; + _new=malloc(i+1); + memset(_new,0,i+1); + _new[0]='*'; + memcpy(_new+1,name,i); -item = _iconsole_vars; -if (item == NULL) { - _iconsole_vars = item_new; + item_new->name = _new; + + item = _iconsole_vars; + if (item == NULL) { + _iconsole_vars = item_new; } else { - while (item->_next != NULL) { item = item->_next; }; - item->_next = item_new; + while (item->_next != NULL) { item = item->_next; }; + item->_next = item_new; } } -_iconsole_var * IConsoleVarGet(byte * name) { -_iconsole_var * item; - -item = _iconsole_vars; -while (item != NULL) { - if (strcmp(item->name,name)==0) return item; - item = item->_next; - } -return NULL; -} +_iconsole_var * IConsoleVarGet(byte * name) +{ + _iconsole_var * item; -_iconsole_var * IConsoleVarAlloc(byte type) { -_iconsole_var * item; -item=malloc(sizeof(_iconsole_var)); -item->_next = NULL; -item->name = ""; -item->type = type; -switch (item->type) { - case ICONSOLE_VAR_BOOLEAN: - { - item->addr=malloc(sizeof(bool)); - memset(item->addr,0,sizeof(bool)); - item->_malloc=true; - } - break; - case ICONSOLE_VAR_BYTE: - { - item->addr=malloc(sizeof(byte)); - memset(item->addr,0,sizeof(byte)); - item->_malloc=true; - } - break; - case ICONSOLE_VAR_UINT16: - { - item->addr=malloc(sizeof(unsigned short)); - memset(item->addr,0,sizeof(unsigned short)); - item->_malloc=true; - } - break; - case ICONSOLE_VAR_UINT32: - { - item->addr=malloc(sizeof(unsigned int)); - memset(item->addr,0,sizeof(unsigned int)); - item->_malloc=true; - } - break; - case ICONSOLE_VAR_INT16: - { - item->addr=malloc(sizeof(signed short)); - memset(item->addr,0,sizeof(signed short)); - item->_malloc=true; - } - break; - case ICONSOLE_VAR_INT32: - { - item->addr=malloc(sizeof(signed int)); - memset(item->addr,0,sizeof(signed int)); - item->_malloc=true; - } - break; - default: - item->addr = NULL; - item->_malloc = false; - break; + item = _iconsole_vars; + while (item != NULL) { + if (strcmp(item->name,name)==0) return item; + item = item->_next; } -return item; + return NULL; } +_iconsole_var * IConsoleVarAlloc(byte type) +{ + _iconsole_var * item; + item=malloc(sizeof(_iconsole_var)); + item->_next = NULL; + item->name = ""; + item->type = type; + switch (item->type) { + case ICONSOLE_VAR_BOOLEAN: + { + item->addr=malloc(sizeof(bool)); + memset(item->addr,0,sizeof(bool)); + item->_malloc=true; + } + break; + case ICONSOLE_VAR_BYTE: + { + item->addr=malloc(sizeof(byte)); + memset(item->addr,0,sizeof(byte)); + item->_malloc=true; + } + break; + case ICONSOLE_VAR_UINT16: + { + item->addr=malloc(sizeof(unsigned short)); + memset(item->addr,0,sizeof(unsigned short)); + item->_malloc=true; + } + break; + case ICONSOLE_VAR_UINT32: + { + item->addr=malloc(sizeof(unsigned int)); + memset(item->addr,0,sizeof(unsigned int)); + item->_malloc=true; + } + break; + case ICONSOLE_VAR_INT16: + { + item->addr=malloc(sizeof(signed short)); + memset(item->addr,0,sizeof(signed short)); + item->_malloc=true; + } + break; + case ICONSOLE_VAR_INT32: + { + item->addr=malloc(sizeof(signed int)); + memset(item->addr,0,sizeof(signed int)); + item->_malloc=true; + } + break; + default: + item->addr = NULL; + item->_malloc = false; + break; + } -void IConsoleVarFree(_iconsole_var * var) { -if (var ->_malloc) { - free(var ->addr); - } -free(var); + item->hook_access = NULL; + item->hook_after_change = NULL; + item->hook_before_change = NULL; + return item; } -void IConsoleVarSetString(_iconsole_var * var, byte * string) { -int l; -if (string == NULL) return; +void IConsoleVarFree(_iconsole_var * var) +{ + if (var ->_malloc) { + free(var ->addr); + } + free(var); +} -if (var->_malloc) { - free(var->addr); - } +void IConsoleVarSetString(_iconsole_var * var, byte * string) +{ + int l; -l=strlen((char *) string); -var->addr=malloc(l+1); -var->_malloc=true; -memset(var->addr,0,l); -memcpy((void *) var->addr,(void *) string, l); -((byte *)var->addr)[l]=0; -} + if (string == NULL) return; -void IConsoleVarSetValue(_iconsole_var * var, int value) { -switch (var->type) { - case ICONSOLE_VAR_BOOLEAN: - { - (*(bool *)var->addr)=(value!=0); - } - break; - case ICONSOLE_VAR_BYTE: - { - (*(byte *)var->addr)=value; - } - break; - case ICONSOLE_VAR_UINT16: - { - (*(unsigned short *)var->addr)=value; - } - break; - case ICONSOLE_VAR_UINT32: - { - (*(unsigned int *)var->addr)=value; - } - break; - case ICONSOLE_VAR_INT16: - { - (*(signed short *)var->addr)=value; - } - break; - case ICONSOLE_VAR_INT32: - { - (*(signed int *)var->addr)=value; - } - break; - default: - break; + if (var->_malloc) { + free(var->addr); } -} -void IConsoleVarDump(_iconsole_var * var, byte * dump_desc) { + l=strlen((char *) string); + var->addr=malloc(l+1); + var->_malloc=true; + memset(var->addr,0,l); + memcpy((void *) var->addr,(void *) string, l); + ((byte *)var->addr)[l]=0; + } -byte var_b; // TYPE BYTE -unsigned short var_ui16; // TYPE UINT16 -unsigned int var_ui32; // TYPE UINT32 -signed short var_i16; // TYPE INT16 -signed int var_i32; // TYPE INT32 -byte * var_s; // TYPE STRING + void IConsoleVarSetValue(_iconsole_var * var, int value) { + switch (var->type) { + case ICONSOLE_VAR_BOOLEAN: + { + (*(bool *)var->addr)=(value!=0); + } + break; + case ICONSOLE_VAR_BYTE: + { + (*(byte *)var->addr)=value; + } + break; + case ICONSOLE_VAR_UINT16: + { + (*(unsigned short *)var->addr)=value; + } + break; + case ICONSOLE_VAR_UINT32: + { + (*(unsigned int *)var->addr)=value; + } + break; + case ICONSOLE_VAR_INT16: + { + (*(signed short *)var->addr)=value; + } + break; + case ICONSOLE_VAR_INT32: + { + (*(signed int *)var->addr)=value; + } + break; + default: + break; + } +} + +void IConsoleVarDump(_iconsole_var * var, byte * dump_desc) +{ + byte var_b; // TYPE BYTE + unsigned short var_ui16; // TYPE UINT16 + unsigned int var_ui32; // TYPE UINT32 + signed short var_i16; // TYPE INT16 + signed int var_i32; // TYPE INT32 + byte * var_s; // TYPE STRING if (dump_desc==NULL) dump_desc = var->name; @@ -651,672 +680,545 @@ byte * var_s; // TYPE STRING } break; } +} +// * ************************* * // +// * hooking code * // +// * ************************* * // + +void IConsoleVarHook(byte * name, byte type, void * proc) +{ + _iconsole_var * hook_var; + hook_var = IConsoleVarGet(name); + if (hook_var == NULL) return; + switch (type) { + case ICONSOLE_HOOK_BEFORE_CHANGE: + hook_var->hook_after_change = proc; + break; + case ICONSOLE_HOOK_AFTER_CHANGE: + hook_var->hook_after_change = proc; + break; + case ICONSOLE_HOOK_ACCESS: + hook_var->hook_access = proc; + break; + } } -void IConsoleCmdExec(byte * cmdstr) { -_iconsole_var * (*function)(byte argc, byte* argv[], byte argt[]); -byte * tokens[20]; -byte tokentypes[20]; -byte * tokenstream; -byte * tokenstream_s; -byte execution_mode; -_iconsole_var * var = NULL; -_iconsole_var * result = NULL; - -bool longtoken; -bool valid_token; -bool skip_lt_change; - -int c; -int i; -int l; - -//** clearing buffer **// - -for (i=0;i<20;i++) { tokens[i]=NULL; tokentypes[i]=ICONSOLE_VAR_NONE; }; -tokenstream_s=tokenstream=malloc(1024); -memset(tokenstream,0,1024); - -//** parsing **// - -longtoken=false; -valid_token=false; -skip_lt_change=false; -l=strlen((char *) cmdstr); -i=0; -c=0; -tokens[c] = tokenstream; -while (i<l) { - if (cmdstr[i]=='"') { - if (longtoken) { - if (cmdstr[i+1]=='"') { - i++; - *tokenstream = '"'; - tokenstream++; - skip_lt_change=true; +bool IConsoleVarHookHandle(_iconsole_var * hook_var, byte type) +{ + bool (*proc)(_iconsole_var * hook_var); + switch (type) { + case ICONSOLE_HOOK_BEFORE_CHANGE: + proc = hook_var->hook_before_change; + break; + case ICONSOLE_HOOK_AFTER_CHANGE: + proc = hook_var->hook_after_change; + break; + case ICONSOLE_HOOK_ACCESS: + proc = hook_var->hook_access; + break; + } + if (proc == NULL) return true; + return proc(hook_var); +} + +void IConsoleCmdHook(byte * name, byte type, void * proc) +{ + _iconsole_cmd * hook_cmd; + hook_cmd = IConsoleCmdGet(name); + if (hook_cmd == NULL) return; + switch (type) { + case ICONSOLE_HOOK_AFTER_EXEC: + hook_cmd->hook_after_exec = proc; + break; + case ICONSOLE_HOOK_BEFORE_EXEC: + hook_cmd->hook_before_exec = proc; + break; + case ICONSOLE_HOOK_ACCESS: + hook_cmd->hook_access = proc; + break; + } +} + +bool IConsoleCmdHookHandle(_iconsole_cmd * hook_cmd, byte type) +{ + bool (*proc)(_iconsole_cmd * hook_cmd); + switch (type) { + case ICONSOLE_HOOK_AFTER_EXEC: + proc = hook_cmd->hook_after_exec; + break; + case ICONSOLE_HOOK_BEFORE_EXEC: + proc = hook_cmd->hook_before_exec; + break; + case ICONSOLE_HOOK_ACCESS: + proc = hook_cmd->hook_access; + break; + } + if (proc == NULL) return true; + return proc(hook_cmd); +} + +void IConsoleCmdExec(byte * cmdstr) +{ + _iconsole_var * (*function)(byte argc, byte* argv[], byte argt[]); + byte * tokens[20]; + byte tokentypes[20]; + byte * tokenstream; + byte * tokenstream_s; + byte execution_mode; + _iconsole_var * var = NULL; + _iconsole_var * result = NULL; + _iconsole_cmd * cmd = NULL; + + bool longtoken; + bool valid_token; + bool skip_lt_change; + + int c; + int i; + int l; + + //** clearing buffer **// + + for (i=0;i<20;i++) { tokens[i]=NULL; tokentypes[i]=ICONSOLE_VAR_NONE; }; + tokenstream_s=tokenstream=malloc(1024); + memset(tokenstream,0,1024); + + //** parsing **// + + longtoken=false; + valid_token=false; + skip_lt_change=false; + l=strlen((char *) cmdstr); + i=0; + c=0; + tokens[c] = tokenstream; + while (i<l) { + if (cmdstr[i]=='"') { + if (longtoken) { + if (cmdstr[i+1]=='"') { + i++; + *tokenstream = '"'; + tokenstream++; + skip_lt_change=true; + } else { + longtoken=!longtoken; + } } else { longtoken=!longtoken; } - } else { - longtoken=!longtoken; - } - if (!skip_lt_change) { - if (!longtoken) { - if (valid_token) { - c++; - *tokenstream = 0; - tokenstream++; - tokens[c] = tokenstream; - valid_token = false; + if (!skip_lt_change) { + if (!longtoken) { + if (valid_token) { + c++; + *tokenstream = 0; + tokenstream++; + tokens[c] = tokenstream; + valid_token = false; + } } + skip_lt_change=false; } - skip_lt_change=false; } - } - else if ((!longtoken) && (cmdstr[i]==' ')) { - if (valid_token) { - c++; - *tokenstream = 0; + else if ((!longtoken) && (cmdstr[i]==' ')) { + if (valid_token) { + c++; + *tokenstream = 0; + tokenstream++; + tokens[c] = tokenstream; + valid_token = false; + } + } + else { + valid_token=true; + *tokenstream = cmdstr[i]; tokenstream++; - tokens[c] = tokenstream; - valid_token = false; } + i++; } - else { - valid_token=true; - *tokenstream = cmdstr[i]; + + tokenstream--; + if (!(*tokenstream==0)) { + c++; tokenstream++; + *tokenstream = 0; } - i++; - } - -tokenstream--; -if (!(*tokenstream==0)) { - c++; - tokenstream++; - *tokenstream = 0; - } -//** interpreting **// + //** interpreting **// -for (i=0; i<c; i++) { - tokentypes[i]=ICONSOLE_VAR_UNKNOWN; - if (tokens[i]!=NULL) if (i>0) if (strlen((char *) tokens[i])>0) { - if (tokens[i][0]=='*') { - if ((i==2) && (tokentypes[1]==ICONSOLE_VAR_UNKNOWN) && (strcmp(tokens[1],"<<")==0)) { - // dont change the variable to an pointer if execution_mode 4 is being prepared - // this is used to assign one variable the value of the other one [token 0 and 2] - } else { - var = IConsoleVarGet(tokens[i]); - if (var!=NULL) { - tokens[i]=(byte *)var->addr; - tokentypes[i]=var->type; + for (i=0; i<c; i++) { + tokentypes[i]=ICONSOLE_VAR_UNKNOWN; + if (tokens[i]!=NULL) if (i>0) if (strlen((char *) tokens[i])>0) { + if (tokens[i][0]=='*') { + if ((i==2) && (tokentypes[1]==ICONSOLE_VAR_UNKNOWN) && (strcmp(tokens[1],"<<")==0)) { + // dont change the variable to an pointer if execution_mode 4 is being prepared + // this is used to assign one variable the value of the other one [token 0 and 2] + } else { + var = IConsoleVarGet(tokens[i]); + if (var!=NULL) { + tokens[i]=(byte *)var->addr; + tokentypes[i]=var->type; + } } } - } - if (tokens[i]!=NULL) if (tokens[i][0]=='@') if (tokens[i][1]=='*') { - var = IConsoleVarGet(tokens[i]+1); - if (var!=NULL) { - tokens[i]=(byte *)var; - tokentypes[i]=ICONSOLE_VAR_REFERENCE; + if (tokens[i]!=NULL) if (tokens[i][0]=='@') if (tokens[i][1]=='*') { + var = IConsoleVarGet(tokens[i]+1); + if (var!=NULL) { + tokens[i]=(byte *)var; + tokentypes[i]=ICONSOLE_VAR_REFERENCE; + } } } } - } -execution_mode=0; + execution_mode=0; -function = IConsoleCmdGetAddr(tokens[0]); -if (function != NULL) { - execution_mode=1; // this is a command - } else { - var = IConsoleVarGet(tokens[0]); - if (var != NULL) { - execution_mode=2; // this is a variable - if (c>2) if (strcmp(tokens[1],"<<")==0) { - // this is command to variable mode [normal] - function = IConsoleCmdGetAddr(tokens[2]); - if (function != NULL) { - execution_mode=3; - } else { - result = IConsoleVarGet(tokens[2]); - if (result != NULL) { - execution_mode=4; + function = NULL; + cmd = IConsoleCmdGet(tokens[0]); + if (cmd != NULL) function = cmd->addr; + + if (function != NULL) { + execution_mode=1; // this is a command + } else { + var = IConsoleVarGet(tokens[0]); + if (var != NULL) { + execution_mode=2; // this is a variable + if (c>2) if (strcmp(tokens[1],"<<")==0) { + // this is command to variable mode [normal] + + function = NULL; + cmd = IConsoleCmdGet(tokens[2]); + if (cmd != NULL) function = cmd->addr; + + if (function != NULL) { + execution_mode=3; + } else { + result = IConsoleVarGet(tokens[2]); + if (result != NULL) { + execution_mode=4; + } } } } } - } -//** executing **// -if (_stdlib_con_developer) IConsolePrintF(_iconsole_color_debug,"CONDEBUG: execution_mode: %i",execution_mode); -switch (execution_mode) { -case 0: - { - // not found - IConsoleError("command or variable not found"); - } - break; -case 1: - { - // execution with command syntax - result = function(c,tokens,tokentypes); - if (result!=NULL) { - IConsoleVarDump(result,"result"); - IConsoleVarFree(result); + //** executing **// + if (_stdlib_con_developer) IConsolePrintF(_iconsole_color_debug,"CONDEBUG: execution_mode: %i",execution_mode); + switch (execution_mode) { + case 0: + { + // not found + IConsoleError("command or variable not found"); } - } - break; -case 2: - { - // execution with variable syntax - if ((c==2) || (c==3)) { - // ** variable modifications ** // - switch (var->type) { - case ICONSOLE_VAR_BOOLEAN: - { - if (strcmp(tokens[1],"=")==0) { - if (c==3) { - *(bool *)var->addr=(atoi((char *) tokens[2])!=0); + break; + case 1: + if (IConsoleCmdHookHandle(cmd,ICONSOLE_HOOK_ACCESS)) { + // execution with command syntax + IConsoleCmdHookHandle(cmd,ICONSOLE_HOOK_BEFORE_EXEC); + result = function(c,tokens,tokentypes); + if (result!=NULL) { + IConsoleVarDump(result,"result"); + IConsoleVarFree(result); + } + IConsoleCmdHookHandle(cmd,ICONSOLE_HOOK_AFTER_EXEC); + } + break; + case 2: + { + // execution with variable syntax + if (IConsoleVarHookHandle(var,ICONSOLE_HOOK_ACCESS)) if ((c==2) || (c==3)) { + // ** variable modifications ** // + IConsoleVarHookHandle(var,ICONSOLE_HOOK_BEFORE_CHANGE); + switch (var->type) { + case ICONSOLE_VAR_BOOLEAN: + { + if (strcmp(tokens[1],"=")==0) { + if (c==3) { + *(bool *)var->addr=(atoi((char *) tokens[2])!=0); + IConsoleVarDump(var,NULL); + } else { + *(bool *)var->addr=false; + IConsoleVarDump(var,NULL); + } + } + else if (strcmp(tokens[1],"++")==0) { + *(bool *)var->addr=!*(bool *)var->addr; IConsoleVarDump(var,NULL); - } else { - *(bool *)var->addr=false; + } + else if (strcmp(tokens[1],"--")==0) { + *(bool *)var->addr=!*(bool *)var->addr; IConsoleVarDump(var,NULL); } + else { IConsoleError("operation not supported"); } } - else if (strcmp(tokens[1],"++")==0) { - *(bool *)var->addr=!*(bool *)var->addr; - IConsoleVarDump(var,NULL); - } - else if (strcmp(tokens[1],"--")==0) { - *(bool *)var->addr=!*(bool *)var->addr; - IConsoleVarDump(var,NULL); - } - else { IConsoleError("operation not supported"); } - } - break; - case ICONSOLE_VAR_BYTE: - { - if (strcmp(tokens[1],"=")==0) { - if (c==3) { - *(byte *)var->addr=atoi((char *) tokens[2]); + break; + case ICONSOLE_VAR_BYTE: + { + if (strcmp(tokens[1],"=")==0) { + if (c==3) { + *(byte *)var->addr=atoi((char *) tokens[2]); + IConsoleVarDump(var,NULL); + } else { + *(byte *)var->addr=0; + IConsoleVarDump(var,NULL); + } + } + else if (strcmp(tokens[1],"++")==0) { + (*(byte *)var->addr)++; IConsoleVarDump(var,NULL); - } else { - *(byte *)var->addr=0; + } + else if (strcmp(tokens[1],"--")==0) { + (*(byte *)var->addr)--; IConsoleVarDump(var,NULL); } + else { IConsoleError("operation not supported"); } } - else if (strcmp(tokens[1],"++")==0) { - (*(byte *)var->addr)++; - IConsoleVarDump(var,NULL); - } - else if (strcmp(tokens[1],"--")==0) { - (*(byte *)var->addr)--; - IConsoleVarDump(var,NULL); - } - else { IConsoleError("operation not supported"); } - } - break; - case ICONSOLE_VAR_UINT16: - { - if (strcmp(tokens[1],"=")==0) { - if (c==3) { - *(unsigned short *)var->addr=atoi((char *) tokens[2]); + break; + case ICONSOLE_VAR_UINT16: + { + if (strcmp(tokens[1],"=")==0) { + if (c==3) { + *(unsigned short *)var->addr=atoi((char *) tokens[2]); + IConsoleVarDump(var,NULL); + } else { + *(unsigned short *)var->addr=0; + IConsoleVarDump(var,NULL); + } + } + else if (strcmp(tokens[1],"++")==0) { + (*(unsigned short *)var->addr)++; IConsoleVarDump(var,NULL); - } else { - *(unsigned short *)var->addr=0; + } + else if (strcmp(tokens[1],"--")==0) { + (*(unsigned short *)var->addr)--; IConsoleVarDump(var,NULL); } + else { IConsoleError("operation not supported"); } } - else if (strcmp(tokens[1],"++")==0) { - (*(unsigned short *)var->addr)++; - IConsoleVarDump(var,NULL); - } - else if (strcmp(tokens[1],"--")==0) { - (*(unsigned short *)var->addr)--; - IConsoleVarDump(var,NULL); - } - else { IConsoleError("operation not supported"); } - } - break; - case ICONSOLE_VAR_UINT32: - { - if (strcmp(tokens[1],"=")==0) { - if (c==3) { - *(unsigned int *)var->addr=atoi((char *) tokens[2]); + break; + case ICONSOLE_VAR_UINT32: + { + if (strcmp(tokens[1],"=")==0) { + if (c==3) { + *(unsigned int *)var->addr=atoi((char *) tokens[2]); + IConsoleVarDump(var,NULL); + } else { + *(unsigned int *)var->addr=0; + IConsoleVarDump(var,NULL); + } + } + else if (strcmp(tokens[1],"++")==0) { + (*(unsigned int *)var->addr)++; IConsoleVarDump(var,NULL); - } else { - *(unsigned int *)var->addr=0; + } + else if (strcmp(tokens[1],"--")==0) { + (*(unsigned int *)var->addr)--; IConsoleVarDump(var,NULL); } + else { IConsoleError("operation not supported"); } } - else if (strcmp(tokens[1],"++")==0) { - (*(unsigned int *)var->addr)++; - IConsoleVarDump(var,NULL); - } - else if (strcmp(tokens[1],"--")==0) { - (*(unsigned int *)var->addr)--; - IConsoleVarDump(var,NULL); - } - else { IConsoleError("operation not supported"); } - } - break; - case ICONSOLE_VAR_INT16: - { - if (strcmp(tokens[1],"=")==0) { - if (c==3) { - *(signed short *)var->addr=atoi((char *) tokens[2]); + break; + case ICONSOLE_VAR_INT16: + { + if (strcmp(tokens[1],"=")==0) { + if (c==3) { + *(signed short *)var->addr=atoi((char *) tokens[2]); + IConsoleVarDump(var,NULL); + } else { + *(signed short *)var->addr=0; + IConsoleVarDump(var,NULL); + } + } + else if (strcmp(tokens[1],"++")==0) { + (*(signed short *)var->addr)++; IConsoleVarDump(var,NULL); - } else { - *(signed short *)var->addr=0; + } + else if (strcmp(tokens[1],"--")==0) { + (*(signed short *)var->addr)--; IConsoleVarDump(var,NULL); } + else { IConsoleError("operation not supported"); } } - else if (strcmp(tokens[1],"++")==0) { - (*(signed short *)var->addr)++; - IConsoleVarDump(var,NULL); - } - else if (strcmp(tokens[1],"--")==0) { - (*(signed short *)var->addr)--; - IConsoleVarDump(var,NULL); - } - else { IConsoleError("operation not supported"); } - } - break; - case ICONSOLE_VAR_INT32: - { - if (strcmp(tokens[1],"=")==0) { - if (c==3) { - *(signed int *)var->addr=atoi((char *) tokens[2]); + break; + case ICONSOLE_VAR_INT32: + { + if (strcmp(tokens[1],"=")==0) { + if (c==3) { + *(signed int *)var->addr=atoi((char *) tokens[2]); + IConsoleVarDump(var,NULL); + } else { + *(signed int *)var->addr=0; + IConsoleVarDump(var,NULL); + } + } + else if (strcmp(tokens[1],"++")==0) { + (*(signed int *)var->addr)++; IConsoleVarDump(var,NULL); - } else { - *(signed int *)var->addr=0; + } + else if (strcmp(tokens[1],"--")==0) { + (*(signed int *)var->addr)--; IConsoleVarDump(var,NULL); } + else { IConsoleError("operation not supported"); } } - else if (strcmp(tokens[1],"++")==0) { - (*(signed int *)var->addr)++; - IConsoleVarDump(var,NULL); - } - else if (strcmp(tokens[1],"--")==0) { - (*(signed int *)var->addr)--; - IConsoleVarDump(var,NULL); - } - else { IConsoleError("operation not supported"); } - } - break; - case ICONSOLE_VAR_STRING: - { - if (strcmp(tokens[1],"=")==0) { - if (c==3) { - IConsoleVarSetString(var, tokens[2]); - IConsoleVarDump(var,NULL); - } else { - IConsoleVarSetString(var, ""); - IConsoleVarDump(var,NULL); + break; + case ICONSOLE_VAR_STRING: + { + if (strcmp(tokens[1],"=")==0) { + if (c==3) { + IConsoleVarSetString(var, tokens[2]); + IConsoleVarDump(var,NULL); + } else { + IConsoleVarSetString(var, ""); + IConsoleVarDump(var,NULL); + } } + else { IConsoleError("operation not supported"); } } - else { IConsoleError("operation not supported"); } - } - break; - case ICONSOLE_VAR_POINTER: - { - if (strcmp(tokens[1],"=")==0) { - if (c==3) { - if (tokentypes[2]==ICONSOLE_VAR_UNKNOWN) { - var->addr = (void *)atoi(tokens[2]); + break; + case ICONSOLE_VAR_POINTER: + { + if (strcmp(tokens[1],"=")==0) { + if (c==3) { + if (tokentypes[2]==ICONSOLE_VAR_UNKNOWN) { + var->addr = (void *)atoi(tokens[2]); + } else { + var->addr = (void *)tokens[2]; + } + IConsoleVarDump(var,NULL); } else { - var->addr = (void *)tokens[2]; + var->addr = NULL; + IConsoleVarDump(var,NULL); } + } + else if (strcmp(tokens[1],"++")==0) { + var->addr = ((char *)var->addr)+1; IConsoleVarDump(var,NULL); - } else { - var->addr = NULL; + } + else if (strcmp(tokens[1],"--")==0) { + var->addr = ((char *)var->addr)-1;; IConsoleVarDump(var,NULL); } + else { IConsoleError("operation not supported"); } } - else if (strcmp(tokens[1],"++")==0) { - var->addr = ((char *)var->addr)+1; - IConsoleVarDump(var,NULL); - } - else if (strcmp(tokens[1],"--")==0) { - var->addr = ((char *)var->addr)-1;; - IConsoleVarDump(var,NULL); - } - else { IConsoleError("operation not supported"); } + break; } - break; + IConsoleVarHookHandle(var,ICONSOLE_HOOK_AFTER_CHANGE); + } + if (c==1) { + // ** variable output ** // + IConsoleVarDump(var,NULL); } - } - if (c==1) { - // ** variable output ** // - IConsoleVarDump(var,NULL); } - } - break; -case 3: -case 4: - { - // execute command with result or assign a variable - if (execution_mode==3) { - int i; - int diff; - void * temp; - byte temp2; - - // tokenshifting - for (diff=0; diff<2; diff++) { - temp=tokens[0]; - temp2=tokentypes[0]; - for (i=1; i<20; i++) { - tokens[i-1]=tokens[i]; - tokentypes[i-1]=tokentypes[i]; + break; + case 3: + case 4: + { + // execute command with result or assign a variable + if (execution_mode==3) if (IConsoleCmdHookHandle(cmd,ICONSOLE_HOOK_ACCESS)) { + int i; + int diff; + void * temp; + byte temp2; + + // tokenshifting + for (diff=0; diff<2; diff++) { + temp=tokens[0]; + temp2=tokentypes[0]; + for (i=1; i<20; i++) { + tokens[i-1]=tokens[i]; + tokentypes[i-1]=tokentypes[i]; + } + tokens[19]=temp; + tokentypes[19]=temp2; } - tokens[19]=temp; - tokentypes[19]=temp2; + IConsoleCmdHookHandle(cmd,ICONSOLE_HOOK_BEFORE_EXEC); + result = function(c,tokens,tokentypes); + IConsoleCmdHookHandle(cmd,ICONSOLE_HOOK_AFTER_EXEC); + } else { + execution_mode=255; } - result = function(c,tokens,tokentypes); - } - - if (result!=NULL) { - if (result ->type != var -> type) { - IConsoleError("variable type missmatch"); - } else { - switch (result->type) { - case ICONSOLE_VAR_BOOLEAN: - { - (*(bool *)var->addr)=(*(bool *)result->addr); - IConsoleVarDump(var,NULL); - } - break; - case ICONSOLE_VAR_BYTE: - { - (*(byte *)var->addr)=(*(byte *)result->addr); - IConsoleVarDump(var,NULL); - } - break; - case ICONSOLE_VAR_UINT16: - { - (*(unsigned short *)var->addr)=(*(unsigned short *)result->addr); - IConsoleVarDump(var,NULL); - } - break; - case ICONSOLE_VAR_UINT32: - { - (*(unsigned int *)var->addr)=(*(unsigned int *)result->addr); - IConsoleVarDump(var,NULL); - } - break; - case ICONSOLE_VAR_INT16: - { - (*(signed short *)var->addr)=(*(signed short *)result->addr); - IConsoleVarDump(var,NULL); - } - break; - case ICONSOLE_VAR_INT32: - { - (*(signed int *)var->addr)=(*(signed int *)result->addr); - IConsoleVarDump(var,NULL); - } - break; - case ICONSOLE_VAR_POINTER: - { - var->addr=result->addr; - IConsoleVarDump(var,NULL); - } - break; - case ICONSOLE_VAR_STRING: - { - IConsoleVarSetString(var,result->addr); - IConsoleVarDump(var,NULL); - } - break; - default: - { + if (IConsoleVarHookHandle(var,ICONSOLE_HOOK_ACCESS)) if (result!=NULL) { + if (result ->type != var -> type) { IConsoleError("variable type missmatch"); + } else { + IConsoleVarHookHandle(var,ICONSOLE_HOOK_BEFORE_CHANGE); + switch (result->type) { + case ICONSOLE_VAR_BOOLEAN: + { + (*(bool *)var->addr)=(*(bool *)result->addr); + IConsoleVarDump(var,NULL); + } + break; + case ICONSOLE_VAR_BYTE: + { + (*(byte *)var->addr)=(*(byte *)result->addr); + IConsoleVarDump(var,NULL); + } + break; + case ICONSOLE_VAR_UINT16: + { + (*(unsigned short *)var->addr)=(*(unsigned short *)result->addr); + IConsoleVarDump(var,NULL); + } + break; + case ICONSOLE_VAR_UINT32: + { + (*(unsigned int *)var->addr)=(*(unsigned int *)result->addr); + IConsoleVarDump(var,NULL); + } + break; + case ICONSOLE_VAR_INT16: + { + (*(signed short *)var->addr)=(*(signed short *)result->addr); + IConsoleVarDump(var,NULL); + } + break; + case ICONSOLE_VAR_INT32: + { + (*(signed int *)var->addr)=(*(signed int *)result->addr); + IConsoleVarDump(var,NULL); + } + break; + case ICONSOLE_VAR_POINTER: + { + var->addr=result->addr; + IConsoleVarDump(var,NULL); + } + break; + case ICONSOLE_VAR_STRING: + { + IConsoleVarSetString(var,result->addr); + IConsoleVarDump(var,NULL); + } + break; + default: + { + IConsoleError("variable type missmatch"); + } + break; + } + IConsoleVarHookHandle(var,ICONSOLE_HOOK_AFTER_CHANGE); } - break; - } - } - - if (execution_mode==3) { - IConsoleVarFree(result); - result = NULL; - } - } - - } - break; -default: - { - // execution mode invalid - IConsoleError("invalid execution mode"); - } -} - -//** freeing the tokens **// -for (i=0;i<20;i++) tokens[i]=NULL; -free(tokenstream_s); - -} - -/* **************************** */ -/* default console commands */ -/* **************************** */ - - -static _iconsole_var * IConsoleStdLibEcho(byte argc, byte* argv[], byte argt[]) { - if (argc<2) return NULL; - IConsolePrint(_iconsole_color_default, argv[1]); - return NULL; -} - -static _iconsole_var * IConsoleStdLibEchoC(byte argc, byte* argv[], byte argt[]) { - if (argc<3) return NULL; - IConsolePrint(atoi(argv[1]), argv[2]); - return NULL; -} - -static _iconsole_var * IConsoleStdLibPrintF(byte argc, byte* argv[], byte argt[]) { - if (argc<3) return NULL; - IConsolePrintF(_iconsole_color_default, argv[1] ,argv[2],argv[3],argv[4],argv[5],argv[6],argv[7],argv[8],argv[9],argv[10],argv[11],argv[12],argv[13],argv[14],argv[15],argv[16],argv[17],argv[18],argv[19]); - return NULL; -} - -static _iconsole_var * IConsoleStdLibPrintFC(byte argc, byte* argv[], byte argt[]) { - if (argc<3) return NULL; - IConsolePrintF(atoi(argv[1]), argv[2] ,argv[3],argv[4],argv[5],argv[6],argv[7],argv[8],argv[9],argv[10],argv[11],argv[12],argv[13],argv[14],argv[15],argv[16],argv[17],argv[18],argv[19]); - return NULL; -} -static _iconsole_var * IConsoleStdLibScreenShot(byte argc, byte* argv[], byte argt[]) { - - if (argc<2) { - _make_screenshot=1; - } else { - if (strcmp(argv[1],"big")==0) { - _make_screenshot=2; - } - if (strcmp(argv[1],"no_con")==0) { - IConsoleClose(); - _make_screenshot=1; + if (execution_mode==3) { + IConsoleVarFree(result); + result = NULL; + } } - } - -return NULL; -} - -static _iconsole_var * IConsoleStdLibVarInfo(byte argc, byte* argv[], byte argt[]) { -if (argc<2) return NULL; -if (argt[1]!=ICONSOLE_VAR_REFERENCE) { - IConsoleError("variable must be an variable reference"); - } else { - _iconsole_var * item; - item = (_iconsole_var *) argv[1]; - IConsolePrintF(_iconsole_color_default,"variable_name: %s",item->name); - IConsolePrintF(_iconsole_color_default,"variable_type: %i",item->type); - IConsolePrintF(_iconsole_color_default,"variable_addr: %i",item->addr); - if (item->_malloc) IConsolePrintF(_iconsole_color_default,"variable_malloc: internal allocated"); else IConsolePrintF(_iconsole_color_default, "variable_malloc: external allocated"); - } -return NULL; -} - -static _iconsole_var * IConsoleStdLibDebugLevel(byte argc, byte* argv[], byte argt[]) { - if (argc<2) return NULL; - SetDebugString(argv[1]); - return NULL; -} - -static _iconsole_var * IConsoleStdLibExit(byte argc, byte* argv[], byte argt[]) { - _exit_game = true; - return NULL; -} - -static _iconsole_var * IConsoleStdLibHelp(byte argc, byte* argv[], byte argt[]) { - IConsolePrint(13 ," -- console help -- "); - IConsolePrint(1 ," variables: [command to list them: list_vars]"); - IConsolePrint(1 ," *temp_string = \"my little \""); - IConsolePrint(1 ,""); - IConsolePrint(1 ," commands: [command to list them: list_cmds]"); - IConsolePrint(1 ," [command] [\"string argument with spaces\"] [argument 2] ..."); - IConsolePrint(1 ," printf \"%s world\" *temp_string"); - IConsolePrint(1 ,""); - IConsolePrint(1 ," command/variable returning a value into an variable:"); - IConsolePrint(1 ," *temp_uint16 << random"); - IConsolePrint(1 ," *temp_uint16 << *temp_uint16_2"); - IConsolePrint(1 ,""); -return NULL; -} - -static _iconsole_var * IConsoleStdLibRandom(byte argc, byte* argv[], byte argt[]) { -_iconsole_var * result; -result = IConsoleVarAlloc(ICONSOLE_VAR_UINT16); -IConsoleVarSetValue(result,rand()); -return result; -} - -static _iconsole_var * IConsoleStdLibListCommands(byte argc, byte* argv[], byte argt[]) { -_iconsole_cmd * item; -int l = 0; - -if (argv[1]!=NULL) l = strlen((char *) argv[1]); - -item = _iconsole_cmds; -while (item != NULL) { - if (argv[1]!=NULL) { - - if (memcmp((void *) item->name, (void *) argv[1],l)==0) - IConsolePrintF(_iconsole_color_default,"%s",item->name); - - } else { - - IConsolePrintF(_iconsole_color_default,"%s",item->name); } - item = item->_next; - } - -return NULL; -} - -static _iconsole_var * IConsoleStdLibListVariables(byte argc, byte* argv[], byte argt[]) { -_iconsole_var * item; -int l = 0; - -if (argv[1]!=NULL) l = strlen((char *) argv[1]); - -item = _iconsole_vars; -while (item != NULL) { - if (argv[1]!=NULL) { - - if (memcmp((void *) item->name, (void *) argv[1],l)==0) - IConsolePrintF(_iconsole_color_default,"%s",item->name); - - } else { - - IConsolePrintF(_iconsole_color_default,"%s",item->name); - - } - item = item->_next; - } - -return NULL; -} - -static _iconsole_var * IConsoleStdLibListDumpVariables(byte argc, byte* argv[], byte argt[]) { -_iconsole_var * item; -int l = 0; - -if (argv[1]!=NULL) l = strlen((char *) argv[1]); - -item = _iconsole_vars; -while (item != NULL) { - if (argv[1]!=NULL) { - - if (memcmp((void *) item->name, (void *) argv[1],l)==0) - IConsoleVarDump(item,NULL); - - } else { - - IConsoleVarDump(item,NULL); - + break; + default: + { + // execution mode invalid + IConsoleError("invalid execution mode"); } - item = item->_next; } -return NULL; -} + //** freeing the tokens **// + for (i=0;i<20;i++) tokens[i]=NULL; + free(tokenstream_s); -static void IConsoleStdLibRegister() { - // functions - IConsoleCmdRegister("debug_level",IConsoleStdLibDebugLevel); - IConsoleCmdRegister("dump_vars",IConsoleStdLibListDumpVariables); - IConsoleCmdRegister("echo",IConsoleStdLibEcho); - IConsoleCmdRegister("echoc",IConsoleStdLibEchoC); - IConsoleCmdRegister("exit",IConsoleStdLibExit); - IConsoleCmdRegister("help",IConsoleStdLibHelp); - IConsoleCmdRegister("printf",IConsoleStdLibPrintF); - IConsoleCmdRegister("printfc",IConsoleStdLibPrintFC); - IConsoleCmdRegister("quit",IConsoleStdLibExit); - IConsoleCmdRegister("random",IConsoleStdLibRandom); - IConsoleCmdRegister("list_cmds",IConsoleStdLibListCommands); - IConsoleCmdRegister("list_vars",IConsoleStdLibListVariables); - IConsoleCmdRegister("screenshot",IConsoleStdLibScreenShot); - IConsoleCmdRegister("varinfo",IConsoleStdLibVarInfo); - IConsoleCmdRegister("resetengines",IConsoleResetEngines); - - // variables - IConsoleVarRegister("cursor_rate",(void *) &_icursor_rate,ICONSOLE_VAR_BYTE); - IConsoleVarRegister("con_developer",(void *) &_stdlib_con_developer,ICONSOLE_VAR_BOOLEAN); - IConsoleVarRegister("developer",(void *) &_stdlib_developer,ICONSOLE_VAR_BYTE); -#if defined(_DEBUG) - { - _iconsole_var * var; - var = IConsoleVarAlloc(ICONSOLE_VAR_BOOLEAN); - IConsoleVarInsert(var,"temp_bool"); - - var = IConsoleVarAlloc(ICONSOLE_VAR_INT16); - IConsoleVarInsert(var,"temp_int16"); - var = IConsoleVarAlloc(ICONSOLE_VAR_INT32); - IConsoleVarInsert(var,"temp_int32"); - - var = IConsoleVarAlloc(ICONSOLE_VAR_POINTER); - IConsoleVarInsert(var,"temp_pointer"); - - var = IConsoleVarAlloc(ICONSOLE_VAR_UINT16); - IConsoleVarInsert(var,"temp_uint16"); - var = IConsoleVarAlloc(ICONSOLE_VAR_UINT16); - IConsoleVarInsert(var,"temp_uint16_2"); - var = IConsoleVarAlloc(ICONSOLE_VAR_UINT32); - IConsoleVarInsert(var,"temp_uint32"); - - var = IConsoleVarAlloc(ICONSOLE_VAR_STRING); - IConsoleVarInsert(var,"temp_string"); - var = IConsoleVarAlloc(ICONSOLE_VAR_STRING); - IConsoleVarInsert(var,"temp_string2"); - } -#endif } - - @@ -1,5 +1,6 @@ #ifndef CONSOLE_H #define CONSOLE_H + // ** console ** // enum { @@ -20,14 +21,26 @@ enum { ICONSOLE_VAR_STRING, ICONSOLE_VAR_POINTER, ICONSOLE_VAR_REFERENCE, - ICONSOLE_VAR_UNKNOWN + ICONSOLE_VAR_UNKNOWN, } _iconsole_var_types; +enum { + ICONSOLE_HOOK_ACCESS, + ICONSOLE_HOOK_BEFORE_CHANGE, + ICONSOLE_HOOK_BEFORE_EXEC, + ICONSOLE_HOOK_AFTER_CHANGE, + ICONSOLE_HOOK_AFTER_EXEC, +} _iconsole_hook_types; + typedef struct { // -------------- // void * addr; byte * name; // -------------- // + void * hook_access; + void * hook_before_exec; + void * hook_after_exec; + // -------------- // void * _next; } _iconsole_cmd; @@ -37,10 +50,19 @@ typedef struct { byte * name; byte type; // -------------- // + void * hook_access; + void * hook_before_change; + void * hook_after_change; + // -------------- // void * _next; bool _malloc; } _iconsole_var; +// ** console parser ** // + +_iconsole_cmd * _iconsole_cmds; // list of registred commands +_iconsole_var * _iconsole_vars; // list of registred vars + // ** console colors ** // VARDEF byte _iconsole_color_default; VARDEF byte _iconsole_color_error; @@ -48,6 +70,7 @@ VARDEF byte _iconsole_color_debug; VARDEF byte _iconsole_color_commands; // ** ttd.c functions ** // + void SetDebugString(const char *s); // ** console functions ** // @@ -79,6 +102,7 @@ void* IConsoleCmdGetAddr(byte * name); // *** Variables *** // void IConsoleVarRegister(byte * name, void * addr, byte type); +void IConsoleVarMemRegister(byte * name, byte type); void IConsoleVarInsert(_iconsole_var * var, byte * name); _iconsole_var * IConsoleVarGet(byte * name); _iconsole_var * IConsoleVarAlloc(byte type); @@ -91,6 +115,14 @@ void IConsoleVarDump(_iconsole_var * var, byte * dump_desc); void IConsoleCmdExec(byte * cmdstr); -#include "console_cmds.h" +// ** console std lib ** // +void IConsoleStdLibRegister(); + +// ** hook code ** // +void IConsoleVarHook(byte * name, byte type, void * proc); +void IConsoleCmdHook(byte * name, byte type, void * proc); +bool IConsoleVarHookHandle(_iconsole_var * hook_var, byte type); +bool IConsoleCmdHookHandle(_iconsole_cmd * hook_cmd, byte type); + #endif /* CONSOLE_H */ diff --git a/console_cmds.c b/console_cmds.c new file mode 100644 index 000000000..9fc239d89 --- /dev/null +++ b/console_cmds.c @@ -0,0 +1,387 @@ +/* -------------------- dont cross this line --------------------- */
+#include "stdafx.h"
+#include "ttd.h"
+#include "console.h"
+#include "engine.h"
+#include "functions.h"
+#include "variables.h"
+
+#if defined(WIN32)
+# define ENABLE_NETWORK
+#endif
+
+// ** 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)
+
+static int32 GetArgumentInteger(byte *arg)
+{
+ int32 result;
+ sscanf((char *)arg, "%u", &result);
+
+ if (result == 0 && arg[0] == '0' && arg[1] == 'x')
+ sscanf((char *)arg, "%x", &result);
+
+ return result;
+}
+
+/* **************************** */
+/* variable and command hooks */
+/* **************************** */
+
+DEF_CONSOLE_CMD_HOOK(ConCmdHookNoNetwork)
+{
+ if (_networking) {
+ IConsoleError("this command is forbidden in multiplayer");
+ return false;
+ }
+ return true;
+}
+
+DEF_CONSOLE_VAR_HOOK(ConVarHookNoNetwork)
+{
+ if (_networking) {
+ IConsoleError("this variable is forbidden in multiplayer");
+ return false;
+ }
+ return true;
+}
+
+DEF_CONSOLE_VAR_HOOK(ConVarHookNoNetClient)
+{
+ if (!_networking_server) {
+ IConsoleError("this variable only makes sense for a network server");
+ return false;
+ }
+ return true;
+}
+
+/* **************************** */
+/* reset commands */
+/* **************************** */
+
+DEF_CONSOLE_CMD(ConResetEngines)
+{
+ StartupEngines();
+ return 0;
+}
+
+DEF_CONSOLE_CMD(ConResetTile)
+{
+ if (argc == 2) {
+ TileIndex tile = (TileIndex)GetArgumentInteger(argv[1]);
+ DoClearSquare(tile);
+ }
+
+ return 0;
+}
+
+DEF_CONSOLE_CMD(ConScrollToTile)
+{
+ if (argc == 2) {
+ TileIndex tile = (TileIndex)GetArgumentInteger(argv[1]);
+ ScrollMainWindowToTile(tile);
+ }
+
+ return 0;
+}
+
+// ********************************* //
+// * Network Core Console Commands * //
+// ********************************* //
+#ifdef ENABLE_NETWORK
+
+DEF_CONSOLE_CMD(ConNetworkConnect)
+{
+ byte * b;
+ byte * ip = NULL;
+ byte * port = NULL;
+ byte * player = NULL;
+ byte c;
+ uint16 rport;
+
+ if (argc<2) return NULL;
+
+ b = argv[1];
+ rport = _network_server_port;
+ c = 0;
+ ip = b;
+
+ while (b[c] != 0) {
+ if (((char)b[c]) == '#') {
+ player = &b[c+1];
+ b[c] = 0;
+ }
+ if (((char)b[c]) == ':') {
+ port = &b[c+1];
+ b[c] = 0;
+ }
+ c++;
+ }
+
+ IConsolePrintF(_iconsole_color_default,"Connecting to %s...",ip);
+ if (player!=NULL) {
+ _network_playas = atoi(player);
+ IConsolePrintF(_iconsole_color_default," player-no: %s",player);
+ }
+ if (port!=NULL) {
+ rport = atoi(port);
+ IConsolePrintF(_iconsole_color_default," port: %s",port);
+ }
+
+ NetworkCoreConnectGame(b, rport);
+
+ return NULL;
+}
+
+#endif
+
+/* **************************** */
+/* default console commands */
+/* **************************** */
+
+DEF_CONSOLE_CMD(ConEcho)
+{
+ if (argc<2) return NULL;
+ IConsolePrint(_iconsole_color_default, argv[1]);
+ return NULL;
+}
+
+DEF_CONSOLE_CMD(ConEchoC)
+{
+ if (argc<3) return NULL;
+ IConsolePrint(atoi(argv[1]), argv[2]);
+ return NULL;
+}
+
+DEF_CONSOLE_CMD(ConPrintF)
+{
+ if (argc<3) return NULL;
+ IConsolePrintF(_iconsole_color_default, argv[1] ,argv[2],argv[3],argv[4],argv[5],argv[6],argv[7],argv[8],argv[9],argv[10],argv[11],argv[12],argv[13],argv[14],argv[15],argv[16],argv[17],argv[18],argv[19]);
+ return NULL;
+}
+
+DEF_CONSOLE_CMD(ConPrintFC)
+{
+ if (argc<3) return NULL;
+ IConsolePrintF(atoi(argv[1]), argv[2] ,argv[3],argv[4],argv[5],argv[6],argv[7],argv[8],argv[9],argv[10],argv[11],argv[12],argv[13],argv[14],argv[15],argv[16],argv[17],argv[18],argv[19]);
+ return NULL;
+}
+
+DEF_CONSOLE_CMD(ConScreenShot)
+{
+ if (argc<2) {
+ _make_screenshot=1;
+ } else {
+ if (strcmp(argv[1],"big")==0) {
+ _make_screenshot=2;
+ }
+ if (strcmp(argv[1],"no_con")==0) {
+ IConsoleClose();
+ _make_screenshot=1;
+ }
+ }
+ return NULL;
+}
+
+DEF_CONSOLE_CMD(ConVarInfo)
+{
+ if (argc<2) return NULL;
+ if (argt[1]!=ICONSOLE_VAR_REFERENCE) {
+ IConsoleError("variable must be an variable reference");
+ } else {
+ _iconsole_var * item;
+ item = (_iconsole_var *) argv[1];
+ IConsolePrintF(_iconsole_color_default,"variable_name: %s",item->name);
+ IConsolePrintF(_iconsole_color_default,"variable_type: %i",item->type);
+ IConsolePrintF(_iconsole_color_default,"variable_addr: %i",item->addr);
+ if (item->_malloc) IConsolePrintF(_iconsole_color_default,"variable_malloc: internal allocated"); else IConsolePrintF(_iconsole_color_default, "variable_malloc: external allocated");
+ }
+ return NULL;
+}
+
+DEF_CONSOLE_CMD(ConDebugLevel)
+{
+ if (argc<2) return NULL;
+ SetDebugString(argv[1]);
+ return NULL;
+}
+
+DEF_CONSOLE_CMD(ConExit)
+{
+ _exit_game = true;
+ return NULL;
+}
+
+DEF_CONSOLE_CMD(ConHelp)
+{
+ IConsolePrint(13 ," -- console help -- ");
+ IConsolePrint(1 ," variables: [command to list them: list_vars]");
+ IConsolePrint(1 ," *temp_string = \"my little \"");
+ IConsolePrint(1 ,"");
+ IConsolePrint(1 ," commands: [command to list them: list_cmds]");
+ IConsolePrint(1 ," [command] [\"string argument with spaces\"] [argument 2] ...");
+ IConsolePrint(1 ," printf \"%s world\" *temp_string");
+ IConsolePrint(1 ,"");
+ IConsolePrint(1 ," command/variable returning a value into an variable:");
+ IConsolePrint(1 ," *temp_uint16 << random");
+ IConsolePrint(1 ," *temp_uint16 << *temp_uint16_2");
+ IConsolePrint(1 ,"");
+ return NULL;
+}
+
+DEF_CONSOLE_CMD(ConRandom)
+{
+ _iconsole_var * result;
+ result = IConsoleVarAlloc(ICONSOLE_VAR_UINT16);
+ IConsoleVarSetValue(result,rand());
+ return result;
+}
+
+DEF_CONSOLE_CMD(ConListCommands)
+{
+ _iconsole_cmd * item;
+ int l = 0;
+
+ if (argv[1]!=NULL) l = strlen((char *) argv[1]);
+
+ item = _iconsole_cmds;
+ while (item != NULL) {
+ if (argv[1]!=NULL) {
+
+ if (memcmp((void *) item->name, (void *) argv[1],l)==0)
+ IConsolePrintF(_iconsole_color_default,"%s",item->name);
+
+ } else {
+
+ IConsolePrintF(_iconsole_color_default,"%s",item->name);
+
+ }
+ item = item->_next;
+ }
+
+ return NULL;
+}
+
+DEF_CONSOLE_CMD(ConListVariables)
+{
+ _iconsole_var * item;
+ int l = 0;
+
+ if (argv[1]!=NULL) l = strlen((char *) argv[1]);
+
+ item = _iconsole_vars;
+ while (item != NULL) {
+ if (argv[1]!=NULL) {
+
+ if (memcmp((void *) item->name, (void *) argv[1],l)==0)
+ IConsolePrintF(_iconsole_color_default,"%s",item->name);
+
+ } else {
+
+ IConsolePrintF(_iconsole_color_default,"%s",item->name);
+
+ }
+ item = item->_next;
+ }
+
+ return NULL;
+}
+
+DEF_CONSOLE_CMD(ConListDumpVariables)
+{
+ _iconsole_var * item;
+ int l = 0;
+
+ if (argv[1]!=NULL) l = strlen((char *) argv[1]);
+
+ item = _iconsole_vars;
+ while (item != NULL) {
+ if (argv[1]!=NULL) {
+
+ if (memcmp((void *) item->name, (void *) argv[1],l)==0)
+ IConsoleVarDump(item,NULL);
+
+ } else {
+
+ IConsoleVarDump(item,NULL);
+
+ }
+ item = item->_next;
+ }
+
+ return NULL;
+}
+
+#ifdef _DEBUG
+/* ****************************************** */
+/* debug commands and variables */
+/* ****************************************** */
+
+void IConsoleDebugLibRegister()
+{
+ IConsoleVarMemRegister("temp_bool",ICONSOLE_VAR_BOOLEAN);
+ IConsoleVarMemRegister("temp_int16",ICONSOLE_VAR_INT16);
+ IConsoleVarMemRegister("temp_int32",ICONSOLE_VAR_INT32);
+ IConsoleVarMemRegister("temp_pointer",ICONSOLE_VAR_POINTER);
+ IConsoleVarMemRegister("temp_uint16",ICONSOLE_VAR_UINT16);
+ IConsoleVarMemRegister("temp_uint16_2",ICONSOLE_VAR_UINT16);
+ IConsoleVarMemRegister("temp_uint32",ICONSOLE_VAR_UINT32);
+ IConsoleVarMemRegister("temp_string",ICONSOLE_VAR_STRING);
+ IConsoleVarMemRegister("temp_string2",ICONSOLE_VAR_STRING);
+ IConsoleCmdRegister("resettile",ConResetTile);
+}
+#endif
+
+/* ****************************************** */
+/* console command and variable registration */
+/* ****************************************** */
+
+void IConsoleStdLibRegister()
+{
+ // stdlib
+ extern byte _stdlib_developer;
+ extern bool _stdlib_con_developer;
+
+#ifdef _DEBUG
+ IConsoleDebugLibRegister();
+#endif
+
+ // functions [please add them alphabeticaly]
+#ifdef ENABLE_NETWORK
+ IConsoleCmdRegister("connect",ConNetworkConnect);
+ IConsoleCmdHook("connect",ICONSOLE_HOOK_ACCESS,ConCmdHookNoNetwork);
+#endif
+ IConsoleCmdRegister("debug_level",ConDebugLevel);
+ IConsoleCmdRegister("dump_vars",ConListDumpVariables);
+ IConsoleCmdRegister("echo",ConEcho);
+ IConsoleCmdRegister("echoc",ConEchoC);
+ IConsoleCmdRegister("exit",ConExit);
+ IConsoleCmdRegister("help",ConHelp);
+ IConsoleCmdRegister("printf",ConPrintF);
+ IConsoleCmdRegister("printfc",ConPrintFC);
+ IConsoleCmdRegister("quit",ConExit);
+ IConsoleCmdRegister("random",ConRandom);
+ IConsoleCmdRegister("list_cmds",ConListCommands);
+ IConsoleCmdRegister("list_vars",ConListVariables);
+ IConsoleCmdRegister("resetengines",ConResetEngines);
+ IConsoleCmdHook("resetengines",ICONSOLE_HOOK_ACCESS,ConCmdHookNoNetwork);
+ IConsoleCmdRegister("screenshot",ConScreenShot);
+ IConsoleCmdRegister("scrollto",ConScrollToTile);
+ IConsoleCmdRegister("varinfo",ConVarInfo);
+
+ // 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);
+ IConsoleVarHook("*net_client_timeout",ICONSOLE_HOOK_ACCESS,ConVarHookNoNetClient);
+ IConsoleVarRegister("net_ready_ahead",&_network_ready_ahead,ICONSOLE_VAR_UINT16);
+ IConsoleVarRegister("net_sync_freq",&_network_sync_freq,ICONSOLE_VAR_UINT16);
+ IConsoleVarHook("*net_sync_freq",ICONSOLE_HOOK_ACCESS,ConVarHookNoNetClient);
+#endif
+
+
+}
+/* -------------------- dont cross this line --------------------- */
diff --git a/console_cmds.h b/console_cmds.h index 28346ac81..e69de29bb 100644 --- a/console_cmds.h +++ b/console_cmds.h @@ -1,13 +0,0 @@ -#ifndef CONSOLE_CMDS_H -#define CONSOLE_CMDS_H - -/* Console_CMDS.h is the placeholder of all the console commands - * that will be added to the game. Register the command in - * * console.c IConsoleStdLibRegister; - * then put the command in the appropiate place (eg. where it belongs, stations - * stuff in station_cmd.c, etc.), and add the function decleration here. - */ - -_iconsole_var * IConsoleResetEngines(byte argc, byte* argv[], byte argt[]); - -#endif /* CONSOLE_CMDS_H */ @@ -7,7 +7,6 @@ #include "vehicle.h" #include "news.h" #include "saveload.h" -#include "console.h" #define UPDATE_PLAYER_RAILTYPE(e,p) if ((byte)(e->railtype + 1) > p->max_railtype) p->max_railtype = e->railtype + 1; @@ -165,8 +164,6 @@ void StartupEngines() AdjustAvailAircraft(); } -_iconsole_var * IConsoleResetEngines(byte argc, byte* argv[], byte argt[]) {StartupEngines(); return 0;} - uint32 _engine_refit_masks[256]; @@ -202,8 +202,6 @@ static int _num_clients; // keep a history of the 16 most recent seeds to be able to capture out of sync errors. static uint32 _my_seed_list[16][2]; static bool _network_ready_sent; -static uint16 _network_ready_ahead = 1; -static uint16 _network_client_timeout; static uint32 _frame_fsync_last; typedef struct FutureSeeds { @@ -1348,28 +1346,6 @@ void NetworkStartSync(bool fcreset) memset(_my_seed_list, 0, sizeof(_my_seed_list)); } -// ********************************* // -// * Network Core Console Commands * // -// ********************************* // - -static _iconsole_var * NetworkConsoleCmdConnect(byte argc, byte* argv[], byte argt[]) -{ - if (argc<2) return NULL; - - if (argc == 2) { - IConsolePrintF(_iconsole_color_default, "connecting to %s",argv[1]); - NetworkCoreConnectGame(argv[1],_network_server_port); - } else if (argc == 3) { - IConsolePrintF(_iconsole_color_default, "connecting to %s on port %s",argv[1],argv[2]); - NetworkCoreConnectGame(argv[1],atoi(argv[2])); - } else if (argc == 4) { - IConsolePrintF(_iconsole_color_default, "connecting to %s on port %s as player %s",argv[1],argv[2],argv[3]); - _network_playas = atoi(argv[3]); - NetworkCoreConnectGame(argv[1],atoi(argv[2])); - } - return NULL; -} - // ************************** // // * UDP Network Extensions * // // ************************** // @@ -1587,8 +1563,9 @@ void NetworkIPListInit() void NetworkCoreInit() { DEBUG(net, 3) ("[NET][Core] init()"); - _network_available=true; - _network_client_timeout=300; + _network_available = true; + _network_client_timeout = 300; + _network_ready_ahead = 1; // [win32] winsock startup @@ -1644,10 +1621,6 @@ void NetworkCoreInit() DEBUG(net, 3) ("[NET][Core] OK: multiplayer available"); // initiate network ip list NetworkIPListInit(); - IConsoleCmdRegister("connect",NetworkConsoleCmdConnect); - IConsoleVarRegister("net_client_timeout",&_network_client_timeout,ICONSOLE_VAR_UINT16); - IConsoleVarRegister("net_ready_ahead",&_network_ready_ahead,ICONSOLE_VAR_UINT16); - IConsoleVarRegister("net_sync_freq",&_network_sync_freq,ICONSOLE_VAR_UINT16); } else DEBUG(net, 3) ("[NET][Core] FAILED: multiplayer not available"); } @@ -1938,6 +1911,7 @@ void NetworkGameListFromLAN() {}; void NetworkGameListFromInternet() {}; void NetworkGameFillDefaults() {}; NetworkGameList * NetworkGameListItem(uint16 index) {return NULL;}; +bool NetworkCoreConnectGameStruct(NetworkGameList * item) {return false;}; void NetworkGameChangeDate(uint16 newdate) {}; #endif diff --git a/ttd.vcproj b/ttd.vcproj index 364c67acd..cea1bef5e 100644 --- a/ttd.vcproj +++ b/ttd.vcproj @@ -296,6 +296,9 @@ RelativePath=".\console.c">
</File>
<File
+ RelativePath=".\console_cmds.c">
+ </File>
+ <File
RelativePath="economy.c">
<FileConfiguration
Name="Release|Win32">
@@ -1105,9 +1108,6 @@ RelativePath="console.h">
</File>
<File
- RelativePath=".\console_cmds.h">
- </File>
- <File
RelativePath="economy.h">
</File>
<File
diff --git a/variables.h b/variables.h index 26b133e8b..ae14c6136 100644 --- a/variables.h +++ b/variables.h @@ -231,6 +231,8 @@ VARDEF uint _network_server_port; VARDEF uint16 _network_sync_freq; VARDEF uint16 _network_ahead_frames; +VARDEF uint16 _network_ready_ahead; +VARDEF uint16 _network_client_timeout; VARDEF uint32 _sync_seed_1, _sync_seed_2; |