Skip to content
Open
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
19 changes: 19 additions & 0 deletions gamedata/srccoop.games.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,20 @@
}
}
}
"CAI_BaseNPC::IsValidEnemy" //bool CAI_BaseNPC::IsValidEnemy( CBaseEntity *pEnemy )
{
"offset" "CAI_BaseNPC::IsValidEnemy"
"hooktype" "entity"
"return" "bool"
"this" "entity"
"arguments"
{
"pEnemy"
{
"type" "cbaseentity"
}
}
}
"CAI_BaseNPC::IsNavigationUrgent"
{
"offset" "CAI_BaseNPC::IsNavigationUrgent"
Expand Down Expand Up @@ -1357,6 +1371,11 @@
"windows" "445"
"linux" "446"
}
"CAI_BaseNPC::IsValidEnemy" // CAI_BaseNPC::IsValidEnemy(CBaseEntity*)
{
"windows" "434"
"linux" "435"
}
"CAI_BaseNPC::IsNavigationUrgent" // CAI_BaseNPC::IsNavigationUrgent()
{
"windows" "482"
Expand Down
1 change: 1 addition & 0 deletions scripting/include/srccoop.inc
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
#define ENTPATCH_BM_GARGANTUA
#define ENTPATCH_BM_PUFFBALLFUNGUS
#define ENTPATCH_BM_MEDIC
#define ENTPATCH_BM_SNARK
#define ENTPATCH_BM_LAV
#define ENTPATCH_BM_TRIPMINE_COLORS
#define ENTPATCH_BM_PROP_CHARGERS
Expand Down
53 changes: 53 additions & 0 deletions scripting/include/srccoop/bms/entitypatch.inc
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,59 @@ public MRESReturn Hook_HumanMedicKilled(int _this, DHookParam hParams)
return MRES_Ignored;
}

//------------------------------------------------------
// npc_snark
// Set snark's team to make it evil or peaceful to the players.
//------------------------------------------------------
public void Hook_Snark_OnCreated(const int iEntIndex)
{
if (CBaseEntity(iEntIndex).GetHammerID() != 0) //don't for map-placed
return;

CBasePlayer pPlayer = CBasePlayer(CNpc_Snark(iEntIndex).GetSnarkOwner());

//don't if i don't have any owner
if (!pPlayer.IsValid())
return;

int iTeam = (mp_friendlyfire.BoolValue) ? TEAM_ANY : pPlayer.GetTeam();
SetEntProp(iEntIndex, Prop_Data, "m_iInitialTeamNum", iTeam);
SetEntProp(iEntIndex, Prop_Data, "m_iTeamNum", iTeam);
}

//------------------------------------------------------
// npc_snark
// Make snark owned by a player peaceful with mp_friendlyfire, filter players (by teamnum) and ally to owner NPCs
//------------------------------------------------------
public MRESReturn Hook_SnarkIsValidEnemy(int _this, DHookReturn hReturn, DHookParam hParams)
{
if (DHookIsNullParam(hParams, 1) || mp_friendlyfire.BoolValue)
return MRES_Ignored;


CBasePlayer pOwner = CBasePlayer(CNpc_Snark(_this).GetSnarkOwner());

//check if i have owner
if (!pOwner.IsValid())
return MRES_Ignored;

CAI_BaseNPC pEnemy = CAI_BaseNPC(DHookGetParam(hParams, 1));

//check if the targer plr/npc is valid for me
if (!pEnemy.IsValid())
return MRES_Ignored;

//check if in my owner's team or if is owner's ally
if (pEnemy.GetTeam() == pOwner.GetTeam() || pEnemy.IsPlayerAlly(pOwner))
{
//not valid enemy
DHookSetReturn(hReturn, false);
return MRES_Supercede;
}

return MRES_Ignored;
}

//------------------------------------------------------
// CPropRadiationCharger - prop_radiation_charger
//
Expand Down
4 changes: 4 additions & 0 deletions scripting/include/srccoop/globals.inc
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ DynamicDetour hkTestGroundMove;
DynamicDetour hkStartLagCompensation;
#endif

#if defined ENTPATCH_BM_SNARK
DynamicHook hkIsBaseNPCIsValidEnemy;
#endif

