2006-02-24 04:48:15 +00:00
|
|
|
/*
|
|
|
|
** d_protocol.cpp
|
|
|
|
** Basic network packet creation routines and simple IFF parsing
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
2006-06-11 01:37:00 +00:00
|
|
|
** Copyright 1998-2006 Randy Heit
|
2006-02-24 04:48:15 +00:00
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "i_system.h"
|
|
|
|
#include "d_ticcmd.h"
|
|
|
|
#include "d_net.h"
|
|
|
|
#include "doomdef.h"
|
|
|
|
#include "doomstat.h"
|
|
|
|
#include "cmdlib.h"
|
2008-09-14 23:54:38 +00:00
|
|
|
#include "farchive.h"
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
|
2006-09-14 00:02:31 +00:00
|
|
|
char *ReadString (BYTE **stream)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
char *string = *((char **)stream);
|
|
|
|
|
|
|
|
*stream += strlen (string) + 1;
|
|
|
|
return copystring (string);
|
|
|
|
}
|
|
|
|
|
2009-02-20 22:28:48 +00:00
|
|
|
const char *ReadStringConst(BYTE **stream)
|
|
|
|
{
|
|
|
|
const char *string = *((const char **)stream);
|
|
|
|
*stream += strlen (string) + 1;
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
2006-09-14 00:02:31 +00:00
|
|
|
int ReadByte (BYTE **stream)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-09-14 00:02:31 +00:00
|
|
|
BYTE v = **stream;
|
2006-02-24 04:48:15 +00:00
|
|
|
*stream += 1;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2006-09-14 00:02:31 +00:00
|
|
|
int ReadWord (BYTE **stream)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
short v = (((*stream)[0]) << 8) | (((*stream)[1]));
|
|
|
|
*stream += 2;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2006-09-14 00:02:31 +00:00
|
|
|
int ReadLong (BYTE **stream)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
int v = (((*stream)[0]) << 24) | (((*stream)[1]) << 16) | (((*stream)[2]) << 8) | (((*stream)[3]));
|
|
|
|
*stream += 4;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2006-09-14 00:02:31 +00:00
|
|
|
float ReadFloat (BYTE **stream)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-05-26 04:38:22 +00:00
|
|
|
union
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
float f;
|
|
|
|
} fakeint;
|
|
|
|
fakeint.i = ReadLong (stream);
|
|
|
|
return fakeint.f;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2006-09-14 00:02:31 +00:00
|
|
|
void WriteString (const char *string, BYTE **stream)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
char *p = *((char **)stream);
|
|
|
|
|
|
|
|
while (*string) {
|
|
|
|
*p++ = *string++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*p++ = 0;
|
2006-09-14 00:02:31 +00:00
|
|
|
*stream = (BYTE *)p;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-14 00:02:31 +00:00
|
|
|
void WriteByte (BYTE v, BYTE **stream)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
**stream = v;
|
|
|
|
*stream += 1;
|
|
|
|
}
|
|
|
|
|
2006-09-14 00:02:31 +00:00
|
|
|
void WriteWord (short v, BYTE **stream)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
(*stream)[0] = v >> 8;
|
|
|
|
(*stream)[1] = v & 255;
|
|
|
|
*stream += 2;
|
|
|
|
}
|
|
|
|
|
2006-09-14 00:02:31 +00:00
|
|
|
void WriteLong (int v, BYTE **stream)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
(*stream)[0] = v >> 24;
|
|
|
|
(*stream)[1] = (v >> 16) & 255;
|
|
|
|
(*stream)[2] = (v >> 8) & 255;
|
|
|
|
(*stream)[3] = v & 255;
|
|
|
|
*stream += 4;
|
|
|
|
}
|
|
|
|
|
2006-09-14 00:02:31 +00:00
|
|
|
void WriteFloat (float v, BYTE **stream)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-05-26 04:38:22 +00:00
|
|
|
union
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
float f;
|
|
|
|
} fakeint;
|
|
|
|
fakeint.f = v;
|
|
|
|
WriteLong (fakeint.i, stream);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the number of bytes read
|
2006-09-14 00:02:31 +00:00
|
|
|
int UnpackUserCmd (usercmd_t *ucmd, const usercmd_t *basis, BYTE **stream)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-09-14 00:02:31 +00:00
|
|
|
BYTE *start = *stream;
|
|
|
|
BYTE flags;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
if (basis != NULL)
|
2006-05-04 03:49:46 +00:00
|
|
|
{
|
|
|
|
if (basis != ucmd)
|
|
|
|
{
|
|
|
|
memcpy (ucmd, basis, sizeof(usercmd_t));
|
|
|
|
}
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
else
|
2006-05-04 03:49:46 +00:00
|
|
|
{
|
2006-02-24 04:48:15 +00:00
|
|
|
memset (ucmd, 0, sizeof(usercmd_t));
|
2006-05-04 03:49:46 +00:00
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
flags = ReadByte (stream);
|
|
|
|
|
|
|
|
if (flags)
|
|
|
|
{
|
2008-09-13 02:55:45 +00:00
|
|
|
// We can support up to 29 buttons, using from 0 to 4 bytes to store them.
|
2006-02-24 04:48:15 +00:00
|
|
|
if (flags & UCMDF_BUTTONS)
|
2008-09-13 02:55:45 +00:00
|
|
|
{
|
|
|
|
DWORD buttons = ucmd->buttons;
|
|
|
|
BYTE in = ReadByte(stream);
|
|
|
|
|
|
|
|
buttons = (buttons & ~0x7F) | (in & 0x7F);
|
|
|
|
if (in & 0x80)
|
|
|
|
{
|
|
|
|
in = ReadByte(stream);
|
|
|
|
buttons = (buttons & ~(0x7F << 7)) | ((in & 0x7F) << 7);
|
|
|
|
if (in & 0x80)
|
|
|
|
{
|
|
|
|
in = ReadByte(stream);
|
|
|
|
buttons = (buttons & ~(0x7F << 14)) | ((in & 0x7F) << 14);
|
|
|
|
if (in & 0x80)
|
|
|
|
{
|
|
|
|
in = ReadByte(stream);
|
|
|
|
buttons = (buttons & ~(0xFF << 21)) | (in << 21);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ucmd->buttons = buttons;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
if (flags & UCMDF_PITCH)
|
|
|
|
ucmd->pitch = ReadWord (stream);
|
|
|
|
if (flags & UCMDF_YAW)
|
|
|
|
ucmd->yaw = ReadWord (stream);
|
|
|
|
if (flags & UCMDF_FORWARDMOVE)
|
|
|
|
ucmd->forwardmove = ReadWord (stream);
|
|
|
|
if (flags & UCMDF_SIDEMOVE)
|
|
|
|
ucmd->sidemove = ReadWord (stream);
|
|
|
|
if (flags & UCMDF_UPMOVE)
|
|
|
|
ucmd->upmove = ReadWord (stream);
|
|
|
|
if (flags & UCMDF_ROLL)
|
|
|
|
ucmd->roll = ReadWord (stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
return *stream - start;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the number of bytes written
|
2006-09-14 00:02:31 +00:00
|
|
|
int PackUserCmd (const usercmd_t *ucmd, const usercmd_t *basis, BYTE **stream)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-09-14 00:02:31 +00:00
|
|
|
BYTE flags = 0;
|
|
|
|
BYTE *temp = *stream;
|
|
|
|
BYTE *start = *stream;
|
2006-02-24 04:48:15 +00:00
|
|
|
usercmd_t blank;
|
2008-09-13 02:55:45 +00:00
|
|
|
DWORD buttons_changed;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
if (basis == NULL)
|
|
|
|
{
|
|
|
|
memset (&blank, 0, sizeof(blank));
|
|
|
|
basis = ␣
|
|
|
|
}
|
|
|
|
|
|
|
|
WriteByte (0, stream); // Make room for the packing bits
|
|
|
|
|
2008-09-13 02:55:45 +00:00
|
|
|
buttons_changed = ucmd->buttons ^ basis->buttons;
|
|
|
|
if (buttons_changed != 0)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-09-13 02:55:45 +00:00
|
|
|
BYTE bytes[4] = { ucmd->buttons & 0x7F,
|
|
|
|
(ucmd->buttons >> 7) & 0x7F,
|
|
|
|
(ucmd->buttons >> 14) & 0x7F,
|
|
|
|
(ucmd->buttons >> 21) & 0xFF };
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
flags |= UCMDF_BUTTONS;
|
2008-09-13 02:55:45 +00:00
|
|
|
|
|
|
|
if (buttons_changed & 0xFFFFFF80)
|
|
|
|
{
|
|
|
|
bytes[0] |= 0x80;
|
|
|
|
if (buttons_changed & 0xFFFFC000)
|
|
|
|
{
|
|
|
|
bytes[1] |= 0x80;
|
|
|
|
if (buttons_changed & 0xFFE00000)
|
|
|
|
{
|
|
|
|
bytes[2] |= 0x80;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WriteByte (bytes[0], stream);
|
|
|
|
if (bytes[0] & 0x80)
|
|
|
|
{
|
|
|
|
WriteByte (bytes[1], stream);
|
|
|
|
if (bytes[1] & 0x80)
|
|
|
|
{
|
|
|
|
WriteByte (bytes[2], stream);
|
|
|
|
if (bytes[2] & 0x80)
|
|
|
|
{
|
|
|
|
WriteByte (bytes[3], stream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
if (ucmd->pitch != basis->pitch)
|
|
|
|
{
|
|
|
|
flags |= UCMDF_PITCH;
|
|
|
|
WriteWord (ucmd->pitch, stream);
|
|
|
|
}
|
|
|
|
if (ucmd->yaw != basis->yaw)
|
|
|
|
{
|
|
|
|
flags |= UCMDF_YAW;
|
|
|
|
WriteWord (ucmd->yaw, stream);
|
|
|
|
}
|
|
|
|
if (ucmd->forwardmove != basis->forwardmove)
|
|
|
|
{
|
|
|
|
flags |= UCMDF_FORWARDMOVE;
|
|
|
|
WriteWord (ucmd->forwardmove, stream);
|
|
|
|
}
|
|
|
|
if (ucmd->sidemove != basis->sidemove)
|
|
|
|
{
|
|
|
|
flags |= UCMDF_SIDEMOVE;
|
|
|
|
WriteWord (ucmd->sidemove, stream);
|
|
|
|
}
|
|
|
|
if (ucmd->upmove != basis->upmove)
|
|
|
|
{
|
|
|
|
flags |= UCMDF_UPMOVE;
|
|
|
|
WriteWord (ucmd->upmove, stream);
|
|
|
|
}
|
|
|
|
if (ucmd->roll != basis->roll)
|
|
|
|
{
|
|
|
|
flags |= UCMDF_ROLL;
|
|
|
|
WriteWord (ucmd->roll, stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write the packing bits
|
|
|
|
WriteByte (flags, &temp);
|
|
|
|
|
|
|
|
return *stream - start;
|
|
|
|
}
|
|
|
|
|
2008-09-14 23:54:38 +00:00
|
|
|
FArchive &operator<< (FArchive &arc, ticcmd_t &cmd)
|
|
|
|
{
|
|
|
|
return arc << cmd.consistancy << cmd.ucmd;
|
|
|
|
}
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
FArchive &operator<< (FArchive &arc, usercmd_t &cmd)
|
|
|
|
{
|
2006-09-14 00:02:31 +00:00
|
|
|
BYTE bytes[256];
|
|
|
|
BYTE *stream = bytes;
|
2006-02-24 04:48:15 +00:00
|
|
|
if (arc.IsStoring ())
|
|
|
|
{
|
|
|
|
BYTE len = PackUserCmd (&cmd, NULL, &stream);
|
|
|
|
arc << len;
|
|
|
|
arc.Write (bytes, len);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BYTE len;
|
|
|
|
arc << len;
|
|
|
|
arc.Read (bytes, len);
|
|
|
|
UnpackUserCmd (&cmd, NULL, &stream);
|
|
|
|
}
|
|
|
|
return arc;
|
|
|
|
}
|
|
|
|
|
2006-09-14 00:02:31 +00:00
|
|
|
int WriteUserCmdMessage (usercmd_t *ucmd, const usercmd_t *basis, BYTE **stream)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
if (basis == NULL)
|
|
|
|
{
|
|
|
|
if (ucmd->buttons != 0 ||
|
|
|
|
ucmd->pitch != 0 ||
|
|
|
|
ucmd->yaw != 0 ||
|
|
|
|
ucmd->forwardmove != 0 ||
|
|
|
|
ucmd->sidemove != 0 ||
|
|
|
|
ucmd->upmove != 0 ||
|
|
|
|
ucmd->roll != 0)
|
|
|
|
{
|
|
|
|
WriteByte (DEM_USERCMD, stream);
|
|
|
|
return PackUserCmd (ucmd, basis, stream) + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (ucmd->buttons != basis->buttons ||
|
|
|
|
ucmd->pitch != basis->pitch ||
|
|
|
|
ucmd->yaw != basis->yaw ||
|
|
|
|
ucmd->forwardmove != basis->forwardmove ||
|
|
|
|
ucmd->sidemove != basis->sidemove ||
|
|
|
|
ucmd->upmove != basis->upmove ||
|
|
|
|
ucmd->roll != basis->roll)
|
|
|
|
{
|
|
|
|
WriteByte (DEM_USERCMD, stream);
|
|
|
|
return PackUserCmd (ucmd, basis, stream) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
WriteByte (DEM_EMPTYUSERCMD, stream);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-14 00:02:31 +00:00
|
|
|
int SkipTicCmd (BYTE **stream, int count)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
int i, skip;
|
2006-09-14 00:02:31 +00:00
|
|
|
BYTE *flow = *stream;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
for (i = count; i > 0; i--)
|
|
|
|
{
|
|
|
|
bool moreticdata = true;
|
|
|
|
|
|
|
|
flow += 2; // Skip consistancy marker
|
|
|
|
while (moreticdata)
|
|
|
|
{
|
2006-09-14 00:02:31 +00:00
|
|
|
BYTE type = *flow++;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
if (type == DEM_USERCMD)
|
|
|
|
{
|
|
|
|
moreticdata = false;
|
|
|
|
skip = 1;
|
|
|
|
if (*flow & UCMDF_PITCH) skip += 2;
|
|
|
|
if (*flow & UCMDF_YAW) skip += 2;
|
|
|
|
if (*flow & UCMDF_FORWARDMOVE) skip += 2;
|
|
|
|
if (*flow & UCMDF_SIDEMOVE) skip += 2;
|
|
|
|
if (*flow & UCMDF_UPMOVE) skip += 2;
|
|
|
|
if (*flow & UCMDF_ROLL) skip += 2;
|
2008-09-13 02:55:45 +00:00
|
|
|
if (*flow & UCMDF_BUTTONS)
|
|
|
|
{
|
|
|
|
if (*++flow & 0x80)
|
|
|
|
{
|
|
|
|
if (*++flow & 0x80)
|
|
|
|
{
|
|
|
|
if (*++flow & 0x80)
|
|
|
|
{
|
|
|
|
++flow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
flow += skip;
|
|
|
|
}
|
|
|
|
else if (type == DEM_EMPTYUSERCMD)
|
|
|
|
{
|
|
|
|
moreticdata = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Net_SkipCommand (type, &flow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
skip = flow - *stream;
|
|
|
|
*stream = flow;
|
|
|
|
|
|
|
|
return skip;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
extern short consistancy[MAXPLAYERS][BACKUPTICS];
|
2006-09-14 00:02:31 +00:00
|
|
|
void ReadTicCmd (BYTE **stream, int player, int tic)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
int type;
|
2006-09-14 00:02:31 +00:00
|
|
|
BYTE *start;
|
2006-02-24 04:48:15 +00:00
|
|
|
ticcmd_t *tcmd;
|
|
|
|
|
|
|
|
int ticmod = tic % BACKUPTICS;
|
|
|
|
|
|
|
|
tcmd = &netcmds[player][ticmod];
|
|
|
|
tcmd->consistancy = ReadWord (stream);
|
|
|
|
|
|
|
|
start = *stream;
|
|
|
|
|
|
|
|
while ((type = ReadByte (stream)) != DEM_USERCMD && type != DEM_EMPTYUSERCMD)
|
|
|
|
Net_SkipCommand (type, stream);
|
|
|
|
|
|
|
|
NetSpecs[player][ticmod].SetData (start, *stream - start - 1);
|
|
|
|
|
|
|
|
if (type == DEM_USERCMD)
|
|
|
|
{
|
|
|
|
UnpackUserCmd (&tcmd->ucmd,
|
|
|
|
tic ? &netcmds[player][(tic-1)%BACKUPTICS].ucmd : NULL, stream);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (tic)
|
|
|
|
{
|
|
|
|
memcpy (&tcmd->ucmd, &netcmds[player][(tic-1)%BACKUPTICS].ucmd, sizeof(tcmd->ucmd));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memset (&tcmd->ucmd, 0, sizeof(tcmd->ucmd));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (player==consoleplayer&&tic>BACKUPTICS)
|
|
|
|
assert(consistancy[player][ticmod] == tcmd->consistancy);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RunNetSpecs (int player, int buf)
|
|
|
|
{
|
2006-09-14 00:02:31 +00:00
|
|
|
BYTE *stream;
|
2006-02-24 04:48:15 +00:00
|
|
|
int len;
|
|
|
|
|
|
|
|
if (gametic % ticdup == 0)
|
|
|
|
{
|
|
|
|
stream = NetSpecs[player][buf].GetData (&len);
|
|
|
|
if (stream)
|
|
|
|
{
|
2006-09-14 00:02:31 +00:00
|
|
|
BYTE *end = stream + len;
|
2006-02-24 04:48:15 +00:00
|
|
|
while (stream < end)
|
|
|
|
{
|
|
|
|
int type = ReadByte (&stream);
|
|
|
|
Net_DoCommand (type, &stream, player);
|
|
|
|
}
|
|
|
|
if (!demorecording)
|
|
|
|
NetSpecs[player][buf].SetData (NULL, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-14 00:02:31 +00:00
|
|
|
BYTE *lenspot;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
// Write the header of an IFF chunk and leave space
|
|
|
|
// for the length field.
|
2006-09-14 00:02:31 +00:00
|
|
|
void StartChunk (int id, BYTE **stream)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
WriteLong (id, stream);
|
|
|
|
lenspot = *stream;
|
|
|
|
*stream += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write the length field for the chunk and insert
|
|
|
|
// pad byte if the chunk is odd-sized.
|
2006-09-14 00:02:31 +00:00
|
|
|
void FinishChunk (BYTE **stream)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (!lenspot)
|
|
|
|
return;
|
|
|
|
|
|
|
|
len = *stream - lenspot - 4;
|
|
|
|
WriteLong (len, &lenspot);
|
|
|
|
if (len & 1)
|
|
|
|
WriteByte (0, stream);
|
|
|
|
|
|
|
|
lenspot = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skip past an unknown chunk. *stream should be
|
|
|
|
// pointing to the chunk's length field.
|
2006-09-14 00:02:31 +00:00
|
|
|
void SkipChunk (BYTE **stream)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = ReadLong (stream);
|
|
|
|
stream += len + (len & 1);
|
|
|
|
}
|