Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add edgebug forward #45

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions addons/sourcemod/gamedata/movementapi.games.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
{
Expand Down Expand Up @@ -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" "\x55\x89\xE5\x57\x56\x53\x81\xEC\xA8\x00\x00\x00\x8B\x7D\x08"
}
"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"
}
}
}
}
87 changes: 86 additions & 1 deletion addons/sourcemod/scripting/include/movementapi.inc
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ forward void Movement_OnStopDucking(int client);
*/
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.
Expand Down Expand Up @@ -283,6 +293,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 ]=====

/**
Expand Down Expand Up @@ -484,13 +516,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_SetLandingVelocity(int client, float velocity[3]);
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 ]=====

Expand Down Expand Up @@ -608,6 +669,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);
Expand Down Expand Up @@ -659,5 +740,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
38 changes: 36 additions & 2 deletions addons/sourcemod/scripting/movementapi/forwards.sp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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;
Expand All @@ -21,6 +22,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()
{
Expand All @@ -30,6 +33,7 @@ void CreateGlobalForwards()
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);
Expand All @@ -54,6 +58,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)
Expand Down Expand Up @@ -85,8 +92,6 @@ void Call_OnStopTouchGround(int client, bool jumped, bool ladderJump, bool jumpb
Call_PushCell(ladderJump);
Call_PushCell(jumpbug);
Call_Finish();
// Immediately update OldOnGround state, so we can catch takeoffs that happen outside movement processing.
gB_OldOnGround[client] = false;
}


Expand All @@ -107,6 +112,15 @@ void Call_OnPlayerJump(int client, bool 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);
Expand Down Expand Up @@ -265,4 +279,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;
}
Loading