From f5837d068f9ac6e49e9ef679f4b5f00f00bc91fc Mon Sep 17 00:00:00 2001 From: samisalreadytaken <46823719+samisalreadytaken@users.noreply.github.com> Date: Tue, 27 Dec 2022 16:00:08 +0300 Subject: [PATCH] Change vscript net message header size to 4 bytes from 2 bytes to reduce hash collisions --- sp/src/game/shared/mapbase/vscript_singletons.cpp | 5 ++--- sp/src/game/shared/mapbase/vscript_singletons.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/sp/src/game/shared/mapbase/vscript_singletons.cpp b/sp/src/game/shared/mapbase/vscript_singletons.cpp index e313f82f..eeb50d84 100644 --- a/sp/src/game/shared/mapbase/vscript_singletons.cpp +++ b/sp/src/game/shared/mapbase/vscript_singletons.cpp @@ -1338,8 +1338,7 @@ static const char *HasNetMsgCollision( int hash, const char *ignore ) inline int CNetMsgScriptHelper::Hash( const char *key ) { - int hash = HashStringCaseless( key ); - Assert( hash < (1 << SCRIPT_NETMSG_HEADER_BITS) ); + int hash = CaselessStringHashFunctor()( key ); return hash; } @@ -1923,7 +1922,7 @@ BEGIN_SCRIPTDESC_ROOT_NAMED( CNetMsgScriptHelper, "CNetMsg", SCRIPT_SINGLETON "N DEFINE_SCRIPTFUNC( Receive, "Set custom network message callback" ) DEFINE_SCRIPTFUNC_NAMED( Receive, "Recieve", SCRIPT_HIDE ) // This was a typo until v6.3 #ifdef GAME_DLL - DEFINE_SCRIPTFUNC( Send, "Send a custom network message from the server to the client (max 252 bytes)" ) + DEFINE_SCRIPTFUNC( Send, "Send a custom network message from the server to the client (max 251 bytes)" ) #else DEFINE_SCRIPTFUNC( Send, "Send a custom network message from the client to the server (max 2044 bytes)" ) #endif diff --git a/sp/src/game/shared/mapbase/vscript_singletons.h b/sp/src/game/shared/mapbase/vscript_singletons.h index e514f4d9..b20cc67c 100644 --- a/sp/src/game/shared/mapbase/vscript_singletons.h +++ b/sp/src/game/shared/mapbase/vscript_singletons.h @@ -24,7 +24,7 @@ void RegisterScriptSingletons(); #endif #define SCRIPT_NETMSG_QUEUE_BITS 3 // determines the number of custom messages client can write to a usercmd -#define SCRIPT_NETMSG_HEADER_BITS (sizeof(word) << 3) +#define SCRIPT_NETMSG_HEADER_BITS (sizeof(unsigned int) << 3) #define SCRIPT_NETMSG_STRING_SIZE 512