just updating plugins to 64bit support

This commit is contained in:
jenz
2026-11-22 22:12:20 +01:00
parent 7a4f26c2bd
commit 2dca39be8a
32 changed files with 2990 additions and 516 deletions
+88 -8
View File
@@ -15,7 +15,9 @@
{
"library" "server"
"windows" "@CreateInterface"
"windows64" "@CreateInterface"
"linux" "@CreateInterface"
"linux64" "@CreateInterface"
}
}
@@ -24,7 +26,9 @@
"ProcessMovement"
{
"windows" "1"
"windows64" "1"
"linux" "2"
"linux64" "2"
}
}
}
@@ -36,15 +40,15 @@
// applies to trigger_vphysics_motion and trigger_wind
"CBaseVPhysicsTrigger::PassesTriggerFilters"
{
"windows" "199"
"linux" "200"
"windows" "200"
"linux" "201"
}
// applies to all other triggers
"CBaseTrigger::PassesTriggerFilters"
{
"windows" "209"
"linux" "210"
"windows" "210"
"linux" "211"
}
"IServerGameEnts::MarkEntitiesAsTouching"
@@ -52,6 +56,36 @@
"windows" "1"
"linux" "2"
}
"CMoveData::m_flForwardMove"
{
"windows" "44"
"linux" "44"
}
"CMoveData::m_flSideMove"
{
"windows" "48"
"linux" "48"
}
"CMoveData::m_flMaxSpeed"
{
"windows" "56"
"linux" "56"
}
"CMoveData::m_vecVelocity"
{
"windows" "64"
"linux" "64"
}
"CMoveData::m_vecAbsOrigin"
{
"windows" "172"
"linux" "172"
}
}
}
@@ -59,24 +93,70 @@
{
"Offsets"
{
"CMoveData::m_flForwardMove"
{
"windows" "44"
"windows64" "44"
"linux" "44"
"linux64" "44"
}
"CMoveData::m_flSideMove"
{
"windows" "52"
"windows64" "52"
"linux" "52"
"linux64" "52"
}
"CMoveData::m_flMaxSpeed"
{
"windows" "60"
"windows64" "60"
"linux" "60"
"linux64" "60"
}
"CMoveData::m_vecVelocity"
{
"windows" "68"
"windows64" "68"
"linux" "68"
"linux64" "68"
}
"CMoveData::m_vecAbsOrigin"
{
"windows" "156"
"windows64" "156"
"linux" "156"
"linux64" "156"
}
// applies to trigger_vphysics_motion and trigger_wind
"CBaseVPhysicsTrigger::PassesTriggerFilters"
{
"windows" "188"
"linux" "189"
"windows" "195"
"windows64" "195"
"linux" "196"
"linux64" "196"
}
// applies to all other triggers
"CBaseTrigger::PassesTriggerFilters"
{
"windows" "197"
"linux" "198"
"windows" "204"
"windows64" "204"
"linux" "205"
"linux64" "205"
}
"IServerGameEnts::MarkEntitiesAsTouching"
{
"windows" "2"
"windows64" "2"
"linux" "3"
"linux64" "3"
}
}
}
+51
View File
@@ -0,0 +1,51 @@
#if defined _rngfix_included
#endinput
#endif
#define _rngfix_included
/**
* Called when trigger_* is Hooked.
*
* @param entity Entity
* @param classname Clasname
* @noreturn
*/
forward void RNGFix_OnTriggerDetected(int entity, const char[] classname);
/**
* Called when trigger_* on StartTouch.
*
* @param entity Entity
* @param other Activator
* @noreturn
*/
forward void RNGFix_OnTriggerStartTouch(int entity, int other);
/**
* Called when trigger_* on EndTouch.
*
* @param entity Entity
* @param other Activator
* @noreturn
*/
forward void RNGFix_OnTriggerEndTouch(int entity, int other);
/**
* Called after trigger_teleport is touched.
*
* @param entity Entity
* @param other Activator
* @noreturn
*/
forward void RNGFix_OnTriggerTeleportTouchPost(int entity, int other);
public SharedPlugin __pl_rngfix =
{
name = "rngfix",
file = "rngfix.smx",
#if defined REQUIRE_PLUGIN
required = 1
#else
required = 0
#endif
};
+395 -44
View File
@@ -6,7 +6,7 @@
#pragma semicolon 1
#pragma newdecls required
#define PLUGIN_VERSION "1.1.2"
#define PLUGIN_VERSION "1.1.8"
public Plugin myinfo =
{
@@ -33,6 +33,11 @@ float g_flDuckDelta;
int g_iTick[MAXPLAYERS+1];
float g_flFrameTime[MAXPLAYERS+1];
bool g_bTouchingTrigger[MAXPLAYERS+1][2048];
// Teleport target name -> reference of the last entity found with that name (see NameExists)
StringMap g_smTargetEntity;
int g_iButtons[MAXPLAYERS+1];
float g_vVel[MAXPLAYERS+1][3];
float g_vAngles[MAXPLAYERS+1][3];
@@ -80,10 +85,24 @@ ConVar g_cvJumpImpulse;
ConVar g_cvAutoBunnyHopping;
Handle g_hPassesTriggerFilters;
Handle g_hProcessMovementHookPre;
DynamicHook g_hProcessMovementHookPre;
Address g_IServerGameEnts;
Handle g_hMarkEntitiesAsTouching;
int g_iCMoveData_ForwardMove;
int g_iCMoveData_SideMove;
int g_iCMoveData_MaxSpeed;
int g_iCMoveData_Velocity;
int g_iCMoveData_Origin;
// API
GlobalForward g_hOnTriggerDetected;
GlobalForward g_hOnTriggerStartTouch;
GlobalForward g_hOnTriggerEndTouch;
GlobalForward g_hOnTriggerTeleportTouchPost;
bool g_bIsSurfMap;
bool g_bLateLoad;
int g_iLaserIndex;
@@ -110,14 +129,23 @@ void DebugLaser(int client, const float p1[3], const float p2[3], float life, fl
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
g_bLateLoad = late;
RegPluginLibrary("rngfix");
g_hOnTriggerDetected = new GlobalForward("RNGFix_OnTriggerDetected", ET_Ignore, Param_Cell, Param_String);
g_hOnTriggerStartTouch = new GlobalForward("RNGFix_OnTriggerStartTouch", ET_Ignore, Param_Cell, Param_Cell);
g_hOnTriggerEndTouch = new GlobalForward("RNGFix_OnTriggerEndTouch", ET_Ignore, Param_Cell, Param_Cell);
g_hOnTriggerTeleportTouchPost = new GlobalForward("RNGFix_OnTriggerTeleportTouchPost", ET_Ignore, Param_Cell, Param_Cell);
return APLRes_Success;
}
public void OnPluginStart()
{
g_smTargetEntity = new StringMap();
EngineVersion engine = GetEngineVersion();
if (engine != Engine_CSGO && engine != Engine_CSS)
if (engine != Engine_CSS)
{
SetFailState("Game is not supported");
}
@@ -125,20 +153,9 @@ public void OnPluginStart()
g_vecMins = view_as<float>({-16.0, -16.0, 0.0});
g_vecMaxsUnducked = view_as<float>({16.0, 16.0, 0.0});
g_vecMaxsDucked = view_as<float>({16.0, 16.0, 0.0});
switch (engine)
{
case Engine_CSGO:
{
g_vecMaxsUnducked[2] = 72.0;
g_vecMaxsDucked[2] = 64.0;
}
case Engine_CSS:
{
g_vecMaxsUnducked[2] = 62.0;
g_vecMaxsDucked[2] = 45.0;
}
}
g_vecMaxsUnducked[2] = 62.0;
g_vecMaxsDucked[2] = 45.0;
g_flDuckDelta = (g_vecMaxsUnducked[2]-g_vecMaxsDucked[2]) / 2;
@@ -153,7 +170,7 @@ public void OnPluginStart()
g_cvDebug = CreateConVar("rngfix_debug", "0", "1 = Enable debug messages. 2 = Enable debug messages and lasers.", _, true, 0.0, true, 2.0);
AutoExecConfig();
AutoExecConfig(true);
g_cvMaxVelocity = FindConVar("sv_maxvelocity");
g_cvGravity = FindConVar("sv_gravity");
@@ -169,7 +186,7 @@ public void OnPluginStart()
g_cvJumpImpulse = FindConVar("sv_jump_impulse");
g_cvAutoBunnyHopping = FindConVar("sv_autobunnyhopping");
Handle gamedataConf = LoadGameConfigFile("rngfix.games");
GameData gamedataConf = new GameData("rngfix.games");
if (gamedataConf == null) SetFailState("Failed to load rngfix gamedata");
// PassesTriggerFilters
@@ -193,7 +210,13 @@ public void OnPluginStart()
}
PrepSDKCall_AddParameter(SDKType_String, SDKPass_Pointer);
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Pointer, VDECODE_FLAG_ALLOWNULL);
#if SOURCEMOD_V_MINOR >= 13
// A pointer does not fit in a cell on x64: SM 1.13 returns it through an Address (int64) argument
PrepSDKCall_SetReturnInfo(SDKType_Address, SDKPass_Plain);
#else
// SM 1.12 has no SDKType_Address: the pointer is returned in a cell, which only works on 32-bit servers
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
#endif
Handle CreateInterface = EndPrepSDKCall();
if (CreateInterface == null) SetFailState("Unable to prepare SDKCall for CreateInterface");
@@ -201,31 +224,52 @@ public void OnPluginStart()
char interfaceName[64];
// ProcessMovement
if (!GameConfGetKeyValue(gamedataConf, "IGameMovement", interfaceName, sizeof(interfaceName)))
if (!gamedataConf.GetKeyValue("IGameMovement", interfaceName, sizeof(interfaceName)))
{
SetFailState("Failed to get IGameMovement interface name");
}
Address IGameMovement = SDKCall(CreateInterface, interfaceName, 0);
if (!IGameMovement)
Address IGameMovement = GetInterface(CreateInterface, interfaceName);
if (IGameMovement == Address_Null)
{
SetFailState("Failed to get IGameMovement pointer");
}
int offset = GameConfGetOffset(gamedataConf, "ProcessMovement");
int offset = gamedataConf.GetOffset("ProcessMovement");
if (offset == -1) SetFailState("Failed to get ProcessMovement offset");
g_hProcessMovementHookPre = DHookCreate(offset, HookType_Raw, ReturnType_Void, ThisPointer_Ignore, DHook_ProcessMovementPre);
DHookAddParam(g_hProcessMovementHookPre, HookParamType_CBaseEntity);
DHookAddParam(g_hProcessMovementHookPre, HookParamType_ObjectPtr);
DHookRaw(g_hProcessMovementHookPre, false, IGameMovement);
g_hProcessMovementHookPre = new DynamicHook(offset, HookType_Raw, ReturnType_Void, ThisPointer_Ignore);
g_hProcessMovementHookPre.AddParam(HookParamType_CBaseEntity);
g_hProcessMovementHookPre.AddParam(HookParamType_ObjectPtr);
g_hProcessMovementHookPre.HookRaw(Hook_Pre, IGameMovement, DHook_ProcessMovementPre);
if ((g_iCMoveData_ForwardMove = gamedataConf.GetOffset("CMoveData::m_flForwardMove")) == -1)
{
SetFailState("Failed to get CMoveData::m_flForwardMove");
}
if ((g_iCMoveData_SideMove = gamedataConf.GetOffset("CMoveData::m_flSideMove")) == -1)
{
SetFailState("Failed to get CMoveData::m_flSideMove");
}
if ((g_iCMoveData_MaxSpeed = gamedataConf.GetOffset("CMoveData::m_flMaxSpeed")) == -1)
{
SetFailState("Failed to get CMoveData::m_flMaxSpeed");
}
if ((g_iCMoveData_Velocity = gamedataConf.GetOffset("CMoveData::m_vecVelocity")) == -1)
{
SetFailState("Failed to get CMoveData::m_vecVelocity");
}
if ((g_iCMoveData_Origin = gamedataConf.GetOffset("CMoveData::m_vecAbsOrigin")) == -1)
{
SetFailState("Failed to get CMoveData::m_vecAbsOrigin");
}
// MarkEntitiesAsTouching
if (!GameConfGetKeyValue(gamedataConf, "IServerGameEnts", interfaceName, sizeof(interfaceName)))
if (!gamedataConf.GetKeyValue("IServerGameEnts", interfaceName, sizeof(interfaceName)))
{
SetFailState("Failed to get IServerGameEnts interface name");
}
g_IServerGameEnts = SDKCall(CreateInterface, interfaceName, 0);
if (!g_IServerGameEnts)
g_IServerGameEnts = GetInterface(CreateInterface, interfaceName);
if (g_IServerGameEnts == Address_Null)
{
SetFailState("Failed to get IServerGameEnts pointer");
}
@@ -250,16 +294,56 @@ public void OnPluginStart()
{
if (IsClientInGame(client)) OnClientPutInServer(client);
}
char classname[64];
for (int entity = MaxClients+1; entity < sizeof(g_bTouchingTrigger[]); entity++)
{
if (!IsValidEntity(entity)) continue;
GetEntPropString(entity, Prop_Data, "m_iClassname", classname, sizeof(classname));
HookTrigger(entity, classname);
}
}
}
// Calls CreateInterface(name, NULL) and returns the interface pointer
Address GetInterface(Handle createInterface, const char[] name)
{
#if SOURCEMOD_V_MINOR >= 13
Address pInterface = Address_Null;
SDKCall(createInterface, pInterface, name, 0);
return pInterface;
#else
return SDKCall(createInterface, name, 0);
#endif
}
public void OnMapStart()
{
delete g_smTargetEntity;
g_smTargetEntity = new StringMap();
g_iLaserIndex = PrecacheModel("materials/sprites/laserbeam.vmt", true);
char map[PLATFORM_MAX_PATH];
GetCurrentMap(map, sizeof(map));
g_bIsSurfMap = StrContains(map, "surf_", false) == 0;
}
public void OnEntityCreated(int entity, const char[] classname)
{
if (entity >= sizeof(g_bTouchingTrigger[])) return;
HookTrigger(entity, classname);
}
void HookTrigger(int entity, const char[] classname)
{
if (StrContains(classname, "trigger_") != -1)
{
SDKHook(entity, SDKHook_StartTouchPost, Hook_TriggerStartTouch);
SDKHook(entity, SDKHook_EndTouchPost, Hook_TriggerEndTouch);
Forward_OnTriggerDetected(entity, classname);
}
if (StrContains(classname, "trigger_teleport") != -1)
{
SDKHook(entity, SDKHook_TouchPost, Hook_TriggerTeleportTouchPost);
@@ -269,6 +353,7 @@ public void OnEntityCreated(int entity, const char[] classname)
public void OnClientConnected(int client)
{
g_iTick[client] = 0;
for (int i = 0; i < sizeof(g_bTouchingTrigger[]); i++) g_bTouchingTrigger[client][i] = false;
}
public void OnClientPutInServer(int client)
@@ -277,6 +362,18 @@ public void OnClientPutInServer(int client)
SDKHook(client, SDKHook_PostThink, Hook_PlayerPostThink);
}
public Action Hook_TriggerStartTouch(int entity, int other)
{
if (1 <= other <= MaxClients)
{
g_bTouchingTrigger[other][entity] = true;
DebugMsg(other, "StartTouch %i", entity);
Forward_OnTriggerStartTouch(entity, other);
}
return Plugin_Continue;
}
// TODO Would be nice to have IServerTools::FindEntityByName / CGlobalEntityList::FindEntityByName
bool NameExists(const char[] targetname)
{
@@ -285,15 +382,34 @@ bool NameExists(const char[] targetname)
char targetname2[128];
// This runs on every tick a player touches a trigger_teleport, and a mass teleport touches it
// with every player in the same tick: check the entity found last time before walking all edicts.
// Teleport destinations rarely change, so the walk below only runs again when that entity is gone
// or renamed, or when no entity has the name.
int ref;
if (g_smTargetEntity.GetValue(targetname, ref))
{
int entity = EntRefToEntIndex(ref);
if (entity != INVALID_ENT_REFERENCE
&& GetEntPropString(entity, Prop_Data, "m_iName", targetname2, sizeof(targetname2)) != 0
&& StrEqual(targetname, targetname2))
return true;
}
int max = GetMaxEntities();
for (int entity = 1; entity < max; entity++)
{
if (!IsValidEntity(entity)) continue;
if (GetEntPropString(entity, Prop_Data, "m_iName", targetname2, sizeof(targetname2)) == 0) continue;
if (StrEqual(targetname, targetname2)) return true;
if (StrEqual(targetname, targetname2))
{
g_smTargetEntity.SetValue(targetname, EntIndexToEntRef(entity));
return true;
}
}
g_smTargetEntity.Remove(targetname);
return false;
}
@@ -316,6 +432,18 @@ public void Hook_TriggerTeleportTouchPost(int entity, int other)
g_iLastMapTeleportTick[other] = g_iTick[other];
DebugMsg(other, "Triggered teleport %i", entity);
Forward_OnTriggerTeleportEndTouch(entity, other);
}
public Action Hook_TriggerEndTouch(int entity, int other)
{
if (1 <= other <= MaxClients)
{
g_bTouchingTrigger[other][entity] = false;
DebugMsg(other, "EndTouch %i", entity);
Forward_OnTriggerEndTouch(entity, other);
}
return Plugin_Continue;
}
public bool PlayerFilter(int entity, int mask)
@@ -419,7 +547,7 @@ void CheckJumpButton(int client, float velocity[3])
FinishGravity(client, velocity);
}
void AirAccelerate(int client, float velocity[3], Handle hParams)
void AirAccelerate(int client, float velocity[3], DHookParam hParams)
{
// This also includes the initial parts of AirMove()
@@ -436,7 +564,7 @@ void AirAccelerate(int client, float velocity[3], Handle hParams)
for (int i = 0; i < 2; i++) wishvel[i] = fore[i] * g_vVel[client][0] + side[i] * g_vVel[client][1];
float wishspeed = NormalizeVector(wishvel, wishdir);
float m_flMaxSpeed = DHookGetParamObjectPtrVar(hParams, 2, 56, ObjectValueType_Float);
float m_flMaxSpeed = hParams.GetObjectVar(2, g_iCMoveData_MaxSpeed, ObjectValueType_Float);
if (wishspeed > m_flMaxSpeed && m_flMaxSpeed != 0.0) wishspeed = m_flMaxSpeed;
if (wishspeed)
@@ -499,7 +627,7 @@ bool CheckWater(int client)
return GetEntProp(client, Prop_Data, "m_nWaterLevel") > 1;
}
void PreventCollision(int client, Handle hParams, const float origin[3], const float collisionPoint[3], const float velocity_tick[3])
void PreventCollision(int client, DHookParam hParams, const float origin[3], const float collisionPoint[3], const float velocity_tick[3])
{
DebugLaser(client, origin, collisionPoint, 15.0, 0.5, g_color1);
@@ -515,7 +643,7 @@ void PreventCollision(int client, Handle hParams, const float origin[3], const f
// Since the MoveData for this tick has already been filled and is about to be used, we need
// to modify it directly instead of changing the player entity's actual position (such as with TeleportEntity).
DHookSetParamObjectPtrVarVector(hParams, 2, GetEngineVersion() == Engine_CSGO ? 172 : 152, ObjectValueType_Vector, newOrigin);
hParams.SetObjectVarVector(2, g_iCMoveData_Origin, ObjectValueType_Vector, newOrigin);
DebugLaser(client, origin, newOrigin, 15.0, 0.5, g_color2);
@@ -563,9 +691,12 @@ void SetVelocity(int client, float velocity[3], bool dontUseTeleportEntity = fal
}
}
public MRESReturn DHook_ProcessMovementPre(Handle hParams)
public MRESReturn DHook_ProcessMovementPre(DHookParam hParams)
{
int client = DHookGetParam(hParams, 1);
int client = hParams.Get(1);
if (!IsClientInGame(client))
return MRES_Ignored;
g_iTick[client]++;
g_flFrameTime[client] = GetTickInterval() * GetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue");
@@ -582,7 +713,7 @@ public MRESReturn DHook_ProcessMovementPre(Handle hParams)
return MRES_Ignored;
}
void RunPreTickChecks(int client, Handle hParams)
void RunPreTickChecks(int client, DHookParam hParams)
{
// Recreate enough of CGameMovement::ProcessMovement to predict if fixes are needed.
// We only really care about a limited set of scenarios (less than waist-deep in water, MOVETYPE_WALK, air movement).
@@ -598,20 +729,22 @@ void RunPreTickChecks(int client, Handle hParams)
g_iLastTickPredicted[client] = g_iTick[client];
g_iButtons[client] = DHookGetParamObjectPtrVar(hParams, 2, 36, ObjectValueType_Int);
g_iOldButtons[client] = DHookGetParamObjectPtrVar(hParams, 2, 40, ObjectValueType_Int);
DHookGetParamObjectPtrVarVector(hParams, 2, 44, ObjectValueType_Vector, g_vVel[client]);
DHookGetParamObjectPtrVarVector(hParams, 2, 12, ObjectValueType_Vector, g_vAngles[client]);
g_iButtons[client] = hParams.GetObjectVar(2, 36, ObjectValueType_Int);
g_iOldButtons[client] = hParams.GetObjectVar(2, 40, ObjectValueType_Int);
g_vVel[client][0] = hParams.GetObjectVar(2, g_iCMoveData_ForwardMove, ObjectValueType_Float);
g_vVel[client][1] = hParams.GetObjectVar(2, g_iCMoveData_SideMove, ObjectValueType_Float);
g_vVel[client][2] = 0.0;
hParams.GetObjectVarVector(2, 12, ObjectValueType_Vector, g_vAngles[client]);
float velocity[3];
DHookGetParamObjectPtrVarVector(hParams, 2, 64, ObjectValueType_Vector, velocity);
hParams.GetObjectVarVector(2, g_iCMoveData_Velocity, ObjectValueType_Vector, velocity);
float baseVelocity[3];
// basevelocity is not stored in MoveData
GetEntPropVector(client, Prop_Data, "m_vecBaseVelocity", baseVelocity);
float origin[3];
DHookGetParamObjectPtrVarVector(hParams, 2, GetEngineVersion() == Engine_CSGO ? 172 : 152, ObjectValueType_Vector, origin);
hParams.GetObjectVarVector(2, g_iCMoveData_Origin, ObjectValueType_Vector, origin);
float nextOrigin[3], mins[3], maxs[3];
@@ -779,6 +912,173 @@ public void Hook_PlayerGroundEntChanged(int client)
}
}
bool DoTriggerjumpFix(int client, const float landingPoint[3], const float landingMins[3], const float landingMaxs[3])
{
if (!g_cvTriggerjump.BoolValue) return false;
// It's possible to land above a trigger but also in another trigger_teleport, have the teleport move you to
// another location, and then the trigger jumping fix wouldn't fire the other trigger you technically landed above,
// but I can't imagine a mapper would ever actually stack triggers like that.
float origin[3];
GetEntPropVector(client, Prop_Data, "m_vecAbsOrigin", origin);
float landingMaxsBelow[3];
landingMaxsBelow[0] = landingMaxs[0];
landingMaxsBelow[1] = landingMaxs[1];
landingMaxsBelow[2] = origin[2] - landingPoint[2];
ArrayList triggers = new ArrayList();
// Find triggers that are between us and the ground (using the bounding box quadrant we landed with if applicable).
TR_EnumerateEntitiesHull(landingPoint, landingPoint, landingMins, landingMaxsBelow, true, AddTrigger, triggers);
bool didSomething = false;
for (int i = 0; i < triggers.Length; i++)
{
int trigger = triggers.Get(i);
// MarkEntitiesAsTouching always fires the Touch function even if it was already fired this tick.
// In case that could cause side-effects, manually keep track of triggers we are actually touching
// and don't re-touch them.
if (g_bTouchingTrigger[client][trigger]) continue;
DebugMsg(client, "DO FIX: Trigger Jumping (entity %i)", trigger);
SDKCall(g_hMarkEntitiesAsTouching, g_IServerGameEnts, client, trigger);
didSomething = true;
}
delete triggers;
return didSomething;
}
bool DoStairsFix(int client)
{
if (!g_cvStairs.BoolValue) return false;
if (g_iLastTickPredicted[client] != g_iTick[client]) return false;
// This fix has undesirable side-effects on bhop. It is also very unlikely to help on bhop.
if (!g_bIsSurfMap) return false;
// Let teleports take precedence (including teleports activated by the trigger jumping fix).
if (g_iLastMapTeleportTick[client] == g_iTick[client]) return false;
// If moving upward, the player would never be able to slide up with any current position.
if (g_vPreCollisionVelocity[client][2] > 0.0) return false;
// Stair step faces don't necessarily have to be completely vertical, but, if they are not,
// sliding up them at high speed -- or even just walking up -- usually doesn't work.
// Plus, it's really unlikely that there are actual stairs shaped like that.
if (g_iLastCollisionTick[client] == g_iTick[client] && g_vCollisionNormal[client][2] == 0.0)
{
// Do this first and stop if we are moving slowly (less than 1 unit per tick).
float velocity_dir[3];
velocity_dir = g_vPreCollisionVelocity[client];
velocity_dir[2] = 0.0;
if (NormalizeVector(velocity_dir, velocity_dir) * g_flFrameTime[client] < 1.0) return false;
float mins[3], maxs[3];
GetEntPropVector(client, Prop_Data, "m_vecMins", mins);
GetEntPropVector(client, Prop_Data, "m_vecMaxs", maxs);
// We seem to have collided with a "wall", now figure out if it's a stair step.
// Look for ground below us
float stepsize = GetEntPropFloat(client, Prop_Data, "m_flStepSize");
float end[3];
end = g_vCollisionPoint[client];
end[2] -= stepsize;
TR_TraceHullFilter(g_vCollisionPoint[client], end, mins, maxs, MASK_PLAYERSOLID, PlayerFilter);
if (TR_DidHit())
{
float nrm[3];
TR_GetPlaneNormal(null, nrm);
// Ground below is not walkable, not stairs
if (nrm[2] < MIN_STANDABLE_ZNRM) return false;
float start[3];
TR_GetEndPosition(start);
// Find triggers that we would trigger if we did touch the ground here.
ArrayList triggers = new ArrayList();
TR_EnumerateEntitiesHull(start, start, mins, maxs, true, AddTrigger, triggers);
for (int i = 0; i < triggers.Length; i++)
{
int trigger = triggers.Get(i);
if (SDKCall(g_hPassesTriggerFilters, trigger, client))
{
// We would have triggered something on the ground here, so we cant be sure the stairs fix is safe to do.
// The most likely scenario here is this isn't stairs, but just a short ledge with a fail teleport in front.
delete triggers;
return false;
}
}
delete triggers;
// Now follow CGameMovement::StepMove behavior.
// Trace up
end = start;
end[2] += stepsize;
TR_TraceHullFilter(start, end, mins, maxs, MASK_PLAYERSOLID, PlayerFilter);
if (TR_DidHit()) TR_GetEndPosition(end);
// Trace over (only 1 unit, just to find a stair step)
start = end;
AddVectors(start, velocity_dir, end);
TR_TraceHullFilter(start, end, mins, maxs, MASK_PLAYERSOLID, PlayerFilter);
if (TR_DidHit())
{
// The plane we collided with is too tall to be a stair step (i.e. it's a wall, not stairs).
// Or possibly: the ceiling is too low to get on top of it.
return false;
}
else
{
// Trace downward
start = end;
end[2] -= stepsize;
TR_TraceHullFilter(start, end, mins, maxs, MASK_PLAYERSOLID, PlayerFilter);
if (!TR_DidHit()) return false; // Shouldn't happen
TR_GetPlaneNormal(null, nrm);
// Ground atop "stair" is not walkable, not stairs
if (nrm[2] < MIN_STANDABLE_ZNRM) return false;
// It looks like we actually collided with a stair step.
// Put the player just barely on top of the stair step we found and restore their speed
TR_GetEndPosition(end);
DebugMsg(client, "DO FIX: Stair Sliding");
TeleportEntity(client, end, NULL_VECTOR, NULL_VECTOR);
SetVelocity(client, g_vPreCollisionVelocity[client]);
return true;
}
}
}
return false;
}
bool DoInclineCollisionFixes(int client, const float nrm[3])
{
if (!g_cvDownhill.BoolValue && g_cvUphill.IntValue != UPHILL_LOSS) return false;
@@ -968,6 +1268,17 @@ public void Hook_PlayerPostThink(int client)
}
}
if (landed && TR_GetFraction() > 0.0)
{
DoTriggerjumpFix(client, landingPoint, landingMins, landingMaxs);
// Check if a trigger we just touched put us in the air (probably due to a teleport).
if (GetEntityFlags(client) & FL_ONGROUND == 0) landed = false;
}
// The stair sliding fix changes the outcome of this tick more significantly, so it doesn't really make sense to do incline fixes too.
if (DoStairsFix(client)) return;
if (landed)
{
DoInclineCollisionFixes(client, nrm);
@@ -976,6 +1287,14 @@ public void Hook_PlayerPostThink(int client)
DoTelehopFix(client);
}
public bool AddTrigger(int entity, ArrayList triggers)
{
TR_ClipCurrentRayToEntity(MASK_ALL, entity);
if (TR_DidHit()) triggers.Push(entity);
return true;
}
bool TracePlayerBBoxForGround(const float origin[3], const float originBelow[3], float mins[3], float maxs[3])
{
// See CGameMovement::TracePlayerBBoxForGround()
@@ -1052,3 +1371,35 @@ bool TracePlayerBBoxForGround(const float origin[3], const float originBelow[3],
return false;
}
void Forward_OnTriggerDetected(int entity, const char[] classname)
{
Call_StartForward(g_hOnTriggerDetected);
Call_PushCell(entity);
Call_PushString(classname);
Call_Finish();
}
void Forward_OnTriggerStartTouch(int entity, int other)
{
Call_StartForward(g_hOnTriggerStartTouch);
Call_PushCell(entity);
Call_PushCell(other);
Call_Finish();
}
void Forward_OnTriggerEndTouch(int entity, int other)
{
Call_StartForward(g_hOnTriggerEndTouch);
Call_PushCell(entity);
Call_PushCell(other);
Call_Finish();
}
void Forward_OnTriggerTeleportEndTouch(int entity, int other)
{
Call_StartForward(g_hOnTriggerTeleportTouchPost);
Call_PushCell(entity);
Call_PushCell(other);
Call_Finish();
}