Skip to content

Commit

Permalink
Fixed some crashes related to server commands unregistration.
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanbriere committed Oct 4, 2021
1 parent 39ca701 commit 1604995
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
2 changes: 2 additions & 0 deletions addons/source-python/packages/source-python/cvars/__init__.py
Expand Up @@ -8,6 +8,7 @@
# Source.Python Imports
# Cvars
from _cvars import ConVar
from _cvars import SP_CVAR_DLL_IDENTIFIER
from _cvars import _Cvar
from cvars.flags import ConVarFlags

Expand All @@ -24,5 +25,6 @@
# >> ALL DECLARATION
# =============================================================================
__all__ = ('ConVar',
'SP_CVAR_DLL_IDENTIFIER',
'cvar',
)
9 changes: 7 additions & 2 deletions src/core/modules/commands/commands_say.cpp
Expand Up @@ -42,6 +42,7 @@

#include "commands_say.h"
#include "commands.h"
#include "modules/cvars/cvars.h"


//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -191,8 +192,12 @@ SayConCommand::~SayConCommand()
// Get the ConCommand instance
ConCommand* pConCommand = g_pCVar->FindCommand(m_Name);

// Unregister the ConCommand
g_pCVar->UnregisterConCommand(pConCommand);
// Was the command overwritten as a ConVar or by another DLL?
if (pConCommand && pConCommand->GetDLLIdentifier() == CVarDLLIdentifier())
{
// Unregister the ConCommand
g_pCVar->UnregisterConCommand(pConCommand);
}

// Was the command registered before we registered it?
if( m_pOldCommand )
Expand Down
9 changes: 7 additions & 2 deletions src/core/modules/commands/commands_server.cpp
Expand Up @@ -38,6 +38,7 @@

#include "commands.h"
#include "commands_server.h"
#include "modules/cvars/cvars.h"

//-----------------------------------------------------------------------------
// Externs.
Expand Down Expand Up @@ -162,8 +163,12 @@ CServerCommandManager::~CServerCommandManager()
// Get the ConCommand instance
ConCommand* pConCommand = g_pCVar->FindCommand(m_Name);

// Unregister the ConCommand
g_pCVar->UnregisterConCommand(pConCommand);
// Was the command overwritten as a ConVar or by another DLL?
if (pConCommand && pConCommand->GetDLLIdentifier() == CVarDLLIdentifier())
{
// Unregister the ConCommand
g_pCVar->UnregisterConCommand(pConCommand);
}

// Was the command registered before we registered it?
if( m_pOldCommand )
Expand Down
10 changes: 10 additions & 0 deletions src/core/modules/cvars/cvars.h
Expand Up @@ -34,6 +34,16 @@
#include "utilities/sp_util.h"


//-----------------------------------------------------------------------------
// Returns Source.Python's DLL identifier.
//-----------------------------------------------------------------------------
inline CVarDLLIdentifier_t CVarDLLIdentifier()
{
static CVarDLLIdentifier_t s_nDLLIdentifier = ConCommandBase().GetDLLIdentifier();
return s_nDLLIdentifier;
}


//-----------------------------------------------------------------------------
// ConVar extension class.
//-----------------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions src/core/modules/cvars/cvars_wrap.cpp
Expand Up @@ -63,6 +63,9 @@ DECLARE_SP_MODULE(_cvars)
export_convar_interface(_cvars);
export_convar(_cvars);
export_convar_flags(_cvars);

// Constants...
_cvars.attr("SP_CVAR_DLL_IDENTIFIER") = object(CVarDLLIdentifier());
}


Expand Down

0 comments on commit 1604995

Please sign in to comment.