Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CAI_ScriptedSequence crash #175

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions gamedata/srccoop.games.txt
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,13 @@
}
}
}
"CAI_ScriptedSequence::StartScript"
{
"signature" "CAI_ScriptedSequence::StartScript"
"callconv" "thiscall"
"return" "void"
"this" "entity"
}
}
}

Expand Down Expand Up @@ -1070,6 +1077,11 @@
"windows" "\x55\x8B\xEC\x83\xEC\x18\x56\xE8\x2A\x2A\x2A\x2A\x8B\xF0\x85\xF6\x75"
"linux" "@_ZL24UTIL_FindClientInPVSGutsP7edict_tPhj.constprop.66"
}
"CAI_ScriptedSequence::StartScript" // void CAI_ScriptedSequence::StartScript()
{
"windows" "\x55\x8B\xEC\x83\xEC\x10\x53\x8B\xD9\x8B\x8B\x9C\x03\x00\x00"
"linux" "@_ZN20CAI_ScriptedSequence11StartScriptEv"
}
}

// ____ __ __ _____ __ __ ______ __ __ _____ _______ _____ _ _ ______ _____
Expand Down
1 change: 1 addition & 0 deletions scripting/include/srccoop.inc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
#define ENTPATCH_LOGIC_AUTOSAVE_SURVIVAL_RESPAWN
#define ENTPATCH_GAME_END
#define ENTPATCH_NPC_DIALOGUE
#define ENTPATCH_SCRIPTED_SEQUENCE
#define ENTPATCH_REMOVE_BONE_FOLLOWERS
#define ENTPATCH_WEAPON_MODELS
#define ENTPATCH_PLAYER_ALLY
Expand Down
29 changes: 29 additions & 0 deletions scripting/include/srccoop/classdef.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,27 @@ methodmap CSceneEntity < CPointEntity
}
}

methodmap CAI_ScriptedSequence < CBaseEntity
{
public CAI_ScriptedSequence(const int iEntIndex = -1)
{
return view_as<CAI_ScriptedSequence>(CBaseEntity(iEntIndex));
}
public static CAI_ScriptedSequence Create()
{
return CAI_ScriptedSequence(CreateEntityByName("scripted_sequence"));
}

public CBaseEntity GetTargetEnt()
{
return CBaseEntity(GetEntPropEnt(this.entindex, Prop_Data, "m_hTargetEnt"));
}
public void SetTargetEnt(CBaseEntity pTarget)
{
SetEntPropEnt(this.entindex, Prop_Data, "m_hTargetEnt", pTarget.entindex);
}
}

methodmap CSoundEnt < CPointEntity
{
public CSoundEnt(const int iEntIndex = -1)
Expand Down Expand Up @@ -2060,6 +2081,14 @@ methodmap CAI_BaseNPC < CBaseCombatCharacter
{
SetEntProp(this.GetEntIndex(), Prop_Data, "m_bPlayerAvoidState", bPlayerAvoidState);
}
public CAI_ScriptedSequence GetCine()
{
return CAI_ScriptedSequence(GetEntPropEnt(this.entindex, Prop_Data, "m_hCine"));
}
public void SetCine(CAI_ScriptedSequence pCine)
{
SetEntPropEnt(this.entindex, Prop_Data, "m_hCine", pCine.entindex);
}
}

methodmap CProtoSniper < CAI_BaseNPC
Expand Down
20 changes: 20 additions & 0 deletions scripting/include/srccoop/entitypatch.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1575,3 +1575,23 @@ public MRESReturn Hook_UTIL_FindClientInPVSGuts(DHookReturn hReturn, DHookParam
return MRES_Supercede;
*/
}

//------------------------------------------------------
// CAI_ScriptedSequence::StartScript
// Attempts to fix null reference on m_hTargetEnt inside CAI_ScriptedSequence::ScriptThink
// by preventing CAI_ScriptedSequence::StartScript from nullifying its own target entity.
//------------------------------------------------------
public MRESReturn Hook_ScriptedSequenceStartScript(int _this)
{
CAI_ScriptedSequence pThis = CAI_ScriptedSequence(_this);
CBaseEntity pTarget = pThis.GetTargetEnt();
if (pTarget != NULL_CBASEENTITY && pTarget.IsClassNPC())
{
CAI_BaseNPC pTargetNpc = view_as<CAI_BaseNPC>(pTarget);
if (pThis == pTargetNpc.GetCine())
{
pTargetNpc.SetCine(NULL_CBASEENTITY);
}
}
return MRES_Ignored;
}
4 changes: 4 additions & 0 deletions scripting/include/srccoop/globals.inc
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ DynamicDetour hkDissolve;
DynamicDetour hkUtilFindClientInPVSGuts;
#endif

#if defined ENTPATCH_SCRIPTED_SEQUENCE
DynamicDetour hkScriptedSequenceStartScript;
#endif

#if defined GAMEPATCH_PREDICTED_EFFECTS
DynamicDetour hkIgnorePredictionCull;
DynamicHook hkDispatchEffect;
Expand Down
4 changes: 4 additions & 0 deletions scripting/srccoop.sp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ void LoadGameData()
LoadDHookDetour(pGameConfig, hkUtilFindClientInPVSGuts, "UTIL_FindClientInPVSGuts", Hook_UTIL_FindClientInPVSGuts);
#endif

#if defined ENTPATCH_SCRIPTED_SEQUENCE
LoadDHookDetour(pGameConfig, hkScriptedSequenceStartScript, "CAI_ScriptedSequence::StartScript", Hook_ScriptedSequenceStartScript);
#endif

#if defined GAMEPATCH_PREDICTED_EFFECTS
LoadDHookDetour(pGameConfig, hkIgnorePredictionCull, "CRecipientFilter::IgnorePredictionCull", Hook_IgnorePredictionCull);
LoadDHookVirtual(pGameConfig, hkDispatchEffect, "CTempEntsSystem::DispatchEffect");
Expand Down