From ef898de18d1c3ec82ce4b90dd880f6e4a513b794 Mon Sep 17 00:00:00 2001 From: Jordan Cristiano Date: Thu, 11 Jan 2018 01:35:00 -0500 Subject: [PATCH] Updated SVC_VoiceInit for latest TF2 version. --- demboyz/netmessages/svc_voiceinit.cpp | 26 ++++++++++++++-- demboyz/netmessages/svc_voiceinit.h | 3 ++ .../include/sourcesdk/valve_support.h | 30 +++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/demboyz/netmessages/svc_voiceinit.cpp b/demboyz/netmessages/svc_voiceinit.cpp index 805b23d..95fd0b9 100644 --- a/demboyz/netmessages/svc_voiceinit.cpp +++ b/demboyz/netmessages/svc_voiceinit.cpp @@ -9,6 +9,15 @@ namespace NetHandlers { bitbuf.ReadString(data->voiceCodec, sizeof(data->voiceCodec)); data->quality = bitbuf.ReadByte(); + if(data->quality == NetMsg::SVC_VoiceInit::QUALITY_HAS_SAMPLE_RATE) + { + data->sampleRate = bitbuf.ReadShort(); + } + else + { + // V_strnicmp < 1 is from them, not me. + data->sampleRate = V_strnicmp(data->voiceCodec, "vaudio_celt", sizeof(data->voiceCodec)) < 1 ? 22050 : 11025; + } return !bitbuf.IsOverflowed(); } @@ -16,6 +25,10 @@ namespace NetHandlers { bitbuf.WriteString(data->voiceCodec); bitbuf.WriteByte(data->quality); + if(data->quality == NetMsg::SVC_VoiceInit::QUALITY_HAS_SAMPLE_RATE) + { + bitbuf.WriteShort(data->sampleRate); + } return !bitbuf.IsOverflowed(); } @@ -25,6 +38,7 @@ namespace NetHandlers assert(!reader.HasReadError()); reader.ReadString("voiceCodec", data->voiceCodec, sizeof(data->voiceCodec)); data->quality = reader.ReadUInt32("quality"); + data->sampleRate = reader.ReadInt32("sampleRate"); return !reader.HasReadError(); } @@ -34,13 +48,21 @@ namespace NetHandlers jsonbuf.StartObject(); jsonbuf.WriteString("voiceCodec", data->voiceCodec); jsonbuf.WriteUInt32("quality", data->quality); + jsonbuf.WriteInt32("sampleRate", data->sampleRate); jsonbuf.EndObject(); return jsonbuf.IsComplete(); } void SVC_VoiceInit_ToString_Internal(std::ostringstream& out, NetMsg::SVC_VoiceInit* data) { - out << "svc_VoiceInit: codec \"" << data->voiceCodec - << "\", qualitty " << static_cast(data->quality); + out << "svc_VoiceInit: codec \"" << data->voiceCodec; + if(data->quality == NetMsg::SVC_VoiceInit::QUALITY_HAS_SAMPLE_RATE) + { + out << "\", sample rate " << static_cast(data->sampleRate); + } + else + { + out << "\", qualitty " << static_cast(data->quality); + } } } diff --git a/demboyz/netmessages/svc_voiceinit.h b/demboyz/netmessages/svc_voiceinit.h index f302160..e932bb3 100644 --- a/demboyz/netmessages/svc_voiceinit.h +++ b/demboyz/netmessages/svc_voiceinit.h @@ -7,8 +7,11 @@ namespace NetMsg { struct SVC_VoiceInit { + static const uint8_t QUALITY_HAS_SAMPLE_RATE = 255; + char voiceCodec[MAX_OSPATH]; // used voice codec .dll uint8_t quality; // custom quality setting + int32_t sampleRate; // Hz }; } diff --git a/external/sourcesdk/include/sourcesdk/valve_support.h b/external/sourcesdk/include/sourcesdk/valve_support.h index 8eceb1a..c185989 100644 --- a/external/sourcesdk/include/sourcesdk/valve_support.h +++ b/external/sourcesdk/include/sourcesdk/valve_support.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "vector.h" using uint64 = std::uint64_t; @@ -160,3 +161,32 @@ inline int GetBitForBitnum( int bitNum ) }; return bitsForBitnum[ (bitNum) & (BITS_PER_INT-1) ]; } + +#ifndef _WIN32 +#define _strnicmp strncasecmp +#endif + +inline int V_strnicmp( const char *str1, const char *str2, int n ) +{ + const unsigned char *s1 = (const unsigned char*)str1; + const unsigned char *s2 = (const unsigned char*)str2; + for ( ; n > 0 && *s1; --n, ++s1, ++s2 ) + { + if ( *s1 != *s2 ) + { + // in ascii char set, lowercase = uppercase | 0x20 + unsigned char c1 = *s1 | 0x20; + unsigned char c2 = *s2 | 0x20; + if ( c1 != c2 || (unsigned char)(c1 - 'a') > ('z' - 'a') ) + { + // if non-ascii mismatch, fall back to CRT for locale + if ( (c1 | c2) >= 0x80 ) return _strnicmp( (const char*)s1, (const char*)s2, n ); + // ascii mismatch. only use the | 0x20 value if alphabetic. + if ((unsigned char)(c1 - 'a') > ('z' - 'a')) c1 = *s1; + if ((unsigned char)(c2 - 'a') > ('z' - 'a')) c2 = *s2; + return c1 > c2 ? 1 : -1; + } + } + } + return (n > 0 && *s2) ? -1 : 0; +}