Merge pull request #206 from samisalreadytaken/fix

Fix CScriptNetMsgHelper::WriteEntity()
This commit is contained in:
Blixibon 2022-10-21 22:54:12 -05:00 committed by GitHub
commit 216ea46c25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

View File

@ -740,7 +740,11 @@ void CScriptGameEventListener::StopListeningForEvent()
#ifdef _DEBUG #ifdef _DEBUG
// Event listeners are iterated forwards in the game event manager, // Event listeners are iterated forwards in the game event manager,
// removing while iterating will cause it to skip one listener. // removing while iterating will cause it to skip one listener.
// This could be prevented by writing a custom game event manager. //
// Fix this in engine without altering any behaviour by
// changing event exeuction order to tail->head,
// changing listener removal to tail->head,
// changing listener addition to head
if ( m_nEventTick == gpGlobals->tickcount ) if ( m_nEventTick == gpGlobals->tickcount )
{ {
Warning("CScriptGameEventListener stopped in the same frame it was fired. This will break other event listeners!\n"); Warning("CScriptGameEventListener stopped in the same frame it was fired. This will break other event listeners!\n");
@ -1749,8 +1753,8 @@ void CNetMsgScriptHelper::WriteEntity( HSCRIPT hEnt )
{ {
SCRIPT_NETMSG_WRITE_FUNC SCRIPT_NETMSG_WRITE_FUNC
CBaseEntity *p = ToEnt(hEnt); CBaseEntity *p = ToEnt(hEnt);
int i = p ? p->entindex() : -1; int i = p ? p->entindex() : 0;
m_MsgOut.WriteSBitLong( i, MAX_EDICT_BITS ); m_MsgOut.WriteUBitLong( i, MAX_EDICT_BITS );
} }
void CNetMsgScriptHelper::WriteEHandle( HSCRIPT hEnt ) void CNetMsgScriptHelper::WriteEHandle( HSCRIPT hEnt )
@ -1861,7 +1865,11 @@ bool CNetMsgScriptHelper::ReadBool()
HSCRIPT CNetMsgScriptHelper::ReadEntity() HSCRIPT CNetMsgScriptHelper::ReadEntity()
{ {
int index = m_MsgIn_()ReadSBitLong( MAX_EDICT_BITS ); int index = m_MsgIn_()ReadUBitLong( MAX_EDICT_BITS );
if ( !index )
return NULL;
#ifdef GAME_DLL #ifdef GAME_DLL
edict_t *e = INDEXENT(index); edict_t *e = INDEXENT(index);
if ( e && !e->IsFree() ) if ( e && !e->IsFree() )

View File

@ -2779,7 +2779,6 @@ bool SquirrelVM::GenerateUniqueKey(const char* pszRoot, char* pBuf, int nBufSize
static int keyIdx = 0; static int keyIdx = 0;
// This gets used for script scope, still confused why it needs to be inside IScriptVM // This gets used for script scope, still confused why it needs to be inside IScriptVM
// is it just to be a compatible name for CreateScope? // is it just to be a compatible name for CreateScope?
SquirrelSafeCheck safeCheck(vm_);
V_snprintf(pBuf, nBufSize, "%08X_%s", ++keyIdx, pszRoot); V_snprintf(pBuf, nBufSize, "%08X_%s", ++keyIdx, pszRoot);
return true; return true;
} }