2
0
mirror of https://github.com/rehlds/revoice.git synced 2024-12-27 23:25:53 +03:00

Client codec detection code

This commit is contained in:
thecrock 2015-12-13 17:48:22 +04:00
parent a493f845a0
commit 6775e6b67c
12 changed files with 208 additions and 29 deletions

View File

@ -31,6 +31,7 @@
<ClInclude Include="..\src\osconf.h" />
<ClInclude Include="..\src\precompiled.h" />
<ClInclude Include="..\src\revoice_cfg.h" />
<ClInclude Include="..\src\revoice_main.h" />
<ClInclude Include="..\src\revoice_player.h" />
<ClInclude Include="..\src\revoice_rehlds_api.h" />
<ClInclude Include="..\src\revoice_shared.h" />
@ -50,6 +51,8 @@
</ClCompile>
<ClCompile Include="..\src\public_amalgamation.cpp" />
<ClCompile Include="..\src\revoice_cfg.cpp" />
<ClCompile Include="..\src\revoice_main.cpp" />
<ClCompile Include="..\src\revoice_player.cpp" />
<ClCompile Include="..\src\revoice_rehlds_api.cpp" />
<ClCompile Include="..\src\revoice_utils.cpp" />
<ClCompile Include="..\src\sdk_util.cpp" />

View File

