Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions rehlds/HLTV/Core/src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1727,6 +1727,12 @@ char *Server::GetType()
{
return SERVER_INTERFACE_VERSION;
}
#ifdef HLTV_FIXES
void Server::SetWorld(IWorld* world)
{
m_World = world;
}
#endif

IWorld *Server::GetWorld()
{
Expand Down
1 change: 1 addition & 0 deletions rehlds/HLTV/Core/src/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class Server: public IServer, public BaseSystemModule {
EXT_FUNC char *GetHostName();
EXT_FUNC float GetPacketLoss();
EXT_FUNC int GetProtocol();
EXT_FUNC void SetWorld(IWorld* world);

private:
public:
Expand Down
9 changes: 8 additions & 1 deletion rehlds/HLTV/Core/src/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,14 @@ bool World::AddSignonData(unsigned char type, unsigned char *data, int size)
return m_SignonData.IsOverflowed();
}


bool World::AddSignonData(unsigned char* data, int size)
{
m_SignonData.WriteBuf(data, size);

return m_SignonData.IsOverflowed();
}

int World::FindUserMsgByName(char *name)
{
for (UserMsg *pList = m_ClientUserMsgs; pList; pList = pList->next)
Expand Down Expand Up @@ -2376,6 +2384,5 @@ delta_t *World::GetEntityDelta() const {
delta_t *World::GetWeaponDelta() const {
return Delta::m_WeaponDelta;
}

EXPOSE_INTERFACE_FN(CreateWorld, World, WORLD_INTERFACE_VERSION);
#endif // HOOK_HLTV
16 changes: 11 additions & 5 deletions rehlds/HLTV/Core/src/World.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,15 @@ class World: public IWorld, public BaseSystemModule {
EXT_FUNC bool AddResource(resource_t *resource);
EXT_FUNC void AddLightStyle(int index, char *style);
EXT_FUNC bool AddSignonData(unsigned char type, unsigned char *data, int size);
bool AddSignonData(unsigned char* data, int size);
EXT_FUNC bool AddUserMessage(int msgNumber, int size, char *name);
EXT_FUNC void AddBaselineEntity(int index, entity_state_t *ent);
EXT_FUNC void AddInstancedBaselineEntity(int index, entity_state_t *ent);
EXT_FUNC void UpdatePlayer(int playerNum, int userId, char *infostring, char *hashedcdkey);

EXT_FUNC void WriteFrame(frame_t *frame, unsigned int lastFrameSeqnr, BitBuffer *reliableStream, BitBuffer *unreliableStream, unsigned int deltaSeqNr, unsigned int clientDelta, bool addVoice);
EXT_FUNC void WriteFrame(frame_t *frame, unsigned int lastFrameSeqnr, BitBuffer *reliableStream,
BitBuffer *unreliableStream, unsigned int deltaSeqNr, unsigned int clientDelta,
bool addVoice);
EXT_FUNC void WriteNewData(BitBuffer *stream);
EXT_FUNC void WriteClientUpdate(BitBuffer *stream, int playerIndex);
EXT_FUNC void WriteMovevars(BitBuffer *stream);
Expand All @@ -139,7 +142,8 @@ class World: public IWorld, public BaseSystemModule {

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);
Expand All @@ -158,7 +162,8 @@ class World: public IWorld, public BaseSystemModule {
void WritePacketEntities(BitBuffer *stream, frame_t *frame, frame_t *deltaframe);
bool WriteDeltaEntities(BitBuffer *stream, frame_t *fullFrame, unsigned int deltaSeqNr, unsigned int clientDelta);

enum WorldState {
enum WorldState
{
WORLD_UNDEFINED,
WORLD_INITIALIZING,
WORLD_DISCONNECTED,
Expand Down Expand Up @@ -188,9 +193,9 @@ class World: public IWorld, public BaseSystemModule {
delta_t *GetEventDelta() const;
delta_t *GetClientDelta() const;
delta_t *GetEntityDelta() const;
delta_t *GetWeaponDelta() const;
delta_t *GetDeltaEncoder(int index, bool custom);
bool IsDeltaEncoder() const;
delta_t* GetWeaponDelta() const;

protected:
bool m_IsPaused;
Expand All @@ -209,7 +214,8 @@ class World: public IWorld, public BaseSystemModule {
int m_ViewEntity;
serverinfo_t m_DetailedServerInfo;

enum {
enum
{
MAX_ENTITIES = 1380,
MAX_INSTANCED_BASELINES = 64,
MAX_FRAME_CACHE = 32,
Expand Down
2 changes: 1 addition & 1 deletion rehlds/HLTV/Director/src/Director.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ float Director::AddBestGenericCut()
float sumTarget2Rank[MAX_CLIENTS];
float bestTarget2Rank, bestRank = 0;
float targetRankSum = 0;
int newTarget, newTarget2;
int newTarget = 0, newTarget2 = 0;
int bestTarget2;

for (int i = 0; i < MAX_CLIENTS; i++)
Expand Down
7 changes: 6 additions & 1 deletion rehlds/HLTV/Proxy/src/DemoClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ void DemoClient::RunFrame(double time)

void DemoClient::SendDatagram()
{
#ifndef HLTV_FIXES
/*
* Delaying frames to demo is wrong.
* Early stopping demo will lost server frames.
*/
if (m_Proxy->GetDelay() > 0)
{
double worldTime = m_Proxy->GetSpectatorTime();
Expand All @@ -173,7 +178,7 @@ void DemoClient::SendDatagram()

return;
}

#endif
frame_t *frame = m_World->GetLastFrame();
if (frame) {
WriteDatagram(frame->time, frame);
Expand Down
102 changes: 95 additions & 7 deletions rehlds/HLTV/Proxy/src/Proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,41 @@ Proxy::LocalCommandID_s Proxy::m_LocalCmdReg[] = {
#ifndef HOOK_HLTV
EXPOSE_SINGLE_INTERFACE(Proxy, IProxy, PROXY_INTERFACE_VERSION);
#endif // HOOK_HLTV
#ifdef HLTV_FIXES
void Proxy::AddNextWorld()
{
BitBuffer temp_buff;
temp_buff.Resize(0x8000);
static int num_alloc = 0;
static char instance[64];
snprintf(instance, sizeof(instance), "AddNextWorld_%d", num_alloc++);
IWorld* nextWorld = (IWorld*)m_System->GetModule(WORLD_INTERFACE_VERSION, "core", instance);
if (!nextWorld)
{
m_System->Errorf("Proxy::AddNextWorld: couldn't load world module.\n");
return;
}

m_World->WriteSigonData(&temp_buff);
nextWorld->AddSignonData(temp_buff.GetData(), temp_buff.CurrentSize());

nextWorld->RegisterListener(this);

m_Worlds.AddTail(nextWorld);

if (m_DemoClient.IsActive())
{
m_DemoClient.FinishDemo();
}

m_Server->SetWorld(nextWorld);
m_DemoClient.SetWorld(nextWorld);

if (m_Server->IsConnected()) {
m_Server->Reconnect();
}
}
#endif
bool Proxy::Init(IBaseSystem *system, int serial, char *name)
{
BaseSystemModule::Init(system, serial, name);
Expand Down Expand Up @@ -315,8 +349,27 @@ void Proxy::RunFrame(double time)
RunClocks();
if (m_IsFinishingBroadcast && m_ClientWorldTime > m_World->GetTime() && !m_IsReconnectRequested)
{
if (m_Server->IsConnected()) {
m_Server->Reconnect();
#ifdef HLTV_FIXES
IWorld* head = (IWorld*)m_Worlds.GetFirst();

// If we just finished playback previous world record
if(head)
{
// We can't RemoveModule m_World right now because it will fire events to unload us.
// Store it in temp var to unload it after set new world
IWorld* oldWorld = m_World;
m_World = head;
m_Worlds.RemoveHead();
NewGameStarted();
ReconnectClients();
m_System->RemoveModule((ISystemModule*)oldWorld);
}
else
#endif
{
if (m_Server->IsConnected()) {
m_Server->Reconnect();
}
}
m_IsReconnectRequested = true;
}
Expand Down Expand Up @@ -1423,8 +1476,17 @@ void Proxy::ReceiveSignal(ISystemModule *module, unsigned int signal, void *data
break;
case 5:
case 6:
{
#ifdef HLTV_FIXES
if (!m_IsFinishingBroadcast && m_ClientDelay > 0.f)
{
//If we finished broadcast we need to get frames from next "World" (Next server map)
AddNextWorld();
}
#endif
m_IsFinishingBroadcast = true;
break;
}
case 7:
BroadcastRetryMessage();
break;
Expand All @@ -1441,15 +1503,26 @@ void Proxy::ReceiveSignal(ISystemModule *module, unsigned int signal, void *data
switch (signal)
{
case 2:
NewGameStarted();
ReconnectClients();

#ifdef HLTV_FIXES
if(m_ClientDelay <= 0)
#endif
{
NewGameStarted();
ReconnectClients();
}
break;
case 5:
case 6:
BroadcastPaused(signal == 5 ? true : false);
break;
case 8:
StopBroadcast("HLTV shutddown.");
#ifdef HLTV_FIXES
if (m_ClientDelay <= 0)
#endif
{
StopBroadcast("HLTV shutdown.");
}
break;
default:
break;
Expand Down Expand Up @@ -1841,11 +1914,20 @@ void Proxy::ReconnectClients()
IClient *client = (IClient *)m_Clients.GetFirst();
while (client)
{
#ifdef HLTV_FIXES
client->SetWorld(m_World);
#endif
client->Reconnect();
client = (IClient *)m_Clients.GetNext();
}

m_DemoClient.Reconnect();
#ifdef HLTV_FIXES
// If delay set than m_DemoClient is already stopped demo in AddNextWorld
// Reconnect (Stoping demo) in this case will stop demo and write new one with lost frames
if (m_ClientDelay <= 0 && m_DemoClient.IsActive())
#endif
{
m_DemoClient.Reconnect();
}
}

void Proxy::CMD_OffLineText(char *cmdLine)
Expand Down Expand Up @@ -2479,11 +2561,17 @@ void Proxy::SetDelay(float seconds)
{
m_ClientDelay = 0;
m_World->SetBufferSize(10);
#ifdef HLTV_FIXES
m_Server->SetDelayReconnect(false);
#endif
}
else
{
m_World->SetBufferSize(seconds + seconds);
m_ClientWorldTime = m_World->GetTime() - m_ClientDelay;
#ifdef HLTV_FIXES
m_Server->SetDelayReconnect(true);
#endif
}

m_Server->SetUserInfo("hdelay", COM_VarArgs("%u", (int)m_ClientDelay));
Expand Down
3 changes: 2 additions & 1 deletion rehlds/HLTV/Proxy/src/Proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class Proxy: public IProxy, public BaseSystemModule {
void CMD_Protocol(char *cmdLine);
void CMD_Region(char *cmdLine);
void CMD_ChatDelay(char *cmdLine);

void AddNextWorld();
struct LocalCommandID_s {
char *name;
LocalCommandIDs id;
Expand Down Expand Up @@ -388,4 +388,5 @@ class Proxy: public IProxy, public BaseSystemModule {
BitBuffer m_InfoDetails;
BitBuffer m_InfoInfo;
BitBuffer m_InfoString;
ObjectList m_Worlds;
};
1 change: 1 addition & 0 deletions rehlds/public/HLTV/IServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class IServer {
virtual bool GetAutoRetry() = 0;
virtual float GetPacketLoss() = 0;
virtual int GetProtocol() = 0;
virtual void SetWorld(IWorld* world) = 0;
};

#define SERVER_INTERFACE_VERSION "server001"
1 change: 1 addition & 0 deletions rehlds/public/HLTV/IWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class IWorld {
virtual bool AddResource(resource_t *resource) = 0;
virtual void AddLightStyle(int index, char *style) = 0;
virtual bool AddSignonData(unsigned char type, unsigned char *data, int size) = 0;
virtual bool AddSignonData(unsigned char* data, int size) = 0;
virtual bool AddUserMessage(int msgNumber, int size, char *name) = 0;
virtual void AddBaselineEntity(int index, entity_state_t *ent) = 0;
virtual void AddInstancedBaselineEntity(int index, entity_state_t *ent) = 0;
Expand Down