From fa6bc4b98edecf62644c632ecdbf2b31fa9941c8 Mon Sep 17 00:00:00 2001 From: s1lent Date: Fri, 5 May 2017 21:54:31 +0700 Subject: [PATCH] HLTV: Fix crash and small refactoring. HLTV: Removed the obsolete filesystem_steam. --- rehlds/HLTV/Console/src/System.cpp | 6 -- rehlds/HLTV/Core/src/Server.cpp | 2 +- rehlds/HLTV/Core/src/Server.h | 2 +- rehlds/HLTV/Core/src/World.cpp | 90 +++++++++++++++--------------- rehlds/HLTV/Core/src/World.h | 4 +- rehlds/HLTV/README.md | 1 - 6 files changed, 49 insertions(+), 56 deletions(-) diff --git a/rehlds/HLTV/Console/src/System.cpp b/rehlds/HLTV/Console/src/System.cpp index e263c13..b5e3306 100644 --- a/rehlds/HLTV/Console/src/System.cpp +++ b/rehlds/HLTV/Console/src/System.cpp @@ -644,12 +644,6 @@ void System::Sleep(int msec) bool System::InitFileSystem() { char *filesystemmodule = STDIO_FILESYSTEM_LIB; -#ifdef _WIN32 - if (CheckParam("-steam")) { - filesystemmodule = STEAM_FILESYSTEM_LIB; - } -#endif // _WIN32 - m_FileSystemModule = Sys_LoadModule(filesystemmodule); if (!m_FileSystemModule) { diff --git a/rehlds/HLTV/Core/src/Server.cpp b/rehlds/HLTV/Core/src/Server.cpp index 24f257d..958d3b5 100644 --- a/rehlds/HLTV/Core/src/Server.cpp +++ b/rehlds/HLTV/Core/src/Server.cpp @@ -1508,7 +1508,7 @@ void Server::ParseDeltaPacketEntities() { int entnum = m_Instream->ReadShort(); if (entnum > MAX_PACKET_ENTITIES) { - m_System->Errorf("Server::ParsePacketEntities: entnum > MAX_PACKET_ENTITIES.\n"); + m_System->Errorf("Server::ParseDeltaPacketEntities: entnum > MAX_PACKET_ENTITIES.\n"); } m_Frame.delta = 0; diff --git a/rehlds/HLTV/Core/src/Server.h b/rehlds/HLTV/Core/src/Server.h index f238424..73cd7be 100644 --- a/rehlds/HLTV/Core/src/Server.h +++ b/rehlds/HLTV/Core/src/Server.h @@ -234,7 +234,7 @@ protected: char m_CDKey[32]; int m_AuthProtocol; frame_t m_Frame; - unsigned char m_EntityBuffer[87040]; + unsigned char m_EntityBuffer[MAX_PACKET_ENTITIES * sizeof(entity_state_t)]; int m_Rate; int m_UpdateRate; float m_Time; diff --git a/rehlds/HLTV/Core/src/World.cpp b/rehlds/HLTV/Core/src/World.cpp index 54e0669..52c9164 100644 --- a/rehlds/HLTV/Core/src/World.cpp +++ b/rehlds/HLTV/Core/src/World.cpp @@ -1060,65 +1060,65 @@ void World::ParseClientData(BitBuffer *stream, unsigned int deltaSeqNr, BitBuffe } } -int World::ParseDeltaHeader(BitBuffer *stream, bool *remove, bool *custom, int *numbase, bool *newbl, int *newblindex, bool full, int *offset) +int World::ParseDeltaHeader(BitBuffer *stream, bool &remove, bool &custom, int &numbase, bool &newbl, int &newblindex, bool full, int &offset) { int num; + bool isdelta, isnext; - *custom = false; - *newbl = false; + offset = 0; + custom = false; + newbl = false; if (full) { - *remove = false; - - if (stream->ReadBit() != 0) - { - num = *numbase + 1; - } - else if (stream->ReadBit() == 0) - { - num = stream->ReadBits(6) + *numbase; - } - else - { - num = stream->ReadBits(11); - } + isdelta = stream->ReadBit() ? true : false; + remove = false; } else { - *remove = stream->ReadBit() != 0; - - if (stream->ReadBit() == 0) - num = stream->ReadBits(6) + *numbase; - else - num = stream->ReadBits(11); + isdelta = false; + remove = stream->ReadBit() ? true : false; } - *numbase = num; - - if (!*remove) + if (isdelta) { - *custom = stream->ReadBit() != 0; + num = numbase + 1; + } + else + { + if (stream->ReadBit()) + { + num = stream->ReadBits(11); + } + else + { + int delta = stream->ReadBits(6); + num = delta + numbase; + } + } + + numbase = num; + + if (!remove) + { + custom = stream->ReadBit() ? true : false; + if (m_MaxInstanced_BaseLine) { - *newbl = stream->ReadBit() != 0; - if (*newbl) - *newblindex = stream->ReadBits(6); - } - else - { - *newbl = false; + isnext = stream->ReadBit() ? true : false; + if (isnext) + { + newbl = true; + newblindex = stream->ReadBits(6); + } } - if (!full || *newbl) + if (full && !newbl) { - *offset = 0; - } - else - { - *offset = stream->ReadBit(); - if (*offset) { - *offset = stream->ReadBits(6); + isnext = stream->ReadBit() ? true : false; + if (isnext) + { + offset = stream->ReadBits(6); } } } @@ -1498,7 +1498,7 @@ bool World::UncompressEntitiesFromStream(frame_t *frame, BitBuffer *stream, unsi while (stream->PeekBits(16)) { - newnum = ParseDeltaHeader(stream, &remove, &custom, &numbase, &newbl, &newblindex, false, &offset); + newnum = ParseDeltaHeader(stream, remove, custom, numbase, newbl, newblindex, false, offset); if ((unsigned)oldindex < deltaFrame.entitynum) oldnum = deltaEntity[oldindex].number; @@ -1634,7 +1634,7 @@ bool World::UncompressEntitiesFromStream(frame_t *frame, BitBuffer *stream) break; } - num = ParseDeltaHeader(stream, &remove, &custom, &numbase, &newbl, &newblindex, true, &offset); + num = ParseDeltaHeader(stream, remove, custom, numbase, newbl, newblindex, true, offset); if (num >= MAX_ENTITIES) { m_System->Errorf("World::GetUncompressedFrame: entity number %i >= MAX_ENTITIES\n", num); @@ -1662,7 +1662,7 @@ bool World::UncompressEntitiesFromStream(frame_t *frame, BitBuffer *stream) baseline = &m_BaseLines[num]; } - entities[num].entityType = custom ? ENTITY_BEAM : ENTITY_NORMAL; + entities[newindex].entityType = custom ? ENTITY_BEAM : ENTITY_NORMAL; delta_t *delta = GetDeltaEncoder(num, custom); m_Delta.ParseDelta(stream, (byte *)baseline, (byte *)&entities[newindex], delta); diff --git a/rehlds/HLTV/Core/src/World.h b/rehlds/HLTV/Core/src/World.h index 057c2c8..e7b1d4f 100644 --- a/rehlds/HLTV/Core/src/World.h +++ b/rehlds/HLTV/Core/src/World.h @@ -139,7 +139,7 @@ public: private: int CompressFrame(frame_t *from, BitBuffer *stream); - int ParseDeltaHeader(BitBuffer *stream, bool *remove, bool *custom, int *numbase, bool *newbl, int *newblindex, bool full, int *offset); + int ParseDeltaHeader(BitBuffer *stream, bool &remove, bool &custom, int &numbase, bool &newbl, int &newblindex, bool full, int &offset); void SetDirector(IDirector *director); void SetTimeScale(float scale); void SetGameGroupAddress(NetAddress *addr); @@ -244,7 +244,7 @@ protected: } player_info_t; player_info_t m_Players[MAX_CLIENTS]; - unsigned char m_EntityBuffer[87040]; + unsigned char m_EntityBuffer[MAX_PACKET_ENTITIES * sizeof(entity_state_t)]; entity_state_t m_BaseLines[MAX_ENTITIES]; int m_MaxBaseLines; diff --git a/rehlds/HLTV/README.md b/rehlds/HLTV/README.md index c774022..9c0e4a6 100644 --- a/rehlds/HLTV/README.md +++ b/rehlds/HLTV/README.md @@ -316,7 +316,6 @@ Some parameters can only be set in the command line: -maxfps - sets maximum system cycles per seconds (default "100") -highpriority - starts the HLTV proxy as high priority process -multicastttl - sets the Time-To-Live value for multicast packets --steam - proxy enables special Steam support -dev - developer mode