2
0
mirror of https://github.com/rehlds/revoice.git synced 2024-12-28 15:45:52 +03:00
Conflicts:
	revoice/msvc/ReVoice.vcxproj.filters
	revoice/src/VoiceEncoder_Speex.cpp
	revoice/src/revoice_main.cpp
This commit is contained in:
thecrock 2015-12-14 17:16:15 +04:00
commit 81a705a87a
13 changed files with 122 additions and 32 deletions

View File

@ -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<qboolean, IGameClient*, const void*, unsigned int> 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 {

View File

@ -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;

View File

@ -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
}

View File

@ -25,6 +25,7 @@
<ClInclude Include="..\include\sdk_util.h" />
<ClInclude Include="..\include\types_meta.h" />
<ClInclude Include="..\public\IVoiceCodec.h" />
<ClInclude Include="..\public\reunion_api.h" />
<ClInclude Include="..\public\utlbuffer.h" />
<ClInclude Include="..\public\utlmemory.h" />
<ClInclude Include="..\src\iframeencoder.h" />
@ -34,6 +35,7 @@
<ClInclude Include="..\src\revoice_main.h" />
<ClInclude Include="..\src\revoice_player.h" />
<ClInclude Include="..\src\revoice_rehlds_api.h" />
<ClInclude Include="..\src\revoice_reunion_api.h" />
<ClInclude Include="..\src\revoice_shared.h" />
<ClInclude Include="..\src\SteamP2PCodec.h" />
<ClInclude Include="..\src\VoiceEncoder_Silk.h" />
@ -55,6 +57,7 @@
<ClCompile Include="..\src\revoice_main.cpp" />
<ClCompile Include="..\src\revoice_player.cpp" />
<ClCompile Include="..\src\revoice_rehlds_api.cpp" />
<ClCompile Include="..\src\revoice_reunion_api.cpp" />
<ClCompile Include="..\src\revoice_utils.cpp" />
<ClCompile Include="..\src\sdk_util.cpp" />
<ClCompile Include="..\src\SteamP2PCodec.cpp" />
@ -112,7 +115,7 @@
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;REVOICE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;REVOICE_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(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)</AdditionalIncludeDirectories>
<PrecompiledHeaderFile>precompiled.h</PrecompiledHeaderFile>
</ClCompile>
@ -136,7 +139,7 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;REVOICE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;REVOICE_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(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)</AdditionalIncludeDirectories>
<PrecompiledHeaderFile>precompiled.h</PrecompiledHeaderFile>
</ClCompile>

View File

@ -96,6 +96,12 @@
<ClInclude Include="..\src\SteamP2PCodec.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="..\public\reunion_api.h">
<Filter>public</Filter>
</ClInclude>
<ClInclude Include="..\src\revoice_reunion_api.h">
<Filter>src</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\dllapi.cpp">
@ -149,5 +155,8 @@
<ClCompile Include="..\src\SteamP2PCodec.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\src\revoice_reunion_api.cpp">
<Filter>src</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -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

View File

@ -55,6 +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);
postfilter = 1;
speex_decoder_ctl(m_DecoderState, SPEEX_SET_ENH, &postfilter);

View File

@ -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");

View File

@ -27,3 +27,5 @@
#include "interface.h"
#include "utlbuffer.h"
#include "reunion_api.h"
#include "revoice_reunion_api.h"

View File

@ -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;

View File

@ -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(value, ',');
const char* lastSeparator = strrchr(cvarValue, ',');
int buildNumber = 0;
if (lastSeparator) {
buildNumber = atoi(lastSeparator + 1);
@ -63,6 +58,9 @@ 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();
@ -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;
@ -90,10 +85,6 @@ void SV_ParseVoiceData_emu(IGameClient* cl) {
switch (srcPlayer->GetCodecType()) {
case vct_silk:
{
CRC32_t hCrc;
g_engfuncs.pfnCRC32_Init(&hCrc);
g_engfuncs.pfnCRC32_ProcessBuffer(&hCrc, chReceived, nDataLength - 4);
hCrc = g_engfuncs.pfnCRC32_Final(hCrc);
silkData = chReceived; silkDataLen = nDataLength;
speexData = transcodedBuf;
speexDataLen = TranscodeVoice(silkData, silkDataLen, srcPlayer->GetSilkCodec(), srcPlayer->GetSpeexCodec(), transcodedBuf, sizeof(transcodedBuf));
@ -114,7 +105,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())
@ -168,7 +159,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) {
@ -195,7 +186,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);

View File

@ -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;
}

View File

@ -0,0 +1,5 @@
#pragma once
extern IReunionApi* g_ReunionApi;
extern bool Revoice_ReunionApi_Init();