2
0
mirror of https://github.com/FWGS/hlsdk-xash3d synced 2024-12-01 06:20:56 +01:00
hlsdk-xash3d/cl_dll/parsemsg.cpp

165 lines
2.3 KiB
C++
Raw Normal View History

2016-06-04 15:24:23 +02:00
/***
*
* 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
//
2016-07-03 15:39:55 +02:00
2016-06-04 15:24:23 +02:00
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 )
{
2016-07-03 15:39:55 +02:00
int c;
if( giRead + 1 > giSize )
2016-06-04 15:24:23 +02:00
{
giBadRead = true;
return -1;
}
2016-07-03 15:39:55 +02:00
2016-06-04 15:24:23 +02:00
c = (signed char)gpBuf[giRead];
giRead++;
2016-07-03 15:39:55 +02:00
2016-06-04 15:24:23 +02:00
return c;
}
int READ_BYTE( void )
{
2016-07-03 15:39:55 +02:00
int c;
if( giRead + 1 > giSize )
2016-06-04 15:24:23 +02:00
{
giBadRead = true;
return -1;
}
c = (unsigned char)gpBuf[giRead];
giRead++;
return c;
}
int READ_SHORT( void )
{
2016-07-03 15:39:55 +02:00
int c;
if( giRead + 2 > giSize )
2016-06-04 15:24:23 +02:00
{
giBadRead = true;
return -1;
}
2016-07-03 15:39:55 +02:00
c = (short)( gpBuf[giRead] + ( gpBuf[giRead + 1] << 8 ) );
2016-06-04 15:24:23 +02:00
giRead += 2;
2016-07-03 15:39:55 +02:00
2016-06-04 15:24:23 +02:00
return c;
}
int READ_WORD( void )
{
return READ_SHORT();
}
int READ_LONG( void )
{
2016-07-03 15:39:55 +02:00
int c;
if( giRead + 4 > giSize )
2016-06-04 15:24:23 +02:00
{
giBadRead = true;
return -1;
}
2016-07-03 15:39:55 +02:00
c = gpBuf[giRead] + ( gpBuf[giRead + 1] << 8 ) + ( gpBuf[giRead + 2] << 16 ) + ( gpBuf[giRead + 3] << 24 );
2016-06-04 15:24:23 +02:00
giRead += 4;
2016-07-03 15:39:55 +02:00
2016-06-04 15:24:23 +02:00
return c;
}
float READ_FLOAT( void )
{
union
{
2016-07-03 15:39:55 +02:00
byte b[4];
float f;
int l;
2016-06-04 15:24:23 +02:00
} dat;
2016-07-03 15:39:55 +02:00
2016-06-04 15:24:23 +02:00
dat.b[0] = gpBuf[giRead];
2016-07-03 15:39:55 +02:00
dat.b[1] = gpBuf[giRead + 1];
dat.b[2] = gpBuf[giRead + 2];
dat.b[3] = gpBuf[giRead + 3];
2016-06-04 15:24:23 +02:00
giRead += 4;
2016-07-03 15:39:55 +02:00
//dat.l = LittleLong( dat.l );
return dat.f;
2016-06-04 15:24:23 +02:00
}
char* READ_STRING( void )
{
2016-07-03 15:39:55 +02:00
static char string[2048];
int l, c;
2016-06-04 15:24:23 +02:00
string[0] = 0;
l = 0;
do
{
2016-07-03 15:39:55 +02:00
if( giRead+1 > giSize )
2016-06-04 15:24:23 +02:00
break; // no more characters
c = READ_BYTE();
2016-07-03 15:39:55 +02:00
if( c == -1 || c == 0 )
2016-06-04 15:24:23 +02:00
break;
string[l] = c;
l++;
2016-07-03 15:39:55 +02:00
}while( l < sizeof(string) - 1 );
2016-06-04 15:24:23 +02:00
string[l] = 0;
2016-07-03 15:39:55 +02:00
2016-06-04 15:24:23 +02:00
return string;
}
float READ_COORD( void )
{
2016-07-03 15:39:55 +02:00
return (float)( READ_SHORT() * ( 1.0 / 8 ) );
2016-06-04 15:24:23 +02:00
}
float READ_ANGLE( void )
{
2016-07-03 15:39:55 +02:00
return (float)( READ_CHAR() * ( 360.0 / 256 ) );
2016-06-04 15:24:23 +02:00
}
float READ_HIRESANGLE( void )
{
2016-07-03 15:39:55 +02:00
return (float)( READ_SHORT() * ( 360.0 / 65536 ) );
2016-06-04 15:24:23 +02:00
}