Skip to content

Commit 1604995

Browse files
committed
Fixed some crashes related to server commands unregistration.
1 parent 39ca701 commit 1604995

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-4
lines changed

Diff for: addons/source-python/packages/source-python/cvars/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# Source.Python Imports
99
# Cvars
1010
from _cvars import ConVar
11+
from _cvars import SP_CVAR_DLL_IDENTIFIER
1112
from _cvars import _Cvar
1213
from cvars.flags import ConVarFlags
1314

@@ -24,5 +25,6 @@
2425
# >> ALL DECLARATION
2526
# =============================================================================
2627
__all__ = ('ConVar',
28+
'SP_CVAR_DLL_IDENTIFIER',
2729
'cvar',
2830
)

Diff for: src/core/modules/commands/commands_say.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
#include "commands_say.h"
4444
#include "commands.h"
45+
#include "modules/cvars/cvars.h"
4546

4647

4748
//-----------------------------------------------------------------------------
@@ -191,8 +192,12 @@ SayConCommand::~SayConCommand()
191192
// Get the ConCommand instance
192193
ConCommand* pConCommand = g_pCVar->FindCommand(m_Name);
193194

194-
// Unregister the ConCommand
195-
g_pCVar->UnregisterConCommand(pConCommand);
195+
// Was the command overwritten as a ConVar or by another DLL?
196+
if (pConCommand && pConCommand->GetDLLIdentifier() == CVarDLLIdentifier())
197+
{
198+
// Unregister the ConCommand
199+
g_pCVar->UnregisterConCommand(pConCommand);
200+
}
196201

197202
// Was the command registered before we registered it?
198203
if( m_pOldCommand )

Diff for: src/core/modules/commands/commands_server.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
#include "commands.h"
4040
#include "commands_server.h"
41+
#include "modules/cvars/cvars.h"
4142

4243
//-----------------------------------------------------------------------------
4344
// Externs.
@@ -162,8 +163,12 @@ CServerCommandManager::~CServerCommandManager()
162163
// Get the ConCommand instance
163164
ConCommand* pConCommand = g_pCVar->FindCommand(m_Name);
164165

165-
// Unregister the ConCommand
166-
g_pCVar->UnregisterConCommand(pConCommand);
166+
// Was the command overwritten as a ConVar or by another DLL?
167+
if (pConCommand && pConCommand->GetDLLIdentifier() == CVarDLLIdentifier())
168+
{
169+
// Unregister the ConCommand
170+
g_pCVar->UnregisterConCommand(pConCommand);
171+
}
167172

168173
// Was the command registered before we registered it?
169174
if( m_pOldCommand )

Diff for: src/core/modules/cvars/cvars.h

+10
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@
3434
#include "utilities/sp_util.h"
3535

3636

37+
//-----------------------------------------------------------------------------
38+
// Returns Source.Python's DLL identifier.
39+
//-----------------------------------------------------------------------------
40+
inline CVarDLLIdentifier_t CVarDLLIdentifier()
41+
{
42+
static CVarDLLIdentifier_t s_nDLLIdentifier = ConCommandBase().GetDLLIdentifier();
43+
return s_nDLLIdentifier;
44+
}
45+
46+
3747
//-----------------------------------------------------------------------------
3848
// ConVar extension class.
3949
//-----------------------------------------------------------------------------

Diff for: src/core/modules/cvars/cvars_wrap.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ DECLARE_SP_MODULE(_cvars)
6363
export_convar_interface(_cvars);
6464
export_convar(_cvars);
6565
export_convar_flags(_cvars);
66+
67+
// Constants...
68+
_cvars.attr("SP_CVAR_DLL_IDENTIFIER") = object(CVarDLLIdentifier());
6669
}
6770

6871

0 commit comments

Comments
 (0)