From fb55f65f8f10dfaf093b99b8055d204888af0e85 Mon Sep 17 00:00:00 2001 From: divverent Date: Sun, 24 Aug 2008 10:44:50 +0000 Subject: [PATCH] fix Sajt's errors (in Visual Studio, I assume) in a better way - by changing the variable types, not casting. Also, only record one instance of the same csprogs into the demo. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8472 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_demo.c | 8 +++++--- client.h | 6 ++++-- csprogs.c | 36 +++++++++++++++++++++--------------- csprogs.h | 2 +- 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/cl_demo.c b/cl_demo.c index bffb2656..5be4e808 100644 --- a/cl_demo.c +++ b/cl_demo.c @@ -127,7 +127,7 @@ Dumps the current demo to a buffer, and resets the demo to its starting point. Used to insert csprogs.dat files as a download to the beginning of a demo file. ==================== */ -void CL_CutDemo (void **buf, fs_offset_t *filesize) +void CL_CutDemo (unsigned char **buf, fs_offset_t *filesize) { *buf = NULL; *filesize = 0; @@ -150,7 +150,7 @@ Adds the cut stuff back to the demo. Also frees the buffer. Used to insert csprogs.dat files as a download to the beginning of a demo file. ==================== */ -void CL_PasteDemo (void **buf, fs_offset_t *filesize) +void CL_PasteDemo (unsigned char **buf, fs_offset_t *filesize) { fs_offset_t startoffset = 0; @@ -163,7 +163,7 @@ void CL_PasteDemo (void **buf, fs_offset_t *filesize) if(startoffset < *filesize) ++startoffset; - FS_Write(cls.demofile, (char*)*buf + startoffset, *filesize - startoffset); + FS_Write(cls.demofile, *buf + startoffset, *filesize - startoffset); Mem_Free(*buf); *buf = NULL; @@ -377,6 +377,8 @@ void CL_Record_f (void) FS_Printf(cls.demofile, "%i\n", cls.forcetrack); cls.demorecording = true; + cls.demo_lastcsprogssize = -1; + cls.demo_lastcsprogscrc = -1; } diff --git a/client.h b/client.h index 6d032f34..d5da4864 100644 --- a/client.h +++ b/client.h @@ -523,6 +523,8 @@ typedef struct client_static_s // demo recording info must be here, because record is started before // entering a map (and clearing client_state_t) qboolean demorecording; + fs_offset_t demo_lastcsprogssize; + int demo_lastcsprogscrc; qboolean demoplayback; qboolean timedemo; // -1 = use normal cd track @@ -1214,8 +1216,8 @@ void CL_StopPlayback(void); void CL_ReadDemoMessage(void); void CL_WriteDemoMessage(sizebuf_t *mesage); -void CL_CutDemo(void **buf, fs_offset_t *filesize); -void CL_PasteDemo(void **buf, fs_offset_t *filesize); +void CL_CutDemo(unsigned char **buf, fs_offset_t *filesize); +void CL_PasteDemo(unsigned char **buf, fs_offset_t *filesize); void CL_NextDemo(void); void CL_Stop_f(void); diff --git a/csprogs.c b/csprogs.c index 4b421f3c..299e914f 100644 --- a/csprogs.c +++ b/csprogs.c @@ -666,7 +666,7 @@ void Cmd_ClearCsqcFuncs (void); // returns true if the packet is valid, false if end of file is reached // used for dumping the CSQC download into demo files -qboolean MakeDownloadPacket(const char *filename, void *data, unsigned long len, int crc, int cnt, sizebuf_t *buf, int protocol) +qboolean MakeDownloadPacket(const char *filename, unsigned char *data, unsigned long len, int crc, int cnt, sizebuf_t *buf, int protocol) { int packetsize = buf->maxsize - 7; // byte short long int npackets = (len + packetsize - 1) / (packetsize); @@ -691,7 +691,7 @@ qboolean MakeDownloadPacket(const char *filename, void *data, unsigned long len, MSG_WriteByte(buf, svc_downloaddata); MSG_WriteLong(buf, thispacketoffset); MSG_WriteShort(buf, thispacketsize); - SZ_Write(buf, (char*)data + thispacketoffset, thispacketsize); + SZ_Write(buf, data + thispacketoffset, thispacketsize); return true; } @@ -810,19 +810,25 @@ void CL_VM_Init (void) if(cls.demorecording) { - int i; - char buf[NET_MAXMESSAGE]; - sizebuf_t sb; - void *demobuf; fs_offset_t demofilesize; - - sb.data = (void *) buf; - sb.maxsize = sizeof(buf); - i = 0; - - CL_CutDemo(&demobuf, &demofilesize); - while(MakeDownloadPacket(csprogsfn, csprogsdata, csprogsdatasize, csprogsdatacrc, i++, &sb, cls.protocol)) - CL_WriteDemoMessage(&sb); - CL_PasteDemo(&demobuf, &demofilesize); + if(cls.demo_lastcsprogssize != csprogsdatasize || cls.demo_lastcsprogscrc != csprogsdatacrc) + { + int i; + char buf[NET_MAXMESSAGE]; + sizebuf_t sb; + unsigned char *demobuf; fs_offset_t demofilesize; + + sb.data = (void *) buf; + sb.maxsize = sizeof(buf); + i = 0; + + CL_CutDemo(&demobuf, &demofilesize); + while(MakeDownloadPacket(csprogsfn, csprogsdata, csprogsdatasize, csprogsdatacrc, i++, &sb, cls.protocol)) + CL_WriteDemoMessage(&sb); + CL_PasteDemo(&demobuf, &demofilesize); + + cls.demo_lastcsprogssize = csprogsdatasize; + cls.demo_lastcsprogscrc = csprogsdatacrc; + } } Mem_Free(csprogsdata); diff --git a/csprogs.h b/csprogs.h index 25fabd91..24856dd7 100644 --- a/csprogs.h +++ b/csprogs.h @@ -53,6 +53,6 @@ extern cvar_t csqc_progname; //[515]: csqc crc check and right csprogs name acco extern cvar_t csqc_progcrc; extern cvar_t csqc_progsize; -qboolean MakeDownloadPacket(const char *filename, void *data, unsigned long len, int crc, int cnt, sizebuf_t *buf, int protocol); +qboolean MakeDownloadPacket(const char *filename, unsigned char *data, unsigned long len, int crc, int cnt, sizebuf_t *buf, int protocol); #endif -- 2.39.2