From 5741936fb6dba87e05706b535705bf6dbb5fc7f1 Mon Sep 17 00:00:00 2001 From: maxime1907 <19607336+maxime1907@users.noreply.github.com> Date: Sat, 4 Dec 2021 00:15:25 +0100 Subject: [PATCH] Add back compatibility with csgo (LittleQWord problem) --- extension.cpp | 2 ++ inetworksystem.h | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/extension.cpp b/extension.cpp index 71cf212..80ecfd7 100644 --- a/extension.cpp +++ b/extension.cpp @@ -98,6 +98,8 @@ ConVar *g_SvCountBotsInfo = CreateConVar("sv_count_bots_info", "1", FCVAR_NOTIFY ConVar *g_SvCountBotsPlayer = CreateConVar("sv_count_bots_player", "0", FCVAR_NOTIFY, "Display bots as players in the a2s_player server query. Enable = '1', Disable = '0'"); #if SOURCE_ENGINE < SE_CSGO ConVar *g_SvHostNameStore = CreateConVar("host_name_store", "1", FCVAR_NOTIFY, "Whether hostname is recorded in game events and GOTV."); +#else +ConVar *g_SvHostNameStore = NULL; #endif ConVar *g_pSvVisibleMaxPlayers = NULL; ConVar *g_pSvTags = NULL; diff --git a/inetworksystem.h b/inetworksystem.h index 6d02a0e..afe24a2 100644 --- a/inetworksystem.h +++ b/inetworksystem.h @@ -13,6 +13,62 @@ #include "tier0/platform.h" #include "appframework/IAppSystem.h" +// FIX FOR CSGO SDK THAT DOESNT DEFINES LittleQWord + +#ifndef QWordSwap + #ifdef _DEBUG + #if !defined( PLAT_COMPILE_TIME_ASSERT ) + #define PLAT_COMPILE_TIME_ASSERT( pred ) switch(0){case 0:case pred:;} + #endif + #else + #if !defined( PLAT_COMPILE_TIME_ASSERT ) + #define PLAT_COMPILE_TIME_ASSERT( pred ) + #endif + #endif + + template + inline T QWordSwapC( T dw ) + { + // Assert sizes passed to this are already correct, otherwise + // the cast to uint64 * below is unsafe and may have wrong results + // or even crash. + PLAT_COMPILE_TIME_ASSERT( sizeof( dw ) == sizeof(uint64) ); + + uint64 temp; + + temp = *((uint64 *)&dw) >> 56; + temp |= ((*((uint64 *)&dw) & 0x00FF000000000000ull) >> 40); + temp |= ((*((uint64 *)&dw) & 0x0000FF0000000000ull) >> 24); + temp |= ((*((uint64 *)&dw) & 0x000000FF00000000ull) >> 8); + temp |= ((*((uint64 *)&dw) & 0x00000000FF000000ull) << 8); + temp |= ((*((uint64 *)&dw) & 0x0000000000FF0000ull) << 24); + temp |= ((*((uint64 *)&dw) & 0x000000000000FF00ull) << 40); + temp |= ((*((uint64 *)&dw) & 0x00000000000000FFull) << 56); + + return *((T*)&temp); + } + + // No ASM implementation for this yet + #define QWordSwap QWordSwapC + + //------------------------------------- + // The typically used methods. + //------------------------------------- + + #if (defined( _SGI_SOURCE ) || defined( _X360 )) || defined( PLATFORM_X360 ) && !defined CUSTOM_PLAT_BIG_ENDIAN + #define CUSTOM_PLAT_BIG_ENDIAN 1 + #else + #define CUSTOM_PLAT_LITTLE_ENDIAN 1 + #endif + + #if defined(CUSTOM_PLAT_LITTLE_ENDIAN) + #define LittleQWord( val ) ( val ) + #elif defined(CUSTOM_PLAT_BIG_ENDIAN) + #define LittleQWord( val ) QWordSwap( val ) + #else + inline uint64 LittleQWord( uint64 val ) { int test = 1; return ( *(char *)&test == 1 ) ? val : QWordSwap( val ); } + #endif +#endif // This is the packet payload without any header bytes (which are attached for actual sending) #define NET_MAX_PAYLOAD ( 262144 - 4) // largest message we can send in bytes