Skip to content

Commit

Permalink
Merge pull request #213 from ampreeT/xen-portal-push-fix
Browse files Browse the repository at this point in the history
Fix `env_xen_portal_effect` not pushing players
  • Loading branch information
ampreeT authored Jan 8, 2025
2 parents c7c2d01 + bb48c48 commit 94ea558
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions scripting/include/srccoop.inc
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
#define ENTPATCH_BM_SNARK_NEST
#define ENTPATCH_BM_SP_WEAPONS
#define ENTPATCH_BM_DISSOLVE
#define ENTPATCH_BM_XENPORTAL_PUSH_PLAYERS

#define PLAYERPATCH_SUIT_SOUNDS
#define PLAYERPATCH_PICKUP_FORCEPLAYERTODROPTHISOBJECT
Expand Down
44 changes: 44 additions & 0 deletions scripting/include/srccoop/blackmesa/entitypatch.inc
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,50 @@ public MRESReturn Hook_TestGroundMove(Address _this, DHookReturn hReturn, DHookP
return MRES_Ignored;
}

//------------------------------------------------------
// `env_xen_portal_effect`
// Fixes xen portals not pushing players.
//------------------------------------------------------
public MRESReturn Hook_XenPortalEffect_AcceptInput(int _this, Handle hReturn, Handle hParams)
{
char szInputType[MAX_FORMAT];
DHookGetParamString(hParams, 1, szInputType, sizeof(szInputType));
if (strcmp(szInputType, "PushAway", false) == 0 || strcmp(szInputType, "Burst", false) == 0)
{
CEnv_XenPortalEffect pPortalEffect = CEnv_XenPortalEffect(_this);

float flSize = pPortalEffect.GetSize();
float vec3PortalEffectPosition[3];
pPortalEffect.GetAbsOrigin(vec3PortalEffectPosition);

for (int i = 1; i <= MaxClients; ++i)
{
CBasePlayer pPlayer = CBasePlayer(i);
if (pPlayer != NULL_CBASEENTITY && pPlayer.IsAlive())
{
float vec3PlayerPosition[3];
pPlayer.GetAbsOrigin(vec3PlayerPosition);

if (GetVectorDistance(vec3PortalEffectPosition, vec3PlayerPosition) < (flSize * 2))
{
float vec3Distance[3];
SubtractVectors(vec3PlayerPosition, vec3PortalEffectPosition, vec3Distance);
NormalizeVector(vec3Distance, vec3Distance);

float vec3Angles[3];
GetVectorAngles(vec3Distance, vec3Angles);

float vec3Forward[3];
GetAngleVectors(vec3Angles, vec3Forward, NULL_VECTOR, NULL_VECTOR);
ScaleVector(vec3Forward, 1024.0); // TODO: Add better implementation matching original game.

pPlayer.SetAbsVelocity(vec3Forward);
}
}
}
}
return MRES_Ignored;
}

// Fixes map-placed tripmines not having the proper color with `mp_teamplay 1`.
//
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 @@ -82,6 +82,7 @@
#include <srccoop_api/classdef/bms/CBlackMesaBaseDetonator.inc>
#include <srccoop_api/classdef/bms/CBlackMesaPlayer.inc>
#include <srccoop_api/classdef/bms/CBM_MP_GameRules.inc>
#include <srccoop_api/classdef/bms/CEnv_XenPortalEffect.inc>
#include <srccoop_api/classdef/bms/CEnvBeamTeam.inc>
#include <srccoop_api/classdef/bms/CParamsManager.inc>
#include <srccoop_api/classdef/bms/CPropChargerBase.inc>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma newdecls required
#pragma semicolon 1

// TODO: Find what class this really inherits from.
methodmap CEnv_XenPortalEffect < CBaseEntity
{
public CEnv_XenPortalEffect(const int iEntIndex = -1)
{
return view_as<CEnv_XenPortalEffect>(CBaseEntity(iEntIndex));
}
public static CEnv_XenPortalEffect Create()
{
return CEnv_XenPortalEffect(CreateEntityByName("env_xen_portal_effect"));
}

public float GetSize()
{
return GetEntPropFloat(this.entindex, Prop_Data, "m_flSize");
}
public void SetSize(const float flSize)
{
SetEntPropFloat(this.entindex, Prop_Data, "m_flSize", flSize);
}
}
8 changes: 8 additions & 0 deletions scripting/srccoop.sp
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,14 @@ public void OnEntityCreated(int iEntIndex, const char[] szClassname)
}
else // !isNPC
{
#if defined ENTPATCH_BM_XENPORTAL_PUSH_PLAYERS
if (strcmp(szClassname, "env_xen_portal_effect") == 0)
{
DHookEntity(hkAcceptInput, false, iEntIndex, _, Hook_XenPortalEffect_AcceptInput);
return;
}
#endif

#if defined ENTPATCH_BM_SP_WEAPONS
if (strcmp(szClassname, "grenade_frag") == 0)
{
Expand Down

0 comments on commit 94ea558

Please sign in to comment.