Portable Half-Life SDK. GoldSource and Xash3D. Crossplatform.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
2.3 KiB

9 years ago
/***
*
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* All Rights Reserved.
*
* Use, distribution, and modification of this source code and/or resulting
* object code is restricted to non-commercial enhancements to products from
* Valve LLC. All other use, distribution, or modification is prohibited
* without written permission from Valve LLC.
*
****/
//
// parsemsg.cpp
//
9 years ago
9 years ago
typedef unsigned char byte;
#define true 1
static byte *gpBuf;
static int giSize;
static int giRead;
static int giBadRead;
void BEGIN_READ( void *buf, int size )
{
giRead = 0;
giBadRead = 0;
giSize = size;
gpBuf = (byte*)buf;
}
int READ_CHAR( void )
{
9 years ago
int c;
if( giRead + 1 > giSize )
9 years ago
{
giBadRead = true;
return -1;
}
9 years ago
9 years ago
c = (signed char)gpBuf[giRead];
giRead++;
9 years ago
9 years ago
return c;
}
int READ_BYTE( void )
{
9 years ago
int c;
if( giRead + 1 > giSize )
9 years ago
{
giBadRead = true;
return -1;
}
c = (unsigned char)gpBuf[giRead];
giRead++;
return c;
}
int READ_SHORT( void )
{
9 years ago
int c;
if( giRead + 2 > giSize )
9 years ago
{
giBadRead = true;
return -1;
}
9 years ago
c = (short)( gpBuf[giRead] + ( gpBuf[giRead + 1] << 8 ) );
9 years ago
giRead += 2;
9 years ago
9 years ago
return c;
}
int READ_WORD( void )
{
return READ_SHORT();
}
int READ_LONG( void )
{
9 years ago
int c;
if( giRead + 4 > giSize )
9 years ago
{
giBadRead = true;
return -1;
}
9 years ago
c = gpBuf[giRead] + ( gpBuf[giRead + 1] << 8 ) + ( gpBuf[giRead + 2] << 16 ) + ( gpBuf[giRead + 3] << 24 );
9 years ago
giRead += 4;
9 years ago
9 years ago
return c;
}
float READ_FLOAT( void )
{
union
{
9 years ago
byte b[4];
float f;
int l;
9 years ago
} dat;
9 years ago
9 years ago
dat.b[0] = gpBuf[giRead];
9 years ago
dat.b[1] = gpBuf[giRead + 1];
dat.b[2] = gpBuf[giRead + 2];
dat.b[3] = gpBuf[giRead + 3];
9 years ago
giRead += 4;
9 years ago
//dat.l = LittleLong( dat.l );
return dat.f;
9 years ago
}
char* READ_STRING( void )
{
9 years ago
static char string[2048];
int l, c;
9 years ago
string[0] = 0;
l = 0;
do
{
9 years ago
if( giRead+1 > giSize )
9 years ago
break; // no more characters
c = READ_BYTE();
9 years ago
if( c == -1 || c == 0 )
9 years ago
break;
string[l] = c;
l++;
9 years ago
}while( l < sizeof(string) - 1 );
9 years ago
string[l] = 0;
9 years ago
9 years ago
return string;
}
float READ_COORD( void )
{
9 years ago
return (float)( READ_SHORT() * ( 1.0 / 8 ) );
9 years ago
}
float READ_ANGLE( void )
{
9 years ago
return (float)( READ_CHAR() * ( 360.0 / 256 ) );
9 years ago
}
float READ_HIRESANGLE( void )
{
9 years ago
return (float)( READ_SHORT() * ( 360.0 / 65536 ) );
9 years ago
}