@ -90,6 +90,9 @@
<ClInclude Include="..\src\VoiceEncoder_Speex.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="..\src\revoice_main.h">
<Filter>src</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\dllapi.cpp">
@ -134,5 +137,11 @@
<ClCompile Include="..\src\VoiceEncoder_Speex.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\src\revoice_player.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\src\revoice_main.cpp">
<Filter>src</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -4,27 +4,27 @@
#include "utlbuffer.h"
#include "SKP_Silk_SDK_API.h"
class VoiceEncoder_Silk : public IVoiceCodec {
private:
void * m_pEncoder; /* 4 4 */
int m_API_fs_Hz; /* 8 4 */
int m_targetRate_bps; /* 12 4 */
int m_packetLoss_perc; /* 16 4 */
SKP_SILK_SDK_EncControlStruct m_encControl; /* 20 32 */
CUtlBuffer m_bufOverflowBytes; /* 52 24 */
void * m_pDecoder; /* 76 4 */
SKP_SILK_SDK_DecControlStruct m_decControl; /* 80 20 */
public:
VoiceEncoder_Silk();
virtual ~VoiceEncoder_Silk();
virtual bool Init(int quality);
virtual void Release();
virtual bool ResetState();
virtual int Compress(const char *pUncompressedBytes, int nSamples, char *pCompressed, int maxCompressedBytes, bool bFinal);
virtual int Decompress(const char *pCompressed, int compressedBytes, char *pUncompressed, int maxUncompressedBytes);
class VoiceEncoder_Silk : public IVoiceCodec {
private:
void * m_pEncoder; /* 4 4 */
int m_API_fs_Hz; /* 8 4 */
int m_targetRate_bps; /* 12 4 */
int m_packetLoss_perc; /* 16 4 */
SKP_SILK_SDK_EncControlStruct m_encControl; /* 20 32 */
CUtlBuffer m_bufOverflowBytes; /* 52 24 */
void * m_pDecoder; /* 76 4 */
SKP_SILK_SDK_DecControlStruct m_decControl; /* 80 20 */
public:
VoiceEncoder_Silk();
virtual ~VoiceEncoder_Silk();
virtual bool Init(int quality);
virtual void Release();
virtual bool ResetState();
virtual int Compress(const char *pUncompressedBytes, int nSamples, char *pCompressed, int maxCompressedBytes, bool bFinal);
virtual int Decompress(const char *pCompressed, int compressedBytes, char *pUncompressed, int maxUncompressedBytes);
}; /* size: 100 */

View File

@ -5,7 +5,7 @@
#include "speex.h"
/* <61c> ../engine/voice_codecs/speex/VoiceEncoder_Speex.h:57 */
class VoiceEncoder_Speex: IFrameEncoder {
class VoiceEncoder_Speex: public IFrameEncoder {
protected:
virtual ~VoiceEncoder_Speex();

View File

@ -51,7 +51,7 @@ static DLL_FUNCTIONS gFunctionTable =
NULL, // pfnRestoreGlobalState
NULL, // pfnResetGlobalState
NULL, // pfnClientConnect
&mm_ClientConnect,
NULL, // pfnClientDisconnect
NULL, // pfnClientKill
NULL, // pfnClientPutInServer
@ -95,6 +95,15 @@ static DLL_FUNCTIONS gFunctionTable =
NULL, // pfnAllowLagCompensation
};
static NEW_DLL_FUNCTIONS gNewFunctionTable = {
NULL, //pfnOnFreeEntPrivateData
NULL, //pfnGameShutdown
NULL, //pfnShouldCollide
NULL, //pfnCvarValue
&mm_CvarValue2, //pfnCvarValue2
};
C_DLLEXPORT int GetEntityAPI2(DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion)
{
if(!pFunctionTable) {
@ -109,4 +118,19 @@ C_DLLEXPORT int GetEntityAPI2(DLL_FUNCTIONS *pFunctionTable, int *interfaceVersi
}
memcpy(pFunctionTable, &gFunctionTable, sizeof(DLL_FUNCTIONS));
return(TRUE);
}
C_DLLEXPORT int GetNewDLLFunctions(NEW_DLL_FUNCTIONS *pNewFunctionTable, int *interfaceVersion) {
if (!pNewFunctionTable) {
UTIL_LogPrintf("GetNewDLLFunctions called with null pNewFunctionTable");
return(FALSE);
}
else if (*interfaceVersion != NEW_DLL_FUNCTIONS_VERSION) {
UTIL_LogPrintf("GetNewDLLFunctions version mismatch; requested=%d ours=%d", *interfaceVersion, NEW_DLL_FUNCTIONS_VERSION);
//! Tell metamod what version we had, so it can figure out who is out of date.
*interfaceVersion = NEW_DLL_FUNCTIONS_VERSION;
return(FALSE);
}
memcpy(pNewFunctionTable, &gNewFunctionTable, sizeof(NEW_DLL_FUNCTIONS));
return(TRUE);
}

View File

@ -42,7 +42,7 @@ static META_FUNCTIONS gMetaFunctionTable = {
NULL, // pfnGetEntityAPI_Post META; called after game DLL
&GetEntityAPI2, // pfnGetEntityAPI2 HL SDK2; called before game DLL
NULL, // pfnGetEntityAPI2_Post META; called after game DLL
NULL, // pfnGetNewDLLFunctions HL SDK2; called before game DLL
&GetNewDLLFunctions, // pfnGetNewDLLFunctions HL SDK2; called before game DLL
NULL, // pfnGetNewDLLFunctions_Post META; called after game DLL
NULL, // pfnGetEngineFunctions META; called before HL engine
NULL, // pfnGetEngineFunctions_Post META; called after HL engine

View File

@ -1,3 +1,5 @@
#pragma once
#include "osconf.h"
#include "sys_shared.h"
#include "crc32c.h"
@ -19,6 +21,8 @@
#include "VoiceEncoder_Silk.h"
#include "VoiceEncoder_Speex.h"
#include "voice_codec_frame.h"
#include "revoice_player.h"
#include "revoice_main.h"
#include "interface.h"
#include "utlbuffer.h"
#include "utlbuffer.h"

View File

@ -0,0 +1,56 @@
#include "precompiled.h"
int g_ClientBeingConnected_Protocol = 0;
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) {
CRevoicePlayer* plr = GetPlayerByClientPtr(cl);
plr->OnConnected(g_ClientBeingConnected_Protocol);
if (g_ClientBeingConnected_Protocol == 47) {
plr->InitVoice(vct_speex);
} else {
g_engfuncs.pfnQueryClientCvarValue2(cl->GetEdict(), "sv_version", 0);
}
}
chain->callNext(cl);
}
void mm_CvarValue2(const edict_t *pEnt, int requestID, const char *cvarName, const char *value) {
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, ',');
int buildNumber = 0;
if (lastSeparator) {
buildNumber = atoi(lastSeparator + 1);
}
CRevoicePlayer* plr = GetPlayerByEdict(pEnt);
if (buildNumber > 4554) {
plr->InitVoice(vct_silk);
} else {
plr->InitVoice(vct_speex);
}
}
RETURN_META(MRES_IGNORED);
}
qboolean mm_ClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[128]) {
RETURN_META_VALUE(MRES_IGNORED, 1);
}
bool Revoice_Main_Init() {
g_RehldsHookchains->SV_ConnectClient()->registerHook(SV_ConnectClient_hook);
g_RehldsHookchains->ClientConnected()->registerHook(Rehlds_ClientConnected_Hook);
return true;
}

