2
0
mirror of https://github.com/rehlds/rehlds.git synced 2025-01-16 00:28:20 +03:00

HLTV: Some fixes and small refactoring. (#466)

* HLTV: Some fixes and small refactoring.
Update README.md
This commit is contained in:
Dmitry Novikov 2017-05-09 16:43:15 +03:00 committed by GitHub
parent 3c05dad7a7
commit 7432df957c
7 changed files with 78 additions and 59 deletions

View File

@ -35,6 +35,7 @@ void BSPModel::Init(IBaseSystem *system)
m_currentLeaf = nullptr;
m_base = nullptr;
m_wadpath = nullptr;
m_IsMinimal = false;
memset(&m_model, 0, sizeof(m_model));
memset(m_novis, 0xFF, sizeof(m_novis));
@ -48,6 +49,7 @@ bool BSPModel::Load(const char *name, bool minimal)
return false;
}
m_IsMinimal = minimal;
return LoadFromBuffer(buffer, length, COM_SkipPath((char *)name));
}
@ -411,7 +413,6 @@ bool BSPModel::InPVS(vec_t *point)
void BSPModel::Clear()
{
#define FREE_FIELD(field) if (field) { free(field); }
FREE_FIELD(m_model.leafs);
FREE_FIELD(m_model.nodes);
FREE_FIELD(m_model.planes);
@ -437,6 +438,7 @@ void BSPModel::Clear()
}
FREE_FIELD(m_wadpath);
#undef FREE_FIELD
memset(&m_model, 0, sizeof(m_model));

View File

@ -175,13 +175,13 @@ void Server::SetGameDirectory(const char *defaultDir, const char *gameDir)
if (gameDir && _stricmp(gameDir, defaultDir) != 0)
{
sprintf(temp, "%s/%s", GetBaseDir(), gameDir);
sprintf(temp, "%s/%s", m_System->GetBaseDir(), gameDir);
m_FileSystem->AddSearchPath(temp, "GAME");
}
sprintf(temp, "%s/%s", GetBaseDir(), defaultDir);
sprintf(temp, "%s/%s", m_System->GetBaseDir(), defaultDir);
m_FileSystem->AddSearchPath(temp, "DEFAULTGAME");
m_FileSystem->AddSearchPath(GetBaseDir(), "ROOT");
m_FileSystem->AddSearchPath(m_System->GetBaseDir(), "ROOT");
}
void Server::ExecuteCommand(int commandID, char *commandLine)

View File

