diff --git a/plugins/plugin.c b/plugins/plugin.c index 9ba2e1c00..a8e76f4ea 100644 --- a/plugins/plugin.c +++ b/plugins/plugin.c @@ -48,10 +48,24 @@ BUILTINR(int, Plug_ExportToEngine, (char *funcname, int expnum)); BUILTIN(void, Con_Print, (char *text)); //on to main console. #undef ARGNAMES +#define ARGNAMES ,conname,text +BUILTIN(void, Con_SubPrint, (char *conname, char *text)); //on to named sub console (creating it too). +#undef ARGNAMES + +#define ARGNAMES ,old,new +BUILTIN(void, Con_RenameSub, (char *old, char *new)); //on to named sub console (creating it too). +#undef ARGNAMES + #define ARGNAMES ,message BUILTIN(void, Sys_Error, (char *message)); //abort the entire engine. #undef ARGNAMES +#define ARGNAMES +BUILTINR(unsigned int, Sys_Milliseconds, (void)); //abort the entire engine. +#undef ARGNAMES +#define ARGNAMES ,buffer +BUILTIN(void, Cmd_AddCommand, (char *buffer)); //abort the entire engine. +#undef ARGNAMES #define ARGNAMES ,buffer,bufsize BUILTIN(void, Cmd_Args, (char *buffer, int bufsize)); //abort the entire engine. #undef ARGNAMES @@ -115,6 +129,10 @@ BUILTIN(void, Draw_Colour3f, (float r, float g, float b)); BUILTIN(void, Draw_Colour4f, (float r, float g, float b, float a)); #undef ARGNAMES +#define ARGNAMES ,src,srcwidth,srcheight,x,y,width,height +BUILTIN(void, Media_ShowFrameRGBA_32, (void *src, int srcwidth, int srcheight, int x, int y, int width, int height)); +#undef ARGNAMES + #define ARGNAMES ,mnum BUILTIN(void, Menu_Control, (int mnum)); #undef ARGNAMES @@ -123,6 +141,34 @@ BUILTIN(void, Menu_Control, (int mnum)); BUILTINR(int, Key_GetKeyCode, (char *keyname)); #undef ARGNAMES +#define ARGNAMES ,ip,port +BUILTINR(int, Net_TCPConnect, (char *ip, int port)); +#undef ARGNAMES +#define ARGNAMES ,ip,port,maxcount +BUILTINR(int, Net_TCPListen, (char *ip, int port, int maxcount)); +#undef ARGNAMES +#define ARGNAMES ,socket,address,addresslen +BUILTINR(int, Net_Accept, (int socket, char *address, int addresslen)); +#undef ARGNAMES +#define ARGNAMES ,socket,buffer,len +BUILTINR(int, Net_Recv, (int socket, void *buffer, int len)); +#undef ARGNAMES +#define ARGNAMES ,socket,buffer,len +BUILTINR(int, Net_Send, (int socket, void *buffer, int len)); +#undef ARGNAMES +#define ARGNAMES ,socket +BUILTIN(void, Net_Close, (int socket)); +#undef ARGNAMES + +#ifdef Q3_VM +#define ARGNAMES ,out,in,len +BUILTIN(void, memcpy, (void *out, void *in, int len)); +#undef ARGNAMES +#define ARGNAMES ,out,in,len +BUILTIN(void, memset, (void *out, int in, int len)); +#undef ARGNAMES +#endif + char *va(char *format, ...) //Identical in function to the one in Quake, though I can assure you that I wrote it... { //It's not exactly hard, just easy to use, so gets duplicated lots. va_list argptr; @@ -160,15 +206,24 @@ void Sys_Errorf(char *format, ...) void Plug_InitStandardBuiltins(void) { +#ifdef Q3_VM + CHECKBUILTIN(memcpy); + CHECKBUILTIN(memset); +#endif + CHECKBUILTIN(Plug_ExportToEngine); CHECKBUILTIN(Con_Print); CHECKBUILTIN(Sys_Error); + CHECKBUILTIN(Sys_Milliseconds); + //command execution + CHECKBUILTIN(Cmd_AddCommand); CHECKBUILTIN(Cmd_Args); CHECKBUILTIN(Cmd_Argv); CHECKBUILTIN(Cmd_Argc); CHECKBUILTIN(Cmd_AddText); + //cvar stuff CHECKBUILTIN(Cvar_SetString); CHECKBUILTIN(Cvar_SetFloat); CHECKBUILTIN(Cvar_GetString); @@ -176,11 +231,21 @@ void Plug_InitStandardBuiltins(void) CHECKBUILTIN(Cvar_Register); CHECKBUILTIN(Cvar_Update); + //networking + CHECKBUILTIN(Net_TCPConnect); + CHECKBUILTIN(Net_TCPListen); + CHECKBUILTIN(Net_Accept); + CHECKBUILTIN(Net_Recv); + CHECKBUILTIN(Net_Send); + CHECKBUILTIN(Net_Close); + + //random things CHECKBUILTIN(CL_GetStats); CHECKBUILTIN(LocalSound); CHECKBUILTIN(Menu_Control); CHECKBUILTIN(Key_GetKeyCode); + //drawing routines CHECKBUILTIN(Draw_LoadImage); CHECKBUILTIN(Draw_Image); CHECKBUILTIN(Draw_Fill); @@ -188,6 +253,13 @@ void Plug_InitStandardBuiltins(void) CHECKBUILTIN(Draw_Colourp); CHECKBUILTIN(Draw_Colour3f); CHECKBUILTIN(Draw_Colour4f); + + CHECKBUILTIN(Media_ShowFrameRGBA_32); + + //sub consoles (optional) + CHECKBUILTIN(Con_SubPrint); + CHECKBUILTIN(Con_RenameSub); + } #ifndef Q3_VM @@ -241,3 +313,6 @@ exports_t exports[sizeof(exports)/sizeof(exports[0])] = { {"Plug_Init", Plug_InitAPI}, }; + + + diff --git a/plugins/plugin.h b/plugins/plugin.h index 7ea79e3b7..8c53cae0c 100644 --- a/plugins/plugin.h +++ b/plugins/plugin.h @@ -1,3 +1,5 @@ +#ifndef __PLUGIN_H__ +#define __PLUGIN_H__ #ifdef Q3_VM //qvms just call the return value, and the engine works out which one it called. @@ -43,8 +45,12 @@ typedef void *qhandle_t; //Basic builtins: EBUILTIN(void*, Plug_GetEngineFunction, (char *funcname)); //set up in vmMain, use this to get all other builtins EBUILTIN(void, Con_Print, (char *text)); //on to main console. +EBUILTIN(void, Con_SubPrint, (char *subname, char *text)); //on to sub console. +EBUILTIN(void, Con_RenameSub, (char *old, char *new)); //rename a console. EBUILTIN(void, Sys_Error, (char *message)); //abort the entire engine. +EBUILTIN(unsigned int, Sys_Milliseconds, ()); +EBUILTIN(void, Cmd_AddCommand, (char *buffer)); //abort the entire engine. EBUILTIN(void, Cmd_Args, (char *buffer, int bufsize)); //abort the entire engine. EBUILTIN(void, Cmd_Argv, (int argnum, char *buffer, int bufsize)); //abort the entire engine. EBUILTIN(void, Cmd_Argc, (void)); //abort the entire engine. @@ -61,7 +67,10 @@ EBUILTIN(void, LocalSound, (char *soundname)); EBUILTIN(void, CL_GetStats, (int pnum, unsigned int *stats, int maxstats)); EBUILTIN(void, Menu_Control, (int mnum)); +#define MENU_CLEAR 0 +#define MENU_GRAB 1 EBUILTIN(int, Key_GetKeyCode, (char *keyname)); +EBUILTIN(void, Media_ShowFrameRGBA_32, (void *src, int srcwidth, int srcheight, int x, int y, int width, int height)); EBUILTIN(qhandle_t, Draw_LoadImage, (char *name, qboolean iswadimage)); //wad image is ONLY for loading out of q1 gfx.wad EBUILTIN(void, Draw_Image, (float x, float y, float w, float h, float s1, float t1, float s2, float t2, qhandle_t image)); @@ -71,6 +80,21 @@ EBUILTIN(void, Draw_Colourp, (int palcol)); EBUILTIN(void, Draw_Colour3f, (float r, float g, float b)); EBUILTIN(void, Draw_Colour4f, (float r, float g, float b, float a)); +EBUILTIN(int, Net_TCPConnect, (char *ip, int port)); +EBUILTIN(int, Net_TCPListen, (char *ip, int port, int maxcount)); +EBUILTIN(int, Net_Accept, (int socket, char *address, int addresssize)); +EBUILTIN(int, Net_Recv, (int socket, void *buffer, int len)); +EBUILTIN(int, Net_Send, (int socket, void *buffer, int len)); +EBUILTIN(void, Net_Close, (int socket)); +#define N_WOULDBLOCK -1 + + + +#ifdef Q3_VM +EBUILTIN(void, memcpy, (void *, void *, int len)); +EBUILTIN(void, memset, (void *, int, int len)); +#endif + typedef int (*export_t) (int *args); char *va(char *format, ...); int Plug_Init(int *args); @@ -78,6 +102,7 @@ qboolean Plug_Export(char *name, export_t func); void Con_Printf(char *format, ...); void Sys_Errorf(char *format, ...); typedef unsigned char qbyte; +void Q_strncpyz(char *d, const char *s, int n); typedef struct { @@ -118,3 +143,4 @@ void Info_RemoveNonStarKeys (char *start); void Info_SetValueForKey (char *s, char *key, char *value, int maxsize); void Info_SetValueForStarKey (char *s, char *key, char *value, int maxsize); +#endif diff --git a/plugins/qvm_api.c b/plugins/qvm_api.c index 4f54e0345..e46876738 100644 --- a/plugins/qvm_api.c +++ b/plugins/qvm_api.c @@ -136,7 +136,7 @@ retry: tokens++; break; case 'f': - _float = va_arg(vargs, double); + _float = (float)va_arg(vargs, double); //integer part. _int = (int)_float; @@ -149,10 +149,17 @@ retry: } i = sizeof(tempbuffer)-2; tempbuffer[sizeof(tempbuffer)-1] = '\0'; - while(_int) + if (!_int) { - tempbuffer[i--] = _int%10 + '0'; - _int/=10; + tempbuffer[i--] = '0'; + } + else + { + while(_int) + { + tempbuffer[i--] = _int%10 + '0'; + _int/=10; + } } string = tempbuffer+i+1; while (*string) @@ -289,3 +296,19 @@ char *strstr(char *str, char *sub) return NULL; } #endif + +void Q_strncpyz(char *d, const char *s, int n) +{ + int i; + n--; + if (n < 0) + return; //this could be an error + + for (i=0; *s; i++) + { + if (i == n) + break; + *d++ = *s++; + } + *d='\0'; +}