Skip to content

Commit

Permalink
Implement CScriptHookManager
Browse files Browse the repository at this point in the history
  • Loading branch information
samisalreadytaken committed Jul 22, 2022
1 parent 22f0b2c commit 6e6bb4d
Show file tree
Hide file tree
Showing 7 changed files with 349 additions and 87 deletions.
11 changes: 9 additions & 2 deletions sp/src/game/client/vscript_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class CScriptClientEntityIterator : public IClientEntityListener

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

void OnEntityDeleted( CBaseEntity *pEntity )
{
if ( g_pScriptVM )
if ( g_pScriptVM && GetScriptHookManager().IsEventHooked( "OnEntityDeleted" ) )
{
// entity
ScriptVariant_t args[] = { ScriptVariant_t( pEntity->GetScriptInstance() ) };
Expand Down Expand Up @@ -645,6 +645,11 @@ bool VScriptClientInit()
#else
Log( "VSCRIPT: Started VScript virtual machine using script language '%s'\n", g_pScriptVM->GetLanguageName() );
#endif

#ifdef MAPBASE_VSCRIPT
GetScriptHookManager().OnInit();
#endif

ScriptRegisterFunction( g_pScriptVM, GetMapName, "Get the name of the map.");
ScriptRegisterFunction( g_pScriptVM, Time, "Get the current server time" );
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." ) );
Expand Down Expand Up @@ -770,6 +775,8 @@ class CVScriptGameSystem : public CAutoGameSystemPerFrame
{
#ifdef MAPBASE_VSCRIPT
g_ScriptNetMsg->LevelShutdownPreVM();

GetScriptHookManager().OnShutdown();
#endif
VScriptClientTerm();
}
Expand Down
12 changes: 9 additions & 3 deletions sp/src/game/server/vscript_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class CScriptEntityIterator : public IEntityListener

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

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

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

#ifdef MAPBASE_VSCRIPT
GetScriptHookManager().OnInit();
#endif

#ifdef MAPBASE_VSCRIPT
// MULTIPLAYER
// ScriptRegisterFunctionNamed( g_pScriptVM, UTIL_PlayerByIndex, "GetPlayerByIndex", "PlayerInstanceFromIndex" );
Expand Down Expand Up @@ -836,6 +840,8 @@ class CVScriptGameSystem : public CAutoGameSystemPerFrame
{
#ifdef MAPBASE_VSCRIPT
g_ScriptNetMsg->LevelShutdownPreVM();

GetScriptHookManager().OnShutdown();
#endif
VScriptServerTerm();
}
Expand Down
6 changes: 4 additions & 2 deletions sp/src/game/shared/mapbase/vscript_singletons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,8 @@ class CScriptSaveRestoreUtil : public CAutoGameSystem
{
if ( g_pScriptVM )
{
g_Hook_OnSave.Call( NULL, NULL, NULL );
if ( GetScriptHookManager().IsEventHooked( "OnSave" ) )
g_Hook_OnSave.Call( NULL, NULL, NULL );

// Legacy hook
HSCRIPT hFunc = g_pScriptVM->LookupFunction( "OnSave" );
Expand All @@ -893,7 +894,8 @@ class CScriptSaveRestoreUtil : public CAutoGameSystem
{
if ( g_pScriptVM )
{
g_Hook_OnRestore.Call( NULL, NULL, NULL );
if ( GetScriptHookManager().IsEventHooked( "OnRestore" ) )
g_Hook_OnRestore.Call( NULL, NULL, NULL );

// Legacy hook
HSCRIPT hFunc = g_pScriptVM->LookupFunction( "OnRestore" );
Expand Down
4 changes: 4 additions & 0 deletions sp/src/game/shared/vscript_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,10 @@ class CVScriptSaveRestoreBlockHandler : public CDefSaveRestoreBlockHandler
}
m_InstanceMap.Purge();

#ifdef MAPBASE_VSCRIPT
GetScriptHookManager().OnRestore();
#endif

#if defined(MAPBASE_VSCRIPT) && defined(CLIENT_DLL)
VScriptSaveRestoreUtil_OnVMRestore();
#endif
Expand Down
Loading

0 comments on commit 6e6bb4d

Please sign in to comment.