From c24e04a0eb41dcd3ad477fa140e06f06a337842f Mon Sep 17 00:00:00 2001 From: "zer0.k" Date: Sat, 11 Mar 2023 04:16:58 +0100 Subject: [PATCH 1/4] Use TryPlayerMove's m_tracelist for true landing origin in bugged jumps --- .../sourcemod/gamedata/movementapi.games.txt | 42 ++++++ .../scripting/include/movementapi.inc | 77 +++++++++- .../scripting/movementapi/forwards.sp | 25 ++++ .../sourcemod/scripting/movementapi/hooks.sp | 91 +++++++++++- .../scripting/movementapi/natives.sp | 28 ++++ .../sourcemod/scripting/movementapi/stocks.sp | 137 ++++++++++++++++++ 6 files changed, 398 insertions(+), 2 deletions(-) diff --git a/addons/sourcemod/gamedata/movementapi.games.txt b/addons/sourcemod/gamedata/movementapi.games.txt index 38194aa..bb1a6b4 100644 --- a/addons/sourcemod/gamedata/movementapi.games.txt +++ b/addons/sourcemod/gamedata/movementapi.games.txt @@ -2,6 +2,24 @@ { "csgo" { + "Addresses" + { + "sm_pSingleton" + { + "windows" + { + "signature" "CGameMovement::TryPlayerMove" + "read" "718" + } + "linux" + { + "signature" "CGameMovement::TryPlayerMove" + "read" "483" + } + + "read" "0" + } + } "Keys" { "CGameMovement::player" "4" @@ -90,6 +108,24 @@ "this" "address" "return" "void" } + "CGameMovement::TryPlayerMove" + { + "signature" "CGameMovement::TryPlayerMove" + "callconv" "thiscall" + "this" "address" + "return" "int" + "arguments" + { + "pFirstDest" + { + "type" "vectorptr" + } + "pFirstTrace" + { + "type" "objectptr" + } + } + } } "Offsets" { @@ -150,6 +186,12 @@ "windows" "\x2A\x2A\x2A\x2A\x2A\x2A\x2A\x2A\xF9\xC7\x45\x2A\x00\x00\x00\x00\x8B\x47\x2A\xC7\x80" "linux" "\x2A\x2A\x2A\x2A\x2A\x2A\x2A\x2A\x2A\x00\x00\x00\xC7\x45\x2A\x00\x00\x00\x00\x8B\x5D\x2A\x8B\x43\x2A\xC7" } + "CGameMovement::TryPlayerMove" + { + "library" "server" + "windows" "\x55\x8B\xEC\x83\xE4\xF8\x81\xEC\x38\x01\x00\x00\xF3\x0F\x10\x35\x2A\x2A\x2A\x2A" + "linux" "\x55\x66\x0F\xEF\xDB\x89\xE5\x57\x56\x53\x81\xEC\x2A\x2A\x2A\x2A\x8B\x7D\x08" + } } } } \ No newline at end of file diff --git a/addons/sourcemod/scripting/include/movementapi.inc b/addons/sourcemod/scripting/include/movementapi.inc index 45ee263..08a073a 100644 --- a/addons/sourcemod/scripting/include/movementapi.inc +++ b/addons/sourcemod/scripting/include/movementapi.inc @@ -283,6 +283,28 @@ forward Action Movement_OnCategorizePositionPre(int client, float origin[3], flo */ forward Action Movement_OnCategorizePositionPost(int client, float origin[3], float velocity[3]); +/** + * Called before TryPlayerMove movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnTryPlayerMovePre(int client, float origin[3], float velocity[3]); + +/** + * Called after TryPlayerMove movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnTryPlayerMovePost(int client, float origin[3], float velocity[3]); + // =====[ NATIVES ]===== /** @@ -484,13 +506,42 @@ native void Movement_SetTakeoffVelocity(int client, float velocity[3]); */ native void Movement_SetLandingOrigin(int client, float origin[3]); +/** + * Get the player's number of collisions during movement processing. + * This function should ideally be called after inside Movement_OnTryPlayerMovePost. + * + * @param client Client index. + * @param origin Desired velocity. + */ +native int Movement_GetCollisionCount(int client); + +/** + * Set the player's landing velocity. + * This function should ideally be called after inside Movement_OnTryPlayerMovePost. + * + * @param client Client index. + * @param num Collision number, must not exceed Movement_GetCollisionCount's value. + * @param result Resultant vector. + */ +native void Movement_GetCollisionStartOrigin(int client, int num, float result[3]); + +/** + * Set the player's landing velocity. + * This function should ideally be called after inside Movement_OnTryPlayerMovePost. + * + * @param client Client index. + * @param origin Desired velocity. + */ +native void Movement_GetCollisionEndOrigin(int client, int num, float result[3]); + /** * Set the player's landing velocity. + * This function should ideally be called after inside Movement_OnTryPlayerMovePost. * * @param client Client index. * @param origin Desired velocity. */ -native void Movement_SetLandingVelocity(int client, float velocity[3]); +native void Movement_GetCollisionNormal(int client, int num, float result[3]); // =====[ METHODMAP ]===== @@ -608,6 +659,26 @@ methodmap MovementAPIPlayer < MovementPlayer { } } + property int CollisionCount { + public get() { + return Movement_GetCollisionCount(this.ID); + } + } + public void GetCollisionStartOrigin(int num, float buffer[3]) + { + Movement_GetCollisionStartOrigin(this.ID, num, buffer); + } + + public void GetCollisionEndOrigin(int num, float buffer[3]) + { + Movement_GetCollisionEndOrigin(this.ID, num, buffer); + } + + public void GetCollisionNormal(int num, float buffer[3]) + { + Movement_GetCollisionNormal(this.ID, num, buffer); + } + public void GetProcessingVelocity(float buffer[3]) { Movement_GetProcessingVelocity(this.ID, buffer); @@ -659,5 +730,9 @@ public void __pl_movementapi_SetNTVOptional() MarkNativeAsOptional("Movement_SetTakeoffVelocity"); MarkNativeAsOptional("Movement_SetLandingOrigin"); MarkNativeAsOptional("Movement_SetLandingVelocity"); + MarkNativeAsOptional("Movement_GetCollisionCount"); + MarkNativeAsOptional("Movement_GetCollisionStartOrigin"); + MarkNativeAsOptional("Movement_GetCollisionEndOrigin"); + MarkNativeAsOptional("Movement_GetCollisionNormal"); } #endif diff --git a/addons/sourcemod/scripting/movementapi/forwards.sp b/addons/sourcemod/scripting/movementapi/forwards.sp index 0cf8e53..9653b57 100644 --- a/addons/sourcemod/scripting/movementapi/forwards.sp +++ b/addons/sourcemod/scripting/movementapi/forwards.sp @@ -21,6 +21,8 @@ static Handle H_OnWalkMovePre; static Handle H_OnWalkMovePost; static Handle H_OnCategorizePositionPre; static Handle H_OnCategorizePositionPost; +static Handle H_OnTryPlayerMovePre; +static Handle H_OnTryPlayerMovePost; void CreateGlobalForwards() { @@ -54,6 +56,9 @@ void CreateGlobalForwards() H_OnCategorizePositionPre = CreateGlobalForward("Movement_OnCategorizePositionPre", ET_Event, Param_Cell, Param_Array, Param_Array); H_OnCategorizePositionPost = CreateGlobalForward("Movement_OnCategorizePositionPost", ET_Event, Param_Cell, Param_Array, Param_Array); + + H_OnTryPlayerMovePre = CreateGlobalForward("Movement_OnTryPlayerMovePre", ET_Event, Param_Cell, Param_Array, Param_Array); + H_OnTryPlayerMovePost = CreateGlobalForward("Movement_OnTryPlayerMovePost", ET_Event, Param_Cell, Param_Array, Param_Array); } void Call_OnStartDucking(int client) @@ -263,4 +268,24 @@ Action Call_OnCategorizePositionPost(int client, float origin[3], float velocity Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); Call_Finish(result); return result; +} + +Action Call_OnTryPlayerMovePre(int client, float origin[3], float velocity[3], Action &result) +{ + Call_StartForward(H_OnTryPlayerMovePre); + Call_PushCell(client); + Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); + Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); + Call_Finish(result); + return result; +} + +Action Call_OnTryPlayerMovePost(int client, float origin[3], float velocity[3], Action &result) +{ + Call_StartForward(H_OnTryPlayerMovePost); + Call_PushCell(client); + Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); + Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); + Call_Finish(result); + return result; } \ No newline at end of file diff --git a/addons/sourcemod/scripting/movementapi/hooks.sp b/addons/sourcemod/scripting/movementapi/hooks.sp index 73783bf..f53e89b 100644 --- a/addons/sourcemod/scripting/movementapi/hooks.sp +++ b/addons/sourcemod/scripting/movementapi/hooks.sp @@ -6,6 +6,9 @@ static DynamicDetour H_OnJump; static DynamicDetour H_OnAirAccelerate; static DynamicDetour H_OnWalkMove; static DynamicDetour H_OnCategorizePosition; +static DynamicDetour H_OnTryPlayerMove; +static Address moveHelperAddr; +static bool tryPlayerMoveThisTick; float gF_Origin[MAXPLAYERS + 1][3]; float gF_Velocity[MAXPLAYERS + 1][3]; @@ -31,6 +34,12 @@ float gF_PostAAVelocity[MAXPLAYERS + 1][3]; bool gB_OldWalkMoved[MAXPLAYERS + 1]; +int gI_CollisionCount[MAXPLAYERS + 1]; + +float gF_TraceStartOrigin[MAXPLAYERS + 1][MAX_BUMPS][3]; +float gF_TraceEndOrigin[MAXPLAYERS + 1][MAX_BUMPS][3]; +float gF_TraceNormal[MAXPLAYERS + 1][MAX_BUMPS][3]; + void HookGameMovementFunctions() { HookGameMovementFunction(H_OnDuck, "CCSGameMovement::Duck", DHooks_OnDuck_Pre, DHooks_OnDuck_Post); @@ -41,6 +50,13 @@ void HookGameMovementFunctions() HookGameMovementFunction(H_OnJump, "CCSGameMovement::OnJump", DHooks_OnJump_Pre, DHooks_OnJump_Post); HookGameMovementFunction(H_OnPlayerMove, "CCSGameMovement::PlayerMove", DHooks_OnPlayerMove_Pre, DHooks_OnPlayerMove_Post); HookGameMovementFunction(H_OnCategorizePosition, "CGameMovement::CategorizePosition", DHooks_OnCategorizePosition_Pre, DHooks_OnCategorizePosition_Post); + HookGameMovementFunction(H_OnTryPlayerMove, "CGameMovement::TryPlayerMove", DHooks_OnTryPlayerMove_Pre, DHooks_OnTryPlayerMove_Post); + + moveHelperAddr = GameConfGetAddress(gH_GameData, "sm_pSingleton"); + if (!moveHelperAddr) + { + SetFailState("Failed to find IMoveHelper::sm_pSingleton."); + } } Action UpdateMoveData(Address pThis, int client, Function func) @@ -429,7 +445,7 @@ public MRESReturn DHooks_OnPlayerMove_Post(Address pThis) return MRES_Ignored; } Action result = UpdateMoveData(pThis, client, Call_OnPlayerMovePost); - + tryPlayerMoveThisTick = false; if (result != Plugin_Continue) { return MRES_Handled; @@ -512,8 +528,81 @@ public MRESReturn DHooks_OnCategorizePosition_Post(Address pThis) } } +public MRESReturn DHooks_OnTryPlayerMove_Pre(Address pThis, DHookReturn hReturn, DHookParam hParams) +{ + int client = GetClientFromGameMovementAddress(pThis); + if (!IsPlayerAlive(client) || IsFakeClient(client)) + { + return MRES_Ignored; + } + Action result = UpdateMoveData(pThis, client, Call_OnTryPlayerMovePre); + + for (int i = 0; i < MAX_BUMPS; i++) + { + gF_TraceStartOrigin[client][i] = NULL_VECTOR; + gF_TraceEndOrigin[client][i] = NULL_VECTOR; + gF_TraceNormal[client][i] = NULL_VECTOR; + } + + if (result != Plugin_Continue) + { + return MRES_Handled; + } + else + { + return MRES_Ignored; + } +} + +public MRESReturn DHooks_OnTryPlayerMove_Post(Address pThis, DHookReturn hReturn, DHookParam hParams) +{ + int client = GetClientFromGameMovementAddress(pThis); + if (!IsPlayerAlive(client) || IsFakeClient(client)) + { + return MRES_Ignored; + } + + tryPlayerMoveThisTick = true; + gI_CollisionCount[client] = LoadFromAddress(moveHelperAddr + view_as
(8) + view_as
(12), NumberType_Int32); + + Address m_TouchList_m_pElements = LoadFromAddress(moveHelperAddr + view_as
(8) + view_as
(16), NumberType_Int32); + + bool hitStandableSurface = false; + static ConVar sv_standable_normal; + if (sv_standable_normal == INVALID_HANDLE) + { + sv_standable_normal = FindConVar("sv_standable_normal"); + } + for (int i = 0; i < gI_CollisionCount[client]; i++) + { + Trace trace = Trace(m_TouchList_m_pElements + view_as
(i*96) + view_as
(12)); + trace.startpos.ToArray(gF_TraceStartOrigin[client][i]); + trace.endpos.ToArray(gF_TraceEndOrigin[client][i]); + trace.plane.normal.ToArray(gF_TraceNormal[client][i]); + } + } + + Action result = UpdateMoveData(pThis, client, Call_OnTryPlayerMovePost); + if (result != Plugin_Continue) + { + return MRES_Handled; + } + else + { + return MRES_Ignored; + } +} + static void NobugLandingOrigin(int client, float landingOrigin[3]) { + // Jump is bugged, try to use the trace result of TryPlayerMove if possible. + if (tryPlayerMoveThisTick && gI_CollisionCount[client] > 0) + { + landingOrigin = gF_TraceEndOrigin[client][0]; + return; + } + // Fallback when no collision happened during TryPlayerMove, or that function was not called. + // NOTE: Get ground position and distance to ground. float groundEndPoint[3]; groundEndPoint = gF_Origin[client]; diff --git a/addons/sourcemod/scripting/movementapi/natives.sp b/addons/sourcemod/scripting/movementapi/natives.sp index f8cd7a5..0e5d45a 100644 --- a/addons/sourcemod/scripting/movementapi/natives.sp +++ b/addons/sourcemod/scripting/movementapi/natives.sp @@ -25,6 +25,11 @@ void CreateNatives() CreateNative("Movement_SetTakeoffVelocity", Native_SetTakeoffVelocity); CreateNative("Movement_SetLandingOrigin", Native_SetLandingOrigin); CreateNative("Movement_SetLandingVelocity", Native_SetLandingVelocity); + + CreateNative("Movement_GetCollisionCount", Native_GetCollisionCount); + CreateNative("Movement_GetCollisionStartOrigin", Native_GetCollisionStartOrigin); + CreateNative("Movement_GetCollisionEndOrigin", Native_GetCollisionEndOrigin); + CreateNative("Movement_GetCollisionNormal", Native_GetCollisionNormal); } public int Native_GetJumped(Handle plugin, int numParams) @@ -180,4 +185,27 @@ public int Native_SetLandingVelocity(Handle plugin, int numParams) } return 0; +} + +public int Native_GetCollisionCount(Handle plugin, int numParams) +{ + return gI_CollisionCount[GetNativeCell(1)]; +} + +public int Native_GetCollisionStartOrigin(Handle plugin, int numParams) +{ + SetNativeArray(3, gF_TraceStartOrigin[GetNativeCell(1)][GetNativeCell(2)], sizeof(gF_TraceStartOrigin[][])); + return 0; +} + +public int Native_GetCollisionEndOrigin(Handle plugin, int numParams) +{ + SetNativeArray(3, gF_TraceEndOrigin[GetNativeCell(1)][GetNativeCell(2)], sizeof(gF_TraceEndOrigin[][])); + return 0; +} + +public int Native_GetCollisionNormal(Handle plugin, int numParams) +{ + SetNativeArray(3, gF_TraceNormal[GetNativeCell(1)][GetNativeCell(2)], sizeof(gF_TraceNormal[][])); + return 0; } \ No newline at end of file diff --git a/addons/sourcemod/scripting/movementapi/stocks.sp b/addons/sourcemod/scripting/movementapi/stocks.sp index e080efc..fde78fd 100644 --- a/addons/sourcemod/scripting/movementapi/stocks.sp +++ b/addons/sourcemod/scripting/movementapi/stocks.sp @@ -1,3 +1,140 @@ +#define MAX_BUMPS 4 + +methodmap Vector +{ + public Vector(Address address) + { + return view_as(address); + } + + property float x + { + public get() + { + return view_as( LoadFromAddress(view_as
(this) + view_as
(0), NumberType_Int32) ); + } + public set(float x) + { + StoreToAddress(view_as
(this) + view_as
(0), view_as(x), NumberType_Int32, false); + } + } + + property float y + { + public get() + { + return view_as( LoadFromAddress(view_as
(this) + view_as
(4), NumberType_Int32) ); + } + public set(float y) + { + StoreToAddress(view_as
(this) + view_as
(4), view_as(y), NumberType_Int32, false); + } + } + + property float z + { + public get() + { + return view_as( LoadFromAddress(view_as
(this) + view_as
(8), NumberType_Int32) ); + } + public set(float z) + { + StoreToAddress(view_as
(this) + view_as
(8), view_as(z), NumberType_Int32, false); + } + } + + public void ToArray(float vec[3]) + { + vec[0] = this.x; + vec[1] = this.y; + vec[2] = this.z; + } +}; + +methodmap Plane +{ + public Plane(Address address) + { + return view_as(address); + } + + property Vector normal + { + public get() + { + return view_as( view_as
(this) + view_as
(0) ); + } + } + + property float dist + { + public get() + { + return view_as( LoadFromAddress(view_as
(this) + view_as
(12), NumberType_Int32) ); + } + public set(float dist) + { + StoreToAddress(view_as
(this) + view_as
(12), view_as(dist), NumberType_Int32, false); + } + } + + property int type + { + public get() + { + return view_as( LoadFromAddress(view_as
(this) + view_as
(16), NumberType_Int8) ); + } + public set(int type) + { + StoreToAddress(view_as
(this) + view_as
(16), view_as(type), NumberType_Int8, false); + } + } + + property int signbits + { + public get() + { + return view_as( LoadFromAddress(view_as
(this) + view_as
(17), NumberType_Int8) ); + } + public set(int signbits) + { + StoreToAddress(view_as
(this) + view_as
(17), view_as(signbits), NumberType_Int8, false); + } + } +}; + +methodmap Trace +{ + public Trace(Address address) + { + return view_as(address); + } + + property Vector startpos + { + public get() + { + return view_as( view_as
(this) + view_as
(0) ); + } + } + + property Vector endpos + { + public get() + { + return view_as( view_as
(this) + view_as
(12) ); + } + } + + property Plane plane + { + public get() + { + return view_as( view_as
(this) + view_as
(24) ); + } + } +}; + stock void GameMove_SetVelocity(Address addr, float velocity[3]) { if (velocity[0] != velocity[0] || velocity[1] != velocity[1] || velocity[2] != velocity[2]) From ddd70ff9108d5b5ba96c61d572089a2eacb2584b Mon Sep 17 00:00:00 2001 From: "zer0.k" Date: Sat, 11 Mar 2023 04:20:57 +0100 Subject: [PATCH 2/4] Remove unnecessary code --- addons/sourcemod/scripting/movementapi/hooks.sp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/addons/sourcemod/scripting/movementapi/hooks.sp b/addons/sourcemod/scripting/movementapi/hooks.sp index f53e89b..a21a03b 100644 --- a/addons/sourcemod/scripting/movementapi/hooks.sp +++ b/addons/sourcemod/scripting/movementapi/hooks.sp @@ -567,12 +567,6 @@ public MRESReturn DHooks_OnTryPlayerMove_Post(Address pThis, DHookReturn hReturn Address m_TouchList_m_pElements = LoadFromAddress(moveHelperAddr + view_as
(8) + view_as
(16), NumberType_Int32); - bool hitStandableSurface = false; - static ConVar sv_standable_normal; - if (sv_standable_normal == INVALID_HANDLE) - { - sv_standable_normal = FindConVar("sv_standable_normal"); - } for (int i = 0; i < gI_CollisionCount[client]; i++) { Trace trace = Trace(m_TouchList_m_pElements + view_as
(i*96) + view_as
(12)); @@ -580,7 +574,6 @@ public MRESReturn DHooks_OnTryPlayerMove_Post(Address pThis, DHookReturn hReturn trace.endpos.ToArray(gF_TraceEndOrigin[client][i]); trace.plane.normal.ToArray(gF_TraceNormal[client][i]); } - } Action result = UpdateMoveData(pThis, client, Call_OnTryPlayerMovePost); if (result != Plugin_Continue) From 0a8e982476b6ef4b95bd1cf87b4f9f002f994473 Mon Sep 17 00:00:00 2001 From: "zer0.k" Date: Sat, 11 Mar 2023 04:22:33 +0100 Subject: [PATCH 3/4] Add edgebug forward --- .../scripting/include/movementapi.inc | 1442 +++++++++-------- .../scripting/movementapi/forwards.sp | 587 +++---- .../sourcemod/scripting/movementapi/hooks.sp | 33 + 3 files changed, 1058 insertions(+), 1004 deletions(-) diff --git a/addons/sourcemod/scripting/include/movementapi.inc b/addons/sourcemod/scripting/include/movementapi.inc index 08a073a..cfaa649 100644 --- a/addons/sourcemod/scripting/include/movementapi.inc +++ b/addons/sourcemod/scripting/include/movementapi.inc @@ -1,288 +1,298 @@ -/* - MovementAPI Plugin Include - - Website: https://github.com/danzayau/MovementAPI -*/ - -#if defined _movementapi_included_ - #endinput -#endif -#define _movementapi_included_ - -#include - - - -/* - Terminology - - Takeoff - Becoming airborne, including jumping, falling, getting off a ladder and leaving noclip. - - Landing - Leaving the air, including landing on the ground, grabbing a ladder and entering noclip. - - Perfect Bunnyhop (Perf) - When the player has jumped in the tick after landing and keeps their speed. - - Duckbug/Crouchbug - When the player sucessfully lands due to uncrouching from mid air and not by falling - down. This causes no stamina loss or fall damage upon landing. - - Jumpbug - This is achieved by duckbugging and jumping at the same time. The player is never seen - as 'on ground' when bunnyhopping from a tick by tick perspective. A jumpbug inherits - the same behavior as a duckbug/crouchbug, along with its effects such as maintaining - speed due to no stamina loss. - - Distbug - Landing behavior varies depending on whether the player lands close to the edge of a - block or not: - - 1. If the player lands close to the edge of a block, this causes the jump duration to - be one tick longer and the player can "slide" on the ground during the landing tick, - using the position post-tick as landing position becomes inaccurate. - - 2. On the other hand, if the player does not land close to the edge, the player will - be considered on the ground one tick earlier, using this position as landing position - is not accurate as the player has yet to be fully on the ground. - - In scenario 1, GetNobugLandingOrigin calculates the correct landing position of the - player before the sliding effect takes effect. - - In scenario 2, GetNobugLandingOrigin attempts to extrapolate the player's fully on - ground position to make landing positions consistent across scenarios. -*/ - - - -// =====[ FORWARDS ]===== - -/** - * Called when a player's movetype changes. - * - * @param client Client index. - * @param oldMovetype Player's old movetype. - * @param newMovetype Player's new movetype. - */ -forward void Movement_OnChangeMovetype(int client, MoveType oldMovetype, MoveType newMovetype); - -/** - * Called when a player touches the ground. - * - * @param client Client index. - */ -forward void Movement_OnStartTouchGround(int client); - -/** - * Called when a player leaves the ground. - * - * @param client Client index. - * @param jumped Whether player jumped to leave ground. - * @param ladderJump Whether player jumped from a ladder. - * @param jumpbug Whether player performed a jumpbug. - */ -forward void Movement_OnStopTouchGround(int client, bool jumped, bool ladderJump, bool jumpbug); - -/** - * Called when a player starts ducking. - * - * @param client Client index. - */ -forward void Movement_OnStartDucking(int client); - -/** - * Called when a player stops ducking. - * - * @param client Client index. - */ -forward void Movement_OnStopDucking(int client); - -/** - * Called when a player jumps (player_jump event), including 'jumpbugs'. - * Setting velocity when this is called may not be effective. - * - * @param client Client index. - * @param jumpbug Whether player 'jumpbugged'. - */ -forward void Movement_OnPlayerJump(int client, bool jumpbug); - -/** - * Called before PlayerMove movement function is called. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnPlayerMovePre(int client, float origin[3], float velocity[3]); - -/** - * Called after PlayerMove movement function is called. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnPlayerMovePost(int client, float origin[3], float velocity[3]); - -/** - * Called before Duck movement function is called. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnDuckPre(int client, float origin[3], float velocity[3]); - -/** - * Called after Duck movement function is called. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnDuckPost(int client, float origin[3], float velocity[3]); - -/** - * Called before LadderMove movement function is called. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnLadderMovePre(int client, float origin[3], float velocity[3]); - -/** - * Called after LadderMove movement function is called. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnLadderMovePost(int client, float origin[3], float velocity[3]); - -/** - * Called before FullLadderMove movement function is called. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnFullLadderMovePre(int client, float origin[3], float velocity[3]); - -/** - * Called after FullLadderMove movement function is called. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnFullLadderMovePost(int client, float origin[3], float velocity[3]); - -/** - * Called after the player jumps, but before jumping stamina is applied and takeoff variables are not set yet. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnJumpPre(int client, float origin[3], float velocity[3]); - -/** - * Called after the player jumps and after jumping stamina is applied and takeoff variables are already set here. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnJumpPost(int client, float origin[3], float velocity[3]); - -/** - * Called before AirAccelerate movement function is called. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnAirAcceleratePre(int client, float origin[3], float velocity[3]); - -/** - * Called after AirAccelerate movement function is called. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnAirAcceleratePost(int client, float origin[3], float velocity[3]); - -/** - * Called before WalkMove movement function is called. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnWalkMovePre(int client, float origin[3], float velocity[3]); - -/** - * Called after WalkMove movement function is called. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnWalkMovePost(int client, float origin[3], float velocity[3]); - -/** - * Called before CategorizePosition movement function is called. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnCategorizePositionPre(int client, float origin[3], float velocity[3]); - -/** - * Called after CategorizePosition movement function is called. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnCategorizePositionPost(int client, float origin[3], float velocity[3]); - +/* + MovementAPI Plugin Include + + Website: https://github.com/danzayau/MovementAPI +*/ + +#if defined _movementapi_included_ + #endinput +#endif +#define _movementapi_included_ + +#include + + + +/* + Terminology + + Takeoff + Becoming airborne, including jumping, falling, getting off a ladder and leaving noclip. + + Landing + Leaving the air, including landing on the ground, grabbing a ladder and entering noclip. + + Perfect Bunnyhop (Perf) + When the player has jumped in the tick after landing and keeps their speed. + + Duckbug/Crouchbug + When the player sucessfully lands due to uncrouching from mid air and not by falling + down. This causes no stamina loss or fall damage upon landing. + + Jumpbug + This is achieved by duckbugging and jumping at the same time. The player is never seen + as 'on ground' when bunnyhopping from a tick by tick perspective. A jumpbug inherits + the same behavior as a duckbug/crouchbug, along with its effects such as maintaining + speed due to no stamina loss. + + Distbug + Landing behavior varies depending on whether the player lands close to the edge of a + block or not: + + 1. If the player lands close to the edge of a block, this causes the jump duration to + be one tick longer and the player can "slide" on the ground during the landing tick, + using the position post-tick as landing position becomes inaccurate. + + 2. On the other hand, if the player does not land close to the edge, the player will + be considered on the ground one tick earlier, using this position as landing position + is not accurate as the player has yet to be fully on the ground. + + In scenario 1, GetNobugLandingOrigin calculates the correct landing position of the + player before the sliding effect takes effect. + + In scenario 2, GetNobugLandingOrigin attempts to extrapolate the player's fully on + ground position to make landing positions consistent across scenarios. +*/ + + + +// =====[ FORWARDS ]===== + +/** + * Called when a player's movetype changes. + * + * @param client Client index. + * @param oldMovetype Player's old movetype. + * @param newMovetype Player's new movetype. + */ +forward void Movement_OnChangeMovetype(int client, MoveType oldMovetype, MoveType newMovetype); + +/** + * Called when a player touches the ground. + * + * @param client Client index. + */ +forward void Movement_OnStartTouchGround(int client); + +/** + * Called when a player leaves the ground. + * + * @param client Client index. + * @param jumped Whether player jumped to leave ground. + * @param ladderJump Whether player jumped from a ladder. + * @param jumpbug Whether player performed a jumpbug. + */ +forward void Movement_OnStopTouchGround(int client, bool jumped, bool ladderJump, bool jumpbug); + +/** + * Called when a player starts ducking. + * + * @param client Client index. + */ +forward void Movement_OnStartDucking(int client); + +/** + * Called when a player stops ducking. + * + * @param client Client index. + */ +forward void Movement_OnStopDucking(int client); + +/** + * Called when a player jumps (player_jump event), including 'jumpbugs'. + * Setting velocity when this is called may not be effective. + * + * @param client Client index. + * @param jumpbug Whether player 'jumpbugged'. + */ +forward void Movement_OnPlayerJump(int client, bool jumpbug); + +/** + * Called when a player edgebugs + * Setting velocity when this is called may not be effective. + * + * @param client Client index. + * @param origin Player origin before edgebug. + * @param velocity Player velocity before edgebug. + */ +forward void Movement_OnPlayerEdgebug(int client, float origin[3], float velocity[3]); + +/** + * Called before PlayerMove movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnPlayerMovePre(int client, float origin[3], float velocity[3]); + +/** + * Called after PlayerMove movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnPlayerMovePost(int client, float origin[3], float velocity[3]); + +/** + * Called before Duck movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnDuckPre(int client, float origin[3], float velocity[3]); + +/** + * Called after Duck movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnDuckPost(int client, float origin[3], float velocity[3]); + +/** + * Called before LadderMove movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnLadderMovePre(int client, float origin[3], float velocity[3]); + +/** + * Called after LadderMove movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnLadderMovePost(int client, float origin[3], float velocity[3]); + +/** + * Called before FullLadderMove movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnFullLadderMovePre(int client, float origin[3], float velocity[3]); + +/** + * Called after FullLadderMove movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnFullLadderMovePost(int client, float origin[3], float velocity[3]); + +/** + * Called after the player jumps, but before jumping stamina is applied and takeoff variables are not set yet. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnJumpPre(int client, float origin[3], float velocity[3]); + +/** + * Called after the player jumps and after jumping stamina is applied and takeoff variables are already set here. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnJumpPost(int client, float origin[3], float velocity[3]); + +/** + * Called before AirAccelerate movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnAirAcceleratePre(int client, float origin[3], float velocity[3]); + +/** + * Called after AirAccelerate movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnAirAcceleratePost(int client, float origin[3], float velocity[3]); + +/** + * Called before WalkMove movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnWalkMovePre(int client, float origin[3], float velocity[3]); + +/** + * Called after WalkMove movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnWalkMovePost(int client, float origin[3], float velocity[3]); + +/** + * Called before CategorizePosition movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnCategorizePositionPre(int client, float origin[3], float velocity[3]); + +/** + * Called after CategorizePosition movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnCategorizePositionPost(int client, float origin[3], float velocity[3]); + /** * Called before TryPlayerMove movement function is called. * Modifying origin or velocity parameters will change player's origin and velocity accordingly. @@ -305,434 +315,434 @@ forward Action Movement_OnTryPlayerMovePre(int client, float origin[3], float ve */ forward Action Movement_OnTryPlayerMovePost(int client, float origin[3], float velocity[3]); -// =====[ NATIVES ]===== - -/** - * Gets whether a player's last takeoff was a jump. - * - * @param client Client index. - * @return Whether player's last takeoff was a jump. - */ -native bool Movement_GetJumped(int client); - -/** - * Gets whether a player's last takeoff was a perfect bunnyhop. - * - * @param client Client index. - * @return Whether player's last takeoff was a perfect bunnyhop. - */ -native bool Movement_GetHitPerf(int client); - -/** - * Gets a player's origin at the time of their last takeoff. - * - * @param client Client index. - * @param result Resultant vector. - */ -native void Movement_GetTakeoffOrigin(int client, float result[3]); - -/** - * Gets a player's velocity at the time of their last takeoff. - * - * If sv_enablebunnyhopping is 0, CS:GO may adjust the player's - * velocity after the takeoff velocity has already been measured. - * - * @param client Client index. - * @param result Resultant vector. - */ -native void Movement_GetTakeoffVelocity(int client, float result[3]); - -/** - * Gets a player's horizontal speed at the time of their last takeoff. - * - * If sv_enablebunnyhopping is 0, CS:GO may adjust the player's - * velocity after the takeoff velocity has already been measured. - * - * @param client Client index. - * @return Player's last takeoff speed. - */ -native float Movement_GetTakeoffSpeed(int client); - -/** - * Gets a player's 'tickcount' at the time of their last takeoff. - * - * @param client Client index. - * @return Player's last takeoff 'tickcount'. - */ -native int Movement_GetTakeoffTick(int client); - -/** - * Gets a player's 'cmdnum' at the time of their last takeoff. - * - * @param client Client index. - * @return Player's last takeoff 'cmdnum'. - */ -native int Movement_GetTakeoffCmdNum(int client); - -/** - * Gets a player's origin at the time of their last landing with the distbug fixed. - * - * @param client Client index. - * @param result Resultant vector. - */ -native void Movement_GetNobugLandingOrigin(int client, float result[3]); - -/** - * Gets a player's origin at the time of their last landing. - * - * @param client Client index. - * @param result Resultant vector. - */ -native void Movement_GetLandingOrigin(int client, float result[3]); - -/** - * Gets a player's velocity at the time of their last landing. - * - * @param client Client index. - * @param result Resultant vector. - */ -native void Movement_GetLandingVelocity(int client, float result[3]); - -/** - * Gets a player's horizontal speed at the time of their last landing. - * - * @param client Client index. - * @return Last landing speed of the player (horizontal). - */ -native float Movement_GetLandingSpeed(int client); - -/** - * Gets a player's 'tickcount' at the time of their last landing. - * - * @param client Client index. - * @return Player's last landing 'tickcount'. - */ -native int Movement_GetLandingTick(int client); - -/** - * Gets a player's 'cmdnum' at the time of their last landing. - * - * @param client Client index. - * @return Player's last landing 'cmdnum'. - */ -native int Movement_GetLandingCmdNum(int client); - -/** - * Gets whether a player is turning their aim horizontally. - * - * @param client Client index. - * @return Whether player is turning their aim horizontally. - */ -native bool Movement_GetTurning(int client); - -/** - * Gets whether a player is turning their aim left. - * - * @param client Client index. - * @return Whether player is turning their aim left. - */ -native bool Movement_GetTurningLeft(int client); - -/** - * Gets whether a player is turning their aim right. - * - * @param client Client index. - * @return Whether player is turning their aim right. - */ -native bool Movement_GetTurningRight(int client); - -/** - * Gets result of CCSPlayer::GetPlayerMaxSpeed(client), which - * is the player's max speed as limited by their weapon. - * - * @param client Client index. - * @return Player's max speed as limited by their weapon. - */ -native float Movement_GetMaxSpeed(int client); - -/** - * Gets whether a player duckbugged on this tick. - * - * @param client Client index. - * @return Whether a player duckbugged on this tick. - */ -native bool Movement_GetDuckbugged(int client); - -/** - * Gets whether a player jumpbugged on this tick. - * - * @param client Client index. - * @return Whether a player jumpbugged on this tick. - */ -native bool Movement_GetJumpbugged(int client); - -/** - * Get the player's origin during movement processing. - * - * @param client Client index. - * @param result Resultant vector. - */ -native void Movement_GetProcessingOrigin(int client, float result[3]); - -/** - * Get the player's velocity during movement processing. - * - * @param client Param description - * @param result Resultant vector. - */ -native void Movement_GetProcessingVelocity(int client, float result[3]); - -/** - * Set the player's takeoff origin. - * - * @param client Client index. - * @param origin Desired origin. - */ -native void Movement_SetTakeoffOrigin(int client, float origin[3]); - -/** - * Set the player's takeoff velocity. - * - * @param client Client index. - * @param origin Desired velocity. - */ -native void Movement_SetTakeoffVelocity(int client, float velocity[3]); - -/** - * Set the player's landing origin. - * - * @param client Client index. - * @param origin Desired origin. - */ -native void Movement_SetLandingOrigin(int client, float origin[3]); - -/** - * Get the player's number of collisions during movement processing. - * This function should ideally be called after inside Movement_OnTryPlayerMovePost. - * - * @param client Client index. - * @param origin Desired velocity. - */ -native int Movement_GetCollisionCount(int client); - -/** - * Set the player's landing velocity. - * This function should ideally be called after inside Movement_OnTryPlayerMovePost. - * - * @param client Client index. - * @param num Collision number, must not exceed Movement_GetCollisionCount's value. - * @param result Resultant vector. - */ -native void Movement_GetCollisionStartOrigin(int client, int num, float result[3]); - -/** - * Set the player's landing velocity. - * This function should ideally be called after inside Movement_OnTryPlayerMovePost. - * - * @param client Client index. - * @param origin Desired velocity. - */ -native void Movement_GetCollisionEndOrigin(int client, int num, float result[3]); - -/** - * Set the player's landing velocity. - * This function should ideally be called after inside Movement_OnTryPlayerMovePost. - * - * @param client Client index. - * @param origin Desired velocity. - */ -native void Movement_GetCollisionNormal(int client, int num, float result[3]); - -// =====[ METHODMAP ]===== - -methodmap MovementAPIPlayer < MovementPlayer { - - public MovementAPIPlayer(int client) { - return view_as(MovementPlayer(client)); - } - - property bool Jumped { - public get() { - return Movement_GetJumped(this.ID); - } - } - - property bool HitPerf { - public get() { - return Movement_GetHitPerf(this.ID); - } - } - - public void GetTakeoffOrigin(float buffer[3]) { - Movement_GetTakeoffOrigin(this.ID, buffer); - } - - public void GetTakeoffVelocity(float buffer[3]) { - Movement_GetTakeoffVelocity(this.ID, buffer); - } - - public void SetTakeoffOrigin(float buffer[3]) - { - Movement_SetTakeoffOrigin(this.ID, buffer); - } - - public void SetTakeoffVelocity(float buffer[3]) - { - Movement_SetTakeoffVelocity(this.ID, buffer); - } - - property float TakeoffSpeed { - public get() { - return Movement_GetTakeoffSpeed(this.ID); - } - } - - property int TakeoffTick { - public get() { - return Movement_GetTakeoffTick(this.ID); - } - } - - property int TakeoffCmdNum { - public get() { - return Movement_GetTakeoffCmdNum(this.ID); - } - } - - public void GetLandingOrigin(float buffer[3]) { - Movement_GetLandingOrigin(this.ID, buffer); - } - - public void GetLandingVelocity(float buffer[3]) { - Movement_GetLandingVelocity(this.ID, buffer); - } - - public void SetLandingOrigin(float buffer[3]) - { - Movement_SetLandingOrigin(this.ID, buffer); - } - - public void SetLandingVelocity(float buffer[3]) - { - Movement_SetLandingVelocity(this.ID, buffer); - } - - property float LandingSpeed { - public get() { - return Movement_GetLandingSpeed(this.ID); - } - } - - property int LandingTick { - public get() { - return Movement_GetLandingTick(this.ID); - } - } - - property int LandingCmdNum { - public get() { - return Movement_GetLandingCmdNum(this.ID); - } - } - - property bool Turning { - public get() { - return Movement_GetTurning(this.ID); - } - } - - property bool TurningLeft { - public get() { - return Movement_GetTurningLeft(this.ID); - } - } - - property bool TurningRight { - public get() { - return Movement_GetTurningRight(this.ID); - } - } - - property float MaxSpeed { - public get() { - return Movement_GetMaxSpeed(this.ID); - } - } - - property int CollisionCount { - public get() { - return Movement_GetCollisionCount(this.ID); - } - } - public void GetCollisionStartOrigin(int num, float buffer[3]) - { - Movement_GetCollisionStartOrigin(this.ID, num, buffer); - } - - public void GetCollisionEndOrigin(int num, float buffer[3]) - { - Movement_GetCollisionEndOrigin(this.ID, num, buffer); - } - - public void GetCollisionNormal(int num, float buffer[3]) - { - Movement_GetCollisionNormal(this.ID, num, buffer); - } - - public void GetProcessingVelocity(float buffer[3]) - { - Movement_GetProcessingVelocity(this.ID, buffer); - } - - public void GetProcessingOrigin(float buffer[3]) - { - Movement_GetProcessingOrigin(this.ID, buffer); - } -} - - - -// =====[ DEPENDENCY ]===== - -public SharedPlugin __pl_movementapi = -{ - name = "movementapi", - file = "movementapi.smx", - #if defined REQUIRE_PLUGIN - required = 1, - #else - required = 0, - #endif -}; - -#if !defined REQUIRE_PLUGIN -public void __pl_movementapi_SetNTVOptional() -{ - MarkNativeAsOptional("Movement_GetJumped"); - MarkNativeAsOptional("Movement_GetHitPerf"); - MarkNativeAsOptional("Movement_GetTakeoffOrigin"); - MarkNativeAsOptional("Movement_GetTakeoffVelocity"); - MarkNativeAsOptional("Movement_GetTakeoffSpeed"); - MarkNativeAsOptional("Movement_GetTakeoffTick"); - MarkNativeAsOptional("Movement_GetTakeoffCmdNum"); - MarkNativeAsOptional("Movement_GetLandingOrigin"); - MarkNativeAsOptional("Movement_GetLandingVelocity"); - MarkNativeAsOptional("Movement_GetLandingSpeed"); - MarkNativeAsOptional("Movement_GetLandingTick"); - MarkNativeAsOptional("Movement_GetLandingCmdNum"); - MarkNativeAsOptional("Movement_GetTurning"); - MarkNativeAsOptional("Movement_GetTurningLeft"); - MarkNativeAsOptional("Movement_GetTurningRight"); - MarkNativeAsOptional("Movement_GetMaxSpeed"); - MarkNativeAsOptional("Movement_GetProcessingOrigin"); - MarkNativeAsOptional("Movement_GetProcessingVelocity"); - MarkNativeAsOptional("Movement_SetTakeoffOrigin"); - MarkNativeAsOptional("Movement_SetTakeoffVelocity"); - MarkNativeAsOptional("Movement_SetLandingOrigin"); - MarkNativeAsOptional("Movement_SetLandingVelocity"); - MarkNativeAsOptional("Movement_GetCollisionCount"); - MarkNativeAsOptional("Movement_GetCollisionStartOrigin"); - MarkNativeAsOptional("Movement_GetCollisionEndOrigin"); - MarkNativeAsOptional("Movement_GetCollisionNormal"); -} -#endif +// =====[ NATIVES ]===== + +/** + * Gets whether a player's last takeoff was a jump. + * + * @param client Client index. + * @return Whether player's last takeoff was a jump. + */ +native bool Movement_GetJumped(int client); + +/** + * Gets whether a player's last takeoff was a perfect bunnyhop. + * + * @param client Client index. + * @return Whether player's last takeoff was a perfect bunnyhop. + */ +native bool Movement_GetHitPerf(int client); + +/** + * Gets a player's origin at the time of their last takeoff. + * + * @param client Client index. + * @param result Resultant vector. + */ +native void Movement_GetTakeoffOrigin(int client, float result[3]); + +/** + * Gets a player's velocity at the time of their last takeoff. + * + * If sv_enablebunnyhopping is 0, CS:GO may adjust the player's + * velocity after the takeoff velocity has already been measured. + * + * @param client Client index. + * @param result Resultant vector. + */ +native void Movement_GetTakeoffVelocity(int client, float result[3]); + +/** + * Gets a player's horizontal speed at the time of their last takeoff. + * + * If sv_enablebunnyhopping is 0, CS:GO may adjust the player's + * velocity after the takeoff velocity has already been measured. + * + * @param client Client index. + * @return Player's last takeoff speed. + */ +native float Movement_GetTakeoffSpeed(int client); + +/** + * Gets a player's 'tickcount' at the time of their last takeoff. + * + * @param client Client index. + * @return Player's last takeoff 'tickcount'. + */ +native int Movement_GetTakeoffTick(int client); + +/** + * Gets a player's 'cmdnum' at the time of their last takeoff. + * + * @param client Client index. + * @return Player's last takeoff 'cmdnum'. + */ +native int Movement_GetTakeoffCmdNum(int client); + +/** + * Gets a player's origin at the time of their last landing with the distbug fixed. + * + * @param client Client index. + * @param result Resultant vector. + */ +native void Movement_GetNobugLandingOrigin(int client, float result[3]); + +/** + * Gets a player's origin at the time of their last landing. + * + * @param client Client index. + * @param result Resultant vector. + */ +native void Movement_GetLandingOrigin(int client, float result[3]); + +/** + * Gets a player's velocity at the time of their last landing. + * + * @param client Client index. + * @param result Resultant vector. + */ +native void Movement_GetLandingVelocity(int client, float result[3]); + +/** + * Gets a player's horizontal speed at the time of their last landing. + * + * @param client Client index. + * @return Last landing speed of the player (horizontal). + */ +native float Movement_GetLandingSpeed(int client); + +/** + * Gets a player's 'tickcount' at the time of their last landing. + * + * @param client Client index. + * @return Player's last landing 'tickcount'. + */ +native int Movement_GetLandingTick(int client); + +/** + * Gets a player's 'cmdnum' at the time of their last landing. + * + * @param client Client index. + * @return Player's last landing 'cmdnum'. + */ +native int Movement_GetLandingCmdNum(int client); + +/** + * Gets whether a player is turning their aim horizontally. + * + * @param client Client index. + * @return Whether player is turning their aim horizontally. + */ +native bool Movement_GetTurning(int client); + +/** + * Gets whether a player is turning their aim left. + * + * @param client Client index. + * @return Whether player is turning their aim left. + */ +native bool Movement_GetTurningLeft(int client); + +/** + * Gets whether a player is turning their aim right. + * + * @param client Client index. + * @return Whether player is turning their aim right. + */ +native bool Movement_GetTurningRight(int client); + +/** + * Gets result of CCSPlayer::GetPlayerMaxSpeed(client), which + * is the player's max speed as limited by their weapon. + * + * @param client Client index. + * @return Player's max speed as limited by their weapon. + */ +native float Movement_GetMaxSpeed(int client); + +/** + * Gets whether a player duckbugged on this tick. + * + * @param client Client index. + * @return Whether a player duckbugged on this tick. + */ +native bool Movement_GetDuckbugged(int client); + +/** + * Gets whether a player jumpbugged on this tick. + * + * @param client Client index. + * @return Whether a player jumpbugged on this tick. + */ +native bool Movement_GetJumpbugged(int client); + +/** + * Get the player's origin during movement processing. + * + * @param client Client index. + * @param result Resultant vector. + */ +native void Movement_GetProcessingOrigin(int client, float result[3]); + +/** + * Get the player's velocity during movement processing. + * + * @param client Param description + * @param result Resultant vector. + */ +native void Movement_GetProcessingVelocity(int client, float result[3]); + +/** + * Set the player's takeoff origin. + * + * @param client Client index. + * @param origin Desired origin. + */ +native void Movement_SetTakeoffOrigin(int client, float origin[3]); + +/** + * Set the player's takeoff velocity. + * + * @param client Client index. + * @param origin Desired velocity. + */ +native void Movement_SetTakeoffVelocity(int client, float velocity[3]); + +/** + * Set the player's landing origin. + * + * @param client Client index. + * @param origin Desired origin. + */ +native void Movement_SetLandingOrigin(int client, float origin[3]); + +/** + * Get the player's number of collisions during movement processing. + * This function should ideally be called after inside Movement_OnTryPlayerMovePost. + * + * @param client Client index. + * @param origin Desired velocity. + */ +native int Movement_GetCollisionCount(int client); + +/** + * Set the player's landing velocity. + * This function should ideally be called after inside Movement_OnTryPlayerMovePost. + * + * @param client Client index. + * @param num Collision number, must not exceed Movement_GetCollisionCount's value. + * @param result Resultant vector. + */ +native void Movement_GetCollisionStartOrigin(int client, int num, float result[3]); + +/** + * Set the player's landing velocity. + * This function should ideally be called after inside Movement_OnTryPlayerMovePost. + * + * @param client Client index. + * @param origin Desired velocity. + */ +native void Movement_GetCollisionEndOrigin(int client, int num, float result[3]); + +/** + * Set the player's landing velocity. + * This function should ideally be called after inside Movement_OnTryPlayerMovePost. + * + * @param client Client index. + * @param origin Desired velocity. + */ +native void Movement_GetCollisionNormal(int client, int num, float result[3]); + +// =====[ METHODMAP ]===== + +methodmap MovementAPIPlayer < MovementPlayer { + + public MovementAPIPlayer(int client) { + return view_as(MovementPlayer(client)); + } + + property bool Jumped { + public get() { + return Movement_GetJumped(this.ID); + } + } + + property bool HitPerf { + public get() { + return Movement_GetHitPerf(this.ID); + } + } + + public void GetTakeoffOrigin(float buffer[3]) { + Movement_GetTakeoffOrigin(this.ID, buffer); + } + + public void GetTakeoffVelocity(float buffer[3]) { + Movement_GetTakeoffVelocity(this.ID, buffer); + } + + public void SetTakeoffOrigin(float buffer[3]) + { + Movement_SetTakeoffOrigin(this.ID, buffer); + } + + public void SetTakeoffVelocity(float buffer[3]) + { + Movement_SetTakeoffVelocity(this.ID, buffer); + } + + property float TakeoffSpeed { + public get() { + return Movement_GetTakeoffSpeed(this.ID); + } + } + + property int TakeoffTick { + public get() { + return Movement_GetTakeoffTick(this.ID); + } + } + + property int TakeoffCmdNum { + public get() { + return Movement_GetTakeoffCmdNum(this.ID); + } + } + + public void GetLandingOrigin(float buffer[3]) { + Movement_GetLandingOrigin(this.ID, buffer); + } + + public void GetLandingVelocity(float buffer[3]) { + Movement_GetLandingVelocity(this.ID, buffer); + } + + public void SetLandingOrigin(float buffer[3]) + { + Movement_SetLandingOrigin(this.ID, buffer); + } + + public void SetLandingVelocity(float buffer[3]) + { + Movement_SetLandingVelocity(this.ID, buffer); + } + + property float LandingSpeed { + public get() { + return Movement_GetLandingSpeed(this.ID); + } + } + + property int LandingTick { + public get() { + return Movement_GetLandingTick(this.ID); + } + } + + property int LandingCmdNum { + public get() { + return Movement_GetLandingCmdNum(this.ID); + } + } + + property bool Turning { + public get() { + return Movement_GetTurning(this.ID); + } + } + + property bool TurningLeft { + public get() { + return Movement_GetTurningLeft(this.ID); + } + } + + property bool TurningRight { + public get() { + return Movement_GetTurningRight(this.ID); + } + } + + property float MaxSpeed { + public get() { + return Movement_GetMaxSpeed(this.ID); + } + } + + property int CollisionCount { + public get() { + return Movement_GetCollisionCount(this.ID); + } + } + public void GetCollisionStartOrigin(int num, float buffer[3]) + { + Movement_GetCollisionStartOrigin(this.ID, num, buffer); + } + + public void GetCollisionEndOrigin(int num, float buffer[3]) + { + Movement_GetCollisionEndOrigin(this.ID, num, buffer); + } + + public void GetCollisionNormal(int num, float buffer[3]) + { + Movement_GetCollisionNormal(this.ID, num, buffer); + } + + public void GetProcessingVelocity(float buffer[3]) + { + Movement_GetProcessingVelocity(this.ID, buffer); + } + + public void GetProcessingOrigin(float buffer[3]) + { + Movement_GetProcessingOrigin(this.ID, buffer); + } +} + + + +// =====[ DEPENDENCY ]===== + +public SharedPlugin __pl_movementapi = +{ + name = "movementapi", + file = "movementapi.smx", + #if defined REQUIRE_PLUGIN + required = 1, + #else + required = 0, + #endif +}; + +#if !defined REQUIRE_PLUGIN +public void __pl_movementapi_SetNTVOptional() +{ + MarkNativeAsOptional("Movement_GetJumped"); + MarkNativeAsOptional("Movement_GetHitPerf"); + MarkNativeAsOptional("Movement_GetTakeoffOrigin"); + MarkNativeAsOptional("Movement_GetTakeoffVelocity"); + MarkNativeAsOptional("Movement_GetTakeoffSpeed"); + MarkNativeAsOptional("Movement_GetTakeoffTick"); + MarkNativeAsOptional("Movement_GetTakeoffCmdNum"); + MarkNativeAsOptional("Movement_GetLandingOrigin"); + MarkNativeAsOptional("Movement_GetLandingVelocity"); + MarkNativeAsOptional("Movement_GetLandingSpeed"); + MarkNativeAsOptional("Movement_GetLandingTick"); + MarkNativeAsOptional("Movement_GetLandingCmdNum"); + MarkNativeAsOptional("Movement_GetTurning"); + MarkNativeAsOptional("Movement_GetTurningLeft"); + MarkNativeAsOptional("Movement_GetTurningRight"); + MarkNativeAsOptional("Movement_GetMaxSpeed"); + MarkNativeAsOptional("Movement_GetProcessingOrigin"); + MarkNativeAsOptional("Movement_GetProcessingVelocity"); + MarkNativeAsOptional("Movement_SetTakeoffOrigin"); + MarkNativeAsOptional("Movement_SetTakeoffVelocity"); + MarkNativeAsOptional("Movement_SetLandingOrigin"); + MarkNativeAsOptional("Movement_SetLandingVelocity"); + MarkNativeAsOptional("Movement_GetCollisionCount"); + MarkNativeAsOptional("Movement_GetCollisionStartOrigin"); + MarkNativeAsOptional("Movement_GetCollisionEndOrigin"); + MarkNativeAsOptional("Movement_GetCollisionNormal"); +} +#endif diff --git a/addons/sourcemod/scripting/movementapi/forwards.sp b/addons/sourcemod/scripting/movementapi/forwards.sp index 9653b57..2bd698d 100644 --- a/addons/sourcemod/scripting/movementapi/forwards.sp +++ b/addons/sourcemod/scripting/movementapi/forwards.sp @@ -1,291 +1,302 @@ -static Handle H_OnStartDucking; -static Handle H_OnStopDucking; -static Handle H_OnStartTouchGround; -static Handle H_OnStopTouchGround; -static Handle H_OnChangeMovetype; -static Handle H_OnPlayerJump; - -static Handle H_OnPlayerMovePre; -static Handle H_OnPlayerMovePost; -static Handle H_OnDuckPre; -static Handle H_OnDuckPost; -static Handle H_OnLadderMovePre; -static Handle H_OnLadderMovePost; -static Handle H_OnFullLadderMovePre; -static Handle H_OnFullLadderMovePost; -static Handle H_OnJumpPre; -static Handle H_OnJumpPost; -static Handle H_OnAirAcceleratePre; -static Handle H_OnAirAcceleratePost; -static Handle H_OnWalkMovePre; -static Handle H_OnWalkMovePost; -static Handle H_OnCategorizePositionPre; -static Handle H_OnCategorizePositionPost; +static Handle H_OnStartDucking; +static Handle H_OnStopDucking; +static Handle H_OnStartTouchGround; +static Handle H_OnStopTouchGround; +static Handle H_OnChangeMovetype; +static Handle H_OnPlayerJump; +static Handle H_OnPlayerEdgebug; + +static Handle H_OnPlayerMovePre; +static Handle H_OnPlayerMovePost; +static Handle H_OnDuckPre; +static Handle H_OnDuckPost; +static Handle H_OnLadderMovePre; +static Handle H_OnLadderMovePost; +static Handle H_OnFullLadderMovePre; +static Handle H_OnFullLadderMovePost; +static Handle H_OnJumpPre; +static Handle H_OnJumpPost; +static Handle H_OnAirAcceleratePre; +static Handle H_OnAirAcceleratePost; +static Handle H_OnWalkMovePre; +static Handle H_OnWalkMovePost; +static Handle H_OnCategorizePositionPre; +static Handle H_OnCategorizePositionPost; static Handle H_OnTryPlayerMovePre; static Handle H_OnTryPlayerMovePost; - -void CreateGlobalForwards() -{ - H_OnStartDucking = CreateGlobalForward("Movement_OnStartDucking", ET_Ignore, Param_Cell); - H_OnStopDucking = CreateGlobalForward("Movement_OnStopDucking", ET_Ignore, Param_Cell); - H_OnStartTouchGround = CreateGlobalForward("Movement_OnStartTouchGround", ET_Ignore, Param_Cell); - H_OnStopTouchGround = CreateGlobalForward("Movement_OnStopTouchGround", ET_Ignore, Param_Cell, Param_Cell, Param_Cell, Param_Cell); - H_OnChangeMovetype = CreateGlobalForward("Movement_OnChangeMovetype", ET_Ignore, Param_Cell, Param_Cell, Param_Cell); - H_OnPlayerJump = CreateGlobalForward("Movement_OnPlayerJump", ET_Ignore, Param_Cell, Param_Cell); - - H_OnPlayerMovePre = CreateGlobalForward("Movement_OnPlayerMovePre", ET_Event, Param_Cell, Param_Array, Param_Array); - H_OnPlayerMovePost = CreateGlobalForward("Movement_OnPlayerMovePost", ET_Event, Param_Cell, Param_Array, Param_Array); - - H_OnDuckPre = CreateGlobalForward("Movement_OnDuckPre", ET_Event, Param_Cell, Param_Array, Param_Array); - H_OnDuckPost = CreateGlobalForward("Movement_OnDuckPost", ET_Event, Param_Cell, Param_Array, Param_Array); - - H_OnLadderMovePre = CreateGlobalForward("Movement_OnLadderMovePre", ET_Event, Param_Cell, Param_Array, Param_Array); - H_OnLadderMovePost = CreateGlobalForward("Movement_OnLadderMovePost", ET_Event, Param_Cell, Param_Array, Param_Array); - - H_OnFullLadderMovePre = CreateGlobalForward("Movement_OnFullLadderMovePre", ET_Event, Param_Cell, Param_Array, Param_Array); - H_OnFullLadderMovePost = CreateGlobalForward("Movement_OnFullLadderMovePost", ET_Event, Param_Cell, Param_Array, Param_Array); - - H_OnJumpPre = CreateGlobalForward("Movement_OnJumpPre", ET_Event, Param_Cell, Param_Array, Param_Array); - H_OnJumpPost = CreateGlobalForward("Movement_OnJumpPost", ET_Event, Param_Cell, Param_Array, Param_Array); - - H_OnAirAcceleratePre = CreateGlobalForward("Movement_OnAirAcceleratePre", ET_Event, Param_Cell, Param_Array, Param_Array); - H_OnAirAcceleratePost = CreateGlobalForward("Movement_OnAirAcceleratePost", ET_Event, Param_Cell, Param_Array, Param_Array); - - H_OnWalkMovePre = CreateGlobalForward("Movement_OnWalkMovePre", ET_Event, Param_Cell, Param_Array, Param_Array); - H_OnWalkMovePost = CreateGlobalForward("Movement_OnWalkMovePost", ET_Event, Param_Cell, Param_Array, Param_Array); - - H_OnCategorizePositionPre = CreateGlobalForward("Movement_OnCategorizePositionPre", ET_Event, Param_Cell, Param_Array, Param_Array); - H_OnCategorizePositionPost = CreateGlobalForward("Movement_OnCategorizePositionPost", ET_Event, Param_Cell, Param_Array, Param_Array); - - H_OnTryPlayerMovePre = CreateGlobalForward("Movement_OnTryPlayerMovePre", ET_Event, Param_Cell, Param_Array, Param_Array); - H_OnTryPlayerMovePost = CreateGlobalForward("Movement_OnTryPlayerMovePost", ET_Event, Param_Cell, Param_Array, Param_Array); -} - -void Call_OnStartDucking(int client) -{ - Call_StartForward(H_OnStartDucking); - Call_PushCell(client); - Call_Finish(); -} - -void Call_OnStopDucking(int client) -{ - Call_StartForward(H_OnStopDucking); - Call_PushCell(client); - Call_Finish(); -} - -void Call_OnStartTouchGround(int client) -{ - Call_StartForward(H_OnStartTouchGround); - Call_PushCell(client); - Call_Finish(); -} - -void Call_OnStopTouchGround(int client, bool jumped, bool ladderJump, bool jumpbug) -{ - Call_StartForward(H_OnStopTouchGround); - Call_PushCell(client); - Call_PushCell(jumped); - Call_PushCell(ladderJump); - Call_PushCell(jumpbug); - Call_Finish(); -} - - -void Call_OnChangeMovetype(int client, MoveType oldMovetype, MoveType newMovetype) -{ - Call_StartForward(H_OnChangeMovetype); - Call_PushCell(client); - Call_PushCell(oldMovetype); - Call_PushCell(newMovetype); - Call_Finish(); -} - -void Call_OnPlayerJump(int client, bool jumpbug) -{ - Call_StartForward(H_OnPlayerJump); - Call_PushCell(client); - Call_PushCell(jumpbug); - Call_Finish(); -} - -Action Call_OnPlayerMovePre(int client, float origin[3], float velocity[3], Action &result) -{ - Call_StartForward(H_OnPlayerMovePre); - Call_PushCell(client); - Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); - Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); - Call_Finish(result); - return result; -} - -Action Call_OnPlayerMovePost(int client, float origin[3], float velocity[3], Action &result) -{ - Call_StartForward(H_OnPlayerMovePost); - Call_PushCell(client); - Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); - Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); - Call_Finish(result); - return result; -} - -Action Call_OnDuckPre(int client, float origin[3], float velocity[3], Action &result) -{ - Call_StartForward(H_OnDuckPre); - Call_PushCell(client); - Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); - Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); - Call_Finish(result); - return result; -} - -Action Call_OnDuckPost(int client, float origin[3], float velocity[3], Action &result) -{ - Call_StartForward(H_OnDuckPost); - Call_PushCell(client); - Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); - Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); - Call_Finish(result); - return result; -} - -Action Call_OnLadderMovePre(int client, float origin[3], float velocity[3], Action &result) -{ - Call_StartForward(H_OnLadderMovePre); - Call_PushCell(client); - Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); - Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); - Call_Finish(result); - return result; -} - -Action Call_OnLadderMovePost(int client, float origin[3], float velocity[3], Action &result) -{ - Call_StartForward(H_OnLadderMovePost); - Call_PushCell(client); - Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); - Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); - Call_Finish(result); - return result; -} - -Action Call_OnFullLadderMovePre(int client, float origin[3], float velocity[3], Action &result) -{ - Call_StartForward(H_OnFullLadderMovePre); - Call_PushCell(client); - Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); - Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); - Call_Finish(result); - return result; -} - -Action Call_OnFullLadderMovePost(int client, float origin[3], float velocity[3], Action &result) -{ - Call_StartForward(H_OnFullLadderMovePost); - Call_PushCell(client); - Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); - Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); - Call_Finish(result); - return result; -} - -Action Call_OnJumpPre(int client, float origin[3], float velocity[3], Action &result) -{ - Call_StartForward(H_OnJumpPre); - Call_PushCell(client); - Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); - Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); - Call_Finish(result); - return result; -} - -Action Call_OnJumpPost(int client, float origin[3], float velocity[3], Action &result) -{ - Call_StartForward(H_OnJumpPost); - Call_PushCell(client); - Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); - Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); - Call_Finish(result); - return result; -} - -Action Call_OnAirAcceleratePre(int client, float origin[3], float velocity[3], Action &result) -{ - Call_StartForward(H_OnAirAcceleratePre); - Call_PushCell(client); - Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); - Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); - Call_Finish(result); - return result; -} - -Action Call_OnAirAcceleratePost(int client, float origin[3], float velocity[3], Action &result) -{ - Call_StartForward(H_OnAirAcceleratePost); - Call_PushCell(client); - Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); - Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); - Call_Finish(result); - return result; -} - -Action Call_OnWalkMovePre(int client, float origin[3], float velocity[3], Action &result) -{ - Call_StartForward(H_OnWalkMovePre); - Call_PushCell(client); - Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); - Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); - Call_Finish(result); - return result; -} - -Action Call_OnWalkMovePost(int client, float origin[3], float velocity[3], Action &result) -{ - Call_StartForward(H_OnWalkMovePost); - Call_PushCell(client); - Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); - Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); - Call_Finish(result); - return result; -} - -Action Call_OnCategorizePositionPre(int client, float origin[3], float velocity[3], Action &result) -{ - Call_StartForward(H_OnCategorizePositionPre); - Call_PushCell(client); - Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); - Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); - Call_Finish(result); - return result; -} - -Action Call_OnCategorizePositionPost(int client, float origin[3], float velocity[3], Action &result) -{ - Call_StartForward(H_OnCategorizePositionPost); - Call_PushCell(client); - Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); - Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); - Call_Finish(result); - return result; -} - -Action Call_OnTryPlayerMovePre(int client, float origin[3], float velocity[3], Action &result) -{ - Call_StartForward(H_OnTryPlayerMovePre); - Call_PushCell(client); - Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); - Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); - Call_Finish(result); - return result; -} - -Action Call_OnTryPlayerMovePost(int client, float origin[3], float velocity[3], Action &result) -{ - Call_StartForward(H_OnTryPlayerMovePost); - Call_PushCell(client); - Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); - Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); - Call_Finish(result); - return result; + +void CreateGlobalForwards() +{ + H_OnStartDucking = CreateGlobalForward("Movement_OnStartDucking", ET_Ignore, Param_Cell); + H_OnStopDucking = CreateGlobalForward("Movement_OnStopDucking", ET_Ignore, Param_Cell); + H_OnStartTouchGround = CreateGlobalForward("Movement_OnStartTouchGround", ET_Ignore, Param_Cell); + H_OnStopTouchGround = CreateGlobalForward("Movement_OnStopTouchGround", ET_Ignore, Param_Cell, Param_Cell, Param_Cell, Param_Cell); + H_OnChangeMovetype = CreateGlobalForward("Movement_OnChangeMovetype", ET_Ignore, Param_Cell, Param_Cell, Param_Cell); + H_OnPlayerJump = CreateGlobalForward("Movement_OnPlayerJump", ET_Ignore, Param_Cell, Param_Cell); + H_OnPlayerEdgebug = CreateGlobalForward("Movement_OnPlayerEdgebug", ET_Ignore, Param_Cell, Param_Array, Param_Array); + + H_OnPlayerMovePre = CreateGlobalForward("Movement_OnPlayerMovePre", ET_Event, Param_Cell, Param_Array, Param_Array); + H_OnPlayerMovePost = CreateGlobalForward("Movement_OnPlayerMovePost", ET_Event, Param_Cell, Param_Array, Param_Array); + + H_OnDuckPre = CreateGlobalForward("Movement_OnDuckPre", ET_Event, Param_Cell, Param_Array, Param_Array); + H_OnDuckPost = CreateGlobalForward("Movement_OnDuckPost", ET_Event, Param_Cell, Param_Array, Param_Array); + + H_OnLadderMovePre = CreateGlobalForward("Movement_OnLadderMovePre", ET_Event, Param_Cell, Param_Array, Param_Array); + H_OnLadderMovePost = CreateGlobalForward("Movement_OnLadderMovePost", ET_Event, Param_Cell, Param_Array, Param_Array); + + H_OnFullLadderMovePre = CreateGlobalForward("Movement_OnFullLadderMovePre", ET_Event, Param_Cell, Param_Array, Param_Array); + H_OnFullLadderMovePost = CreateGlobalForward("Movement_OnFullLadderMovePost", ET_Event, Param_Cell, Param_Array, Param_Array); + + H_OnJumpPre = CreateGlobalForward("Movement_OnJumpPre", ET_Event, Param_Cell, Param_Array, Param_Array); + H_OnJumpPost = CreateGlobalForward("Movement_OnJumpPost", ET_Event, Param_Cell, Param_Array, Param_Array); + + H_OnAirAcceleratePre = CreateGlobalForward("Movement_OnAirAcceleratePre", ET_Event, Param_Cell, Param_Array, Param_Array); + H_OnAirAcceleratePost = CreateGlobalForward("Movement_OnAirAcceleratePost", ET_Event, Param_Cell, Param_Array, Param_Array); + + H_OnWalkMovePre = CreateGlobalForward("Movement_OnWalkMovePre", ET_Event, Param_Cell, Param_Array, Param_Array); + H_OnWalkMovePost = CreateGlobalForward("Movement_OnWalkMovePost", ET_Event, Param_Cell, Param_Array, Param_Array); + + H_OnCategorizePositionPre = CreateGlobalForward("Movement_OnCategorizePositionPre", ET_Event, Param_Cell, Param_Array, Param_Array); + H_OnCategorizePositionPost = CreateGlobalForward("Movement_OnCategorizePositionPost", ET_Event, Param_Cell, Param_Array, Param_Array); + + H_OnTryPlayerMovePre = CreateGlobalForward("Movement_OnTryPlayerMovePre", ET_Event, Param_Cell, Param_Array, Param_Array); + H_OnTryPlayerMovePost = CreateGlobalForward("Movement_OnTryPlayerMovePost", ET_Event, Param_Cell, Param_Array, Param_Array); +} + +void Call_OnStartDucking(int client) +{ + Call_StartForward(H_OnStartDucking); + Call_PushCell(client); + Call_Finish(); +} + +void Call_OnStopDucking(int client) +{ + Call_StartForward(H_OnStopDucking); + Call_PushCell(client); + Call_Finish(); +} + +void Call_OnStartTouchGround(int client) +{ + Call_StartForward(H_OnStartTouchGround); + Call_PushCell(client); + Call_Finish(); +} + +void Call_OnStopTouchGround(int client, bool jumped, bool ladderJump, bool jumpbug) +{ + Call_StartForward(H_OnStopTouchGround); + Call_PushCell(client); + Call_PushCell(jumped); + Call_PushCell(ladderJump); + Call_PushCell(jumpbug); + Call_Finish(); +} + + +void Call_OnChangeMovetype(int client, MoveType oldMovetype, MoveType newMovetype) +{ + Call_StartForward(H_OnChangeMovetype); + Call_PushCell(client); + Call_PushCell(oldMovetype); + Call_PushCell(newMovetype); + Call_Finish(); +} + +void Call_OnPlayerJump(int client, bool jumpbug) +{ + Call_StartForward(H_OnPlayerJump); + Call_PushCell(client); + Call_PushCell(jumpbug); + Call_Finish(); +} + +void Call_OnPlayerEdgebug(int client, float origin[3], float velocity[3]) +{ + Call_StartForward(H_OnPlayerEdgebug); + Call_PushCell(client); + Call_PushArray(origin, 3); + Call_PushArray(velocity, 3); + Call_Finish(); +} + +Action Call_OnPlayerMovePre(int client, float origin[3], float velocity[3], Action &result) +{ + Call_StartForward(H_OnPlayerMovePre); + Call_PushCell(client); + Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); + Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); + Call_Finish(result); + return result; +} + +Action Call_OnPlayerMovePost(int client, float origin[3], float velocity[3], Action &result) +{ + Call_StartForward(H_OnPlayerMovePost); + Call_PushCell(client); + Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); + Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); + Call_Finish(result); + return result; +} + +Action Call_OnDuckPre(int client, float origin[3], float velocity[3], Action &result) +{ + Call_StartForward(H_OnDuckPre); + Call_PushCell(client); + Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); + Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); + Call_Finish(result); + return result; +} + +Action Call_OnDuckPost(int client, float origin[3], float velocity[3], Action &result) +{ + Call_StartForward(H_OnDuckPost); + Call_PushCell(client); + Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); + Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); + Call_Finish(result); + return result; +} + +Action Call_OnLadderMovePre(int client, float origin[3], float velocity[3], Action &result) +{ + Call_StartForward(H_OnLadderMovePre); + Call_PushCell(client); + Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); + Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); + Call_Finish(result); + return result; +} + +Action Call_OnLadderMovePost(int client, float origin[3], float velocity[3], Action &result) +{ + Call_StartForward(H_OnLadderMovePost); + Call_PushCell(client); + Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); + Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); + Call_Finish(result); + return result; +} + +Action Call_OnFullLadderMovePre(int client, float origin[3], float velocity[3], Action &result) +{ + Call_StartForward(H_OnFullLadderMovePre); + Call_PushCell(client); + Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); + Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); + Call_Finish(result); + return result; +} + +Action Call_OnFullLadderMovePost(int client, float origin[3], float velocity[3], Action &result) +{ + Call_StartForward(H_OnFullLadderMovePost); + Call_PushCell(client); + Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); + Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); + Call_Finish(result); + return result; +} + +Action Call_OnJumpPre(int client, float origin[3], float velocity[3], Action &result) +{ + Call_StartForward(H_OnJumpPre); + Call_PushCell(client); + Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); + Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); + Call_Finish(result); + return result; +} + +Action Call_OnJumpPost(int client, float origin[3], float velocity[3], Action &result) +{ + Call_StartForward(H_OnJumpPost); + Call_PushCell(client); + Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); + Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); + Call_Finish(result); + return result; +} + +Action Call_OnAirAcceleratePre(int client, float origin[3], float velocity[3], Action &result) +{ + Call_StartForward(H_OnAirAcceleratePre); + Call_PushCell(client); + Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); + Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); + Call_Finish(result); + return result; +} + +Action Call_OnAirAcceleratePost(int client, float origin[3], float velocity[3], Action &result) +{ + Call_StartForward(H_OnAirAcceleratePost); + Call_PushCell(client); + Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); + Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); + Call_Finish(result); + return result; +} + +Action Call_OnWalkMovePre(int client, float origin[3], float velocity[3], Action &result) +{ + Call_StartForward(H_OnWalkMovePre); + Call_PushCell(client); + Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); + Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); + Call_Finish(result); + return result; +} + +Action Call_OnWalkMovePost(int client, float origin[3], float velocity[3], Action &result) +{ + Call_StartForward(H_OnWalkMovePost); + Call_PushCell(client); + Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); + Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); + Call_Finish(result); + return result; +} + +Action Call_OnCategorizePositionPre(int client, float origin[3], float velocity[3], Action &result) +{ + Call_StartForward(H_OnCategorizePositionPre); + Call_PushCell(client); + Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); + Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); + Call_Finish(result); + return result; +} + +Action Call_OnCategorizePositionPost(int client, float origin[3], float velocity[3], Action &result) +{ + Call_StartForward(H_OnCategorizePositionPost); + Call_PushCell(client); + Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); + Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); + Call_Finish(result); + return result; +} + +Action Call_OnTryPlayerMovePre(int client, float origin[3], float velocity[3], Action &result) +{ + Call_StartForward(H_OnTryPlayerMovePre); + Call_PushCell(client); + Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); + Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); + Call_Finish(result); + return result; +} + +Action Call_OnTryPlayerMovePost(int client, float origin[3], float velocity[3], Action &result) +{ + Call_StartForward(H_OnTryPlayerMovePost); + Call_PushCell(client); + Call_PushArrayEx(origin, 3, SM_PARAM_COPYBACK); + Call_PushArrayEx(velocity, 3, SM_PARAM_COPYBACK); + Call_Finish(result); + return result; } \ No newline at end of file diff --git a/addons/sourcemod/scripting/movementapi/hooks.sp b/addons/sourcemod/scripting/movementapi/hooks.sp index a21a03b..836acc1 100644 --- a/addons/sourcemod/scripting/movementapi/hooks.sp +++ b/addons/sourcemod/scripting/movementapi/hooks.sp @@ -567,12 +567,45 @@ public MRESReturn DHooks_OnTryPlayerMove_Post(Address pThis, DHookReturn hReturn Address m_TouchList_m_pElements = LoadFromAddress(moveHelperAddr + view_as
(8) + view_as
(16), NumberType_Int32); + bool hitStandableSurface = false; + static ConVar sv_standable_normal; + if (sv_standable_normal == INVALID_HANDLE) + { + sv_standable_normal = FindConVar("sv_standable_normal"); + } for (int i = 0; i < gI_CollisionCount[client]; i++) { Trace trace = Trace(m_TouchList_m_pElements + view_as
(i*96) + view_as
(12)); trace.startpos.ToArray(gF_TraceStartOrigin[client][i]); trace.endpos.ToArray(gF_TraceEndOrigin[client][i]); trace.plane.normal.ToArray(gF_TraceNormal[client][i]); + if (trace.plane.normal.z >= sv_standable_normal.FloatValue) + { + hitStandableSurface = true; + } + } + + // Edgebug detection + + if (hitStandableSurface) + { + float currentOrigin[3], groundEndPoint[3]; + + GameMove_GetOrigin(pThis, currentOrigin); + groundEndPoint = currentOrigin; + groundEndPoint[2] -= 2.0; + float mins[3] = {-16.0, -16.0, 0.0}; + float maxs[3] = {16.0, 16.0, 0.0}; + TR_TraceHullFilter(currentOrigin, groundEndPoint, mins, maxs, MASK_PLAYERSOLID, TraceEntityFilterPlayers, client); + + float groundPos[3]; + TR_GetEndPosition(groundPos); + + // Note: Origin and velocity are not updated yet. + if (!TR_DidHit()) + { + Call_OnPlayerEdgebug(client, gF_Origin[client], gF_Velocity[client]); + } } Action result = UpdateMoveData(pThis, client, Call_OnTryPlayerMovePost); From 99743ae56bf90b58bc0ef3b820866c4f7846631e Mon Sep 17 00:00:00 2001 From: "zer0.k" Date: Sat, 11 Mar 2023 04:27:12 +0100 Subject: [PATCH 4/4] Fix line ending --- .../scripting/include/movementapi.inc | 1496 ++++++++--------- 1 file changed, 748 insertions(+), 748 deletions(-) diff --git a/addons/sourcemod/scripting/include/movementapi.inc b/addons/sourcemod/scripting/include/movementapi.inc index cfaa649..0cb1525 100644 --- a/addons/sourcemod/scripting/include/movementapi.inc +++ b/addons/sourcemod/scripting/include/movementapi.inc @@ -1,748 +1,748 @@ -/* - MovementAPI Plugin Include - - Website: https://github.com/danzayau/MovementAPI -*/ - -#if defined _movementapi_included_ - #endinput -#endif -#define _movementapi_included_ - -#include - - - -/* - Terminology - - Takeoff - Becoming airborne, including jumping, falling, getting off a ladder and leaving noclip. - - Landing - Leaving the air, including landing on the ground, grabbing a ladder and entering noclip. - - Perfect Bunnyhop (Perf) - When the player has jumped in the tick after landing and keeps their speed. - - Duckbug/Crouchbug - When the player sucessfully lands due to uncrouching from mid air and not by falling - down. This causes no stamina loss or fall damage upon landing. - - Jumpbug - This is achieved by duckbugging and jumping at the same time. The player is never seen - as 'on ground' when bunnyhopping from a tick by tick perspective. A jumpbug inherits - the same behavior as a duckbug/crouchbug, along with its effects such as maintaining - speed due to no stamina loss. - - Distbug - Landing behavior varies depending on whether the player lands close to the edge of a - block or not: - - 1. If the player lands close to the edge of a block, this causes the jump duration to - be one tick longer and the player can "slide" on the ground during the landing tick, - using the position post-tick as landing position becomes inaccurate. - - 2. On the other hand, if the player does not land close to the edge, the player will - be considered on the ground one tick earlier, using this position as landing position - is not accurate as the player has yet to be fully on the ground. - - In scenario 1, GetNobugLandingOrigin calculates the correct landing position of the - player before the sliding effect takes effect. - - In scenario 2, GetNobugLandingOrigin attempts to extrapolate the player's fully on - ground position to make landing positions consistent across scenarios. -*/ - - - -// =====[ FORWARDS ]===== - -/** - * Called when a player's movetype changes. - * - * @param client Client index. - * @param oldMovetype Player's old movetype. - * @param newMovetype Player's new movetype. - */ -forward void Movement_OnChangeMovetype(int client, MoveType oldMovetype, MoveType newMovetype); - -/** - * Called when a player touches the ground. - * - * @param client Client index. - */ -forward void Movement_OnStartTouchGround(int client); - -/** - * Called when a player leaves the ground. - * - * @param client Client index. - * @param jumped Whether player jumped to leave ground. - * @param ladderJump Whether player jumped from a ladder. - * @param jumpbug Whether player performed a jumpbug. - */ -forward void Movement_OnStopTouchGround(int client, bool jumped, bool ladderJump, bool jumpbug); - -/** - * Called when a player starts ducking. - * - * @param client Client index. - */ -forward void Movement_OnStartDucking(int client); - -/** - * Called when a player stops ducking. - * - * @param client Client index. - */ -forward void Movement_OnStopDucking(int client); - -/** - * Called when a player jumps (player_jump event), including 'jumpbugs'. - * Setting velocity when this is called may not be effective. - * - * @param client Client index. - * @param jumpbug Whether player 'jumpbugged'. - */ -forward void Movement_OnPlayerJump(int client, bool jumpbug); - -/** - * Called when a player edgebugs - * Setting velocity when this is called may not be effective. - * - * @param client Client index. - * @param origin Player origin before edgebug. - * @param velocity Player velocity before edgebug. - */ -forward void Movement_OnPlayerEdgebug(int client, float origin[3], float velocity[3]); - -/** - * Called before PlayerMove movement function is called. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnPlayerMovePre(int client, float origin[3], float velocity[3]); - -/** - * Called after PlayerMove movement function is called. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnPlayerMovePost(int client, float origin[3], float velocity[3]); - -/** - * Called before Duck movement function is called. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnDuckPre(int client, float origin[3], float velocity[3]); - -/** - * Called after Duck movement function is called. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnDuckPost(int client, float origin[3], float velocity[3]); - -/** - * Called before LadderMove movement function is called. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnLadderMovePre(int client, float origin[3], float velocity[3]); - -/** - * Called after LadderMove movement function is called. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnLadderMovePost(int client, float origin[3], float velocity[3]); - -/** - * Called before FullLadderMove movement function is called. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnFullLadderMovePre(int client, float origin[3], float velocity[3]); - -/** - * Called after FullLadderMove movement function is called. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnFullLadderMovePost(int client, float origin[3], float velocity[3]); - -/** - * Called after the player jumps, but before jumping stamina is applied and takeoff variables are not set yet. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnJumpPre(int client, float origin[3], float velocity[3]); - -/** - * Called after the player jumps and after jumping stamina is applied and takeoff variables are already set here. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnJumpPost(int client, float origin[3], float velocity[3]); - -/** - * Called before AirAccelerate movement function is called. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnAirAcceleratePre(int client, float origin[3], float velocity[3]); - -/** - * Called after AirAccelerate movement function is called. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnAirAcceleratePost(int client, float origin[3], float velocity[3]); - -/** - * Called before WalkMove movement function is called. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnWalkMovePre(int client, float origin[3], float velocity[3]); - -/** - * Called after WalkMove movement function is called. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnWalkMovePost(int client, float origin[3], float velocity[3]); - -/** - * Called before CategorizePosition movement function is called. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnCategorizePositionPre(int client, float origin[3], float velocity[3]); - -/** - * Called after CategorizePosition movement function is called. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnCategorizePositionPost(int client, float origin[3], float velocity[3]); - -/** - * Called before TryPlayerMove movement function is called. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnTryPlayerMovePre(int client, float origin[3], float velocity[3]); - -/** - * Called after TryPlayerMove movement function is called. - * Modifying origin or velocity parameters will change player's origin and velocity accordingly. - * - * @param client Client index. - * @param origin Player origin. - * @param velocity Player velocity. - * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. - */ -forward Action Movement_OnTryPlayerMovePost(int client, float origin[3], float velocity[3]); - -// =====[ NATIVES ]===== - -/** - * Gets whether a player's last takeoff was a jump. - * - * @param client Client index. - * @return Whether player's last takeoff was a jump. - */ -native bool Movement_GetJumped(int client); - -/** - * Gets whether a player's last takeoff was a perfect bunnyhop. - * - * @param client Client index. - * @return Whether player's last takeoff was a perfect bunnyhop. - */ -native bool Movement_GetHitPerf(int client); - -/** - * Gets a player's origin at the time of their last takeoff. - * - * @param client Client index. - * @param result Resultant vector. - */ -native void Movement_GetTakeoffOrigin(int client, float result[3]); - -/** - * Gets a player's velocity at the time of their last takeoff. - * - * If sv_enablebunnyhopping is 0, CS:GO may adjust the player's - * velocity after the takeoff velocity has already been measured. - * - * @param client Client index. - * @param result Resultant vector. - */ -native void Movement_GetTakeoffVelocity(int client, float result[3]); - -/** - * Gets a player's horizontal speed at the time of their last takeoff. - * - * If sv_enablebunnyhopping is 0, CS:GO may adjust the player's - * velocity after the takeoff velocity has already been measured. - * - * @param client Client index. - * @return Player's last takeoff speed. - */ -native float Movement_GetTakeoffSpeed(int client); - -/** - * Gets a player's 'tickcount' at the time of their last takeoff. - * - * @param client Client index. - * @return Player's last takeoff 'tickcount'. - */ -native int Movement_GetTakeoffTick(int client); - -/** - * Gets a player's 'cmdnum' at the time of their last takeoff. - * - * @param client Client index. - * @return Player's last takeoff 'cmdnum'. - */ -native int Movement_GetTakeoffCmdNum(int client); - -/** - * Gets a player's origin at the time of their last landing with the distbug fixed. - * - * @param client Client index. - * @param result Resultant vector. - */ -native void Movement_GetNobugLandingOrigin(int client, float result[3]); - -/** - * Gets a player's origin at the time of their last landing. - * - * @param client Client index. - * @param result Resultant vector. - */ -native void Movement_GetLandingOrigin(int client, float result[3]); - -/** - * Gets a player's velocity at the time of their last landing. - * - * @param client Client index. - * @param result Resultant vector. - */ -native void Movement_GetLandingVelocity(int client, float result[3]); - -/** - * Gets a player's horizontal speed at the time of their last landing. - * - * @param client Client index. - * @return Last landing speed of the player (horizontal). - */ -native float Movement_GetLandingSpeed(int client); - -/** - * Gets a player's 'tickcount' at the time of their last landing. - * - * @param client Client index. - * @return Player's last landing 'tickcount'. - */ -native int Movement_GetLandingTick(int client); - -/** - * Gets a player's 'cmdnum' at the time of their last landing. - * - * @param client Client index. - * @return Player's last landing 'cmdnum'. - */ -native int Movement_GetLandingCmdNum(int client); - -/** - * Gets whether a player is turning their aim horizontally. - * - * @param client Client index. - * @return Whether player is turning their aim horizontally. - */ -native bool Movement_GetTurning(int client); - -/** - * Gets whether a player is turning their aim left. - * - * @param client Client index. - * @return Whether player is turning their aim left. - */ -native bool Movement_GetTurningLeft(int client); - -/** - * Gets whether a player is turning their aim right. - * - * @param client Client index. - * @return Whether player is turning their aim right. - */ -native bool Movement_GetTurningRight(int client); - -/** - * Gets result of CCSPlayer::GetPlayerMaxSpeed(client), which - * is the player's max speed as limited by their weapon. - * - * @param client Client index. - * @return Player's max speed as limited by their weapon. - */ -native float Movement_GetMaxSpeed(int client); - -/** - * Gets whether a player duckbugged on this tick. - * - * @param client Client index. - * @return Whether a player duckbugged on this tick. - */ -native bool Movement_GetDuckbugged(int client); - -/** - * Gets whether a player jumpbugged on this tick. - * - * @param client Client index. - * @return Whether a player jumpbugged on this tick. - */ -native bool Movement_GetJumpbugged(int client); - -/** - * Get the player's origin during movement processing. - * - * @param client Client index. - * @param result Resultant vector. - */ -native void Movement_GetProcessingOrigin(int client, float result[3]); - -/** - * Get the player's velocity during movement processing. - * - * @param client Param description - * @param result Resultant vector. - */ -native void Movement_GetProcessingVelocity(int client, float result[3]); - -/** - * Set the player's takeoff origin. - * - * @param client Client index. - * @param origin Desired origin. - */ -native void Movement_SetTakeoffOrigin(int client, float origin[3]); - -/** - * Set the player's takeoff velocity. - * - * @param client Client index. - * @param origin Desired velocity. - */ -native void Movement_SetTakeoffVelocity(int client, float velocity[3]); - -/** - * Set the player's landing origin. - * - * @param client Client index. - * @param origin Desired origin. - */ -native void Movement_SetLandingOrigin(int client, float origin[3]); - -/** - * Get the player's number of collisions during movement processing. - * This function should ideally be called after inside Movement_OnTryPlayerMovePost. - * - * @param client Client index. - * @param origin Desired velocity. - */ -native int Movement_GetCollisionCount(int client); - -/** - * Set the player's landing velocity. - * This function should ideally be called after inside Movement_OnTryPlayerMovePost. - * - * @param client Client index. - * @param num Collision number, must not exceed Movement_GetCollisionCount's value. - * @param result Resultant vector. - */ -native void Movement_GetCollisionStartOrigin(int client, int num, float result[3]); - -/** - * Set the player's landing velocity. - * This function should ideally be called after inside Movement_OnTryPlayerMovePost. - * - * @param client Client index. - * @param origin Desired velocity. - */ -native void Movement_GetCollisionEndOrigin(int client, int num, float result[3]); - -/** - * Set the player's landing velocity. - * This function should ideally be called after inside Movement_OnTryPlayerMovePost. - * - * @param client Client index. - * @param origin Desired velocity. - */ -native void Movement_GetCollisionNormal(int client, int num, float result[3]); - -// =====[ METHODMAP ]===== - -methodmap MovementAPIPlayer < MovementPlayer { - - public MovementAPIPlayer(int client) { - return view_as(MovementPlayer(client)); - } - - property bool Jumped { - public get() { - return Movement_GetJumped(this.ID); - } - } - - property bool HitPerf { - public get() { - return Movement_GetHitPerf(this.ID); - } - } - - public void GetTakeoffOrigin(float buffer[3]) { - Movement_GetTakeoffOrigin(this.ID, buffer); - } - - public void GetTakeoffVelocity(float buffer[3]) { - Movement_GetTakeoffVelocity(this.ID, buffer); - } - - public void SetTakeoffOrigin(float buffer[3]) - { - Movement_SetTakeoffOrigin(this.ID, buffer); - } - - public void SetTakeoffVelocity(float buffer[3]) - { - Movement_SetTakeoffVelocity(this.ID, buffer); - } - - property float TakeoffSpeed { - public get() { - return Movement_GetTakeoffSpeed(this.ID); - } - } - - property int TakeoffTick { - public get() { - return Movement_GetTakeoffTick(this.ID); - } - } - - property int TakeoffCmdNum { - public get() { - return Movement_GetTakeoffCmdNum(this.ID); - } - } - - public void GetLandingOrigin(float buffer[3]) { - Movement_GetLandingOrigin(this.ID, buffer); - } - - public void GetLandingVelocity(float buffer[3]) { - Movement_GetLandingVelocity(this.ID, buffer); - } - - public void SetLandingOrigin(float buffer[3]) - { - Movement_SetLandingOrigin(this.ID, buffer); - } - - public void SetLandingVelocity(float buffer[3]) - { - Movement_SetLandingVelocity(this.ID, buffer); - } - - property float LandingSpeed { - public get() { - return Movement_GetLandingSpeed(this.ID); - } - } - - property int LandingTick { - public get() { - return Movement_GetLandingTick(this.ID); - } - } - - property int LandingCmdNum { - public get() { - return Movement_GetLandingCmdNum(this.ID); - } - } - - property bool Turning { - public get() { - return Movement_GetTurning(this.ID); - } - } - - property bool TurningLeft { - public get() { - return Movement_GetTurningLeft(this.ID); - } - } - - property bool TurningRight { - public get() { - return Movement_GetTurningRight(this.ID); - } - } - - property float MaxSpeed { - public get() { - return Movement_GetMaxSpeed(this.ID); - } - } - - property int CollisionCount { - public get() { - return Movement_GetCollisionCount(this.ID); - } - } - public void GetCollisionStartOrigin(int num, float buffer[3]) - { - Movement_GetCollisionStartOrigin(this.ID, num, buffer); - } - - public void GetCollisionEndOrigin(int num, float buffer[3]) - { - Movement_GetCollisionEndOrigin(this.ID, num, buffer); - } - - public void GetCollisionNormal(int num, float buffer[3]) - { - Movement_GetCollisionNormal(this.ID, num, buffer); - } - - public void GetProcessingVelocity(float buffer[3]) - { - Movement_GetProcessingVelocity(this.ID, buffer); - } - - public void GetProcessingOrigin(float buffer[3]) - { - Movement_GetProcessingOrigin(this.ID, buffer); - } -} - - - -// =====[ DEPENDENCY ]===== - -public SharedPlugin __pl_movementapi = -{ - name = "movementapi", - file = "movementapi.smx", - #if defined REQUIRE_PLUGIN - required = 1, - #else - required = 0, - #endif -}; - -#if !defined REQUIRE_PLUGIN -public void __pl_movementapi_SetNTVOptional() -{ - MarkNativeAsOptional("Movement_GetJumped"); - MarkNativeAsOptional("Movement_GetHitPerf"); - MarkNativeAsOptional("Movement_GetTakeoffOrigin"); - MarkNativeAsOptional("Movement_GetTakeoffVelocity"); - MarkNativeAsOptional("Movement_GetTakeoffSpeed"); - MarkNativeAsOptional("Movement_GetTakeoffTick"); - MarkNativeAsOptional("Movement_GetTakeoffCmdNum"); - MarkNativeAsOptional("Movement_GetLandingOrigin"); - MarkNativeAsOptional("Movement_GetLandingVelocity"); - MarkNativeAsOptional("Movement_GetLandingSpeed"); - MarkNativeAsOptional("Movement_GetLandingTick"); - MarkNativeAsOptional("Movement_GetLandingCmdNum"); - MarkNativeAsOptional("Movement_GetTurning"); - MarkNativeAsOptional("Movement_GetTurningLeft"); - MarkNativeAsOptional("Movement_GetTurningRight"); - MarkNativeAsOptional("Movement_GetMaxSpeed"); - MarkNativeAsOptional("Movement_GetProcessingOrigin"); - MarkNativeAsOptional("Movement_GetProcessingVelocity"); - MarkNativeAsOptional("Movement_SetTakeoffOrigin"); - MarkNativeAsOptional("Movement_SetTakeoffVelocity"); - MarkNativeAsOptional("Movement_SetLandingOrigin"); - MarkNativeAsOptional("Movement_SetLandingVelocity"); - MarkNativeAsOptional("Movement_GetCollisionCount"); - MarkNativeAsOptional("Movement_GetCollisionStartOrigin"); - MarkNativeAsOptional("Movement_GetCollisionEndOrigin"); - MarkNativeAsOptional("Movement_GetCollisionNormal"); -} -#endif +/* + MovementAPI Plugin Include + + Website: https://github.com/danzayau/MovementAPI +*/ + +#if defined _movementapi_included_ + #endinput +#endif +#define _movementapi_included_ + +#include + + + +/* + Terminology + + Takeoff + Becoming airborne, including jumping, falling, getting off a ladder and leaving noclip. + + Landing + Leaving the air, including landing on the ground, grabbing a ladder and entering noclip. + + Perfect Bunnyhop (Perf) + When the player has jumped in the tick after landing and keeps their speed. + + Duckbug/Crouchbug + When the player sucessfully lands due to uncrouching from mid air and not by falling + down. This causes no stamina loss or fall damage upon landing. + + Jumpbug + This is achieved by duckbugging and jumping at the same time. The player is never seen + as 'on ground' when bunnyhopping from a tick by tick perspective. A jumpbug inherits + the same behavior as a duckbug/crouchbug, along with its effects such as maintaining + speed due to no stamina loss. + + Distbug + Landing behavior varies depending on whether the player lands close to the edge of a + block or not: + + 1. If the player lands close to the edge of a block, this causes the jump duration to + be one tick longer and the player can "slide" on the ground during the landing tick, + using the position post-tick as landing position becomes inaccurate. + + 2. On the other hand, if the player does not land close to the edge, the player will + be considered on the ground one tick earlier, using this position as landing position + is not accurate as the player has yet to be fully on the ground. + + In scenario 1, GetNobugLandingOrigin calculates the correct landing position of the + player before the sliding effect takes effect. + + In scenario 2, GetNobugLandingOrigin attempts to extrapolate the player's fully on + ground position to make landing positions consistent across scenarios. +*/ + + + +// =====[ FORWARDS ]===== + +/** + * Called when a player's movetype changes. + * + * @param client Client index. + * @param oldMovetype Player's old movetype. + * @param newMovetype Player's new movetype. + */ +forward void Movement_OnChangeMovetype(int client, MoveType oldMovetype, MoveType newMovetype); + +/** + * Called when a player touches the ground. + * + * @param client Client index. + */ +forward void Movement_OnStartTouchGround(int client); + +/** + * Called when a player leaves the ground. + * + * @param client Client index. + * @param jumped Whether player jumped to leave ground. + * @param ladderJump Whether player jumped from a ladder. + * @param jumpbug Whether player performed a jumpbug. + */ +forward void Movement_OnStopTouchGround(int client, bool jumped, bool ladderJump, bool jumpbug); + +/** + * Called when a player starts ducking. + * + * @param client Client index. + */ +forward void Movement_OnStartDucking(int client); + +/** + * Called when a player stops ducking. + * + * @param client Client index. + */ +forward void Movement_OnStopDucking(int client); + +/** + * Called when a player jumps (player_jump event), including 'jumpbugs'. + * Setting velocity when this is called may not be effective. + * + * @param client Client index. + * @param jumpbug Whether player 'jumpbugged'. + */ +forward void Movement_OnPlayerJump(int client, bool jumpbug); + +/** + * Called when a player edgebugs + * Setting velocity when this is called may not be effective. + * + * @param client Client index. + * @param origin Player origin before edgebug. + * @param velocity Player velocity before edgebug. + */ +forward void Movement_OnPlayerEdgebug(int client, float origin[3], float velocity[3]); + +/** + * Called before PlayerMove movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnPlayerMovePre(int client, float origin[3], float velocity[3]); + +/** + * Called after PlayerMove movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnPlayerMovePost(int client, float origin[3], float velocity[3]); + +/** + * Called before Duck movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnDuckPre(int client, float origin[3], float velocity[3]); + +/** + * Called after Duck movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnDuckPost(int client, float origin[3], float velocity[3]); + +/** + * Called before LadderMove movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnLadderMovePre(int client, float origin[3], float velocity[3]); + +/** + * Called after LadderMove movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnLadderMovePost(int client, float origin[3], float velocity[3]); + +/** + * Called before FullLadderMove movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnFullLadderMovePre(int client, float origin[3], float velocity[3]); + +/** + * Called after FullLadderMove movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnFullLadderMovePost(int client, float origin[3], float velocity[3]); + +/** + * Called after the player jumps, but before jumping stamina is applied and takeoff variables are not set yet. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnJumpPre(int client, float origin[3], float velocity[3]); + +/** + * Called after the player jumps and after jumping stamina is applied and takeoff variables are already set here. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnJumpPost(int client, float origin[3], float velocity[3]); + +/** + * Called before AirAccelerate movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnAirAcceleratePre(int client, float origin[3], float velocity[3]); + +/** + * Called after AirAccelerate movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnAirAcceleratePost(int client, float origin[3], float velocity[3]); + +/** + * Called before WalkMove movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnWalkMovePre(int client, float origin[3], float velocity[3]); + +/** + * Called after WalkMove movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnWalkMovePost(int client, float origin[3], float velocity[3]); + +/** + * Called before CategorizePosition movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnCategorizePositionPre(int client, float origin[3], float velocity[3]); + +/** + * Called after CategorizePosition movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnCategorizePositionPost(int client, float origin[3], float velocity[3]); + +/** + * Called before TryPlayerMove movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnTryPlayerMovePre(int client, float origin[3], float velocity[3]); + +/** + * Called after TryPlayerMove movement function is called. + * Modifying origin or velocity parameters will change player's origin and velocity accordingly. + * + * @param client Client index. + * @param origin Player origin. + * @param velocity Player velocity. + * @return Plugin_Changed if origin or velocity is changed, Plugin_Continue otherwise. + */ +forward Action Movement_OnTryPlayerMovePost(int client, float origin[3], float velocity[3]); + +// =====[ NATIVES ]===== + +/** + * Gets whether a player's last takeoff was a jump. + * + * @param client Client index. + * @return Whether player's last takeoff was a jump. + */ +native bool Movement_GetJumped(int client); + +/** + * Gets whether a player's last takeoff was a perfect bunnyhop. + * + * @param client Client index. + * @return Whether player's last takeoff was a perfect bunnyhop. + */ +native bool Movement_GetHitPerf(int client); + +/** + * Gets a player's origin at the time of their last takeoff. + * + * @param client Client index. + * @param result Resultant vector. + */ +native void Movement_GetTakeoffOrigin(int client, float result[3]); + +/** + * Gets a player's velocity at the time of their last takeoff. + * + * If sv_enablebunnyhopping is 0, CS:GO may adjust the player's + * velocity after the takeoff velocity has already been measured. + * + * @param client Client index. + * @param result Resultant vector. + */ +native void Movement_GetTakeoffVelocity(int client, float result[3]); + +/** + * Gets a player's horizontal speed at the time of their last takeoff. + * + * If sv_enablebunnyhopping is 0, CS:GO may adjust the player's + * velocity after the takeoff velocity has already been measured. + * + * @param client Client index. + * @return Player's last takeoff speed. + */ +native float Movement_GetTakeoffSpeed(int client); + +/** + * Gets a player's 'tickcount' at the time of their last takeoff. + * + * @param client Client index. + * @return Player's last takeoff 'tickcount'. + */ +native int Movement_GetTakeoffTick(int client); + +/** + * Gets a player's 'cmdnum' at the time of their last takeoff. + * + * @param client Client index. + * @return Player's last takeoff 'cmdnum'. + */ +native int Movement_GetTakeoffCmdNum(int client); + +/** + * Gets a player's origin at the time of their last landing with the distbug fixed. + * + * @param client Client index. + * @param result Resultant vector. + */ +native void Movement_GetNobugLandingOrigin(int client, float result[3]); + +/** + * Gets a player's origin at the time of their last landing. + * + * @param client Client index. + * @param result Resultant vector. + */ +native void Movement_GetLandingOrigin(int client, float result[3]); + +/** + * Gets a player's velocity at the time of their last landing. + * + * @param client Client index. + * @param result Resultant vector. + */ +native void Movement_GetLandingVelocity(int client, float result[3]); + +/** + * Gets a player's horizontal speed at the time of their last landing. + * + * @param client Client index. + * @return Last landing speed of the player (horizontal). + */ +native float Movement_GetLandingSpeed(int client); + +/** + * Gets a player's 'tickcount' at the time of their last landing. + * + * @param client Client index. + * @return Player's last landing 'tickcount'. + */ +native int Movement_GetLandingTick(int client); + +/** + * Gets a player's 'cmdnum' at the time of their last landing. + * + * @param client Client index. + * @return Player's last landing 'cmdnum'. + */ +native int Movement_GetLandingCmdNum(int client); + +/** + * Gets whether a player is turning their aim horizontally. + * + * @param client Client index. + * @return Whether player is turning their aim horizontally. + */ +native bool Movement_GetTurning(int client); + +/** + * Gets whether a player is turning their aim left. + * + * @param client Client index. + * @return Whether player is turning their aim left. + */ +native bool Movement_GetTurningLeft(int client); + +/** + * Gets whether a player is turning their aim right. + * + * @param client Client index. + * @return Whether player is turning their aim right. + */ +native bool Movement_GetTurningRight(int client); + +/** + * Gets result of CCSPlayer::GetPlayerMaxSpeed(client), which + * is the player's max speed as limited by their weapon. + * + * @param client Client index. + * @return Player's max speed as limited by their weapon. + */ +native float Movement_GetMaxSpeed(int client); + +/** + * Gets whether a player duckbugged on this tick. + * + * @param client Client index. + * @return Whether a player duckbugged on this tick. + */ +native bool Movement_GetDuckbugged(int client); + +/** + * Gets whether a player jumpbugged on this tick. + * + * @param client Client index. + * @return Whether a player jumpbugged on this tick. + */ +native bool Movement_GetJumpbugged(int client); + +/** + * Get the player's origin during movement processing. + * + * @param client Client index. + * @param result Resultant vector. + */ +native void Movement_GetProcessingOrigin(int client, float result[3]); + +/** + * Get the player's velocity during movement processing. + * + * @param client Param description + * @param result Resultant vector. + */ +native void Movement_GetProcessingVelocity(int client, float result[3]); + +/** + * Set the player's takeoff origin. + * + * @param client Client index. + * @param origin Desired origin. + */ +native void Movement_SetTakeoffOrigin(int client, float origin[3]); + +/** + * Set the player's takeoff velocity. + * + * @param client Client index. + * @param origin Desired velocity. + */ +native void Movement_SetTakeoffVelocity(int client, float velocity[3]); + +/** + * Set the player's landing origin. + * + * @param client Client index. + * @param origin Desired origin. + */ +native void Movement_SetLandingOrigin(int client, float origin[3]); + +/** + * Get the player's number of collisions during movement processing. + * This function should ideally be called after inside Movement_OnTryPlayerMovePost. + * + * @param client Client index. + * @param origin Desired velocity. + */ +native int Movement_GetCollisionCount(int client); + +/** + * Set the player's landing velocity. + * This function should ideally be called after inside Movement_OnTryPlayerMovePost. + * + * @param client Client index. + * @param num Collision number, must not exceed Movement_GetCollisionCount's value. + * @param result Resultant vector. + */ +native void Movement_GetCollisionStartOrigin(int client, int num, float result[3]); + +/** + * Set the player's landing velocity. + * This function should ideally be called after inside Movement_OnTryPlayerMovePost. + * + * @param client Client index. + * @param origin Desired velocity. + */ +native void Movement_GetCollisionEndOrigin(int client, int num, float result[3]); + +/** + * Set the player's landing velocity. + * This function should ideally be called after inside Movement_OnTryPlayerMovePost. + * + * @param client Client index. + * @param origin Desired velocity. + */ +native void Movement_GetCollisionNormal(int client, int num, float result[3]); + +// =====[ METHODMAP ]===== + +methodmap MovementAPIPlayer < MovementPlayer { + + public MovementAPIPlayer(int client) { + return view_as(MovementPlayer(client)); + } + + property bool Jumped { + public get() { + return Movement_GetJumped(this.ID); + } + } + + property bool HitPerf { + public get() { + return Movement_GetHitPerf(this.ID); + } + } + + public void GetTakeoffOrigin(float buffer[3]) { + Movement_GetTakeoffOrigin(this.ID, buffer); + } + + public void GetTakeoffVelocity(float buffer[3]) { + Movement_GetTakeoffVelocity(this.ID, buffer); + } + + public void SetTakeoffOrigin(float buffer[3]) + { + Movement_SetTakeoffOrigin(this.ID, buffer); + } + + public void SetTakeoffVelocity(float buffer[3]) + { + Movement_SetTakeoffVelocity(this.ID, buffer); + } + + property float TakeoffSpeed { + public get() { + return Movement_GetTakeoffSpeed(this.ID); + } + } + + property int TakeoffTick { + public get() { + return Movement_GetTakeoffTick(this.ID); + } + } + + property int TakeoffCmdNum { + public get() { + return Movement_GetTakeoffCmdNum(this.ID); + } + } + + public void GetLandingOrigin(float buffer[3]) { + Movement_GetLandingOrigin(this.ID, buffer); + } + + public void GetLandingVelocity(float buffer[3]) { + Movement_GetLandingVelocity(this.ID, buffer); + } + + public void SetLandingOrigin(float buffer[3]) + { + Movement_SetLandingOrigin(this.ID, buffer); + } + + public void SetLandingVelocity(float buffer[3]) + { + Movement_SetLandingVelocity(this.ID, buffer); + } + + property float LandingSpeed { + public get() { + return Movement_GetLandingSpeed(this.ID); + } + } + + property int LandingTick { + public get() { + return Movement_GetLandingTick(this.ID); + } + } + + property int LandingCmdNum { + public get() { + return Movement_GetLandingCmdNum(this.ID); + } + } + + property bool Turning { + public get() { + return Movement_GetTurning(this.ID); + } + } + + property bool TurningLeft { + public get() { + return Movement_GetTurningLeft(this.ID); + } + } + + property bool TurningRight { + public get() { + return Movement_GetTurningRight(this.ID); + } + } + + property float MaxSpeed { + public get() { + return Movement_GetMaxSpeed(this.ID); + } + } + + property int CollisionCount { + public get() { + return Movement_GetCollisionCount(this.ID); + } + } + public void GetCollisionStartOrigin(int num, float buffer[3]) + { + Movement_GetCollisionStartOrigin(this.ID, num, buffer); + } + + public void GetCollisionEndOrigin(int num, float buffer[3]) + { + Movement_GetCollisionEndOrigin(this.ID, num, buffer); + } + + public void GetCollisionNormal(int num, float buffer[3]) + { + Movement_GetCollisionNormal(this.ID, num, buffer); + } + + public void GetProcessingVelocity(float buffer[3]) + { + Movement_GetProcessingVelocity(this.ID, buffer); + } + + public void GetProcessingOrigin(float buffer[3]) + { + Movement_GetProcessingOrigin(this.ID, buffer); + } +} + + + +// =====[ DEPENDENCY ]===== + +public SharedPlugin __pl_movementapi = +{ + name = "movementapi", + file = "movementapi.smx", + #if defined REQUIRE_PLUGIN + required = 1, + #else + required = 0, + #endif +}; + +#if !defined REQUIRE_PLUGIN +public void __pl_movementapi_SetNTVOptional() +{ + MarkNativeAsOptional("Movement_GetJumped"); + MarkNativeAsOptional("Movement_GetHitPerf"); + MarkNativeAsOptional("Movement_GetTakeoffOrigin"); + MarkNativeAsOptional("Movement_GetTakeoffVelocity"); + MarkNativeAsOptional("Movement_GetTakeoffSpeed"); + MarkNativeAsOptional("Movement_GetTakeoffTick"); + MarkNativeAsOptional("Movement_GetTakeoffCmdNum"); + MarkNativeAsOptional("Movement_GetLandingOrigin"); + MarkNativeAsOptional("Movement_GetLandingVelocity"); + MarkNativeAsOptional("Movement_GetLandingSpeed"); + MarkNativeAsOptional("Movement_GetLandingTick"); + MarkNativeAsOptional("Movement_GetLandingCmdNum"); + MarkNativeAsOptional("Movement_GetTurning"); + MarkNativeAsOptional("Movement_GetTurningLeft"); + MarkNativeAsOptional("Movement_GetTurningRight"); + MarkNativeAsOptional("Movement_GetMaxSpeed"); + MarkNativeAsOptional("Movement_GetProcessingOrigin"); + MarkNativeAsOptional("Movement_GetProcessingVelocity"); + MarkNativeAsOptional("Movement_SetTakeoffOrigin"); + MarkNativeAsOptional("Movement_SetTakeoffVelocity"); + MarkNativeAsOptional("Movement_SetLandingOrigin"); + MarkNativeAsOptional("Movement_SetLandingVelocity"); + MarkNativeAsOptional("Movement_GetCollisionCount"); + MarkNativeAsOptional("Movement_GetCollisionStartOrigin"); + MarkNativeAsOptional("Movement_GetCollisionEndOrigin"); + MarkNativeAsOptional("Movement_GetCollisionNormal"); +} +#endif