Add CSS support

This commit is contained in:
Peace-Maker 2016-02-29 14:55:23 +01:00
parent e51143d05a
commit 3210a8d249
8 changed files with 154 additions and 17 deletions

View File

@ -25,7 +25,7 @@ else:
project.sources += sourceFiles project.sources += sourceFiles
for sdk_name in ['csgo']: for sdk_name in ['css', 'csgo']:
if sdk_name not in Extension.sdks: if sdk_name not in Extension.sdks:
continue continue
sdk = Extension.sdks[sdk_name] sdk = Extension.sdks[sdk_name]

View File

@ -46,8 +46,12 @@ ISDKTools *sdktools = nullptr;
IServer *iserver = nullptr; IServer *iserver = nullptr;
IGameConfig *g_pGameConf = nullptr; IGameConfig *g_pGameConf = nullptr;
#if SOURCE_ENGINE == SE_CSGO
SH_DECL_HOOK1_void(IHLTVDirector, AddHLTVServer, SH_NOATTRIB, 0, IHLTVServer *); SH_DECL_HOOK1_void(IHLTVDirector, AddHLTVServer, SH_NOATTRIB, 0, IHLTVServer *);
SH_DECL_HOOK1_void(IHLTVDirector, RemoveHLTVServer, SH_NOATTRIB, 0, IHLTVServer *); SH_DECL_HOOK1_void(IHLTVDirector, RemoveHLTVServer, SH_NOATTRIB, 0, IHLTVServer *);
#else
SH_DECL_HOOK1_void(IHLTVDirector, SetHLTVServer, SH_NOATTRIB, 0, IHLTVServer *);
#endif
SH_DECL_HOOK1(IClient, ExecuteStringCommand, SH_NOATTRIB, 0, bool, const char *); SH_DECL_HOOK1(IClient, ExecuteStringCommand, SH_NOATTRIB, 0, bool, const char *);
@ -92,8 +96,12 @@ bool SourceTVManager::SDK_OnLoad(char *error, size_t maxlength, bool late)
void SourceTVManager::SDK_OnAllLoaded() void SourceTVManager::SDK_OnAllLoaded()
{ {
#if SOURCE_ENGINE == SE_CSGO
SH_ADD_HOOK(IHLTVDirector, AddHLTVServer, hltvdirector, SH_MEMBER(this, &SourceTVManager::OnAddHLTVServer_Post), true); SH_ADD_HOOK(IHLTVDirector, AddHLTVServer, hltvdirector, SH_MEMBER(this, &SourceTVManager::OnAddHLTVServer_Post), true);
SH_ADD_HOOK(IHLTVDirector, RemoveHLTVServer, hltvdirector, SH_MEMBER(this, &SourceTVManager::OnRemoveHLTVServer_Post), true); SH_ADD_HOOK(IHLTVDirector, RemoveHLTVServer, hltvdirector, SH_MEMBER(this, &SourceTVManager::OnRemoveHLTVServer_Post), true);
#else
SH_ADD_HOOK(IHLTVDirector, SetHLTVServer, hltvdirector, SH_MEMBER(this, &SourceTVManager::OnSetHLTVServer_Post), true);
#endif
SM_GET_LATE_IFACE(BINTOOLS, bintools); SM_GET_LATE_IFACE(BINTOOLS, bintools);
SM_GET_LATE_IFACE(SDKTOOLS, sdktools); SM_GET_LATE_IFACE(SDKTOOLS, sdktools);
@ -104,6 +112,7 @@ void SourceTVManager::SDK_OnAllLoaded()
if (!iserver) if (!iserver)
smutils->LogError(myself, "Failed to get IServer interface from SDKTools. Some functions won't work."); smutils->LogError(myself, "Failed to get IServer interface from SDKTools. Some functions won't work.");
#if SOURCE_ENGINE == SE_CSGO
if (hltvdirector->GetHLTVServerCount() > 0) if (hltvdirector->GetHLTVServerCount() > 0)
SelectSourceTVServer(hltvdirector->GetHLTVServer(0)); SelectSourceTVServer(hltvdirector->GetHLTVServer(0));
@ -112,6 +121,13 @@ void SourceTVManager::SDK_OnAllLoaded()
{ {
g_pSTVForwards.HookRecorder(GetDemoRecorderPtr(hltvdirector->GetHLTVServer(i))); g_pSTVForwards.HookRecorder(GetDemoRecorderPtr(hltvdirector->GetHLTVServer(i)));
} }
#else
if (hltvdirector->GetHLTVServer())
{
SelectSourceTVServer(hltvdirector->GetHLTVServer());
g_pSTVForwards.HookRecorder(GetDemoRecorderPtr(hltvdirector->GetHLTVServer()));
}
#endif
} }
bool SourceTVManager::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool late) bool SourceTVManager::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool late)
@ -124,16 +140,26 @@ bool SourceTVManager::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxle
void SourceTVManager::SDK_OnUnload() void SourceTVManager::SDK_OnUnload()
{ {
#if SOURCE_ENGINE == SE_CSGO
SH_REMOVE_HOOK(IHLTVDirector, AddHLTVServer, hltvdirector, SH_MEMBER(this, &SourceTVManager::OnAddHLTVServer_Post), true); SH_REMOVE_HOOK(IHLTVDirector, AddHLTVServer, hltvdirector, SH_MEMBER(this, &SourceTVManager::OnAddHLTVServer_Post), true);
SH_REMOVE_HOOK(IHLTVDirector, RemoveHLTVServer, hltvdirector, SH_MEMBER(this, &SourceTVManager::OnRemoveHLTVServer_Post), true); SH_REMOVE_HOOK(IHLTVDirector, RemoveHLTVServer, hltvdirector, SH_MEMBER(this, &SourceTVManager::OnRemoveHLTVServer_Post), true);
#else
SH_REMOVE_HOOK(IHLTVDirector, SetHLTVServer, hltvdirector, SH_MEMBER(this, &SourceTVManager::OnSetHLTVServer_Post), true);
#endif
gameconfs->CloseGameConfigFile(g_pGameConf); gameconfs->CloseGameConfigFile(g_pGameConf);
#if SOURCE_ENGINE == SE_CSGO
// Unhook all the existing servers. // Unhook all the existing servers.
for (int i = 0; i < hltvdirector->GetHLTVServerCount(); i++) for (int i = 0; i < hltvdirector->GetHLTVServerCount(); i++)
{ {
g_pSTVForwards.UnhookRecorder(GetDemoRecorderPtr(hltvdirector->GetHLTVServer(i))); g_pSTVForwards.UnhookRecorder(GetDemoRecorderPtr(hltvdirector->GetHLTVServer(i)));
} }
#else
// Unhook the server
if (hltvdirector->GetHLTVServer())
g_pSTVForwards.UnhookRecorder(GetDemoRecorderPtr(hltvdirector->GetHLTVServer()));
#endif
g_pSTVForwards.Shutdown(); g_pSTVForwards.Shutdown();
} }
@ -176,7 +202,7 @@ void SourceTVManager::SelectSourceTVServer(IHLTVServer *hltv)
SH_ADD_HOOK(IClient, ExecuteStringCommand, pClient, SH_MEMBER(this, &SourceTVManager::OnHLTVBotExecuteStringCommand_Post), true); SH_ADD_HOOK(IClient, ExecuteStringCommand, pClient, SH_MEMBER(this, &SourceTVManager::OnHLTVBotExecuteStringCommand_Post), true);
} }
IDemoRecorder *SourceTVManager::GetDemoRecorderPtr(IHLTVServer *hltvserver) IDemoRecorder *SourceTVManager::GetDemoRecorderPtr(IHLTVServer *hltv)
{ {
static int offset = -1; static int offset = -1;
if (offset == -1 && !g_pGameConf->GetOffset("CHLTVServer::m_DemoRecorder", &offset)) if (offset == -1 && !g_pGameConf->GetOffset("CHLTVServer::m_DemoRecorder", &offset))
@ -185,8 +211,8 @@ IDemoRecorder *SourceTVManager::GetDemoRecorderPtr(IHLTVServer *hltvserver)
return nullptr; return nullptr;
} }
if (hltvserver) if (hltv)
return (IDemoRecorder *)((intptr_t)hltvserver + offset); return (IDemoRecorder *)((intptr_t)hltv + offset);
else else
return nullptr; return nullptr;
} }
@ -196,6 +222,7 @@ void SourceTVManager::UpdateDemoRecorderPointer()
demorecorder = GetDemoRecorderPtr(hltvserver); demorecorder = GetDemoRecorderPtr(hltvserver);
} }
#if SOURCE_ENGINE == SE_CSGO
void SourceTVManager::OnAddHLTVServer_Post(IHLTVServer *hltv) void SourceTVManager::OnAddHLTVServer_Post(IHLTVServer *hltv)
{ {
g_pSTVForwards.HookRecorder(GetDemoRecorderPtr(hltv)); g_pSTVForwards.HookRecorder(GetDemoRecorderPtr(hltv));
@ -206,6 +233,7 @@ void SourceTVManager::OnAddHLTVServer_Post(IHLTVServer *hltv)
// This is the first SourceTV server to be added. Hook it. // This is the first SourceTV server to be added. Hook it.
SelectSourceTVServer(hltv); SelectSourceTVServer(hltv);
RETURN_META(MRES_IGNORED);
} }
void SourceTVManager::OnRemoveHLTVServer_Post(IHLTVServer *hltv) void SourceTVManager::OnRemoveHLTVServer_Post(IHLTVServer *hltv)
@ -221,7 +249,29 @@ void SourceTVManager::OnRemoveHLTVServer_Post(IHLTVServer *hltv)
else else
SelectSourceTVServer(nullptr); SelectSourceTVServer(nullptr);
} }
RETURN_META(MRES_IGNORED);
} }
#else
void SourceTVManager::OnSetHLTVServer_Post(IHLTVServer *hltv)
{
META_CONPRINTF("%x == %x ?", hltv, hltvdirector->GetHLTVServer());
// Server shut down?
if (!hltv)
{
// We didn't catch the server being set..
if (!hltvserver)
RETURN_META(MRES_IGNORED);
g_pSTVForwards.UnhookRecorder(GetDemoRecorderPtr(hltvserver));
}
else
{
g_pSTVForwards.HookRecorder(GetDemoRecorderPtr(hltv));
}
SelectSourceTVServer(hltv);
RETURN_META(MRES_IGNORED);
}
#endif
bool SourceTVManager::OnHLTVBotExecuteStringCommand(const char *s) bool SourceTVManager::OnHLTVBotExecuteStringCommand(const char *s)
{ {

View File

@ -43,6 +43,7 @@
#include "ihltvdirector.h" #include "ihltvdirector.h"
#include "ihltv.h" #include "ihltv.h"
#include "iserver.h" #include "iserver.h"
#include "iclient.h"
#include "ihltvdemorecorder.h" #include "ihltvdemorecorder.h"
#include "igameevents.h" #include "igameevents.h"
@ -126,9 +127,12 @@ public:
IDemoRecorder *GetDemoRecorderPtr(IHLTVServer *hltvserver); IDemoRecorder *GetDemoRecorderPtr(IHLTVServer *hltvserver);
private: private:
#if SOURCE_ENGINE == SE_CSGO
void OnAddHLTVServer_Post(IHLTVServer *hltv); void OnAddHLTVServer_Post(IHLTVServer *hltv);
void OnRemoveHLTVServer_Post(IHLTVServer *hltv); void OnRemoveHLTVServer_Post(IHLTVServer *hltv);
bool OnHLTVBotSendNetMsg_Post(INetMessage &msg, bool bForceReliable, bool bVoice); #else
void OnSetHLTVServer_Post(IHLTVServer *hltv);
#endif
bool OnHLTVBotExecuteStringCommand(const char *s); bool OnHLTVBotExecuteStringCommand(const char *s);
bool OnHLTVBotExecuteStringCommand_Post(const char *s); bool OnHLTVBotExecuteStringCommand_Post(const char *s);

View File

@ -35,7 +35,11 @@
CForwardManager g_pSTVForwards; CForwardManager g_pSTVForwards;
SH_DECL_HOOK2_void(IDemoRecorder, StartRecording, SH_NOATTRIB, 0, const char *, bool) SH_DECL_HOOK2_void(IDemoRecorder, StartRecording, SH_NOATTRIB, 0, const char *, bool)
#if SOURCE_ENGINE == SE_CSGO
SH_DECL_HOOK1_void(IDemoRecorder, StopRecording, SH_NOATTRIB, 0, CGameInfo const *) SH_DECL_HOOK1_void(IDemoRecorder, StopRecording, SH_NOATTRIB, 0, CGameInfo const *)
#else
SH_DECL_HOOK0_void(IDemoRecorder, StopRecording, SH_NOATTRIB, 0)
#endif
void CForwardManager::Init() void CForwardManager::Init()
{ {
@ -74,7 +78,11 @@ void CForwardManager::OnStartRecording_Post(const char *filename, bool bContinuo
RETURN_META(MRES_IGNORED); RETURN_META(MRES_IGNORED);
} }
#if SOURCE_ENGINE == SE_CSGO
void CForwardManager::OnStopRecording_Post(CGameInfo const *info) void CForwardManager::OnStopRecording_Post(CGameInfo const *info)
#else
void CForwardManager::OnStopRecording_Post()
#endif
{ {
if (m_StopRecordingFwd->GetFunctionCount() == 0) if (m_StopRecordingFwd->GetFunctionCount() == 0)
RETURN_META(MRES_IGNORED); RETURN_META(MRES_IGNORED);

View File

@ -47,7 +47,11 @@ public:
private: private:
void OnStartRecording_Post(const char *filename, bool bContinuously); void OnStartRecording_Post(const char *filename, bool bContinuously);
#if SOURCE_ENGINE == SE_CSGO
void OnStopRecording_Post(CGameInfo const *info); void OnStopRecording_Post(CGameInfo const *info);
#else
void OnStopRecording_Post();
#endif
private: private:
IForward *m_StartRecordingFwd; IForward *m_StartRecordingFwd;

View File

@ -18,7 +18,11 @@ public:
virtual bool IsRecording(void) = 0; virtual bool IsRecording(void) = 0;
virtual void PauseRecording(void) = 0; virtual void PauseRecording(void) = 0;
virtual void ResumeRecording(void) = 0; virtual void ResumeRecording(void) = 0;
#if SOURCE_ENGINE == SE_CSGO
virtual void StopRecording(CGameInfo const *info) = 0; virtual void StopRecording(CGameInfo const *info) = 0;
#else
virtual void StopRecording(void) = 0;
#endif
virtual void RecordCommand(const char *cmdstring) = 0; virtual void RecordCommand(const char *cmdstring) = 0;
virtual void RecordUserInput(int cmdnumber) = 0; virtual void RecordUserInput(int cmdnumber) = 0;
@ -26,7 +30,9 @@ public:
virtual void RecordPacket(void) = 0; virtual void RecordPacket(void) = 0;
virtual void RecordServerClasses(ServerClass *pClasses) = 0; virtual void RecordServerClasses(ServerClass *pClasses) = 0;
virtual void RecordStringTables(void); virtual void RecordStringTables(void);
#if SOURCE_ENGINE == SE_CSGO
virtual void RecordCustomData(int, void const *, unsigned int); virtual void RecordCustomData(int, void const *, unsigned int);
#endif
virtual void ResetDemoInterpolation(void) = 0; virtual void ResetDemoInterpolation(void) = 0;
}; };

View File

@ -36,18 +36,32 @@ extern const sp_nativeinfo_t sourcetv_natives[];
// native SourceTV_GetHLTVServerCount(); // native SourceTV_GetHLTVServerCount();
static cell_t Native_GetHLTVServerCount(IPluginContext *pContext, const cell_t *params) static cell_t Native_GetHLTVServerCount(IPluginContext *pContext, const cell_t *params)
{ {
#if SOURCE_ENGINE == SE_CSGO
return hltvdirector->GetHLTVServerCount(); return hltvdirector->GetHLTVServerCount();
#else
return hltvdirector->GetHLTVServer() ? 1 : 0;
#endif
} }
// native SourceTV_SelectHLTVServer(); // native SourceTV_SelectHLTVServer();
static cell_t Native_SelectHLTVServer(IPluginContext *pContext, const cell_t *params) static cell_t Native_SelectHLTVServer(IPluginContext *pContext, const cell_t *params)
{ {
#if SOURCE_ENGINE == SE_CSGO
if (params[1] < 0 || params[1] >= hltvdirector->GetHLTVServerCount()) if (params[1] < 0 || params[1] >= hltvdirector->GetHLTVServerCount())
{ {
pContext->ReportError("Invalid HLTV server instance number (%d).", params[1]); pContext->ReportError("Invalid HLTV server instance number (%d).", params[1]);
return 0; return 0;
} }
g_STVManager.SelectSourceTVServer(hltvdirector->GetHLTVServer(params[1])); g_STVManager.SelectSourceTVServer(hltvdirector->GetHLTVServer(params[1]));
#else
if (params[1] != 0 || !hltvdirector->GetHLTVServer())
{
pContext->ReportError("Invalid HLTV server instance number (%d).", params[1]);
return 0;
}
// There only is one hltv server.
g_STVManager.SelectSourceTVServer(hltvdirector->GetHLTVServer());
#endif
return 0; return 0;
} }
@ -58,6 +72,7 @@ static cell_t Native_GetSelectedHLTVServer(IPluginContext *pContext, const cell_
if (hltvserver == nullptr) if (hltvserver == nullptr)
return -1; return -1;
#if SOURCE_ENGINE == SE_CSGO
for (int i = 0; i < hltvdirector->GetHLTVServerCount(); i++) for (int i = 0; i < hltvdirector->GetHLTVServerCount(); i++)
{ {
if (hltvserver == hltvdirector->GetHLTVServer(i)) if (hltvserver == hltvdirector->GetHLTVServer(i))
@ -67,6 +82,10 @@ static cell_t Native_GetSelectedHLTVServer(IPluginContext *pContext, const cell_
// We should have found it in the above loop :S // We should have found it in the above loop :S
hltvserver = nullptr; hltvserver = nullptr;
return -1; return -1;
#else
// There only is one hltv server.
return 0;
#endif
} }
// native SourceTV_GetBotIndex(); // native SourceTV_GetBotIndex();
@ -228,10 +247,10 @@ static cell_t Native_GetViewCoordinates(IPluginContext *pContext, const cell_t *
// native bool:SourceTV_IsRecording(); // native bool:SourceTV_IsRecording();
static cell_t Native_IsRecording(IPluginContext *pContext, const cell_t *params) static cell_t Native_IsRecording(IPluginContext *pContext, const cell_t *params)
{ {
if (hltvserver == nullptr) if (demorecorder == nullptr)
return 0; return 0;
return hltvserver->IsRecording(); return demorecorder->IsRecording();
} }
// Checks in COM_IsValidPath in the engine // Checks in COM_IsValidPath in the engine
@ -243,7 +262,7 @@ static bool IsValidPath(const char *path)
// native bool:SourceTV_StartRecording(const String:sFilename[]); // native bool:SourceTV_StartRecording(const String:sFilename[]);
static cell_t Native_StartRecording(IPluginContext *pContext, const cell_t *params) static cell_t Native_StartRecording(IPluginContext *pContext, const cell_t *params)
{ {
if (hltvserver == nullptr) if (hltvserver == nullptr || demorecorder == nullptr)
return 0; return 0;
// SourceTV is not active. // SourceTV is not active.
@ -255,7 +274,7 @@ static cell_t Native_StartRecording(IPluginContext *pContext, const cell_t *para
return 0; return 0;
// already recording // already recording
if (hltvserver->IsRecording()) if (demorecorder->IsRecording())
return 0; return 0;
char *pFile; char *pFile;
@ -275,6 +294,7 @@ static cell_t Native_StartRecording(IPluginContext *pContext, const cell_t *para
ext = ""; ext = "";
smutils->Format(pPath, sizeof(pPath), "%s%s", pFile, ext); smutils->Format(pPath, sizeof(pPath), "%s%s", pFile, ext);
#if SOURCE_ENGINE == SE_CSGO
if (hltvdirector->GetHLTVServerCount() > 1) if (hltvdirector->GetHLTVServerCount() > 1)
{ {
for (int i = 0; i < hltvdirector->GetHLTVServerCount(); i++) for (int i = 0; i < hltvdirector->GetHLTVServerCount(); i++)
@ -288,6 +308,7 @@ static cell_t Native_StartRecording(IPluginContext *pContext, const cell_t *para
return 0; return 0;
} }
} }
#endif
demorecorder->StartRecording(pPath, false); demorecorder->StartRecording(pPath, false);
@ -297,15 +318,18 @@ static cell_t Native_StartRecording(IPluginContext *pContext, const cell_t *para
// native bool:SourceTV_StopRecording(); // native bool:SourceTV_StopRecording();
static cell_t Native_StopRecording(IPluginContext *pContext, const cell_t *params) static cell_t Native_StopRecording(IPluginContext *pContext, const cell_t *params)
{ {
if (hltvserver == nullptr) if (demorecorder == nullptr)
return 0; return 0;
if (!hltvserver->IsRecording()) if (!demorecorder->IsRecording())
return 0; return 0;
#if SOURCE_ENGINE == SE_CSGO
hltvserver->StopRecording(NULL); hltvserver->StopRecording(NULL);
// TODO: Stop recording on all other active hltvservers (tv_stoprecord in csgo does this) // TODO: Stop recording on all other active hltvservers (tv_stoprecord in csgo does this)
#else
demorecorder->StopRecording();
#endif
return 1; return 1;
} }
@ -313,13 +337,13 @@ static cell_t Native_StopRecording(IPluginContext *pContext, const cell_t *param
// native bool:SourceTV_GetDemoFileName(String:sFilename[], maxlen); // native bool:SourceTV_GetDemoFileName(String:sFilename[], maxlen);
static cell_t Native_GetDemoFileName(IPluginContext *pContext, const cell_t *params) static cell_t Native_GetDemoFileName(IPluginContext *pContext, const cell_t *params)
{ {
if (hltvserver == nullptr) if (demorecorder == nullptr)
return 0; return 0;
if (!hltvserver->IsRecording()) if (!demorecorder->IsRecording())
return 0; return 0;
char *pDemoFile = hltvserver->GetRecordingDemoFilename(); char *pDemoFile = (char *)demorecorder->GetDemoFile();
if (!pDemoFile) if (!pDemoFile)
return 0; return 0;

View File

@ -23,7 +23,6 @@
{ {
"windows" "39" "windows" "39"
"linux" "40" "linux" "40"
"mac" "40"
} }
"CHLTVServer::m_DemoRecorder" "CHLTVServer::m_DemoRecorder"
@ -43,4 +42,46 @@
} }
} }
} }
"cstrike"
{
"Addresses"
{
"host_client"
{
"windows"
{
"signature" "host_client"
"read" "92"
}
"linux"
{
"signature" "host_client"
}
}
}
"Offsets"
{
"BroadcastPrintf"
{
"windows" "35"
"linux" "36"
}
"CHLTVServer::m_DemoRecorder"
{
"windows" "19192"
"linux" "19424" // -416
}
}
"Signatures"
{
"host_client"
{
"library" "engine"
"linux" "@host_client"
// ping(CCommand const&) "Client ping times:\n"
"windows" "\x55\x8B\xEC\x51\x83\x3D\x2A\x2A\x2A\x2A\x01\x75\x2A"
}
}
}
} }