From 10910e8b8e8e70902355d0dfa136dec3164005e2 Mon Sep 17 00:00:00 2001 From: Peace-Maker Date: Sun, 6 Mar 2016 12:26:45 +0100 Subject: [PATCH] Pass the right SourceTV instance index in forwards --- forwards.cpp | 20 ++++++++++++++++---- hltvserverwrapper.cpp | 11 +++++++++++ hltvserverwrapper.h | 1 + 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/forwards.cpp b/forwards.cpp index 2228171..9f9e3d6 100644 --- a/forwards.cpp +++ b/forwards.cpp @@ -31,6 +31,7 @@ #include "extension.h" #include "forwards.h" +#include "hltvserverwrapper.h" CForwardManager g_pSTVForwards; @@ -196,13 +197,13 @@ void CForwardManager::UnhookClient(IClient *client) void CForwardManager::CallOnServerStart(IHLTVServer *server) { - m_ServerStartFwd->PushCell(0); // TODO: Get right hltvinstance + m_ServerStartFwd->PushCell(g_HLTVServers.GetInstanceNumber(server)); m_ServerStartFwd->Execute(); } void CForwardManager::CallOnServerShutdown(IHLTVServer *server) { - m_ServerShutdownFwd->PushCell(0); // TODO: Get right hltvinstance + m_ServerShutdownFwd->PushCell(g_HLTVServers.GetInstanceNumber(server)); m_ServerShutdownFwd->Execute(); } @@ -365,7 +366,13 @@ void CForwardManager::OnStartRecording_Post(const char *filename, bool bContinuo if (m_StartRecordingFwd->GetFunctionCount() == 0) RETURN_META(MRES_IGNORED); - m_StartRecordingFwd->PushCell(0); // TODO: Get current hltvserver index + IDemoRecorder *recorder = META_IFACEPTR(IDemoRecorder); + HLTVServerWrapper *wrapper = g_HLTVServers.GetWrapper(recorder); + int instance = -1; + if (wrapper) + instance = wrapper->GetInstanceNumber(); + + m_StartRecordingFwd->PushCell(instance); m_StartRecordingFwd->PushString(filename); m_StartRecordingFwd->Execute(); @@ -387,7 +394,12 @@ void CForwardManager::OnStopRecording_Post() char *pDemoFile = (char *)recorder->GetDemoFile(); - m_StopRecordingFwd->PushCell(0); // TODO: Get current hltvserver index + HLTVServerWrapper *wrapper = g_HLTVServers.GetWrapper(recorder); + int instance = -1; + if (wrapper) + instance = wrapper->GetInstanceNumber(); + + m_StopRecordingFwd->PushCell(instance); m_StopRecordingFwd->PushString(pDemoFile); m_StopRecordingFwd->PushCell(recorder->GetRecordingTick()); m_StopRecordingFwd->Execute(); diff --git a/hltvserverwrapper.cpp b/hltvserverwrapper.cpp index 81e40e5..0badc7c 100644 --- a/hltvserverwrapper.cpp +++ b/hltvserverwrapper.cpp @@ -277,6 +277,17 @@ HLTVServerWrapper *HLTVServerWrapperManager::GetWrapper(IHLTVServer *hltvserver) return nullptr; } +HLTVServerWrapper *HLTVServerWrapperManager::GetWrapper(IDemoRecorder *demorecorder) +{ + for (unsigned int i = 0; i < m_HLTVServers.length(); i++) + { + HLTVServerWrapper *wrapper = m_HLTVServers[i]; + if (wrapper->GetDemoRecorder() == demorecorder) + return wrapper; + } + return nullptr; +} + int HLTVServerWrapperManager::GetInstanceNumber(IHLTVServer *hltvserver) { #if SOURCE_ENGINE == SE_CSGO diff --git a/hltvserverwrapper.h b/hltvserverwrapper.h index a1d1b0f..3bddb41 100644 --- a/hltvserverwrapper.h +++ b/hltvserverwrapper.h @@ -73,6 +73,7 @@ public: void AddServer(IHLTVServer *hltvserver); void RemoveServer(IHLTVServer *hltvserver, bool bInformPlugins); HLTVServerWrapper *GetWrapper(IHLTVServer *hltvserver); + HLTVServerWrapper *GetWrapper(IDemoRecorder *demorecorder); int GetInstanceNumber(IHLTVServer *hltvserver); IDemoRecorder *GetDemoRecorderPtr(IHLTVServer *hltv);