From 21d6a223c5dce40c691d3211daa11cefa9365625 Mon Sep 17 00:00:00 2001 From: asmodai Date: Mon, 14 Dec 2015 01:54:05 +0300 Subject: [PATCH] Using Reunion API for protocol detection Updated ReHLDS SDK Small fixes --- dep/rehlsdk/engine/rehlds_api.h | 4 ++- dep/rehlsdk/engine/rehlds_interfaces.h | 3 ++- dep/rehlsdk/engine/sys_shared.cpp | 17 ++++++++++++- revoice/msvc/ReVoice.vcxproj | 7 ++++-- revoice/msvc/ReVoice.vcxproj.filters | 9 +++++++ revoice/public/reunion_api.h | 35 ++++++++++++++++++++++++++ revoice/src/VoiceEncoder_Speex.cpp | 2 +- revoice/src/meta_api.cpp | 3 +++ revoice/src/precompiled.h | 2 ++ revoice/src/revoice_cfg.cpp | 10 ++++---- revoice/src/revoice_main.cpp | 30 +++++++++------------- revoice/src/revoice_reunion_api.cpp | 24 ++++++++++++++++++ revoice/src/revoice_reunion_api.h | 5 ++++ 13 files changed, 122 insertions(+), 29 deletions(-) create mode 100644 revoice/public/reunion_api.h create mode 100644 revoice/src/revoice_reunion_api.cpp create mode 100644 revoice/src/revoice_reunion_api.h diff --git a/dep/rehlsdk/engine/rehlds_api.h b/dep/rehlsdk/engine/rehlds_api.h index 2857c5b..b5b14de 100644 --- a/dep/rehlsdk/engine/rehlds_api.h +++ b/dep/rehlsdk/engine/rehlds_api.h @@ -35,7 +35,7 @@ #include "model.h" #define REHLDS_API_VERSION_MAJOR 2 -#define REHLDS_API_VERSION_MINOR 3 +#define REHLDS_API_VERSION_MINOR 4 //Steam_NotifyClientConnect hook typedef IHookChain IRehldsHook_Steam_NotifyClientConnect; @@ -233,6 +233,8 @@ struct RehldsFuncs_t { void(*MSG_WriteByte)(sizebuf_t *sb, int c); void(*MSG_WriteShort)(sizebuf_t *sb, int c); void(*MSG_WriteString)(sizebuf_t *sb, const char *s); + void*(*GetPluginApi)(const char *name); + void(*RegisterPluginApi)(const char *name, void *impl); }; class IRehldsApi { diff --git a/dep/rehlsdk/engine/rehlds_interfaces.h b/dep/rehlsdk/engine/rehlds_interfaces.h index ea74dc3..d30af0f 100644 --- a/dep/rehlsdk/engine/rehlds_interfaces.h +++ b/dep/rehlsdk/engine/rehlds_interfaces.h @@ -67,7 +67,8 @@ public: virtual bool IsConnected() = 0; virtual void SetConnected(bool connected) = 0; - virtual uint32 GetVoiceStreams(int id) = 0; + virtual uint32 GetVoiceStream(int stream_id) = 0; + virtual void SetLastVoiceTime(double time) = 0; virtual double GetLastVoiceTime() = 0; virtual bool GetLoopback() = 0; diff --git a/dep/rehlsdk/engine/sys_shared.cpp b/dep/rehlsdk/engine/sys_shared.cpp index 67594e6..e671f46 100644 --- a/dep/rehlsdk/engine/sys_shared.cpp +++ b/dep/rehlsdk/engine/sys_shared.cpp @@ -42,7 +42,15 @@ cpuinfo_t cpuinfo; void Sys_CheckCpuInstructionsSupport(void) { - int cpuid_data[4] = { 0,0,0,0 }; + unsigned int cpuid_data[4]; + +#if defined ASMLIB_H + cpuid_ex((int *)cpuid_data, 1, 0); +#elif defined(__GNUC__) + __get_cpuid(0x1, &cpuid_data[0], &cpuid_data[1], &cpuid_data[2], &cpuid_data[3]); +#else + __cpuidex((int *)cpuid_data, 1, 0); +#endif cpuinfo.sse3 = (cpuid_data[2] & SSE3_FLAG) ? 1 : 0; // ecx cpuinfo.ssse3 = (cpuid_data[2] & SSSE3_FLAG) ? 1 : 0; @@ -50,6 +58,13 @@ void Sys_CheckCpuInstructionsSupport(void) cpuinfo.sse4_2 = (cpuid_data[2] & SSE4_2_FLAG) ? 1 : 0; cpuinfo.avx = (cpuid_data[2] & AVX_FLAG) ? 1 : 0; +#if defined ASMLIB_H + cpuid_ex((int *)cpuid_data, 7, 0); +#elif defined(__GNUC__) + __get_cpuid(0x7, &cpuid_data[0], &cpuid_data[1], &cpuid_data[2], &cpuid_data[3]); +#else + __cpuidex((int *)cpuid_data, 7, 0); +#endif cpuinfo.avx2 = (cpuid_data[1] & AVX2_FLAG) ? 1 : 0; // ebx } \ No newline at end of file diff --git a/revoice/msvc/ReVoice.vcxproj b/revoice/msvc/ReVoice.vcxproj index 36e956c..e389ffb 100644 --- a/revoice/msvc/ReVoice.vcxproj +++ b/revoice/msvc/ReVoice.vcxproj @@ -25,6 +25,7 @@ + @@ -34,6 +35,7 @@ + @@ -54,6 +56,7 @@ + @@ -110,7 +113,7 @@ Use Level3 Disabled - WIN32;_DEBUG;_WINDOWS;_USRDLL;REVOICE_EXPORTS;%(PreprocessorDefinitions) + WIN32;_DEBUG;_WINDOWS;_USRDLL;REVOICE_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) $(ProjectDir)../src/;$(ProjectDir)../public/;$(ProjectDir)../version/;$(ProjectDir)../include/;$(SolutionDir)../dep/rehlsdk/common/;$(SolutionDir)../dep/rehlsdk/dlls/;$(SolutionDir)../dep/rehlsdk/engine/;$(SolutionDir)../dep/rehlsdk/public/;$(SolutionDir)../dep/silk/include/;$(SolutionDir)../dep/speex/include/;$(SolutionDir)../dep/metamod/;%(AdditionalIncludeDirectories) precompiled.h @@ -128,7 +131,7 @@ MaxSpeed true true - WIN32;NDEBUG;_WINDOWS;_USRDLL;REVOICE_EXPORTS;%(PreprocessorDefinitions) + WIN32;NDEBUG;_WINDOWS;_USRDLL;REVOICE_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) $(ProjectDir)../src/;$(ProjectDir)../public/;$(ProjectDir)../version/;$(ProjectDir)../include/;$(SolutionDir)../dep/rehlsdk/common/;$(SolutionDir)../dep/rehlsdk/dlls/;$(SolutionDir)../dep/rehlsdk/engine/;$(SolutionDir)../dep/rehlsdk/public/;$(SolutionDir)../dep/silk/include/;$(SolutionDir)../dep/speex/include/;$(SolutionDir)../dep/metamod/;%(AdditionalIncludeDirectories) precompiled.h diff --git a/revoice/msvc/ReVoice.vcxproj.filters b/revoice/msvc/ReVoice.vcxproj.filters index f9c453d..b8e5fda 100644 --- a/revoice/msvc/ReVoice.vcxproj.filters +++ b/revoice/msvc/ReVoice.vcxproj.filters @@ -93,6 +93,12 @@ src + + public + + + src + @@ -143,5 +149,8 @@ src + + src + \ No newline at end of file diff --git a/revoice/public/reunion_api.h b/revoice/public/reunion_api.h new file mode 100644 index 0000000..56fd77c --- /dev/null +++ b/revoice/public/reunion_api.h @@ -0,0 +1,35 @@ +#ifndef REUNION_API_H +#define REUNION_API_H + +#define REUNION_API_VERSION_MAJOR 1 +#define REUNION_API_VERSION_MINOR 0 + +enum dp_authkind_e +{ + DP_AUTH_NONE = 0, + DP_AUTH_DPROTO = 1, + DP_AUTH_STEAM = 2, + DP_AUTH_STEAMEMU = 3, + DP_AUTH_REVEMU = 4, + DP_AUTH_OLDREVEMU = 5, + DP_AUTH_HLTV = 6, + DP_AUTH_SC2009 = 7, + DP_AUTH_AVSMP = 8, + DP_AUTH_SXEI = 9, + DP_AUTH_REVEMU2013 = 10, + DP_AUTH_SSE3 = 11, +}; + +class IReunionApi +{ +public: + int version_major; + int version_minor; + + virtual int GetClientProtocol(int index) = 0; + virtual dp_authkind_e GetClientAuthtype(int index) = 0; + + virtual size_t GetClientAuthdata(int index, void *data, int maxlen) = 0; +}; + +#endif // REUNION_API_H \ No newline at end of file diff --git a/revoice/src/VoiceEncoder_Speex.cpp b/revoice/src/VoiceEncoder_Speex.cpp index 3f70a0c..e7a20f7 100644 --- a/revoice/src/VoiceEncoder_Speex.cpp +++ b/revoice/src/VoiceEncoder_Speex.cpp @@ -55,7 +55,7 @@ bool VoiceEncoder_Speex::Init(int quality, int &rawFrameSize, int &encodedFrameS encodedFrameSize = ENCODED_FRAME_SIZE[m_Quality]; speex_encoder_ctl(m_EncoderState, SPEEX_SET_QUALITY, &m_Quality); - speex_decoder_ctl(m_DecoderState, SPEEX_SET_QUALITY, &m_Quality); + //speex_decoder_ctl(m_DecoderState, SPEEX_SET_QUALITY, &m_Quality); postfilter = 1; speex_decoder_ctl(m_DecoderState, SPEEX_SET_ENH, &postfilter); diff --git a/revoice/src/meta_api.cpp b/revoice/src/meta_api.cpp index 2e2a640..b9e2b95 100644 --- a/revoice/src/meta_api.cpp +++ b/revoice/src/meta_api.cpp @@ -121,6 +121,9 @@ bool Revoice_Load() { return false; } + if (!Revoice_ReunionApi_Init()) + return false; + Revoice_Init_Players(); if (!Revoice_Main_Init()) { LCPrintf(true, "Initialization failed\n"); diff --git a/revoice/src/precompiled.h b/revoice/src/precompiled.h index 3e3974d..5230e77 100644 --- a/revoice/src/precompiled.h +++ b/revoice/src/precompiled.h @@ -26,3 +26,5 @@ #include "interface.h" #include "utlbuffer.h" +#include "reunion_api.h" +#include "revoice_reunion_api.h" diff --git a/revoice/src/revoice_cfg.cpp b/revoice/src/revoice_cfg.cpp index d09363d..a2a4462 100644 --- a/revoice/src/revoice_cfg.cpp +++ b/revoice/src/revoice_cfg.cpp @@ -74,7 +74,7 @@ CRevoiceConfig* CRevoiceConfig::createDefault() bool CRevoiceConfig::parseCfgParam(const char* param, const char* value) { -#define REU_CFG_PARSE_INT(paramName, field, _type, minVal, maxVal) \ +#define REV_CFG_PARSE_INT(paramName, field, _type, minVal, maxVal) \ if (!strcasecmp(paramName, param)) { \ int i = atoi(value); \ if (i < minVal || i > maxVal) { \ @@ -85,13 +85,13 @@ bool CRevoiceConfig::parseCfgParam(const char* param, const char* value) return true; \ } -#define REU_CFG_PARSE_IP(paramName, field) \ +#define REV_CFG_PARSE_IP(paramName, field) \ if (!strcasecmp(paramName, param)) { \ field = inet_addr(value); \ return true; \ } -#define REU_CFG_PARSE_BOOL(paramName, field) \ +#define REV_CFG_PARSE_BOOL(paramName, field) \ if (!strcasecmp(paramName, param)) { \ int i = atoi(value); \ if (i < 0 || i > 1) { \ @@ -102,14 +102,14 @@ bool CRevoiceConfig::parseCfgParam(const char* param, const char* value) return true; \ } -#define REU_CFG_PARSE_STR(paramName, field) \ +#define REV_CFG_PARSE_STR(paramName, field) \ if (!strcasecmp(paramName, param)) { \ strncpy(field, value, ARRAYSIZE(field) - 1); \ field[ARRAYSIZE(field) - 1] = 0; \ return true; \ } - REU_CFG_PARSE_INT("LoggingMode", m_LogMode, int, rl_none, (rl_console|rl_logfile)); + REV_CFG_PARSE_INT("LoggingMode", m_LogMode, int, rl_none, (rl_console|rl_logfile)); LCPrintf(true, " Config line parsing failed: unknown parameter '%s'\n", param); return false; diff --git a/revoice/src/revoice_main.cpp b/revoice/src/revoice_main.cpp index 321978f..840b9a5 100644 --- a/revoice/src/revoice_main.cpp +++ b/revoice/src/revoice_main.cpp @@ -1,20 +1,15 @@ #include "precompiled.h" -int g_ClientBeingConnected_Protocol = 0; cvar_t* pcv_sv_voiceenable = NULL; -void SV_ConnectClient_hook(IRehldsHook_SV_ConnectClient* chain) { - g_ClientBeingConnected_Protocol = atoi(g_engfuncs.pfnCmd_Argv(1)); - chain->callNext(); -} - void Rehlds_ClientConnected_Hook(IRehldsHook_ClientConnected* chain, IGameClient* cl) { - if (g_ClientBeingConnected_Protocol >= 47 && g_ClientBeingConnected_Protocol <= 48) { + int protocol = g_ReunionApi->GetClientProtocol(cl->GetId()); + if (protocol >= 47 && protocol <= 48) { CRevoicePlayer* plr = GetPlayerByClientPtr(cl); - plr->OnConnected(g_ClientBeingConnected_Protocol); + plr->OnConnected(protocol); - if (g_ClientBeingConnected_Protocol == 47) { + if (protocol == 47) { plr->InitVoice(vct_speex); } @@ -30,12 +25,12 @@ void SV_DropClient_hook(IRehldsHook_SV_DropClient* chain, IGameClient* cl, bool chain->callNext(cl, crash, msg); } -void mm_CvarValue2(const edict_t *pEnt, int requestID, const char *cvarName, const char *value) { +void mm_CvarValue2(const edict_t *pEnt, int requestID, const char *cvarName, const char *cvarValue) { if (!strcmp("sv_version", cvarName)) { // ] sv_version // "sv_version" is "1.1.2.1/2.0.0.0,48,4554" - const char* lastSeparator = strrchr(cvarName, ','); + const char* lastSeparator = strrchr(cvarValue, ','); int buildNumber = 0; if (lastSeparator) { buildNumber = atoi(lastSeparator + 1); @@ -63,9 +58,12 @@ int TranscodeVoice(const char* srcBuf, int srcBufLen, IVoiceCodec* srcCodec, IVo } void SV_ParseVoiceData_emu(IGameClient* cl) { + if (pcv_sv_voiceenable->value == 0.0f) + return; + char chReceived[4096]; unsigned int nDataLength = g_RehldsFuncs->MSG_ReadShort(); - + if (nDataLength > sizeof(chReceived)) { g_RehldsFuncs->DropClient(cl, FALSE, "Invalid voice data\n"); @@ -75,9 +73,6 @@ void SV_ParseVoiceData_emu(IGameClient* cl) { g_RehldsFuncs->MSG_ReadBuf(nDataLength, chReceived); //cl->m_lastvoicetime = g_RehldsSv->GetTime(); - if (pcv_sv_voiceenable->value == 0.0f) - return; - CRevoicePlayer* srcPlayer = GetPlayerByClientPtr(cl); if (srcPlayer->GetCodecType() == vct_none) { return; @@ -108,7 +103,7 @@ void SV_ParseVoiceData_emu(IGameClient* cl) { CRevoicePlayer* dstPlayer = &g_Players[i]; IGameClient* dstClient = dstPlayer->GetClient(); - if (!((1 << (i & 0x1F)) & cl->GetVoiceStreams(i >> 5)) && i != cl->GetId()) + if (!((1 << (i & 0x1F)) & cl->GetVoiceStream(i >> 5)) && i != cl->GetId()) continue; if (!dstClient->IsActive() && !dstClient->IsConnected() && i != cl->GetId()) @@ -162,7 +157,7 @@ qboolean mm_ClientConnect(edict_t *pEntity, const char *pszName, const char *psz if (plr->GetProtocol() == 48) { g_engfuncs.pfnQueryClientCvarValue2(pEntity, "sv_version", 0); } - RETURN_META_VALUE(MRES_IGNORED, 1); + RETURN_META_VALUE(MRES_IGNORED, TRUE); } void SV_WriteVoiceCodec_hooked(IRehldsHook_SV_WriteVoiceCodec* chain, sizebuf_t* sb) { @@ -189,7 +184,6 @@ void SV_WriteVoiceCodec_hooked(IRehldsHook_SV_WriteVoiceCodec* chain, sizebuf_t* } bool Revoice_Main_Init() { - g_RehldsHookchains->SV_ConnectClient()->registerHook(SV_ConnectClient_hook); g_RehldsHookchains->ClientConnected()->registerHook(Rehlds_ClientConnected_Hook); g_RehldsHookchains->SV_DropClient()->registerHook(SV_DropClient_hook); g_RehldsHookchains->HandleNetCommand()->registerHook(Rehlds_HandleNetCommand); diff --git a/revoice/src/revoice_reunion_api.cpp b/revoice/src/revoice_reunion_api.cpp new file mode 100644 index 0000000..b126b23 --- /dev/null +++ b/revoice/src/revoice_reunion_api.cpp @@ -0,0 +1,24 @@ +#include "precompiled.h" + +IReunionApi* g_ReunionApi; + +bool Revoice_ReunionApi_Init() { + g_ReunionApi = (IReunionApi *)g_RehldsFuncs->GetPluginApi("reunion"); + + if (g_ReunionApi == NULL) { + LCPrintf(true, "Failed to locate Reunion api\n"); + return false; + } + + if (g_ReunionApi->version_major != REUNION_API_VERSION_MAJOR) { + LCPrintf(true, "Reunion API major version mismatch; expected %d, real %d\n", REUNION_API_VERSION_MAJOR, g_ReunionApi->version_major); + return false; + } + + if (g_ReunionApi->version_minor < REUNION_API_VERSION_MINOR) { + LCPrintf(true, "Reunion API minor version mismatch; expected at least %d, real %d\n", REUNION_API_VERSION_MINOR, g_ReunionApi->version_minor); + return false; + } + + return true; +} diff --git a/revoice/src/revoice_reunion_api.h b/revoice/src/revoice_reunion_api.h new file mode 100644 index 0000000..ba6a435 --- /dev/null +++ b/revoice/src/revoice_reunion_api.h @@ -0,0 +1,5 @@ +#pragma once + +extern IReunionApi* g_ReunionApi; + +extern bool Revoice_ReunionApi_Init();