diff --git a/AMBuilder b/AMBuilder index 0fa4b7d..cc1c170 100644 --- a/AMBuilder +++ b/AMBuilder @@ -25,7 +25,7 @@ else: project.sources += sourceFiles -for sdk_name in ['csgo']: +for sdk_name in ['css', 'csgo']: if sdk_name not in Extension.sdks: continue sdk = Extension.sdks[sdk_name] diff --git a/extension.cpp b/extension.cpp index bc02a78..6cd5792 100644 --- a/extension.cpp +++ b/extension.cpp @@ -46,8 +46,12 @@ ISDKTools *sdktools = nullptr; IServer *iserver = 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, 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 *); @@ -92,8 +96,12 @@ bool SourceTVManager::SDK_OnLoad(char *error, size_t maxlength, bool late) 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, 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(SDKTOOLS, sdktools); @@ -104,6 +112,7 @@ void SourceTVManager::SDK_OnAllLoaded() if (!iserver) smutils->LogError(myself, "Failed to get IServer interface from SDKTools. Some functions won't work."); +#if SOURCE_ENGINE == SE_CSGO if (hltvdirector->GetHLTVServerCount() > 0) SelectSourceTVServer(hltvdirector->GetHLTVServer(0)); @@ -112,6 +121,13 @@ void SourceTVManager::SDK_OnAllLoaded() { 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) @@ -124,16 +140,26 @@ bool SourceTVManager::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxle 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, 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); +#if SOURCE_ENGINE == SE_CSGO // Unhook all the existing servers. for (int i = 0; i < hltvdirector->GetHLTVServerCount(); 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(); } @@ -176,7 +202,7 @@ void SourceTVManager::SelectSourceTVServer(IHLTVServer *hltv) 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; if (offset == -1 && !g_pGameConf->GetOffset("CHLTVServer::m_DemoRecorder", &offset)) @@ -185,8 +211,8 @@ IDemoRecorder *SourceTVManager::GetDemoRecorderPtr(IHLTVServer *hltvserver) return nullptr; } - if (hltvserver) - return (IDemoRecorder *)((intptr_t)hltvserver + offset); + if (hltv) + return (IDemoRecorder *)((intptr_t)hltv + offset); else return nullptr; } @@ -196,6 +222,7 @@ void SourceTVManager::UpdateDemoRecorderPointer() demorecorder = GetDemoRecorderPtr(hltvserver); } +#if SOURCE_ENGINE == SE_CSGO void SourceTVManager::OnAddHLTVServer_Post(IHLTVServer *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. SelectSourceTVServer(hltv); + RETURN_META(MRES_IGNORED); } void SourceTVManager::OnRemoveHLTVServer_Post(IHLTVServer *hltv) @@ -221,7 +249,29 @@ void SourceTVManager::OnRemoveHLTVServer_Post(IHLTVServer *hltv) else 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) { diff --git a/extension.h b/extension.h index fe4689b..008ee4d 100644 --- a/extension.h +++ b/extension.h @@ -43,6 +43,7 @@ #include "ihltvdirector.h" #include "ihltv.h" #include "iserver.h" +#include "iclient.h" #include "ihltvdemorecorder.h" #include "igameevents.h" @@ -126,9 +127,12 @@ public: IDemoRecorder *GetDemoRecorderPtr(IHLTVServer *hltvserver); private: +#if SOURCE_ENGINE == SE_CSGO void OnAddHLTVServer_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_Post(const char *s); diff --git a/forwards.cpp b/forwards.cpp index c3b7cc3..18ab2b1 100644 --- a/forwards.cpp +++ b/forwards.cpp @@ -35,7 +35,11 @@ CForwardManager g_pSTVForwards; 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 *) +#else +SH_DECL_HOOK0_void(IDemoRecorder, StopRecording, SH_NOATTRIB, 0) +#endif void CForwardManager::Init() { @@ -74,7 +78,11 @@ void CForwardManager::OnStartRecording_Post(const char *filename, bool bContinuo RETURN_META(MRES_IGNORED); } +#if SOURCE_ENGINE == SE_CSGO void CForwardManager::OnStopRecording_Post(CGameInfo const *info) +#else +void CForwardManager::OnStopRecording_Post() +#endif { if (m_StopRecordingFwd->GetFunctionCount() == 0) RETURN_META(MRES_IGNORED); diff --git a/forwards.h b/forwards.h index 3c984e6..ba529b4 100644 --- a/forwards.h +++ b/forwards.h @@ -47,7 +47,11 @@ public: private: void OnStartRecording_Post(const char *filename, bool bContinuously); +#if SOURCE_ENGINE == SE_CSGO void OnStopRecording_Post(CGameInfo const *info); +#else + void OnStopRecording_Post(); +#endif private: IForward *m_StartRecordingFwd; diff --git a/ihltvdemorecorder.h b/ihltvdemorecorder.h index f9d11d5..dc9c993 100644 --- a/ihltvdemorecorder.h +++ b/ihltvdemorecorder.h @@ -18,7 +18,11 @@ public: virtual bool IsRecording(void) = 0; virtual void PauseRecording(void) = 0; virtual void ResumeRecording(void) = 0; +#if SOURCE_ENGINE == SE_CSGO virtual void StopRecording(CGameInfo const *info) = 0; +#else + virtual void StopRecording(void) = 0; +#endif virtual void RecordCommand(const char *cmdstring) = 0; virtual void RecordUserInput(int cmdnumber) = 0; @@ -26,7 +30,9 @@ public: virtual void RecordPacket(void) = 0; virtual void RecordServerClasses(ServerClass *pClasses) = 0; virtual void RecordStringTables(void); +#if SOURCE_ENGINE == SE_CSGO virtual void RecordCustomData(int, void const *, unsigned int); +#endif virtual void ResetDemoInterpolation(void) = 0; }; diff --git a/natives.cpp b/natives.cpp index 8046b11..1298ab9 100644 --- a/natives.cpp +++ b/natives.cpp @@ -36,18 +36,32 @@ extern const sp_nativeinfo_t sourcetv_natives[]; // native SourceTV_GetHLTVServerCount(); static cell_t Native_GetHLTVServerCount(IPluginContext *pContext, const cell_t *params) { +#if SOURCE_ENGINE == SE_CSGO return hltvdirector->GetHLTVServerCount(); +#else + return hltvdirector->GetHLTVServer() ? 1 : 0; +#endif } // native SourceTV_SelectHLTVServer(); static cell_t Native_SelectHLTVServer(IPluginContext *pContext, const cell_t *params) { +#if SOURCE_ENGINE == SE_CSGO if (params[1] < 0 || params[1] >= hltvdirector->GetHLTVServerCount()) { pContext->ReportError("Invalid HLTV server instance number (%d).", params[1]); return 0; } 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; } @@ -58,6 +72,7 @@ static cell_t Native_GetSelectedHLTVServer(IPluginContext *pContext, const cell_ if (hltvserver == nullptr) return -1; +#if SOURCE_ENGINE == SE_CSGO for (int i = 0; i < hltvdirector->GetHLTVServerCount(); 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 hltvserver = nullptr; return -1; +#else + // There only is one hltv server. + return 0; +#endif } // native SourceTV_GetBotIndex(); @@ -228,10 +247,10 @@ static cell_t Native_GetViewCoordinates(IPluginContext *pContext, const cell_t * // native bool:SourceTV_IsRecording(); static cell_t Native_IsRecording(IPluginContext *pContext, const cell_t *params) { - if (hltvserver == nullptr) + if (demorecorder == nullptr) return 0; - return hltvserver->IsRecording(); + return demorecorder->IsRecording(); } // Checks in COM_IsValidPath in the engine @@ -243,7 +262,7 @@ static bool IsValidPath(const char *path) // native bool:SourceTV_StartRecording(const String:sFilename[]); static cell_t Native_StartRecording(IPluginContext *pContext, const cell_t *params) { - if (hltvserver == nullptr) + if (hltvserver == nullptr || demorecorder == nullptr) return 0; // SourceTV is not active. @@ -255,7 +274,7 @@ static cell_t Native_StartRecording(IPluginContext *pContext, const cell_t *para return 0; // already recording - if (hltvserver->IsRecording()) + if (demorecorder->IsRecording()) return 0; char *pFile; @@ -274,7 +293,8 @@ static cell_t Native_StartRecording(IPluginContext *pContext, const cell_t *para else ext = ""; smutils->Format(pPath, sizeof(pPath), "%s%s", pFile, ext); - + +#if SOURCE_ENGINE == SE_CSGO if (hltvdirector->GetHLTVServerCount() > 1) { 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; } } +#endif demorecorder->StartRecording(pPath, false); @@ -297,15 +318,18 @@ static cell_t Native_StartRecording(IPluginContext *pContext, const cell_t *para // native bool:SourceTV_StopRecording(); static cell_t Native_StopRecording(IPluginContext *pContext, const cell_t *params) { - if (hltvserver == nullptr) + if (demorecorder == nullptr) return 0; - if (!hltvserver->IsRecording()) + if (!demorecorder->IsRecording()) return 0; +#if SOURCE_ENGINE == SE_CSGO hltvserver->StopRecording(NULL); - // TODO: Stop recording on all other active hltvservers (tv_stoprecord in csgo does this) +#else + demorecorder->StopRecording(); +#endif return 1; } @@ -313,13 +337,13 @@ static cell_t Native_StopRecording(IPluginContext *pContext, const cell_t *param // native bool:SourceTV_GetDemoFileName(String:sFilename[], maxlen); static cell_t Native_GetDemoFileName(IPluginContext *pContext, const cell_t *params) { - if (hltvserver == nullptr) + if (demorecorder == nullptr) return 0; - if (!hltvserver->IsRecording()) + if (!demorecorder->IsRecording()) return 0; - char *pDemoFile = hltvserver->GetRecordingDemoFilename(); + char *pDemoFile = (char *)demorecorder->GetDemoFile(); if (!pDemoFile) return 0; diff --git a/sourcetvmanager.games.txt b/sourcetvmanager.games.txt index 52724d9..2956809 100644 --- a/sourcetvmanager.games.txt +++ b/sourcetvmanager.games.txt @@ -23,7 +23,6 @@ { "windows" "39" "linux" "40" - "mac" "40" } "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" + } + } + } } \ No newline at end of file