@ -955,7 +955,7 @@ void DemoPlayer::ExecuteDemoFileCommands(BitBuffer *stream)
{
switch (cmd)
{
case DEMO_STRINCMD:
case DEM_STRING:
{
char szCmdName[64];
stream->ReadBuf(sizeof(szCmdName), szCmdName);
@ -963,14 +963,14 @@ void DemoPlayer::ExecuteDemoFileCommands(BitBuffer *stream)
m_Engine->Cbuf_AddText("\n");
break;
}
case DEMO_CLIENTDATA:
case DEM_CLIENTDATA:
{
client_data_t cdat;
stream->ReadBuf(sizeof(cdat), &cdat);
m_Engine->DemoUpdateClientData(&cdat);
break;
}
case DEMO_EVENT:
case DEM_EVENT:
{
int flags = _LittleLong(stream->ReadLong());
int idx = _LittleLong(stream->ReadLong());
@ -982,7 +982,7 @@ void DemoPlayer::ExecuteDemoFileCommands(BitBuffer *stream)
m_Engine->CL_QueueEvent(flags, idx, delay, &eargs);
break;
}
case DEMO_WEAPONANIM:
case DEM_WEAPONANIM:
{
int anim = _LittleLong(stream->ReadLong());
int body = _LittleLong(stream->ReadLong());
@ -990,7 +990,7 @@ void DemoPlayer::ExecuteDemoFileCommands(BitBuffer *stream)
m_Engine->HudWeaponAnim(anim, body);
break;
}
case DEMO_PLAYSOUND:
case DEM_PLAYSOUND:
{
int channel = stream->ReadLong();
int sampleSize = stream->ReadLong();
@ -1007,7 +1007,7 @@ void DemoPlayer::ExecuteDemoFileCommands(BitBuffer *stream)
m_Engine->CL_DemoPlaySound(channel, sample, attenuation, volume, flags, pitch);
break;
}
case DEMO_DATA:
case DEM_PAYLOAD:
{
unsigned char data[32768];
memset(data, 0, sizeof(data));

View File

@ -133,16 +133,6 @@ protected:
void WriteSpawn(BitBuffer *stream);
void ReindexCommands();
void WriteCameraPath(DirectorCmd *, BitBuffer *stream);
enum DemoCmds {
DEMO_STRINCMD = 3,
DEMO_CLIENTDATA = 4,
DEMO_EVENT = 6,
DEMO_WEAPONANIM = 7,
DEMO_PLAYSOUND = 8,
DEMO_DATA = 9
};
void ExecuteDemoFileCommands(BitBuffer *stream);
private:

View File

@ -308,7 +308,7 @@ Lots of these commands are boolean switches, were 1 is meaning ON and 0 is respe
The console does auto-completion by hitting `TAB`.
All commands in the config file `hltv.cfg` are executed during startup.
Some parameters can only be set in the command line:
### Command-line parameters
<pre>
-port <n> - sets the HLTV proxy port that spectators connect to (default "27020" )
-ip <IP> - forces the proxy to use this IP on a multihomed host

View File

@ -260,21 +260,21 @@ bool DemoFile::StartRecording(char *newName)
}
memset(&m_demoHeader, 0, sizeof(m_demoHeader));
strcopy(m_demoHeader.szFileStamp, "HLDEMO");
strcpy(m_demoHeader.szFileStamp, "HLDEMO");
COM_FileBase(m_World->GetLevelName(), m_demoHeader.szMapName);
COM_FileBase(m_World->GetGameDir(), m_demoHeader.szDllDir);
m_demoHeader.mapCRC = 0;
m_demoHeader.nDemoProtocol = DEMO_VERSION;
m_demoHeader.nDemoProtocol = DEMO_PROTOCOL;
m_demoHeader.nNetProtocolVersion = PROTOCOL_VERSION;
m_demoHeader.nDirectoryOffset = 0;
m_FileSystem->Write(&m_demoHeader, sizeof(m_demoHeader), m_FileHandle);
memset(&m_loadEntry, 0, sizeof(m_loadEntry));
strcopy(m_loadEntry.szDescription, "LOADING");
strcpy(m_loadEntry.szDescription, "LOADING");
m_loadEntry.nEntryType = 0;
m_loadEntry.nEntryType = DEMO_STARTUP;
m_loadEntry.nOffset = m_FileSystem->Tell(m_FileHandle);
m_frameCount = 0;
@ -295,7 +295,8 @@ bool DemoFile::StartRecording(char *newName)
memset(&m_gameEntry, 0, sizeof(m_gameEntry));
_snprintf(m_gameEntry.szDescription, sizeof(m_gameEntry.szDescription), "Playback");
m_gameEntry.nEntryType = 1;
m_gameEntry.nEntryType = DEMO_NORMAL;
m_gameEntry.nOffset = m_FileSystem->Tell(m_FileHandle);
b = 2;
@ -353,7 +354,7 @@ bool DemoFile::LoadDemo(char *demoname)
return false;
}
if (m_demoHeader.nNetProtocolVersion != PROTOCOL_VERSION || m_demoHeader.nDemoProtocol != DEMO_VERSION) {
if (m_demoHeader.nNetProtocolVersion != PROTOCOL_VERSION || m_demoHeader.nDemoProtocol != DEMO_PROTOCOL) {
m_System->Printf("WARNING! %s has an outdated demo format.\n", m_FileName);
}
@ -419,7 +420,7 @@ void DemoFile::ReadDemoPacket(BitBuffer *demoData, demo_info_t *demoInfo)
return;
}
int msglen;
int msglen; // command length in bytes
unsigned char msgbuf[MAX_POSSIBLE_MSG];
float time;
unsigned char cmd;
@ -431,7 +432,7 @@ void DemoFile::ReadDemoPacket(BitBuffer *demoData, demo_info_t *demoInfo)
while (readNextCmd)
{
unsigned int curpos = m_FileSystem->Tell(m_FileHandle);
if (m_FileSystem->Read(&cmd, sizeof(unsigned char), m_FileHandle) != 1) {
if (m_FileSystem->Read(&cmd, sizeof(unsigned char), m_FileHandle) != sizeof(unsigned char)) {
StopPlayBack();
return;
}
@ -442,7 +443,7 @@ void DemoFile::ReadDemoPacket(BitBuffer *demoData, demo_info_t *demoInfo)
m_FileSystem->Read(&frame, sizeof(int), m_FileHandle);
frame = _LittleLong(frame);
if (cmd && cmd != 5) {
if (cmd && cmd != DEM_READ) {
m_nextReadTime = m_startTime + time;
}
@ -453,19 +454,18 @@ void DemoFile::ReadDemoPacket(BitBuffer *demoData, demo_info_t *demoInfo)
msglen = 0;
// TODO: Find out or guess the names of the opcode
switch (cmd)
{
case 2:
case DEM_START_TIME:
m_startTime = (float)m_System->GetTime();
break;
case 3:
msglen = 64;
case DEM_STRING:
msglen = sizeof(char [64]);
break;
case 4:
msglen = 32;
case DEM_CLIENTDATA:
msglen = sizeof(client_data_t);
break;
case 5:
case DEM_READ:
{
if (++m_CurrentEntry >= m_EntryNumber) {
StopPlayBack();
@ -477,23 +477,31 @@ void DemoFile::ReadDemoPacket(BitBuffer *demoData, demo_info_t *demoInfo)
}
break;
}
case 6:
msglen = 84;
case DEM_EVENT:
msglen = sizeof(int) // flags
+ sizeof(int) // idx
+ sizeof(float) // delay
+ sizeof(event_args_t); // eargs
break;
case 7:
msglen = 8;
case DEM_WEAPONANIM:
msglen = sizeof(int) // anim
+ sizeof(int); // body
break;
case 8:
case DEM_PLAYSOUND:
{
m_FileSystem->Read(&channel, sizeof(int), m_FileHandle);
channel = _LittleLong(channel);
m_FileSystem->Read(&sampleSize, sizeof(int), m_FileHandle);
sampleSize = _LittleLong(sampleSize);
msglen = sampleSize + 16;
msglen = sampleSize
+ sizeof(float) // attenuation
+ sizeof(float) // volume
+ sizeof(int) // flags
+ sizeof(int); // pitch
break;
}
case 9:
case DEM_PAYLOAD:
{
m_FileSystem->Read(&msglen, sizeof(int), m_FileHandle);
msglen = _LittleLong(msglen);
@ -512,11 +520,11 @@ void DemoFile::ReadDemoPacket(BitBuffer *demoData, demo_info_t *demoInfo)
switch (cmd)
{
case 8:
case DEM_PLAYSOUND:
demoData->WriteLong(channel);
demoData->WriteLong(sampleSize);
break;
case 9:
case DEM_PAYLOAD:
demoData->WriteLong(msglen);
break;
}
@ -529,7 +537,7 @@ void DemoFile::ReadDemoPacket(BitBuffer *demoData, demo_info_t *demoInfo)
ReadSequenceInfo();
int length;
if (m_FileSystem->Read(&length, sizeof(int), m_FileHandle) != 4) {
if (m_FileSystem->Read(&length, sizeof(int), m_FileHandle) != sizeof(int)) {
m_System->DPrintf("WARNING! DemoFile::ReadDemoPacket: Bad demo length.\n");
StopPlayBack();
return;

View File

@ -33,34 +33,52 @@
#include "usercmd.h"
#include "ref_params.h"
#include "event_args.h"
#include "common/ServerInfo.h"
#include "vmodes.h"
#include "cdll_int.h"
#define DEMO_VERSION 5
#define MAX_DEMO_ENTRY 92
const int MAX_DEMO_ENTRY = 92;
const int DEMO_PROTOCOL = 5;
const int DEMO_STARTUP = 0; // this lump contains startup info needed to spawn into the server
const int DEMO_NORMAL = 1; // this lump contains playback info of messages, etc., needed during playback.
enum DemoCmd {
DEM_UNKNOWN = 0,
DEM_NOREWIND, // startup message
DEM_START_TIME,
DEM_STRING,
DEM_CLIENTDATA,
DEM_READ,
DEM_EVENT,
DEM_WEAPONANIM,
DEM_PLAYSOUND,
DEM_PAYLOAD
};
typedef struct demoheader_s {
char szFileStamp[6];
int nDemoProtocol;
int nNetProtocolVersion;
char szMapName[260];
char szDllDir[260];
int nDemoProtocol; // should be DEMO_PROTOCOL
int nNetProtocolVersion; // should be PROTOCOL_VERSION
char szMapName[260]; // name of map
char szDllDir[260]; // name of game directory
CRC32_t mapCRC;
int nDirectoryOffset;
int nDirectoryOffset; // offset of Entry Directory.
} demoheader_t;
typedef struct demoentry_s {
int nEntryType;
int nEntryType; // DEMO_STARTUP or DEMO_NORMAL
char szDescription[64];
int nFlags;
int nCDTrack;
float fTrackTime;
int nFrames;
int nOffset;
int nFileLength;
float fTrackTime; // time of track
int nFrames; // # of frames in track
int nOffset; // file offset of track data
int nFileLength; // length of track
} demoentry_t;
typedef struct demo_info_s {
@ -110,6 +128,7 @@ private:
DEMO_PLAYING,
DEMO_RECORDING
};
int m_DemoState;
unsigned int m_frameCount;
FileHandle_t m_FileHandle;