Skip to content

Commit

Permalink
Get rid of OnEntityDestroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
Alienmario committed Oct 13, 2024
1 parent a50a26a commit 8889429
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 40 deletions.
9 changes: 6 additions & 3 deletions scripting/include/srccoop/blackmesa/entitypatch.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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"))
{
Expand All @@ -311,6 +313,7 @@ void OnEntityDestroyed_Marionettist(CBaseEntity pEntity)
break;
}
}
return MRES_Ignored;
}

//------------------------------------------------------
Expand Down
8 changes: 6 additions & 2 deletions scripting/include/srccoop_api.inc
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,18 @@
#include <srccoop/utils>
#include <srccoop/features>

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()
Expand Down
18 changes: 0 additions & 18 deletions scripting/srccoop.sp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
27 changes: 10 additions & 17 deletions scripting/srccoop_addon_fpd.sp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <sdkhooks>
#include <dhooks>
#include <sourcemod>
#include <clientprefs>

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
}
Expand All @@ -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))
Expand All @@ -203,6 +195,7 @@ void Hook_CameraDeathDestroyed(CBaseEntity pEntity)
}
}
}
return MRES_Ignored;
}

public void SC_OnPlayerRagdollCreated(CBasePlayer pPlayer, CBaseAnimating pRagdoll)
Expand Down

0 comments on commit 8889429

Please sign in to comment.