// ----------------------------
// MemPatches
// ----------------------------
Expand Down
1 change: 1 addition & 0 deletions scripting/include/srccoop_api/classdef.inc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
#include <srccoop_api/classdef/bms/CEnvBeamTeam.inc>
#include <srccoop_api/classdef/bms/CItem_HealthKit.inc>
#include <srccoop_api/classdef/bms/CNewLightPoint.inc>
#include <srccoop_api/classdef/bms/CNpc_Snark.inc>
#include <srccoop_api/classdef/bms/CParamsManager.inc>
#include <srccoop_api/classdef/bms/CPropChargerBase.inc>
#include <srccoop_api/classdef/bms/CSpriteTeam.inc>
Expand Down
34 changes: 34 additions & 0 deletions scripting/include/srccoop_api/classdef/bms/CNpc_Snark.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma newdecls required
#pragma semicolon 1

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

public float GetLifeTime()
{
return GetEntPropFloat(this.entindex, Prop_Data, "m_fLifeTime");
}

public void SetLifeTime(const float flLifeTime)
{
SetEntPropFloat(this.entindex, Prop_Data, "m_fLifeTime", flLifeTime);
}

public int GetSnarkOwner()
{
return GetEntPropEnt(this.entindex, Prop_Data, "m_hOwner");
}

public void SetSnarkOwner(int iEntIndex)
{
SetEntPropEnt(this.entindex, Prop_Data, "m_hOwner", iEntIndex);
}
}
16 changes: 16 additions & 0 deletions scripting/include/srccoop_api/classdef/common/CAI_BaseNPC.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ static Handle g_pGetSoundInterests;
static Handle g_pHearingSensitivity;
static Handle g_pUpdateEnemyMemory;
static Handle g_pShouldPlayerAvoid;
static Handle g_pIsPlayerAlly;

enum CAI_BaseNPC_SpawnFlags
{
Expand Down Expand Up @@ -100,6 +101,17 @@ methodmap CAI_BaseNPC < CBaseCombatCharacter
PrepSDKCall_SetReturnInfo(SDKType_Bool, SDKPass_Plain);
if (!(g_pShouldPlayerAvoid = EndPrepSDKCall())) SetFailState("Could not prep SDK call %s", szShouldPlayerAvoid);
}

char szIsPlayerAlly[] = "CAI_BaseNPC::IsPlayerAlly";
StartPrepSDKCall(SDKCall_Entity);
if (!PrepSDKCall_SetFromConf(hGameConfig, SDKConf_Virtual, szIsPlayerAlly))
LogMessage("Could not obtain gamedata offset %s", szIsPlayerAlly);
else
{
PrepSDKCall_SetReturnInfo(SDKType_Bool, SDKPass_Plain);
PrepSDKCall_AddParameter(SDKType_CBaseEntity, SDKPass_Pointer);
if (!(g_pIsPlayerAlly = EndPrepSDKCall())) SetFailState("Could not prep SDK call %s", szIsPlayerAlly);
}
}
public CAI_BaseNPC(const int iEntIndex = -1)
{
Expand Down Expand Up @@ -136,6 +148,10 @@ methodmap CAI_BaseNPC < CBaseCombatCharacter
{
return GetEntProp(this.entindex, Prop_Data, "m_bInAScript") != 0;
}
public bool IsPlayerAlly(const CBasePlayer pPlayer)
{
return SDKCall(g_pIsPlayerAlly, this, pPlayer);
}
public bool IsSoundVisible(CSound pSound)
{
float vec3SoundReactOrigin[3];
Expand Down
13 changes: 13 additions & 0 deletions scripting/srccoop.sp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ void LoadGameData()
g_iUserCmdOffset = pGameConfig.GetOffset("CBasePlayer::GetCurrentUserCommand");
#endif

#if defined ENTPATCH_BM_SNARK
LoadDHookVirtual(pGameConfig, hkIsBaseNPCIsValidEnemy, "CAI_BaseNPC::IsValidEnemy");
#endif

#if defined PLAYERPATCH_SUIT_SOUNDS
LoadDHookDetour(pGameConfig, hkSetSuitUpdate, "CBasePlayer::SetSuitUpdate", Hook_SetSuitUpdate, Hook_SetSuitUpdatePost);
#endif
Expand Down Expand Up @@ -720,6 +724,15 @@ public void OnEntityCreated(int iEntIndex, const char[] szClassname)
return;
}
#endif

#if defined ENTPATCH_BM_SNARK
if (strcmp(szClassname, "npc_snark") == 0 && CoopManager.IsCoopModeEnabled())
{
RequestFrame(Hook_Snark_OnCreated, iEntIndex);
DHookEntity(hkIsBaseNPCIsValidEnemy, false, iEntIndex, _, Hook_SnarkIsValidEnemy);
return;
}
#endif
}
else // !isNPC
{
Expand Down