1
0
Fork 0
forked from fte/fteqw

Reworked the filesystem. We now support a virtual filesystem. Many places accept stream usage, although many formats do not support this.

I'm not sure if this will break anything. It shouldn't do, but it might.

Not everything is ported over yet. Ideally there would be no more use of fopen anywhere else in the engine, and com_gamedir would be made static to fs.c
There are a couple of other changes too.

http/ftp stuff is currently disabled.


git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@1728 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2005-12-21 03:07:33 +00:00
parent dc6ff40ad6
commit 503eff6421
56 changed files with 1799 additions and 964 deletions

View file

@ -66,7 +66,15 @@ ifeq ($(USEASM),true)
DO_AS=$(CC) $(BASE_CFLAGS) $(WCFLAGS) -x assembler-with-cpp -DELF -o $@ -c $< $(CFLAGS) DO_AS=$(CC) $(BASE_CFLAGS) $(WCFLAGS) -x assembler-with-cpp -DELF -o $@ -c $< $(CFLAGS)
endif endif
endif endif
BASELDFLAGS=-lm
ifeq ($(FTE_TARGET),win32)
BASELDFLAGS=-lm
endif
ifeq ($(FTE_TARGET),cygwin)
BASELDFLAGS=-lm
endif
BASELDFLAGS ?= -lm -ldl
#BASELDFLAGS=-lm -lz #BASELDFLAGS=-lm -lz
GLXLDFLAGS=-L/usr/X11R6/lib -lX11 -lXext -lpng -ljpeg GLXLDFLAGS=-L/usr/X11R6/lib -lX11 -lXext -lpng -ljpeg
GLSLDFLAGS=-L/usr/X11R6/lib -lMesaGL -lglide -lvga GLSLDFLAGS=-L/usr/X11R6/lib -lMesaGL -lglide -lvga

View file

@ -27,6 +27,9 @@ float demtime;
int cls_lastto; int cls_lastto;
int cls_lasttype; int cls_lasttype;
void CL_PlayDemo(char *demoname);
char lastdemoname[256];
/* /*
============================================================================== ==============================================================================
@ -54,7 +57,7 @@ void CL_StopPlayback (void)
Media_CaptureDemoEnd(); Media_CaptureDemoEnd();
fclose (cls.demofile); VFS_CLOSE (cls.demofile);
cls.demofile = NULL; cls.demofile = NULL;
cls.state = ca_disconnected; cls.state = ca_disconnected;
cls.demoplayback = DPB_NONE; cls.demoplayback = DPB_NONE;
@ -84,10 +87,10 @@ void CL_WriteDemoCmd (usercmd_t *pcmd)
//Con_Printf("write: %ld bytes, %4.4f\n", msg->cursize, realtime); //Con_Printf("write: %ld bytes, %4.4f\n", msg->cursize, realtime);
fl = LittleFloat((float)realtime); fl = LittleFloat((float)realtime);
fwrite (&fl, sizeof(fl), 1, cls.demofile); VFS_WRITE (cls.demofile, &fl, sizeof(fl));
c = dem_cmd; c = dem_cmd;
fwrite (&c, sizeof(c), 1, cls.demofile); VFS_WRITE (cls.demofile, &c, sizeof(c));
// correct for byte order, bytes don't matter // correct for byte order, bytes don't matter
@ -102,15 +105,15 @@ void CL_WriteDemoCmd (usercmd_t *pcmd)
cmd.sidemove = LittleShort(pcmd->sidemove); cmd.sidemove = LittleShort(pcmd->sidemove);
cmd.upmove = LittleShort(pcmd->upmove); cmd.upmove = LittleShort(pcmd->upmove);
fwrite(&cmd, sizeof(cmd), 1, cls.demofile); VFS_WRITE (cls.demofile, &cmd, sizeof(cmd));
for (i=0 ; i<3 ; i++) for (i=0 ; i<3 ; i++)
{ {
fl = LittleFloat (cl.viewangles[0][i]); fl = LittleFloat (cl.viewangles[0][i]);
fwrite (&fl, 4, 1, cls.demofile); VFS_WRITE (cls.demofile, &fl, 4);
} }
fflush (cls.demofile); VFS_FLUSH (cls.demofile);
} }
/* /*
@ -132,16 +135,16 @@ void CL_WriteDemoMessage (sizebuf_t *msg)
return; return;
fl = LittleFloat((float)realtime); fl = LittleFloat((float)realtime);
fwrite (&fl, sizeof(fl), 1, cls.demofile); VFS_WRITE (cls.demofile, &fl, sizeof(fl));
c = dem_read; c = dem_read;
fwrite (&c, sizeof(c), 1, cls.demofile); VFS_WRITE (cls.demofile, &c, sizeof(c));
len = LittleLong (msg->cursize); len = LittleLong (msg->cursize);
fwrite (&len, 4, 1, cls.demofile); VFS_WRITE (cls.demofile, &len, 4);
fwrite (msg->data, msg->cursize, 1, cls.demofile); VFS_WRITE (cls.demofile, msg->data, msg->cursize);
fflush (cls.demofile); VFS_FLUSH (cls.demofile);
} }
int unreaddata; int unreaddata;
@ -160,13 +163,71 @@ int readdemobytes(void *data, int len)
return len; return len;
} }
i = fread(data, 1, len, cls.demofile); i = VFS_READ(cls.demofile, data, len);
memcpy(&unreaddata, data, 4); memcpy(&unreaddata, data, 4);
return i; return i;
} }
void CL_ProgressDemoTime(void)
{
extern cvar_t cl_demospeed;
if (cl.parsecount && Media_PausedDemo())
{ //console visible whilst democapturing
#undef realtime
cls.netchan.last_received = realtime;
#define realtime demtime
return;
}
if (cl_demospeed.value>0)
realtime += host_frametime*cl_demospeed.value;
else
realtime += host_frametime;
}
void CL_DemoJump_f(void)
{
float newtime;
char *s = Cmd_Argv(1);
char *colon = strchr(s, ':');
if (*s == '+')
{
if (colon)
{
colon++;
realtime += atoi(colon);
realtime += atoi(s)*60;
}
else
realtime += atoi(s);
}
else
{
if (colon)
{
colon++;
newtime = atoi(colon);
newtime += atoi(s)*60;
}
else
newtime = atoi(s);
if (newtime >= realtime)
realtime = newtime;
else
{
Con_Printf("Rewinding demo\n");
CL_PlayDemo(lastdemoname);
realtime = newtime;
}
}
}
/* /*
==================== ====================
CL_GetDemoMessage CL_GetDemoMessage
@ -186,8 +247,6 @@ qboolean CL_GetDemoMessage (void)
usercmd_t *pcmd; usercmd_t *pcmd;
q1usercmd_t q1cmd; q1usercmd_t q1cmd;
realtime += host_frametime *0.1;
#ifdef NQPROT #ifdef NQPROT
if (cls.demoplayback == DPB_NETQUAKE || cls.demoplayback == DPB_QUAKE2) if (cls.demoplayback == DPB_NETQUAKE || cls.demoplayback == DPB_QUAKE2)
{ //read the nq demo { //read the nq demo
@ -353,7 +412,7 @@ readnext:
Host_Error ("CL_GetDemoMessage: cls.state != ca_active"); Host_Error ("CL_GetDemoMessage: cls.state != ca_active");
// get the msg type // get the msg type
fread (&c, sizeof(c), 1, cls.demofile); VFS_READ (cls.demofile, &c, sizeof(c));
switch (c&7) switch (c&7)
{ {
@ -513,7 +572,7 @@ void CL_Stop_f (void)
CL_WriteDemoMessage (&net_message); CL_WriteDemoMessage (&net_message);
// finish up // finish up
fclose (cls.demofile); VFS_CLOSE (cls.demofile);
cls.demofile = NULL; cls.demofile = NULL;
cls.demorecording = false; cls.demorecording = false;
Con_Printf ("Completed demo\n"); Con_Printf ("Completed demo\n");
@ -540,21 +599,21 @@ void CL_WriteRecordDemoMessage (sizebuf_t *msg, int seq)
return; return;
fl = LittleFloat((float)realtime); fl = LittleFloat((float)realtime);
fwrite (&fl, sizeof(fl), 1, cls.demofile); VFS_WRITE (cls.demofile, &fl, sizeof(fl));
c = dem_read; c = dem_read;
fwrite (&c, sizeof(c), 1, cls.demofile); VFS_WRITE (cls.demofile, &c, sizeof(c));
len = LittleLong (msg->cursize + 8); len = LittleLong (msg->cursize + 8);
fwrite (&len, 4, 1, cls.demofile); VFS_WRITE (cls.demofile, &len, 4);
i = LittleLong(seq); i = LittleLong(seq);
fwrite (&i, 4, 1, cls.demofile); VFS_WRITE (cls.demofile, &i, 4);
fwrite (&i, 4, 1, cls.demofile); VFS_WRITE (cls.demofile, &i, 4);
fwrite (msg->data, msg->cursize, 1, cls.demofile); VFS_WRITE (cls.demofile, msg->data, msg->cursize);
fflush (cls.demofile); VFS_FLUSH (cls.demofile);
} }
@ -570,17 +629,17 @@ void CL_WriteSetDemoMessage (void)
return; return;
fl = LittleFloat((float)realtime); fl = LittleFloat((float)realtime);
fwrite (&fl, sizeof(fl), 1, cls.demofile); VFS_WRITE (cls.demofile, &fl, sizeof(fl));
c = dem_set; c = dem_set;
fwrite (&c, sizeof(c), 1, cls.demofile); VFS_WRITE (cls.demofile, &c, sizeof(c));
len = LittleLong(cls.netchan.outgoing_sequence); len = LittleLong(cls.netchan.outgoing_sequence);
fwrite (&len, 4, 1, cls.demofile); VFS_WRITE (cls.demofile, &len, 4);
len = LittleLong(cls.netchan.incoming_sequence); len = LittleLong(cls.netchan.incoming_sequence);
fwrite (&len, 4, 1, cls.demofile); VFS_WRITE (cls.demofile, &len, 4);
fflush (cls.demofile); VFS_FLUSH (cls.demofile);
} }
@ -720,7 +779,7 @@ void CL_Record_f (void)
// //
// open the demo file // open the demo file
// //
cls.demofile = fopen (name, "wb"); cls.demofile = FS_OpenVFS (name, "wb", FS_GAME);
if (!cls.demofile) if (!cls.demofile)
{ {
Con_Printf ("ERROR: couldn't open.\n"); Con_Printf ("ERROR: couldn't open.\n");
@ -1039,7 +1098,7 @@ void CL_ReRecord_f (void)
// //
COM_DefaultExtension (name, ".qwd"); COM_DefaultExtension (name, ".qwd");
cls.demofile = fopen (name, "wb"); cls.demofile = FS_OpenVFS (name, "wb", FS_GAME);
if (!cls.demofile) if (!cls.demofile)
{ {
Con_Printf ("ERROR: couldn't open.\n"); Con_Printf ("ERROR: couldn't open.\n");
@ -1072,13 +1131,6 @@ play [demoname]
*/ */
void CL_PlayDemo_f (void) void CL_PlayDemo_f (void)
{ {
char name[256];
int ft, c, neg;
int len;
char type;
int protocol;
int start;
if (Cmd_Argc() != 2) if (Cmd_Argc() != 2)
{ {
Con_Printf ("playdemo <demoname> : plays a demo\n"); Con_Printf ("playdemo <demoname> : plays a demo\n");
@ -1094,6 +1146,18 @@ void CL_PlayDemo_f (void)
} }
#endif #endif
CL_PlayDemo(Cmd_Argv(1));
}
void CL_PlayDemo(char *demoname)
{
char name[256];
int ft, c, neg;
int len;
char type;
int protocol;
int start;
// //
// disconnect from server // disconnect from server
// //
@ -1103,20 +1167,20 @@ void CL_PlayDemo_f (void)
// //
// open the demo file // open the demo file
// //
strcpy (name, Cmd_Argv(1)); Q_strncpyz (name, demoname, sizeof(name));
COM_DefaultExtension (name, ".qwd"); COM_DefaultExtension (name, ".qwd");
COM_FOpenFile (name, &cls.demofile); cls.demofile = FS_OpenVFS(name, "rb", FS_GAME);
if (!cls.demofile) if (!cls.demofile)
{ {
strcpy (name, Cmd_Argv(1)); Q_strncpyz (name, demoname, sizeof(name));
COM_DefaultExtension (name, ".dem"); COM_DefaultExtension (name, ".dem");
COM_FOpenFile (name, &cls.demofile); cls.demofile = FS_OpenVFS(name, "rb", FS_GAME);
} }
if (!cls.demofile) if (!cls.demofile)
{ {
strcpy (name, Cmd_Argv(1)); Q_strncpyz (name, demoname, sizeof(name));
COM_DefaultExtension (name, ".mvd"); COM_DefaultExtension (name, ".mvd");
COM_FOpenFile (name, &cls.demofile); cls.demofile = FS_OpenVFS(name, "rb", FS_GAME);
} }
if (!cls.demofile) if (!cls.demofile)
{ {
@ -1124,6 +1188,7 @@ void CL_PlayDemo_f (void)
cls.demonum = -1; // stop demo loop cls.demonum = -1; // stop demo loop
return; return;
} }
Q_strncpyz (lastdemoname, demoname, sizeof(lastdemoname));
Con_Printf ("Playing demo from %s.\n", name); Con_Printf ("Playing demo from %s.\n", name);
if (!Q_strcasecmp(name + strlen(name) - 3, "mvd")) if (!Q_strcasecmp(name + strlen(name) - 3, "mvd"))
@ -1133,6 +1198,7 @@ void CL_PlayDemo_f (void)
} }
else else
cls.demoplayback = DPB_QUAKEWORLD; cls.demoplayback = DPB_QUAKEWORLD;
cls.state = ca_demostart; cls.state = ca_demostart;
net_message.packing = SZ_RAWBYTES; net_message.packing = SZ_RAWBYTES;
Netchan_Setup (NS_CLIENT, &cls.netchan, net_from, 0); Netchan_Setup (NS_CLIENT, &cls.netchan, net_from, 0);
@ -1143,11 +1209,11 @@ void CL_PlayDemo_f (void)
cls.netchan.last_received=0; cls.netchan.last_received=0;
start = ftell(cls.demofile); start = VFS_TELL(cls.demofile);
fread(&len, sizeof(len), 1, cls.demofile); VFS_READ(cls.demofile, &len, sizeof(len));
fread(&type, sizeof(type), 1, cls.demofile); VFS_READ(cls.demofile, &type, sizeof(type));
fread(&protocol, sizeof(protocol), 1, cls.demofile); VFS_READ(cls.demofile, &protocol, sizeof(protocol));
fseek(cls.demofile, start, SEEK_SET); VFS_SEEK(cls.demofile, start);
if (len > 5 && type == svcq2_serverdata && protocol == PROTOCOL_VERSION_Q2) if (len > 5 && type == svcq2_serverdata && protocol == PROTOCOL_VERSION_Q2)
{ {
#ifdef Q2CLIENT #ifdef Q2CLIENT
@ -1164,7 +1230,7 @@ void CL_PlayDemo_f (void)
cls.protocol = CP_QUAKEWORLD; cls.protocol = CP_QUAKEWORLD;
ft = 0; //work out if the first line is a int for the track number. ft = 0; //work out if the first line is a int for the track number.
while ((c = getc(cls.demofile)) != '\n') while ((VFS_READ(cls.demofile, &c, 1)==1) && (c != '\n'))
{ {
if (c == '-') if (c == '-')
neg = true; neg = true;
@ -1185,7 +1251,7 @@ void CL_PlayDemo_f (void)
#endif #endif
} }
else else
fseek(cls.demofile, start, SEEK_SET); //quakeworld demo, so go back to start. VFS_SEEK(cls.demofile, start); //quakeworld demo, so go back to start.
} }
} }

View file

@ -3341,6 +3341,7 @@ void MVD_Interpolate(void)
entity_state_t *oldents; entity_state_t *oldents;
struct predicted_player *pplayer; struct predicted_player *pplayer;
static float old; static float old;
extern float demtime;
self = &cl.frames[cl.parsecount & UPDATE_MASK].playerstate[cl.playernum[0]]; self = &cl.frames[cl.parsecount & UPDATE_MASK].playerstate[cl.playernum[0]];
oldself = &cl.frames[(cls.netchan.outgoing_sequence - 1) & UPDATE_MASK].playerstate[cl.playernum[0]]; oldself = &cl.frames[(cls.netchan.outgoing_sequence - 1) & UPDATE_MASK].playerstate[cl.playernum[0]];
@ -3371,7 +3372,7 @@ void MVD_Interpolate(void)
oldframe = &cl.frames[cl.oldparsecount & UPDATE_MASK]; oldframe = &cl.frames[cl.oldparsecount & UPDATE_MASK];
oldents = oldframe->packet_entities.entities; oldents = oldframe->packet_entities.entities;
f = (realtime - olddemotime) / (nextdemotime - olddemotime); f = (demtime - olddemotime) / (nextdemotime - olddemotime);
if (f < 0) if (f < 0)
f = 0; f = 0;
if (f > 1) if (f > 1)

View file

@ -22,6 +22,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "quakedef.h" #include "quakedef.h"
#include "cl_ignore.h" #include "cl_ignore.h"
#include <ctype.h>
#define MAX_TEAMIGNORELIST 4 #define MAX_TEAMIGNORELIST 4
#define FLOODLIST_SIZE 10 #define FLOODLIST_SIZE 10

View file

