Skip to content

Commit

Permalink
Fixed windows binaries
Browse files Browse the repository at this point in the history
Switched to std::vector from CUtlBuffer to avoid memory debugging allocations
Handled virtual method CHLTVServer::FillServerInfo on windows
  • Loading branch information
shqke committed Mar 7, 2021
1 parent a9e63d8 commit ffecf63
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 27 deletions.
33 changes: 19 additions & 14 deletions core/extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "sdk/public/engine/inetsupport.h"
#include "sdk/engine/networkstringtable.h"

#include <vector>
#include <am-string.h>
#include <checksum_crc.h>
#include <extensions/IBinTools.h>
Expand Down Expand Up @@ -32,10 +33,11 @@ ICallWrapper* CBaseServer::vcall_GetChallengeNr = NULL;
ICallWrapper* CBaseServer::vcall_GetChallengeType = NULL;
int CHLTVServer::offset_m_DemoRecorder = 0;
int CHLTVServer::offset_CClientFrameManager = 0;
int CHLTVServer::offset_CBaseServer = 0;
int CHLTVServer::vtblindex_FillServerInfo = 0;
int CHLTVServer::shookid_ReplyChallenge = 0;
int CHLTVServer::shookid_FillServerInfo = 0;
int CHLTVServer::shookid_thunk_FillServerInfo = 0;
int CHLTVServer::shookid_hltv_FillServerInfo = 0;
void* CHLTVServer::pfn_AddNewFrame = NULL;
CDetour* CHLTVServer::detour_AddNewFrame = NULL;
int CGameServer::shookid_IsPausable = 0;
Expand Down Expand Up @@ -305,13 +307,16 @@ bool SMExtension::SetupFromGameConfig(IGameConfig* gc, char* error, int maxlengt
} s_offsets[] = {
{ "CBaseServer::stringTableCRC", CBaseServer::offset_stringTableCRC },
{ "CHLTVServer::CClientFrameManager", CHLTVServer::offset_CClientFrameManager },
{ "CHLTVServer::CBaseServer", CHLTVServer::offset_CBaseServer },
{ "CHLTVServer::m_DemoRecorder", CHLTVServer::offset_m_DemoRecorder },
{ "CFrameSnapshotManager::m_PackedEntitiesPool", CFrameSnapshotManager::offset_m_PackedEntitiesPool },
{ "CBaseServer::GetChallengeNr", CBaseServer::vtblindex_GetChallengeNr },
{ "CBaseServer::GetChallengeType", CBaseServer::vtblindex_GetChallengeType },
{ "CBaseServer::ReplyChallenge", CBaseServer::vtblindex_ReplyChallenge },
{ "CBaseServer::FillServerInfo", CBaseServer::vtblindex_FillServerInfo },
#if !defined _WIN32
{ "CHLTVServer::FillServerInfo", CHLTVServer::vtblindex_FillServerInfo },
#endif
};

for (auto&& el : s_offsets) {
Expand Down Expand Up @@ -478,8 +483,8 @@ 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_hltv_FillServerInfo);
CHLTVServer::shookid_hltv_FillServerInfo = 0;

SH_REMOVE_HOOK_ID(CHLTVServer::shookid_FillServerInfo);
CHLTVServer::shookid_FillServerInfo = 0;
Expand All @@ -503,12 +508,14 @@ 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::shookid_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);
#if !defined _WIN32
CHLTVServer::shookid_hltv_FillServerInfo = SH_ADD_MANUALHOOK(CHLTVServer_FillServerInfo, pHLTVServer, SH_MEMBER(this, &SMExtension::Handler_CHLTVServer_FillServerInfo), true);
#endif

CHLTVDemoRecorder& demoRecorder = pHLTVServer->GetDemoRecorder();
CHLTVDemoRecorder& demoRecorder = pHLTVServer->m_DemoRecorder();
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 @@ -539,14 +546,13 @@ void SMExtension::Handler_CHLTVDirector_SetHLTVServer(IHLTVServer* pIHLTVServer)

