2
0
mirror of https://github.com/FWGS/hlsdk-xash3d synced 2024-11-22 18:05:23 +01:00
hlsdk-xash3d/cl_dll/demo.cpp

103 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.
*
****/
2016-07-03 15:39:55 +02:00
2016-06-04 15:24:23 +02:00
#include "hud.h"
#include "cl_util.h"
#include "demo.h"
#include "demo_api.h"
#include <memory.h>
int g_demosniper = 0;
int g_demosniperdamage = 0;
float g_demosniperorg[3];
float g_demosniperangles[3];
float g_demozoom;
// FIXME: There should be buffer helper functions to avoid all of the *(int *)& crap.
extern "C"
{
void DLLEXPORT Demo_ReadBuffer( int size, unsigned char *buffer );
}
/*
=====================
Demo_WriteBuffer
Write some data to the demo stream
=====================
*/
void Demo_WriteBuffer( int type, int size, unsigned char *buffer )
{
int pos = 0;
2016-07-03 15:39:55 +02:00
unsigned char buf[32 * 1024];
*(int *)&buf[pos] = type;
pos += sizeof(int);
2016-06-04 15:24:23 +02:00
memcpy( &buf[pos], buffer, size );
// Write full buffer out
2016-07-03 15:39:55 +02:00
gEngfuncs.pDemoAPI->WriteBuffer( size + sizeof(int), buf );
2016-06-04 15:24:23 +02:00
}
/*
=====================
Demo_ReadBuffer
Engine wants us to parse some data from the demo stream
=====================
*/
void DLLEXPORT Demo_ReadBuffer( int size, unsigned char *buffer )
{
int type;
int i = 0;
2016-07-03 15:39:55 +02:00
type = *(int *)buffer;
i += sizeof(int);
switch( type )
2016-06-04 15:24:23 +02:00
{
case TYPE_SNIPERDOT:
2016-07-03 15:39:55 +02:00
g_demosniper = *(int *)&buffer[i];
i += sizeof(int);
2016-06-04 15:24:23 +02:00
2016-07-03 15:39:55 +02:00
if( g_demosniper )
2016-06-04 15:24:23 +02:00
{
2016-07-03 15:39:55 +02:00
g_demosniperdamage = *(int *)&buffer[i];
i += sizeof(int);
2016-06-04 15:24:23 +02:00
2016-07-03 15:39:55 +02:00
g_demosniperangles[0] = *(float *)&buffer[i];
i += sizeof(float);
g_demosniperangles[1] = *(float *)&buffer[i];
i += sizeof(float);
g_demosniperangles[2] = *(float *)&buffer[i];
i += sizeof(float);
g_demosniperorg[0] = *(float *)&buffer[i];
i += sizeof(float);
g_demosniperorg[1] = *(float *)&buffer[i];
i += sizeof(float);
g_demosniperorg[2] = *(float *)&buffer[i];
i += sizeof(float);
2016-06-04 15:24:23 +02:00
}
break;
case TYPE_ZOOM:
2016-07-03 15:39:55 +02:00
g_demozoom = *(float *)&buffer[i];
i += sizeof(float);
2016-06-04 15:24:23 +02:00
break;
default:
gEngfuncs.Con_DPrintf( "Unknown demo buffer type, skipping.\n" );
break;
}
}