From 9af1ba84cc365dfa95f246c251d276cdfe81388d Mon Sep 17 00:00:00 2001 From: Spoike Date: Mon, 17 Sep 2007 20:35:39 +0000 Subject: [PATCH] A few things... f_ruleset stuff, 64bit qvm compatability, added cvars so you can put the built in http server on a custom port, added #warnings to annoy molgrum. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@2659 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/Makefile | 53 +- engine/client/cl_cam.c | 1 - engine/client/cl_cg.c | 138 ++-- engine/client/cl_main.c | 7 + engine/client/cl_parse.c | 34 +- engine/client/cl_plugin.inc | 48 +- engine/client/cl_ui.c | 162 +++-- engine/client/client.h | 5 +- engine/client/clq3_parse.c | 1 + engine/client/clq3defs.h | 8 - engine/client/valid.c | 1131 +++++++++--------------------- engine/common/bothdefs.h | 7 - engine/common/com_mesh.c | 6 +- engine/common/cvar.c | 52 +- engine/common/fs.c | 8 +- engine/common/plugin.c | 89 +-- engine/common/q3common.c | 48 ++ engine/common/ui_public.h | 8 +- engine/common/vm.h | 10 + engine/d3d/d3dquake.h | 12 +- engine/d3d/vid_d3d.c | 1 + engine/d3d9/d3d9_draw.c | 1 + engine/d3d9/d3d9_rmain.c | 1 + engine/d3d9/d3d9_rsurf.c | 1 + engine/d3d9/vid_d3d9.c | 5 +- engine/gl/gl_backend.c | 4 +- engine/gl/gl_draw.c | 2 + engine/http/ftpclient.c | 1 + engine/http/ftpserver.c | 7 +- engine/http/httpserver.c | 25 +- engine/http/iweb.h | 4 +- engine/http/iwebiface.c | 16 +- engine/http/webgen.c | 8 +- engine/libs/dxsdk7/include/d3d.h | 40 +- engine/qclib/hash.c | 32 +- engine/qclib/hash.h | 5 +- engine/server/pr_cmds.c | 11 +- engine/server/svq3_game.c | 91 ++- 38 files changed, 898 insertions(+), 1185 deletions(-) diff --git a/engine/Makefile b/engine/Makefile index 8950f5f84..2126a98b9 100644 --- a/engine/Makefile +++ b/engine/Makefile @@ -75,6 +75,8 @@ endif CLIENT_DIR=$(BASE_DIR)/client GL_DIR=$(BASE_DIR)/gl SW_DIR=$(BASE_DIR)/sw +D3D7_DIR=$(BASE_DIR)/d3d +D3D9_DIR=$(BASE_DIR)/d3d9 SERVER_DIR=$(BASE_DIR)/server COMMON_DIR=$(BASE_DIR)/common HTTP_DIR=$(BASE_DIR)/http @@ -111,10 +113,12 @@ ifeq ($(FTE_TARGET),bsd) endif BASELDFLAGS ?= -lm -ldl -lpthread +IMAGELDFLAGS=-lpng -ljpeg + #BASELDFLAGS=-lm -lz -GLXLDFLAGS=-L/usr/X11R6/lib -lX11 -lXext -lpng -ljpeg +GLXLDFLAGS=-L/usr/X11R6/lib -lX11 -lXext $(IMAGELDFLAGS) GLSLDFLAGS=-L/usr/X11R6/lib -lMesaGL -lglide -lvga -XLDFLAGS=-L/usr/X11R6/lib -lX11 -lXext -lpng -ljpeg +XLDFLAGS=-L/usr/X11R6/lib -lX11 -lXext $(IMAGELDFLAGS) SLDFLAGS=-lvga ifeq ($(USEASM),true) @@ -145,7 +149,7 @@ else BASE_ASM_CFLAGS = -DNOASM endif -BASE_CFLAGS=$(BASE_ASM_CFLAGS) -Wall -Dstrnicmp=strncasecmp -Dstricmp=strcasecmp -I$(CLIENT_DIR) -I$(SERVER_DIR) -I$(COMMON_DIR) -I$(SW_DIR) -I$(GL_DIR) -I$(PROGS_DIR) -I$(LIBS_DIR) -I$(LIBS_DIR)/dxsdk7/include -I$(LIBS_DIR)/sdl/include -I$(LIBS_DIR)/sdl/include/SDL -D_vsnprintf=vsnprintf -D_snprintf=snprintf +BASE_CFLAGS=$(BASE_ASM_CFLAGS) -Wall -Dstrnicmp=strncasecmp -Dstricmp=strcasecmp -I$(CLIENT_DIR) -I$(SERVER_DIR) -I$(COMMON_DIR) -I$(SW_DIR) -I$(GL_DIR) -I$(D3D9_DIR) -I$(D3D7_DIR) -I$(PROGS_DIR) -I$(LIBS_DIR) -I$(LIBS_DIR)/dxsdk7/include -I$(LIBS_DIR)/sdl/include -I$(LIBS_DIR)/sdl/include/SDL -D_vsnprintf=vsnprintf -D_snprintf=snprintf CLIENT_ONLY_CFLAGS=-DCLIENTONLY SERVER_ONLY_CFLAGS=-DSERVERONLY JOINT_CFLAGS= @@ -153,6 +157,7 @@ DEBUG_CFLAGS=-ggdb -g RELEASE_CFLAGS=-O6 -fno-strict-aliasing -ffast-math -funroll-loops -fexpensive-optimizations $(CPUOPTIMIZATIONS) GLCFLAGS=-DGLQUAKE SWCFLAGS=-DSWQUAKE +D3DCFLAGS=-DD3DQUAKE CLIENT_OBJS = $(CLIENT_ASM_OBJS) \ textedit.o \ @@ -264,6 +269,18 @@ GLQUAKE_OBJS = \ gl_vidcommon.o \ gl_hlmdl.o +D3DQUAKE_OBJS = \ + d3d_draw.o \ + d3d_mesh.o \ + d3d_rmain.o \ + d3d_rsurf.o \ + vid_d3d.o \ + d3d9_draw.o \ + d3d9_mesh.o \ + d3d9_rmain.o \ + d3d9_rsurf.o \ + vid_d3d9.o + MP3_OBJS = \ fixed.o \ bit.o \ @@ -369,7 +386,7 @@ GLCL_EXE_NAME=../fteqwcl_sdl.gl$(BITS) ifdef windir GL_LDFLAGS=$(GLLDFLAGS) -lmingw32 -lwsock32 `sdl-config --libs` else - GL_LDFLAGS=$(GLLDFLAGS) -lpng -ljpeg `sdl-config --libs` + GL_LDFLAGS=$(GLLDFLAGS) $(IMAGELDFLAGS) `sdl-config --libs` endif GL_CFLAGS=$(GLCFLAGS) `sdl-config --cflags` GLB_DIR=gl_sdl$(BITS) @@ -382,7 +399,7 @@ ifdef windir SW_LDFLAGS=$(SWLDFLAGS) -lmingw32 -lwsock32 -lSDLmain -lSDL else #pthread is needed because of SDL. -SW_LDFLAGS=$(SWLDFLAGS) `sdl-config --libs` -lpng -ljpeg +SW_LDFLAGS=$(SWLDFLAGS) `sdl-config --libs` $(IMAGELDFLAGS) endif SW_CFLAGS=$(SWCFLAGS) `sdl-config --cflags` SWB_DIR=sw_sdl$(BITS) @@ -446,6 +463,14 @@ endif MB_DIR=m_mgw MCL_DIR=mcl_mgw + D3DCL_OBJS=$(D3DQUAKE_OBJS) snd_win.o snd_directx.o cd_win.o in_win.o sys_win.o + D3D_EXE_NAME=../fted3dqw.exe + D3DCL_EXE_NAME=../fted3dclqw.exe + D3D_LDFLAGS= -ldxguid -lwsock32 -lwinmm -lgdi32 -lole32 + D3D_CFLAGS=$(D3DCFLAGS) $(W32_CFLAGS) -DMINIMAL + D3DB_DIR=d3d_mgw + D3DCL_DIR=d3dcl_mgw + MINGL_EXE_NAME=../fteminglqw.exe MINGL_DIR=mingl_mgw endif @@ -547,7 +572,7 @@ ifeq ($(FTE_TARGET),morphos) GLCL_OBJS=$(GL_OBJS) $(GLQUAKE_OBJS) gl_vidmorphos.o in_morphos.o snd_morphos.o cd_null.o sys_morphos.o GL_EXE_NAME=../fteqw.gl GLCL_EXE_NAME=../fteqwcl.gl - GL_LDFLAGS=$(GLLDFLAGS) -ldl -lsyscall -lpng -ljpeg -lz + GL_LDFLAGS=$(GLLDFLAGS) -ldl -lsyscall $(IMAGELDFLAGS) -lz GL_CFLAGS=$(GLCFLAGS) -noixemul GLB_DIR=gl_morphos GLCL_DIR=glcl_morphos @@ -649,7 +674,7 @@ ifneq ($(OUT_DIR),) endif -VPATH = $(BASE_DIR) : $(CLIENT_DIR) : $(GL_DIR) : $(COMMON_DIR) : $(SW_DIR) : $(SERVER_DIR) : $(HTTP_DIR) : $(BASE_DIR)/irc : $(BASE_DIR)/email : $(QUX_DIR) : $(PROGS_DIR) : $(SNDCODEC_DIR) +VPATH = $(BASE_DIR) : $(CLIENT_DIR) : $(GL_DIR) : $(COMMON_DIR) : $(SW_DIR) : $(SERVER_DIR) : $(HTTP_DIR) : $(BASE_DIR)/irc : $(BASE_DIR)/email : $(QUX_DIR) : $(PROGS_DIR) : $(SNDCODEC_DIR) : $(D3D7_DIR) : $(D3D9_DIR) #$(OUT_DIR)/%.d: %.c # @set -e; rm -f $@; \ @@ -718,6 +743,19 @@ sv-dbg: +d3dcl-tmp: + $(MAKE) $(TYPE) OUT_DIR="$(OUT_DIR)" EXE_NAME="$(D3DCL_EXE_NAME)" WCFLAGS="$(D3D_CFLAGS)" LDFLAGS="$(D3D_LDFLAGS) $(LDFLAGS)" SOBJS="$(D3DCL_OBJS)" +d3d-tmp: + $(MAKE) $(TYPE) OUT_DIR="$(OUT_DIR)" EXE_NAME="$(D3D_EXE_NAME)" WCFLAGS="$(D3D_CFLAGS)" LDFLAGS="$(D3D_LDFLAGS) $(LDFLAGS)" SOBJS="$(D3DCL_OBJS)" + +d3dcl-rel: + $(MAKE) d3dcl-tmp TYPE=_cl-rel OUT_DIR="$(RELEASE_DIR)/$(D3DCL_DIR)" +d3dcl-dbg: + $(MAKE) d3dcl-tmp TYPE=_cl-dbg OUT_DIR="$(DEBUG_DIR)/$(D3DCL_DIR)" +d3d-rel: + $(MAKE) d3d-tmp TYPE=_clsv-rel OUT_DIR="$(RELEASE_DIR)/$(D3DB_DIR)" +d3d-dbg: + $(MAKE) d3d-tmp TYPE=_clsv-dbg OUT_DIR="$(DEBUG_DIR)/$(D3DB_DIR)" glcl-tmp: @@ -805,6 +843,7 @@ help: @-echo "gl" @-echo "sw" @-echo "m" + @-echo "d3d (for windows builds)" @-echo "mcl (currently broken)" @-echo "glcl (currently broken)" @-echo "swcl (currently broken)" diff --git a/engine/client/cl_cam.c b/engine/client/cl_cam.c index 62f00862f..99d873017 100644 --- a/engine/client/cl_cam.c +++ b/engine/client/cl_cam.c @@ -500,7 +500,6 @@ void Cam_Track(int pnum, usercmd_t *cmd) // move there locally immediately VectorCopy(player->origin, self->origin); } - Con_Printf("self->weaponframe = %i\n", self->weaponframe); self->weaponframe = player->weaponframe; return; diff --git a/engine/client/cl_cg.c b/engine/client/cl_cg.c index 4bc28e54d..5baff764d 100644 --- a/engine/client/cl_cg.c +++ b/engine/client/cl_cg.c @@ -27,8 +27,18 @@ void GLDraw_ShaderImage (int x, int y, int w, int h, float s1, float t1, float s #define CGTAGNUM 5423 -#define VM_FROMHANDLE(a) ((void*)a) -#define VM_TOHANDLE(a) ((int)a) +#define VM_TOSTRCACHE(a) VMQ3_StringToHandle(VM_POINTER(a)) +#define VM_FROMSTRCACHE(a) VMQ3_StringFromHandle(a) +char *VMQ3_StringFromHandle(int handle); +int VMQ3_StringToHandle(char *str); + +extern model_t mod_known[]; +#define VM_FROMMHANDLE(a) (a?mod_known+a-1:NULL) +#define VM_TOMHANDLE(a) (a?a-mod_known+1:0) + +extern shader_t r_shaders[]; +#define VM_FROMSHANDLE(a) (a?r_shaders+a-1:NULL) +#define VM_TOSHANDLE(a) (a?a-r_shaders+1:0) typedef enum { CG_PRINT, @@ -139,8 +149,6 @@ typedef enum { } cgameImport_t; -#define VM_FROMHANDLE(a) ((void*)a) -#define VM_TOHANDLE(a) ((int)a) /* ================================================================== @@ -426,7 +434,7 @@ int VM_LerpTag(void *out, model_t *model, int f1, int f2, float l2, char *tagnam #define VALIDATEPOINTER(o,l) if ((int)o + l >= mask || VM_POINTER(o) < offset) Host_EndGame("Call to cgame trap %i passes invalid pointer\n", fn); //out of bounds. -static long CG_SystemCallsEx(void *offset, unsigned int mask, int fn, const long *arg) +static int CG_SystemCallsEx(void *offset, unsigned int mask, int fn, const int *arg) { int ret=0; @@ -463,35 +471,10 @@ static long CG_SystemCallsEx(void *offset, unsigned int mask, int fn, const long case CG_CVAR_REGISTER: if (arg[0]) VALIDATEPOINTER(arg[0], sizeof(vmcvar_t)); - { - vmcvar_t *vmc; - cvar_t *var; - vmc = VM_POINTER(arg[0]); - var = Cvar_Get(VM_POINTER(arg[1]), VM_POINTER(arg[2]), VM_LONG(arg[3])&(CVAR_ARCHIVE|CVAR_USERINFO|CVAR_SERVERINFO), "UI cvar"); - if (!vmc) - break; - vmc->handle = (char *)var - (char *)offset; - - vmc->integer = var->value; - vmc->value = var->value; - vmc->modificationCount = var->modified; - Q_strncpyz(vmc->string, var->string, sizeof(vmc->string)); - } - break; + return VMQ3_Cvar_Register(VM_POINTER(arg[0]), VM_POINTER(arg[1]), VM_POINTER(arg[2]), VM_LONG(arg[3])); case CG_CVAR_UPDATE: VALIDATEPOINTER(arg[0], sizeof(vmcvar_t)); - { - cvar_t *var; - vmcvar_t *vmc; - vmc = VM_POINTER(arg[0]); - var = (cvar_t *)((int)vmc->handle + (char *)offset); - - vmc->integer = var->value; - vmc->value = var->value; - vmc->modificationCount = var->modified; - Q_strncpyz(vmc->string, var->string, sizeof(vmc->string)); - } - break; + return VMQ3_Cvar_Update(VM_POINTER(arg[0])); case CG_CVAR_SET: { @@ -562,7 +545,7 @@ static long CG_SystemCallsEx(void *offset, unsigned int mask, int fn, const long case CG_CM_POINTCONTENTS: //int trap_CM_PointContents( const vec3_t p, clipHandle_t model ); { unsigned int pc; - model_t *mod = VM_FROMHANDLE(arg[1]); + model_t *mod = VM_FROMMHANDLE(arg[1]); if (!mod) mod = cl.worldmodel; if (mod) @@ -577,7 +560,7 @@ static long CG_SystemCallsEx(void *offset, unsigned int mask, int fn, const long { unsigned int pc; float *p = VM_POINTER(arg[0]); - model_t *mod = VM_FROMHANDLE(arg[1]); + model_t *mod = VM_FROMMHANDLE(arg[1]); float *origin = VM_POINTER(arg[2]); float *angles = VM_POINTER(arg[3]); @@ -624,7 +607,7 @@ static long CG_SystemCallsEx(void *offset, unsigned int mask, int fn, const long float *end = VM_POINTER(arg[2]); float *mins = VM_POINTER(arg[3]); float *maxs = VM_POINTER(arg[4]); - model_t *mod = VM_FROMHANDLE(arg[5]); + model_t *mod = VM_FROMMHANDLE(arg[5]); int brushmask = VM_LONG(arg[6]); float *origin = VM_POINTER(arg[7]); float *angles = VM_POINTER(arg[8]); @@ -668,7 +651,7 @@ static long CG_SystemCallsEx(void *offset, unsigned int mask, int fn, const long float *end = VM_POINTER(arg[2]); float *mins = VM_POINTER(arg[3]); float *maxs = VM_POINTER(arg[4]); - model_t *mod = VM_FROMHANDLE(arg[5]); + model_t *mod = VM_FROMMHANDLE(arg[5]); int brushmask = VM_LONG(arg[6]); if (!mod) mod = cl.worldmodel; @@ -703,8 +686,9 @@ static long CG_SystemCallsEx(void *offset, unsigned int mask, int fn, const long case CG_CM_LOADMAP: { int i; - strcpy(cl.model_name[1], VM_POINTER(arg[0])); - cl.worldmodel = cl.model_precache[1] = Mod_ForName(VM_POINTER(arg[0]), false); + char *mapname = VM_POINTER(arg[0]); + strcpy(cl.model_name[1], mapname); + cl.worldmodel = cl.model_precache[1] = Mod_ForName(mapname, false); if (cl.worldmodel->needload) Host_EndGame("Couldn't load map"); @@ -718,21 +702,21 @@ static long CG_SystemCallsEx(void *offset, unsigned int mask, int fn, const long break; case CG_CM_INLINEMODEL: - VM_LONG(ret) = VM_TOHANDLE(cl.model_precache[VM_LONG(arg[0])+1]); + VM_LONG(ret) = VM_TOMHANDLE(cl.model_precache[VM_LONG(arg[0])+1]); break; case CG_CM_NUMINLINEMODELS: VM_LONG(ret) = cl.worldmodel?cl.worldmodel->numsubmodels:0; break; case CG_CM_TEMPBOXMODEL: - VM_LONG(ret) = VM_TOHANDLE(CM_TempBoxModel(VM_POINTER(arg[0]), VM_POINTER(arg[1]))); + VM_LONG(ret) = VM_TOMHANDLE(CM_TempBoxModel(VM_POINTER(arg[0]), VM_POINTER(arg[1]))); break; case CG_R_MODELBOUNDS: VALIDATEPOINTER(arg[1], sizeof(vec3_t)); VALIDATEPOINTER(arg[2], sizeof(vec3_t)); { - model_t *mod = VM_FROMHANDLE(arg[0]); + model_t *mod = VM_FROMMHANDLE(arg[0]); if (mod) { VectorCopy(mod->mins, ((float*)VM_POINTER(arg[1]))); @@ -747,35 +731,29 @@ static long CG_SystemCallsEx(void *offset, unsigned int mask, int fn, const long mod = Mod_ForName(VM_POINTER(arg[0]), false); if (mod->needload || mod->type == mod_dummy) return 0; - VM_LONG(ret) = VM_TOHANDLE(mod); + VM_LONG(ret) = VM_TOMHANDLE(mod); } break; case CG_R_REGISTERSKIN: - { - char *buf; - char *skinname = VM_POINTER(arg[0]); - buf = Z_TagMalloc(strlen(skinname)+1, CGTAGNUM); - strcpy(buf, skinname); - VM_LONG(ret) = VM_TOHANDLE(buf); //precache skin - engine ignores these anyway... (for now) - } + VM_LONG(ret) = VM_TOSTRCACHE(arg[0]); break; case CG_R_REGISTERSHADER: if (!*(char*)VM_POINTER(arg[0])) VM_LONG(ret) = 0; else if (qrenderer == QR_OPENGL) - VM_LONG(ret) = VM_TOHANDLE(R_RegisterPic(VM_POINTER(arg[0]))); - else - VM_LONG(ret) = VM_TOHANDLE(Draw_SafeCachePic(VM_POINTER(arg[0]))); + VM_LONG(ret) = VM_TOSHANDLE(R_RegisterPic(VM_POINTER(arg[0]))); +//FIXME: 64bit else +// VM_LONG(ret) = VM_TOHANDLE(Draw_SafeCachePic(VM_POINTER(arg[0]))); break; case CG_R_REGISTERSHADERNOMIP: if (!*(char*)VM_POINTER(arg[0])) VM_LONG(ret) = 0; else if (qrenderer == QR_OPENGL) - VM_LONG(ret) = VM_TOHANDLE(R_RegisterPic(VM_POINTER(arg[0]))); - else - VM_LONG(ret) = VM_TOHANDLE(Draw_SafeCachePic(VM_POINTER(arg[0]))); + VM_LONG(ret) = VM_TOSHANDLE(R_RegisterPic(VM_POINTER(arg[0]))); +//FIXME: 64bit else +// VM_LONG(ret) = VM_TOHANDLE(Draw_SafeCachePic(VM_POINTER(arg[0]))); break; case CG_R_CLEARSCENE: //clear scene @@ -813,22 +791,22 @@ static long CG_SystemCallsEx(void *offset, unsigned int mask, int fn, const long case CG_R_DRAWSTRETCHPIC: if (qrenderer == QR_OPENGL) - GLDraw_ShaderImage(VM_FLOAT(arg[0]), VM_FLOAT(arg[1]), VM_FLOAT(arg[2]), VM_FLOAT(arg[3]), VM_FLOAT(arg[4]), VM_FLOAT(arg[5]), VM_FLOAT(arg[6]), VM_FLOAT(arg[7]), (void *)VM_LONG(arg[8])); - else - Draw_Image(VM_FLOAT(arg[0]), VM_FLOAT(arg[1]), VM_FLOAT(arg[2]), VM_FLOAT(arg[3]), VM_FLOAT(arg[4]), VM_FLOAT(arg[5]), VM_FLOAT(arg[6]), VM_FLOAT(arg[7]), (mpic_t *)VM_LONG(arg[8])); + GLDraw_ShaderImage(VM_FLOAT(arg[0]), VM_FLOAT(arg[1]), VM_FLOAT(arg[2]), VM_FLOAT(arg[3]), VM_FLOAT(arg[4]), VM_FLOAT(arg[5]), VM_FLOAT(arg[6]), VM_FLOAT(arg[7]), VM_FROMSHANDLE(arg[8])); +// else +// Draw_Image(VM_FLOAT(arg[0]), VM_FLOAT(arg[1]), VM_FLOAT(arg[2]), VM_FLOAT(arg[3]), VM_FLOAT(arg[4]), VM_FLOAT(arg[5]), VM_FLOAT(arg[6]), VM_FLOAT(arg[7]), (mpic_t *)VM_LONG(arg[8])); break; case CG_R_LERPTAG: //Lerp tag... VALIDATEPOINTER(arg[0], sizeof(float)*12); - VM_LONG(ret) = VM_LerpTag(VM_POINTER(arg[0]), (model_t*)VM_LONG(arg[1]), VM_LONG(arg[2]), VM_LONG(arg[3]), VM_FLOAT(arg[4]), VM_POINTER(arg[5])); + VM_LONG(ret) = VM_LerpTag(VM_POINTER(arg[0]), VM_FROMMHANDLE(arg[1]), VM_LONG(arg[2]), VM_LONG(arg[3]), VM_FLOAT(arg[4]), VM_POINTER(arg[5])); break; case CG_S_REGISTERSOUND: { sfx_t *sfx; - sfx = S_PrecacheSound(va("../%s", VM_POINTER(arg[0]))); + sfx = S_PrecacheSound(VM_POINTER(arg[0])); if (sfx) - VM_LONG(ret) = VM_TOHANDLE(sfx); + VM_LONG(ret) = VM_TOSTRCACHE(arg[0]); else VM_LONG(ret) = -1; } @@ -836,11 +814,11 @@ static long CG_SystemCallsEx(void *offset, unsigned int mask, int fn, const long case CG_S_STARTLOCALSOUND: if (VM_LONG(arg[0]) != -1 && arg[0]) - S_LocalSound(((sfx_t*)VM_FROMHANDLE(arg[0]))->name ); + S_LocalSound(VM_FROMSTRCACHE(arg[0])); break; case CG_S_STARTSOUND:// ( vec3_t origin, int entityNum, int entchannel, sfxHandle_t sfx ) - S_StartSound(VM_LONG(arg[1]), VM_LONG(arg[2]), (sfx_t*)VM_LONG(arg[3]), VM_POINTER(arg[0]), 1, 1); + S_StartSound(VM_LONG(arg[1]), VM_LONG(arg[2]), S_PrecacheSound(VM_FROMSTRCACHE(arg[3])), VM_POINTER(arg[0]), 1, 1); break; case CG_S_ADDLOOPINGSOUND: @@ -906,11 +884,14 @@ vec3_t listener_up; VALIDATEPOINTER(arg[0], 11332); //do any needed work - memset(VM_POINTER(arg[0]), 0, 11304); - *(int *)VM_POINTER(arg[0]+11304) = vid.width; - *(int *)VM_POINTER(arg[0]+11308) = vid.height; - *(float *)VM_POINTER(arg[0]+11312) = (float)vid.width/vid.height; - memset(VM_POINTER(arg[0]+11316), 0, 11332-11316); + unsigned char *glconfig = VM_POINTER(arg[0]); + { //FIXME: Clean this shit up + memset(glconfig, 0, 11304); + *(int *)(glconfig+11304) = vid.width; + *(int *)(glconfig+11308) = vid.height; + *(float *)(glconfig+11312) = (float)vid.width/vid.height; + memset((glconfig+11316), 0, 11332-11316); + } break; case CG_GETGAMESTATE: @@ -991,15 +972,26 @@ vec3_t listener_up; // standard Q3 case CG_MEMSET: VALIDATEPOINTER(arg[0], arg[2]); - memset(VM_POINTER(arg[0]), arg[1], arg[2]); + { + void *dst = VM_POINTER(arg[0]); + memset(dst, arg[1], arg[2]); + } break; case CG_MEMCPY: VALIDATEPOINTER(arg[0], arg[2]); - memcpy(VM_POINTER(arg[0]), VM_POINTER(arg[1]), arg[2]); + { + void *dst = VM_POINTER(arg[0]); + void *src = VM_POINTER(arg[1]); + memcpy(dst, src, arg[2]); + } break; case CG_STRNCPY: VALIDATEPOINTER(arg[0], arg[2]); - strncpy(VM_POINTER(arg[0]), VM_POINTER(arg[1]), arg[2]); + { + void *dst = VM_POINTER(arg[0]); + void *src = VM_POINTER(arg[1]); + strncpy(dst, src, arg[2]); + } break; case CG_SIN: VM_FLOAT(ret)=(float)sin(VM_FLOAT(arg[0])); @@ -1034,7 +1026,7 @@ vec3_t listener_up; return ret; } #ifdef _DEBUG -static long CG_SystemCallsExWrapper(void *offset, unsigned int mask, int fn, const long *arg) +static int CG_SystemCallsExWrapper(void *offset, unsigned int mask, int fn, const int *arg) { //this is so we can use edit and continue properly (vc doesn't like function pointers for edit+continue) return CG_SystemCallsEx(offset, mask, fn, arg); } @@ -1045,7 +1037,7 @@ static long CG_SystemCallsExWrapper(void *offset, unsigned int mask, int fn, con //but dlls call it without saying what sort of vm it comes from, so I've got to have them as specifics static int EXPORT_FN CG_SystemCalls(int arg, ...) { - long args[10]; + int args[10]; va_list argptr; va_start(argptr, arg); diff --git a/engine/client/cl_main.c b/engine/client/cl_main.c index b60d2b81e..2366acc74 100644 --- a/engine/client/cl_main.c +++ b/engine/client/cl_main.c @@ -1183,6 +1183,8 @@ void CL_Disconnect (void) cl.servercount = 0; cls.findtrack = false; + Validation_DelatchRulesets(); + #ifdef TCPCONNECT if (cls.sockettcp != INVALID_SOCKET) { @@ -2170,6 +2172,7 @@ void CL_ConnectionlessPacket (void) if (!strcmp(com_token, "ccept")) { Con_Printf ("accept\n"); + Validation_Apply_Ruleset(); Netchan_Setup(NS_CLIENT, &cls.netchan, net_from, cls.qport); Con_DPrintf ("CL_EstablishConnection: connected to %s\n", cls.servername); @@ -2226,6 +2229,8 @@ client_connect: //fixme: make function current_loading_size = 0; loading_stage = 2; + Validation_Apply_Ruleset(); + return; } // remote command from gui front end @@ -2342,6 +2347,8 @@ void CLNQ_ConnectionlessPacket(void) } } + Validation_Apply_Ruleset(); + Netchan_Setup (NS_CLIENT, &cls.netchan, net_from, cls.qport); cls.netchan.isnqprotocol = true; cls.netchan.compress = 0; diff --git a/engine/client/cl_parse.c b/engine/client/cl_parse.c index eeb3e499a..b9fbdf7c7 100644 --- a/engine/client/cl_parse.c +++ b/engine/client/cl_parse.c @@ -3469,38 +3469,14 @@ char *CL_ParseChat(char *text, player_info_t **player) { if (!cls.demoplayback) Sys_ServerActivity(); //chat always flashes the screen.. -/* - //check f_ stuff - if (!strncmp(s, "f_", 2)) - { - static float versionresponsetime; - static float modifiedresponsetime; - static float skinsresponsetime; - static float serverresponsetime; - if (!strncmp(s, "f_version", 9) && versionresponsetime < Sys_DoubleTime()) //respond to it. - { - ValidationPrintVersion(text); - versionresponsetime = Sys_DoubleTime() + 5; - } - else if (!strncmp(s, "f_server", 8) && serverresponsetime < Sys_DoubleTime()) //respond to it. - { - Validation_Server(); - serverresponsetime = Sys_DoubleTime() + 5; - } - else if (!strncmp(s, "f_modified", 10) && modifiedresponsetime < Sys_DoubleTime()) //respond to it. - { - Validation_FilesModified(); - modifiedresponsetime = Sys_DoubleTime() + 5; - } - else if (!strncmp(s, "f_skins", 7) && skinsresponsetime < Sys_DoubleTime()) //respond to it. - { - Validation_Skins(); - skinsresponsetime = Sys_DoubleTime() + 5; - } + //check f_ stuff + if (*player && !strncmp(s, "f_", 2)) + { + Validation_Auto_Response(*player - cl.players, s); return s; } -*/ + Validation_CheckIfResponse(text); #ifdef PLUGINS diff --git a/engine/client/cl_plugin.inc b/engine/client/cl_plugin.inc index 0da420722..1a651a3ea 100644 --- a/engine/client/cl_plugin.inc +++ b/engine/client/cl_plugin.inc @@ -11,7 +11,7 @@ static plugin_t *protocolclientplugin; -int VARGS Plug_Menu_Control(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Menu_Control(void *offset, unsigned int mask, const int *arg) { if (qrenderer <= 0) return 0; @@ -45,7 +45,7 @@ int VARGS Plug_Menu_Control(void *offset, unsigned int mask, const long *arg) } } -int VARGS Plug_Key_GetKeyCode(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Key_GetKeyCode(void *offset, unsigned int mask, const int *arg) { int modifier; return Key_StringToKeynum(VM_POINTER(arg[0]), &modifier); @@ -54,7 +54,7 @@ int VARGS Plug_Key_GetKeyCode(void *offset, unsigned int mask, const long *arg) -int VARGS Plug_SCR_CenterPrint(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_SCR_CenterPrint(void *offset, unsigned int mask, const int *arg) { if (qrenderer <= 0) return 0; @@ -62,7 +62,7 @@ int VARGS Plug_SCR_CenterPrint(void *offset, unsigned int mask, const long *arg) SCR_CenterPrint(0, VM_POINTER(arg[0])); return 0; } -int VARGS Plug_Media_ShowFrameRGBA_32(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Media_ShowFrameRGBA_32(void *offset, unsigned int mask, const int *arg) { void *src = VM_POINTER(arg[0]); int srcwidth = VM_LONG(arg[1]); @@ -92,7 +92,7 @@ typedef struct { int pluginimagearraylen; pluginimagearray_t *pluginimagearray; -int VARGS Plug_Draw_LoadImage(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Draw_LoadImage(void *offset, unsigned int mask, const int *arg) { char *name = VM_POINTER(arg[0]); qboolean fromwad = arg[1]; @@ -179,7 +179,7 @@ void Plug_FreePlugImages(plugin_t *plug) } //int Draw_Image (float x, float y, float w, float h, float s1, float t1, float s2, float t2, qhandle_t image) -int VARGS Plug_Draw_Image(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Draw_Image(void *offset, unsigned int mask, const int *arg) { mpic_t *pic; int i; @@ -210,7 +210,7 @@ int VARGS Plug_Draw_Image(void *offset, unsigned int mask, const long *arg) return 1; } //x1,y1,x2,y2 -int VARGS Plug_Draw_Line(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Draw_Line(void *offset, unsigned int mask, const int *arg) { switch(qrenderer) //FIXME: I don't want qrenderer seen outside the refresh { @@ -229,7 +229,7 @@ int VARGS Plug_Draw_Line(void *offset, unsigned int mask, const long *arg) } return 1; } -int VARGS Plug_Draw_Character(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Draw_Character(void *offset, unsigned int mask, const int *arg) { if (qrenderer <= 0) return 0; @@ -237,7 +237,7 @@ int VARGS Plug_Draw_Character(void *offset, unsigned int mask, const long *arg) return 0; } void (D3D_Draw_Fill_Colours) (int x, int y, int w, int h); -int VARGS Plug_Draw_Fill(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Draw_Fill(void *offset, unsigned int mask, const int *arg) { float x, y, width, height; if (qrenderer <= 0) @@ -268,7 +268,7 @@ int VARGS Plug_Draw_Fill(void *offset, unsigned int mask, const long *arg) } return 0; } -int VARGS Plug_Draw_ColourP(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Draw_ColourP(void *offset, unsigned int mask, const int *arg) { qbyte *pal = host_basepal + VM_LONG(arg[0])*3; @@ -282,7 +282,7 @@ int VARGS Plug_Draw_ColourP(void *offset, unsigned int mask, const long *arg) } return 0; } -int VARGS Plug_Draw_Colour3f(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Draw_Colour3f(void *offset, unsigned int mask, const int *arg) { if (Draw_ImageColours) { @@ -291,7 +291,7 @@ int VARGS Plug_Draw_Colour3f(void *offset, unsigned int mask, const long *arg) } return 0; } -int VARGS Plug_Draw_Colour4f(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Draw_Colour4f(void *offset, unsigned int mask, const int *arg) { if (Draw_ImageColours) { @@ -309,7 +309,7 @@ int VARGS Plug_Draw_Colour4f(void *offset, unsigned int mask, const long *arg) -int VARGS Plug_LocalSound(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_LocalSound(void *offset, unsigned int mask, const int *arg) { if (qrenderer <= 0) return false; @@ -320,7 +320,7 @@ int VARGS Plug_LocalSound(void *offset, unsigned int mask, const long *arg) -int VARGS Plug_CL_GetStats(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_CL_GetStats(void *offset, unsigned int mask, const int *arg) { int i; int pnum = VM_LONG(arg[0]); @@ -361,7 +361,7 @@ typedef struct { char team[8]; } vmplugclientinfo_t; -int VARGS Plug_GetPlayerInfo(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_GetPlayerInfo(void *offset, unsigned int mask, const int *arg) { int i, pt; vmplugclientinfo_t *out; @@ -401,12 +401,12 @@ int VARGS Plug_GetPlayerInfo(void *offset, unsigned int mask, const long *arg) return pt == i; } -int VARGS Plug_LocalPlayerNumber(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_LocalPlayerNumber(void *offset, unsigned int mask, const int *arg) { return cl.playernum[0]; } -int VARGS Plug_GetServerInfo(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_GetServerInfo(void *offset, unsigned int mask, const int *arg) { char *outptr = VM_POINTER(arg[0]); int outlen = VM_LONG(arg[1]); @@ -419,7 +419,7 @@ int VARGS Plug_GetServerInfo(void *offset, unsigned int mask, const long *arg) return true; } -int VARGS Plug_SetUserInfo(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_SetUserInfo(void *offset, unsigned int mask, const int *arg) { char *key = VM_POINTER(arg[0]); char *value = VM_POINTER(arg[1]); @@ -429,7 +429,7 @@ int VARGS Plug_SetUserInfo(void *offset, unsigned int mask, const long *arg) return true; } -int VARGS Plug_Con_SubPrint(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Con_SubPrint(void *offset, unsigned int mask, const int *arg) { char *name = VM_POINTER(arg[0]); char *text = VM_POINTER(arg[1]); @@ -455,7 +455,7 @@ int VARGS Plug_Con_SubPrint(void *offset, unsigned int mask, const long *arg) return 1; } -int VARGS Plug_Con_RenameSub(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Con_RenameSub(void *offset, unsigned int mask, const int *arg) { char *name = VM_POINTER(arg[0]); console_t *con; @@ -469,7 +469,7 @@ int VARGS Plug_Con_RenameSub(void *offset, unsigned int mask, const long *arg) return 1; } -int VARGS Plug_Con_IsActive(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Con_IsActive(void *offset, unsigned int mask, const int *arg) { char *name = VM_POINTER(arg[0]); console_t *con; @@ -481,7 +481,7 @@ int VARGS Plug_Con_IsActive(void *offset, unsigned int mask, const long *arg) return Con_IsActive(con); } -int VARGS Plug_Con_SetActive(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Con_SetActive(void *offset, unsigned int mask, const int *arg) { char *name = VM_POINTER(arg[0]); console_t *con; @@ -494,7 +494,7 @@ int VARGS Plug_Con_SetActive(void *offset, unsigned int mask, const long *arg) Con_SetActive(con); return true; } -int VARGS Plug_Con_Destroy(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Con_Destroy(void *offset, unsigned int mask, const int *arg) { char *name = VM_POINTER(arg[0]); console_t *con; @@ -507,7 +507,7 @@ int VARGS Plug_Con_Destroy(void *offset, unsigned int mask, const long *arg) Con_Destroy(con); return true; } -int VARGS Plug_Con_NameForNum(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Con_NameForNum(void *offset, unsigned int mask, const int *arg) { char num = VM_LONG(arg[0]); char *buffer = VM_POINTER(arg[1]); diff --git a/engine/client/cl_ui.c b/engine/client/cl_ui.c index cfab9010b..84c6a7660 100644 --- a/engine/client/cl_ui.c +++ b/engine/client/cl_ui.c @@ -298,15 +298,20 @@ netadr_t ui_pings[MAX_PINGREQUESTS]; #define UITAGNUM 2452 +extern model_t mod_known[]; +#define VM_FROMMHANDLE(a) (a?mod_known+a-1:NULL) +#define VM_TOMHANDLE(a) (a?a-mod_known+1:0) - +extern shader_t r_shaders[]; +#define VM_FROMSHANDLE(a) (a?r_shaders+a-1:NULL) +#define VM_TOSHANDLE(a) (a?a-r_shaders+1:0) typedef struct q3refEntity_s { refEntityType_t reType; int renderfx; - struct model_s *hModel; // opaque type outside refresh + int hModel; // opaque type outside refresh // most recent data vec3_t lightingOrigin; // so multi-part models can be lit identically (RF_LIGHTING_ORIGIN) @@ -324,8 +329,7 @@ typedef struct q3refEntity_s { // texturing int skinNum; // inline skin index - //int customSkin; // NULL for default skin - char *customSkin; //the function that references this wants a char* not an int + int customSkin; // NULL for default skin int customShader; // use one image for the entire thing // misc @@ -346,13 +350,50 @@ typedef struct q3refEntity_s { #define Q3RF_THIRD_PERSON 2 // don't draw through eyes, only mirrors (player bodies, chat sprites) #define Q3RF_FIRST_PERSON 4 // only draw through eyes (view weapon, damage blood blob) #define Q3RF_DEPTHHACK 8 // for view weapon Z crunching + +#define MAX_VMQ3_CACHED_STRINGS 1024 +char *stringcache[1024]; + +char *VMQ3_StringFromHandle(int handle) +{ + if (!handle) + return ""; + handle--; + if ((unsigned) handle >= MAX_VMQ3_CACHED_STRINGS) + return ""; + return stringcache[handle]; +} + +int VMQ3_StringToHandle(char *str) +{ + int i; + for (i = 0; i < MAX_VMQ3_CACHED_STRINGS; i++) + { + if (!stringcache[i]) + break; + if (!strcmp(str, stringcache[i])) + return i+1; + } + if (i == MAX_VMQ3_CACHED_STRINGS) + { + Con_Printf("Q3VM out of string handle space\n"); + return 0; + } + stringcache[i] = Z_Malloc(strlen(str)+1); + strcpy(stringcache[i], str); + return i+1; +} + +#define VM_TOSTRCACHE(a) VMQ3_StringToHandle(VM_POINTER(a)) +#define VM_FROMSTRCACHE(a) VMQ3_StringFromHandle(a) + void VQ3_AddEntity(const q3refEntity_t *q3) { entity_t ent; if (!cl_visedicts) cl_visedicts = cl_visedicts_list[0]; memset(&ent, 0, sizeof(ent)); - ent.model = q3->hModel; + ent.model = VM_FROMMHANDLE(q3->hModel); ent.frame = q3->frame; ent.oldframe = q3->oldframe; memcpy(ent.axis, q3->axis, sizeof(q3->axis)); @@ -362,14 +403,14 @@ void VQ3_AddEntity(const q3refEntity_t *q3) ent.rotation = q3->rotation; if (q3->customSkin) - ent.skinnum = Mod_SkinForName(ent.model, q3->customSkin); + ent.skinnum = Mod_SkinForName(ent.model, VM_FROMSTRCACHE(q3->customSkin)); ent.shaderRGBAf[0] = q3->shaderRGBA[0]/255.0f; ent.shaderRGBAf[1] = q3->shaderRGBA[1]/255.0f; ent.shaderRGBAf[2] = q3->shaderRGBA[2]/255.0f; ent.shaderRGBAf[3] = q3->shaderRGBA[3]/255.0f; #ifdef Q3SHADERS - ent.forcedshader = (void*)q3->customShader; + ent.forcedshader = VM_FROMSHANDLE(q3->customShader); ent.shaderTime = q3->shaderTime; #endif if (q3->renderfx & Q3RF_FIRST_PERSON) @@ -557,21 +598,19 @@ void UI_RegisterFont(char *fontName, int pointSize, fontInfo_t *font) Q_strncpyz(font->name, name, sizeof(font->name)); for (i = GLYPH_START; i < GLYPH_END; i++) { - font->glyphs[i].glyph = (int)R_RegisterPic(font->glyphs[i].shaderName); + font->glyphs[i].glyph = VM_TOSHANDLE(R_RegisterPic(font->glyphs[i].shaderName)); } } } -#define VM_FROMHANDLE(a) ((void*)a) -#define VM_TOHANDLE(a) ((int)a) #define VALIDATEPOINTER(o,l) if ((int)o + l >= mask || VM_POINTER(o) < offset) SV_Error("Call to ui trap %i passes invalid pointer\n", fn); //out of bounds. #ifndef _DEBUG static #endif -long UI_SystemCallsEx(void *offset, unsigned int mask, int fn, const long *arg) +int UI_SystemCallsEx(void *offset, unsigned int mask, int fn, const int *arg) { int ret=0; @@ -728,7 +767,7 @@ long UI_SystemCallsEx(void *offset, unsigned int mask, int fn, const long *arg) case UI_R_REGISTERMODEL: //precache model { char *name = VM_POINTER(arg[0]); - VM_LONG(ret) = VM_TOHANDLE(Mod_ForName(name, false)); + VM_LONG(ret) = VM_TOMHANDLE(Mod_ForName(name, false)); } break; case UI_R_MODELBOUNDS: @@ -736,7 +775,7 @@ long UI_SystemCallsEx(void *offset, unsigned int mask, int fn, const long *arg) VALIDATEPOINTER(arg[1], sizeof(vec3_t)); VALIDATEPOINTER(arg[2], sizeof(vec3_t)); { - model_t *mod = VM_FROMHANDLE(arg[0]); + model_t *mod = VM_FROMMHANDLE(arg[0]); if (mod) { VectorCopy(mod->mins, ((float*)VM_POINTER(arg[1]))); @@ -754,10 +793,7 @@ long UI_SystemCallsEx(void *offset, unsigned int mask, int fn, const long *arg) case UI_R_REGISTERSKIN: { char *buf; - char *skinname = VM_POINTER(arg[0]); - buf = Z_TagMalloc(strlen(skinname)+1, UITAGNUM); - strcpy(buf, skinname); - VM_LONG(ret) = (int)buf; //precache skin - engine ignores these anyway... (for now) + VM_LONG(ret) = VM_TOSTRCACHE(arg[0]); } break; @@ -768,9 +804,9 @@ long UI_SystemCallsEx(void *offset, unsigned int mask, int fn, const long *arg) if (!*(char*)VM_POINTER(arg[0])) VM_LONG(ret) = 0; else if (qrenderer == QR_OPENGL) - VM_LONG(ret) = (long)R_RegisterPic(VM_POINTER(arg[0])); - else - VM_LONG(ret) = (long)Draw_SafeCachePic(VM_POINTER(arg[0])); + VM_LONG(ret) = VM_TOSHANDLE(R_RegisterPic(VM_POINTER(arg[0]))); +//FIXME: 64bit else +// VM_LONG(ret) = (long)Draw_SafeCachePic(VM_POINTER(arg[0])); break; case UI_R_CLEARSCENE: //clear scene @@ -801,16 +837,16 @@ long UI_SystemCallsEx(void *offset, unsigned int mask, int fn, const long *arg) // qglEnable(GL_BLEND); // GL_TexEnv(GL_MODULATE); if (qrenderer == QR_OPENGL) - GLDraw_ShaderImage(VM_FLOAT(arg[0]), VM_FLOAT(arg[1]), VM_FLOAT(arg[2]), VM_FLOAT(arg[3]), VM_FLOAT(arg[4]), VM_FLOAT(arg[5]), VM_FLOAT(arg[6]), VM_FLOAT(arg[7]), (void *)VM_LONG(arg[8])); - else - Draw_Image(VM_FLOAT(arg[0]), VM_FLOAT(arg[1]), VM_FLOAT(arg[2]), VM_FLOAT(arg[3]), VM_FLOAT(arg[4]), VM_FLOAT(arg[5]), VM_FLOAT(arg[6]), VM_FLOAT(arg[7]), (mpic_t *)VM_LONG(arg[8])); + GLDraw_ShaderImage(VM_FLOAT(arg[0]), VM_FLOAT(arg[1]), VM_FLOAT(arg[2]), VM_FLOAT(arg[3]), VM_FLOAT(arg[4]), VM_FLOAT(arg[5]), VM_FLOAT(arg[6]), VM_FLOAT(arg[7]), VM_FROMSHANDLE(arg[8])); +// else +// Draw_Image(VM_FLOAT(arg[0]), VM_FLOAT(arg[1]), VM_FLOAT(arg[2]), VM_FLOAT(arg[3]), VM_FLOAT(arg[4]), VM_FLOAT(arg[5]), VM_FLOAT(arg[6]), VM_FLOAT(arg[7]), (mpic_t *)VM_LONG(arg[8])); break; case UI_CM_LERPTAG: //Lerp tag... // tag, model, startFrame, endFrame, frac, tagName if ((int)arg[0] + sizeof(float)*12 >= mask || VM_POINTER(arg[0]) < offset) break; //out of bounds. - VM_LerpTag(VM_POINTER(arg[0]), (model_t*)VM_LONG(arg[1]), VM_LONG(arg[2]), VM_LONG(arg[3]), VM_FLOAT(arg[4]), VM_POINTER(arg[5])); + VM_LerpTag(VM_POINTER(arg[0]), VM_FROMMHANDLE(arg[1]), VM_LONG(arg[2]), VM_LONG(arg[3]), VM_FLOAT(arg[4]), VM_POINTER(arg[5])); break; case UI_S_REGISTERSOUND: @@ -818,14 +854,14 @@ long UI_SystemCallsEx(void *offset, unsigned int mask, int fn, const long *arg) sfx_t *sfx; sfx = S_PrecacheSound(va("../%s", VM_POINTER(arg[0]))); if (sfx) - VM_LONG(ret) = sfx->name - (char *)offset; + VM_LONG(ret) = VM_TOSTRCACHE(arg[0]); //return handle is the parameter they just gave else VM_LONG(ret) = -1; } break; case UI_S_STARTLOCALSOUND: if (VM_LONG(arg[0]) != -1 && arg[0]) - S_LocalSound(VM_LONG(arg[0])+(char *)offset); + S_LocalSound(VM_FROMSTRCACHE(arg[0])); //now we can fix up the sound name break; case UI_KEY_GETOVERSTRIKEMODE: @@ -979,37 +1015,14 @@ long UI_SystemCallsEx(void *offset, unsigned int mask, int fn, const long *arg) break; case UI_CVAR_REGISTER: - if ((int)arg[0] + sizeof(vmcvar_t) >= mask || VM_POINTER(arg[0]) < offset) + if (VM_OOB(arg[0], sizeof(vmcvar_t))) break; //out of bounds. - { - vmcvar_t *vmc; - cvar_t *var; - vmc = VM_POINTER(arg[0]); - var = Cvar_Get(VM_POINTER(arg[1]), VM_POINTER(arg[2]), 0/*VM_LONG(arg[3])*/, "UI cvar"); - if (!vmc) - break; - vmc->handle = (char *)var - (char *)offset; + return VMQ3_Cvar_Register(VM_POINTER(arg[0]), VM_POINTER(arg[1]), VM_POINTER(arg[2]), VM_LONG(arg[3])); - vmc->integer = var->value; - vmc->value = var->value; - vmc->modificationCount = var->modified; - Q_strncpyz(vmc->string, var->string, sizeof(vmc->string)); - } case UI_CVAR_UPDATE: - if ((int)arg[0] + sizeof(vmcvar_t) >= mask || VM_POINTER(arg[0]) < offset) + if (VM_OOB(arg[0], sizeof(vmcvar_t))) break; //out of bounds. - { - cvar_t *var; - vmcvar_t *vmc; - vmc = VM_POINTER(arg[0]); - var = (cvar_t *)((int)vmc->handle + (char *)offset); - - vmc->integer = var->value; - vmc->value = var->value; - vmc->modificationCount = var->modified; - Q_strncpyz(vmc->string, var->string, sizeof(vmc->string)); - } - break; + return VMQ3_Cvar_Update(VM_POINTER(arg[0])); case UI_MEMORY_REMAINING: VM_LONG(ret) = Hunk_LowMemAvailable(); @@ -1112,14 +1125,13 @@ long UI_SystemCallsEx(void *offset, unsigned int mask, int fn, const long *arg) case UI_CEIL: VM_FLOAT(ret)=(float)ceil(VM_FLOAT(arg[0])); break; - +/* case UI_CACHE_PIC: if (!Draw_SafeCachePic) VM_LONG(ret) = 0; else { - /*VM_LONG(ret) = (long)*/Draw_SafeCachePic(VM_POINTER(arg[0])); - VM_LONG(ret) = (long)R_RegisterPic(VM_POINTER(arg[0])); + VM_LONG(ret) = 0;//FIXME: 64bit (long)R_RegisterPic(VM_POINTER(arg[0])); } break; case UI_PICFROMWAD: @@ -1127,8 +1139,7 @@ long UI_SystemCallsEx(void *offset, unsigned int mask, int fn, const long *arg) VM_LONG(ret) = 0; else { - /*VM_LONG(ret) = (long)*/Draw_SafePicFromWad(VM_POINTER(arg[0])); - VM_LONG(ret) = (long)R_RegisterPic(VM_POINTER(arg[0])); + VM_LONG(ret) = 0;//FIXME: 64bit (long)R_RegisterPic(VM_POINTER(arg[0])); } break; case UI_GETPLAYERINFO: @@ -1225,7 +1236,7 @@ long UI_SystemCallsEx(void *offset, unsigned int mask, int fn, const long *arg) return strlen(str); } - +*/ case UI_PC_ADD_GLOBAL_DEFINE: Con_Printf("UI_PC_ADD_GLOBAL_DEFINE not supported\n"); @@ -1264,7 +1275,7 @@ long UI_SystemCallsEx(void *offset, unsigned int mask, int fn, const long *arg) } #ifdef _DEBUG -static long UI_SystemCallsExWrapper(void *offset, unsigned int mask, int fn, const long *arg) +static int UI_SystemCallsExWrapper(void *offset, unsigned int mask, int fn, const int *arg) { //this is so we can use edit and continue properly (vc doesn't like function pointers for edit+continue) return UI_SystemCallsEx(offset, mask, fn, arg); } @@ -1275,7 +1286,7 @@ static long UI_SystemCallsExWrapper(void *offset, unsigned int mask, int fn, con //but dlls call it without saying what sort of vm it comes from, so I've got to have them as specifics static int EXPORT_FN UI_SystemCalls(int arg, ...) { - long args[9]; + int args[9]; va_list argptr; va_start(argptr, arg); @@ -1295,26 +1306,35 @@ static int EXPORT_FN UI_SystemCalls(int arg, ...) qboolean UI_DrawStatusBar(int scores) { + return false; +/* if (!uivm) return false; return VM_Call(uivm, UI_DRAWSTATUSBAR, scores); +*/ } qboolean UI_DrawFinale(void) { + return false; +/* if (!uivm) return false; return VM_Call(uivm, UI_FINALE); +*/ } qboolean UI_DrawIntermission(void) { + return false; +/* if (!uivm) return false; return VM_Call(uivm, UI_INTERMISSION); +*/ } void UI_DrawMenu(void) @@ -1330,25 +1350,31 @@ void UI_DrawMenu(void) qboolean UI_CenterPrint(char *text, qboolean finale) { scr_centerstring = text; - + return false; +/* if (!uivm) return false; return VM_Call(uivm, UI_STRINGCHANGED, SID_CENTERPRINTTEXT); +*/ } qboolean UI_Q2LayoutChanged(void) { + return false; +/* if (!uivm) return false; return VM_Call(uivm, UI_STRINGCHANGED, SID_CENTERPRINTTEXT); +*/ } void UI_StringChanged(int num) { - if (uivm) +/* if (uivm) VM_Call(uivm, UI_STRINGCHANGED, num); +*/ } void UI_Reset(void) @@ -1467,15 +1493,11 @@ void UI_Start (void) if (qrenderer != QR_OPENGL && qrenderer != QR_DIRECT3D) return; - uivm = VM_Create(NULL, "vm/qwui", UI_SystemCalls, UI_SystemCallsEx); - if (!uivm) //broken currently, I believe. - uivm = VM_Create(NULL, "vm/ui", UI_SystemCalls, UI_SystemCallsEx); + uivm = VM_Create(NULL, "vm/ui", UI_SystemCalls, UI_SystemCallsEx); if (uivm) { - apiversion = VM_Call(uivm, UI_GETAPIVERSION, UI_API_VERSION); - if (apiversion == UI_API_VERSION) - keycatcher = 0; - else if (apiversion != 4 && apiversion != 6) //make sure we can run the thing + apiversion = VM_Call(uivm, UI_GETAPIVERSION, 6); + if (apiversion != 4 && apiversion != 6) //make sure we can run the thing { Con_Printf("User-Interface VM uses incompatable API version (%i)\n", apiversion); VM_Destroy(uivm); diff --git a/engine/client/client.h b/engine/client/client.h index ffa9690d1..4b48411dd 100644 --- a/engine/client/client.h +++ b/engine/client/client.h @@ -999,13 +999,10 @@ void Skin_FlushPlayers(void); //valid.c void Validation_FlushFileList(void); -void ValidationPrintVersion(char *f_query_string); -void Validation_Server(void); -void Validation_FilesModified (void); -void Validation_Skins(void); void Validation_CheckIfResponse(char *text); void InitValidation(void); void Validation_IncludeFile(char *filename, char *file, int filelen); +void Validation_Auto_Response(int playernum, char *s); extern qboolean f_modified_particles; extern qboolean care_f_modified; diff --git a/engine/client/clq3_parse.c b/engine/client/clq3_parse.c index 8d6be1525..ddb30d6e0 100644 --- a/engine/client/clq3_parse.c +++ b/engine/client/clq3_parse.c @@ -442,6 +442,7 @@ qboolean CLQ3_SystemInfoChanged(char *str) char *pc, *pn; char *rc, *rn; + Con_Printf("Server's sv_pure: \"%s\"\n", Info_ValueForKey(str, "sv_pure")); usingpure = atoi(Info_ValueForKey(str, "sv_pure")); usingcheats = atoi(Info_ValueForKey(str, "sv_cheats")); Cvar_ForceCheatVars(usingpure||usingcheats, usingcheats); diff --git a/engine/client/clq3defs.h b/engine/client/clq3defs.h index ec5d8e85e..e0487a0c6 100644 --- a/engine/client/clq3defs.h +++ b/engine/client/clq3defs.h @@ -247,14 +247,6 @@ typedef struct { extern ClientConnectionState_t ccs; -typedef struct { - int handle; - int modificationCount; - float value; - int integer; - char string[256]; -} vmcvar_t; - typedef enum { svcq3_bad, svcq3_nop, diff --git a/engine/client/valid.c b/engine/client/valid.c index 328eff391..fb119b050 100644 --- a/engine/client/valid.c +++ b/engine/client/valid.c @@ -9,88 +9,29 @@ #include #endif -typedef struct f_query_s -{ - char *query; - char *serverinfo; - char *c_userinfo[MAX_CLIENTS]; - qboolean c_exist[MAX_CLIENTS]; - - unsigned short crc; - double timestamp; -} -f_query_t; - -#define F_QUERIES_REMEMBERED 5 -f_query_t f_last_queries[F_QUERIES_REMEMBERED]; -int f_last_query_pos = 0; - typedef struct f_modified_s { char name[MAX_QPATH]; qboolean ismodified; struct f_modified_s *next; } f_modified_t; -f_modified_t *f_modified_list; +static f_modified_t *f_modified_list; qboolean care_f_modified; qboolean f_modified_particles; -qboolean f_modified_staticlights; cvar_t allow_f_version = SCVAR("allow_f_version", "1"); cvar_t allow_f_server = SCVAR("allow_f_server", "1"); cvar_t allow_f_modified = SCVAR("allow_f_modified", "1"); cvar_t allow_f_skins = SCVAR("allow_f_skins", "1"); +cvar_t allow_f_ruleset = SCVAR("allow_f_ruleset", "1"); +cvar_t allow_f_scripts = SCVAR("allow_f_scripts", "1"); +cvar_t allow_f_fakeshaft = SCVAR("allow_f_fakeshaft", "1"); +cvar_t allow_f_system = SCVAR("allow_f_system", "0"); +cvar_t allow_f_cmdline = SCVAR("allow_f_cmdline", "0"); cvar_t auth_validateclients = SCVAR("auth_validateclients", "1"); +cvar_t ruleset = SCVAR("ruleset", "none"); -unsigned short SCRC_GetQueryStateCrc(char *f_query_string) -{ - unsigned short crc; - int i; - char *tmp; - - QCRC_Init(&crc); - - // add query - QCRC_AddBlock(&crc, f_query_string, strlen(f_query_string)); - - // add snapshot of serverinfo - tmp = Info_ValueForKey(cl.serverinfo, "deathmatch"); - QCRC_AddBlock(&crc, tmp, strlen(tmp)); - tmp = Info_ValueForKey(cl.serverinfo, "teamplay"); - QCRC_AddBlock(&crc, tmp, strlen(tmp)); - tmp = Info_ValueForKey(cl.serverinfo, "hostname"); - QCRC_AddBlock(&crc, tmp, strlen(tmp)); - tmp = Info_ValueForKey(cl.serverinfo, "*progs"); - QCRC_AddBlock(&crc, tmp, strlen(tmp)); - tmp = Info_ValueForKey(cl.serverinfo, "map"); - QCRC_AddBlock(&crc, tmp, strlen(tmp)); - tmp = Info_ValueForKey(cl.serverinfo, "spawn"); - QCRC_AddBlock(&crc, tmp, strlen(tmp)); - tmp = Info_ValueForKey(cl.serverinfo, "watervis"); - QCRC_AddBlock(&crc, tmp, strlen(tmp)); - tmp = Info_ValueForKey(cl.serverinfo, "fraglimit"); - QCRC_AddBlock(&crc, tmp, strlen(tmp)); - tmp = Info_ValueForKey(cl.serverinfo, "*gamedir"); - QCRC_AddBlock(&crc, tmp, strlen(tmp)); - tmp = Info_ValueForKey(cl.serverinfo, "timelimit"); - QCRC_AddBlock(&crc, tmp, strlen(tmp)); - - // add snapshot of userinfo for every connected client - for (i=0; i < MAX_CLIENTS; i++) - if (cl.players[i].name[0]) - { - tmp = Info_ValueForKey(cl.players[i].userinfo, "name"); - QCRC_AddBlock(&crc, tmp, strlen(tmp)); - tmp = Info_ValueForKey(cl.players[i].userinfo, "team"); - QCRC_AddBlock(&crc, tmp, strlen(tmp)); - } - - // done - return crc; -} - -#if 1 #define SECURITY_INIT_BAD_CHECKSUM 1 #define SECURITY_INIT_BAD_VERSION 2 @@ -102,36 +43,30 @@ typedef struct signed_buffer_s { unsigned long size; } signed_buffer_t; -typedef signed_buffer_t *(*Security_Verify_Response_t) (int, unsigned char *); +typedef signed_buffer_t *(*Security_Verify_Response_t) (int playernum, unsigned char *, char *userinfo, char *serverinfo); typedef int (*Security_Init_t) (char *); -typedef signed_buffer_t *(*Security_Generate_Crc_t) (int); +typedef signed_buffer_t *(*Security_Generate_Crc_t) (int playernum, char *userinfo, char *serverinfo); typedef signed_buffer_t *(*Security_IsModelModified_t) (char *, int, qbyte *, int); typedef void (*Security_Supported_Binaries_t) (void *); typedef void (*Security_Shutdown_t) (void); -Security_Verify_Response_t Security_Verify_Response; -Security_Init_t Security_Init; -Security_Generate_Crc_t Security_Generate_Crc; -Security_IsModelModified_t Security_IsModelModified; -Security_Supported_Binaries_t Security_Supported_Binaries; -Security_Shutdown_t Security_Shutdown; +static Security_Verify_Response_t Security_Verify_Response; +static Security_Init_t Security_Init; +static Security_Generate_Crc_t Security_Generate_Crc; +static Security_IsModelModified_t Security_IsModelModified; +static Security_Supported_Binaries_t Security_Supported_Binaries; +static Security_Shutdown_t Security_Shutdown; -void *secmodule; +static void *secmodule; -void ValidationPrintVersion(char *f_query_string) +static void Validation_Version(void) { - f_query_t *this_query; - unsigned short query_crc; - //unsigned long crc; //unreferenced - //char answer; //unreferenced - //char name[128]; //unrefernced char sr[256]; -#ifdef RGLQUAKE - char *s; // unreferenced in software only client -#endif - int i; + char *s = sr; + char *auth; + char authbuf[256]; extern cvar_t r_shadow_realtime_world, r_drawflat; @@ -161,7 +96,18 @@ void ValidationPrintVersion(char *f_query_string) #endif #ifdef SWQUAKE case QR_SOFTWARE: - strcpy(sr, (r_pixbytes==4?"32bpp":"8bpp")); + if (r_pixbytes == 4) + { + *s++ = '3'; + *s++ = '2'; + } + else if (r_pixbytes == 2) + { + *s++ = '1'; + *s++ = '6'; + } + else + *s++ = '8'; break; #endif default: @@ -169,85 +115,28 @@ void ValidationPrintVersion(char *f_query_string) break; } + *s = '\0'; + if (!allow_f_version.value) return; //suppress it if (Security_Generate_Crc) { signed_buffer_t *resp; - query_crc = SCRC_GetQueryStateCrc(f_query_string); - // - // remember this f_version - // - this_query = &f_last_queries[f_last_query_pos++ % F_QUERIES_REMEMBERED]; - this_query->timestamp = realtime; - this_query->crc = query_crc; - if (this_query->query) - BZ_Free(this_query->query); - this_query->query = BZ_Malloc(strlen(f_query_string)+1); - strcpy(this_query->query, f_query_string); - if (this_query->serverinfo) - BZ_Free(this_query->serverinfo); - this_query->serverinfo = BZ_Malloc(strlen(cl.serverinfo)+1); - strcpy(this_query->serverinfo, cl.serverinfo); - for (i=0; i < MAX_CLIENTS; i++) - { - if (this_query->c_userinfo[i]) - { - BZ_Free(this_query->c_userinfo[i]); - this_query->c_userinfo[i] = NULL; - } - this_query->c_exist[i] = false; - - if (cl.players[i].name[0]) - { - this_query->c_exist[i] = true; - this_query->c_userinfo[i] = BZ_Malloc(strlen(cl.players[i].userinfo)+1); - strcpy(this_query->c_userinfo[i], cl.players[i].userinfo); - } - } - - resp = Security_Generate_Crc(cl.playernum[0]); - - //now send the data. - -// SPipe_WriteChar(f_write, SECURE_CMD_GETVERSION); -// SPipe_WriteString(f_write, f_query_string); -// SPipe_WriteString(f_write, cl.serverinfo); -// SPipe_WriteString(f_write, cl.players[cl.playernum[0]].userinfo); - - // get answer -// SPipe_ReadChar(f_read, &answer); -// SPipe_ReadString(f_read, name, 64); -// SPipe_ReadUlong(f_read, &crc); -/* - if (answer == SECURE_ANSWER_OK) - { - // reply - Cbuf_AddText("say ", RESTRICT_LOCAL); - Cbuf_AddText(name, RESTRICT_LOCAL); - if (*sr) - Cbuf_AddText(va("/%s/%s", q_renderername, sr), RESTRICT_LOCAL);//extra info - else - Cbuf_AddText(va("/%s", q_renderername), RESTRICT_LOCAL);//extra info - Cbuf_AddText(" ", RESTRICT_LOCAL); - Cbuf_AddText(va("%04x", query_crc), RESTRICT_LOCAL); - Cbuf_AddText(va("%08x", crc), RESTRICT_LOCAL); - Cbuf_AddText("\n", RESTRICT_LOCAL); - return; - } -*/ + resp = Security_Generate_Crc(cl.playernum[0], cl.players[cl.playernum[0]].userinfo, cl.serverinfo); + if (!resp || !resp->buf) + auth = ""; + else + Q_snprintfz(auth, sizeof(authbuf), " crc: %s", resp->buf); } + else + auth = ""; if (*sr) - Cbuf_AddText (va("say "DISTRIBUTION"Quake v%i "PLATFORM"/%s/%s\n", build_number(), q_renderername, sr), RESTRICT_RCON); + Cbuf_AddText (va("say "DISTRIBUTION"Quake v%i "PLATFORM"/%s/%s%s\n", build_number(), q_renderername, sr, auth), RESTRICT_RCON); else - Cbuf_AddText (va("say "DISTRIBUTION"Quake v%i "PLATFORM"/%s\n", build_number(), q_renderername), RESTRICT_RCON); -} -void Validation_FilesModified (void) -{ - Con_Printf ("Not implemented\n", RESTRICT_RCON); + Cbuf_AddText (va("say "DISTRIBUTION"Quake v%i "PLATFORM"/%s%s\n", build_number(), q_renderername, auth), RESTRICT_RCON); } void Validation_CheckIfResponse(char *text) { @@ -323,83 +212,29 @@ void Validation_CheckIfResponse(char *text) //now do the validation { - //f_query_t *query = NULL; - int itemp; - char buffer[10]; - unsigned short query_crc = 0; - unsigned long user_crc = 0; - //unsigned long auth_crc = 0; - //char auth_answer; //unreferenced - - //int slot; //unreferenced signed_buffer_t *resp; - //easy lame way to get the crc from hex. - Q_strncpyS(buffer, crc, 4); - buffer[4] = '\0'; - itemp = 0; - sscanf(buffer, "%x", &itemp); - query_crc = (unsigned long) itemp; - - Q_strncpyS(buffer, crc+4, 8); - buffer[8] = '\0'; - itemp = 0; - sscanf(buffer, "%x", &itemp); - user_crc = (unsigned long) itemp; - - // - // find that query - // -/* for (i=f_last_query_pos; i > f_last_query_pos-F_QUERIES_REMEMBERED; i--) - { - if (query_crc == f_last_queries[i % F_QUERIES_REMEMBERED].crc && - realtime - 5 < f_last_queries[i % F_QUERIES_REMEMBERED].timestamp) - { - query = &f_last_queries[i % F_QUERIES_REMEMBERED]; - } - } - - if (query == NULL) - return; // reply to unknown query - - if (!query->c_exist[f_query_client]) - return; // should never happen -*/ - resp = Security_Verify_Response(f_query_client, crc); + resp = Security_Verify_Response(f_query_client, crc, cl.players[f_query_client].userinfo, cl.serverinfo); if (resp && resp->size && *resp->buf) Con_Printf(S_NOTICE "Authentication Successful.\n"); else// if (!resp) Con_Printf(S_ERROR "AUTHENTICATION FAILED.\n"); - /* - typedef signed_buffer_t *(*Security_Verify_Response_t) (int, unsigned char *); - // write request - SPipe_WriteChar(f_write, SECURE_CMD_CHECKVERSION2); - SPipe_WriteString(f_write, query->query); - SPipe_WriteString(f_write, query->serverinfo); - SPipe_WriteString(f_write, query->c_userinfo[f_query_client]); - SPipe_WriteString(f_write, versionstring); - - // get answer - SPipe_ReadChar(f_read, &auth_answer); - SPipe_ReadUlong(f_read, &auth_crc); - - if (auth_answer == SECURE_ANSWER_YES && auth_crc == user_crc) - { - Con_Printf(S_NOTICE "Authentication Successful.\n"); - } - else - Con_Printf(S_ERROR "AUTHENTICATION FAILED.\n"); - */ } } -void InitValidation(void) +void InitValidation(void) { Cvar_Register(&allow_f_version, "Authentication"); Cvar_Register(&allow_f_server, "Authentication"); Cvar_Register(&allow_f_modified, "Authentication"); Cvar_Register(&allow_f_skins, "Authentication"); + Cvar_Register(&allow_f_ruleset, "Authentication"); + Cvar_Register(&allow_f_fakeshaft, "Authentication"); + Cvar_Register(&allow_f_scripts, "Authentication"); + Cvar_Register(&allow_f_system, "Authentication"); + Cvar_Register(&allow_f_cmdline, "Authentication"); + Cvar_Register(&ruleset, "Authentication"); #ifdef _WIN32 secmodule = LoadLibrary("fteqw-security.dll"); @@ -428,597 +263,35 @@ void InitValidation(void) Con_Printf("'Generic' security error. Stop hacking.\n"); break; case SECURITY_INIT_NOPROC: - Con_Printf("/proc/* does not exist. You will need to upgrade your kernel.\n"); + Con_Printf("/proc/* does not exist. You will need to upgrade/reconfigure your kernel.\n"); break; case 0: Cvar_Register(&auth_validateclients, "Authentication"); return; } - Security_Verify_Response = NULL; - Security_Init = NULL; - Security_Generate_Crc = NULL; - Security_IsModelModified = NULL; - Security_Supported_Binaries = NULL; - Security_Shutdown = NULL; #ifdef _WIN32 FreeLibrary(secmodule); #endif } + Security_Verify_Response = NULL; + Security_Init = NULL; + Security_Generate_Crc = NULL; + Security_IsModelModified = NULL; + Security_Supported_Binaries = NULL; + Security_Shutdown = NULL; } +////////////////////// +//f_modified + void Validation_IncludeFile(char *filename, char *file, int filelen) { } -qboolean f_modified_particles; -qboolean f_modified_staticlights; -qboolean care_f_modified; - - - -#else - - -#ifdef RGLQUAKE -#include "glquake.h" //overkill -#endif - -#ifndef _WIN32 -#include -#endif - -#define ENV_READ_NAME "FTE_SECURE_CHANNEL_READ" -#define ENV_WRITE_NAME "FTE_SECURE_CHANNEL_WRITE" - -#define SECURE_CMD_CHECKMODEL 'c' // q: name:string, model:buffer - // a: 'y' or 'n' - -#define SECURE_CMD_GETVERSION 'g' // q: check_line:string, serverinfo:string, userinfo:string - // a: ok, client_desc:string, crc:ulong - -#define SECURE_CMD_CHECKVERSION 'v' // q: check_line:string, serverinfo:string, userinfo:string - // a: ok, crc:ulong -#define SECURE_CMD_CHECKVERSION2 'r' //SECURE_CMD_CHECKVERSION with the engine description appended on the end. - //let's my front end work on a variety of engines rathar than just 1 - -#define SECURE_ANSWER_OK 'y' -#define SECURE_ANSWER_YES 'y' -#define SECURE_ANSWER_NO 'n' -#define SECURE_ANSWER_ERROR 'n' - - -// -// last f_queries -// -typedef struct f_query_s +static void Validation_FilesModified (void) { - char *query; - char *serverinfo; - char *c_userinfo[MAX_CLIENTS]; - qboolean c_exist[MAX_CLIENTS]; - - unsigned short crc; - double timestamp; + Con_Printf ("Not implemented\n", RESTRICT_RCON); } -f_query_t; - -#define F_QUERIES_REMEMBERED 5 -f_query_t f_last_queries[F_QUERIES_REMEMBERED]; -int f_last_query_pos = 0; - - -qboolean care_f_modified; -qboolean f_modified_particles; - -#ifdef _WIN32 -#include "winquake.h" - -typedef HANDLE qpipe; - -// write to pipe, returns number of bytes written, or 0 = error -int Sys_WritePipe(qpipe q_pipe, unsigned char *buf, int buflen) -{ - DWORD dwBytesWritten; - BOOL ret; - - ret = WriteFile( - q_pipe, - (LPVOID) buf, - buflen, - &dwBytesWritten, - NULL); - - if (ret) - return dwBytesWritten; - else - return 0; -} - -// read from pipe, returns number of bytes read, or 0 = error -int Sys_ReadPipe(qpipe q_pipe, unsigned char *buf, int buflen) -{ - DWORD dwBytesRead; - BOOL ret; - - ret = ReadFile( - q_pipe, - (LPVOID) buf, - buflen, - &dwBytesRead, - NULL); - - if (ret) - return dwBytesRead; - else - return 0; -} -#else -typedef int qpipe; - -int Sys_WritePipe(qpipe q_pipe, unsigned char *buf, int buflen) -{ - return write(q_pipe, buf, buflen); -} - -int Sys_ReadPipe(qpipe q_pipe, unsigned char *buf, int buflen) -{ - return read(q_pipe, buf, buflen); -} -#endif - -static qpipe f_read, f_write; - -int SPipe_ReadMemory(qpipe read_pipe, unsigned char *buf, int buflen) -{ - int completed = 0; - - while (completed < buflen) - { - int read; - - read = Sys_ReadPipe(read_pipe, buf+completed, buflen-completed); - - if (read == 0) - return false; - - completed += read; - } - return true; -} - -int SPipe_ReadChar(qpipe read_pipe, char *c) -{ - return SPipe_ReadMemory(read_pipe, (unsigned char *)c, 1); -} - -int SPipe_ReadInt(qpipe read_pipe, int *val) -{ - return SPipe_ReadMemory(read_pipe, (unsigned char *)val, sizeof(int)); -} - -int SPipe_ReadUlong(qpipe read_pipe, unsigned long *val) -{ - return SPipe_ReadMemory(read_pipe, (unsigned char *)val, sizeof(unsigned long)); -} - -int SPipe_ReadString(qpipe read_pipe, char *buf, int buflen) -{ - int i; - int slen; - if (!SPipe_ReadInt(read_pipe, &slen)) - return false; - - for (i = 0; i < buflen && i < slen; i++) - { - if (!SPipe_ReadChar(read_pipe, buf+i)) - return false; - } - buf[i] = '\0'; - for (; i < slen; i++) //now read the extra data that wouldn't fit. - { - if (!SPipe_ReadChar(read_pipe, buf+i)) - return false; - } - - return true; -} - -int SPipe_WriteMemory(qpipe write_pipe, unsigned char *buf, int buflen) -{ - int completed = 0; - - while (completed < buflen) - { - int written; - - written = Sys_WritePipe(write_pipe, buf+completed, buflen-completed); - - if (written == 0) - return written; - - completed += written; - } - return completed; -} - -int SPipe_WriteChar(qpipe write_pipe, char c) -{ - int written; - written = SPipe_WriteMemory(write_pipe, (unsigned char *)(&c), 1); - - return (written==1); -} - -int SPipe_WriteInt(qpipe write_pipe, int val) -{ - int written; - written = SPipe_WriteMemory(write_pipe, (unsigned char *)(&val), sizeof(int)); - - return (written==sizeof(int)); -} - -int SPipe_WriteString(qpipe write_pipe, char *string) -{ - int i; - int len = strlen(string); - if (!SPipe_WriteInt(write_pipe, len)) - return false; - - for (i = 0; i < len; i++) - if (!SPipe_WriteMemory(write_pipe, (unsigned char *)(string+i), 1)) - return false; - - return true; -} - -void InitValidation(void) -{ - char *read, *write; - read = getenv(ENV_READ_NAME); - write = getenv(ENV_WRITE_NAME); - - Cvar_Register(&allow_f_version, "Authentication"); - Cvar_Register(&allow_f_modified, "Authentication"); - Cvar_Register(&allow_f_skins, "Authentication"); - Cvar_Register(&auth_validateclients, "Authentication"); - - if (!read || !write) - return; - - f_read = (qpipe)atoi(read); - f_write = (qpipe)atoi(write); - - if (!f_read || !f_write) - { - f_write = f_read = 0; - return; - } - -} - -void ValidationThink (void) -{ -} - -void ValidationSendRequest (void) -{ -} - - -void Validation_FilesModified (void) -{ - f_modified_t *fm; - int count=0; - char buf[1024]; - buf[0] = 0; - - if (!allow_f_modified.value) - return; - - care_f_modified = true; - - if (f_modified_particles) - { - strcat(buf, "modified: particles"); - count++; - } - - for (fm = f_modified_list; fm; fm = fm->next) - { - if (fm->ismodified) - { - char *tmp; - if (!count) - strcat(buf, "modified:"); - if (strlen(buf) < 250) - { - tmp = fm->name+1; - while (strchr(tmp, '/')) - tmp = strchr(tmp, '/')+1; - strcat(buf, " "); - strcat(buf, tmp); - count++; - } - else - { - strcat(buf, " & more..."); - break; - } - } - } - if (count == 0) - strcat(buf, "all models ok"); - - Cbuf_AddText("say ", RESTRICT_LOCAL); - Cbuf_AddText(buf, RESTRICT_LOCAL); - Cbuf_AddText("\n", RESTRICT_LOCAL); -} - -void Validation_IncludeFile(char *filename, char *file, int filelen) -{ - char result; - f_modified_t *fm; - - for (fm = f_modified_list; fm; fm = fm->next) - { - if (!strcmp(fm->name, filename)) - break; - } - if (!fm) - { - fm = Z_Malloc(sizeof(f_modified_t)); - fm->next = f_modified_list; - f_modified_list = fm; - Q_strncpyz(fm->name, filename, sizeof(fm->name)); - } - - fm->ismodified = true; - if (f_read && allow_f_modified.value) - { - SPipe_WriteChar(f_write, SECURE_CMD_CHECKMODEL); - SPipe_WriteString(f_write, fm->name); - SPipe_WriteInt (f_write, filelen); - SPipe_WriteMemory(f_write, file, filelen); - - SPipe_ReadChar(f_read, &result); - - if (result == SECURE_ANSWER_YES) - fm->ismodified = false; - } - if (fm->ismodified && care_f_modified) - { - Cbuf_AddText("say previous f_modified response is no longer valid.\n", RESTRICT_LOCAL); - care_f_modified = false; - } -} - -void ValidationPrintVersion(char *f_query_string) -{ - f_query_t *this_query; - unsigned short query_crc; - unsigned long crc; - char answer; - char name[128]; - char sr[256]; - int i; - - switch(qrenderer) - { -#ifdef RGLQUAKE - case QR_OPENGL: - *sr = *""; - break; -#endif -#ifdef SWQUAKE - case QR_SOFTWARE: - strcpy(sr, (r_pixbytes==4?"32bpp":"8bpp")); - break; -#endif - default: - *sr = *""; - break; - } - if (f_read && allow_f_version.value) - { - query_crc = SCRC_GetQueryStateCrc(f_query_string); - - // - // remember this f_version - // - this_query = &f_last_queries[f_last_query_pos++ % F_QUERIES_REMEMBERED]; - this_query->timestamp = realtime; - this_query->crc = query_crc; - if (this_query->query) - BZ_Free(this_query->query); - this_query->query = BZ_Malloc(strlen(f_query_string)+1); - strcpy(this_query->query, f_query_string); - if (this_query->serverinfo) - BZ_Free(this_query->serverinfo); - this_query->serverinfo = BZ_Malloc(strlen(cl.serverinfo)+1); - strcpy(this_query->serverinfo, cl.serverinfo); - for (i=0; i < MAX_CLIENTS; i++) - { - if (this_query->c_userinfo[i]) - { - BZ_Free(this_query->c_userinfo[i]); - this_query->c_userinfo[i] = NULL; - } - this_query->c_exist[i] = false; - - if (cl.players[i].name[0]) - { - this_query->c_exist[i] = true; - this_query->c_userinfo[i] = BZ_Malloc(strlen(cl.players[i].userinfo)+1); - strcpy(this_query->c_userinfo[i], cl.players[i].userinfo); - } - } - - //now send the data. - - SPipe_WriteChar(f_write, SECURE_CMD_GETVERSION); - SPipe_WriteString(f_write, f_query_string); - SPipe_WriteString(f_write, cl.serverinfo); - SPipe_WriteString(f_write, cl.players[cl.playernum[0]].userinfo); - - // get answer - SPipe_ReadChar(f_read, &answer); - SPipe_ReadString(f_read, name, 64); - SPipe_ReadUlong(f_read, &crc); - - if (answer == SECURE_ANSWER_OK) - { - // reply - Cbuf_AddText("say ", RESTRICT_LOCAL); - Cbuf_AddText(name, RESTRICT_LOCAL); - if (*sr) - Cbuf_AddText(va("/%s/%s", q_renderername, sr), RESTRICT_LOCAL);//extra info - else - Cbuf_AddText(va("/%s", q_renderername), RESTRICT_LOCAL);//extra info - Cbuf_AddText(" ", RESTRICT_LOCAL); - Cbuf_AddText(va("%04x", query_crc), RESTRICT_LOCAL); - Cbuf_AddText(va("%08x", crc), RESTRICT_LOCAL); - Cbuf_AddText("\n", RESTRICT_LOCAL); - return; - } - } - - if (*sr) - Cbuf_AddText (va("say "DISTRIBUTION"Quake v%4.3f-%i "PLATFORM"/%s/%s\n", VERSION, build_number(), q_renderername, sr), RESTRICT_RCON); - else - Cbuf_AddText (va("say "DISTRIBUTION"Quake v%4.3f-%i "PLATFORM"/%s\n", VERSION, build_number(), q_renderername), RESTRICT_RCON); -} - -void Validation_CheckIfResponse(char *text) -{ - //client name, version type(os-renderer where it matters, os/renderer where renderer doesn't), 12 char hex crc - int f_query_client; - int i; - char *crc; - char *versionstring; - - if (!f_read) - return; //valid or not, we can't check it. - - if (!auth_validateclients.value) - return; - - //do the parsing. - { - char *comp; - int namelen; - - for (crc = text + strlen(text) - 1; crc > text; crc--) - if (*crc > ' ') - break; - - //find the crc. - for (i = 0; i < 12; i++) - { - if (crc <= text) - return; //not enough chars. - if ((*crc < '0' || *crc > '9') && (*crc < 'a' || *crc > 'f')) - return; //not a hex char. - crc--; - } - - //we now want 3 string seperated tokens, so the first starts at the fourth found ' ' + 1 - i = 4; - for (comp = crc; ; comp--) - { - if (comp < text) - return; - if (*comp == ' ') - { - i--; - if (!i) - break; - } - - } - - versionstring = comp+1; - if (comp <= text) - return; //not enough space for the 'name:' - if (*(comp-1) != ':') - return; //whoops. not a say. - - namelen = comp - text-1; - - for (f_query_client = 0; f_query_client < MAX_CLIENTS; f_query_client++) - { - if (strlen(cl.players[f_query_client].name) == namelen) - if (!strncmp(cl.players[f_query_client].name, text, namelen)) - break; - } - if (f_query_client == MAX_CLIENTS) - return; //looks like a validation, but it's not from a known client. - - crc++; - } - - //now do the validation - { - f_query_t *query = NULL; - int itemp; - char buffer[10]; - unsigned short query_crc = 0; - unsigned long user_crc = 0; - unsigned long auth_crc = 0; - char auth_answer; - - //easy lame way to get the crc from hex. - Q_strncpyS(buffer, crc, 4); - buffer[4] = '\0'; - itemp = 0; - sscanf(buffer, "%x", &itemp); - query_crc = (unsigned long) itemp; - - Q_strncpyS(buffer, crc+4, 8); - buffer[8] = '\0'; - itemp = 0; - sscanf(buffer, "%x", &itemp); - user_crc = (unsigned long) itemp; - - // - // find that query - // - for (i=f_last_query_pos; i > f_last_query_pos-F_QUERIES_REMEMBERED; i--) - { - if (query_crc == f_last_queries[i % F_QUERIES_REMEMBERED].crc && - realtime - 5 < f_last_queries[i % F_QUERIES_REMEMBERED].timestamp) - { - query = &f_last_queries[i % F_QUERIES_REMEMBERED]; - } - } - - if (query == NULL) - return; // reply to unknown query - - if (!query->c_exist[f_query_client]) - return; // should never happen - - // write request - SPipe_WriteChar(f_write, SECURE_CMD_CHECKVERSION2); - SPipe_WriteString(f_write, query->query); - SPipe_WriteString(f_write, query->serverinfo); - SPipe_WriteString(f_write, query->c_userinfo[f_query_client]); - SPipe_WriteString(f_write, versionstring); - - // get answer - SPipe_ReadChar(f_read, &auth_answer); - SPipe_ReadUlong(f_read, &auth_crc); - - if (auth_answer == SECURE_ANSWER_YES && auth_crc == user_crc) - { - Con_Printf(S_NOTICE "Authentication Successful.\n"); - } - else - Con_Printf(S_ERROR "AUTHENTICATION FAILED.\n"); - } -} - - -#endif void Validation_FlushFileList(void) { @@ -1032,12 +305,18 @@ void Validation_FlushFileList(void) } } -void Validation_Server(void) +///////////////////////// +//minor (codewise) responses + +static void Validation_Server(void) { + #warning is allowing the user to turn this off practical?.. + if (!allow_f_server.value) + return; Cbuf_AddText(va("say server is %s\n", NET_AdrToString(cls.netchan.remote_address)), RESTRICT_LOCAL); } -void Validation_Skins(void) +static void Validation_Skins(void) { extern cvar_t r_fullbrightSkins, r_fb_models; int percent = r_fullbrightSkins.value*100; @@ -1045,6 +324,9 @@ void Validation_Skins(void) if (!allow_f_skins.value) return; + RulesetLatch(&r_fb_models); + RulesetLatch(&r_fullbrightSkins); + if (percent < 0) percent = 0; if (percent > cls.allow_fbskins*100) @@ -1056,3 +338,268 @@ void Validation_Skins(void) else Cbuf_AddText("say Only cheaters use full bright skins\n", RESTRICT_LOCAL); } + +static void Validation_Scripts(void) +{ //subset of ruleset + if (!allow_f_scripts.value) + return; + if (ruleset_allow_frj.value) + Cbuf_AddText("say scripts are allowed\n", RESTRICT_LOCAL); + else + Cbuf_AddText("say scripts are capped\n", RESTRICT_LOCAL); +} + +static void Validation_FakeShaft(void) +{ + extern cvar_t cl_truelightning; + if (!allow_f_fakeshaft.value) + return; + if (cl_truelightning.value > 0.999) + Cbuf_AddText("say fakeshaft on\n", RESTRICT_LOCAL); + else if (cl_truelightning.value > 0) + Cbuf_AddText(va("say fakeshaft %.1f%%\n", cl_truelightning.value), RESTRICT_LOCAL); + else + Cbuf_AddText("say fakeshaft off\n", RESTRICT_LOCAL); +} + +static void Validation_System(void) +{ //subset of ruleset + if (!allow_f_system.value) + return; + Cbuf_AddText("say f_system not supported\n", RESTRICT_LOCAL); +} + +static void Validation_CmdLine(void) +{ + if (!allow_f_cmdline.value) + return; + Cbuf_AddText("say f_cmdline not supported\n", RESTRICT_LOCAL); +} + +////////////////////// +//rulesets + +typedef struct { + char *rulename; + char *rulevalue; +} rulesetrule_t; +typedef struct { + char *rulesetname; + + rulesetrule_t *rule; + + qboolean flagged; +} ruleset_t; + +rulesetrule_t rulesetrules_strict[] = { + {"gl_shadeq1", "0"}, + {"gl_shadeq3", "0"}, //FIXME: there needs to be some other way to block these + {"ruleset_allow_playercount", "0"}, + {"ruleset_allow_frj", "0"}, + {"ruleset_allow_packet", "0"}, + {"ruleset_allow_particle_lightning", "0"}, + {"ruleset_allow_overlongsounds", "0"}, + {"ruleset_allow_larger_models", "0"}, + {"tp_disputablemacros", "0"}, + {"cl_instantrotate", "0"}, + {NULL} +}; + +rulesetrule_t rulesetrules_nnql[] = { + {"ruleset_allow_larger_models", "0"}, + {"ruleset_allow_overlong_sounds", "0"}, + {"ruleset_allow_particle_lightning", "0"}, + {"ruleset_allow_packet", "0"}, + {"ruleset_allow_frj", "0"}, + {"ruleset_allow_playercount", "0"}, + {"gl_shadeq1", "0"}, + {"gl_shadeq3", "0"}, + {NULL} +}; + +static ruleset_t rulesets[] = +{ + {"strict", rulesetrules_strict}, + {"nnql", rulesetrules_nnql}, + {NULL} +}; + +void RulesetLatch(cvar_t *cvar) +{ + cvar->flags |= CVAR_RULESETLATCH; +} + +void Validation_DelatchRulesets(void) +{ //game has come to an end, allow the ruleset to be changed + Cvar_ApplyLatches(CVAR_RULESETLATCH); + Con_DPrintf("Ruleset deactivated\n"); +} + +void Validation_Ruleset(void) +{ //this code is more complex than it needs to be + //this allows for the ruleset code to print a ruleset name that is applied via the cvars, but not directly named by the user + cvar_t *var; + ruleset_t *rs; + int i; + char rsnames[1024]; + rs = rulesets; + *rsnames = '\0'; + +#ifndef _MSC_VER +#warning here's a question... Should we latch the ruleset unconditionally, or only when someone actually cares? +#warning if we do it only when someone checks, we have a lot more checking, otherwise we have a freer tournament if the users choose to play that way +#warning I'm going to do it the old-fashioned way +#warning (yes, this is one for molgrum to resolve!) +#endif + for (rs = rulesets; rs->rulesetname; rs++) + { + rs->flagged = false; + + for (i = 0; rs->rule[i].rulename; i++) + { + var = Cvar_FindVar(rs->rule[i].rulename); + if (!var) //sw rendering? + continue; + + if (strcmp(var->string, rs->rule[i].rulevalue)) + break; //current settings don't match + } + if (!rs->rule[i].rulename) + { + if (*rsnames) + { + Q_strncatz(rsnames, ", ", sizeof(rsnames)); + } + Q_strncatz(rsnames, rs->rulesetname, sizeof(rsnames)); + rs->flagged = true; + } + } + if (*rsnames) + { + Cbuf_AddText(va("say Ruleset: %s\n", rsnames), RESTRICT_LOCAL); + + //now we've told the other players what rules we're playing by, we'd best stick to them + for (rs = rulesets; rs->rulesetname; rs++) + { + if (!rs->flagged) + continue; + for (i = 0; rs->rule[i].rulename; i++) + { + var = Cvar_FindVar(rs->rule[i].rulename); + if (!var) + continue; + RulesetLatch(var); //set the latched flag + } + } + } + else + Cbuf_AddText("say No specific ruleset\n", RESTRICT_LOCAL); +} + +void Validation_Apply_Ruleset(void) +{ //rulesets are applied when the client first gets a connection to the server + ruleset_t *rs; + rulesetrule_t *rule; + cvar_t *var; + int i; + +#warning fixme: the following line should not be needed. ensure this is the case + Validation_DelatchRulesets(); //make sure there's no old one + + if (!*ruleset.string || !strcmp(ruleset.string, "none")) + return; //no ruleset is set + + for (rs = rulesets; rs->rulesetname; rs++) + { + if (!stricmp(rs->rulesetname, ruleset.string)) + break; + } + if (!rs->rulesetname) + { + Con_Printf("Cannot apply ruleset %s - not recognised\n", rs->rulesetname); + return; + } + + for (rule = rs->rule; rule->rulename; rule++) + { + for (i = 0; rs->rule[i].rulename; i++) + { + var = Cvar_FindVar(rs->rule[i].rulename); + if (!var) + continue; + + if (!Cvar_ApplyLatchFlag(var, rs->rule[i].rulevalue, CVAR_RULESETLATCH)) + { + Con_Printf("Failed to apply ruleset %s due to cvar %s\n", rs->rulesetname, var->name); + break; + } + } + } + + Con_DPrintf("Ruleset set to %s\n", rs->rulesetname); +} + +////////////////////// + +void Validation_Auto_Response(int playernum, char *s) +{ + static float versionresponsetime; + static float modifiedresponsetime; + static float skinsresponsetime; + static float serverresponsetime; + static float rulesetresponsetime; + static float systemresponsetime; + static float fakeshaftresponsetime; + static float cmdlineresponsetime; + static float scriptsresponsetime; + + if (!strncmp(s, "f_version", 9) && versionresponsetime < Sys_DoubleTime()) //respond to it. + { + Validation_Version(); + versionresponsetime = Sys_DoubleTime() + 5; + } + else if (cl.spectator) + return; + else if (!strncmp(s, "f_server", 8) && serverresponsetime < Sys_DoubleTime()) //respond to it. + { + Validation_Server(); + serverresponsetime = Sys_DoubleTime() + 5; + } + else if (!strncmp(s, "f_system", 8) && systemresponsetime < Sys_DoubleTime()) + { + Validation_System(); + systemresponsetime = Sys_DoubleTime() + 5; + } + else if (!strncmp(s, "f_cmdline", 9) && cmdlineresponsetime < Sys_DoubleTime()) + { + Validation_CmdLine(); + cmdlineresponsetime = Sys_DoubleTime() + 5; + } + else if (!strncmp(s, "f_fakeshaft", 11) && fakeshaftresponsetime < Sys_DoubleTime()) + { + Validation_FakeShaft(); + fakeshaftresponsetime = Sys_DoubleTime() + 5; + } + else if (!strncmp(s, "f_modified", 10) && modifiedresponsetime < Sys_DoubleTime()) //respond to it. + { + Validation_FilesModified(); + modifiedresponsetime = Sys_DoubleTime() + 5; + } + else if (!strncmp(s, "f_scripts", 9) && scriptsresponsetime < Sys_DoubleTime()) + { + Validation_Scripts(); + scriptsresponsetime = Sys_DoubleTime() + 5; + } + else if (!strncmp(s, "f_skins", 7) && skinsresponsetime < Sys_DoubleTime()) //respond to it. + { + Validation_Skins(); + skinsresponsetime = Sys_DoubleTime() + 5; + } + else if (!strncmp(s, "f_ruleset", 9) && rulesetresponsetime < Sys_DoubleTime()) + { + Validation_Ruleset(); + rulesetresponsetime = Sys_DoubleTime() + 5; + } +} + + diff --git a/engine/common/bothdefs.h b/engine/common/bothdefs.h index 00713d520..ccd8101c2 100644 --- a/engine/common/bothdefs.h +++ b/engine/common/bothdefs.h @@ -154,13 +154,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #undef QTERM //not supported - FIXME: move to native plugin #endif -#ifdef __amd64__ - //I'm slowly getting these working in 64bit - #undef Q3CLIENT - #undef Q3SERVER - #undef PLUGINS -#endif - #if (defined(Q2CLIENT) || defined(Q2SERVER)) #ifndef Q2BSPS #error "Q2 game support without Q2BSP support. doesn't make sense" diff --git a/engine/common/com_mesh.c b/engine/common/com_mesh.c index 0e4ea7350..c3b52e371 100644 --- a/engine/common/com_mesh.c +++ b/engine/common/com_mesh.c @@ -2,7 +2,7 @@ #if defined(D3DQUAKE) || defined(RGLQUAKE) || defined(SERVERONLY) #ifdef D3DQUAKE -#include "d3dquake.h" +//#include "d3dquake.h" #endif #ifdef RGLQUAKE #include "glquake.h" @@ -2597,8 +2597,8 @@ qboolean Mod_LoadQ3Model(model_t *mod, void *buffer) md3tag_t *src; md3tag_t *dst; - src = (md3tag_t *)(((unsigned int)header)+LittleLong(header->ofsTags)); - dst = (md3tag_t *)(((unsigned int)root)+root->ofstags); + src = (md3tag_t *)((char*)header+LittleLong(header->ofsTags)); + dst = (md3tag_t *)((char*)root+root->ofstags); for(i=0;inumTags)*LittleLong(header->numFrames);i++) { memcpy(dst->name, src->name, sizeof(dst->name)); diff --git a/engine/common/cvar.c b/engine/common/cvar.c index 639af8db1..ecb5923cb 100644 --- a/engine/common/cvar.c +++ b/engine/common/cvar.c @@ -160,6 +160,8 @@ char *Cvar_FlagToName(int flag) return "rendercallback"; case CVAR_NOUNSAFEEXPAND: return "nounsafeexpand"; + case CVAR_RULESETLATCH: + return "rulesetlatch"; } return NULL; @@ -604,7 +606,7 @@ Cvar_Set ============ */ cvar_t *Cvar_SetCore (cvar_t *var, const char *value, qboolean force) -{ +{ //fixme: force should probably be a latch bitmask char *latch=NULL; if (!var) @@ -722,6 +724,47 @@ cvar_t *Cvar_SetCore (cvar_t *var, const char *value, qboolean force) return var; } +qboolean Cvar_ApplyLatchFlag(cvar_t *var, char *value, int flag) +{ + qboolean result = true; + + char *latch; + var->flags &= ~flag; + latch = var->latched_string; + var->latched_string = NULL; + if (!latch) + { +#ifndef _MSC_VER + #warning this means the callback will never be called +#endif + latch = var->string; + var->string = NULL; + } +#ifndef _MSC_VER +#warning set or forceset? +#endif + Cvar_Set(var, value); + + if (var->latched_string) + { //something else latched it + Z_Free(var->latched_string); + var->latched_string = NULL; + result = false; + } + else + var->flags |= flag; + + if (latch) + { + if (!strcmp(var->string, latch)) + Z_Free(latch); //don't allow a latch to be the same as the current value + else + var->latched_string = latch; + } + + return result; +} + void Cvar_ForceCheatVars(qboolean semicheats, qboolean absolutecheats) { //this either unlatches if the cheat type is allowed, or enforces a default for full cheats and blank for semicheats. //this is clientside only. @@ -741,6 +784,9 @@ void Cvar_ForceCheatVars(qboolean semicheats, qboolean absolutecheats) var->latched_string = NULL; if (!latch) { +#ifndef _MSC_VER + #warning this means the callback will never be called +#endif latch = var->string; var->string = NULL; } @@ -777,8 +823,8 @@ void Cvar_ApplyLatches(int latchflag) int mask = ~0; int of; - if (latchflag == CVAR_SERVEROVERRIDE) //these ones are cleared - mask = ~CVAR_SERVEROVERRIDE; + if (latchflag == CVAR_SERVEROVERRIDE || latchflag == CVAR_RULESETLATCH) //these ones are cleared + mask = ~latchflag; for (grp=cvar_groups ; grp ; grp=grp->next) for (var=grp->cvars ; var ; var=var->next) diff --git a/engine/common/fs.c b/engine/common/fs.c index fd9d8ad17..765b89cf8 100644 --- a/engine/common/fs.c +++ b/engine/common/fs.c @@ -1417,11 +1417,13 @@ void COM_Path_f (void) if (com_purepaths) { + Con_Printf ("Pure paths:\n"); for (s=com_purepaths ; s ; s=s->nextpure) { s->funcs->PrintPath(s->handle); } Con_Printf ("----------\n"); + Con_Printf ("Impure paths:\n"); } @@ -1605,7 +1607,7 @@ void FS_FlushFSHash(void) while(bucket) { next = bucket->next; - if (bucket->keystring == (char*)(bucket+1)) + if (bucket->key.string == (char*)(bucket+1)) Z_Free(bucket); bucket = next; } @@ -2856,10 +2858,14 @@ void FS_ForceToPure(char *str, char *crcs, int seed) if (!str) { //pure isn't in use. + if (com_purepaths) + Con_Printf("Pure FS deactivated\n"); com_purepaths = NULL; FS_FlushFSHash(); return; } + if (!com_purepaths) + Con_Printf("Pure FS activated\n"); for (sp = com_searchpaths; sp; sp = sp->next) { diff --git a/engine/common/plugin.c b/engine/common/plugin.c index 2527a8670..f177152e1 100644 --- a/engine/common/plugin.c +++ b/engine/common/plugin.c @@ -103,7 +103,7 @@ cvar_t plug_loaddefault = SCVAR("plug_loaddefault", "1"); #endif //custom plugin builtins. -typedef int (VARGS *Plug_Builtin_t)(void *offset, unsigned int mask, const long *arg); +typedef int (VARGS *Plug_Builtin_t)(void *offset, unsigned int mask, const int *arg); void Plug_RegisterBuiltin(char *name, Plug_Builtin_t bi, int flags); #define PLUG_BIF_DLLONLY 1 #define PLUG_BIF_QVMONLY 2 @@ -214,7 +214,7 @@ static void Plug_RegisterBuiltinIndex(char *name, Plug_Builtin_t bi, int flags, } */ -int VARGS Plug_FindBuiltin(void *offset, unsigned int mask, const long *args) +int VARGS Plug_FindBuiltin(void *offset, unsigned int mask, const int *args) { int i; for (i = 0; i < numplugbuiltins; i++) @@ -231,7 +231,7 @@ int VARGS Plug_FindBuiltin(void *offset, unsigned int mask, const long *args) return 0; } -long Plug_SystemCallsEx(void *offset, unsigned int mask, int fn, const long *arg) +int Plug_SystemCallsEx(void *offset, unsigned int mask, int fn, const int *arg) { fn = fn+1; @@ -243,7 +243,7 @@ long Plug_SystemCallsEx(void *offset, unsigned int mask, int fn, const long *arg } #ifdef _DEBUG -static long Plug_SystemCallsExWrapper(void *offset, unsigned int mask, int fn, const long *arg) +static int Plug_SystemCallsExWrapper(void *offset, unsigned int mask, int fn, const int *arg) { //this is so we can use edit and continue properly (vc doesn't like function pointers for edit+continue) return Plug_SystemCallsEx(offset, mask, fn, arg); } @@ -254,7 +254,7 @@ static long Plug_SystemCallsExWrapper(void *offset, unsigned int mask, int fn, c //but dlls call it without saying what sort of vm it comes from, so I've got to have them as specifics static int EXPORT_FN Plug_SystemCalls(int arg, ...) { - long args[9]; + int args[9]; va_list argptr; va_start(argptr, arg); @@ -282,7 +282,7 @@ static int EXPORT_FN Plug_SystemCalls(int arg, ...) plugin_t *Plug_Load(char *file) { plugin_t *newplug; - long argarray; + int argarray; for (newplug = plugs; newplug; newplug = newplug->next) { @@ -336,23 +336,23 @@ int Plug_Emumerated (char *name, int size, void *param) return true; } -int VARGS Plug_Con_Print(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Con_Print(void *offset, unsigned int mask, const int *arg) { // if (qrenderer <= 0) // return false; Con_Printf("%s", (char*)VM_POINTER(arg[0])); return 0; } -int VARGS Plug_Sys_Error(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Sys_Error(void *offset, unsigned int mask, const int *arg) { Sys_Error("%s", (char*)offset+arg[0]); return 0; } -int VARGS Plug_Sys_Milliseconds(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Sys_Milliseconds(void *offset, unsigned int mask, const int *arg) { return Sys_DoubleTime()*1000; } -int VARGS Plug_ExportToEngine(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_ExportToEngine(void *offset, unsigned int mask, const int *arg) { char *name = (char*)VM_POINTER(arg[0]); if (!strcmp(name, "Tick")) @@ -387,7 +387,7 @@ int VARGS Plug_ExportToEngine(void *offset, unsigned int mask, const long *arg) } //retrieve a plugin's name -int VARGS Plug_GetPluginName(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_GetPluginName(void *offset, unsigned int mask, const int *arg) { int plugnum = VM_LONG(arg[0]); plugin_t *plug; @@ -414,7 +414,7 @@ int VARGS Plug_GetPluginName(void *offset, unsigned int mask, const long *arg) } typedef void (*funcptr_t) (); -int VARGS Plug_ExportNative(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_ExportNative(void *offset, unsigned int mask, const int *arg) { funcptr_t func; char *name = (char*)VM_POINTER(arg[0]); @@ -470,7 +470,7 @@ typedef struct { int plugincvararraylen; plugincvararray_t *plugincvararray; //qhandle_t Cvar_Register (char *name, char *defaultval, int flags, char *grouphint); -int VARGS Plug_Cvar_Register(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Cvar_Register(void *offset, unsigned int mask, const int *arg) { char *name = VM_POINTER(arg[0]); char *defaultvalue = VM_POINTER(arg[1]); @@ -491,14 +491,15 @@ int VARGS Plug_Cvar_Register(void *offset, unsigned int mask, const long *arg) } } - plugincvararray = BZ_Realloc(plugincvararray, (plugincvararraylen+1)*sizeof(plugincvararray_t)); - plugincvararray[plugincvararraylen].plugin = currentplug; - plugincvararray[plugincvararraylen].var = var; + i = plugincvararraylen; plugincvararraylen++; - return plugincvararraylen-1; + plugincvararray = BZ_Realloc(plugincvararray, (plugincvararraylen)*sizeof(plugincvararray_t)); + plugincvararray[i].plugin = currentplug; + plugincvararray[i].var = var; + return i; } //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. -int VARGS Plug_Cvar_Update(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Cvar_Update(void *offset, unsigned int mask, const int *arg) { int handle; int modcount; @@ -528,7 +529,7 @@ int VARGS Plug_Cvar_Update(void *offset, unsigned int mask, const long *arg) } //void Cmd_Args(char *buffer, int buffersize) -int VARGS Plug_Cmd_Args(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Cmd_Args(void *offset, unsigned int mask, const int *arg) { char *buffer = (char*)VM_POINTER(arg[0]); char *args; @@ -539,7 +540,7 @@ int VARGS Plug_Cmd_Args(void *offset, unsigned int mask, const long *arg) return 1; } //void Cmd_Argv(int num, char *buffer, int buffersize) -int VARGS Plug_Cmd_Argv(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Cmd_Argv(void *offset, unsigned int mask, const int *arg) { char *buffer = (char*)VM_POINTER(arg[1]); char *args; @@ -550,13 +551,13 @@ int VARGS Plug_Cmd_Argv(void *offset, unsigned int mask, const long *arg) return 1; } //int Cmd_Argc(void) -int VARGS Plug_Cmd_Argc(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Cmd_Argc(void *offset, unsigned int mask, const int *arg) { return Cmd_Argc(); } //void Cvar_SetString (char *name, char *value); -int VARGS Plug_Cvar_SetString(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Cvar_SetString(void *offset, unsigned int mask, const int *arg) { char *name = VM_POINTER(arg[0]), *value = VM_POINTER(arg[1]); @@ -571,7 +572,7 @@ int VARGS Plug_Cvar_SetString(void *offset, unsigned int mask, const long *arg) } //void Cvar_SetFloat (char *name, float value); -int VARGS Plug_Cvar_SetFloat(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Cvar_SetFloat(void *offset, unsigned int mask, const int *arg) { char *name = VM_POINTER(arg[0]); float value = VM_FLOAT(arg[1]); @@ -586,7 +587,7 @@ int VARGS Plug_Cvar_SetFloat(void *offset, unsigned int mask, const long *arg) } //void Cvar_GetFloat (char *name); -int VARGS Plug_Cvar_GetFloat(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Cvar_GetFloat(void *offset, unsigned int mask, const int *arg) { char *name = VM_POINTER(arg[0]); int ret; @@ -601,7 +602,7 @@ int VARGS Plug_Cvar_GetFloat(void *offset, unsigned int mask, const long *arg) } //qboolean Cvar_GetString (char *name, char *retstring, int sizeofretstring); -int VARGS Plug_Cvar_GetString(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Cvar_GetString(void *offset, unsigned int mask, const int *arg) { char *name, *ret; int retsize; @@ -626,7 +627,7 @@ int VARGS Plug_Cvar_GetString(void *offset, unsigned int mask, const long *arg) } //void Cmd_AddText (char *text, qboolean insert); //abort the entire engine. -int VARGS Plug_Cmd_AddText(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Cmd_AddText(void *offset, unsigned int mask, const int *arg) { if (VM_LONG(arg[1])) Cbuf_InsertText(VM_POINTER(arg[0]), RESTRICT_LOCAL, false); @@ -665,7 +666,7 @@ void Plug_Command_f(void) currentplug = oldplug; } -int VARGS Plug_Cmd_AddCommand(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Cmd_AddCommand(void *offset, unsigned int mask, const int *arg) { int i; char *name = VM_POINTER(arg[0]); @@ -756,7 +757,7 @@ int Plug_NewStreamHandle(plugstream_e type) //EBUILTIN(int, NET_TCPListen, (char *ip, int port, int maxcount)); //returns a new socket with listen enabled. -int VARGS Plug_Net_TCPListen(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Net_TCPListen(void *offset, unsigned int mask, const int *arg) { int handle; int sock; @@ -815,7 +816,7 @@ int VARGS Plug_Net_TCPListen(void *offset, unsigned int mask, const long *arg) return handle; } -int VARGS Plug_Net_Accept(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Net_Accept(void *offset, unsigned int mask, const int *arg) { int handle = VM_LONG(arg[0]); struct sockaddr_in address; @@ -854,7 +855,7 @@ int VARGS Plug_Net_Accept(void *offset, unsigned int mask, const long *arg) return handle; } //EBUILTIN(int, NET_TCPConnect, (char *ip, int port)); -int VARGS Plug_Net_TCPConnect(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Net_TCPConnect(void *offset, unsigned int mask, const int *arg) { char *localip = VM_POINTER(arg[0]); unsigned short localport = VM_LONG(arg[1]); @@ -910,7 +911,7 @@ int VARGS Plug_Net_TCPConnect(void *offset, unsigned int mask, const long *arg) #ifdef GNUTLS -int VARGS Plug_Net_SetTLSClient(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Net_SetTLSClient(void *offset, unsigned int mask, const int *arg) { static gnutls_anon_client_credentials anoncred; static gnutls_certificate_credentials xcred; @@ -1006,7 +1007,7 @@ int VARGS Plug_Net_SetTLSClient(void *offset, unsigned int mask, const long *arg } #endif -int VARGS Plug_FS_Open(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_FS_Open(void *offset, unsigned int mask, const int *arg) { //modes: //1: read @@ -1061,7 +1062,7 @@ int VARGS Plug_FS_Open(void *offset, unsigned int mask, const long *arg) return -2; } -int VARGS Plug_memset(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_memset(void *offset, unsigned int mask, const int *arg) { if (VM_OOB(arg[0], arg[2])) return false; @@ -1069,7 +1070,7 @@ int VARGS Plug_memset(void *offset, unsigned int mask, const long *arg) memset(VM_POINTER(arg[0]), VM_LONG(arg[1]), VM_LONG(arg[2])); return arg[0]; } -int VARGS Plug_memcpy(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_memcpy(void *offset, unsigned int mask, const int *arg) { if (VM_OOB(arg[0], arg[2])) return false; @@ -1079,7 +1080,7 @@ int VARGS Plug_memcpy(void *offset, unsigned int mask, const long *arg) memcpy(VM_POINTER(arg[0]), VM_POINTER(arg[1]), VM_LONG(arg[2])); return arg[0]; } -int VARGS Plug_memmove(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_memmove(void *offset, unsigned int mask, const int *arg) { if (VM_OOB(arg[0], arg[2])) return false; @@ -1090,32 +1091,32 @@ int VARGS Plug_memmove(void *offset, unsigned int mask, const long *arg) return arg[0]; } -int VARGS Plug_sqrt(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_sqrt(void *offset, unsigned int mask, const int *arg) { int ret; VM_FLOAT(ret) = sqrt(VM_FLOAT(arg[0])); return ret; } -int VARGS Plug_sin(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_sin(void *offset, unsigned int mask, const int *arg) { int ret; VM_FLOAT(ret) = sin(VM_FLOAT(arg[0])); return ret; } -int VARGS Plug_cos(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_cos(void *offset, unsigned int mask, const int *arg) { int ret; VM_FLOAT(ret) = cos(VM_FLOAT(arg[0])); return ret; } -int VARGS Plug_atan2(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_atan2(void *offset, unsigned int mask, const int *arg) { int ret; VM_FLOAT(ret) = atan2(VM_FLOAT(arg[0]), VM_FLOAT(arg[1])); return ret; } -int VARGS Plug_Net_Recv(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Net_Recv(void *offset, unsigned int mask, const int *arg) { int read; int handle = VM_LONG(arg[0]); @@ -1172,7 +1173,7 @@ int VARGS Plug_Net_Recv(void *offset, unsigned int mask, const long *arg) return -2; } } -int VARGS Plug_Net_Send(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Net_Send(void *offset, unsigned int mask, const int *arg) { int written; int handle = VM_LONG(arg[0]); @@ -1228,7 +1229,7 @@ int VARGS Plug_Net_Send(void *offset, unsigned int mask, const long *arg) return -2; } } -int VARGS Plug_Net_SendTo(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Net_SendTo(void *offset, unsigned int mask, const int *arg) { int written; int handle = VM_LONG(arg[0]); @@ -1296,7 +1297,7 @@ void Plug_Net_Close_Internal(int handle) pluginstreamarray[handle].plugin = NULL; } -int VARGS Plug_Net_Close(void *offset, unsigned int mask, const long *arg) +int VARGS Plug_Net_Close(void *offset, unsigned int mask, const int *arg) { int handle = VM_LONG(arg[0]); if (handle < 0 || handle >= pluginstreamarraylen || pluginstreamarray[handle].plugin != currentplug) @@ -1328,7 +1329,7 @@ void Plug_Load_f(void) } } /* -static long Test_SysCalls_Ex(void *offset, unsigned int mask, int fn, const long *arg) +static int Test_SysCalls_Ex(void *offset, unsigned int mask, int fn, const int *arg) { switch(fn) { diff --git a/engine/common/q3common.c b/engine/common/q3common.c index e70da233e..0a0d574e4 100644 --- a/engine/common/q3common.c +++ b/engine/common/q3common.c @@ -308,8 +308,56 @@ int VM_GetFileList(char *path, char *ext, char *output, int buffersize) #include "clq3defs.h" //okay, urr, this is bad for dedicated servers. urhum. Maybe they're not looking? It's only typedefs and one extern. +#define MAX_VMQ3_CVARS 256 //can be blindly increased +cvar_t *q3cvlist[MAX_VMQ3_CVARS]; +int VMQ3_Cvar_Register(vmcvar_t *v, char *name, char *defval, int flags) +{ + int i; + cvar_t *c = Cvar_Get(name, defval, 0, "Q3VM cvars"); + if (!c) //command name, etc + return 0; + for (i = 0; i < MAX_VMQ3_CVARS; i++) + { + if (!q3cvlist[i]) + q3cvlist[i] = c; + if (q3cvlist[i] == c) + { + if (v) + { + v->handle = i+1; + VMQ3_Cvar_Update(v); + } + return i+1; + } + } + Con_Printf("Ran out of VMQ3 cvar handles\n"); + + return 0; +} +int VMQ3_Cvar_Update(vmcvar_t *v) +{ + cvar_t *c; + int i; + i = v->handle; + if (!i) + return 0; //not initialised + i--; + if ((unsigned)i >= MAX_VMQ3_CVARS) + return 0; //a hack attempt + + c = q3cvlist[i]; + if (!c) + return 0; //that slot isn't active yet + + v->integer = c->value; + v->value = c->value; + v->modificationCount = c->modified; + Q_strncpyz(v->string, c->string, sizeof(v->string)); + + return 1; +} /* diff --git a/engine/common/ui_public.h b/engine/common/ui_public.h index 6deeb5929..4c7878438 100644 --- a/engine/common/ui_public.h +++ b/engine/common/ui_public.h @@ -93,7 +93,6 @@ typedef struct { char messageString[MAX_STRING_CHARS]; } uiClientState_t; -#define UI_API_VERSION 5000 typedef enum { UI_GETAPIVERSION = 0, // system reserved @@ -128,12 +127,15 @@ typedef enum { // overlayed over whatever the cgame has drawn. // a GetClientState syscall will be made to get the current strings + +/* UI_DRAWSTATUSBAR = 500, UI_MOUSE_POS, UI_INTERMISSION, UI_FINALE, UI_STRINGCHANGED, //parma is the string id UI_NEWSERVER //indicates that all the strings have changed. +*/ } uiExport_t; typedef enum { @@ -236,12 +238,12 @@ typedef enum { UI_SQRT, UI_FLOOR, UI_CEIL, - +/* UI_CACHE_PIC = 500, UI_PICFROMWAD = 501, UI_GETPLAYERINFO = 502, UI_GETSTAT = 503, UI_GETVIDINFO = 504, UI_GET_STRING = 510, - +*/ } uiImport_t; diff --git a/engine/common/vm.h b/engine/common/vm.h index bb14b5f5c..ccbea8585 100644 --- a/engine/common/vm.h +++ b/engine/common/vm.h @@ -94,4 +94,14 @@ qboolean CG_Command(void); qboolean CG_KeyPress(int key, int down); #endif +typedef struct { + int handle; + int modificationCount; + float value; + int integer; + char string[256]; +} vmcvar_t; +int VMQ3_Cvar_Register(vmcvar_t *v, char *name, char *defval, int flags); +int VMQ3_Cvar_Update(vmcvar_t *v); + #endif diff --git a/engine/d3d/d3dquake.h b/engine/d3d/d3dquake.h index edcb5cc62..0919d7151 100644 --- a/engine/d3d/d3dquake.h +++ b/engine/d3d/d3dquake.h @@ -1,3 +1,10 @@ +#ifndef __D3DQUAKE_H__ +#define __D3DQUAKE_H__ + +#ifdef __GNUC__ +#define _inline static inline +#endif + #include "ddraw.h" #include "d3d.h" #include "d3dx.h" @@ -70,4 +77,7 @@ extern LPDIRECTDRAWSURFACE7 *deluxmap_d3dtextures; extern lightmapinfo_t **lightmap; extern void *d3dexplosiontexture; -extern void *d3dballtexture; \ No newline at end of file +extern void *d3dballtexture; + +#endif + diff --git a/engine/d3d/vid_d3d.c b/engine/d3d/vid_d3d.c index 02a23bea9..000726bf8 100644 --- a/engine/d3d/vid_d3d.c +++ b/engine/d3d/vid_d3d.c @@ -1,5 +1,6 @@ #include "quakedef.h" #ifdef D3DQUAKE +#include "winquake.h" #include "d3dquake.h" diff --git a/engine/d3d9/d3d9_draw.c b/engine/d3d9/d3d9_draw.c index 7cc33f39b..e8a916924 100644 --- a/engine/d3d9/d3d9_draw.c +++ b/engine/d3d9/d3d9_draw.c @@ -1,5 +1,6 @@ #include "quakedef.h" #ifdef D3DQUAKE +#include "winquake.h" #include "d3d9quake.h" #define MAX_WIDTH 512 diff --git a/engine/d3d9/d3d9_rmain.c b/engine/d3d9/d3d9_rmain.c index 5ffe5ff7a..8d1dd61d2 100644 --- a/engine/d3d9/d3d9_rmain.c +++ b/engine/d3d9/d3d9_rmain.c @@ -1,5 +1,6 @@ #include "quakedef.h" #ifdef D3DQUAKE +#include "winquake.h" #include "d3d9quake.h" mleaf_t *r_viewleaf, *r_oldviewleaf; diff --git a/engine/d3d9/d3d9_rsurf.c b/engine/d3d9/d3d9_rsurf.c index 2468087e3..d98379227 100644 --- a/engine/d3d9/d3d9_rsurf.c +++ b/engine/d3d9/d3d9_rsurf.c @@ -1,5 +1,6 @@ #include "quakedef.h" #ifdef D3DQUAKE +#include "winquake.h" #include "d3d9quake.h" int numlightmaps; diff --git a/engine/d3d9/vid_d3d9.c b/engine/d3d9/vid_d3d9.c index 5dc34e807..d2d539a04 100644 --- a/engine/d3d9/vid_d3d9.c +++ b/engine/d3d9/vid_d3d9.c @@ -1,6 +1,7 @@ #include "quakedef.h" #ifdef D3DQUAKE -#include "d3d9quake.h" +#include "winquake.h" +#include "d3d9quake.h" //#include "d3d9.h" @@ -526,7 +527,7 @@ void resetD3D9(void) } -#if WINVER < 0x500 +#if (WINVER < 0x500) && !defined(__GNUC__) typedef struct tagMONITORINFO { DWORD cbSize; diff --git a/engine/gl/gl_backend.c b/engine/gl/gl_backend.c index b6ec98e7a..a65046933 100644 --- a/engine/gl/gl_backend.c +++ b/engine/gl/gl_backend.c @@ -147,13 +147,13 @@ cvar_t r_shownormals = SCVAR("r_shownormals", "1"); float Q_rsqrt( float number ) { - long i; + int i; float x2, y; const float threehalfs = 1.5F; x2 = number * 0.5F; y = number; - i = * ( long * ) &y; // evil floating point bit level hacking + i = * ( int * ) &y; // evil floating point bit level hacking i = 0x5f3759df - ( i >> 1 ); // what the fuck? y = * ( float * ) &i; y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration diff --git a/engine/gl/gl_draw.c b/engine/gl/gl_draw.c index 9f5478fbf..8b55ba2e9 100644 --- a/engine/gl/gl_draw.c +++ b/engine/gl/gl_draw.c @@ -363,6 +363,8 @@ mpic_t *GLDraw_SafePicFromWad (char *name) mpic_t *GLDraw_SafeCachePic (char *path) { + //this is EVIL! WRITE IT! + int height = 0; qbyte *data; glcachepic_t *pic; diff --git a/engine/http/ftpclient.c b/engine/http/ftpclient.c index 046829f3c..b0662d694 100644 --- a/engine/http/ftpclient.c +++ b/engine/http/ftpclient.c @@ -378,6 +378,7 @@ iwboolean FTP_ClientConnThink (FTPclientconn_t *con) //true to kill con if (temp != INVALID_SOCKET) { + int _true = true; ioctlsocket(temp, FIONBIO, &_true); con->stage = 6; if (con->type == ftp_getting) diff --git a/engine/http/ftpserver.c b/engine/http/ftpserver.c index 472498844..82c1b6092 100644 --- a/engine/http/ftpserver.c +++ b/engine/http/ftpserver.c @@ -45,12 +45,11 @@ typedef struct FTPclient_s{ FTPclient_t *FTPclient; -qboolean FTP_ServerInit(void) +qboolean FTP_ServerInit(int port) { struct sockaddr_in address; unsigned long _true = true; int i; - int port = 21; if ((ftpserversocket = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) { @@ -752,7 +751,7 @@ unsigned int WINAPI BlockingClient(FTPclient_t *cl) } #endif -iwboolean FTP_ServerRun(iwboolean ftpserverwanted) +iwboolean FTP_ServerRun(iwboolean ftpserverwanted, int port) { FTPclient_t *cl, *prevcl; struct sockaddr_in from; @@ -763,7 +762,7 @@ unsigned long _true = true; if (!ftpserverinitied) { if (ftpserverwanted) - return FTP_ServerInit(); + return FTP_ServerInit(port); return false; } else if (!ftpserverwanted) diff --git a/engine/http/httpserver.c b/engine/http/httpserver.c index 1ed5a1261..c15aaaa16 100644 --- a/engine/http/httpserver.c +++ b/engine/http/httpserver.c @@ -16,12 +16,11 @@ typedef enum {HTTP_WAITINGFORREQUEST,HTTP_SENDING} http_mode_t; -qboolean HTTP_ServerInit(void) +qboolean HTTP_ServerInit(int port) { struct sockaddr_in address; unsigned long _true = true; int i; - int port = 80; if ((httpserversocket = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) { @@ -331,11 +330,16 @@ cont: cl->mode = HTTP_SENDING; } else if (!stricmp(mode, "GET") || !stricmp(mode, "HEAD") || !stricmp(mode, "POST")) - { + { + if (*resource != '/') + resource[1] = 0; //I'm lazy, they need to comply + Con_Printf("Download request for \"%s\"\n", resource+1); if (!strnicmp(mode, "P", 1)) //when stuff is posted, data is provided. Give an error message if we couldn't do anything with that data. cl->file = IWebGenerateFile(resource+1, content, contentlen); + else if (!SV_AllowDownload(resource+1)) + cl->file = NULL; else - cl->file = FS_OpenVFS(resource, "rb", FS_GAME); + cl->file = FS_OpenVFS(resource+1, "rb", FS_GAME); if (!cl->file) { if (HTTPmarkup >= 3) @@ -477,7 +481,7 @@ notimplemented: } } -qboolean HTTP_ServerPoll(qboolean httpserverwanted) //loop while true +qboolean HTTP_ServerPoll(qboolean httpserverwanted, int portnum) //loop while true { struct sockaddr_in from; int fromlen; @@ -489,7 +493,7 @@ qboolean HTTP_ServerPoll(qboolean httpserverwanted) //loop while true if (!httpserverinitied) { if (httpserverwanted) - return HTTP_ServerInit(); + return HTTP_ServerInit(portnum); return false; } else if (!httpserverwanted) @@ -523,7 +527,14 @@ qboolean HTTP_ServerPoll(qboolean httpserverwanted) //loop while true return false; } - ioctlsocket(clientsock, FIONBIO, &_true); + if (ioctlsocket (clientsock, FIONBIO, &_true) == -1) + { + Con_Printf ("HTTP_ServerInit: ioctl FIONBIO: %s\n", strerror(qerrno)); + closesocket(clientsock); + return false; + } + + Con_Printf("New connection\n"); cl = IWebMalloc(sizeof(HTTP_active_connections_t)); diff --git a/engine/http/iweb.h b/engine/http/iweb.h index a5fcd4dde..200a46e30 100644 --- a/engine/http/iweb.h +++ b/engine/http/iweb.h @@ -120,8 +120,8 @@ char *Q_strcpyline(char *out, char *in, int maxlen); iwboolean FTP_StringToAdr (const char *s, qbyte ip[4], qbyte port[2]); //server tick/control functions -iwboolean FTP_ServerRun(iwboolean ftpserverwanted); -qboolean HTTP_ServerPoll(qboolean httpserverwanted); +iwboolean FTP_ServerRun(iwboolean ftpserverwanted, int port); +qboolean HTTP_ServerPoll(qboolean httpserverwanted, int port); void HTTP_CL_Think(void); qboolean HTTP_CL_Get(char *url, char *localfile, void (*NotifyFunction)(char *localfile, qboolean sucess)); diff --git a/engine/http/iwebiface.c b/engine/http/iwebiface.c index 1a4afb5f3..b5283e612 100644 --- a/engine/http/iwebiface.c +++ b/engine/http/iwebiface.c @@ -311,7 +311,9 @@ IWEBFILE *IWebFOpenRead(char *name) //fread(name, "rb"); #ifndef CLIENTONLY cvar_t ftpserver = SCVAR("sv_ftp", "0"); +cvar_t ftpserver_port = SCVAR("sv_ftp_port", "21"); cvar_t httpserver = SCVAR("sv_http", "0"); +cvar_t httpserver_port = SCVAR("sv_http_port", "80"); cvar_t sv_readlevel = SCVAR("sv_readlevel", "0"); //default to allow anyone cvar_t sv_writelevel = SCVAR("sv_writelevel", "35"); //allowed to write to uploads/uname cvar_t sv_fulllevel = SCVAR("sv_fulllevel", "51"); //allowed to write anywhere, replace any file... @@ -364,7 +366,17 @@ void IWebInit(void) Cvar_Register(&sv_readlevel, "Internet Server Access"); Cvar_Register(&ftpserver, "Internet Server Access"); + Cvar_Register(&ftpserver_port, "Internet Server Access"); Cvar_Register(&httpserver, "Internet Server Access"); + Cvar_Register(&httpserver_port, "Internet Server Access"); + + //don't allow these to be changed easily + //this basically blocks these from rcon / stuffcmd + ftpserver.restriction = RESTRICT_MAX; + httpserver.restriction = RESTRICT_MAX; + sv_fulllevel.restriction = RESTRICT_MAX; + sv_writelevel.restriction = RESTRICT_MAX; + sv_readlevel.restriction = RESTRICT_MAX; #endif } void IWebRun(void) @@ -372,8 +384,8 @@ void IWebRun(void) #ifdef WEBSERVER extern qboolean httpserverfailed, ftpserverfailed; - FTP_ServerRun(ftpserver.value!= 0); - HTTP_ServerPoll(httpserver.value!=0); + FTP_ServerRun(ftpserver.value!= 0, ftpserver_port.value); + HTTP_ServerPoll(httpserver.value!=0, httpserver_port.value); if (ftpserverfailed) { Con_Printf("FTP Server failed to load, setting %s to 0\n", ftpserver.name); diff --git a/engine/http/webgen.c b/engine/http/webgen.c index 1b11ec7af..0742b1da7 100644 --- a/engine/http/webgen.c +++ b/engine/http/webgen.c @@ -321,7 +321,7 @@ typedef struct { IWebFile_t IWebFiles[] = { {"allplayers.html", IWeb_GenerateRankingsFile}, {"index.html", IWeb_GenerateIndexFile}, - {"admin.html", IWeb_GenerateAdminFile} +//code is too flawed for this {"admin.html", IWeb_GenerateAdminFile} }; typedef struct { @@ -409,6 +409,7 @@ vfsfile_t *IWebGenerateFile(char *name, char *content, int contentlength) int fnum; char *parms; int len; + IWeb_FileGen_t *fbuf; if (!sv.state) return NULL; @@ -434,7 +435,7 @@ vfsfile_t *IWebGenerateFile(char *name, char *content, int contentlength) { if (IWebFiles[fnum].buffer) { - if (IWebFiles[fnum].lastgenerationtime+10 < Sys_DoubleTime() || contentlength||*parms) //10 sec lifetime + if (IWebFiles[fnum].lastgenerationtime < Sys_DoubleTime()) { IWebFiles[fnum].buffer->references--; //remove our reference and check free if (IWebFiles[fnum].buffer->references<=0) @@ -452,7 +453,8 @@ vfsfile_t *IWebGenerateFile(char *name, char *content, int contentlength) IWebFiles[fnum].buffer = IWeb_GenerationBuffer; //so it can't be sent once and freed instantly. - IWebFiles[fnum].lastgenerationtime = Sys_DoubleTime(); + if (contentlength) + IWebFiles[fnum].lastgenerationtime = Sys_DoubleTime()+10; } IWebFiles[fnum].buffer->references++; IWeb_GenerationBuffer = NULL; diff --git a/engine/libs/dxsdk7/include/d3d.h b/engine/libs/dxsdk7/include/d3d.h index ae69335b8..d75d14c9f 100644 --- a/engine/libs/dxsdk7/include/d3d.h +++ b/engine/libs/dxsdk7/include/d3d.h @@ -212,7 +212,7 @@ DECLARE_INTERFACE_(IDirect3D, IUnknown) STDMETHOD(FindDevice)(THIS_ LPD3DFINDDEVICESEARCH,LPD3DFINDDEVICERESULT) PURE; }; -typedef struct IDirect3D *LPDIRECT3D; +//*sigh*... typedef struct IDirect3D *LPDIRECT3D; #if !defined(__cplusplus) || defined(CINTERFACE) #define IDirect3D_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) @@ -256,7 +256,7 @@ DECLARE_INTERFACE_(IDirect3D2, IUnknown) STDMETHOD(CreateDevice)(THIS_ REFCLSID,LPDIRECTDRAWSURFACE,LPDIRECT3DDEVICE2*) PURE; }; -typedef struct IDirect3D2 *LPDIRECT3D2; +//typedef struct IDirect3D2 *LPDIRECT3D2; #if !defined(__cplusplus) || defined(CINTERFACE) #define IDirect3D2_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) @@ -304,7 +304,7 @@ DECLARE_INTERFACE_(IDirect3D3, IUnknown) STDMETHOD(EvictManagedTextures)(THIS) PURE; }; -typedef struct IDirect3D3 *LPDIRECT3D3; +//this could take a while typedef struct IDirect3D3 *LPDIRECT3D3; #if !defined(__cplusplus) || defined(CINTERFACE) #define IDirect3D3_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) @@ -354,7 +354,7 @@ DECLARE_INTERFACE_(IDirect3D7, IUnknown) STDMETHOD(EvictManagedTextures)(THIS) PURE; }; -typedef struct IDirect3D7 *LPDIRECT3D7; +//gcc is kinda fussy typedef struct IDirect3D7 *LPDIRECT3D7; #if !defined(__cplusplus) || defined(CINTERFACE) #define IDirect3D7_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) @@ -411,7 +411,7 @@ DECLARE_INTERFACE_(IDirect3DDevice, IUnknown) STDMETHOD(GetDirect3D)(THIS_ LPDIRECT3D*) PURE; }; -typedef struct IDirect3DDevice *LPDIRECT3DDEVICE; +//getting bored already typedef struct IDirect3DDevice *LPDIRECT3DDEVICE; #if !defined(__cplusplus) || defined(CINTERFACE) #define IDirect3DDevice_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) @@ -505,7 +505,7 @@ DECLARE_INTERFACE_(IDirect3DDevice2, IUnknown) STDMETHOD(GetClipStatus)(THIS_ LPD3DCLIPSTATUS) PURE; }; -typedef struct IDirect3DDevice2 *LPDIRECT3DDEVICE2; +//typedef struct IDirect3DDevice2 *LPDIRECT3DDEVICE2; #if !defined(__cplusplus) || defined(CINTERFACE) #define IDirect3DDevice2_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) @@ -631,7 +631,7 @@ DECLARE_INTERFACE_(IDirect3DDevice3, IUnknown) STDMETHOD(ValidateDevice)(THIS_ LPDWORD) PURE; }; -typedef struct IDirect3DDevice3 *LPDIRECT3DDEVICE3; +//dum de dum typedef struct IDirect3DDevice3 *LPDIRECT3DDEVICE3; #if !defined(__cplusplus) || defined(CINTERFACE) #define IDirect3DDevice3_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) @@ -782,7 +782,7 @@ DECLARE_INTERFACE_(IDirect3DDevice7, IUnknown) STDMETHOD(GetInfo)(THIS_ DWORD,LPVOID,DWORD) PURE; }; -typedef struct IDirect3DDevice7 *LPDIRECT3DDEVICE7; +//they are at least consistant typedef struct IDirect3DDevice7 *LPDIRECT3DDEVICE7; #if !defined(__cplusplus) || defined(CINTERFACE) #define IDirect3DDevice7_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) @@ -910,7 +910,7 @@ DECLARE_INTERFACE_(IDirect3DExecuteBuffer, IUnknown) STDMETHOD(Optimize)(THIS_ DWORD) PURE; }; -typedef struct IDirect3DExecuteBuffer *LPDIRECT3DEXECUTEBUFFER; +//did anyone ever like this object anyway? typedef struct IDirect3DExecuteBuffer *LPDIRECT3DEXECUTEBUFFER; #if !defined(__cplusplus) || defined(CINTERFACE) #define IDirect3DExecuteBuffer_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) @@ -955,7 +955,7 @@ DECLARE_INTERFACE_(IDirect3DLight, IUnknown) STDMETHOD(GetLight)(THIS_ LPD3DLIGHT) PURE; }; -typedef struct IDirect3DLight *LPDIRECT3DLIGHT; +//slow typedef struct IDirect3DLight *LPDIRECT3DLIGHT; #if !defined(__cplusplus) || defined(CINTERFACE) #define IDirect3DLight_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) @@ -995,7 +995,7 @@ DECLARE_INTERFACE_(IDirect3DMaterial, IUnknown) STDMETHOD(Unreserve)(THIS) PURE; }; -typedef struct IDirect3DMaterial *LPDIRECT3DMATERIAL; +//so many of these! typedef struct IDirect3DMaterial *LPDIRECT3DMATERIAL; #if !defined(__cplusplus) || defined(CINTERFACE) #define IDirect3DMaterial_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) @@ -1036,7 +1036,7 @@ DECLARE_INTERFACE_(IDirect3DMaterial2, IUnknown) STDMETHOD(GetHandle)(THIS_ LPDIRECT3DDEVICE2,LPD3DMATERIALHANDLE) PURE; }; -typedef struct IDirect3DMaterial2 *LPDIRECT3DMATERIAL2; +//and other errors to fix after these, lucky me! typedef struct IDirect3DMaterial2 *LPDIRECT3DMATERIAL2; #if !defined(__cplusplus) || defined(CINTERFACE) #define IDirect3DMaterial2_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) @@ -1072,7 +1072,7 @@ DECLARE_INTERFACE_(IDirect3DMaterial3, IUnknown) STDMETHOD(GetHandle)(THIS_ LPDIRECT3DDEVICE3,LPD3DMATERIALHANDLE) PURE; }; -typedef struct IDirect3DMaterial3 *LPDIRECT3DMATERIAL3; +//this is getting dull typedef struct IDirect3DMaterial3 *LPDIRECT3DMATERIAL3; #if !defined(__cplusplus) || defined(CINTERFACE) #define IDirect3DMaterial3_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) @@ -1112,7 +1112,7 @@ DECLARE_INTERFACE_(IDirect3DTexture, IUnknown) STDMETHOD(Unload)(THIS) PURE; }; -typedef struct IDirect3DTexture *LPDIRECT3DTEXTURE; +//monkey typedef struct IDirect3DTexture *LPDIRECT3DTEXTURE; #if !defined(__cplusplus) || defined(CINTERFACE) #define IDirect3DTexture_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) @@ -1151,7 +1151,7 @@ DECLARE_INTERFACE_(IDirect3DTexture2, IUnknown) STDMETHOD(Load)(THIS_ LPDIRECT3DTEXTURE2) PURE; }; -typedef struct IDirect3DTexture2 *LPDIRECT3DTEXTURE2; +//*snore* typedef struct IDirect3DTexture2 *LPDIRECT3DTEXTURE2; #if !defined(__cplusplus) || defined(CINTERFACE) #define IDirect3DTexture2_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) @@ -1199,7 +1199,7 @@ DECLARE_INTERFACE_(IDirect3DViewport, IUnknown) STDMETHOD(NextLight)(THIS_ LPDIRECT3DLIGHT,LPDIRECT3DLIGHT*,DWORD) PURE; }; -typedef struct IDirect3DViewport *LPDIRECT3DVIEWPORT; +//*yawn* typedef struct IDirect3DViewport *LPDIRECT3DVIEWPORT; #if !defined(__cplusplus) || defined(CINTERFACE) #define IDirect3DViewport_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) @@ -1266,7 +1266,7 @@ DECLARE_INTERFACE_(IDirect3DViewport2, IDirect3DViewport) STDMETHOD(SetViewport2)(THIS_ LPD3DVIEWPORT2) PURE; }; -typedef struct IDirect3DViewport2 *LPDIRECT3DVIEWPORT2; +//they could have coded this right in the first place, you know typedef struct IDirect3DViewport2 *LPDIRECT3DVIEWPORT2; #if !defined(__cplusplus) || defined(CINTERFACE) #define IDirect3DViewport2_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) @@ -1342,7 +1342,7 @@ DECLARE_INTERFACE_(IDirect3DViewport3, IDirect3DViewport2) STDMETHOD(Clear2)(THIS_ DWORD,LPD3DRECT,DWORD,D3DCOLOR,D3DVALUE,DWORD) PURE; }; -typedef struct IDirect3DViewport3 *LPDIRECT3DVIEWPORT3; +//not too many of these left to go typedef struct IDirect3DViewport3 *LPDIRECT3DVIEWPORT3; #if !defined(__cplusplus) || defined(CINTERFACE) #define IDirect3DViewport3_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) @@ -1410,7 +1410,7 @@ DECLARE_INTERFACE_(IDirect3DVertexBuffer, IUnknown) STDMETHOD(Optimize)(THIS_ LPDIRECT3DDEVICE3,DWORD) PURE; }; -typedef struct IDirect3DVertexBuffer *LPDIRECT3DVERTEXBUFFER; +//nearly there typedef struct IDirect3DVertexBuffer *LPDIRECT3DVERTEXBUFFER; #if !defined(__cplusplus) || defined(CINTERFACE) #define IDirect3DVertexBuffer_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) @@ -1453,7 +1453,7 @@ DECLARE_INTERFACE_(IDirect3DVertexBuffer7, IUnknown) STDMETHOD(ProcessVerticesStrided)(THIS_ DWORD,DWORD,DWORD,LPD3DDRAWPRIMITIVESTRIDEDDATA,DWORD,LPDIRECT3DDEVICE7,DWORD) PURE; }; -typedef struct IDirect3DVertexBuffer7 *LPDIRECT3DVERTEXBUFFER7; +//well that was painful typedef struct IDirect3DVertexBuffer7 *LPDIRECT3DVERTEXBUFFER7; #if !defined(__cplusplus) || defined(CINTERFACE) #define IDirect3DVertexBuffer7_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) diff --git a/engine/qclib/hash.c b/engine/qclib/hash.c index 8b453401c..5b0f2d88e 100644 --- a/engine/qclib/hash.c +++ b/engine/qclib/hash.c @@ -45,7 +45,7 @@ void *Hash_Get(hashtable_t *table, char *name) while(buck) { - if (!STRCMP(name, buck->keystring)) + if (!STRCMP(name, buck->key.string)) return buck->data; buck = buck->next; @@ -61,7 +61,7 @@ void *Hash_GetInsensative(hashtable_t *table, char *name) while(buck) { - if (!stricmp(name, buck->keystring)) + if (!stricmp(name, buck->key.string)) return buck->data; buck = buck->next; @@ -77,7 +77,7 @@ void *Hash_GetKey(hashtable_t *table, int key) while(buck) { - if ((int)buck->keystring == key) + if (buck->key.value == key) return buck->data; buck = buck->next; @@ -93,7 +93,7 @@ void *Hash_GetNext(hashtable_t *table, char *name, void *old) while(buck) { - if (!STRCMP(name, buck->keystring)) + if (!STRCMP(name, buck->key.string)) { if (buck->data == old) //found the old one break; @@ -107,7 +107,7 @@ void *Hash_GetNext(hashtable_t *table, char *name, void *old) buck = buck->next;//don't return old while(buck) { - if (!STRCMP(name, buck->keystring)) + if (!STRCMP(name, buck->key.string)) return buck->data; buck = buck->next; @@ -123,7 +123,7 @@ void *Hash_GetNextInsensative(hashtable_t *table, char *name, void *old) while(buck) { - if (!STRCMP(name, buck->keystring)) + if (!STRCMP(name, buck->key.string)) { if (buck->data == old) //found the old one break; @@ -137,7 +137,7 @@ void *Hash_GetNextInsensative(hashtable_t *table, char *name, void *old) buck = buck->next;//don't return old while(buck) { - if (!STRCMP(name, buck->keystring)) + if (!STRCMP(name, buck->key.string)) return buck->data; buck = buck->next; @@ -151,7 +151,7 @@ void *Hash_Add(hashtable_t *table, char *name, void *data, bucket_t *buck) int bucknum = Hash_Key(name, table->numbuckets); buck->data = data; - buck->keystring = name; + buck->key.string = name; buck->next = table->bucket[bucknum]; table->bucket[bucknum] = buck; @@ -162,7 +162,7 @@ void *Hash_AddInsensative(hashtable_t *table, char *name, void *data, bucket_t * int bucknum = Hash_KeyInsensative(name, table->numbuckets); buck->data = data; - buck->keystring = name; + buck->key.string = name; buck->next = table->bucket[bucknum]; table->bucket[bucknum] = buck; @@ -173,7 +173,7 @@ void *Hash_AddKey(hashtable_t *table, int key, void *data, bucket_t *buck) int bucknum = key%table->numbuckets; buck->data = data; - buck->keystring = (char*)key; + buck->key.value = key; buck->next = table->bucket[bucknum]; table->bucket[bucknum] = buck; @@ -187,7 +187,7 @@ void Hash_Remove(hashtable_t *table, char *name) buck = table->bucket[bucknum]; - if (!STRCMP(name, buck->keystring)) + if (!STRCMP(name, buck->key.string)) { table->bucket[bucknum] = buck->next; return; @@ -196,7 +196,7 @@ void Hash_Remove(hashtable_t *table, char *name) while(buck->next) { - if (!STRCMP(name, buck->next->keystring)) + if (!STRCMP(name, buck->next->key.string)) { buck->next = buck->next->next; return; @@ -215,7 +215,7 @@ void Hash_RemoveData(hashtable_t *table, char *name, void *data) buck = table->bucket[bucknum]; if (buck->data == data) - if (!STRCMP(name, buck->keystring)) + if (!STRCMP(name, buck->key.string)) { table->bucket[bucknum] = buck->next; return; @@ -225,7 +225,7 @@ void Hash_RemoveData(hashtable_t *table, char *name, void *data) while(buck->next) { if (buck->next->data == data) - if (!STRCMP(name, buck->next->keystring)) + if (!STRCMP(name, buck->next->key.string)) { buck->next = buck->next->next; return; @@ -244,7 +244,7 @@ void Hash_RemoveKey(hashtable_t *table, int key) buck = table->bucket[bucknum]; - if ((int)buck->keystring == key) + if (buck->key.value == key) { table->bucket[bucknum] = buck->next; return; @@ -253,7 +253,7 @@ void Hash_RemoveKey(hashtable_t *table, int key) while(buck->next) { - if ((int)buck->next->keystring == key) + if (buck->next->key.value == key) { buck->next = buck->next->next; return; diff --git a/engine/qclib/hash.h b/engine/qclib/hash.h index af55d444d..a46e38011 100644 --- a/engine/qclib/hash.h +++ b/engine/qclib/hash.h @@ -7,7 +7,10 @@ #define STRCMP(s1,s2) (((*s1)!=(*s2)) || strcmp(s1+1,s2+1)) //saves about 2-6 out of 120 - expansion of idea from fastqcc typedef struct bucket_s { void *data; - char *keystring; + union { + char *string; + int value; + } key; struct bucket_s *next; } bucket_t; typedef struct hashtable_s { diff --git a/engine/server/pr_cmds.c b/engine/server/pr_cmds.c index 69a5ac0b1..b0a461ee1 100644 --- a/engine/server/pr_cmds.c +++ b/engine/server/pr_cmds.c @@ -447,6 +447,7 @@ void PR_Deinit(void) #define PREREL_PROGHEADER_CRC 26940 //prerelease #define H2_PROGHEADER_CRC 38488 //basic hexen2 #define H2MP_PROGHEADER_CRC 26905 //hexen2 mission pack uses slightly different defs... *sigh*... +#define H2DEMO_PROGHEADER_CRC 14046 //I'm guessing this is from the original release or something void PR_LoadGlabalStruct(void) { @@ -664,6 +665,8 @@ progsnum_t AddProgs(char *name) num = PR_LoadProgs (svprogfuncs, name, H2_PROGHEADER_CRC, NULL, 0); if (num == -1) //don't commit if bad. num = PR_LoadProgs (svprogfuncs, name, H2MP_PROGHEADER_CRC, NULL, 0); + if (num == -1) + num = PR_LoadProgs (svprogfuncs, name, H2DEMO_PROGHEADER_CRC, NULL, 0); if (num == -1) //don't commit if bad. { progstype = PROG_PREREL; @@ -1388,9 +1391,9 @@ qboolean PR_GameCodePacket(char *s) - G_INT(OFS_PARM0) = (int)NET_AdrToString (net_from); + G_INT(OFS_PARM0) = PR_SetString(svprogfuncs, NET_AdrToString (net_from)); - G_INT(OFS_PARM1) = (int)PR_SetString(svprogfuncs, s); + G_INT(OFS_PARM1) = PR_SetString(svprogfuncs, s); PR_ExecuteProgram (svprogfuncs, SV_ParseConnectionlessPacket); return G_FLOAT(OFS_RETURN); } @@ -2006,7 +2009,7 @@ void PF_setmodel_Internal (progfuncs_t *prinst, edict_t *e, char *m) // if it is an inline model, get the size information for it if (m[0] == '*' || (*m&&progstype == PROG_H2)) { - mod = Mod_ForName (m, true); + mod = Mod_ForName (m, false); if (mod) { VectorCopy (mod->mins, e->v->mins); @@ -3758,7 +3761,7 @@ void PF_precache_model_Internal (progfuncs_t *prinst, char *s) if (s[0] <= ' ') { - PR_BIError (prinst, "Bad string"); + Con_Printf ("precache_model: empty string\n"); return; } diff --git a/engine/server/svq3_game.c b/engine/server/svq3_game.c index b114f8db0..952bb6530 100644 --- a/engine/server/svq3_game.c +++ b/engine/server/svq3_game.c @@ -8,7 +8,7 @@ float RadiusFromBounds (vec3_t mins, vec3_t maxs); -#define USEBOTLIB +//#define USEBOTLIB #ifdef USEBOTLIB @@ -19,7 +19,7 @@ float RadiusFromBounds (vec3_t mins, vec3_t maxs); #else #define QDECL #endif -#define fileHandle_t char* +#define fileHandle_t int #define fsMode_t int #define pc_token_t void #include "botlib.h" @@ -64,7 +64,7 @@ float RadiusFromBounds (vec3_t mins, vec3_t maxs); handle = dlopen("botlib.so", RTLD_LAZY); if (!handle) return NULL; - + pGetBotLibAPI = dlsym(handle, "GetBotLibAPI"); if (!pGetBotLibAPI) return NULL; @@ -219,7 +219,7 @@ void QDECL Com_sprintf( char *dest, int size, const char *fmt, ...) #include "clq3defs.h" #include "q3g_public.h" -vm_t *q3gamevm; +static vm_t *q3gamevm; #define fs_key 0 @@ -874,7 +874,7 @@ void SVQ3_Adjust_Area_Portal_State(q3sharedEntity_t *ge, qboolean open) } #define VALIDATEPOINTER(o,l) if ((int)o + l >= mask || VM_POINTER(o) < offset) SV_Error("Call to game trap %i passes invalid pointer\n", fn); //out of bounds. -long Q3G_SystemCallsEx(void *offset, unsigned int mask, int fn, const long *arg) +int Q3G_SystemCallsEx(void *offset, unsigned int mask, int fn, const int *arg) { int ret = 0; switch(fn) @@ -891,37 +891,10 @@ long Q3G_SystemCallsEx(void *offset, unsigned int mask, int fn, const long *arg) case G_CVAR_REGISTER:// ( vmCvar_t *vmCvar, const char *varName, const char *defaultValue, int flags ); if (arg[0]) VALIDATEPOINTER(arg[0], sizeof(vmcvar_t)); - { - vmcvar_t *vmc; - cvar_t *var; - vmc = VM_POINTER(arg[0]); - var = Cvar_Get(VM_POINTER(arg[1]), VM_POINTER(arg[2]), 0/*VM_LONG(arg[3])*/, "Q3-Game-Code created"); - if (!vmc) //qvm doesn't need to retreive it - break; - vmc->handle = (char *)var - (char *)offset; - - vmc->integer = var->value; - vmc->value = var->value; - vmc->modificationCount = var->modified; - Q_strncpyz(vmc->string, var->string, sizeof(vmc->string)); - } - break; + return VMQ3_Cvar_Register(VM_POINTER(arg[0]), VM_POINTER(arg[1]), VM_POINTER(arg[2]), VM_LONG(arg[3])); case G_CVAR_UPDATE:// ( vmCvar_t *vmCvar ); VALIDATEPOINTER(arg[0], sizeof(vmcvar_t)); - { - cvar_t *var; - vmcvar_t *vmc; - vmc = VM_POINTER(arg[0]); - var = (cvar_t *)((int)vmc->handle + (char *)offset); - if (!var || !vmc->handle) - return false; - - vmc->integer = var->value; - vmc->value = var->value; - vmc->modificationCount = var->modified; - Q_strncpyz(vmc->string, var->string, sizeof(vmc->string)); - } - break; + return VMQ3_Cvar_Update(VM_POINTER(arg[0])); case G_CVAR_SET:// ( const char *var_name, const char *value ); { @@ -1061,6 +1034,8 @@ long Q3G_SystemCallsEx(void *offset, unsigned int mask, int fn, const long *arg) case G_GET_USERINFO://int num, char *buffer, int bufferSize 20 if (VM_OOB(arg[1], arg[2])) return 0; + if ((unsigned)VM_LONG(arg[0]) >= sv.allocated_client_slots) + return 0; Q_strncpyz(VM_POINTER(arg[1]), svs.clients[VM_LONG(arg[0])].userinfo, VM_LONG(arg[2])); break; @@ -1087,7 +1062,7 @@ long Q3G_SystemCallsEx(void *offset, unsigned int mask, int fn, const long *arg) case G_ENTITIES_IN_BOX: // ( const vec3_t mins, const vec3_t maxs, gentity_t **list, int maxcount ); 32 // EntitiesInBox will return brush models based on their bounding box, // so exact determination must still be done with EntityContact - VALIDATEPOINTER(arg[2], sizeof(int*)*VM_LONG(arg[3])); + VALIDATEPOINTER(arg[2], sizeof(int)*VM_LONG(arg[3])); return SVQ3_EntitiesInBox(VM_POINTER(arg[0]), VM_POINTER(arg[1]), VM_POINTER(arg[2]), VM_LONG(arg[3])); case G_ADJUST_AREA_PORTAL_STATE: @@ -1122,15 +1097,26 @@ long Q3G_SystemCallsEx(void *offset, unsigned int mask, int fn, const long *arg) // standard Q3 case G_MEMSET: VALIDATEPOINTER(arg[0], arg[2]); - memset(VM_POINTER(arg[0]), arg[1], arg[2]); + { + void *dst = VM_POINTER(arg[0]); + memset(dst, arg[1], arg[2]); + } break; case G_MEMCPY: VALIDATEPOINTER(arg[0], arg[2]); - memmove(VM_POINTER(arg[0]), VM_POINTER(arg[1]), arg[2]); + { + void *dst = VM_POINTER(arg[0]); + void *src = VM_POINTER(arg[1]); + memmove(dst, src, arg[2]); + } break; case G_STRNCPY: VALIDATEPOINTER(arg[0], arg[2]); - Q_strncpyS(VM_POINTER(arg[0]), VM_POINTER(arg[1]), arg[2]); + { + void *dst = VM_POINTER(arg[0]); + void *src = VM_POINTER(arg[1]); + Q_strncpyS(src, dst, arg[2]); + } break; case G_SIN: VM_FLOAT(ret)=(float)sin(VM_FLOAT(arg[0])); @@ -1592,7 +1578,7 @@ long Q3G_SystemCallsEx(void *offset, unsigned int mask, int fn, const long *arg) int EXPORT_FN Q3G_SystemCalls(int arg, ...) { - long args[13]; + int args[13]; va_list argptr; va_start(argptr, arg); @@ -1849,6 +1835,7 @@ qboolean SVQ3_InitGame(void) char *str; char sysinfo[8192]; extern cvar_t progs; + cvar_t *sv_pure; if (sv.worldmodel->type == mod_heightmap) { @@ -1900,13 +1887,14 @@ qboolean SVQ3_InitGame(void) str = FS_GetPackNames(buffer, sizeof(buffer), true); Info_SetValueForKey(sysinfo, "sv_referencedPakNames", str, MAX_SERVERINFO_STRING); - Info_SetValueForKey(sysinfo, "sv_pure", "1", MAX_SERVERINFO_STRING); + sv_pure = Cvar_Get("sv_pure", "1", 0, "Q3 compatability"); + Info_SetValueForKey(sysinfo, "sv_pure", sv_pure->string, MAX_SERVERINFO_STRING); SVQ3_SetConfigString(1, sysinfo); mapentspointer = sv.worldmodel->entities; - VM_Call(q3gamevm, GAME_INIT, 0, rand(), false); + VM_Call(q3gamevm, GAME_INIT, 0, (int)rand(), false); CM_InitBoxHull(); @@ -1937,17 +1925,17 @@ void SVQ3_RunFrame(void) void SVQ3_ClientCommand(client_t *cl) { - VM_Call(q3gamevm, GAME_CLIENT_COMMAND, cl-svs.clients); + VM_Call(q3gamevm, GAME_CLIENT_COMMAND, (int)(cl-svs.clients)); } void SVQ3_ClientBegin(client_t *cl) { - VM_Call(q3gamevm, GAME_CLIENT_BEGIN, cl-svs.clients); + VM_Call(q3gamevm, GAME_CLIENT_BEGIN, (int)(cl-svs.clients)); } void SVQ3_ClientThink(client_t *cl) { - VM_Call(q3gamevm, GAME_CLIENT_THINK, cl-svs.clients); + VM_Call(q3gamevm, GAME_CLIENT_THINK, (int)(cl-svs.clients)); } qboolean SVQ3_Command(void) @@ -2303,7 +2291,8 @@ void SVQ3_BuildClientSnapshot( client_t *client ) bitvector = sv.worldmodel->funcs.LeafPVS(sv.worldmodel, sv.worldmodel->funcs.LeafnumForPoint(sv.worldmodel, org), NULL); clientarea = CM_LeafArea(sv.worldmodel, clientarea); /* - if( client->areanum != clientarea ) { + if (client->areanum != clientarea) + { Com_Printf( "%s entered area %i\n", client->name, clientarea); client->areanum = clientarea; } @@ -2409,7 +2398,7 @@ void SVQ3_BuildClientSnapshot( client_t *client ) void SVQ3_SendGameState(client_t *client) { sizebuf_t msg; - char buffer[MAX_OVERALLMSGLEN]; + unsigned char buffer[MAX_OVERALLMSGLEN]; int i; int j; char *configString; @@ -2712,7 +2701,7 @@ void SVQ3_UpdateUserinfo_f(client_t *cl) SV_ExtractFromUserinfo (cl); - VM_Call(q3gamevm, GAME_CLIENT_USERINFO_CHANGED, cl-svs.clients); + VM_Call(q3gamevm, GAME_CLIENT_USERINFO_CHANGED, (int)(cl-svs.clients)); } void SVQ3_Drop_f(client_t *cl) @@ -2850,7 +2839,6 @@ void SVQ3_ParseClientMessage(client_t *client) { Con_Printf("corrupted packet from %s\n", client->name); client->drop = true; -// SV_DropClient(client); return; } @@ -2865,7 +2853,6 @@ void SVQ3_ParseClientMessage(client_t *client) default: Con_Printf("corrupted packet from %s\n", client->name); client->drop = true; -// SV_DropClient(client); return; case clcq3_nop: break; @@ -2937,7 +2924,7 @@ void SVQ3_DirectConnect(void) //Actually connect the client, use up a slot, and Huff_DecryptPacket(&net_message, 12); - Cmd_TokenizeString(net_message.data+4, false, false); + Cmd_TokenizeString((char*)net_message.data+4, false, false); userinfo = Cmd_Argv(1); qport = atoi(Info_ValueForKey(userinfo, "qport")); challenge = atoi(Info_ValueForKey(userinfo, "challenge")); @@ -2980,7 +2967,7 @@ void SVQ3_DirectConnect(void) //Actually connect the client, use up a slot, and reason = NET_AdrToString(net_from); Info_SetValueForStarKey(cl->userinfo, "ip", reason, sizeof(cl->userinfo)); - ret = VM_Call(q3gamevm, GAME_CLIENT_CONNECT, cl-svs.clients, false, false); + ret = VM_Call(q3gamevm, GAME_CLIENT_CONNECT, (int)(cl-svs.clients), false, false); if (!ret) reason = NULL; else @@ -3039,7 +3026,7 @@ int SVQ3_AddBot(void) void SVQ3_DropClient(client_t *cl) { if (q3gamevm) - VM_Call(q3gamevm, GAME_CLIENT_DISCONNECT, cl-svs.clients); + VM_Call(q3gamevm, GAME_CLIENT_DISCONNECT, (int)(cl-svs.clients)); } #endif