View File

@ -0,0 +1,9 @@
#pragma once
#include "revoice_shared.h"
#include "revoice_player.h"
extern qboolean mm_ClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[128]);
extern void mm_CvarValue2(const edict_t *pEnt, int requestID, const char *cvarName, const char *value);
extern bool Revoice_Main_Init();

View File

@ -0,0 +1,52 @@
#include "precompiled.h"
CRevoicePlayer g_Players[MAX_PLAYERS];
CRevoicePlayer::CRevoicePlayer() {
m_CodecType = vct_none;
m_SpeexCodec = new VoiceCodec_Frame(new VoiceEncoder_Speex());
m_SilkCodec = new VoiceEncoder_Silk();
m_SpeexCodec->Init(5);
m_SilkCodec->Init(5);
m_RehldsClient = NULL;
m_Protocol = 0;
}
void CRevoicePlayer::Initialize(IGameClient* cl) {
m_RehldsClient = cl;
}
void CRevoicePlayer::InitVoice(revoice_codec_type codecType) {
m_CodecType = codecType;
m_SilkCodec->ResetState();
m_SpeexCodec->ResetState();
}
void CRevoicePlayer::OnConnected(int protocol) {
m_Protocol = protocol;
m_CodecType = vct_none;
}
void Revoice_Init_Players() {
int maxclients = g_RehldsSvs->GetMaxClients();
for (int i = 0; i < maxclients; i++) {
g_Players[i].Initialize(g_RehldsSvs->GetClient(i));
}
}
CRevoicePlayer* GetPlayerByClientPtr(IGameClient* cl) {
return &g_Players[cl->GetId()];
}
CRevoicePlayer* GetPlayerByEdict(const edict_t* ed) {
int clientId = g_engfuncs.pfnIndexOfEdict(ed) - 1;
if (clientId < 0 || clientId >= g_RehldsSvs->GetMaxClients()) {
util_syserror("Invalid player edict id=%d\n", clientId);
}
return &g_Players[clientId];
}

View File

@ -1,10 +1,29 @@
#pragma once
#include "revoice_shared.h"
#include "VoiceEncoder_Silk.h"
#include "VoiceEncoder_Speex.h"
#include "voice_codec_frame.h"
class CRevoicePlayer {
private:
IGameClient* m_RehldsClient;
revoice_codec_type m_CodecType;
VoiceEncoder_Silk* m_SilkCodec;
IVoiceCodec* m_SpeexCodec;
};
VoiceCodec_Frame* m_SpeexCodec;
int m_Protocol;
public:
CRevoicePlayer();
void Initialize(IGameClient* cl);
void OnConnected(int protocol);
void InitVoice(revoice_codec_type codecType);
};
extern CRevoicePlayer g_Players[MAX_PLAYERS];
extern void Revoice_Init_Players();
extern CRevoicePlayer* GetPlayerByClientPtr(IGameClient* cl);
extern CRevoicePlayer* GetPlayerByEdict(const edict_t* ed);

View File

@ -1,5 +1,8 @@
#pragma once
#include "IVoiceCodec.h"
#include "iframeencoder.h"
/* <19b1> ../engine/voice_codecs/speex/../frame_encoder/voice_codec_frame.cpp:18 */
class VoiceCodec_Frame: public IVoiceCodec {
public: