Skip to content

Commit 94ea558

Browse files
authored
Merge pull request #213 from ampreeT/xen-portal-push-fix
Fix `env_xen_portal_effect` not pushing players
2 parents c7c2d01 + bb48c48 commit 94ea558

File tree

5 files changed

+78
-0
lines changed

5 files changed

+78
-0
lines changed

scripting/include/srccoop.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
#define ENTPATCH_BM_SNARK_NEST
112112
#define ENTPATCH_BM_SP_WEAPONS
113113
#define ENTPATCH_BM_DISSOLVE
114+
#define ENTPATCH_BM_XENPORTAL_PUSH_PLAYERS
114115

115116
#define PLAYERPATCH_SUIT_SOUNDS
116117
#define PLAYERPATCH_PICKUP_FORCEPLAYERTODROPTHISOBJECT

scripting/include/srccoop/blackmesa/entitypatch.inc

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,50 @@ public MRESReturn Hook_TestGroundMove(Address _this, DHookReturn hReturn, DHookP
644644
return MRES_Ignored;
645645
}
646646

647+
//------------------------------------------------------
648+
// `env_xen_portal_effect`
649+
// Fixes xen portals not pushing players.
650+
//------------------------------------------------------
651+
public MRESReturn Hook_XenPortalEffect_AcceptInput(int _this, Handle hReturn, Handle hParams)
652+
{
653+
char szInputType[MAX_FORMAT];
654+
DHookGetParamString(hParams, 1, szInputType, sizeof(szInputType));
655+
if (strcmp(szInputType, "PushAway", false) == 0 || strcmp(szInputType, "Burst", false) == 0)
656+
{
657+
CEnv_XenPortalEffect pPortalEffect = CEnv_XenPortalEffect(_this);
658+
659+
float flSize = pPortalEffect.GetSize();
660+
float vec3PortalEffectPosition[3];
661+
pPortalEffect.GetAbsOrigin(vec3PortalEffectPosition);
662+
663+
for (int i = 1; i <= MaxClients; ++i)
664+
{
665+
CBasePlayer pPlayer = CBasePlayer(i);
666+
if (pPlayer != NULL_CBASEENTITY && pPlayer.IsAlive())
667+
{
668+
float vec3PlayerPosition[3];
669+
pPlayer.GetAbsOrigin(vec3PlayerPosition);
670+
671+
if (GetVectorDistance(vec3PortalEffectPosition, vec3PlayerPosition) < (flSize * 2))
672+
{
673+
float vec3Distance[3];
674+
SubtractVectors(vec3PlayerPosition, vec3PortalEffectPosition, vec3Distance);
675+
NormalizeVector(vec3Distance, vec3Distance);
676+
677+
float vec3Angles[3];
678+
GetVectorAngles(vec3Distance, vec3Angles);
679+
680+
float vec3Forward[3];
681+
GetAngleVectors(vec3Angles, vec3Forward, NULL_VECTOR, NULL_VECTOR);
682+
ScaleVector(vec3Forward, 1024.0); // TODO: Add better implementation matching original game.
683+
684+
pPlayer.SetAbsVelocity(vec3Forward);
685+
}
686+
}
687+
}
688+
}
689+
return MRES_Ignored;
690+
}
647691

648692
// Fixes map-placed tripmines not having the proper color with `mp_teamplay 1`.
649693
//

scripting/include/srccoop_api/classdef.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
#include <srccoop_api/classdef/bms/CBlackMesaBaseDetonator.inc>
8383
#include <srccoop_api/classdef/bms/CBlackMesaPlayer.inc>
8484
#include <srccoop_api/classdef/bms/CBM_MP_GameRules.inc>
85+
#include <srccoop_api/classdef/bms/CEnv_XenPortalEffect.inc>
8586
#include <srccoop_api/classdef/bms/CEnvBeamTeam.inc>
8687
#include <srccoop_api/classdef/bms/CParamsManager.inc>
8788
#include <srccoop_api/classdef/bms/CPropChargerBase.inc>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#pragma newdecls required
2+
#pragma semicolon 1
3+
4+
// TODO: Find what class this really inherits from.
5+
methodmap CEnv_XenPortalEffect < CBaseEntity
6+
{
7+
public CEnv_XenPortalEffect(const int iEntIndex = -1)
8+
{
9+
return view_as<CEnv_XenPortalEffect>(CBaseEntity(iEntIndex));
10+
}
11+
public static CEnv_XenPortalEffect Create()
12+
{
13+
return CEnv_XenPortalEffect(CreateEntityByName("env_xen_portal_effect"));
14+
}
15+
16+
public float GetSize()
17+
{
18+
return GetEntPropFloat(this.entindex, Prop_Data, "m_flSize");
19+
}
20+
public void SetSize(const float flSize)
21+
{
22+
SetEntPropFloat(this.entindex, Prop_Data, "m_flSize", flSize);
23+
}
24+
}

scripting/srccoop.sp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,14 @@ public void OnEntityCreated(int iEntIndex, const char[] szClassname)
708708
}
709709
else // !isNPC
710710
{
711+
#if defined ENTPATCH_BM_XENPORTAL_PUSH_PLAYERS
712+
if (strcmp(szClassname, "env_xen_portal_effect") == 0)
713+
{
714+
DHookEntity(hkAcceptInput, false, iEntIndex, _, Hook_XenPortalEffect_AcceptInput);
715+
return;
716+
}
717+
#endif
718+
711719
#if defined ENTPATCH_BM_SP_WEAPONS
712720
if (strcmp(szClassname, "grenade_frag") == 0)
713721
{

0 commit comments

Comments
 (0)