2005-07-20 11:50:00 +00:00
# ifndef __PLUGIN_H__
# define __PLUGIN_H__
2005-12-01 01:16:55 +00:00
2004-10-15 00:35:53 +00:00
# ifdef Q3_VM
2012-10-08 05:29:52 +00:00
typedef int qintptr_t ;
typedef unsigned int quintptr_t ;
2005-12-01 01:16:55 +00:00
# define TESTBI 1
# ifdef TESTBI
# define EBUILTIN(t, n, args) extern t (*n) args
# define BUILTINR(t, n, args) t (*n) args
# define BUILTIN(t, n, args) t (*n) args
# define BUILTINISVALID(n) (n!=NULL && (funcptr_t)n != (funcptr_t)&BadBuiltin)
# define CHECKBUILTIN(n) n = (funcptr_t)Plug_GetEngineFunction(#n);if (n==NULL) {n = (funcptr_t)&BadBuiltin;Con_Print("Warning: builtin "#n" is not supported by the engine\n");}
# else
2004-10-15 00:35:53 +00:00
//qvms just call the return value, and the engine works out which one it called.
2005-12-01 01:16:55 +00:00
# define EBUILTIN(t, n, args) extern t (*n) args
# define BUILTINR(t, n, args) t (*n) args
# define BUILTIN(t, n, args) t (*n) args
# define CHECKBUILTIN(n) n = (funcptr_t)Plug_GetEngineFunction(#n);
2005-12-15 18:52:03 +00:00
# define BUILTINISVALID(n) (n!=NULL)
2005-12-01 01:16:55 +00:00
# endif
2004-10-15 00:35:53 +00:00
# define double float //all floats are 32bit, qvm stuff
typedef char * va_list ;
# define va_start(va,f) (va = (char *)&f + sizeof(int))
# define va_arg(va, type) (*(type *)((va += sizeof(int)) - sizeof(int)))
# define va_end(va) (va = NULL)
# define NULL (void*)0
2005-11-27 01:12:16 +00:00
void * malloc ( int size ) ;
void free ( void * mem ) ;
char * strstr ( char * str , const char * sub ) ;
void strlcpy ( char * d , const char * s , int n ) ;
2005-11-27 03:18:43 +00:00
char * strchr ( char * str , char sub ) ;
2005-11-27 01:12:16 +00:00
2005-11-30 01:02:10 +00:00
float atof ( char * str ) ;
int atoi ( char * str ) ;
2005-12-06 15:40:52 +00:00
# define strcasecmp stricmp
2005-12-01 01:16:55 +00:00
void BadBuiltin ( void ) ;
2004-10-15 00:35:53 +00:00
# else
2005-12-06 15:40:52 +00:00
# define strcasecmp stricmp
2004-10-15 00:35:53 +00:00
# include <string.h>
# include <stdlib.h>
# include <stdarg.h>
2005-12-06 15:40:52 +00:00
# include "math.h"
2012-10-07 18:26:22 +00:00
2012-10-08 05:29:52 +00:00
# ifdef _WIN64
typedef long long qintptr_t ;
typedef unsigned long long quintptr_t ;
# else
typedef long qintptr_t ;
typedef unsigned long quintptr_t ;
# endif
# ifndef _WIN32
# define NATIVEEXPORT __attribute__((visibility("default")))
# endif
2012-10-07 18:26:22 +00:00
# ifdef __cplusplus
extern " C " {
# endif
2004-10-15 00:35:53 +00:00
//DLLs need a wrapper to add the extra parameter and call a boring function.
2012-10-08 05:29:52 +00:00
# define EBUILTIN(t, n, args) extern qintptr_t BUILTIN_##n; t n args
2005-12-01 01:16:55 +00:00
# define TEST
# ifdef TEST
2012-10-08 05:29:52 +00:00
# define BUILTINR(t, n, args) qintptr_t BUILTIN_##n; t n args {qintptr_t res; if (!BUILTINISVALID(n))Sys_Error("Builtin "#n" is not valid\n");res = plugin_syscall(BUILTIN_##n ARGNAMES); return *(t*)&res;}
# define BUILTIN(t, n, args) qintptr_t BUILTIN_##n; t n args {if (!BUILTINISVALID(n))Sys_Error("Builtin "#n" is not valid\n");plugin_syscall(BUILTIN_##n ARGNAMES);}
2005-12-01 01:16:55 +00:00
# else
2012-10-08 05:29:52 +00:00
# define BUILTINR(t, n, args) qintptr_t BUILTIN_##n; t n args {qintptr_t res = plugin_syscall(BUILTIN_##n ARGNAMES); return *(t*)&res;}
# define BUILTIN(t, n, args) qintptr_t BUILTIN_##n; t n args {plugin_syscall(BUILTIN_##n ARGNAMES);}
2005-12-01 01:16:55 +00:00
# endif
2012-10-08 05:29:52 +00:00
# define CHECKBUILTIN(n) BUILTIN_##n = (qintptr_t)Plug_GetEngineFunction(#n);
2005-12-15 18:52:03 +00:00
# define BUILTINISVALID(n) (BUILTIN_##n != 0)
2004-10-15 00:35:53 +00:00
# ifdef _WIN32
# define QDECL __cdecl
# else
# define QDECL
# endif
2012-10-08 05:29:52 +00:00
extern qintptr_t ( * plugin_syscall ) ( qintptr_t arg , . . . ) ;
2004-10-15 00:35:53 +00:00
2005-11-27 01:12:16 +00:00
# ifdef _WIN32
void strlcpy ( char * d , const char * s , int n ) ;
2012-04-23 05:07:40 +00:00
int snprintf ( char * buffer , size_t maxlen , const char * format , . . . ) ;
2005-11-27 01:12:16 +00:00
# endif
2004-10-15 00:35:53 +00:00
# endif
2012-10-08 05:29:52 +00:00
# ifndef NATIVEEXPORT
# define NATIVEEXPORT
# endif
2012-10-07 18:26:22 +00:00
# ifdef __cplusplus
typedef enum { qfalse , qtrue } qboolean ;
# else
typedef enum { qfalse , qtrue } qboolean ;
# define false qfalse
# define true qtrue
# endif
2004-10-15 00:35:53 +00:00
typedef void * qhandle_t ;
2005-11-27 01:12:16 +00:00
typedef float vec3_t [ 3 ] ;
2005-12-01 01:16:55 +00:00
typedef void * funcptr_t ;
2004-10-15 00:35:53 +00:00
2006-01-21 00:07:47 +00:00
# define PLUGMAX_SCOREBOARDNAME 64
typedef struct {
int topcolour ;
int bottomcolour ;
int frags ;
char name [ PLUGMAX_SCOREBOARDNAME ] ;
int ping ;
int pl ;
int starttime ;
int userid ;
int spectator ;
char userinfo [ 1024 ] ;
char team [ 8 ] ;
} plugclientinfo_t ;
2004-10-15 00:35:53 +00:00
//Basic builtins:
2012-10-08 05:29:52 +00:00
EBUILTIN ( funcptr_t , Plug_GetEngineFunction , ( const char * funcname ) ) ; //set up in vmMain, use this to get all other builtins
2012-04-23 05:07:40 +00:00
# ifndef Q3_VM
2012-10-08 05:29:52 +00:00
EBUILTIN ( qboolean , Plug_ExportNative , ( const char * funcname , void * func ) ) ; //set up in vmMain, use this to get all other builtins
2012-04-23 05:07:40 +00:00
# endif
2012-10-08 05:29:52 +00:00
EBUILTIN ( void , Con_Print , ( const char * text ) ) ; //on to main console.
2005-12-16 18:08:40 +00:00
2005-07-20 11:50:00 +00:00
EBUILTIN ( void , Con_SubPrint , ( char * subname , char * text ) ) ; //on to sub console.
2012-10-07 18:26:22 +00:00
EBUILTIN ( void , Con_RenameSub , ( char * oldname , char * newname ) ) ; //rename a console.
2005-12-16 18:08:40 +00:00
EBUILTIN ( int , Con_IsActive , ( char * conname ) ) ;
EBUILTIN ( void , Con_SetActive , ( char * conname ) ) ;
EBUILTIN ( void , Con_Destroy , ( char * conname ) ) ;
EBUILTIN ( void , Con_NameForNum , ( int connum , char * conname , int connamelen ) ) ;
2004-10-15 00:35:53 +00:00
EBUILTIN ( void , Sys_Error , ( char * message ) ) ; //abort the entire engine.
2005-07-20 11:50:00 +00:00
EBUILTIN ( unsigned int , Sys_Milliseconds , ( ) ) ;
2004-10-15 00:35:53 +00:00
2005-12-15 18:52:03 +00:00
EBUILTIN ( int , Cmd_AddCommand , ( char * buffer ) ) ; //abort the entire engine.
2004-10-15 00:35:53 +00:00
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.
2005-11-27 01:12:16 +00:00
EBUILTIN ( int , Cmd_Argc , ( void ) ) ; //abort the entire engine.
2004-10-15 00:35:53 +00:00
EBUILTIN ( void , Cmd_AddText , ( char * text , qboolean insert ) ) ;
2005-11-27 01:12:16 +00:00
EBUILTIN ( void , Cmd_Tokenize , ( char * msg ) ) ; //abort the entire engine.
2004-10-15 00:35:53 +00:00
EBUILTIN ( void , Cvar_SetString , ( char * name , char * value ) ) ;
EBUILTIN ( void , Cvar_SetFloat , ( char * name , float value ) ) ;
EBUILTIN ( qboolean , Cvar_GetString , ( char * name , char * retstring , int sizeofretstring ) ) ;
EBUILTIN ( float , Cvar_GetFloat , ( char * name ) ) ;
EBUILTIN ( qhandle_t , Cvar_Register , ( char * name , char * defaultval , int flags , char * grouphint ) ) ;
2005-11-27 01:12:16 +00:00
EBUILTIN ( int , Cvar_Update , ( qhandle_t handle , int * modificationcount , char * stringv , float * floatv ) ) ; //stringv is 256 chars long, don't expect this function to do anything if modification count is unchanged.
2004-10-15 00:35:53 +00:00
2005-12-15 18:52:03 +00:00
EBUILTIN ( void , GetPluginName , ( int plugnum , char * buffer , int bufsize ) ) ;
2004-10-15 00:35:53 +00:00
EBUILTIN ( void , LocalSound , ( char * soundname ) ) ;
EBUILTIN ( void , CL_GetStats , ( int pnum , unsigned int * stats , int maxstats ) ) ;
2006-01-21 00:07:47 +00:00
EBUILTIN ( int , GetPlayerInfo , ( int pnum , plugclientinfo_t * info ) ) ;
2009-04-19 01:46:52 +00:00
2007-09-17 20:54:26 +00:00
EBUILTIN ( int , LocalPlayerNumber , ( void ) ) ;
EBUILTIN ( void , GetServerInfo , ( char * info , int infolen ) ) ;
EBUILTIN ( void , SetUserInfo , ( char * key , char * value ) ) ;
2007-10-05 10:58:50 +00:00
EBUILTIN ( void , GetLocationName , ( float * pos , char * buffer , int bufferlen ) ) ;
2004-10-15 00:35:53 +00:00
EBUILTIN ( void , Menu_Control , ( int mnum ) ) ;
2005-07-20 11:50:00 +00:00
# define MENU_CLEAR 0
# define MENU_GRAB 1
2004-10-15 00:35:53 +00:00
EBUILTIN ( int , Key_GetKeyCode , ( char * keyname ) ) ;
EBUILTIN ( qhandle_t , Draw_LoadImage , ( char * name , qboolean iswadimage ) ) ; //wad image is ONLY for loading out of q1 gfx.wad
2006-02-11 13:48:31 +00:00
EBUILTIN ( int , Draw_Image , ( float x , float y , float w , float h , float s1 , float t1 , float s2 , float t2 , qhandle_t image ) ) ;
2006-01-13 06:11:47 +00:00
EBUILTIN ( void , Draw_Fill , ( float x , float y , float w , float h ) ) ;
2005-12-10 00:19:24 +00:00
EBUILTIN ( void , Draw_Line , ( float x1 , float y1 , float x2 , float y2 ) ) ;
2004-10-15 00:35:53 +00:00
EBUILTIN ( void , Draw_Character , ( int x , int y , unsigned int characture ) ) ;
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 ) ) ;
2005-11-27 01:12:16 +00:00
EBUILTIN ( void , SCR_CenterPrint , ( char * s ) ) ;
2004-10-15 00:35:53 +00:00
2009-04-19 01:46:52 +00:00
EBUILTIN ( int , ReadInputBuffer , ( void * inputbuffer , int buffersize ) ) ;
EBUILTIN ( int , UpdateInputBuffer , ( void * inputbuffer , int bytes ) ) ;
2005-12-06 15:40:52 +00:00
EBUILTIN ( int , FS_Open , ( char * name , qhandle_t * handle , int mode ) ) ;
EBUILTIN ( void , FS_Close , ( qhandle_t handle ) ) ;
EBUILTIN ( int , FS_Write , ( qhandle_t handle , void * data , int len ) ) ;
EBUILTIN ( int , FS_Read , ( qhandle_t handle , void * data , int len ) ) ;
EBUILTIN ( qhandle_t , Net_TCPConnect , ( char * ip , int port ) ) ;
EBUILTIN ( qhandle_t , Net_TCPListen , ( char * ip , int port , int maxcount ) ) ;
EBUILTIN ( qhandle_t , Net_Accept , ( qhandle_t socket , char * address , int addresssize ) ) ;
EBUILTIN ( int , Net_Recv , ( qhandle_t socket , void * buffer , int len ) ) ;
EBUILTIN ( int , Net_Send , ( qhandle_t socket , void * buffer , int len ) ) ;
EBUILTIN ( void , Net_Close , ( qhandle_t socket ) ) ;
2005-07-20 11:50:00 +00:00
# define N_WOULDBLOCK -1
2005-11-27 01:12:16 +00:00
# define NET_CLIENTPORT -1
# define NET_SERVERPORT -2
2005-07-20 11:50:00 +00:00
2009-04-19 01:46:52 +00:00
# if defined(_WIN32) || defined(Q3_VM)
2012-04-23 05:07:40 +00:00
int vsnprintf ( char * buffer , size_t maxlen , const char * format , va_list vargs ) ;
2009-04-19 01:46:52 +00:00
# endif
2005-07-20 11:50:00 +00:00
# ifdef Q3_VM
EBUILTIN ( void , memcpy , ( void * , void * , int len ) ) ;
2005-12-01 01:16:55 +00:00
EBUILTIN ( void , memmove , ( void * , void * , int len ) ) ;
2005-07-20 11:50:00 +00:00
EBUILTIN ( void , memset , ( void * , int , int len ) ) ;
2005-12-06 15:40:52 +00:00
EBUILTIN ( float , sqrt , ( float f ) ) ;
2005-12-10 00:19:24 +00:00
EBUILTIN ( float , cos , ( float f ) ) ;
EBUILTIN ( float , sin , ( float f ) ) ;
2005-07-20 11:50:00 +00:00
# endif
2012-10-08 05:29:52 +00:00
typedef qintptr_t ( * export_t ) ( qintptr_t * args ) ;
2004-10-15 00:35:53 +00:00
char * va ( char * format , . . . ) ;
2012-10-08 05:29:52 +00:00
qintptr_t Plug_Init ( qintptr_t * args ) ;
qboolean Plug_Export ( const char * name , export_t func ) ;
void Con_Printf ( const char * format , . . . ) ;
void Sys_Errorf ( const char * format , . . . ) ;
2004-10-15 00:35:53 +00:00
typedef unsigned char qbyte ;
2005-07-20 11:50:00 +00:00
void Q_strncpyz ( char * d , const char * s , int n ) ;
2004-10-15 00:35:53 +00:00
2009-04-19 01:46:52 +00:00
# define PLUG_SHARED_BEGIN(t,p,b) \
{ \
t * p ; \
char inputbuffer [ 8192 ] ; \
* ( b ) = ReadInputBuffer ( inputbuffer , sizeof ( inputbuffer ) ) ; \
if ( * ( b ) ) \
p = ( t * ) inputbuffer ; \
else \
p = NULL ;
# define PLUG_SHARED_END(p,b) UpdateInputBuffer(inputbuffer, b);}
2007-09-21 11:19:41 +00:00
//
// qvm_api.c
//
2012-04-23 05:07:40 +00:00
int vsnprintf ( char * buffer , size_t maxlen , const char * format , va_list vargs ) ;
2004-10-15 00:35:53 +00:00
typedef struct {
char * name ;
char string [ 256 ] ;
char * group ;
int flags ;
float value ;
qhandle_t handle ;
int modificationcount ;
} vmcvar_t ;
typedef struct {
int width ;
int height ;
} vmvideo_t ;
extern vmvideo_t vid ;
# define VMCvar_SetString(c,v) \
do { \
strcpy ( c - > string , v ) ; \
c - > value = ( float ) atof ( v ) ; \
Cvar_SetString ( c - > name , c - > string ) ; \
} while ( 0 )
# define VMCvar_SetFloat(c,v) \
do { \
snprintf ( c - > string , sizeof ( c - > string ) , " %f " , v ) ; \
c - > value = ( float ) ( v ) ; \
Cvar_SetFloat ( c - > name , c - > value ) ; \
} while ( 0 ) \
# define MAX_INFO_KEY 64
char * Info_ValueForKey ( char * s , char * key ) ;
void Info_RemoveKey ( char * s , char * key ) ;
void Info_RemovePrefixedKeys ( char * start , char prefix ) ;
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 ) ;
2012-10-07 18:26:22 +00:00
# ifdef __cplusplus
}
# endif
2005-07-20 11:50:00 +00:00
# endif