@ -813,7 +813,7 @@ float CL_FilterTime (double time, float wantfps) //now returns the extra time no
if (cls.timedemo || cls.protocol == CP_QUAKE3) if (cls.timedemo || cls.protocol == CP_QUAKE3)
return -1; return -1;
if (cls.demoplayback != DPB_NONE) if (cls.demoplayback != DPB_NONE || cls.protocol != CP_QUAKEWORLD)
{ {
if (!wantfps) if (!wantfps)
return -1; return -1;

View file

@ -56,7 +56,7 @@ cvar_t cl_splitscreen = {"cl_splitscreen", "0"};
cvar_t lookspring = {"lookspring","0", NULL, CVAR_ARCHIVE}; cvar_t lookspring = {"lookspring","0", NULL, CVAR_ARCHIVE};
cvar_t lookstrafe = {"lookstrafe","0", NULL, CVAR_ARCHIVE}; cvar_t lookstrafe = {"lookstrafe","0", NULL, CVAR_ARCHIVE};
cvar_t sensitivity = {"sensitivity","3", NULL, CVAR_ARCHIVE}; cvar_t sensitivity = {"sensitivity","10", NULL, CVAR_ARCHIVE};
cvar_t cl_staticsounds = {"cl_staticsounds", "1"}; cvar_t cl_staticsounds = {"cl_staticsounds", "1"};
@ -1545,10 +1545,10 @@ void CL_SetInfo_f (void)
} }
} }
void CL_SaveInfo(FILE *f) void CL_SaveInfo(vfsfile_t *f)
{ {
fwrite("\n", 1, 1, f); VFS_WRITE(f, "\n", 1);
fwrite("setinfo * \"\"\n", 13, 1, f); VFS_WRITE(f, "setinfo * \"\"\n", 13);
Info_WriteToFile(f, cls.userinfo, "setinfo", CVAR_USERINFO); Info_WriteToFile(f, cls.userinfo, "setinfo", CVAR_USERINFO);
} }
@ -2309,7 +2309,10 @@ void CL_ReadPackets (void)
#endif #endif
case CP_QUAKEWORLD: case CP_QUAKEWORLD:
if (cls.demoplayback == DPB_MVD) if (cls.demoplayback == DPB_MVD)
{
MSG_BeginReading(); MSG_BeginReading();
cls.netchan.last_received = realtime;
}
else if (!Netchan_Process(&cls.netchan)) else if (!Netchan_Process(&cls.netchan))
continue; // wasn't accepted for some reason continue; // wasn't accepted for some reason
CL_ParseServerMessage (); CL_ParseServerMessage ();
@ -2629,6 +2632,7 @@ void CL_Init (void)
Cmd_AddCommand ("rerecord", CL_ReRecord_f); Cmd_AddCommand ("rerecord", CL_ReRecord_f);
Cmd_AddCommand ("stop", CL_Stop_f); Cmd_AddCommand ("stop", CL_Stop_f);
Cmd_AddCommand ("playdemo", CL_PlayDemo_f); Cmd_AddCommand ("playdemo", CL_PlayDemo_f);
Cmd_AddCommand ("demo_jump", CL_DemoJump_f);
Cmd_AddCommand ("timedemo", CL_TimeDemo_f); Cmd_AddCommand ("timedemo", CL_TimeDemo_f);
Cmd_AddCommand ("showpic", SCR_ShowPic_Script_f); Cmd_AddCommand ("showpic", SCR_ShowPic_Script_f);
@ -2775,7 +2779,7 @@ Writes key bindings and archived cvars to config.cfg
*/ */
void Host_WriteConfiguration (void) void Host_WriteConfiguration (void)
{ {
FILE *f; vfsfile_t *f;
if (host_initialized && cfg_save_name.string && *cfg_save_name.string) if (host_initialized && cfg_save_name.string && *cfg_save_name.string)
{ {
@ -2785,7 +2789,7 @@ void Host_WriteConfiguration (void)
return; return;
} }
f = fopen (va("%s/%s.cfg",com_gamedir, cfg_save_name.string), "w"); f = FS_OpenVFS(va("%s.cfg",cfg_save_name.string), "w", FS_GAMEONLY);
if (!f) if (!f)
{ {
Con_TPrintf (TLC_CONFIGCFG_WRITEFAILED); Con_TPrintf (TLC_CONFIGCFG_WRITEFAILED);
@ -2795,7 +2799,7 @@ void Host_WriteConfiguration (void)
Key_WriteBindings (f); Key_WriteBindings (f);
Cvar_WriteVariables (f, false); Cvar_WriteVariables (f, false);
fclose (f); VFS_CLOSE (f);
} }
} }
@ -2868,8 +2872,8 @@ void Host_Frame (double time)
} }
#endif #endif
if (cls.demoplayback && cl_demospeed.value>0) // if (cls.demoplayback && cl_demospeed.value>0)
realframetime *= cl_demospeed.value; // this probably screws up other timings // realframetime *= cl_demospeed.value; // this probably screws up other timings
#ifndef CLIENTONLY #ifndef CLIENTONLY
RSpeedRemark(); RSpeedRemark();
@ -2901,7 +2905,6 @@ void Host_Frame (double time)
cl.gametimemark += time; cl.gametimemark += time;
#ifdef VOICECHAT #ifdef VOICECHAT
CLVC_Poll(); CLVC_Poll();
#endif #endif
@ -2925,7 +2928,7 @@ void Host_Frame (double time)
else else
{ {
realtime += spare/1000; //don't use it all! realtime += spare/1000; //don't use it all!
spare = CL_FilterTime((realtime - oldrealtime)*1000, cl_maxfps.value>0?cl_maxfps.value:cl_netfps.value); spare = CL_FilterTime((realtime - oldrealtime)*1000, (cl_maxfps.value>0||cls.protocol!=CP_QUAKEWORLD)?cl_maxfps.value:cl_netfps.value);
if (!spare) if (!spare)
return; return;
if (spare < 0 || cls.state < ca_onserver) if (spare < 0 || cls.state < ca_onserver)
@ -2939,6 +2942,8 @@ void Host_Frame (double time)
host_frametime = (realtime - oldrealtime)*cl.gamespeed; host_frametime = (realtime - oldrealtime)*cl.gamespeed;
oldrealtime = realtime; oldrealtime = realtime;
CL_ProgressDemoTime();
#if defined(Q2CLIENT) #if defined(Q2CLIENT)
if (cls.protocol == CP_QUAKE2) if (cls.protocol == CP_QUAKE2)

View file

@ -545,7 +545,7 @@ static void CL_LerpMove (int pnum, float msgtime)
int i; int i;
int from, to; int from, to;
if (cl_nolerp.value) if (cl_nolerp.value || cls.demoplayback == DPB_MVD)
return; return;
if (cls.netchan.outgoing_sequence < lastsequence) { if (cls.netchan.outgoing_sequence < lastsequence) {
@ -757,7 +757,7 @@ void CL_PredictMovePNum (int pnum)
vel = vec3_origin; vel = vec3_origin;
goto fixedorg; goto fixedorg;
} }
Con_Printf("Not lerped\n");
/* entity_state_t *CL_FindOldPacketEntity(int num); /* entity_state_t *CL_FindOldPacketEntity(int num);
entity_state_t *CL_FindPacketEntity(int num); entity_state_t *CL_FindPacketEntity(int num);
entity_state_t *state; entity_state_t *state;
@ -814,7 +814,7 @@ fixedorg:
to = &cl.frames[cl.validsequence & UPDATE_MASK]; to = &cl.frames[cl.validsequence & UPDATE_MASK];
if (Cam_TrackNum(pnum)>=0 && !cl_nolerp.value) if (Cam_TrackNum(pnum)>=0 && !cl_nolerp.value && cls.demoplayback != DPB_MVD)
{ {
float f; float f;

View file

@ -1556,6 +1556,7 @@ void SCR_ScreenShot_f (void)
char pcxname[80]; char pcxname[80];
char checkname[MAX_OSPATH]; char checkname[MAX_OSPATH];
int i; int i;
vfsfile_t *vfs;
if (!VID_GetRGBInfo) if (!VID_GetRGBInfo)
{ {
@ -1587,8 +1588,9 @@ void SCR_ScreenShot_f (void)
pcxname[18] = (i%100)/10 + '0'; pcxname[18] = (i%100)/10 + '0';
pcxname[19] = (i%10) + '0'; pcxname[19] = (i%10) + '0';
sprintf (checkname, "%s/%s", com_gamedir, pcxname); sprintf (checkname, "%s/%s", com_gamedir, pcxname);
if (Sys_FileTime(checkname) == -1) if (!(vfs = FS_OpenVFS(pcxname, "r", FS_GAMEONLY)))
break; // file doesn't exist break; // file doesn't exist
VFS_CLOSE(vfs);
} }
if (i==100000) if (i==100000)
{ {

View file

@ -462,9 +462,9 @@ int VMQ3_GetFileList(char *path, char *ext, char *output, int buffersize)
vms.found=0; vms.found=0;
if (*(char *)path == '$') if (*(char *)path == '$')
{ {
extern char *com_basedir;
vms.skip=0; vms.skip=0;
Sys_EnumerateFiles(com_basedir, "*", VMEnumMods, &vms); Sys_EnumerateFiles(com_quakedir, "*", VMEnumMods, &vms);
Sys_EnumerateFiles(com_homedir, "*", VMEnumMods, &vms);
} }
else if (*(char *)ext == '.' || *(char *)ext == '/') else if (*(char *)ext == '.' || *(char *)ext == '/')
COM_EnumerateFiles(va("%s/*%s", path, ext), VMEnum, &vms); COM_EnumerateFiles(va("%s/*%s", path, ext), VMEnum, &vms);
@ -707,7 +707,7 @@ void UI_RegisterFont(char *fontName, int pointSize, fontInfo_t *font)
_snprintf(name, sizeof(name), "fonts/fontImage_%i.dat",pointSize); _snprintf(name, sizeof(name), "fonts/fontImage_%i.dat",pointSize);
in.i = COM_LoadTempFile(name); in.c = COM_LoadTempFile(name);
if (com_filesize == sizeof(fontInfo_t)) if (com_filesize == sizeof(fontInfo_t))
{ {
for(i=0; i<GLYPHS_PER_FONT; i++) for(i=0; i<GLYPHS_PER_FONT; i++)

View file

@ -352,7 +352,7 @@ typedef struct
#endif #endif
} demoplayback; } demoplayback;
qboolean timedemo; qboolean timedemo;
FILE *demofile; vfsfile_t *demofile;
float td_lastframe; // to meter out one message a frame float td_lastframe; // to meter out one message a frame
int td_startframe; // host_framecount at start int td_startframe; // host_framecount at start
float td_starttime; // realtime at second frame of timedemo float td_starttime; // realtime at second frame of timedemo
@ -725,6 +725,7 @@ void CL_Stop_f (void);
void CL_Record_f (void); void CL_Record_f (void);
void CL_ReRecord_f (void); void CL_ReRecord_f (void);
void CL_PlayDemo_f (void); void CL_PlayDemo_f (void);
void CL_DemoJump_f(void);
void CL_TimeDemo_f (void); void CL_TimeDemo_f (void);
// //

View file

@ -31,7 +31,7 @@ typedef struct
qboolean cinematicpalette_active; qboolean cinematicpalette_active;
qbyte cinematicpalette[768]; qbyte cinematicpalette[768];
FILE *cinematic_file; vfsfile_t *cinematic_file;
int cinematicframe; int cinematicframe;
} cinematics_t; } cinematics_t;
@ -61,7 +61,7 @@ void CIN_StopCinematic (void)
} }
if (cin.cinematic_file) if (cin.cinematic_file)
{ {
fclose (cin.cinematic_file); VFS_CLOSE (cin.cinematic_file);
cin.cinematic_file = NULL; cin.cinematic_file = NULL;
} }
if (cin.hnodes1) if (cin.hnodes1)
@ -156,7 +156,7 @@ static void Huff1TableInit (void)
memset (cin.h_used,0,sizeof(cin.h_used)); memset (cin.h_used,0,sizeof(cin.h_used));
// read a row of counts // read a row of counts
fread (counts, 1, sizeof(counts), cin.cinematic_file); VFS_READ (cin.cinematic_file, counts, sizeof(counts));
for (j=0 ; j<256 ; j++) for (j=0 ; j<256 ; j++)
cin.h_count[j] = counts[j]; cin.h_count[j] = counts[j];
@ -331,11 +331,11 @@ qbyte *CIN_ReadNextFrame (void)
int start, end, count; int start, end, count;
// read the next frame // read the next frame
r = fread (&command, 4, 1, cin.cinematic_file); r = VFS_READ (cin.cinematic_file, &command, 4);
if (r == 0) // we'll give it one more chance if (r == 0) // we'll give it one more chance
r = fread (&command, 4, 1, cin.cinematic_file); r = VFS_READ (cin.cinematic_file, &command, 4);
if (r != 1) if (r != 4)
return NULL; return NULL;
command = LittleLong(command); command = LittleLong(command);
if (command == 2) if (command == 2)
@ -343,23 +343,23 @@ qbyte *CIN_ReadNextFrame (void)
if (command == 1) if (command == 1)
{ // read palette { // read palette
fread (cin.cinematicpalette, 1, sizeof(cin.cinematicpalette), cin.cinematic_file); VFS_READ (cin.cinematic_file, cin.cinematicpalette, sizeof(cin.cinematicpalette));
cin.cinematicpalette_active=0; // dubious.... exposes an edge case cin.cinematicpalette_active=0; // dubious.... exposes an edge case
} }
// decompress the next frame // decompress the next frame
fread (&size, 1, 4, cin.cinematic_file); VFS_READ (cin.cinematic_file, &size, 4);
size = LittleLong(size); size = LittleLong(size);
if (size > sizeof(compressed) || size < 1) if (size > sizeof(compressed) || size < 1)
Host_Error ("Bad compressed frame size"); Host_Error ("Bad compressed frame size");
fread (compressed, 1, size, cin.cinematic_file); VFS_READ (cin.cinematic_file, compressed, size);
// read sound // read sound
start = cin.cinematicframe*cin.s_rate/14; start = cin.cinematicframe*cin.s_rate/14;
end = (cin.cinematicframe+1)*cin.s_rate/14; end = (cin.cinematicframe+1)*cin.s_rate/14;
count = end - start; count = end - start;
fread (samples, 1, count*cin.s_width*cin.s_channels, cin.cinematic_file); VFS_READ (cin.cinematic_file, samples, count*cin.s_width*cin.s_channels);
S_RawAudio (0, samples, cin.s_rate, count, cin.s_channels, cin.s_width); S_RawAudio (0, samples, cin.s_rate, count, cin.s_channels, cin.s_width);
@ -485,11 +485,11 @@ qboolean CIN_PlayCinematic (char *arg)
cin.cinematicframe = 0; cin.cinematicframe = 0;
COM_FOpenFile (arg, &cin.cinematic_file); cin.cinematic_file = FS_OpenVFS(arg, "rb", FS_GAME);
if (!cin.cinematic_file) if (!cin.cinematic_file)
{ {
_snprintf (name, sizeof(name), "video/%s", arg); _snprintf (name, sizeof(name), "video/%s", arg);
COM_FOpenFile (name, &cin.cinematic_file); cin.cinematic_file = FS_OpenVFS(name, "rb", FS_GAME);
} }
if (!cin.cinematic_file) if (!cin.cinematic_file)
{ {
@ -501,16 +501,16 @@ qboolean CIN_PlayCinematic (char *arg)
SCR_EndLoadingPlaque (); SCR_EndLoadingPlaque ();
fread (&width, 1, 4, cin.cinematic_file); VFS_READ (cin.cinematic_file, &width, 4);
fread (&height, 1, 4, cin.cinematic_file); VFS_READ (cin.cinematic_file, &height, 4);
cin.width = LittleLong(width); cin.width = LittleLong(width);
cin.height = LittleLong(height); cin.height = LittleLong(height);
fread (&cin.s_rate, 1, 4, cin.cinematic_file); VFS_READ (cin.cinematic_file, &cin.s_rate, 4);
cin.s_rate = LittleLong(cin.s_rate); cin.s_rate = LittleLong(cin.s_rate);
fread (&cin.s_width, 1, 4, cin.cinematic_file); VFS_READ (cin.cinematic_file, &cin.s_width, 4);
cin.s_width = LittleLong(cin.s_width); cin.s_width = LittleLong(cin.s_width);
fread (&cin.s_channels, 1, 4, cin.cinematic_file); VFS_READ (cin.cinematic_file, &cin.s_channels, 4);
cin.s_channels = LittleLong(cin.s_channels); cin.s_channels = LittleLong(cin.s_channels);
Huff1TableInit (); Huff1TableInit ();

View file

@ -964,38 +964,98 @@ qbyte *ReadJPEGFile(qbyte *infile, int length, int *width, int *height)
} }
#define OUTPUT_BUF_SIZE 4096
typedef struct { typedef struct {
struct jpeg_error_mgr pub; struct jpeg_error_mgr pub;
jmp_buf setjmp_buffer; jmp_buf setjmp_buffer;
} jpeg_error_mgr_wrapper; } jpeg_error_mgr_wrapper;
typedef struct {
struct jpeg_destination_mgr pub;
vfsfile_t *vfs;
JOCTET buffer[OUTPUT_BUF_SIZE]; /* start of buffer */
} my_destination_mgr;
METHODDEF(void) init_destination (j_compress_ptr cinfo)
{
my_destination_mgr *dest = (my_destination_mgr*) cinfo->dest;
dest->pub.next_output_byte = dest->buffer;
dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
}
METHODDEF(boolean) empty_output_buffer (j_compress_ptr cinfo)
{
my_destination_mgr *dest = (my_destination_mgr*) cinfo->dest;
VFS_WRITE(dest->vfs, dest->buffer, OUTPUT_BUF_SIZE);
dest->pub.next_output_byte = dest->buffer;
dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
return TRUE;
}
METHODDEF(void) term_destination (j_compress_ptr cinfo)
{
my_destination_mgr *dest = (my_destination_mgr*) cinfo->dest;
VFS_WRITE(dest->vfs, dest->buffer, OUTPUT_BUF_SIZE - dest->pub.free_in_buffer);
dest->pub.next_output_byte = dest->buffer;
dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
}
void jpeg_mem_dest (j_compress_ptr cinfo, vfsfile_t *vfs)
{
my_destination_mgr *dest;
if (cinfo->dest == NULL) { /* first time for this JPEG object? */
cinfo->dest = (struct jpeg_destination_mgr *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
sizeof(my_destination_mgr));
dest = (my_destination_mgr*) cinfo->dest;
// dest->buffer = (JOCTET *)
// (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
// OUTPUT_BUF_SIZE * sizeof(JOCTET));
}
dest = (my_destination_mgr*) cinfo->dest;
dest->pub.init_destination = init_destination;
dest->pub.empty_output_buffer = empty_output_buffer;
dest->pub.term_destination = term_destination;
dest->pub.free_in_buffer = 0; /* forces fill_input_buffer on first read */
dest->pub.next_output_byte = NULL; /* until buffer loaded */
dest->vfs = vfs;
}
METHODDEF(void) jpeg_error_exit (j_common_ptr cinfo) { METHODDEF(void) jpeg_error_exit (j_common_ptr cinfo) {
longjmp(((jpeg_error_mgr_wrapper *) cinfo->err)->setjmp_buffer, 1); longjmp(((jpeg_error_mgr_wrapper *) cinfo->err)->setjmp_buffer, 1);
} }
extern char *com_basedir;
void screenshotJPEG(char *filename, qbyte *screendata, int screenwidth, int screenheight) //input is rgb NOT rgba void screenshotJPEG(char *filename, qbyte *screendata, int screenwidth, int screenheight) //input is rgb NOT rgba
{ {
char name[MAX_OSPATH];
qbyte *buffer; qbyte *buffer;
FILE *outfile; vfsfile_t *outfile;
jpeg_error_mgr_wrapper jerr; jpeg_error_mgr_wrapper jerr;
struct jpeg_compress_struct cinfo; struct jpeg_compress_struct cinfo;
JSAMPROW row_pointer[1]; JSAMPROW row_pointer[1];
sprintf (name, "%s/%s", com_gamedir, filename); if (!(outfile = FS_OpenVFS(filename, "wb", FS_GAMEONLY)))
if (!(outfile = fopen (name, "wb"))) { {
COM_CreatePath (name); FS_CreatePath (filename, FS_GAME);
if (!(outfile = fopen (name, "wb"))) if (!(outfile = FS_OpenVFS(filename, "w", FS_GAMEONLY)))
Sys_Error ("Error opening %s", filename); Sys_Error ("Error opening %s", filename);
} }
cinfo.err = jpeg_std_error(&jerr.pub); cinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = jpeg_error_exit; jerr.pub.error_exit = jpeg_error_exit;
if (setjmp(jerr.setjmp_buffer)) { if (setjmp(jerr.setjmp_buffer))
{
jpeg_destroy_compress(&cinfo); jpeg_destroy_compress(&cinfo);
fclose(outfile); VFS_CLOSE(outfile);
unlink(name); FS_Remove(filename, FS_GAME);
Con_Printf("Failed to create jpeg\n"); Con_Printf("Failed to create jpeg\n");
return; return;
} }
@ -1003,7 +1063,7 @@ void screenshotJPEG(char *filename, qbyte *screendata, int screenwidth, int scre
buffer = screendata; buffer = screendata;
jpeg_stdio_dest(&cinfo, outfile); jpeg_mem_dest(&cinfo, outfile);
cinfo.image_width = screenwidth; cinfo.image_width = screenwidth;
cinfo.image_height = screenheight; cinfo.image_height = screenheight;
cinfo.input_components = 3; cinfo.input_components = 3;
@ -1012,13 +1072,14 @@ void screenshotJPEG(char *filename, qbyte *screendata, int screenwidth, int scre
jpeg_set_quality (&cinfo, 75/*bound(0, (int) gl_image_jpeg_quality_level.value, 100)*/, true); jpeg_set_quality (&cinfo, 75/*bound(0, (int) gl_image_jpeg_quality_level.value, 100)*/, true);
jpeg_start_compress(&cinfo, true); jpeg_start_compress(&cinfo, true);
while (cinfo.next_scanline < cinfo.image_height) { while (cinfo.next_scanline < cinfo.image_height)
{
*row_pointer = &buffer[(cinfo.image_height - cinfo.next_scanline - 1) * cinfo.image_width * 3]; *row_pointer = &buffer[(cinfo.image_height - cinfo.next_scanline - 1) * cinfo.image_width * 3];
jpeg_write_scanlines(&cinfo, row_pointer, 1); jpeg_write_scanlines(&cinfo, row_pointer, 1);
} }
jpeg_finish_compress(&cinfo); jpeg_finish_compress(&cinfo);
fclose(outfile); VFS_CLOSE(outfile);
jpeg_destroy_compress(&cinfo); jpeg_destroy_compress(&cinfo);
} }

View file

@ -967,8 +967,9 @@ Key_WriteBindings
Writes lines containing "bind key value" Writes lines containing "bind key value"
============ ============
*/ */
void Key_WriteBindings (FILE *f) void Key_WriteBindings (vfsfile_t *f)
{ {
char *s;
int i, m; int i, m;
char *binding, *base; char *binding, *base;
@ -997,21 +998,22 @@ void Key_WriteBindings (FILE *f)
if (bindcmdlevel[i][m] != bindcmdlevel[i][0]) if (bindcmdlevel[i][m] != bindcmdlevel[i][0])
{ {
if (i == ';') if (i == ';')
fprintf (f, "bindlevel \"%s%s\" %i \"%s\"\n", prefix, Key_KeynumToString(i), bindcmdlevel[i][m], keybindings[i][m]); s = va("bindlevel \"%s%s\" %i \"%s\"\n", prefix, Key_KeynumToString(i), bindcmdlevel[i][m], keybindings[i][m]);
else if (i == '\"') else if (i == '\"')
fprintf (f, "bindlevel \"%s%s\" %i \"%s\"\n", prefix, "\"\"", bindcmdlevel[i][m], keybindings[i][m]); s = va("bindlevel \"%s%s\" %i \"%s\"\n", prefix, "\"\"", bindcmdlevel[i][m], keybindings[i][m]);
else else
fprintf (f, "bindlevel %s%s %i \"%s\"\n", prefix, Key_KeynumToString(i), bindcmdlevel[i][m], keybindings[i][m]); s = va("bindlevel %s%s %i \"%s\"\n", prefix, Key_KeynumToString(i), bindcmdlevel[i][m], keybindings[i][m]);
} }
else else
{ {
if (i == ';') if (i == ';')
fprintf (f, "bind \"%s%s\" \"%s\"\n", prefix, Key_KeynumToString(i), keybindings[i][m]); s = va("bind \"%s%s\" \"%s\"\n", prefix, Key_KeynumToString(i), keybindings[i][m]);
else if (i == '\"') else if (i == '\"')
fprintf (f, "bind \"%s%s\" \"%s\"\n", prefix, "\"\"", keybindings[i][m]); s = va("bind \"%s%s\" \"%s\"\n", prefix, "\"\"", keybindings[i][m]);
else else
fprintf (f, "bind %s%s \"%s\"\n", prefix, Key_KeynumToString(i), keybindings[i][m]); s = va("bind %s%s \"%s\"\n", prefix, Key_KeynumToString(i), keybindings[i][m]);
} }
VFS_WRITE(f, s, strlen(s));
} }
} }
} }

View file

@ -170,7 +170,7 @@ extern qboolean chat_team;
void Key_Event (int key, qboolean down); void Key_Event (int key, qboolean down);
void Key_Init (void); void Key_Init (void);
void Key_WriteBindings (FILE *f); void Key_WriteBindings (vfsfile_t *f);
void Key_SetBinding (int keynum, int modifier, char *binding, int cmdlevel); void Key_SetBinding (int keynum, int modifier, char *binding, int cmdlevel);
void Key_ClearStates (void); void Key_ClearStates (void);

View file