void SMExtension::Handler_CHLTVDemoRecorder_RecordStringTables()
{
IDemoRecorder* _this = META_IFACEPTR(IDemoRecorder);
CHLTVDemoRecorder* _this = META_IFACEPTR(CHLTVDemoRecorder);

// bug#2
// insufficient buffer size in CHLTVDemoRecorder::RecordStringTables, overflowing it with stringtables data (starting at CHLTVDemoRecorder::RecordStringTables)
// stringtables wont be saved properly, causing demo file to be corrupted
CUtlBuffer bigBuffer;
bigBuffer.EnsureCapacity(DEMO_RECORD_BUFFER_SIZE);
bf_write buf(bigBuffer.Base(), DEMO_RECORD_BUFFER_SIZE);
std::vector<byte> bigBuffer(DEMO_RECORD_BUFFER_SIZE);
bf_write buf(bigBuffer.data(), bigBuffer.size());

int numTables = networkStringTableContainerServer->GetNumTables();
buf.WriteByte(numTables);
Expand Down Expand Up @@ -585,11 +591,10 @@ void SMExtension::Handler_CHLTVDemoRecorder_RecordStringTables()

void SMExtension::Handler_CHLTVDemoRecorder_RecordServerClasses(ServerClass* pClasses)
{
IDemoRecorder* _this = META_IFACEPTR(IDemoRecorder);
CHLTVDemoRecorder* _this = META_IFACEPTR(CHLTVDemoRecorder);

CUtlBuffer bigBuffer;
bigBuffer.EnsureCapacity(DEMO_RECORD_BUFFER_SIZE);
bf_write buf(bigBuffer.Base(), DEMO_RECORD_BUFFER_SIZE);
std::vector<byte> bigBuffer(DEMO_RECORD_BUFFER_SIZE);
bf_write buf(bigBuffer.data(), bigBuffer.size());

// Send SendTable info.
InvokeDataTable_WriteSendTablesBuffer(pClasses, &buf);
Expand Down
7 changes: 5 additions & 2 deletions core/extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@
#include <bitbuf.h>
#include <ihltv.h>

#include <tier0/memdbgon.h>
#include <tier1/utlbuffer.h>

#include <os/am-shared-library.h>
#include <os/am-path.h>

#include <sourcehook.h>

#if defined _WIN32
# define LIBSTEAMAPI_FILE "steam_api.dll"
#else
Expand All @@ -43,8 +48,6 @@ enum ESocketIndex_t
#define S2C_CHALLENGE 'A' // + challenge value

// Metamod Source
#include <sourcehook.h>

class SMExtension :
public SDKExtension
{
Expand Down
2 changes: 0 additions & 2 deletions core/sdk/engine/demo.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ class ServerClass;
abstract_class IDemoRecorder
{
public:
~IDemoRecorder() {}

virtual CDemoFile* GetDemoFile() = 0;
virtual int GetRecordingTick(void) = 0;

Expand Down
3 changes: 3 additions & 0 deletions core/sdk/engine/hltvdemo.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

class CHLTVDemoRecorder : public IDemoRecorder
{
public:
virtual ~CHLTVDemoRecorder();

private:
CDemoFile m_DemoFile;
bool m_bIsRecording;
Expand Down
6 changes: 3 additions & 3 deletions core/smsdk_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
// 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.3"
#define SMEXT_CONF_VERSION "0.9.4"
#define SMEXT_CONF_AUTHOR "Evgeniy \"shqke\" Kazakov"
#define SMEXT_CONF_URL "https://github.com/shqke/sourcetvsupport"
#define SMEXT_CONF_LOGTAG "STVS"
#define SMEXT_CONF_LICENSE "GPL"
#define SMEXT_CONF_DATESTRING __DATE__

#define GAMEDATA_FILE "sourcetvsupport"
#define GAMEDATA_FILE "sourcetvsupport"

#define PLUGIN_LOG_PREFIX "[" SMEXT_CONF_LOGTAG "] "
#define PLUGIN_LOG_PREFIX "[" SMEXT_CONF_LOGTAG "] "

#define SMEXT_CONF_METAMOD
#define SMEXT_ENABLE_PLAYERHELPERS
Expand Down
7 changes: 4 additions & 3 deletions core/wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,19 @@ class CHLTVServer
public:
static int offset_m_DemoRecorder;
static int offset_CClientFrameManager;
static int offset_CBaseServer;

static int vtblindex_FillServerInfo;

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

static void* pfn_AddNewFrame;

static CDetour* detour_AddNewFrame;

CHLTVDemoRecorder& GetDemoRecorder()
CHLTVDemoRecorder& m_DemoRecorder()
{
return *reinterpret_cast<CHLTVDemoRecorder*>(reinterpret_cast<byte*>(this) + offset_m_DemoRecorder);
}
Expand All @@ -192,7 +193,7 @@ class CHLTVServer

static CHLTVServer* FromBaseServer(CBaseServer* pServer)
{
return reinterpret_cast<CHLTVServer*>(reinterpret_cast<byte*>(pServer) - 4);
return reinterpret_cast<CHLTVServer*>(reinterpret_cast<byte*>(pServer) - offset_CBaseServer);
}
};

Expand Down
12 changes: 9 additions & 3 deletions extra/sourcetvsupport.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
"windows" "472"
}

"CHLTVServer::CBaseServer"
{
"linux" "4"
"windows" "8"
}

"CHLTVServer::m_DemoRecorder"
{
"linux" "19460"
Expand All @@ -30,8 +36,8 @@

"CHLTVServer::FillServerInfo"
{
// Entry point "CHLTVDemoRecorder::WriteServerInfo"
"linux" "9"
"windows" "10"
}
}

Expand Down Expand Up @@ -100,7 +106,7 @@
"CBaseServer::FillServerInfo"
{
"linux" "45"
"windows" "46"
"windows" "44"
}
}

Expand Down Expand Up @@ -175,7 +181,7 @@
"CBaseServer::FillServerInfo"
{
"linux" "47"
"windows" "48"
"windows" "46"
}
}

Expand Down

0 comments on commit ffecf63

Please sign in to comment.