diff --git a/scripting/include/srccoop/blackmesa/entitypatch.inc b/scripting/include/srccoop/blackmesa/entitypatch.inc index 8bcfcdea..1f7234a4 100644 --- a/scripting/include/srccoop/blackmesa/entitypatch.inc +++ b/scripting/include/srccoop/blackmesa/entitypatch.inc @@ -234,7 +234,8 @@ void MarionettistManipulate(int iMarionettist, int iClient, CBasePlayer pPlayer) // start it pPuppet.AcceptInputStr("Manipulate", "!activator", pPlayer); - DHookEntity(hkThink, true, pPuppet.GetEntIndex(), _, Hook_MarionettistPuppetThinkPost); + hkThink.HookEntity(Hook_Post, pPuppet.GetEntIndex(), Hook_MarionettistPuppetThinkPost); + hkUpdateOnRemove.HookEntity(Hook_Post, pPuppet.GetEntIndex(), Hook_MarionettistPuppetRemoved); g_pActiveMarionettist[iClient] = pPuppet; } @@ -293,11 +294,12 @@ public MRESReturn Hook_MarionettistPuppetThinkPost(int _this) } // Catches all sources of removal, potentially resets player noclip. -void OnEntityDestroyed_Marionettist(CBaseEntity pEntity) +MRESReturn Hook_MarionettistPuppetRemoved(int iEntIndex) { + CBaseEntity pPuppet = CBaseEntity(iEntIndex); for (int i = 1; i <= MaxClients; i++) { - if (g_pActiveMarionettist[i] == pEntity) + if (g_pActiveMarionettist[i] == pPuppet) { if (GetEntProp(g_pActiveMarionettist[i].GetEntIndex(), Prop_Data, "m_bIgnoreCollisions")) { @@ -311,6 +313,7 @@ void OnEntityDestroyed_Marionettist(CBaseEntity pEntity) break; } } + return MRES_Ignored; } //------------------------------------------------------ diff --git a/scripting/include/srccoop_api.inc b/scripting/include/srccoop_api.inc index 9bab2484..06be5798 100644 --- a/scripting/include/srccoop_api.inc +++ b/scripting/include/srccoop_api.inc @@ -30,14 +30,18 @@ #include #include -stock void InitSourceCoopAddon() +stock GameData InitSourceCoopAddon(bool bCloseGameData = true) { GameData pGameConfig = LoadGameConfigFile(SRCCOOP_GAMEDATA_NAME); if (pGameConfig == null) SetFailState("Couldn't load game config: \"%s\"", SRCCOOP_GAMEDATA_NAME); InitClassdef(pGameConfig); - CloseHandle(pGameConfig); + if (bCloseGameData) + { + CloseHandle(pGameConfig); + } + return pGameConfig; } stock GameData LoadSourceCoopConfig() diff --git a/scripting/srccoop.sp b/scripting/srccoop.sp index 6c779442..69723007 100644 --- a/scripting/srccoop.sp +++ b/scripting/srccoop.sp @@ -907,24 +907,6 @@ public void OnEntityCreated(int iEntIndex, const char[] szClassname) } } -public void OnEntityDestroyed(int iEntIndex) -{ - CBaseEntity pEntity = CBaseEntity(iEntIndex); - if (pEntity.IsValid()) - { - static char szClassname[MAX_CLASSNAME]; - pEntity.GetClassname(szClassname, sizeof(szClassname)); - - #if defined ENTPATCH_BM_MISC_MARIONETTIST - if (strcmp(szClassname, "misc_marionettist") == 0) - { - OnEntityDestroyed_Marionettist(pEntity); - return; - } - #endif - } -} - public void Hook_EntitySpawnPost(int iEntIndex) { if (CoopManager.IsCoopModeEnabled()) diff --git a/scripting/srccoop_addon_fpd.sp b/scripting/srccoop_addon_fpd.sp index 82856fad..bcc09195 100644 --- a/scripting/srccoop_addon_fpd.sp +++ b/scripting/srccoop_addon_fpd.sp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -33,12 +34,16 @@ ConVar g_pConvarFadeToBlackLength; ConVar g_pConvarPlayerToggle; Cookie g_pStateCookie; int g_iAttacment[MAXPLAYERS + 1]; +DynamicHook hkUpdateOnRemove; public void OnPluginStart() { g_Engine = GetEngineVersion(); LoadTranslations("srccoop_fpd.phrases"); - InitSourceCoopAddon(); + + GameData pGameConfig = InitSourceCoopAddon(false); + LoadDHookVirtual(pGameConfig, hkUpdateOnRemove, "CBaseEntity::UpdateOnRemove"); + pGameConfig.Close(); g_pStateCookie = new Cookie("sourcecoop_fpd", "First person death", CookieAccess_Protected); g_pConvarFadeToBlackLength = CreateConVar("sourcecoop_fpd_fade_ms", "1500", "Duration in milliseconds to fade first-person death screen to black. 0 to disable.", _, true, 0.0); @@ -152,21 +157,7 @@ public void OnEntityCreated(int iEntIndex, const char[] szClassname) if (strcmp(szClassname, "camera_death") == 0) { SDKHook(iEntIndex, SDKHook_SpawnPost, Hook_CameraDeathSpawn); - } - } -} - -public void OnEntityDestroyed(int iEntIndex) -{ - if (g_Engine == Engine_BlackMesa) - { - CBaseEntity pEntity = CBaseEntity(iEntIndex); - if (pEntity.IsValid()) - { - if (pEntity.IsClassname("camera_death")) - { - Hook_CameraDeathDestroyed(pEntity); - } + hkUpdateOnRemove.HookEntity(Hook_Post, iEntIndex, Hook_CameraDeathRemoved); } } } @@ -190,8 +181,9 @@ public void Hook_CameraDeathSpawn(int iEntIndex) AcceptEntityInput(iEntIndex, "Kill"); } -void Hook_CameraDeathDestroyed(CBaseEntity pEntity) +MRESReturn Hook_CameraDeathRemoved(int iEntIndex) { + CBaseEntity pEntity = CBaseEntity(iEntIndex); for (int i = 1; i <= MaxClients; i++) { if (IsClientInGame(i)) @@ -203,6 +195,7 @@ void Hook_CameraDeathDestroyed(CBaseEntity pEntity) } } } + return MRES_Ignored; } public void SC_OnPlayerRagdollCreated(CBasePlayer pPlayer, CBaseAnimating pRagdoll)