@ -964,6 +964,7 @@ qboolean Media_PlayFilm(char *name)
media_filmtype = MFT_CIN; media_filmtype = MFT_CIN;
return true; return true;
} }
if ((roqfilm = roq_open(name))) if ((roqfilm = roq_open(name)))
{ {
Con_ClearNotify(); Con_ClearNotify();
@ -1318,6 +1319,17 @@ enum {
CT_SCREENSHOT CT_SCREENSHOT
} capturetype; } capturetype;
char capturefilenameprefix[MAX_QPATH]; char capturefilenameprefix[MAX_QPATH];
qboolean Media_PausedDemo (void)
{
//capturedemo doesn't record any frames when the console is visible
//but that's okay, as we don't load any demo frames either.
if (recordingdemo)
if (scr_con_current > 0 || !cl.validsequence)
return true;
return false;
}
void Media_RecordFrame (void) void Media_RecordFrame (void)
{ {
HRESULT hr; HRESULT hr;
@ -1328,13 +1340,11 @@ void Media_RecordFrame (void)
if (!capturetype) if (!capturetype)
return; return;
if (recordingdemo) if (Media_PausedDemo())
if (scr_con_current > 0 || !cl.validsequence) return;
{
scr_con_current=0; if (cls.findtrack)
key_dest = key_game; return; //skip until we're tracking the right player.
return;
}
//overlay this on the screen, so it appears in the film //overlay this on the screen, so it appears in the film
if (*capturemessage.string) if (*capturemessage.string)
@ -1660,6 +1670,7 @@ void Media_RecordDemo_f(void)
void Media_CaptureDemoEnd(void){} void Media_CaptureDemoEnd(void){}
void Media_RecordAudioFrame (short *sample_buffer, int samples){} void Media_RecordAudioFrame (short *sample_buffer, int samples){}
void Media_RecordFrame (void) {} void Media_RecordFrame (void) {}
void Media_PausedDemo (void) {return false;}
#endif #endif
void Media_Init(void) void Media_Init(void)
{ {
@ -1708,6 +1719,7 @@ void Media_StopRecordFilm_f (void) {}
void Media_RecordFilm_f (void){} void Media_RecordFilm_f (void){}
void M_Menu_Media_f (void) {} void M_Menu_Media_f (void) {}
char *Media_NextTrack(void) {return NULL;} char *Media_NextTrack(void) {return NULL;}
qboolean Media_PausedDemo(void) {return false;}
int filmtexture; int filmtexture;
media_filmtype_t media_filmtype; media_filmtype_t media_filmtype;

View file

@ -547,7 +547,7 @@ void Master_AddMasterHTTP (char *address, int servertype, char *description)
qboolean Master_LoadMasterList (char *filename, int defaulttype, int depth) qboolean Master_LoadMasterList (char *filename, int defaulttype, int depth)
{ {
extern char *com_basedir; extern char *com_basedir;
FILE *f; vfsfile_t *f;
char line[1024]; char line[1024];
char file[1024]; char file[1024];
char *name, *next; char *name, *next;
@ -557,11 +557,11 @@ qboolean Master_LoadMasterList (char *filename, int defaulttype, int depth)
return false; return false;
depth--; depth--;
f = fopen(va("%s/%s", com_basedir, filename), "rb"); f = NULL;//FS_OpenVFS(filename, "rb", FS_BASE);
if (!f) if (!f)
return false; return false;
while(fgets(line, sizeof(line)-1, f)) while(VFS_GETS(f, line, sizeof(line)-1))
{ {
if (*line == '#') //comment if (*line == '#') //comment
continue; continue;
@ -663,7 +663,7 @@ qboolean Master_LoadMasterList (char *filename, int defaulttype, int depth)
else else
Master_AddMaster(line, servertype, name); Master_AddMaster(line, servertype, name);
} }
fclose(f); VFS_CLOSE(f);
return true; return true;
} }
@ -1184,7 +1184,7 @@ void MasterInfo_Begin(void)
Master_AddMaster("master.edome.net", MT_MASTERQW, "edome master server."); Master_AddMaster("master.edome.net", MT_MASTERQW, "edome master server.");
Master_AddMaster("qwmaster.barrysworld.com", MT_MASTERQW, "barrysworld master server."); Master_AddMaster("qwmaster.barrysworld.com", MT_MASTERQW, "barrysworld master server.");
Master_AddMaster("qwmaster.ocrana.de", MT_MASTERQW, "Ocrana2 master server."); Master_AddMaster("qwmaster.ocrana.de:27000", MT_MASTERQW, "Ocrana2 master server.");
Master_AddMaster("213.221.174.165:27000", MT_MASTERQW, "unknown1 master server."); Master_AddMaster("213.221.174.165:27000", MT_MASTERQW, "unknown1 master server.");
Master_AddMaster("195.74.0.8", MT_MASTERQW, "unknown2 master server."); Master_AddMaster("195.74.0.8", MT_MASTERQW, "unknown2 master server.");
Master_AddMaster("192.246.40.37", MT_MASTERQW, "unknown3 master server."); Master_AddMaster("192.246.40.37", MT_MASTERQW, "unknown3 master server.");

View file

@ -1559,16 +1559,18 @@ void P_NewServer(void)
void P_ReadPointFile_f (void) void P_ReadPointFile_f (void)
{ {
FILE *f; vfsfile_t *f;
vec3_t org; vec3_t org;
int r; int r;
int c; int c;
char name[MAX_OSPATH]; char name[MAX_OSPATH];
char line[1024];
char *s;
COM_StripExtension(cl.worldmodel->name, name); COM_StripExtension(cl.worldmodel->name, name);
strcat(name, ".pts"); strcat(name, ".pts");
COM_FOpenFile (name, &f); f = FS_OpenVFS(name, "rb", FS_GAME);
if (!f) if (!f)
{ {
Con_Printf ("couldn't open %s\n", name); Con_Printf ("couldn't open %s\n", name);
@ -1581,9 +1583,23 @@ void P_ReadPointFile_f (void)
c = 0; c = 0;
for ( ;; ) for ( ;; )
{ {
r = fscanf (f,"%f %f %f\n", &org[0], &org[1], &org[2]); VFS_GETS(f, line, sizeof(line));
if (r != 3)
break; s = COM_Parse(line);
org[0] = atof(com_token);
s = COM_Parse(s);
if (!s)
continue;
org[1] = atof(com_token);
s = COM_Parse(s);
if (!s)
continue;
org[2] = atof(com_token);
if (COM_Parse(s))
continue;
c++; c++;
if (c%8) if (c%8)
@ -1597,7 +1613,7 @@ void P_ReadPointFile_f (void)
P_RunParticleEffectType(org, NULL, 1, pt_pointfile); P_RunParticleEffectType(org, NULL, 1, pt_pointfile);
} }
fclose (f); VFS_CLOSE (f);
Con_Printf ("%i points read\n", c); Con_Printf ("%i points read\n", c);
} }

View file

@ -21,7 +21,7 @@ typedef struct {
} roq_qcell; } roq_qcell;
typedef struct { typedef struct {
FILE *fp; vfsfile_t *fp;
unsigned int maxpos; //addition for pack files. all seeks add this, all tells subtract this. unsigned int maxpos; //addition for pack files. all seeks add this, all tells subtract this.
int buf_size; int buf_size;
unsigned char *buf; unsigned char *buf;

View file

@ -24,6 +24,14 @@
#ifndef NOMEDIA #ifndef NOMEDIA
static int VFS_GETC(vfsfile_t *fp)
{
unsigned char c;
VFS_READ(fp, &c, 1);
return c;
}
//#include <stdio.h> //#include <stdio.h>
//#include <stdlib.h> //#include <stdlib.h>
//#include <string.h> //#include <string.h>
@ -34,31 +42,31 @@
#define FAST #define FAST
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
static unsigned int get_word(FILE *fp) static unsigned int get_word(vfsfile_t *fp)
{ {
unsigned int ret; unsigned int ret;
ret = ((fgetc(fp)) & 0xff); ret = ((VFS_GETC(fp)) & 0xff);
ret |= ((fgetc(fp)) & 0xff) << 8; ret |= ((VFS_GETC(fp)) & 0xff) << 8;
return(ret); return(ret);
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
static unsigned long get_long(FILE *fp) static unsigned long get_long(vfsfile_t *fp)
{ {
unsigned long ret; unsigned long ret;
ret = ((fgetc(fp)) & 0xff); ret = ((VFS_GETC(fp)) & 0xff);
ret |= ((fgetc(fp)) & 0xff) << 8; ret |= ((VFS_GETC(fp)) & 0xff) << 8;
ret |= ((fgetc(fp)) & 0xff) << 16; ret |= ((VFS_GETC(fp)) & 0xff) << 16;
ret |= ((fgetc(fp)) & 0xff) << 24; ret |= ((VFS_GETC(fp)) & 0xff) << 24;
return(ret); return(ret);
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
static int roq_parse_file(FILE *fp, roq_info *ri) static int roq_parse_file(vfsfile_t *fp, roq_info *ri)
{ {
unsigned int head1, head3, chunk_id, chunk_arg; unsigned int head1, head3, chunk_id, chunk_arg;
long head2, chunk_size; long head2, chunk_size;
@ -67,7 +75,7 @@ long fpos;
int max_frame; int max_frame;
#endif #endif
#define rfeof(f) (ftell(f)>= ri->maxpos) #define rfeof(f) (VFS_TELL(f)>= ri->maxpos)
#ifndef FAST #ifndef FAST
ri->num_audio_bytes = ri->num_frames = max_frame = 0; ri->num_audio_bytes = ri->num_frames = max_frame = 0;
@ -79,32 +87,34 @@ int max_frame;
head2 = get_long(fp); head2 = get_long(fp);
head3 = get_word(fp); head3 = get_word(fp);
if(head1 != 0x1084 && head2 != 0xffffffff && head3 != 0x1e) if(head1 != 0x1084 && head2 != 0xffffffff && head3 != 0x1e)
{ {
Con_Printf("Not an RoQ file.\n"); Con_Printf("Not an RoQ file.\n");
return 1; return 1;
} }
ri->roq_start = ftell(fp); ri->roq_start = VFS_TELL(fp);
while(!rfeof(fp)) while(!rfeof(fp))
{ {
#if DBUG > 20 #if DBUG > 20
Con_Printf("---------------------------------------------------------------------------\n"); Con_Printf("---------------------------------------------------------------------------\n");
#endif #endif
fpos = ftell(fp); fpos = VFS_TELL(fp);
chunk_id = get_word(fp); chunk_id = get_word(fp);
chunk_size = get_long(fp); chunk_size = get_long(fp);
chunk_arg = get_word(fp); chunk_arg = get_word(fp);
if (chunk_size == -1) //FIXME: THIS SHOULD NOT HAPPEN if (chunk_size == -1) //FIXME: THIS SHOULD NOT HAPPEN
break; break;
if(chunk_size > ri->buf_size) ri->buf_size = chunk_size; if(chunk_size > ri->buf_size)
if(rfeof(fp)) break; ri->buf_size = chunk_size;
if(rfeof(fp))
break;
#if DBUG > 20 #if DBUG > 20
Con_Printf("%03d 0x%06lx: chunk: 0x%02x size: %ld cells: 2x2=%d,4x4=%d\n", i, Con_Printf("%03d 0x%06lx: chunk: 0x%02x size: %ld cells: 2x2=%d,4x4=%d\n", i,
fpos, chunk_id, chunk_size, v1>>8,v1&0xff); fpos, chunk_id, chunk_size, v1>>8,v1&0xff);
#endif #endif
if(chunk_id == RoQ_INFO) /* video info */ if(chunk_id == RoQ_INFO) /* video info */
{ {
ri->width = get_word(fp); ri->width = get_word(fp);
ri->height = get_word(fp); ri->height = get_word(fp);
get_word(fp); get_word(fp);
@ -112,32 +122,35 @@ int max_frame;
#ifdef FAST #ifdef FAST
return 0; //we have all the data we need now. We always find a sound chunk first, or none at all. return 0; //we have all the data we need now. We always find a sound chunk first, or none at all.
#endif #endif
} }
else else
{ {
#ifndef FAST #ifndef FAST
if(chunk_id == RoQ_QUAD_VQ) if(chunk_id == RoQ_QUAD_VQ)
{ {
ri->num_frames++; ri->num_frames++;
if(ri->num_frames > max_frame) if(ri->num_frames > max_frame)
{ {
max_frame += 5000; max_frame += 5000;
if((ri->frame_offset = BZ_Realloc(ri->frame_offset, sizeof(long) * max_frame)) == NULL) return 1; if((ri->frame_offset = BZ_Realloc(ri->frame_offset, sizeof(long) * max_frame)) == NULL)
} return 1;
ri->frame_offset[ri->num_frames] = fpos;
} }
ri->frame_offset[ri->num_frames] = fpos;
}
#endif #endif
if(chunk_id == RoQ_SOUND_MONO || chunk_id == RoQ_SOUND_STEREO) if(chunk_id == RoQ_SOUND_MONO || chunk_id == RoQ_SOUND_STEREO)
{ {
if(chunk_id == RoQ_SOUND_MONO) ri->audio_channels = 1; if(chunk_id == RoQ_SOUND_MONO)
else ri->audio_channels = 2; ri->audio_channels = 1;
else
ri->audio_channels = 2;
#ifndef FAST #ifndef FAST
ri->num_audio_bytes += chunk_size; ri->num_audio_bytes += chunk_size;
#endif #endif
}
fseek(fp, chunk_size, SEEK_CUR);
} }
VFS_SEEK(fp, VFS_TELL(fp) + chunk_size);
} }
}
return 0; return 0;
} }
@ -211,34 +224,34 @@ unsigned char *pa, *pb;
pa = ri->y[0] + (y * ri->width) + x; pa = ri->y[0] + (y * ri->width) + x;
pb = ri->y[1] + (my * ri->width) + mx; pb = ri->y[1] + (my * ri->width) + mx;
for(i = 0; i < 4; i++) for(i = 0; i < 4; i++)
{ {
pa[0] = pb[0]; pa[0] = pb[0];
pa[1] = pb[1]; pa[1] = pb[1];
pa[2] = pb[2]; pa[2] = pb[2];
pa[3] = pb[3]; pa[3] = pb[3];
pa += ri->width; pa += ri->width;
pb += ri->width; pb += ri->width;
} }
pa = ri->u[0] + (y/2) * (ri->width/2) + x/2; pa = ri->u[0] + (y/2) * (ri->width/2) + x/2;
pb = ri->u[1] + (my/2) * (ri->width/2) + (mx + 1)/2; pb = ri->u[1] + (my/2) * (ri->width/2) + (mx + 1)/2;
for(i = 0; i < 2; i++) for(i = 0; i < 2; i++)
{ {
pa[0] = pb[0]; pa[0] = pb[0];
pa[1] = pb[1]; pa[1] = pb[1];
pa += ri->width/2; pa += ri->width/2;
pb += ri->width/2; pb += ri->width/2;
} }
pa = ri->v[0] + (y/2) * (ri->width/2) + x/2; pa = ri->v[0] + (y/2) * (ri->width/2) + x/2;
pb = ri->v[1] + (my/2) * (ri->width/2) + (mx + 1)/2; pb = ri->v[1] + (my/2) * (ri->width/2) + (mx + 1)/2;
for(i = 0; i < 2; i++) for(i = 0; i < 2; i++)
{ {
pa[0] = pb[0]; pa[0] = pb[0];
pa[1] = pb[1]; pa[1] = pb[1];
pa += ri->width/2; pa += ri->width/2;
pb += ri->width/2; pb += ri->width/2;
} }
} }
@ -254,7 +267,7 @@ unsigned char *pa, *pb;
pa = ri->y[0] + (y * ri->width) + x; pa = ri->y[0] + (y * ri->width) + x;
pb = ri->y[1] + (my * ri->width) + mx; pb = ri->y[1] + (my * ri->width) + mx;
for(i = 0; i < 8; i++) for(i = 0; i < 8; i++)
{ {
pa[0] = pb[0]; pa[0] = pb[0];
pa[1] = pb[1]; pa[1] = pb[1];
pa[2] = pb[2]; pa[2] = pb[2];
@ -265,86 +278,88 @@ unsigned char *pa, *pb;
pa[7] = pb[7]; pa[7] = pb[7];
pa += ri->width; pa += ri->width;
pb += ri->width; pb += ri->width;
} }
pa = ri->u[0] + (y/2) * (ri->width/2) + x/2; pa = ri->u[0] + (y/2) * (ri->width/2) + x/2;
pb = ri->u[1] + (my/2) * (ri->width/2) + (mx + 1)/2; pb = ri->u[1] + (my/2) * (ri->width/2) + (mx + 1)/2;
for(i = 0; i < 4; i++) for(i = 0; i < 4; i++)
{ {
pa[0] = pb[0]; pa[0] = pb[0];
pa[1] = pb[1]; pa[1] = pb[1];
pa[2] = pb[2]; pa[2] = pb[2];
pa[3] = pb[3]; pa[3] = pb[3];
pa += ri->width/2; pa += ri->width/2;
pb += ri->width/2; pb += ri->width/2;
} }
pa = ri->v[0] + (y/2) * (ri->width/2) + x/2; pa = ri->v[0] + (y/2) * (ri->width/2) + x/2;
pb = ri->v[1] + (my/2) * (ri->width/2) + (mx + 1)/2; pb = ri->v[1] + (my/2) * (ri->width/2) + (mx + 1)/2;
for(i = 0; i < 4; i++) for(i = 0; i < 4; i++)
{ {
pa[0] = pb[0]; pa[0] = pb[0];
pa[1] = pb[1]; pa[1] = pb[1];
pa[2] = pb[2]; pa[2] = pb[2];
pa[3] = pb[3]; pa[3] = pb[3];
pa += ri->width/2; pa += ri->width/2;
pb += ri->width/2; pb += ri->width/2;
} }
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
roq_info *roq_open(char *fname) roq_info *roq_open(char *fname)
{ {
FILE *fp; vfsfile_t *fp;
roq_info *ri; roq_info *ri;
int i; int i;
if (COM_FOpenFile(fname, &fp)==-1) // if (COM_FOpenFile(fname, &fp)==-1)
// if((fp = fopen(fname, "rb")) == NULL) if((fp = FS_OpenVFS(fname, "rb", FS_GAME)) == NULL)
{ {
return NULL; return NULL;
} }
if((ri = BZF_Malloc(sizeof(roq_info))) == NULL) if((ri = BZF_Malloc(sizeof(roq_info))) == NULL)
{ {
Con_Printf("Error allocating memory.\n"); Con_Printf("Error allocating memory.\n");
return NULL; return NULL;
} }
memset(ri, 0, sizeof(roq_info)); memset(ri, 0, sizeof(roq_info));
ri->maxpos = ftell(fp)+com_filesize;//no adds/subracts for fileoffset here com_filesize = VFS_GETLEN(fp);
ri->maxpos = VFS_TELL(fp)+com_filesize;//no adds/subracts for fileoffset here
ri->fp = fp; ri->fp = fp;
if(roq_parse_file(fp, ri)) return NULL; if(roq_parse_file(fp, ri))
return NULL;
#ifndef FAST #ifndef FAST
ri->stream_length = (ri->num_frames * 1000)/30; ri->stream_length = (ri->num_frames * 1000)/30;
#endif #endif
for(i = 0; i < 128; i++) for(i = 0; i < 128; i++)
{ {
ri->snd_sqr_arr[i] = i * i; ri->snd_sqr_arr[i] = i * i;
ri->snd_sqr_arr[i + 128] = -(i * i); ri->snd_sqr_arr[i + 128] = -(i * i);
} }
for(i = 0; i < 2; i++) for(i = 0; i < 2; i++)
{ {
if((ri->y[i] = BZF_Malloc(ri->width * ri->height)) == NULL || if((ri->y[i] = BZF_Malloc(ri->width * ri->height)) == NULL ||
(ri->u[i] = BZF_Malloc((ri->width * ri->height)/4)) == NULL || (ri->u[i] = BZF_Malloc((ri->width * ri->height)/4)) == NULL ||
(ri->v[i] = BZF_Malloc((ri->width * ri->height)/4)) == NULL) (ri->v[i] = BZF_Malloc((ri->width * ri->height)/4)) == NULL)
{ {
Con_Printf("Memory allocation error.\n"); Con_Printf("Memory allocation error.\n");
return NULL; return NULL;
}
} }
}
ri->buf_size *= 2; ri->buf_size *= 2;
if((ri->buf = BZF_Malloc(ri->buf_size)) == NULL) if((ri->buf = BZF_Malloc(ri->buf_size)) == NULL)
{ {
Con_Printf("Memory allocation error.\n"); Con_Printf("Memory allocation error.\n");
return NULL; return NULL;
} }
ri->audio_buf_size = 0; ri->audio_buf_size = 0;
ri->audio = NULL; ri->audio = NULL;
@ -360,15 +375,20 @@ void roq_close(roq_info *ri)
{ {
int i; int i;
if(ri == NULL) return; if(ri == NULL)
fclose(ri->fp); return;
VFS_CLOSE(ri->fp);
for(i = 0; i < 2; i++) for(i = 0; i < 2; i++)
{ {
if(ri->y[i] != NULL) BZ_Free(ri->y[i]); if(ri->y[i] != NULL)
if(ri->u[i] != NULL) BZ_Free(ri->u[i]); BZ_Free(ri->y[i]);
if(ri->v[i] != NULL) BZ_Free(ri->v[i]); if(ri->u[i] != NULL)
} BZ_Free(ri->u[i]);
if(ri->buf != NULL) BZ_Free(ri->buf); if(ri->v[i] != NULL)
BZ_Free(ri->v[i]);
}
if(ri->buf != NULL)
BZ_Free(ri->buf);
BZ_Free(ri); BZ_Free(ri);
} }
@ -376,7 +396,7 @@ int i;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int roq_read_frame(roq_info *ri) int roq_read_frame(roq_info *ri)
{ {
FILE *fp = ri->fp; vfsfile_t *fp = ri->fp;
unsigned int chunk_id = 0, chunk_arg = 0; unsigned int chunk_id = 0, chunk_arg = 0;
unsigned long chunk_size = 0; unsigned long chunk_size = 0;
int i, j, k, nv1, nv2, vqflg = 0, vqflg_pos = -1, vqid, bpos, xpos, ypos, xp, yp, x, y; int i, j, k, nv1, nv2, vqflg = 0, vqflg_pos = -1, vqid, bpos, xpos, ypos, xp, yp, x, y;
@ -384,75 +404,72 @@ unsigned char *tp, *buf;
int frame_stats[2][4] = {{0},{0}}; int frame_stats[2][4] = {{0},{0}};
roq_qcell *qcell; roq_qcell *qcell;
fseek(fp, ri->vid_pos, SEEK_SET); VFS_SEEK(fp, ri->vid_pos);
while(!rfeof(fp)) while(!rfeof(fp))
{ {
chunk_id = get_word(fp); chunk_id = get_word(fp);
chunk_size = get_long(fp); chunk_size = get_long(fp);
chunk_arg = get_word(fp); chunk_arg = get_word(fp);
if (chunk_size == 0xffffffff) if (chunk_size == 0xffffffff)
return -1; return -1;
if(rfeof(fp)) break; if(rfeof(fp))
if(chunk_id == RoQ_QUAD_VQ) break; break;
if(chunk_id == RoQ_QUAD_VQ)
break;
if(chunk_id == RoQ_QUAD_CODEBOOK) if(chunk_id == RoQ_QUAD_CODEBOOK)
{ {
if((nv1 = chunk_arg >> 8) == 0) nv1 = 256; if((nv1 = chunk_arg >> 8) == 0)
if((nv2 = chunk_arg & 0xff) == 0 && nv1 * 6 < chunk_size) nv2 = 256; nv1 = 256;
for(i = 0; i < nv1; i++) if((nv2 = chunk_arg & 0xff) == 0 && nv1 * 6 < chunk_size)
{ nv2 = 256;
ri->cells[i].y0 = fgetc(fp); VFS_READ(fp, ri->cells, nv1 * sizeof(roq_cell));
ri->cells[i].y1 = fgetc(fp);
ri->cells[i].y2 = fgetc(fp);
ri->cells[i].y3 = fgetc(fp);
ri->cells[i].u = fgetc(fp);
ri->cells[i].v = fgetc(fp);
}
for(i = 0; i < nv2; i++) for(i = 0; i < nv2; i++)
for(j = 0; j < 4; j++) ri->qcells[i].idx[j] = fgetc(fp); for(j = 0; j < 4; j++) ri->qcells[i].idx[j] = VFS_GETC(fp);
}
else fseek(fp, chunk_size, SEEK_CUR);
} }
else
VFS_SEEK(fp, VFS_TELL(fp)+chunk_size);
}
if(chunk_id != RoQ_QUAD_VQ) if(chunk_id != RoQ_QUAD_VQ)
{ {
ri->vid_pos = ftell(fp); ri->vid_pos = VFS_TELL(fp);
return 0; return 0;
} }
ri->frame_num++; ri->frame_num++;
if(ri->buf_size < chunk_size) if(ri->buf_size < chunk_size)
{ {
ri->buf_size *= 2; ri->buf_size *= 2;
if (ri->buf_size < chunk_size) //double wasn't enough if (ri->buf_size < chunk_size) //double wasn't enough
ri->buf_size = chunk_size; ri->buf_size = chunk_size;
BZ_Free(ri->buf); BZ_Free(ri->buf);
if((ri->buf = BZ_Malloc(ri->buf_size)) == NULL) if((ri->buf = BZ_Malloc(ri->buf_size)) == NULL)
{ {
Con_Printf("Memory allocation error.\n"); Con_Printf("Memory allocation error.\n");
return -1; return -1;
}
} }
fread(ri->buf, chunk_size, 1, fp); }
VFS_READ(fp, ri->buf, chunk_size);
buf = ri->buf; buf = ri->buf;
bpos = xpos = ypos = 0; bpos = xpos = ypos = 0;
while(bpos < chunk_size) while(bpos < chunk_size)
{ {
for(yp = ypos; yp < ypos + 16; yp += 8) for(yp = ypos; yp < ypos + 16; yp += 8)
for(xp = xpos; xp < xpos + 16; xp += 8) for(xp = xpos; xp < xpos + 16; xp += 8)
{ {
if(vqflg_pos < 0) if(vqflg_pos < 0)
{ {
vqflg = buf[bpos++]; vqflg |= (buf[bpos++] << 8); vqflg = buf[bpos++]; vqflg |= (buf[bpos++] << 8);
vqflg_pos = 7; vqflg_pos = 7;
} }
vqid = (vqflg >> (vqflg_pos * 2)) & 0x3; vqid = (vqflg >> (vqflg_pos * 2)) & 0x3;
frame_stats[0][vqid]++; frame_stats[0][vqid]++;
vqflg_pos--; vqflg_pos--;
switch(vqid) switch(vqid)
{ {
case RoQ_ID_MOT: break; case RoQ_ID_MOT: break;
case RoQ_ID_FCC: case RoQ_ID_FCC:
apply_motion_8x8(ri, xp, yp, buf[bpos++], (char)(chunk_arg >> 8), (char)(chunk_arg & 0xff)); apply_motion_8x8(ri, xp, yp, buf[bpos++], (char)(chunk_arg >> 8), (char)(chunk_arg & 0xff));
@ -466,21 +483,21 @@ roq_qcell *qcell;
break; break;
case RoQ_ID_CCC: case RoQ_ID_CCC:
for(k = 0; k < 4; k++) for(k = 0; k < 4; k++)
{ {
x = xp; y = yp; x = xp; y = yp;
if(k & 0x01) x += 4; if(k & 0x01) x += 4;
if(k & 0x02) y += 4; if(k & 0x02) y += 4;
if(vqflg_pos < 0) if(vqflg_pos < 0)
{ {
vqflg = buf[bpos++]; vqflg |= (buf[bpos++] << 8); vqflg = buf[bpos++]; vqflg |= (buf[bpos++] << 8);
vqflg_pos = 7; vqflg_pos = 7;
} }
vqid = (vqflg >> (vqflg_pos * 2)) & 0x3; vqid = (vqflg >> (vqflg_pos * 2)) & 0x3;
frame_stats[1][vqid]++; frame_stats[1][vqid]++;
vqflg_pos--; vqflg_pos--;
switch(vqid) switch(vqid)
{ {
case RoQ_ID_MOT: break; case RoQ_ID_MOT: break;
case RoQ_ID_FCC: case RoQ_ID_FCC:
apply_motion_4x4(ri, x, y, buf[bpos++], (char)(chunk_arg >> 8), (char)(chunk_arg & 0xff)); apply_motion_4x4(ri, x, y, buf[bpos++], (char)(chunk_arg >> 8), (char)(chunk_arg & 0xff));
@ -499,22 +516,22 @@ roq_qcell *qcell;
apply_vector_2x2(ri, x+2, y+2, ri->cells + buf[bpos+3]); apply_vector_2x2(ri, x+2, y+2, ri->cells + buf[bpos+3]);
bpos += 4; bpos += 4;
break; break;
}
} }
}
break; break;
default: default:
Con_Printf("Unknown vq code: %d\n", vqid); Con_Printf("Unknown vq code: %d\n", vqid);
}
} }
}
xpos += 16; xpos += 16;
if(xpos >= ri->width) if(xpos >= ri->width)
{ {
xpos -= ri->width; xpos -= ri->width;
ypos += 16; ypos += 16;
}
if(ypos >= ri->height) break;
} }
if(ypos >= ri->height) break;
}
#if 0 #if 0
frame_stats[0][3] = 0; frame_stats[0][3] = 0;
@ -523,20 +540,28 @@ roq_qcell *qcell;
Con_Printf("for 04x04 CCC = %d, FCC = %d, MOT = %d, SLD = %d, PAT = 0\n", frame_stats[1][3], frame_stats[1][1], frame_stats[1][0], frame_stats[1][2]); Con_Printf("for 04x04 CCC = %d, FCC = %d, MOT = %d, SLD = %d, PAT = 0\n", frame_stats[1][3], frame_stats[1][1], frame_stats[1][0], frame_stats[1][2]);
#endif #endif
ri->vid_pos = ftell(fp); ri->vid_pos = VFS_TELL(fp);
if(ri->frame_num == 1) if(ri->frame_num == 1)
{ {
memcpy(ri->y[1], ri->y[0], ri->width * ri->height); memcpy(ri->y[1], ri->y[0], ri->width * ri->height);
memcpy(ri->u[1], ri->u[0], (ri->width * ri->height)/4); memcpy(ri->u[1], ri->u[0], (ri->width * ri->height)/4);
memcpy(ri->v[1], ri->v[0], (ri->width * ri->height)/4); memcpy(ri->v[1], ri->v[0], (ri->width * ri->height)/4);
} }
else else
{ {
tp = ri->y[0]; ri->y[0] = ri->y[1]; ri->y[1] = tp; tp = ri->y[0];
tp = ri->u[0]; ri->u[0] = ri->u[1]; ri->u[1] = tp; ri->y[0] = ri->y[1];
tp = ri->v[0]; ri->v[0] = ri->v[1]; ri->v[1] = tp; ri->y[1] = tp;
}
tp = ri->u[0];
ri->u[0] = ri->u[1];
ri->u[1] = tp;
tp = ri->v[0];
ri->v[0] = ri->v[1];
ri->v[1] = tp;
}
return 1; return 1;
} }
@ -545,16 +570,16 @@ roq_qcell *qcell;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int roq_read_audio(roq_info *ri) int roq_read_audio(roq_info *ri)
{ {
FILE *fp = ri->fp; vfsfile_t *fp = ri->fp;
unsigned int chunk_id = 0, chunk_arg = 0; unsigned int chunk_id = 0, chunk_arg = 0;
unsigned long chunk_size = 0; unsigned long chunk_size = 0;
int i, snd_left, snd_right; int i, snd_left, snd_right;
fseek(fp, ri->aud_pos, SEEK_SET); VFS_SEEK(fp, ri->aud_pos);
ri->audio_size = 0; ri->audio_size = 0;
for(;;) for(;;)
{ {
if(rfeof(fp)) if(rfeof(fp))
return -1; return -1;
chunk_id = get_word(fp); chunk_id = get_word(fp);
@ -566,51 +591,51 @@ int i, snd_left, snd_right;
return -1; return -1;
if (chunk_id == RoQ_SOUND_MONO || chunk_id == RoQ_SOUND_STEREO) if (chunk_id == RoQ_SOUND_MONO || chunk_id == RoQ_SOUND_STEREO)
break; break;
fseek(fp, chunk_size, SEEK_CUR); VFS_SEEK(fp, VFS_TELL(fp)+chunk_size);
} }
if(ri->audio_buf_size < chunk_size*2) if(ri->audio_buf_size < chunk_size*2)
{ {
if(ri->audio != NULL) BZ_Free(ri->audio); if(ri->audio != NULL) BZ_Free(ri->audio);
ri->audio=NULL; ri->audio=NULL;
ri->audio_buf_size = chunk_size * 3; ri->audio_buf_size = chunk_size * 3;
if (ri->audio_buf_size <= 0) if (ri->audio_buf_size <= 0)
return -1; return -1;
if((ri->audio = BZ_Malloc(ri->audio_buf_size)) == NULL) return -1; if((ri->audio = BZ_Malloc(ri->audio_buf_size)) == NULL) return -1;
} }
if (ri->audio_buf_size < 0) if (ri->audio_buf_size < 0)
return -1; return -1;
if(chunk_id == RoQ_SOUND_MONO) if(chunk_id == RoQ_SOUND_MONO)
{ {
ri->audio_size = chunk_size; ri->audio_size = chunk_size;
snd_left = chunk_arg; snd_left = chunk_arg;
for(i = 0; i < chunk_size; i++) for(i = 0; i < chunk_size; i++)
{ {
snd_left += (int)ri->snd_sqr_arr[(unsigned)fgetc(fp)]; snd_left += (int)ri->snd_sqr_arr[(unsigned)VFS_GETC(fp)];
*(short *)&ri->audio[i * 2] = snd_left; *(short *)&ri->audio[i * 2] = snd_left;
}
ri->aud_pos = ftell(fp);
return chunk_size;
} }
ri->aud_pos = VFS_TELL(fp);
return chunk_size;
}
if(chunk_id == RoQ_SOUND_STEREO) if(chunk_id == RoQ_SOUND_STEREO)
{ {
ri->audio_size = chunk_size; ri->audio_size = chunk_size;
snd_left = (chunk_arg & 0xFF00); snd_left = (chunk_arg & 0xFF00);
snd_right = (chunk_arg & 0xFF) << 8; snd_right = (chunk_arg & 0xFF) << 8;
for(i = 0; i < chunk_size; i += 2) for(i = 0; i < chunk_size; i += 2)
{ {
snd_left += (int)ri->snd_sqr_arr[(unsigned)fgetc(fp)]; snd_left += (int)ri->snd_sqr_arr[(unsigned)VFS_GETC(fp)];
snd_right += (int)ri->snd_sqr_arr[(unsigned)fgetc(fp)]; snd_right += (int)ri->snd_sqr_arr[(unsigned)VFS_GETC(fp)];
*(short *)&ri->audio[i * 2] = snd_left; *(short *)&ri->audio[i * 2] = snd_left;
*(short *)&ri->audio[i * 2 + 2] = snd_right; *(short *)&ri->audio[i * 2 + 2] = snd_right;
}
ri->aud_pos = ftell(fp);
return chunk_size;
} }
ri->aud_pos = VFS_TELL(fp);
return chunk_size;
}
ri->aud_pos = ftell(fp); ri->aud_pos = VFS_TELL(fp);
return 0; return 0;
} }
#undef rfeof #undef rfeof

View file

@ -213,9 +213,6 @@ qboolean S_RegisterSoundInputPlugin(S_LoadSound_t loadfnc)
S_LoadSound S_LoadSound
============== ==============
*/ */
#ifdef AVAIL_MP3
sfxcache_t *S_LoadMP3Sound (sfx_t *s);
#endif
sfxcache_t *S_LoadSound (sfx_t *s) sfxcache_t *S_LoadSound (sfx_t *s)
{ {
@ -235,13 +232,6 @@ sfxcache_t *S_LoadSound (sfx_t *s)
s->decoder = NULL; s->decoder = NULL;
#ifdef AVAIL_MP3
//mp3 support. The only bit actual code outside snd_mp3.c (excluding def for the function call)
sc = S_LoadMP3Sound(s); // try and load a replacement mp3 instead.
if (sc)
return sc;
#endif
if (name[1] == ':' && name[2] == '\\') if (name[1] == ':' && name[2] == '\\')

View file

@ -72,6 +72,13 @@ int viewportx;
int viewporty; int viewporty;
static int VFS_GETC(vfsfile_t *fp)
{
unsigned char c;
VFS_READ(fp, &c, 1);
return c;
}
//newsize = number of chars, EXCLUDING terminator. //newsize = number of chars, EXCLUDING terminator.
void MakeNewSize(fileblock_t *block, int newsize) //this is used to resize a block. It allocates a new one, copys the data frees the old one and links it into the right place void MakeNewSize(fileblock_t *block, int newsize) //this is used to resize a block. It allocates a new one, copys the data frees the old one and links it into the right place
//it is called when the user is typing //it is called when the user is typing
@ -248,33 +255,29 @@ void EditorOpenFile(char *name)
int i; int i;
char line[8192]; char line[8192];
int len, flen, pos=0; int len, flen, pos=0;
FILE *F; vfsfile_t *F;
fileblock_t *b; fileblock_t *b;
CloseEditor(); CloseEditor();
strcpy(OpenEditorFile, name); strcpy(OpenEditorFile, name);
if ((flen=COM_FOpenFile(OpenEditorFile, &F)) == -1) if (!(F = FS_OpenVFS(OpenEditorFile, "rb", FS_GAME)))
{ {
sprintf(OpenEditorFile, "src/%s", name); sprintf(OpenEditorFile, "src/%s", name);
if ((flen=COM_FOpenFile(OpenEditorFile, &F)) == -1) if (!(F = FS_OpenVFS(OpenEditorFile, "rb", FS_GAME)))
{ {
F = fopen(OpenEditorFile, "rb"); Con_Printf("Couldn't open file \"%s\"\nA new file will be created\n", name);
if (F) strcpy(OpenEditorFile, name);
flen = COM_filelength(F); key_dest = key_console;
else EditorNewFile();
{ return;
Con_Printf("Couldn't open file \"%s\"\nA new file will be created\n", name);
strcpy(OpenEditorFile, name);
key_dest = key_console;
EditorNewFile();
return;
}
} }
} }
i=1; i=1;
flen = VFS_GETLEN(F);
while(pos < flen) while(pos < flen)
{ {
len = 0; len = 0;
@ -282,7 +285,7 @@ void EditorOpenFile(char *name)
{ {
if (pos+len >= flen) if (pos+len >= flen)
break; break;
line[len] = fgetc(F); line[len] = VFS_GETC(F);
if (line[len] == '\n') if (line[len] == '\n')
break; break;
@ -333,7 +336,7 @@ void EditorOpenFile(char *name)
} }
else else
for (; firstblock->prev; firstblock=firstblock->prev); for (; firstblock->prev; firstblock=firstblock->prev);
fclose(F); VFS_CLOSE(F);
cursorblock = firstblock; cursorblock = firstblock;
cursorx = 0; cursorx = 0;
@ -955,23 +958,23 @@ int QCLibEditor(progfuncs_t *prfncs, char *filename, int line, int nump, char **
int i; int i;
char buffer[8192]; char buffer[8192];
char *r; char *r;
FILE *f; vfsfile_t *f;
if (line == -1) if (line == -1)
return -1; return -1;
COM_FOpenFile(filename, &f); f = FS_OpenVFS(filename, "rb", FS_GAME);
if (!f) if (!f)
Con_Printf("%s - %i\n", filename, line); Con_Printf("%s - %i\n", filename, line);
else else
{ {
for (i = 0; i < line; i++) for (i = 0; i < line; i++)
{ {
fgets(buffer, sizeof(buffer), f); VFS_GETS(f, buffer, sizeof(buffer));
} }
if ((r = strchr(buffer, '\r'))) if ((r = strchr(buffer, '\r')))
{ r[0] = '\n';r[1]='\0';} { r[0] = '\n';r[1]='\0';}
Con_Printf("%s", buffer); Con_Printf("%s", buffer);
fclose(f); VFS_CLOSE(f);
} }
//PF_break(NULL); //PF_break(NULL);
return line; return line;

View file

@ -235,7 +235,7 @@ void SwapPic (qpic_t *pic)
typedef struct typedef struct
{ {
char name[16]; char name[16];
FILE *file; vfsfile_t *file;
int position; int position;
int size; int size;
} texwadlump_t; } texwadlump_t;
@ -275,7 +275,7 @@ void W_LoadTextureWadFile (char *filename, int complain)
wadinfo_t header; wadinfo_t header;
int i, j; int i, j;
int infotableofs; int infotableofs;
FILE *file; vfsfile_t *file;
int numlumps; int numlumps;
wadfile_t *wf = openwadfiles; wadfile_t *wf = openwadfiles;
@ -287,9 +287,9 @@ void W_LoadTextureWadFile (char *filename, int complain)
wf = wf->next; wf = wf->next;
} }
COM_FOpenFile (filename, &file); file = FS_OpenVFS(filename, "rb", FS_GAME);
if (!file) if (!file)
COM_FOpenFile (va("textures/halflife/%s", filename), &file); file = FS_OpenVFS(va("textures/halflife/%s", filename), "rb", FS_GAME);
if (!file) if (!file)
{ {
if (complain) if (complain)
@ -297,7 +297,7 @@ void W_LoadTextureWadFile (char *filename, int complain)
return; return;
} }
if (fread(&header, 1, sizeof(wadinfo_t), file) != sizeof(wadinfo_t)) if (VFS_READ(file, &header, sizeof(wadinfo_t)) != sizeof(wadinfo_t))
{Con_Printf ("W_LoadTextureWadFile: unable to read wad header");return;} {Con_Printf ("W_LoadTextureWadFile: unable to read wad header");return;}
if(memcmp(header.identification, "WAD3", 4)) if(memcmp(header.identification, "WAD3", 4))
@ -307,12 +307,12 @@ void W_LoadTextureWadFile (char *filename, int complain)
if (numlumps < 1 || numlumps > TEXWAD_MAXIMAGES) if (numlumps < 1 || numlumps > TEXWAD_MAXIMAGES)
{Con_Printf ("W_LoadTextureWadFile: invalid number of lumps (%i)\n", numlumps);return;} {Con_Printf ("W_LoadTextureWadFile: invalid number of lumps (%i)\n", numlumps);return;}
infotableofs = LittleLong(header.infotableofs); infotableofs = LittleLong(header.infotableofs);
if (fseek(file, infotableofs, SEEK_SET)) if (VFS_SEEK(file, infotableofs))
{Con_Printf ("W_LoadTextureWadFile: unable to seek to lump table");return;} {Con_Printf ("W_LoadTextureWadFile: unable to seek to lump table");return;}
if (!((lumps = Hunk_TempAlloc(sizeof(lumpinfo_t)*numlumps)))) if (!((lumps = Hunk_TempAlloc(sizeof(lumpinfo_t)*numlumps))))
{Con_Printf ("W_LoadTextureWadFile: unable to allocate temporary memory for lump table");return;} {Con_Printf ("W_LoadTextureWadFile: unable to allocate temporary memory for lump table");return;}
if (fread(lumps, 1, sizeof(lumpinfo_t)*numlumps, file) != (int)sizeof(lumpinfo_t) * numlumps) if (VFS_READ(file, lumps, sizeof(lumpinfo_t)*numlumps) != (int)sizeof(lumpinfo_t) * numlumps)
{Con_Printf ("W_LoadTextureWadFile: unable to read lump table");return;} {Con_Printf ("W_LoadTextureWadFile: unable to read lump table");return;}
for (i=0, lump_p = lumps ; i<numlumps ; i++,lump_p++) for (i=0, lump_p = lumps ; i<numlumps ; i++,lump_p++)
@ -426,7 +426,7 @@ qbyte *W_GetTexture(char *name, int *width, int *height, qboolean *usesalpha)//r
{ {
char texname[17]; char texname[17];
int i, j; int i, j;
FILE *file; vfsfile_t *file;
miptex_t *tex; miptex_t *tex;
qbyte *data; qbyte *data;
@ -437,13 +437,13 @@ qbyte *W_GetTexture(char *name, int *width, int *height, qboolean *usesalpha)//r
if (!strcmp(texname, texwadlump[i].name)) // found it if (!strcmp(texname, texwadlump[i].name)) // found it
{ {
file = texwadlump[i].file; file = texwadlump[i].file;
if (fseek(file, texwadlump[i].position, SEEK_SET)) if (VFS_SEEK(file, texwadlump[i].position))
{Con_Printf("W_GetTexture: corrupt WAD3 file");return NULL;} {Con_Printf("W_GetTexture: corrupt WAD3 file");return NULL;}
tex = BZ_Malloc(texwadlump[i].size); //temp buffer for disk info (was hunk_tempalloc, but that wiped loading maps and the like tex = BZ_Malloc(texwadlump[i].size); //temp buffer for disk info (was hunk_tempalloc, but that wiped loading maps and the like
if (!tex) if (!tex)
return NULL; return NULL;
if (fread(tex, 1, texwadlump[i].size, file) < texwadlump[i].size) if (VFS_READ(file, tex, texwadlump[i].size) < texwadlump[i].size)
{Con_Printf("W_GetTexture: corrupt WAD3 file");return NULL;} {Con_Printf("W_GetTexture: corrupt WAD3 file");return NULL;}
tex->width = LittleLong(tex->width); tex->width = LittleLong(tex->width);

View file

@ -2962,7 +2962,6 @@ qbool TP_CheckSoundTrigger (char *str)
int i, j; int i, j;
int start, length; int start, length;
char soundname[MAX_OSPATH]; char soundname[MAX_OSPATH];
FILE *f;
if (!*str) if (!*str)
return false; return false;
@ -3008,10 +3007,8 @@ qbool TP_CheckSoundTrigger (char *str)
COM_DefaultExtension (soundname, ".wav"); COM_DefaultExtension (soundname, ".wav");
// make sure we have it on disk (FIXME) // make sure we have it on disk (FIXME)
COM_FOpenFile (va("sound/%s", soundname), &f); if (!FS_FLocateFile (va("sound/%s", soundname), FSLFRT_IFFOUND, NULL))
if (!f)
return false; return false;
fclose (f);
// now play the sound // now play the sound
S_LocalSound (soundname); S_LocalSound (soundname);

View file

@ -42,8 +42,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define AVAIL_JPEGLIB #define AVAIL_JPEGLIB
#define AVAIL_ZLIB #define AVAIL_ZLIB
// #define AVAIL_MP3
#define AVAIL_OGGVORBIS #define AVAIL_OGGVORBIS
#endif #endif
#define AVAIL_MASM #define AVAIL_MASM
@ -58,9 +56,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifdef NO_ZLIB #ifdef NO_ZLIB
#undef AVAIL_ZLIB #undef AVAIL_ZLIB
#endif #endif
#ifdef NO_MAD
#undef AVAIL_MP3
#endif
#ifdef NO_OGG #ifdef NO_OGG
#undef AVAIL_OGGVORBIS #undef AVAIL_OGGVORBIS
#endif #endif
@ -84,7 +79,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifdef MINIMAL #ifdef MINIMAL
#define CL_MASTER //this is useful #define CL_MASTER //this is useful
#undef AVAIL_MP3 //no mp3 support
#undef AVAIL_JPEGLIB //no jpeg support #undef AVAIL_JPEGLIB //no jpeg support
#undef AVAIL_PNGLIB //no png support #undef AVAIL_PNGLIB //no png support
#undef USE_MADLIB //no internal mp3 playing #undef USE_MADLIB //no internal mp3 playing
@ -120,8 +114,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define NQPROT //server and client are capable of using quake1/netquake protocols. (qw is still prefered. uses the command 'nqconnect') #define NQPROT //server and client are capable of using quake1/netquake protocols. (qw is still prefered. uses the command 'nqconnect')
#define FISH //sw rendering only #define FISH //sw rendering only
#define ZLIB //zip/pk3 support #define ZLIB //zip/pk3 support
#define WEBSERVER //http/ftp servers // #define WEBSERVER //http/ftp servers
#define WEBCLIENT //http/ftp clients. // #define WEBCLIENT //http/ftp clients.
#define RUNTIMELIGHTING //calculate lit/lux files the first time the map is loaded and doesn't have a loadable lit. #define RUNTIMELIGHTING //calculate lit/lux files the first time the map is loaded and doesn't have a loadable lit.
// #define QTERM //qterm... adds a console command that allows running programs from within quake - bit like xterm. // #define QTERM //qterm... adds a console command that allows running programs from within quake - bit like xterm.
#define CL_MASTER //query master servers and stuff for a dynamic server listing. #define CL_MASTER //query master servers and stuff for a dynamic server listing.
@ -156,10 +150,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#undef AVAIL_ZLIB #undef AVAIL_ZLIB
#endif #endif
#ifdef USE_MADLIB //global option. Specify on compiler command line.
#define AVAIL_MP3 //suposedly anti-gpl. don't use in a distributed binary
#endif
#ifndef _WIN32 #ifndef _WIN32
#undef QTERM #undef QTERM
#endif #endif

View file

@ -883,8 +883,9 @@ void Cmd_AliasList_f (void)
Con_Printf("\n"); Con_Printf("\n");
} }
void Alias_WriteAliases (FILE *f) void Alias_WriteAliases (vfsfile_t *f)
{ {
char *s;
cmdalias_t *cmd; cmdalias_t *cmd;
int num=0; int num=0;
for (cmd=cmd_alias ; cmd ; cmd=cmd->next) for (cmd=cmd_alias ; cmd ; cmd=cmd->next)
@ -894,12 +895,22 @@ void Alias_WriteAliases (FILE *f)
if (cmd->flags & ALIAS_FROMSERVER) if (cmd->flags & ALIAS_FROMSERVER)
continue; continue;
if (!num) if (!num)
fprintf(f, "\n//////////////////\n//Aliases\n"); {
fprintf(f, "alias %s \"%s\"\n", cmd->name, cmd->value); s = va("\n//////////////////\n//Aliases\n");
VFS_WRITE(f, s, strlen(s));
}
s = va("alias %s \"%s\"\n", cmd->name, cmd->value);
VFS_WRITE(f, s, strlen(s));
if (cmd->restriction != 1) //1 is default if (cmd->restriction != 1) //1 is default
fprintf(f, "restrict %s %i\n", cmd->name, cmd->restriction); {
s = va("restrict %s %i\n", cmd->name, cmd->restriction);
VFS_WRITE(f, s, strlen(s));
}
if (cmd->execlevel != 0) //0 is default (runs at user's level) if (cmd->execlevel != 0) //0 is default (runs at user's level)
fprintf(f, "aliaslevel %s %i\n", cmd->name, cmd->execlevel); {
s = va("aliaslevel %s %i\n", cmd->name, cmd->execlevel);
VFS_WRITE(f, s, strlen(s));
}
num++; num++;
} }
} }
@ -2686,24 +2697,13 @@ qboolean Cmd_FilterMessage (char *message, qboolean sameteam) //returns true if
*/ */
void Cmd_WriteConfig_f(void) void Cmd_WriteConfig_f(void)
{ {
FILE *f; vfsfile_t *f;
char *filename; char *filename;
filename = Cmd_Argv(1); filename = Cmd_Argv(1);
if (!*filename) if (!*filename)
filename = "fte"; filename = "fte";
if (!strncmp(filename, "../", 3))
{
filename+=3;
if (strstr(filename, ".."))
{
Con_Printf ("Couldn't write config %s\n",filename);
return;
}
filename = va("%s/fte/%s.cfg",com_basedir, filename);
}
else
{ {
if (strstr(filename, "..")) if (strstr(filename, ".."))
{ {
@ -2711,31 +2711,31 @@ void Cmd_WriteConfig_f(void)
return; return;
} }
filename = va("%s/fte/configs/%s.cfg",com_basedir, filename); filename = va("configs/%s.cfg",filename);
} }
COM_DefaultExtension(filename, ".cfg"); COM_DefaultExtension(filename, ".cfg");
COM_CreatePath(filename); FS_CreatePath(filename, FS_CONFIGONLY);
f = fopen (filename, "wb"); f = FS_OpenVFS(filename, "wb", FS_CONFIGONLY);
if (!f) if (!f)
{ {
Con_Printf ("Couldn't write config %s\n",filename); Con_Printf ("Couldn't write config %s\n",filename);
return; return;
} }
fprintf(f, "// FTE config file\n\n"); VFS_WRITE(f, "// FTE config file\n\n", 20);
#ifndef SERVERONLY #ifndef SERVERONLY
Key_WriteBindings (f); Key_WriteBindings (f);
CL_SaveInfo(f); CL_SaveInfo(f);
#else #else
fprintf(f, "// Dedicated Server config\n\n"); VFS_WRITE(f, "// Dedicated Server config\n\n", 28);
#endif #endif
#ifdef CLIENTONLY #ifdef CLIENTONLY
fprintf(f, "// no local/server infos\n\n"); VFS_WRITE(f, "// no local/server infos\n\n", 26);
#else #else
SV_SaveInfos(f); SV_SaveInfos(f);
#endif #endif
Alias_WriteAliases (f); Alias_WriteAliases (f);
Cvar_WriteVariables (f, true); Cvar_WriteVariables (f, true);
fclose(f); VFS_CLOSE(f);
FS_FlushFSHash(); FS_FlushFSHash();
} }
@ -2819,6 +2819,7 @@ void Cmd_Init (void)
Cmd_AddCommand ("cfg_save",Cmd_WriteConfig_f); Cmd_AddCommand ("cfg_save",Cmd_WriteConfig_f);
Cmd_AddCommand ("cfg_load",Cmd_Exec_f); Cmd_AddCommand ("cfg_load",Cmd_Exec_f);
//Cmd_AddCommand ("cfg_reset",Cmd_Reset_f);
Cmd_AddCommand ("exec",Cmd_Exec_f); Cmd_AddCommand ("exec",Cmd_Exec_f);
Cmd_AddCommand ("echo",Cmd_Echo_f); Cmd_AddCommand ("echo",Cmd_Echo_f);

View file

@ -2131,11 +2131,11 @@ being registered.
*/ */
void COM_CheckRegistered (void) void COM_CheckRegistered (void)
{ {
FILE *h; vfsfile_t *h;
unsigned short check[128]; unsigned short check[128];
int i; int i;
COM_FOpenFile("gfx/pop.lmp", &h); h = FS_OpenVFS("gfx/pop.lmp", "r", FS_GAME);
static_registered = false; static_registered = false;
if (!h) if (!h)
@ -2149,8 +2149,8 @@ void COM_CheckRegistered (void)
return; return;
} }
fread (check, 1, sizeof(check), h); VFS_READ(h, check, sizeof(check));
fclose (h); VFS_CLOSE(h);
for (i=0 ; i<128 ; i++) for (i=0 ; i<128 ; i++)
if (pop[i] != (unsigned short)BigShort (check[i])) if (pop[i] != (unsigned short)BigShort (check[i]))
@ -2743,7 +2743,7 @@ void Info_Print (char *s)
} }
} }
void Info_WriteToFile(FILE *f, char *info, char *commandname, int cvarflags) void Info_WriteToFile(vfsfile_t *f, char *info, char *commandname, int cvarflags)
{ {
char *command; char *command;
char *value; char *value;
@ -2764,12 +2764,12 @@ void Info_WriteToFile(FILE *f, char *info, char *commandname, int cvarflags)
if (var && var->flags & cvarflags) if (var && var->flags & cvarflags)
continue; //this is saved via a cvar. continue; //this is saved via a cvar.
fwrite(commandname, strlen(commandname), 1, f); VFS_WRITE(f, commandname, strlen(commandname));
fwrite(" ", 1, 1, f); VFS_WRITE(f, " ", 1);
fwrite(command, value-command, 1, f); VFS_WRITE(f, command, value-command);
fwrite(" ", 1, 1, f); VFS_WRITE(f, " ", 1);
fwrite(value+1, info-(value+1), 1, f); VFS_WRITE(f, value+1, info-(value+1));
fwrite("\n", 1, 1, f); VFS_WRITE(f, "\n", 1);
} }
} }

View file

@ -266,7 +266,10 @@ extern int com_filesize;
struct cache_user_s; struct cache_user_s;
extern char com_gamedir[MAX_OSPATH]; extern char com_gamedir[MAX_OSPATH];
extern char *com_basedir; extern char com_quakedir[MAX_OSPATH];
extern char com_homedir[MAX_OSPATH];
extern char com_configdir[MAX_OSPATH]; //dir to put cfg_save configs in
//extern char *com_basedir;
void COM_WriteFile (char *filename, void *data, int len); void COM_WriteFile (char *filename, void *data, int len);
FILE *COM_WriteFileOpen (char *filename); FILE *COM_WriteFileOpen (char *filename);
@ -279,7 +282,7 @@ typedef struct {
int len; int len;
} flocation_t; } flocation_t;
typedef enum {FSLFRT_LENGTH, FSLFRT_DEPTH_OSONLY, FSLFRT_DEPTH_ANYPATH} FSLF_ReturnType_e; typedef enum {FSLFRT_IFFOUND, FSLFRT_LENGTH, FSLFRT_DEPTH_OSONLY, FSLFRT_DEPTH_ANYPATH} FSLF_ReturnType_e;
//if loc is valid, loc->search is always filled in, the others are filled on success. //if loc is valid, loc->search is always filled in, the others are filled on success.
//returns -1 if couldn't find. //returns -1 if couldn't find.
int FS_FLocateFile(char *filename, FSLF_ReturnType_e returntype, flocation_t *loc); int FS_FLocateFile(char *filename, FSLF_ReturnType_e returntype, flocation_t *loc);
@ -296,6 +299,36 @@ void COM_CloseFile (FILE *h);
#define COM_FDepthFile(filename,ignorepacks) FS_FLocateFile(filename,ignorepacks?FSLFRT_DEPTH_OSONLY:FSLFRT_DEPTH_ANYPATH, NULL) #define COM_FDepthFile(filename,ignorepacks) FS_FLocateFile(filename,ignorepacks?FSLFRT_DEPTH_OSONLY:FSLFRT_DEPTH_ANYPATH, NULL)
#define COM_FCheckExists(filename) (FS_FLocateFile(filename,FSLFRT_LENGTH, NULL)>0) #define COM_FCheckExists(filename) (FS_FLocateFile(filename,FSLFRT_LENGTH, NULL)>0)
typedef struct vfsfile_s {
int (*ReadBytes) (struct vfsfile_s *file, void *buffer, int bytestoread);
int (*WriteBytes) (struct vfsfile_s *file, void *buffer, int bytestoread);
qboolean (*Seek) (struct vfsfile_s *file, unsigned long pos); //returns false for error
unsigned long (*Tell) (struct vfsfile_s *file);
unsigned long (*GetLen) (struct vfsfile_s *file); //could give some lag
void (*Close) (struct vfsfile_s *file);
} vfsfile_t;
#define VFS_CLOSE(vf) (vf->Close(vf))
#define VFS_TELL(vf) (vf->Tell(vf))
#define VFS_GETLEN(vf) (vf->GetLen(vf))
#define VFS_SEEK(vf,pos) (vf->Seek(vf,pos))
#define VFS_READ(vf,buffer,buflen) (vf->ReadBytes(vf,buffer,buflen))
#define VFS_WRITE(vf,buffer,buflen) (vf->WriteBytes(vf,buffer,buflen))
#define VFS_FLUSH(vf)
#define VFS_GETS(vf,buffer,buflen) Sys_Error("VFS_GETS not implemented"),false //:(
void FS_Remove(char *fname, int relativeto);
vfsfile_t *FS_OpenVFS(char *filename, char *mode, int relativeto);
enum {
FS_GAME,
FS_BASE,
FS_GAMEONLY,
FS_CONFIGONLY,
FS_SKINS
};
int COM_filelength (FILE *f); int COM_filelength (FILE *f);
qbyte *COM_LoadStackFile (char *path, void *buffer, int bufsize); qbyte *COM_LoadStackFile (char *path, void *buffer, int bufsize);
qbyte *COM_LoadTempFile (char *path); qbyte *COM_LoadTempFile (char *path);
@ -328,7 +361,7 @@ void Info_RemoveNonStarKeys (char *start);
void Info_SetValueForKey (char *s, const char *key, const char *value, int maxsize); void Info_SetValueForKey (char *s, const char *key, const char *value, int maxsize);
void Info_SetValueForStarKey (char *s, const char *key, const char *value, int maxsize); void Info_SetValueForStarKey (char *s, const char *key, const char *value, int maxsize);
void Info_Print (char *s); void Info_Print (char *s);
void Info_WriteToFile(FILE *f, char *info, char *commandname, int cvarflags); void Info_WriteToFile(vfsfile_t *f, char *info, char *commandname, int cvarflags);
unsigned int Com_BlockChecksum (void *buffer, int length); unsigned int Com_BlockChecksum (void *buffer, int length);
void Com_BlockFullChecksum (void *buffer, int len, unsigned char *outbuf); void Com_BlockFullChecksum (void *buffer, int len, unsigned char *outbuf);

View file

@ -840,7 +840,7 @@ Cvar_RegisterVariable
Adds a freestanding variable to the variable list. Adds a freestanding variable to the variable list.
============ ============
*/ */
void Cvar_Register (cvar_t *variable, const char *groupname) qboolean Cvar_Register (cvar_t *variable, const char *groupname)
{ {
cvar_t *old; cvar_t *old;
cvar_group_t *group; cvar_group_t *group;
@ -878,18 +878,18 @@ void Cvar_Register (cvar_t *variable, const char *groupname)
Cvar_SetCore (variable, old->string, true); Cvar_SetCore (variable, old->string, true);
Cvar_Free(old); Cvar_Free(old);
return; return false;
} }
Con_Printf ("Can't register variable %s, already defined\n", variable->name); Con_Printf ("Can't register variable %s, already defined\n", variable->name);
return; return false;
} }
// check for overlap with a command // check for overlap with a command
if (Cmd_Exists (variable->name)) if (Cmd_Exists (variable->name))
{ {
Con_Printf ("Cvar_RegisterVariable: %s is a command\n", variable->name); Con_Printf ("Cvar_RegisterVariable: %s is a command\n", variable->name);
return; return false;
} }
group = Cvar_GetGroup(groupname); group = Cvar_GetGroup(groupname);
@ -905,6 +905,8 @@ void Cvar_Register (cvar_t *variable, const char *groupname)
// set it through the function to be consistant // set it through the function to be consistant
Cvar_SetCore (variable, value, true); Cvar_SetCore (variable, value, true);
return true;
} }
/* /*
void Cvar_RegisterVariable (cvar_t *variable) void Cvar_RegisterVariable (cvar_t *variable)
@ -931,7 +933,8 @@ cvar_t *Cvar_Get(const char *name, const char *defaultvalue, int flags, const ch
var->string = (char*)defaultvalue; var->string = (char*)defaultvalue;
var->flags = flags|CVAR_POINTER|CVAR_USERCREATED; var->flags = flags|CVAR_POINTER|CVAR_USERCREATED;
Cvar_Register(var, group); if (!Cvar_Register(var, group))
return NULL;
return var; return var;
} }
@ -1054,12 +1057,13 @@ Writes lines containing "set variable value" for all variables
with the archive flag set to true. with the archive flag set to true.
============ ============
*/ */
void Cvar_WriteVariables (FILE *f, qboolean all) void Cvar_WriteVariables (vfsfile_t *f, qboolean all)
{ {
qboolean writtengroupheader; qboolean writtengroupheader;
cvar_group_t *grp; cvar_group_t *grp;
cvar_t *var; cvar_t *var;
char *val; char *val;
char *s;
for (grp=cvar_groups ; grp ; grp=grp->next) for (grp=cvar_groups ; grp ; grp=grp->next)
{ {
@ -1070,7 +1074,8 @@ void Cvar_WriteVariables (FILE *f, qboolean all)
if (!writtengroupheader) if (!writtengroupheader)
{ {
writtengroupheader = true; writtengroupheader = true;
fprintf(f, "\n// %s\n", grp->name); s = va("\n// %s\n", grp->name);
VFS_WRITE(f, s, strlen(s));
} }
val = var->string; //latched vars should act differently. val = var->string; //latched vars should act differently.
@ -1080,12 +1085,13 @@ void Cvar_WriteVariables (FILE *f, qboolean all)
if (var->flags & CVAR_USERCREATED) if (var->flags & CVAR_USERCREATED)
{ {
if (var->flags & CVAR_ARCHIVE) if (var->flags & CVAR_ARCHIVE)
fprintf (f, "seta %s \"%s\"\n", var->name, val); s = va("seta %s \"%s\"\n", var->name, val);
else else
fprintf (f, "set %s \"%s\"\n", var->name, val); s = va("set %s \"%s\"\n", var->name, val);
} }
else else
fprintf (f, "%s \"%s\"\n", var->name, val); s = va("%s \"%s\"\n", var->name, val);
VFS_WRITE(f, s, strlen(s));
} }
} }
} }

View file

@ -104,7 +104,7 @@ cvar_t *Cvar_Get (const char *var_name, const char *value, int flags, const char
void Cvar_LockFromServer(cvar_t *var, const char *str); void Cvar_LockFromServer(cvar_t *var, const char *str);
void Cvar_Register (cvar_t *variable, const char *cvargroup); qboolean Cvar_Register (cvar_t *variable, const char *cvargroup);
// registers a cvar that already has the name, string, and optionally the // registers a cvar that already has the name, string, and optionally the
// archive elements set. // archive elements set.
@ -135,7 +135,7 @@ qboolean Cvar_Command (int level);
// command. Returns true if the command was a variable reference that // command. Returns true if the command was a variable reference that
// was handled. (print or change) // was handled. (print or change)
void Cvar_WriteVariables (FILE *f, qboolean all); void Cvar_WriteVariables (vfsfile_t *f, qboolean all);
// Writes lines containing "set variable value" for all variables // Writes lines containing "set variable value" for all variables
// with the archive flag set to true. // with the archive flag set to true.

File diff suppressed because it is too large Load diff

View file

@ -16,7 +16,6 @@ cvar_t log_dosformat = {"log_dosformat", "0", NULL, CVAR_NOTFROMSERVER};
// externals // externals
int COM_FileSize(char *path); int COM_FileSize(char *path);
extern char gamedirfile[]; extern char gamedirfile[];
extern char *com_basedir;
// table of readable characters, same as ezquake // table of readable characters, same as ezquake
char readable[256] = char readable[256] =
@ -150,19 +149,19 @@ void Con_Log (char *s)
*t = 0; *t = 0;
f = va("%s/%s/%s.log",com_basedir,d,f); // temp string in va() f = va("%s/%s.log",d,f); // temp string in va()
// file rotation // file rotation
if (log_rotate_size.value >= 4096 && log_rotate_files.value >= 1) if (log_rotate_size.value >= 4096 && log_rotate_files.value >= 1)
{ {
int x; int x;
FILE *fi; vfsfile_t *fi;
// check file size, use x as temp // check file size, use x as temp
if ((fi = fopen(f, "rb"))) if ((fi = FS_OpenVFS(f, "rb", FS_BASE)))
{ {
x = COM_filelength(fi); x = VFS_GETLEN(fi);
fclose(fi); VFS_CLOSE(fi);
} }
else else
x = 0; x = 0;
@ -176,7 +175,7 @@ void Con_Log (char *s)
// unlink file at the top of the chain // unlink file at the top of the chain
_snprintf(oldf, sizeof(oldf)-1, "%s.%i", f, i); _snprintf(oldf, sizeof(oldf)-1, "%s.%i", f, i);
unlink(oldf); FS_Remove(oldf, FS_BASE);
// rename files through chain // rename files through chain
for (x = i-1; x > 0; x--) for (x = i-1; x > 0; x--)
@ -185,12 +184,12 @@ void Con_Log (char *s)
_snprintf(oldf, sizeof(oldf)-1, "%s.%i", f, x); _snprintf(oldf, sizeof(oldf)-1, "%s.%i", f, x);
// check if file exists, otherwise skip // check if file exists, otherwise skip
if ((fi = fopen(oldf, "rb"))) if ((fi = FS_OpenVFS(f, "rb", FS_BASE)))
fclose(fi); VFS_CLOSE(fi);
else else
continue; // skip nonexistant files continue; // skip nonexistant files
if (rename(oldf, newf)) if (FS_Rename(oldf, newf, FS_BASE))
{ {
// rename failed, disable log and bug out // rename failed, disable log and bug out
Cvar_ForceSet(&log_enable, "0"); Cvar_ForceSet(&log_enable, "0");

View file

@ -104,11 +104,10 @@ cvar_t plug_loaddefault = {"plug_loaddefault", "1"};
//custom plugin builtins. //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 long *arg);
void Plug_RegisterBuiltin(char *name, Plug_Builtin_t bi, int flags);
#define PLUG_BIF_DLLONLY 1 #define PLUG_BIF_DLLONLY 1
#define PLUG_BIF_QVMONLY 2 #define PLUG_BIF_QVMONLY 2
void Plug_RegisterBuiltin(char *name, Plug_Builtin_t bi, int flags);
#include "netinc.h" #include "netinc.h"
typedef struct plugin_s { typedef struct plugin_s {

View file

@ -54,7 +54,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define PEXT_SHOWPIC 0x04000000 #define PEXT_SHOWPIC 0x04000000
#define PEXT_SETATTACHMENT 0x08000000 //md3 tags (needs networking, they need to lerp). #define PEXT_SETATTACHMENT 0x08000000 //md3 tags (needs networking, they need to lerp).
//#define PEXT_PK3DOWNLOADS 0x10000000 //retrieve a list of pk3s/pk3s/paks for downloading (with optional URL and crcs) //#define PEXT_PK3DOWNLOADS 0x10000000 //retrieve a list of pk3s/pk3s/paks for downloading (with optional URL and crcs)
//There's still a bug I need to resolve #define PEXT_CHUNKEDDOWNLOADS 0x20000000 //alternate file download method. Hopefully it'll give quadroupled download speed, especially on higher pings. #define PEXT_CHUNKEDDOWNLOADS 0x20000000 //alternate file download method. Hopefully it'll give quadroupled download speed, especially on higher pings.
#ifdef CSQC_DAT #ifdef CSQC_DAT
#define PEXT_CSQC 0x40000000 //csqc additions #define PEXT_CSQC 0x40000000 //csqc additions

View file

@ -94,7 +94,7 @@ typedef struct {
unsigned long crc32_wait; /* crc32 we must obtain after decompress all */ unsigned long crc32_wait; /* crc32 we must obtain after decompress all */
unsigned long rest_read_compressed; /* number of byte to be decompressed */ unsigned long rest_read_compressed; /* number of byte to be decompressed */
unsigned long rest_read_uncompressed;/*number of byte to be obtained after decomp*/ unsigned long rest_read_uncompressed;/*number of byte to be obtained after decomp*/
FILE* file; /* io structore of the zipfile */ vfsfile_t* file; /* io structore of the zipfile */
unsigned long compression_method; /* compression method (0==store) */ unsigned long compression_method; /* compression method (0==store) */
unsigned long byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ unsigned long byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
} file_in_zip_read_info_s; } file_in_zip_read_info_s;
@ -103,7 +103,7 @@ typedef struct {
/* unz_s contain internal information about the zipfile /* unz_s contain internal information about the zipfile
*/ */
typedef struct { typedef struct {
FILE* file; /* io structore of the zipfile */ vfsfile_t* file; /* io structore of the zipfile */
unz_global_info gi; /* public global information */ unz_global_info gi; /* public global information */
unsigned long byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ unsigned long byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
unsigned long num_file; /* number of the current file in the zipfile*/ unsigned long num_file; /* number of the current file in the zipfile*/
@ -129,26 +129,26 @@ typedef struct {
*/ */
local int unzlocal_getShort(FILE *fin,unsigned long *pi) { local int unzlocal_getShort(vfsfile_t *fin,unsigned long *pi) {
unsigned short c; unsigned short c;
int err = fread(&c, 2, 1, fin); int err = VFS_READ(fin, &c, 2);
if (err==1) { if (err==2) {
*pi = LittleShort(c); *pi = LittleShort(c);
return UNZ_OK; return UNZ_OK;
} else { } else {
if (ferror(fin)) return UNZ_ERRNO; if (VFS_TELL(fin) != VFS_GETLEN(fin)) return UNZ_ERRNO;
else return UNZ_EOF; else return UNZ_EOF;
} }
} }
local int unzlocal_getLong(FILE *fin,unsigned long *pi) { local int unzlocal_getLong(vfsfile_t *fin,unsigned long *pi) {
unsigned long c; unsigned long c;
int err = fread(&c, 4, 1, fin); int err = VFS_READ(fin, &c, 4);
if (err==1) { if (err==4) {
*pi = LittleLong(c); *pi = LittleLong(c);
return UNZ_OK; return UNZ_OK;
} else { } else {
if (ferror(fin)) return UNZ_ERRNO; if (VFS_TELL(fin) != VFS_GETLEN(fin)) return UNZ_ERRNO;
else return UNZ_EOF; else return UNZ_EOF;
} }
} }
@ -160,16 +160,14 @@ local int unzlocal_getLong(FILE *fin,unsigned long *pi) {
Locate the Central directory of a zipfile (at the end, just before Locate the Central directory of a zipfile (at the end, just before
the global comment) the global comment)
*/ */
local unsigned long unzlocal_SearchCentralDir(FILE *fin) { local unsigned long unzlocal_SearchCentralDir(vfsfile_t *fin) {
unsigned char* buf; unsigned char* buf;
unsigned long uSizeFile; unsigned long uSizeFile;
unsigned long uBackRead; unsigned long uBackRead;
unsigned long uMaxBack=0xffff; /* maximum size of global comment */ unsigned long uMaxBack=0xffff; /* maximum size of global comment */
unsigned long uPosFound=0; unsigned long uPosFound=0;
if (fseek(fin,0,SEEK_END) != 0) return 0; uSizeFile = VFS_GETLEN(fin);
uSizeFile = ftell( fin );
if (uMaxBack>uSizeFile) uMaxBack = uSizeFile; if (uMaxBack>uSizeFile) uMaxBack = uSizeFile;
@ -186,9 +184,11 @@ local unsigned long unzlocal_SearchCentralDir(FILE *fin) {
uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
(BUFREADCOMMENT+4) : (uSizeFile-uReadPos); (BUFREADCOMMENT+4) : (uSizeFile-uReadPos);
if (fseek(fin,uReadPos,SEEK_SET)!=0) break;
if (fread(buf,(unsigned int)uReadSize,1,fin)!=1) break; if (!VFS_SEEK(fin, uReadPos))
break;
if (VFS_READ(fin,buf,(unsigned int)uReadSize)!=uReadSize) break;
for (i=(int)uReadSize-3; (i--)>0;) for (i=(int)uReadSize-3; (i--)>0;)
if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
@ -212,11 +212,10 @@ local unsigned long unzlocal_SearchCentralDir(FILE *fin) {
Else, the return value is a unzFile Handle, usable with other function Else, the return value is a unzFile Handle, usable with other function
of this unzip package. of this unzip package.
*/ */
extern unzFile ZEXPORT unzOpen (const char *path) { extern unzFile ZEXPORT unzOpen (vfsfile_t *fin) {
unz_s us; unz_s us;
unz_s *s; unz_s *s;
unsigned long central_pos,uL; unsigned long central_pos,uL;
FILE * fin ;
unsigned long number_disk; /* number of the current dist, used for unsigned long number_disk; /* number of the current dist, used for
spaning ZIP, unsupported, always 0*/ spaning ZIP, unsupported, always 0*/
@ -228,13 +227,13 @@ extern unzFile ZEXPORT unzOpen (const char *path) {
int err=UNZ_OK; int err=UNZ_OK;
fin=fopen(path,"rb");
if (!fin) return NULL; if (!fin) return NULL;
central_pos = unzlocal_SearchCentralDir(fin); central_pos = unzlocal_SearchCentralDir(fin);
if (!central_pos) err=UNZ_ERRNO; if (!central_pos) err=UNZ_ERRNO;
if (fseek(fin,central_pos,SEEK_SET)!=0) err=UNZ_ERRNO; if (!VFS_SEEK(fin,central_pos)) err=UNZ_ERRNO;
/* the signature, already checked */ /* the signature, already checked */
if (unzlocal_getLong(fin,&uL)!=UNZ_OK) err=UNZ_ERRNO; if (unzlocal_getLong(fin,&uL)!=UNZ_OK) err=UNZ_ERRNO;
@ -266,7 +265,7 @@ extern unzFile ZEXPORT unzOpen (const char *path) {
if ((central_pos<us.offset_central_dir+us.size_central_dir) && (err==UNZ_OK)) err=UNZ_BADZIPFILE; if ((central_pos<us.offset_central_dir+us.size_central_dir) && (err==UNZ_OK)) err=UNZ_BADZIPFILE;
if (err!=UNZ_OK) { if (err!=UNZ_OK) {
fclose(fin); VFS_CLOSE(fin);
return NULL; return NULL;
} }
@ -295,7 +294,7 @@ extern int ZEXPORT unzClose (unzFile file) {
if (s->pfile_in_zip_read) unzCloseCurrentFile(file); if (s->pfile_in_zip_read) unzCloseCurrentFile(file);
fclose(s->file); VFS_CLOSE(s->file);
TRYFREE(s); TRYFREE(s);
return UNZ_OK; return UNZ_OK;
} }
@ -343,7 +342,7 @@ local int unzlocal_GetCurrentFileInfoInternal (unzFile file,
if (!file) return UNZ_PARAMERROR; if (!file) return UNZ_PARAMERROR;
s=(unz_s*)file; s=(unz_s*)file;
if (fseek(s->file,s->pos_in_central_dir+s->byte_before_the_zipfile,SEEK_SET)!=0) err=UNZ_ERRNO; if (!VFS_SEEK(s->file,s->pos_in_central_dir+s->byte_before_the_zipfile)) err=UNZ_ERRNO;
/* we check the magic */ /* we check the magic */
@ -353,7 +352,7 @@ local int unzlocal_GetCurrentFileInfoInternal (unzFile file,
else if (uMagic!=0x02014b50) err=UNZ_BADZIPFILE; else if (uMagic!=0x02014b50) err=UNZ_BADZIPFILE;
} }
fread(&file_info, sizeof(file_info)-2*4, 1, s->file); // 2*4 is the size of 2 my vars VFS_READ(s->file, &file_info, sizeof(file_info)-2*4); // 2*4 is the size of 2 my vars
file_info.version = LittleShort(file_info.version); file_info.version = LittleShort(file_info.version);
file_info.version_needed = LittleShort(file_info.version_needed); file_info.version_needed = LittleShort(file_info.version_needed);
file_info.flag = LittleShort(file_info.flag); file_info.flag = LittleShort(file_info.flag);
@ -386,7 +385,7 @@ local int unzlocal_GetCurrentFileInfoInternal (unzFile file,
else uSizeRead = fileNameBufferSize; else uSizeRead = fileNameBufferSize;
if ((file_info.size_filename>0) && (fileNameBufferSize>0)) if ((file_info.size_filename>0) && (fileNameBufferSize>0))
if (fread(szFileName,(unsigned int)uSizeRead,1,s->file)!=1) err=UNZ_ERRNO; if (VFS_READ(s->file, szFileName,(unsigned int)uSizeRead)!=uSizeRead) err=UNZ_ERRNO;
lSeek -= uSizeRead; lSeek -= uSizeRead;
} }
@ -399,11 +398,11 @@ local int unzlocal_GetCurrentFileInfoInternal (unzFile file,
if (lSeek!=0) if (lSeek!=0)
{ {
if (fseek(s->file,lSeek,SEEK_CUR)==0) lSeek=0; if (VFS_SEEK(s->file, VFS_TELL(s->file)+lSeek)) lSeek=0;
else err=UNZ_ERRNO; else err=UNZ_ERRNO;
} }
if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
if (fread(extraField,(unsigned int)uSizeRead,1,s->file)!=1) err=UNZ_ERRNO; if (VFS_READ(s->file, extraField,(unsigned int)uSizeRead)!=uSizeRead) err=UNZ_ERRNO;
lSeek += file_info.size_file_extra - uSizeRead; lSeek += file_info.size_file_extra - uSizeRead;
} }
else lSeek+=file_info.size_file_extra; else lSeek+=file_info.size_file_extra;
@ -419,11 +418,11 @@ local int unzlocal_GetCurrentFileInfoInternal (unzFile file,
if (lSeek!=0) if (lSeek!=0)
{ {
if (fseek(s->file,lSeek,SEEK_CUR)==0) lSeek=0; if (VFS_SEEK(s->file, VFS_TELL(s->file)+lSeek)) lSeek=0;
else err=UNZ_ERRNO; else err=UNZ_ERRNO;
} }
if ((file_info.size_file_comment>0) && (commentBufferSize>0)) if ((file_info.size_file_comment>0) && (commentBufferSize>0))
if (fread(szComment,(unsigned int)uSizeRead,1,s->file)!=1) err=UNZ_ERRNO; if (VFS_READ(s->file, szComment,(unsigned int)uSizeRead)!=uSizeRead) err=UNZ_ERRNO;
lSeek+=file_info.size_file_comment - uSizeRead; lSeek+=file_info.size_file_comment - uSizeRead;
} else lSeek+=file_info.size_file_comment; } else lSeek+=file_info.size_file_comment;
@ -525,7 +524,7 @@ local int unzlocal_CheckCurrentFileCoherencyHeader (unz_s *s, unsigned int *piSi
*poffset_local_extrafield = 0; *poffset_local_extrafield = 0;
*psize_local_extrafield = 0; *psize_local_extrafield = 0;
if (fseek(s->file,s->cur_file_info_internal.offset_curfile + s->byte_before_the_zipfile,SEEK_SET)!=0) return UNZ_ERRNO; if (!VFS_SEEK(s->file,s->cur_file_info_internal.offset_curfile + s->byte_before_the_zipfile)) return UNZ_ERRNO;
if (err==UNZ_OK) if (err==UNZ_OK)
@ -755,10 +754,10 @@ extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len) {
unsigned int uReadThis = UNZ_BUFSIZE; unsigned int uReadThis = UNZ_BUFSIZE;
if (pfile_in_zip_read_info->rest_read_compressed<uReadThis) uReadThis = (unsigned int)pfile_in_zip_read_info->rest_read_compressed; if (pfile_in_zip_read_info->rest_read_compressed<uReadThis) uReadThis = (unsigned int)pfile_in_zip_read_info->rest_read_compressed;
if (!uReadThis) return UNZ_EOF; if (!uReadThis) return UNZ_EOF;
if (fseek(pfile_in_zip_read_info->file, if (!VFS_SEEK(pfile_in_zip_read_info->file,
pfile_in_zip_read_info->pos_in_zipfile + pfile_in_zip_read_info->pos_in_zipfile +
pfile_in_zip_read_info->byte_before_the_zipfile,SEEK_SET)!=0) return UNZ_ERRNO; pfile_in_zip_read_info->byte_before_the_zipfile)) return UNZ_ERRNO;
if (fread(pfile_in_zip_read_info->read_buffer,uReadThis,1,pfile_in_zip_read_info->file)!=1) return UNZ_ERRNO; if (VFS_READ(pfile_in_zip_read_info->file, pfile_in_zip_read_info->read_buffer,uReadThis)!=uReadThis) return UNZ_ERRNO;
pfile_in_zip_read_info->pos_in_zipfile += uReadThis; pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
pfile_in_zip_read_info->rest_read_compressed-=uReadThis; pfile_in_zip_read_info->rest_read_compressed-=uReadThis;
@ -881,11 +880,11 @@ extern int ZEXPORT unzGetLocalExtrafield (unzFile file,voidp buf,unsigned len) {
if (!read_now) return 0; if (!read_now) return 0;
if (fseek(pfile_in_zip_read_info->file, if (!VFS_SEEK(pfile_in_zip_read_info->file,
pfile_in_zip_read_info->offset_local_extrafield + pfile_in_zip_read_info->offset_local_extrafield +
pfile_in_zip_read_info->pos_local_extrafield,SEEK_SET)!=0) return UNZ_ERRNO; pfile_in_zip_read_info->pos_local_extrafield)) return UNZ_ERRNO;
if (fread(buf,(unsigned int)size_to_read,1,pfile_in_zip_read_info->file)!=1) return UNZ_ERRNO; if (VFS_READ(pfile_in_zip_read_info->file, buf,(unsigned int)size_to_read)!=size_to_read) return UNZ_ERRNO;
return (int)read_now; return (int)read_now;
} }
@ -939,11 +938,11 @@ extern int ZEXPORT unzGetGlobalComment (unzFile file, char *szComment, unsigned
uReadThis = uSizeBuf; uReadThis = uSizeBuf;
if (uReadThis>s->gi.size_comment) uReadThis = s->gi.size_comment; if (uReadThis>s->gi.size_comment) uReadThis = s->gi.size_comment;
if (fseek(s->file,s->central_pos+22,SEEK_SET)!=0) return UNZ_ERRNO; if (!VFS_SEEK(s->file,s->central_pos+22)) return UNZ_ERRNO;
if (uReadThis>0) { if (uReadThis>0) {
*szComment='\0'; *szComment='\0';
if (fread(szComment,(unsigned int)uReadThis,1,s->file)!=1) return UNZ_ERRNO; if (VFS_READ(s->file, szComment,(unsigned int)uReadThis)!=uReadThis) return UNZ_ERRNO;
} }
if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment)) *(szComment+s->gi.size_comment)='\0'; if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment)) *(szComment+s->gi.size_comment)='\0';

View file

@ -126,7 +126,7 @@ extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
*/ */
extern unzFile ZEXPORT unzOpen OF((const char *path)); extern unzFile ZEXPORT unzOpen OF((vfsfile_t *fin));
/* /*
Open a Zip file. path contain the full pathname (by example, Open a Zip file. path contain the full pathname (by example,
on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer

View file

@ -2516,47 +2516,6 @@ SOURCE=..\client\snd_mix.c
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=..\client\snd_mp3.c
!IF "$(CFG)" == "ftequake - Win32 Release"
!ELSEIF "$(CFG)" == "ftequake - Win32 Debug"
!ELSEIF "$(CFG)" == "ftequake - Win32 GLDebug"
!ELSEIF "$(CFG)" == "ftequake - Win32 GLRelease"
!ELSEIF "$(CFG)" == "ftequake - Win32 MDebug"
!ELSEIF "$(CFG)" == "ftequake - Win32 MRelease"
!ELSEIF "$(CFG)" == "ftequake - Win32 MinGLDebug"
!ELSEIF "$(CFG)" == "ftequake - Win32 MinGLRelease"
!ELSEIF "$(CFG)" == "ftequake - Win32 Debug Dedicated Server"
# PROP Exclude_From_Build 1
!ELSEIF "$(CFG)" == "ftequake - Win32 Release Dedicated Server"
# PROP BASE Exclude_From_Build 1
# PROP Exclude_From_Build 1
!ELSEIF "$(CFG)" == "ftequake - Win32 MinSW"
!ELSEIF "$(CFG)" == "ftequake - Win32 GLDebugQ3"
!ELSEIF "$(CFG)" == "ftequake - Win32 Debug Dedicated ServerQ3"
# PROP BASE Exclude_From_Build 1
# PROP Exclude_From_Build 1
!ENDIF
# End Source File
# Begin Source File
SOURCE=..\client\snd_ov.c SOURCE=..\client\snd_ov.c
!IF "$(CFG)" == "ftequake - Win32 Release" !IF "$(CFG)" == "ftequake - Win32 Release"
@ -5629,6 +5588,10 @@ SOURCE=..\sw\vid_win2.c
# PROP Default_Filter "" # PROP Default_Filter ""
# Begin Source File # Begin Source File
SOURCE=..\client\cl_plugin.inc
# End Source File
# Begin Source File
SOURCE=..\common\cmd.c SOURCE=..\common\cmd.c
# End Source File # End Source File
# Begin Source File # Begin Source File

View file

@ -156,7 +156,6 @@ inline void PPL_EnableVertexArrays(void)
qglDisableClientState(GL_COLOR_ARRAY); qglDisableClientState(GL_COLOR_ARRAY);
qglEnableClientState(GL_VERTEX_ARRAY); qglEnableClientState(GL_VERTEX_ARRAY);
qglVertexPointer(3, GL_FLOAT, sizeof(surfvertexarray_t), varray_v->xyz); qglVertexPointer(3, GL_FLOAT, sizeof(surfvertexarray_t), varray_v->xyz);
qglDisableClientState( GL_COLOR_ARRAY );
} }
inline void PPL_FlushArrays(void) inline void PPL_FlushArrays(void)
{ {

View file

@ -143,10 +143,10 @@ qboolean GLX_InitLibrary(char *driver)
gllibrary = dlopen(driver, RTLD_LAZY); gllibrary = dlopen(driver, RTLD_LAZY);
else else
gllibrary = NULL; gllibrary = NULL;
if (!gllibrary)
gllibrary = dlopen("libGL.so", RTLD_LAZY);
if (!gllibrary) //I hate this. if (!gllibrary) //I hate this.
gllibrary = dlopen("libGL.so.1", RTLD_LAZY); gllibrary = dlopen("libGL.so.1", RTLD_LAZY);
if (!gllibrary)
gllibrary = dlopen("libGL.so", RTLD_LAZY);
if (!gllibrary) if (!gllibrary)
return false; return false;

View file

@ -24,7 +24,7 @@ typedef struct FTPclientconn_s{
enum {ftp_control, ftp_listing, ftp_getting, ftp_putting} type; enum {ftp_control, ftp_listing, ftp_getting, ftp_putting} type;
int stage; int stage;
IWEBFILE *f; vfsfile_t *f;
struct FTPclientconn_s *next; struct FTPclientconn_s *next;
@ -402,7 +402,7 @@ iwboolean FTP_ClientConnThink (FTPclientconn_t *con) //true to kill con
sprintf(tempbuff, "STOR %s\r\n", con->file); sprintf(tempbuff, "STOR %s\r\n", con->file);
con->stage = 6; con->stage = 6;
con->transfered = 0; con->transfered = 0;
con->transfersize = con->f->length; con->transfersize = VFS_GETLEN(con->f);
} }
else else
{ {

View file

@ -73,7 +73,7 @@ void HTTP_ServerShutdown(void)
typedef struct HTTP_active_connections_s { typedef struct HTTP_active_connections_s {
int datasock; int datasock;
IWEBFILE *file; vfsfile_t *file;
struct HTTP_active_connections_s *next; struct HTTP_active_connections_s *next;
http_mode_t mode; http_mode_t mode;

View file

@ -94,25 +94,6 @@ typedef struct {
int len; int len;
} IWeb_FileGen_t; } IWeb_FileGen_t;
typedef struct {
//one or the other
FILE *f;
int pos;
IWeb_FileGen_t *bufferdata;
int start;
int length;
int end;
} IWEBFILE;
IWEBFILE *IWebFOpenRead(char *name); //fread(name, "rb");
IWEBFILE *IWebFOpenWrite(char *name, int append); //fopen(name, append?"ab":"wb");
int IWebFWrite(void *data, int s1, int s2, IWEBFILE *); //fwrite
int IWebFRead(void *data, int s1, int s2, IWEBFILE *); //fwrite
void IWebFClose(IWEBFILE *);
void IWebFSeek(IWEBFILE *file, long pos, int type);
int IWebFTell(IWEBFILE *file);
#ifndef WEBSVONLY #ifndef WEBSVONLY
void *IWebMalloc(int size); void *IWebMalloc(int size);
void *IWebRealloc(void *old, int size); void *IWebRealloc(void *old, int size);
@ -123,7 +104,7 @@ void IWebFree(void *mem);
int IWebAuthorize(char *name, char *password); int IWebAuthorize(char *name, char *password);
iwboolean IWebAllowUpLoad(char *fname, char *uname); iwboolean IWebAllowUpLoad(char *fname, char *uname);
IWEBFILE *IWebGenerateFile(char *name, char *content, int contentlength); vfsfile_t *IWebGenerateFile(char *name, char *content, int contentlength);

View file

@ -375,152 +375,7 @@ void IWebRun(void)
void IWebShutdown(void) void IWebShutdown(void)
{ {
} }
IWEBFILE *IWebFOpenRead(char *name) //fread(name, "rb");
{
IWEBFILE *gf;
FILE *f;
if (*name == '/')
name++;
if (strstr(name, ".."))
return NULL;
if ((com_filesize=COM_FOpenFile(name, &f)) >= 0)
{
IWEBFILE *ret = IWebMalloc(sizeof(IWEBFILE));
if (!ret)
{
fclose(f);
return NULL;
}
ret->f = f;
ret->length = com_filesize;
ret->start = ftell(f);
ret->end = ret->start+ret->length;
return ret;
}
if (com_file_copyprotected)
{
char *buffer;
IWEBFILE *ret;
return NULL; //reject - we don't want to have this hanging over us
//big files take a LOT of memory.
buffer = COM_LoadMallocFile(name);
if (buffer)
{
ret = IWebMalloc(sizeof(IWEBFILE) + sizeof(IWeb_FileGen_t));
ret->bufferdata = (IWeb_FileGen_t *)(ret+1);
ret->length = ret->bufferdata->len = com_filesize;
ret->bufferdata->data = buffer;
ret->bufferdata->references=-1000;
ret->start = 0;
ret->pos = 0;
ret->end = com_filesize;
return ret;
}
}
#ifndef CLIENTONLY
gf = IWebGenerateFile(name, NULL, 0);
if (gf)
return gf;
#endif #endif
return NULL;
}
#endif
IWEBFILE *IWebFOpenWrite(char *name, int append) //fopen(name, append?"ab":"wb");
{
FILE *f;
char name2[512];
if (strstr(name, ".."))
return NULL;
if (*name == '/')
sprintf(name2, "%s%s", com_gamedir, name);
else
sprintf(name2, "%s/%s", com_gamedir, name);
COM_CreatePath(name2);
f = fopen(name2, append?"ab":"wb");
if (f)
{
IWEBFILE *ret = IWebMalloc(sizeof(IWEBFILE));
if (!ret)
{
fclose(f);
return NULL;
}
ret->f = f;
ret->length = 0;
ret->start = 0;
ret->end = ret->start+ret->length;
return ret;
}
return NULL;
}
int IWebFWrite(void *data, int s1, int s2, IWEBFILE *file) //fwrite
{
return fwrite(data, s1, s2, file->f);
}
int IWebFRead(void *data, int s1, int s2, IWEBFILE *file) //fread
{
#ifdef PARANOID
if (s1 != 1)
Sys_Error("IWebFRead: s1 must be 1"); //should never happen. It's a debugging thing.
#endif
if (!file->f)
{
int readable;
readable = s2;
if (s1*readable + file->pos >= file->bufferdata->len)
readable = (file->length - file->pos)/s1;
memcpy(data, file->bufferdata->data+file->pos, readable*s1);
file->pos += readable*s1;
return readable;
}
if (s2 + ftell(file->f) > file->end) //cut down the ammount readable.
s2 = file->end - ftell(file->f);
return fread(data, s1, s2, file->f);
}
void IWebFClose(IWEBFILE *file)
{
if (file->f)
fclose(file->f);
else
{
if (file->bufferdata->references == -1000) //temp condition where buffer->data is malloc, and the buffer header is part of the file info
IWebFree(file->bufferdata->data);
else
{
file->bufferdata->references--;
}
}
IWebFree(file);
}
void IWebFSeek(IWEBFILE *file, long pos, int type)
{
if (!file->f)
{
file->pos = pos;
return;
}
if (type == SEEK_SET)
fseek(file->f, pos + file->start, SEEK_SET);
else
Sys_Error("IWebFSeek: Bad seek type\n");
}
int IWebFTell(IWEBFILE *file)
{
if (!file->f)
return file->pos;
return ftell(file->f) - file->start;
}
#ifndef WEBSVONLY #ifndef WEBSVONLY
//replacement for Z_Malloc. It simply allocates up to a reserve ammount. //replacement for Z_Malloc. It simply allocates up to a reserve ammount.

View file

@ -324,7 +324,18 @@ IWebFile_t IWebFiles[] = {
{"admin.html", IWeb_GenerateAdminFile} {"admin.html", IWeb_GenerateAdminFile}
}; };
IWEBFILE *IWebGenerateFile(char *name, char *content, int contentlength) typedef struct {
vfsfile_t funcs;
char *buffer;
int length;
int pos;
} vfsmemory_t;
vfsfile_t *VFSMEM_FromZMalloc(char *buffer, int length)
{
}
vfsfile_t *IWebGenerateFile(char *name, char *content, int contentlength)
{ {
int fnum; int fnum;
char *parms; char *parms;
@ -381,7 +392,8 @@ IWEBFILE *IWebGenerateFile(char *name, char *content, int contentlength)
IWebFiles[fnum].lastgenerationtime = -10; IWebFiles[fnum].lastgenerationtime = -10;
} }
ret = IWebMalloc(sizeof(IWEBFILE)); ret = VFSMEM_FromZMalloc
ret = IWebMalloc(sizeof(vfsfile_t));
if (!ret) if (!ret)
{ {
BZ_Free(IWeb_GenerationBuffer); BZ_Free(IWeb_GenerationBuffer);

View file

@ -385,7 +385,7 @@ void QC_AddSharedFieldVar(progfuncs_t *progfuncs, int num, char *stringtable)
//oh well, must be a parameter. //oh well, must be a parameter.
if (*(int *)&pr_globals[pr_globaldefs16[num].ofs]) if (*(int *)&pr_globals[pr_globaldefs16[num].ofs])
Sys_Error("QCLIB: Global field var with no matching field \"%s\", from offset %i", pr_globaldefs16[num].s_name, *(int *)&pr_globals[pr_globaldefs16[num].ofs]); Sys_Error("QCLIB: Global field var with no matching field \"%s\", from offset %i", pr_globaldefs16[num].s_name+stringtable, *(int *)&pr_globals[pr_globaldefs16[num].ofs]);
return; return;
case 32: case 32:
for (i=1 ; i<pr_progs->numfielddefs; i++) for (i=1 ; i<pr_progs->numfielddefs; i++)

View file

@ -413,6 +413,7 @@ typedef struct
char params[MAXCONSTANTPARAMS][MAXCONSTANTPARAMLENGTH]; char params[MAXCONSTANTPARAMS][MAXCONSTANTPARAMLENGTH];
int numparams; int numparams;
pbool used; pbool used;
pbool inside;
int namelen; int namelen;
} CompilerConstant_t; } CompilerConstant_t;

View file

@ -1954,7 +1954,7 @@ int QCC_PR_CheakCompConst(void)
// printf("%s\n", pr_token); // printf("%s\n", pr_token);
c = pHash_Get(&compconstantstable, pr_token); c = pHash_Get(&compconstantstable, pr_token);
if (c) if (c && !c->inside)
{ {
pr_file_p = oldpr_file_p+strlen(c->name); pr_file_p = oldpr_file_p+strlen(c->name);
while(*pr_file_p == ' ' || *pr_file_p == '\t') while(*pr_file_p == ' ' || *pr_file_p == '\t')
@ -2084,7 +2084,9 @@ int QCC_PR_CheakCompConst(void)
else else
QCC_PR_IncludeChunk(c->value, false, NULL); QCC_PR_IncludeChunk(c->value, false, NULL);
c->inside++;
QCC_PR_Lex(); QCC_PR_Lex();
c->inside--;
return true; return true;
} }

View file

@ -3202,6 +3202,8 @@ void PF_cvar_set (progfuncs_t *prinst, struct globalvars_s *pr_globals)
val = PR_GetStringOfs(prinst, OFS_PARM1); val = PR_GetStringOfs(prinst, OFS_PARM1);
var = Cvar_Get(var_name, val, 0, "QC variables"); var = Cvar_Get(var_name, val, 0, "QC variables");
if (!var)
return;
Cvar_Set (var, val); Cvar_Set (var, val);
} }
@ -5097,9 +5099,10 @@ void PF_logfrag (progfuncs_t *prinst, struct globalvars_s *pr_globals)
s = va("\\%s\\%s\\\n",svs.clients[e1-1].name, svs.clients[e2-1].name); s = va("\\%s\\%s\\\n",svs.clients[e1-1].name, svs.clients[e2-1].name);
SZ_Print (&svs.log[svs.logsequence&1], s); SZ_Print (&svs.log[svs.logsequence&1], s);
if (sv_fraglogfile) { if (sv_fraglogfile)
fprintf (sv_fraglogfile, s); {
fflush (sv_fraglogfile); VFS_WRITE(sv_fraglogfile, s, strlen(s));
VFS_FLUSH (sv_fraglogfile);
} }
} }
@ -5270,9 +5273,10 @@ void PF_logstring (progfuncs_t *prinst, struct globalvars_s *pr_globals)
s = PF_VarString(prinst, 0, pr_globals); s = PF_VarString(prinst, 0, pr_globals);
if (sv_fraglogfile) { if (sv_fraglogfile)
fprintf (sv_fraglogfile, s); {
fflush (sv_fraglogfile); VFS_WRITE(sv_fraglogfile, s, strlen(s));
VFS_FLUSH(sv_fraglogfile);
} }
} }
#define PRSTR 0xa6ffb3d7 #define PRSTR 0xa6ffb3d7

View file

@ -457,9 +457,9 @@ qboolean SV_LoadLevelCache(char *level, char *startspot, qboolean ignoreplayers)
eval_t *eval, *e2; eval_t *eval, *e2;
char name[MAX_OSPATH]; char name[MAX_OSPATH];
FILE *f; vfsfile_t *f;
char mapname[MAX_QPATH]; char mapname[MAX_QPATH];
float time, tfloat; float time;
char str[32768]; char str[32768];
int i,j; int i,j;
edict_t *ent; edict_t *ent;
@ -519,41 +519,43 @@ qboolean SV_LoadLevelCache(char *level, char *startspot, qboolean ignoreplayers)
// been used. The menu calls it before stuffing loadgame command // been used. The menu calls it before stuffing loadgame command
// SCR_BeginLoadingPlaque (); // SCR_BeginLoadingPlaque ();
COM_FOpenFile(name, &f); f = FS_OpenVFS(name, "rt", FS_GAME);
if (!f) if (!f)
{ {
Con_TPrintf (STL_ERRORCOULDNTOPEN); Con_TPrintf (STL_ERRORCOULDNTOPEN);
return false; return false;
} }
fscanf (f, "%i\n", &version); VFS_GETS(f, str, sizeof(str));
version = atoi(str);
if (version != CACHEGAME_VERSION) if (version != CACHEGAME_VERSION)
{ {
fclose (f); VFS_CLOSE (f);
Con_TPrintf (STL_BADSAVEVERSION, version, CACHEGAME_VERSION); Con_TPrintf (STL_BADSAVEVERSION, version, CACHEGAME_VERSION);
return false; return false;
} }
fscanf (f, "%s\n", str); VFS_GETS(f, str, sizeof(str)); //comment
SV_SendMessagesToAll(); SV_SendMessagesToAll();
fscanf (f, "%f\n", &tfloat); VFS_GETS(f, str, sizeof(str));
pt = tfloat; pt = atof(str);
// this silliness is so we can load 1.06 save files, which have float skill values // this silliness is so we can load 1.06 save files, which have float skill values
fscanf (f, "%f\n", &tfloat); VFS_GETS(f, str, sizeof(str));
current_skill = (int)(tfloat + 0.1); current_skill = (int)(atof(str) + 0.1);
Cvar_Set (&skill, va("%i", current_skill)); Cvar_Set (&skill, va("%i", current_skill));
fscanf (f, "%f\n", &tfloat); VFS_GETS(f, str, sizeof(str));
Cvar_SetValue (&deathmatch, tfloat); Cvar_SetValue (&deathmatch, atof(str));
fscanf (f, "%f\n", &tfloat); VFS_GETS(f, str, sizeof(str));
Cvar_SetValue (&coop, tfloat); Cvar_SetValue (&coop, atof(str));
fscanf (f, "%f\n", &tfloat); VFS_GETS(f, str, sizeof(str));
Cvar_SetValue (&teamplay, tfloat); Cvar_SetValue (&teamplay, atof(str));
fscanf (f, "%s\n",mapname); VFS_GETS(f, mapname, sizeof(mapname));
fscanf (f, "%f\n",&time); VFS_GETS(f, str, sizeof(str));
time = atof(str);
SV_SpawnServer (mapname, startspot, false, false); SV_SpawnServer (mapname, startspot, false, false);
if (svs.gametype != gametype) if (svs.gametype != gametype)
@ -563,7 +565,7 @@ qboolean SV_LoadLevelCache(char *level, char *startspot, qboolean ignoreplayers)
} }
if (sv.state != ss_active) if (sv.state != ss_active)
{ {
fclose (f); VFS_CLOSE (f);
Con_TPrintf (STL_LOADFAILED); Con_TPrintf (STL_LOADFAILED);
return false; return false;
} }
@ -575,7 +577,7 @@ qboolean SV_LoadLevelCache(char *level, char *startspot, qboolean ignoreplayers)
for (i=0 ; i<MAX_LIGHTSTYLES ; i++) for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
{ {
fscanf (f, "%s\n", str); VFS_GETS(f, str, sizeof(str));
if (sv.lightstyles[i]) if (sv.lightstyles[i])
Z_Free(sv.lightstyles[i]); Z_Free(sv.lightstyles[i]);
sv.lightstyles[i] = Z_Malloc (strlen(str)+1); sv.lightstyles[i] = Z_Malloc (strlen(str)+1);
@ -594,7 +596,7 @@ qboolean SV_LoadLevelCache(char *level, char *startspot, qboolean ignoreplayers)
sv.model_precache[0] = PR_AddString(svprogfuncs, "", 0); sv.model_precache[0] = PR_AddString(svprogfuncs, "", 0);
for (i=1; i < MAX_MODELS; i++) for (i=1; i < MAX_MODELS; i++)
{ {
fscanf (f, "%s\n", str); VFS_GETS(f, str, sizeof(str));
if (!*str) if (!*str)
break; break;
@ -602,7 +604,7 @@ qboolean SV_LoadLevelCache(char *level, char *startspot, qboolean ignoreplayers)
} }
if (i == MAX_MODELS) if (i == MAX_MODELS)
{ {
fscanf (f, "%s\n", str); VFS_GETS(f, str, sizeof(str));
if (*str) if (*str)
SV_Error("Too many model precaches in loadgame cache"); SV_Error("Too many model precaches in loadgame cache");
} }
@ -612,7 +614,7 @@ qboolean SV_LoadLevelCache(char *level, char *startspot, qboolean ignoreplayers)
// sv.sound_precache[0] = PR_AddString(svprogfuncs, "", 0); // sv.sound_precache[0] = PR_AddString(svprogfuncs, "", 0);
for (i=1; i < MAX_SOUNDS; i++) for (i=1; i < MAX_SOUNDS; i++)
{ {
fscanf (f, "%s\n", str); VFS_GETS(f, str, sizeof(str));
if (!*str) if (!*str)
break; break;
@ -620,21 +622,19 @@ qboolean SV_LoadLevelCache(char *level, char *startspot, qboolean ignoreplayers)
} }
if (i == MAX_SOUNDS) if (i == MAX_SOUNDS)
{ {
fscanf (f, "%s\n", str); VFS_GETS(f, str, sizeof(str));
if (*str) if (*str)
SV_Error("Too many sound precaches in loadgame cache"); SV_Error("Too many sound precaches in loadgame cache");
} }
for (; i < MAX_SOUNDS; i++) for (; i < MAX_SOUNDS; i++)
*sv.sound_precache[i] = 0; *sv.sound_precache[i] = 0;
filepos = ftell(f); filepos = VFS_TELL(f);
fseek(f, 0, SEEK_END); filelen = VFS_GETLEN(f);
filelen = ftell(f);
fseek(f, filepos, SEEK_SET);
filelen -= filepos; filelen -= filepos;
file = BZ_Malloc(filelen+1); file = BZ_Malloc(filelen+1);
memset(file, 0, filelen+1); memset(file, 0, filelen+1);
clnum=fread(file, 1, filelen, f); clnum=VFS_READ(f, file, filelen);
file[filelen]='\0'; file[filelen]='\0';
pr_edict_size=svprogfuncs->load_ents(svprogfuncs, file, 0); pr_edict_size=svprogfuncs->load_ents(svprogfuncs, file, 0);
BZ_Free(file); BZ_Free(file);
@ -645,7 +645,7 @@ qboolean SV_LoadLevelCache(char *level, char *startspot, qboolean ignoreplayers)
pr_global_struct->time = sv.time = time; pr_global_struct->time = sv.time = time;
fclose (f); VFS_CLOSE(f);
SV_ClearWorld (); SV_ClearWorld ();

View file

@ -210,7 +210,7 @@ typedef struct
qboolean mvdplayback; qboolean mvdplayback;
float realtime; float realtime;
FILE *demofile; //also signifies playing the thing. vfsfile_t *demofile; //also signifies playing the thing.
int lasttype; int lasttype;
int lastto; int lastto;
@ -408,7 +408,7 @@ typedef struct client_s
q3client_frame_t *q3frames; q3client_frame_t *q3frames;
#endif #endif
}; };
FILE *download; // file being downloaded vfsfile_t *download; // file being downloaded
int downloadsize; // total bytes int downloadsize; // total bytes
int downloadcount; // bytes sent int downloadcount; // bytes sent
@ -442,7 +442,7 @@ typedef struct client_s
qboolean upgradewarn; // did we warn him? qboolean upgradewarn; // did we warn him?
FILE *upload; vfsfile_t *upload;
char uploadfn[MAX_QPATH]; char uploadfn[MAX_QPATH];
netadr_t snap_from; netadr_t snap_from;
qboolean remote_snap; qboolean remote_snap;
@ -860,7 +860,7 @@ extern char localmodels[MAX_MODELS][5]; // inline model names for precache
extern char localinfo[MAX_LOCALINFO_STRING+1]; extern char localinfo[MAX_LOCALINFO_STRING+1];
extern int host_hunklevel; extern int host_hunklevel;
extern FILE *sv_fraglogfile; extern vfsfile_t *sv_fraglogfile;
//=========================================================== //===========================================================
@ -902,7 +902,7 @@ void SV_InitOperatorCommands (void);
void SV_SendServerinfo (client_t *client); void SV_SendServerinfo (client_t *client);
void SV_ExtractFromUserinfo (client_t *cl); void SV_ExtractFromUserinfo (client_t *cl);
void SV_SaveInfos(FILE *f); void SV_SaveInfos(vfsfile_t *f);
void Master_Heartbeat (void); void Master_Heartbeat (void);

View file

@ -21,6 +21,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef CLIENTONLY #ifndef CLIENTONLY
#ifndef INVALID_SOCKET
#define INVALID_SOCKET -1
#endif
qboolean sv_allow_cheats; qboolean sv_allow_cheats;
int fp_messages=4, fp_persecond=4, fp_secondsdead=10; int fp_messages=4, fp_persecond=4, fp_secondsdead=10;
@ -187,7 +193,6 @@ void SV_Logfile_f (void)
{ {
extern cvar_t log_enable, log_dir, log_name; extern cvar_t log_enable, log_dir, log_name;
extern char gamedirfile[]; extern char gamedirfile[];
extern char *com_basedir;
if (log_enable.value) if (log_enable.value)
{ {
@ -206,7 +211,7 @@ void SV_Logfile_f (void)
if (log_name.string[0]) if (log_name.string[0])
f = log_name.string; f = log_name.string;
Con_Printf(va("Logging to %s/%s/%s.log.\n", com_basedir, d, f)); Con_Printf(va("Logging to %s/%s.log.\n", d, f));
Cvar_SetValue(&log_enable, 1); Cvar_SetValue(&log_enable, 1);
} }
@ -225,7 +230,7 @@ void SV_Fraglogfile_f (void)
if (sv_fraglogfile) if (sv_fraglogfile)
{ {
Con_TPrintf (STL_FLOGGINGOFF); Con_TPrintf (STL_FLOGGINGOFF);
fclose (sv_fraglogfile); VFS_CLOSE (sv_fraglogfile);
sv_fraglogfile = NULL; sv_fraglogfile = NULL;
return; return;
} }
@ -233,16 +238,16 @@ void SV_Fraglogfile_f (void)
// find an unused name // find an unused name
for (i=0 ; i<1000 ; i++) for (i=0 ; i<1000 ; i++)
{ {
sprintf (name, "%s/frag_%i.log", com_gamedir, i); sprintf (name, "frag_%i.log", i);
sv_fraglogfile = fopen (name, "r"); sv_fraglogfile = FS_OpenVFS(name, "r", FS_GAME);
if (!sv_fraglogfile) if (!sv_fraglogfile)
{ // can't read it, so create this one { // can't read it, so create this one
sv_fraglogfile = fopen (name, "w"); sv_fraglogfile = FS_OpenVFS (name, "w", FS_GAME);
if (!sv_fraglogfile) if (!sv_fraglogfile)
i=1000; // give error i=1000; // give error
break; break;
} }
fclose (sv_fraglogfile); VFS_CLOSE (sv_fraglogfile);
} }
if (i==1000) if (i==1000)
{ {
@ -1282,13 +1287,13 @@ void SV_Localinfo_f (void)
Con_DPrintf("Localinfo %s changed (%s -> %s)\n", Cmd_Argv(1), old, Cmd_Argv(2)); Con_DPrintf("Localinfo %s changed (%s -> %s)\n", Cmd_Argv(1), old, Cmd_Argv(2));
} }
void SV_SaveInfos(FILE *f) void SV_SaveInfos(vfsfile_t *f)
{ {
fwrite("\n", 1, 1, f); VFS_WRITE(f, "\n", 1);
fwrite("serverinfo * \"\"\n", 16, 1, f); VFS_WRITE(f, "serverinfo * \"\"\n", 16);
Info_WriteToFile(f, svs.info, "serverinfo", CVAR_SERVERINFO); Info_WriteToFile(f, svs.info, "serverinfo", CVAR_SERVERINFO);
fwrite("\n", 1, 1, f); VFS_WRITE(f, "\n", 1);
fwrite("localinfo * \"\"\n", 15, 1, f); VFS_WRITE(f, "localinfo * \"\"\n", 15);
Info_WriteToFile(f, localinfo, "localinfo", 0); Info_WriteToFile(f, localinfo, "localinfo", 0);
} }

View file

@ -225,7 +225,7 @@ void SV_LoadClientDemo_f (void)
if (svd.demofile) if (svd.demofile)
{ {
Con_Printf ("Ending old demo\n"); Con_Printf ("Ending old demo\n");
fclose(svd.demofile); VFS_CLOSE(svd.demofile);
svd.demofile = NULL; svd.demofile = NULL;
SV_ReadMVD(); SV_ReadMVD();
@ -240,10 +240,10 @@ void SV_LoadClientDemo_f (void)
} }
demoname = Cmd_Argv(1); demoname = Cmd_Argv(1);
com_filesize = COM_FOpenFile(demoname, &svd.demofile); svd.demofile = FS_OpenVFS(demoname, "rb", FS_GAME);
if (!svd.demofile) //try with a different path if (!svd.demofile) //try with a different path
com_filesize = COM_FOpenFile(va("demos/%s", demoname), &svd.demofile); svd.demofile = FS_OpenVFS(va("demos/%s", demoname), "rb", FS_GAME);
com_filesize = VFS_GETLEN(svd.demofile);
if (!svd.demofile) if (!svd.demofile)
{ {
@ -253,7 +253,7 @@ void SV_LoadClientDemo_f (void)
if (com_filesize <= 0) if (com_filesize <= 0)
{ {
Con_Printf("Failed to open %s\n", demoname); Con_Printf("Failed to open %s\n", demoname);
fclose(svd.demofile); VFS_CLOSE(svd.demofile);
svd.demofile = NULL; svd.demofile = NULL;
return; return;
} }
@ -337,13 +337,13 @@ readnext:
// read the time from the packet // read the time from the packet
if (svd.mvdplayback) if (svd.mvdplayback)
{ {
fread(&newtime, sizeof(newtime), 1, svd.demofile); VFS_READ(svd.demofile, &newtime, sizeof(newtime));
nextdemotime = olddemotime + newtime * (1/1000.0f); nextdemotime = olddemotime + newtime * (1/1000.0f);
demotime = nextdemotime; demotime = nextdemotime;
if (nextdemotime > svd.realtime) if (nextdemotime > svd.realtime)
{ {
fseek(svd.demofile, ftell(svd.demofile) - sizeof(newtime), SEEK_SET); VFS_SEEK(svd.demofile, VFS_TELL(svd.demofile) - sizeof(newtime));
return false; return false;
} }
else if (nextdemotime + 0.1 < svd.realtime) else if (nextdemotime + 0.1 < svd.realtime)
@ -351,7 +351,7 @@ readnext:
} }
else else
{ {
fread(&demotime, sizeof(demotime), 1, svd.demofile); VFS_READ(svd.demofile, &demotime, sizeof(demotime));
demotime = LittleFloat(demotime); demotime = LittleFloat(demotime);
if (!nextdemotime) if (!nextdemotime)
svd.realtime = nextdemotime = demotime; svd.realtime = nextdemotime = demotime;
@ -365,11 +365,11 @@ readnext:
// too far back // too far back
svd.realtime = demotime - 1.0; svd.realtime = demotime - 1.0;
// rewind back to time // rewind back to time
fseek(svd.demofile, ftell(svd.demofile) - sizeof(demotime), SEEK_SET); VFS_SEEK(svd.demofile, VFS_TELL(svd.demofile) - sizeof(demotime));
return false; return false;
} else if (nextdemotime < demotime) { } else if (nextdemotime < demotime) {
// rewind back to time // rewind back to time
fseek(svd.demofile, ftell(svd.demofile) - sizeof(demotime), SEEK_SET); VFS_SEEK(svd.demofile, VFS_TELL(svd.demofile) - sizeof(demotime));
return false; // don't need another message yet return false; // don't need another message yet
} }
} }
@ -380,10 +380,10 @@ readnext:
olddemotime = demotime; olddemotime = demotime;
// get the msg type // get the msg type
if ((r = fread (&c, sizeof(c), 1, svd.demofile)) != 1) if ((r = VFS_READ(svd.demofile, &c, sizeof(c))) != sizeof(c))
{ {
Con_Printf ("Unexpected end of demo\n"); Con_Printf ("Unexpected end of demo\n");
fclose(svd.demofile); VFS_CLOSE(svd.demofile);
svd.demofile = NULL; svd.demofile = NULL;
return false; return false;
// SV_Error ("Unexpected end of demo"); // SV_Error ("Unexpected end of demo");
@ -393,7 +393,7 @@ readnext:
case dem_cmd : case dem_cmd :
Con_Printf ("dem_cmd not supported\n"); Con_Printf ("dem_cmd not supported\n");
fclose(svd.demofile); VFS_CLOSE(svd.demofile);
svd.demofile = NULL; svd.demofile = NULL;
return false; return false;
@ -426,7 +426,7 @@ readnext:
case dem_read: case dem_read:
readit: readit:
// get the next message // get the next message
fread (&net_message.cursize, 4, 1, svd.demofile); VFS_READ (svd.demofile, &net_message.cursize, 4);
net_message.cursize = LittleLong (net_message.cursize); net_message.cursize = LittleLong (net_message.cursize);
if (!svd.mvdplayback && net_message.cursize > MAX_QWMSGLEN + 8) if (!svd.mvdplayback && net_message.cursize > MAX_QWMSGLEN + 8)
@ -434,7 +434,7 @@ readit:
else if (svd.mvdplayback && net_message.cursize > net_message.maxsize) else if (svd.mvdplayback && net_message.cursize > net_message.maxsize)
SV_Error ("Demo message > MAX_UDP_PACKET"); SV_Error ("Demo message > MAX_UDP_PACKET");
if ((r = fread (net_message.data, net_message.cursize, 1, svd.demofile)) != 1) if ((r = VFS_READ(svd.demofile, net_message.data, net_message.cursize)) != net_message.cursize)
SV_Error ("Corrupted demo"); SV_Error ("Corrupted demo");
/* if (svd.mvdplayback) { /* if (svd.mvdplayback) {
@ -455,12 +455,12 @@ readit:
return true; return true;
case dem_set: case dem_set:
fread (&i, 4, 1, svd.demofile); VFS_READ(svd.demofile, &i, 4);
fread (&i, 4, 1, svd.demofile); VFS_READ(svd.demofile, &i, 4);
goto readnext; goto readnext;
case dem_multiple: case dem_multiple:
if ((r = fread (&i, 4, 1, svd.demofile)) != 1) if ((r = VFS_READ(svd.demofile, &i, 4)) != 1)
SV_Error ("Corrupted demo"); SV_Error ("Corrupted demo");
svd.lastto = LittleLong(i); svd.lastto = LittleLong(i);
@ -579,7 +579,7 @@ qboolean SV_ReadMVD (void)
if (oldsc != svs.spawncount) if (oldsc != svs.spawncount)
{ {
fclose(svd.demofile); VFS_CLOSE(svd.demofile);
svd.demofile = NULL; svd.demofile = NULL;
for (i=0, host_client = svs.clients ; i<MAX_CLIENTS ; i++, host_client++) for (i=0, host_client = svs.clients ; i<MAX_CLIENTS ; i++, host_client++)

View file

@ -18,7 +18,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#include "qwsvdef.h" #include "qwsvdef.h"
#include "sys/types.h" #include <sys/types.h>
#ifndef CLIENTONLY #ifndef CLIENTONLY
#define Q2EDICT_NUM(i) (q2edict_t*)((char *)ge->edicts+i*ge->edict_size) #define Q2EDICT_NUM(i) (q2edict_t*)((char *)ge->edicts+i*ge->edict_size)
@ -103,6 +103,7 @@ cvar_t allow_download_root = {"allow_download_root", "0"};
cvar_t allow_download_textures = {"allow_download_textures", "1"}; cvar_t allow_download_textures = {"allow_download_textures", "1"};
cvar_t allow_download_pk3s = {"allow_download_pk3s", "1"}; cvar_t allow_download_pk3s = {"allow_download_pk3s", "1"};
cvar_t allow_download_wads = {"allow_download_wads", "1"}; cvar_t allow_download_wads = {"allow_download_wads", "1"};
cvar_t allow_download_configs = {"allow_download_configs", "0"};
cvar_t sv_public = {"sv_public", "0"}; cvar_t sv_public = {"sv_public", "0"};
cvar_t sv_listen = {"sv_listen", "1"}; cvar_t sv_listen = {"sv_listen", "1"};
@ -172,7 +173,7 @@ char cvargroup_serverinfo[] = "serverinfo variables";
char cvargroup_serverphysics[] = "server physics variables"; char cvargroup_serverphysics[] = "server physics variables";
char cvargroup_servercontrol[] = "server control variables"; char cvargroup_servercontrol[] = "server control variables";
FILE *sv_fraglogfile; vfsfile_t *sv_fraglogfile;
void SV_FixupName(char *in, char *out); void SV_FixupName(char *in, char *out);
void SV_AcceptClient (netadr_t adr, int userid, char *userinfo); void SV_AcceptClient (netadr_t adr, int userid, char *userinfo);
@ -197,7 +198,7 @@ void SV_Shutdown (void)
Master_Shutdown (); Master_Shutdown ();
if (sv_fraglogfile) if (sv_fraglogfile)
{ {
fclose (sv_fraglogfile); VFS_CLOSE (sv_fraglogfile);
sv_fraglogfile = NULL; sv_fraglogfile = NULL;
} }
@ -435,12 +436,12 @@ void SV_DropClient (client_t *drop)
if (drop->download) if (drop->download)
{ {
fclose (drop->download); VFS_CLOSE (drop->download);
drop->download = NULL; drop->download = NULL;
} }
if (drop->upload) if (drop->upload)
{ {
fclose (drop->upload); VFS_CLOSE (drop->upload);
drop->upload = NULL; drop->upload = NULL;
} }
*drop->uploadfn = 0; *drop->uploadfn = 0;
@ -2498,16 +2499,17 @@ SV_WriteIP_f
*/ */
void SV_WriteIP_f (void) void SV_WriteIP_f (void)
{ {
FILE *f; vfsfile_t *f;
char name[MAX_OSPATH]; char name[MAX_OSPATH];
qbyte b[4]; qbyte b[4];
int i; int i;
char *s;
sprintf (name, "%s/listip.cfg", com_gamedir); sprintf (name, "listip.cfg");
Con_Printf ("Writing %s.\n", name); Con_Printf ("Writing %s.\n", name);
COM_FOpenWriteFile(name, &f); f = FS_OpenVFS(name, "wt", FS_GAME);
if (!f) if (!f)
{ {
Con_Printf ("Couldn't open %s\n", name); Con_Printf ("Couldn't open %s\n", name);
@ -2517,10 +2519,11 @@ void SV_WriteIP_f (void)
for (i=0 ; i<numipfilters ; i++) for (i=0 ; i<numipfilters ; i++)
{ {
*(unsigned *)b = ipfilters[i].compare; *(unsigned *)b = ipfilters[i].compare;
fprintf (f, "addip %i.%i.%i.%i\n", b[0], b[1], b[2], b[3]); s = va("addip %i.%i.%i.%i\n", b[0], b[1], b[2], b[3]);
VFS_WRITE(f, s, strlen(s));
} }
fclose (f); VFS_CLOSE (f);
} }
/* /*
@ -3187,6 +3190,7 @@ void SV_InitLocal (void)
Cvar_Register (&allow_download_anymap, cvargroup_serverpermissions); Cvar_Register (&allow_download_anymap, cvargroup_serverpermissions);
Cvar_Register (&allow_download_pakcontents, cvargroup_serverpermissions); Cvar_Register (&allow_download_pakcontents, cvargroup_serverpermissions);
Cvar_Register (&allow_download_textures,cvargroup_serverpermissions); Cvar_Register (&allow_download_textures,cvargroup_serverpermissions);
Cvar_Register (&allow_download_configs, cvargroup_serverpermissions);
Cvar_Register (&allow_download_pk3s, cvargroup_serverpermissions); Cvar_Register (&allow_download_pk3s, cvargroup_serverpermissions);
Cvar_Register (&allow_download_wads, cvargroup_serverpermissions); Cvar_Register (&allow_download_wads, cvargroup_serverpermissions);
Cvar_Register (&allow_download_root, cvargroup_serverpermissions); Cvar_Register (&allow_download_root, cvargroup_serverpermissions);

View file

@ -27,17 +27,25 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#endif #endif
#include <sys/stat.h> #include <sys/stat.h>
#include <termios.h>
#include <unistd.h> #include <unistd.h>
#include <sys/time.h> #include <sys/time.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
cvar_t sys_nostdout = {"sys_nostdout","0"}; cvar_t sys_nostdout = {"sys_nostdout","0"};
cvar_t sys_extrasleep = {"sys_extrasleep","0"}; cvar_t sys_extrasleep = {"sys_extrasleep","0"};
cvar_t sys_maxtic = {"sys_maxtic", "100"}; cvar_t sys_maxtic = {"sys_maxtic", "100"};
cvar_t sys_colorconsole = {"sys_colorconsole", "0"};
cvar_t sys_linebuffer = {"sys_linebuffer", "1"};
qboolean stdin_ready; qboolean stdin_ready;
struct termios orig, changes;
/* /*
=============================================================================== ===============================================================================
@ -172,10 +180,216 @@ void Sys_Error (const char *error, ...)
va_end (argptr); va_end (argptr);
printf ("Fatal error: %s\n",string); printf ("Fatal error: %s\n",string);
tcsetattr(STDIN_FILENO, TCSADRAIN, &orig);
*(int*)-3 = 0; *(int*)-3 = 0;
exit (1); exit (1);
} }
void ApplyColour(unsigned int chr)
{
static int oldchar = 7*256;
chr = chr&~255;
if (oldchar == chr)
return;
oldchar = chr;
switch(chr&CON_COLOURMASK)
{
//to get around wierd defaults (like a white background) we have these special hacks for colours 0 and 7
case 0*256:
printf("\e[0;7%sm", (chr&CON_BLINKTEXT)?";5":"");
break;
case 7*256:
printf("\e[0%sm", (chr&CON_BLINKTEXT)?";5":"");
break;
default:
printf("\e[0;%i%sm", 30+((chr&CON_COLOURMASK)>>8), (chr&CON_BLINKTEXT)?";5":"");
break;
}
}
#define putch(c) putc(c, stdout);
void Sys_PrintColouredChar(unsigned int chr)
{
ApplyColour(chr);
putch(chr&255);
}
/*
================
Sys_Printf
================
*/
#define MAXPRINTMSG 4096
char coninput_text[256];
int coninput_len;
void Sys_Printf (char *fmt, ...)
{
va_list argptr;
if (sys_nostdout.value)
return;
if (1)
{
char msg[MAXPRINTMSG];
unsigned char *t;
va_start (argptr,fmt);
vsnprintf (msg,sizeof(msg)-1, fmt,argptr);
va_end (argptr);
if (!sys_linebuffer.value)
{
int i;
for (i = 0; i < coninput_len; i++)
putch('\b');
putch('\b');
for (i = 0; i < coninput_len; i++)
putch(' ');
putch(' ');
for (i = 0; i < coninput_len; i++)
putch('\b');
putch('\b');
}
for (t = (unsigned char*)msg; *t; t++)
{
if (*t >= 146 && *t < 156)
*t = *t - 146 + '0';
if (*t >= 0x12 && *t <= 0x1b)
*t = *t - 0x12 + '0';
if (*t == 143)
*t = '.';
if (*t == 157 || *t == 158 || *t == 159)
*t = '-';
if (*t >= 128)
*t -= 128;
if (*t == 16)
*t = '[';
if (*t == 17)
*t = ']';
if (*t == 0x1c)
*t = 249;
}
if (sys_colorconsole.value)
{
int ext = COLOR_WHITE<<8;
int extstack[4];
int extstackdepth = 0;
unsigned char *str = (unsigned char*)msg;
while(*str)
{
if (*str == '^')
{
str++;
if (*str >= '0' && *str <= '7')
{
ext = (*str++-'0')*256 + (ext&~CON_COLOURMASK); //change colour only.
continue;
}
else if (*str == 'a')
{
str++;
ext = (ext & ~CON_2NDCHARSETTEXT) + (CON_2NDCHARSETTEXT - (ext & CON_2NDCHARSETTEXT));
continue;
}
else if (*str == 'b')
{
str++;
ext = (ext & ~CON_BLINKTEXT) + (CON_BLINKTEXT - (ext & CON_BLINKTEXT));
continue;
}
else if (*str == 's') //store on stack (it's great for names)
{
str++;
if (extstackdepth < sizeof(extstack)/sizeof(extstack[0]))
{
extstack[extstackdepth] = ext;
extstackdepth++;
}
continue;
}
else if (*str == 'r') //restore from stack (it's great for names)
{
str++;
if (extstackdepth)
{
extstackdepth--;
ext = extstack[extstackdepth];
}
continue;
}
else if (*str == '^')
{
Sys_PrintColouredChar('^' + ext);
str++;
}
else
{
Sys_PrintColouredChar('^' + ext);
Sys_PrintColouredChar ((*str++) + ext);
}
continue;
}
Sys_PrintColouredChar ((*str++) + ext);
}
ApplyColour(7*256);
}
else
{
for (t = msg; *t; t++)
{
*t &= 0x7f;
if ((*t > 128 || *t < 32) && *t != 10 && *t != 13 && *t != 9)
printf("[%02x]", *t);
else
putc(*t, stdout);
}
}
if (!sys_linebuffer.value)
{
if (coninput_len)
printf("]%s", coninput_text);
else
putch(']');
}
}
else
{
va_start (argptr,fmt);
vprintf (fmt,argptr);
va_end (argptr);
}
fflush(stdout);
}
#if 0
/* /*
================ ================
Sys_Printf Sys_Printf
@ -207,6 +421,7 @@ void Sys_Printf (char *fmt, ...)
fflush(stdout); fflush(stdout);
} }
#endif
/* /*
================ ================
@ -215,11 +430,70 @@ Sys_Quit
*/ */
void Sys_Quit (void) void Sys_Quit (void)
{ {
tcsetattr(STDIN_FILENO, TCSADRAIN, &orig);
exit (0); // appkit isn't running exit (0); // appkit isn't running
} }
static int do_stdin = 1; static int do_stdin = 1;
#if 1
char *Sys_LineInputChar(char *line)
{
char c;
while(*line)
{
c = *line++;
if (c == '\r' || c == '\n')
{
coninput_text[coninput_len] = 0;
putch ('\n');
putch (']');
coninput_len = 0;
fflush(stdout);
return coninput_text;
}
if (c == 8)
{
if (coninput_len)
{
putch (c);
putch (' ');
putch (c);
coninput_len--;
coninput_text[coninput_len] = 0;
}
continue;
}
if (c == '\t')
{
int i;
char *s = Cmd_CompleteCommand(coninput_text, true, true, 0);
if(s)
{
for (i = 0; i < coninput_len; i++)
putch('\b');
for (i = 0; i < coninput_len; i++)
putch(' ');
for (i = 0; i < coninput_len; i++)
putch('\b');
strcpy(coninput_text, s);
coninput_len = strlen(coninput_text);
printf("%s", coninput_text);
}
continue;
}
putch (c);
coninput_text[coninput_len] = c;
coninput_len++;
coninput_text[coninput_len] = 0;
if (coninput_len == sizeof(coninput_text))
coninput_len = 0;
}
fflush(stdout);
return NULL;
}
#endif
/* /*
================ ================
Sys_ConsoleInput Sys_ConsoleInput
@ -230,24 +504,51 @@ it to the host command processor
*/ */
char *Sys_ConsoleInput (void) char *Sys_ConsoleInput (void)
{ {
static char text[256]; char text[256];
int len; int len;
if (sys_linebuffer.modified)
{
sys_linebuffer.modified = false;
changes = orig;
if (sys_linebuffer.value)
{
changes.c_lflag |= (ICANON|ECHO);
}
else
{
changes.c_lflag &= ~(ICANON|ECHO);
changes.c_cc[VTIME] = 0;
changes.c_cc[VMIN] = 1;
}
tcsetattr(STDIN_FILENO, TCSADRAIN, &changes);
}
if (!stdin_ready || !do_stdin) if (!stdin_ready || !do_stdin)
return NULL; // the select didn't say it was ready return NULL; // the select didn't say it was ready
stdin_ready = false; stdin_ready = false;
len = read (0, text, sizeof(text)); if (sys_linebuffer.value == 0)
if (len == 0) { {
// end of file text[0] = getc(stdin);
do_stdin = 0; text[1] = 0;
return NULL; len = 1;
return Sys_LineInputChar(text);
} }
if (len < 1) else
return NULL; {
text[len-1] = 0; // rip off the /n and terminate len = read (0, text, sizeof(text)-1);
if (len == 0) {
// end of file
do_stdin = 0;
return NULL;
}
if (len < 1)
return NULL;
text[len-1] = 0; // rip off the /n and terminate
return text; return text;
}
} }
/* /*
@ -263,6 +564,9 @@ void Sys_Init (void)
Cvar_Register (&sys_nostdout, "System configuration"); Cvar_Register (&sys_nostdout, "System configuration");
Cvar_Register (&sys_extrasleep, "System configuration"); Cvar_Register (&sys_extrasleep, "System configuration");
Cvar_Register (&sys_maxtic, "System configuration"); Cvar_Register (&sys_maxtic, "System configuration");
Cvar_Register (&sys_colorconsole, "System configuration");
Cvar_Register (&sys_linebuffer, "System configuration");
} }
/* /*
@ -277,6 +581,9 @@ int main(int argc, char *argv[])
// extern int net_socket; // extern int net_socket;
int j; int j;
tcgetattr(STDIN_FILENO, &orig);
changes = orig;
memset (&parms, 0, sizeof(parms)); memset (&parms, 0, sizeof(parms));
COM_InitArgv (argc, argv); COM_InitArgv (argc, argv);
@ -294,12 +601,6 @@ int main(int argc, char *argv[])
parms.basedir = "."; parms.basedir = ".";
/*
if (Sys_FileTime ("id1/pak0.pak") != -1)
else
parms.basedir = "/raid/quake/v2";
*/
SV_Init (&parms); SV_Init (&parms);
// run one frame immediately for first heartbeat // run one frame immediately for first heartbeat

View file

@ -428,6 +428,7 @@ void ApplyColour(unsigned int chr)
return; return;
oldchar = chr; oldchar = chr;
#if 1
if (hconsoleout) if (hconsoleout)
{ {
int val; int val;
@ -462,7 +463,7 @@ void ApplyColour(unsigned int chr)
SetConsoleTextAttribute(hconsoleout, val); SetConsoleTextAttribute(hconsoleout, val);
} }
#if 0 #else
//does ansi work? //does ansi work?
//no? //no?
//windows sucks. //windows sucks.

View file

@ -1402,8 +1402,8 @@ void SV_NextChunkedDownload(int chunknum)
char buffer[1024]; char buffer[1024];
if (host_client->datagram.cursize + CHUNKSIZE+5+50 > host_client->datagram.maxsize) if (host_client->datagram.cursize + CHUNKSIZE+5+50 > host_client->datagram.maxsize)
return; //choked! return; //choked!
fseek (host_client->download, chunknum*CHUNKSIZE, SEEK_SET); VFS_SEEK (host_client->download, chunknum*CHUNKSIZE);
fread (buffer, 1, CHUNKSIZE, host_client->download); VFS_READ (host_client->download, buffer, CHUNKSIZE);
MSG_WriteByte(&host_client->datagram, svc_download); MSG_WriteByte(&host_client->datagram, svc_download);
MSG_WriteLong(&host_client->datagram, chunknum); MSG_WriteLong(&host_client->datagram, chunknum);
@ -1446,7 +1446,7 @@ void SV_NextDownload_f (void)
*/ */
if (r > 768) if (r > 768)
r = 768; r = 768;
r = fread (buffer, 1, r, host_client->download); r = VFS_READ (host_client->download, buffer, r);
ClientReliableWrite_Begin (host_client, ISQ2CLIENT(host_client)?svcq2_download:svc_download, 6+r); ClientReliableWrite_Begin (host_client, ISQ2CLIENT(host_client)?svcq2_download:svc_download, 6+r);
ClientReliableWrite_Short (host_client, r); ClientReliableWrite_Short (host_client, r);
@ -1472,7 +1472,7 @@ void SV_NextDownload_f (void)
if (host_client->downloadcount != host_client->downloadsize) if (host_client->downloadcount != host_client->downloadsize)
return; return;
fclose (host_client->download); VFS_CLOSE (host_client->download);
host_client->download = NULL; host_client->download = NULL;
} }
@ -1521,7 +1521,7 @@ void SV_NextUpload (void)
if (!host_client->upload) if (!host_client->upload)
{ {
host_client->upload = fopen(host_client->uploadfn, "wb"); host_client->upload = FS_OpenVFS(host_client->uploadfn, "wb", FS_GAME);
if (!host_client->upload) if (!host_client->upload)
{ {
Sys_Printf("Can't create %s\n", host_client->uploadfn); Sys_Printf("Can't create %s\n", host_client->uploadfn);
@ -1535,11 +1535,9 @@ void SV_NextUpload (void)
OutofBandPrintf(host_client->snap_from, "Server receiving %s from %d...\n", host_client->uploadfn, host_client->userid); OutofBandPrintf(host_client->snap_from, "Server receiving %s from %d...\n", host_client->uploadfn, host_client->userid);
} }
fwrite (net_message.data + msg_readcount, 1, size, host_client->upload); VFS_WRITE (host_client->upload, net_message.data + msg_readcount, size);
msg_readcount += size; msg_readcount += size;
Con_DPrintf ("UPLOAD: %d received\n", size);
if (percent != 100) if (percent != 100)
{ {
ClientReliableWrite_Begin (host_client, svc_stufftext, 8); ClientReliableWrite_Begin (host_client, svc_stufftext, 8);
@ -1547,7 +1545,7 @@ Con_DPrintf ("UPLOAD: %d received\n", size);
} }
else else
{ {
fclose (host_client->upload); VFS_CLOSE (host_client->upload);
host_client->upload = NULL; host_client->upload = NULL;
Con_Printf("%s upload completed.\n", host_client->uploadfn); Con_Printf("%s upload completed.\n", host_client->uploadfn);
@ -1582,6 +1580,7 @@ qboolean SV_AllowDownload (char *name)
extern cvar_t allow_download_pk3s; extern cvar_t allow_download_pk3s;
extern cvar_t allow_download_wads; extern cvar_t allow_download_wads;
extern cvar_t allow_download_root; extern cvar_t allow_download_root;
extern cvar_t allow_download_configs;
//allowed at all? //allowed at all?
if (!allow_download.value) if (!allow_download.value)
@ -1625,10 +1624,13 @@ qboolean SV_AllowDownload (char *name)
return !!allow_download_wads.value; return !!allow_download_wads.value;
//pk3s. //pk3s.
if (!strcmp(".pk3", COM_FileExtension(name))) if (!strcmp(".pk3", COM_FileExtension(name)) || !strcmp(".pak", COM_FileExtension(name)))
if (strnicmp(name, "pak", 3)) //don't give out q3 pk3 files. if (strnicmp(name, "pak", 3)) //don't give out q3 pk3 files.
return !!allow_download_pk3s.value; return !!allow_download_pk3s.value;
if (!strcmp(".cfg", COM_FileExtension(name)))
return !!allow_download_configs.value;
//root of gamedir //root of gamedir
if (!strchr(name, '/') && !allow_download_root.value) if (!strchr(name, '/') && !allow_download_root.value)
{ {
@ -1678,7 +1680,7 @@ void SV_BeginDownload_f(void)
if (host_client->download) if (host_client->download)
{ {
fclose (host_client->download); VFS_CLOSE (host_client->download);
host_client->download = NULL; host_client->download = NULL;
} }
@ -1690,7 +1692,7 @@ void SV_BeginDownload_f(void)
*p = (char)tolower(*p); *p = (char)tolower(*p);
} }
host_client->downloadsize = COM_FOpenFile (name, &host_client->download); host_client->download = FS_OpenVFS(name, "rb", FS_GAME);
host_client->downloadcount = 0; host_client->downloadcount = 0;
if (!host_client->download if (!host_client->download
@ -1700,7 +1702,7 @@ void SV_BeginDownload_f(void)
{ {
if (host_client->download) if (host_client->download)
{ {
fclose(host_client->download); VFS_CLOSE(host_client->download);
host_client->download = NULL; host_client->download = NULL;
} }
@ -1723,6 +1725,8 @@ void SV_BeginDownload_f(void)
return; return;
} }
host_client->downloadsize = VFS_GETLEN(host_client->download);
#ifdef PEXT_CHUNKEDDOWNLOADS #ifdef PEXT_CHUNKEDDOWNLOADS
if (host_client->fteprotocolextensions & PEXT_CHUNKEDDOWNLOADS) if (host_client->fteprotocolextensions & PEXT_CHUNKEDDOWNLOADS)
{ {

View file

@ -29,9 +29,10 @@
#pragma comment (lib, "botlib.lib") #pragma comment (lib, "botlib.lib")
#define FTE_GetBotLibAPI GetBotLibAPI #define FTE_GetBotLibAPI GetBotLibAPI
#else #else
#include <windows.h>
botlib_export_t *FTE_GetBotLibAPI( int apiVersion, botlib_import_t *import ) botlib_export_t *FTE_GetBotLibAPI( int apiVersion, botlib_import_t *import )
{ {
botlib_export_t *(*QDECL pGetBotLibAPI)( int apiVersion, botlib_import_t *import ); botlib_export_t *(QDECL *pGetBotLibAPI)( int apiVersion, botlib_import_t *import );
static HINSTANCE hmod; static HINSTANCE hmod;
if (!hmod) if (!hmod)