Skip to content

Commit 6e6bb4d

Browse files
Implement CScriptHookManager
1 parent 22f0b2c commit 6e6bb4d

File tree

7 files changed

+349
-87
lines changed

7 files changed

+349
-87
lines changed

sp/src/game/client/vscript_client.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class CScriptClientEntityIterator : public IClientEntityListener
114114

115115
void OnEntityCreated( CBaseEntity *pEntity )
116116
{
117-
if ( g_pScriptVM )
117+
if ( g_pScriptVM && GetScriptHookManager().IsEventHooked( "OnEntityCreated" ) )
118118
{
119119
// entity
120120
ScriptVariant_t args[] = { ScriptVariant_t( pEntity->GetScriptInstance() ) };
@@ -124,7 +124,7 @@ class CScriptClientEntityIterator : public IClientEntityListener
124124

125125
void OnEntityDeleted( CBaseEntity *pEntity )
126126
{
127-
if ( g_pScriptVM )
127+
if ( g_pScriptVM && GetScriptHookManager().IsEventHooked( "OnEntityDeleted" ) )
128128
{
129129
// entity
130130
ScriptVariant_t args[] = { ScriptVariant_t( pEntity->GetScriptInstance() ) };
@@ -645,6 +645,11 @@ bool VScriptClientInit()
645645
#else
646646
Log( "VSCRIPT: Started VScript virtual machine using script language '%s'\n", g_pScriptVM->GetLanguageName() );
647647
#endif
648+
649+
#ifdef MAPBASE_VSCRIPT
650+
GetScriptHookManager().OnInit();
651+
#endif
652+
648653
ScriptRegisterFunction( g_pScriptVM, GetMapName, "Get the name of the map.");
649654
ScriptRegisterFunction( g_pScriptVM, Time, "Get the current server time" );
650655
ScriptRegisterFunction( g_pScriptVM, DoUniqueString, SCRIPT_ALIAS( "UniqueString", "Generate a string guaranteed to be unique across the life of the script VM, with an optional root string." ) );
@@ -770,6 +775,8 @@ class CVScriptGameSystem : public CAutoGameSystemPerFrame
770775
{
771776
#ifdef MAPBASE_VSCRIPT
772777
g_ScriptNetMsg->LevelShutdownPreVM();
778+
779+
GetScriptHookManager().OnShutdown();
773780
#endif
774781
VScriptClientTerm();
775782
}

sp/src/game/server/vscript_server.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class CScriptEntityIterator : public IEntityListener
154154

155155
void OnEntityCreated( CBaseEntity *pEntity )
156156
{
157-
if ( g_pScriptVM )
157+
if ( g_pScriptVM && GetScriptHookManager().IsEventHooked( "OnEntityCreated" ) )
158158
{
159159
// entity
160160
ScriptVariant_t args[] = { ScriptVariant_t( pEntity->GetScriptInstance() ) };
@@ -164,7 +164,7 @@ class CScriptEntityIterator : public IEntityListener
164164

165165
void OnEntitySpawned( CBaseEntity *pEntity )
166166
{
167-
if ( g_pScriptVM )
167+
if ( g_pScriptVM && GetScriptHookManager().IsEventHooked( "OnEntitySpawned" ) )
168168
{
169169
// entity
170170
ScriptVariant_t args[] = { ScriptVariant_t( pEntity->GetScriptInstance() ) };
@@ -174,7 +174,7 @@ class CScriptEntityIterator : public IEntityListener
174174

175175
void OnEntityDeleted( CBaseEntity *pEntity )
176176
{
177-
if ( g_pScriptVM )
177+
if ( g_pScriptVM && GetScriptHookManager().IsEventHooked( "OnEntityDeleted" ) )
178178
{
179179
// entity
180180
ScriptVariant_t args[] = { ScriptVariant_t( pEntity->GetScriptInstance() ) };
@@ -600,6 +600,10 @@ bool VScriptServerInit()
600600
Log( "VSCRIPT: Started VScript virtual machine using script language '%s'\n", g_pScriptVM->GetLanguageName() );
601601
#endif
602602

603+
#ifdef MAPBASE_VSCRIPT
604+
GetScriptHookManager().OnInit();
605+
#endif
606+
603607
#ifdef MAPBASE_VSCRIPT
604608
// MULTIPLAYER
605609
// ScriptRegisterFunctionNamed( g_pScriptVM, UTIL_PlayerByIndex, "GetPlayerByIndex", "PlayerInstanceFromIndex" );
@@ -836,6 +840,8 @@ class CVScriptGameSystem : public CAutoGameSystemPerFrame
836840
{
837841
#ifdef MAPBASE_VSCRIPT
838842
g_ScriptNetMsg->LevelShutdownPreVM();
843+
844+
GetScriptHookManager().OnShutdown();
839845
#endif
840846
VScriptServerTerm();
841847
}

sp/src/game/shared/mapbase/vscript_singletons.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,8 @@ class CScriptSaveRestoreUtil : public CAutoGameSystem
872872
{
873873
if ( g_pScriptVM )
874874
{
875-
g_Hook_OnSave.Call( NULL, NULL, NULL );
875+
if ( GetScriptHookManager().IsEventHooked( "OnSave" ) )
876+
g_Hook_OnSave.Call( NULL, NULL, NULL );
876877

877878
// Legacy hook
878879
HSCRIPT hFunc = g_pScriptVM->LookupFunction( "OnSave" );
@@ -893,7 +894,8 @@ class CScriptSaveRestoreUtil : public CAutoGameSystem
893894
{
894895
if ( g_pScriptVM )
895896
{
896-
g_Hook_OnRestore.Call( NULL, NULL, NULL );
897+
if ( GetScriptHookManager().IsEventHooked( "OnRestore" ) )
898+
g_Hook_OnRestore.Call( NULL, NULL, NULL );
897899

898900
// Legacy hook
899901
HSCRIPT hFunc = g_pScriptVM->LookupFunction( "OnRestore" );

sp/src/game/shared/vscript_shared.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,10 @@ class CVScriptSaveRestoreBlockHandler : public CDefSaveRestoreBlockHandler
451451
}
452452
m_InstanceMap.Purge();
453453

454+
#ifdef MAPBASE_VSCRIPT
455+
GetScriptHookManager().OnRestore();
456+
#endif
457+
454458
#if defined(MAPBASE_VSCRIPT) && defined(CLIENT_DLL)
455459
VScriptSaveRestoreUtil_OnVMRestore();
456460
#endif

0 commit comments

Comments
 (0)