mirror of
https://github.com/srcdslab/sm-ext-voice.git
synced 2025-12-07 10:38:22 +00:00
fix: win build
This commit is contained in:
parent
4a3f225486
commit
ddc62f1baf
@ -222,28 +222,42 @@ DETOUR_DECL_STATIC2(SV_BroadcastVoiceData_LTCG, void, char *, data, int64, xuid)
|
|||||||
IClient *pClient = NULL;
|
IClient *pClient = NULL;
|
||||||
int nBytes = 0;
|
int nBytes = 0;
|
||||||
|
|
||||||
|
#ifndef WIN64
|
||||||
__asm mov pClient, ecx;
|
__asm mov pClient, ecx;
|
||||||
__asm mov nBytes, edx;
|
__asm mov nBytes, edx;
|
||||||
|
#endif
|
||||||
|
|
||||||
bool ret = g_Interface.OnBroadcastVoiceData(pClient, nBytes, data);
|
bool ret = g_Interface.OnBroadcastVoiceData(pClient, nBytes, data);
|
||||||
|
|
||||||
|
#ifndef WIN64
|
||||||
__asm mov ecx, pClient;
|
__asm mov ecx, pClient;
|
||||||
__asm mov edx, nBytes;
|
__asm mov edx, nBytes;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (ret)
|
if (ret)
|
||||||
DETOUR_STATIC_CALL(SV_BroadcastVoiceData_LTCG)(data, xuid);
|
DETOUR_STATIC_CALL(SV_BroadcastVoiceData_LTCG)(data, xuid);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
double getTime()
|
#ifdef _WIN32
|
||||||
{
|
double getTime() {
|
||||||
struct timespec tv;
|
LARGE_INTEGER freq, count;
|
||||||
if(clock_gettime(CLOCK_REALTIME, &tv) != 0)
|
if (!QueryPerformanceFrequency(&freq) || !QueryPerformanceCounter(&count)) {
|
||||||
return 0;
|
return 0.0;
|
||||||
|
}
|
||||||
return (tv.tv_sec + (tv.tv_nsec / 1000000000.0));
|
return static_cast<double>(count.QuadPart) / static_cast<double>(freq.QuadPart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
double getTime() {
|
||||||
|
struct timespec tv;
|
||||||
|
if (clock_gettime(CLOCK_REALTIME, &tv) != 0) {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
return tv.tv_sec + tv.tv_nsec / 1e9;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void OnGameFrame(bool simulating)
|
void OnGameFrame(bool simulating)
|
||||||
{
|
{
|
||||||
g_Interface.OnGameFrame(simulating);
|
g_Interface.OnGameFrame(simulating);
|
||||||
@ -450,7 +464,7 @@ void CVoice::SDK_OnAllLoaded()
|
|||||||
}
|
}
|
||||||
|
|
||||||
int yes = 1;
|
int yes = 1;
|
||||||
if(setsockopt(m_ListenSocket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) < 0)
|
if(setsockopt(m_ListenSocket, SOL_SOCKET, SO_REUSEADDR, (const char*)&yes, sizeof(yes)) < 0)
|
||||||
{
|
{
|
||||||
smutils->LogError(myself, "Failed setting SO_REUSEADDR on socket.");
|
smutils->LogError(myself, "Failed setting SO_REUSEADDR on socket.");
|
||||||
SDK_OnUnload();
|
SDK_OnUnload();
|
||||||
@ -494,7 +508,7 @@ int my_poll(struct pollfd *fds, int nfds, int timeout)
|
|||||||
int my_ioctl(socket_t sockfd, long cmd, size_t *argp)
|
int my_ioctl(socket_t sockfd, long cmd, size_t *argp)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
return ioctlsocket(sockfd, cmd, argp); // Windows version
|
return ioctlsocket(sockfd, cmd, reinterpret_cast<u_long*>(argp)); // Windows version
|
||||||
#else
|
#else
|
||||||
return ioctl(sockfd, cmd, argp); // Linux/macOS version
|
return ioctl(sockfd, cmd, argp); // Linux/macOS version
|
||||||
#endif
|
#endif
|
||||||
@ -707,7 +721,7 @@ void CVoice::HandleNetwork()
|
|||||||
m_Buffer.SetWriteIndex(pClient->m_BufferWriteIndex);
|
m_Buffer.SetWriteIndex(pClient->m_BufferWriteIndex);
|
||||||
|
|
||||||
// Don't recv() when we can't fit data into the ringbuffer
|
// Don't recv() when we can't fit data into the ringbuffer
|
||||||
unsigned char aBuf[32768];
|
char aBuf[32768];
|
||||||
if(min_ext(BytesAvailable, sizeof(aBuf)) > m_Buffer.CurrentFree() * sizeof(int16_t))
|
if(min_ext(BytesAvailable, sizeof(aBuf)) > m_Buffer.CurrentFree() * sizeof(int16_t))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -849,7 +863,7 @@ void CVoice::HandleVoiceData()
|
|||||||
for(size_t Frame = 0; Frame < FramesAvailable; Frame++)
|
for(size_t Frame = 0; Frame < FramesAvailable; Frame++)
|
||||||
{
|
{
|
||||||
// Get data into buffer from ringbuffer.
|
// Get data into buffer from ringbuffer.
|
||||||
int16_t aBuffer[SamplesPerFrame];
|
int16_t *aBuffer = new int16_t[SamplesPerFrame];
|
||||||
|
|
||||||
size_t OldReadIdx = m_Buffer.m_ReadIndex;
|
size_t OldReadIdx = m_Buffer.m_ReadIndex;
|
||||||
size_t OldCurLength = m_Buffer.CurrentLength();
|
size_t OldCurLength = m_Buffer.CurrentLength();
|
||||||
@ -862,12 +876,12 @@ void CVoice::HandleVoiceData()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Encode it!
|
// Encode it!
|
||||||
unsigned char aFinal[packetSize];
|
unsigned char *aFinal = new unsigned char[packetSize];
|
||||||
int FinalSize = 0;
|
int FinalSize = 0;
|
||||||
|
|
||||||
if (m_pCodec)
|
if (m_pCodec)
|
||||||
{
|
{
|
||||||
FinalSize = celt_encode(m_pCodec, aBuffer, SamplesPerFrame, aFinal, sizeof(aFinal));
|
FinalSize = celt_encode(m_pCodec, aBuffer, SamplesPerFrame, aFinal, packetSize);
|
||||||
|
|
||||||
if(FinalSize <= 0)
|
if(FinalSize <= 0)
|
||||||
{
|
{
|
||||||
@ -899,6 +913,9 @@ void CVoice::HandleVoiceData()
|
|||||||
}
|
}
|
||||||
|
|
||||||
BroadcastVoiceData(pClient, FinalSize, aFinal);
|
BroadcastVoiceData(pClient, FinalSize, aFinal);
|
||||||
|
|
||||||
|
delete[] aBuffer;
|
||||||
|
delete[] aFinal;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_AvailableTime < getTime())
|
if(m_AvailableTime < getTime())
|
||||||
@ -965,11 +982,15 @@ void CVoice::BroadcastVoiceData(IClient *pClient, size_t nBytes, unsigned char *
|
|||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
#ifndef WIN64
|
||||||
__asm mov ecx, pClient;
|
__asm mov ecx, pClient;
|
||||||
__asm mov edx, nBytes;
|
__asm mov edx, nBytes;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (g_SvCallOriginalBroadcast->GetInt())
|
||||||
DETOUR_STATIC_CALL(SV_BroadcastVoiceData_LTCG)((char *)pData, 0);
|
DETOUR_STATIC_CALL(SV_BroadcastVoiceData_LTCG)((char *)pData, 0);
|
||||||
#else
|
#else
|
||||||
|
if (g_SvCallOriginalBroadcast->GetInt())
|
||||||
DETOUR_STATIC_CALL(SV_BroadcastVoiceData)(pClient, nBytes, (char *)pData, 0);
|
DETOUR_STATIC_CALL(SV_BroadcastVoiceData)(pClient, nBytes, (char *)pData, 0);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user