Skip to content

Commit

Permalink
Allow addons for HLTV clients and in demos (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
shqke committed Mar 6, 2021
1 parent 050aa5f commit 435893f
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 3 deletions.
29 changes: 27 additions & 2 deletions core/extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <am-string.h>
#include <checksum_crc.h>
#include <networkstringtabledefs.h>
#include <extensions/IBinTools.h>
#include <extensions/ISDKTools.h>

Expand All @@ -26,13 +25,17 @@ int CBaseServer::offset_stringTableCRC = 0;
int CBaseServer::vtblindex_GetChallengeNr = 0;
int CBaseServer::vtblindex_GetChallengeType = 0;
int CBaseServer::vtblindex_ReplyChallenge = 0;
int CBaseServer::vtblindex_FillServerInfo = 0;
void* CBaseServer::pfn_IsExclusiveToLobbyConnections = NULL;
CDetour* CBaseServer::detour_IsExclusiveToLobbyConnections = NULL;
ICallWrapper* CBaseServer::vcall_GetChallengeNr = NULL;
ICallWrapper* CBaseServer::vcall_GetChallengeType = NULL;
int CHLTVServer::offset_m_DemoRecorder = 0;
int CHLTVServer::offset_CClientFrameManager = 0;
int CHLTVServer::vtblindex_FillServerInfo = 0;
int CHLTVServer::shookid_ReplyChallenge = 0;
int CHLTVServer::shookid_FillServerInfo = 0;
int CHLTVServer::shookid_thunk_FillServerInfo = 0;
void* CHLTVServer::pfn_AddNewFrame = NULL;
CDetour* CHLTVServer::detour_AddNewFrame = NULL;
int CGameServer::shookid_IsPausable = 0;
Expand Down Expand Up @@ -62,6 +65,8 @@ SH_DECL_HOOK1_void(IHLTVDirector, SetHLTVServer, SH_NOATTRIB, 0, IHLTVServer*);
SH_DECL_HOOK0_void(CHLTVDemoRecorder, RecordStringTables, SH_NOATTRIB, 0);
SH_DECL_HOOK1_void(CHLTVDemoRecorder, RecordServerClasses, SH_NOATTRIB, 0, ServerClass*);
SH_DECL_MANUALHOOK2_void(CBaseServer_ReplyChallenge, 0, 0, 0, netadr_s&, CBitRead&);
SH_DECL_MANUALHOOK1_void(CBaseServer_FillServerInfo, 0, 0, 0, SVC_ServerInfo&);
SH_DECL_MANUALHOOK1_void(CHLTVServer_FillServerInfo, 0, 0, 0, SVC_ServerInfo&);
SH_DECL_HOOK0(IServer, IsPausable, const, 0, bool);
#if SOURCE_ENGINE == SE_LEFT4DEAD2
SH_DECL_HOOK0_void(ISteamGameServer, LogOff, SH_NOATTRIB, 0);
Expand Down Expand Up @@ -305,6 +310,8 @@ bool SMExtension::SetupFromGameConfig(IGameConfig* gc, char* error, int maxlengt
{ "CBaseServer::GetChallengeNr", CBaseServer::vtblindex_GetChallengeNr },
{ "CBaseServer::GetChallengeType", CBaseServer::vtblindex_GetChallengeType },
{ "CBaseServer::ReplyChallenge", CBaseServer::vtblindex_ReplyChallenge },
{ "CBaseServer::FillServerInfo", CBaseServer::vtblindex_FillServerInfo },
{ "CHLTVServer::FillServerInfo", CHLTVServer::vtblindex_FillServerInfo },
};

for (auto&& el : s_offsets) {
Expand Down Expand Up @@ -471,6 +478,12 @@ void SMExtension::OnSetHLTVServer(IHLTVServer* pIHLTVServer)
SH_REMOVE_HOOK_ID(CHLTVServer::shookid_ReplyChallenge);
CHLTVServer::shookid_ReplyChallenge = 0;

SH_REMOVE_HOOK_ID(CHLTVServer::shookid_thunk_FillServerInfo);
CHLTVServer::shookid_thunk_FillServerInfo = 0;

SH_REMOVE_HOOK_ID(CHLTVServer::shookid_FillServerInfo);
CHLTVServer::shookid_FillServerInfo = 0;

SH_REMOVE_HOOK_ID(shookid_CHLTVDemoRecorder_RecordStringTables);
shookid_CHLTVDemoRecorder_RecordStringTables = 0;

Expand All @@ -490,8 +503,12 @@ void SMExtension::OnSetHLTVServer(IHLTVServer* pIHLTVServer)
}

CHLTVServer::shookid_ReplyChallenge = SH_ADD_MANUALHOOK(CBaseServer_ReplyChallenge, pServer, SH_MEMBER(this, &SMExtension::Handler_CHLTVServer_ReplyChallenge), false);
CHLTVServer::shookid_thunk_FillServerInfo = SH_ADD_MANUALHOOK(CBaseServer_FillServerInfo, pServer, SH_MEMBER(this, &SMExtension::Handler_CHLTVServer_FillServerInfo), true);

CHLTVServer* pHLTVServer = CHLTVServer::FromBaseServer(pServer);
CHLTVServer::shookid_FillServerInfo = SH_ADD_MANUALHOOK(CHLTVServer_FillServerInfo, pHLTVServer, SH_MEMBER(this, &SMExtension::Handler_CHLTVServer_FillServerInfo), true);

CHLTVDemoRecorder& demoRecorder = CHLTVServer::FromBaseServer(pServer)->GetDemoRecorder();
CHLTVDemoRecorder& demoRecorder = pHLTVServer->GetDemoRecorder();
shookid_CHLTVDemoRecorder_RecordStringTables = SH_ADD_HOOK(CHLTVDemoRecorder, RecordStringTables, &demoRecorder, SH_MEMBER(this, &SMExtension::Handler_CHLTVDemoRecorder_RecordStringTables), false);
shookid_CHLTVDemoRecorder_RecordServerClasses = SH_ADD_HOOK(CHLTVDemoRecorder, RecordServerClasses, &demoRecorder, SH_MEMBER(this, &SMExtension::Handler_CHLTVDemoRecorder_RecordServerClasses), false);

Expand Down Expand Up @@ -655,6 +672,12 @@ const void* SMExtension::Handler_CNetworkStringTable_GetStringUserData(int strin
RETURN_META_VALUE(MRES_SUPERCEDE, _this->GetStringUserDataFixed(stringNumber, length));
}

void SMExtension::Handler_CHLTVServer_FillServerInfo(SVC_ServerInfo& serverinfo)
{
// feature request #12 - allow addons in demos
serverinfo.m_bIsVanilla = false;
}

bool SMExtension::SDK_OnLoad(char* error, size_t maxlength, bool late)
{
sm_sendprop_info_t info;
Expand Down Expand Up @@ -682,6 +705,8 @@ bool SMExtension::SDK_OnLoad(char* error, size_t maxlength, bool late)
gameconfs->CloseGameConfigFile(gc);

SH_MANUALHOOK_RECONFIGURE(CBaseServer_ReplyChallenge, CBaseServer::vtblindex_ReplyChallenge, 0, 0);
SH_MANUALHOOK_RECONFIGURE(CBaseServer_FillServerInfo, CBaseServer::vtblindex_FillServerInfo, 0, 0);
SH_MANUALHOOK_RECONFIGURE(CHLTVServer_FillServerInfo, CHLTVServer::vtblindex_FillServerInfo, 0, 0);

// Retrieve addresses from steam_api shared library
if (!SetupFromSteamAPILibrary(error, maxlength)) {
Expand Down
2 changes: 2 additions & 0 deletions core/extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#endif

#include "sdk/engine/hltvdemo.h"
#include "sdk/common/netmessages.h"

enum ESocketIndex_t
{
Expand Down Expand Up @@ -69,6 +70,7 @@ class SMExtension :
void Handler_ISteamGameServer_LogOff();
bool Handler_CGameServer_IsPausable() const;
const void* Handler_CNetworkStringTable_GetStringUserData(int stringNumber, int* length) const;
void Handler_CHLTVServer_FillServerInfo(SVC_ServerInfo& serverinfo);

public: // SDKExtension
/**
Expand Down
100 changes: 100 additions & 0 deletions core/sdk/common/netmessages.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//

#ifndef NETMESSAGES_H
#define NETMESSAGES_H

#include <inetmessage.h>
#include <checksum_crc.h>
#include <const.h>
#include <utlvector.h>
#include <bitbuf.h>
#include <inetchannel.h>
#include <inetmsghandler.h>

#define MAX_OSPATH 260 // max length of a filesystem pathname

class INetMessageHandler;
class IServerMessageHandler;
class IClientMessageHandler;

class CNetMessageRatelimitPolicy
{
public:
int unk;
int m_nBytes;
double m_unk;
int unk1;
int unk2;
double m_prevTime;

int unk3;
int unk4;
bool m_bunk;
double m_unkTimeDelta;
int unk5;
int unk6;
};

class CNetMessage : public INetMessage
{
public:
virtual ~CNetMessage() {};

virtual int GetGroup() const { return INetChannelInfo::GENERIC; }
INetChannel *GetNetChannel() const { return m_NetChannel; }

virtual void SetReliable( bool state) {m_bReliable = state;};
virtual bool IsReliable() const { return m_bReliable; };
virtual void SetNetChannel(INetChannel * netchan) { m_NetChannel = netchan; }
virtual bool Process() { Assert( 0 ); return false; }; // no handler set

protected:
bool m_bReliable; // true if message should be send reliable
INetChannel *m_NetChannel; // netchannel this message is from/for

CNetMessageRatelimitPolicy m_rateLimitPolicy;
};


///////////////////////////////////////////////////////////////////////////////////////
// server messages:
///////////////////////////////////////////////////////////////////////////////////////

class SVC_ServerInfo : public CNetMessage
{
IServerMessageHandler* m_pMessageHandler;

public: // member vars are public for faster handling
int m_nProtocol; // protocol version
int m_nServerCount; // number of changelevels since server start
bool m_bIsDedicated; // dedicated server ?
bool m_bIsVanilla;
bool m_bIsHLTV; // HLTV server ?
char m_cOS;
CRC32_t m_nMapCRC;
CRC32_t m_nClientCRC;
CRC32_t m_nStringTableCRC;
int m_nMaxClients;
int m_nMaxClasses;
int m_nPlayerSlot;
float m_fTickInterval;
const char* m_szGameDir;
const char* m_szMapName;
const char* m_szSkyName;
const char* m_szHostName;
const char* m_szMissionName;
const char* m_szModeName;

char m_szGameDirBuffer[MAX_OSPATH];
char m_szMapNameBuffer[MAX_OSPATH];
char m_szSkyNameBuffer[MAX_OSPATH];
char m_szHostNameBuffer[MAX_OSPATH];
char m_szMissionBuffer[MAX_OSPATH];
char m_szGamemodeBuffer[MAX_OSPATH];
};

#endif // NETMESSAGES_H
2 changes: 1 addition & 1 deletion core/smsdk_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Configuration
#define SMEXT_CONF_NAME "SourceTV Support"
#define SMEXT_CONF_DESCRIPTION "Restores broadcasting/recording SourceTV features in Left 4 Dead engine"
#define SMEXT_CONF_VERSION "0.9.1"
#define SMEXT_CONF_VERSION "0.9.3"
#define SMEXT_CONF_AUTHOR "Evgeniy \"shqke\" Kazakov"
#define SMEXT_CONF_URL "https://github.com/shqke/sourcetvsupport"
#define SMEXT_CONF_LOGTAG "STVS"
Expand Down
6 changes: 6 additions & 0 deletions core/wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <game/server/iplayerinfo.h>
#include <iclient.h>
#include <igameevents.h>
#include <networkstringtabledefs.h>

extern IServerGameEnts* gameents;
extern IPlayerInfoManager* playerinfomanager;
Expand Down Expand Up @@ -107,6 +108,7 @@ class CBaseServer
static int vtblindex_GetChallengeNr;
static int vtblindex_GetChallengeType;
static int vtblindex_ReplyChallenge;
static int vtblindex_FillServerInfo;

static void* pfn_IsExclusiveToLobbyConnections;

Expand Down Expand Up @@ -168,7 +170,11 @@ class CHLTVServer
static int offset_m_DemoRecorder;
static int offset_CClientFrameManager;

static int vtblindex_FillServerInfo;

static int shookid_ReplyChallenge;
static int shookid_FillServerInfo;
static int shookid_thunk_FillServerInfo;

static void* pfn_AddNewFrame;

Expand Down
18 changes: 18 additions & 0 deletions extra/sourcetvsupport.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
"linux" "40"
"windows" "40"
}

"CHLTVServer::FillServerInfo"
{
"linux" "9"
"windows" "10"
}
}

"Signatures"
Expand Down Expand Up @@ -90,6 +96,12 @@
"linux" "58"
"windows" "59"
}

"CBaseServer::FillServerInfo"
{
"linux" "45"
"windows" "46"
}
}

"Signatures"
Expand Down Expand Up @@ -159,6 +171,12 @@
"linux" "60"
"windows" "61"
}

"CBaseServer::FillServerInfo"
{
"linux" "47"
"windows" "48"
}
}

"Signatures"
Expand Down

0 comments on commit 435893f

Please sign in to comment.