Skip to content

Commit

Permalink
Add GetPlayerShootPosition
Browse files Browse the repository at this point in the history
  • Loading branch information
nosoop committed Feb 3, 2021
1 parent 8de14fd commit 8a0eb55
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
5 changes: 5 additions & 0 deletions gamedata/tf2.utils.nosoop.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"Offsets"
{
// virtual offsets
"CBaseCombatCharacter::Weapon_ShootPosition()"
{
"windows" "268"
"linux" "269"
}
"CBaseCombatWeapon::GetSlot()"
{
"windows" "326"
Expand Down
5 changes: 5 additions & 0 deletions scripting/include/tf2utils.inc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ native int TF2Util_GetPlayerMaxAmmo(int client, int iAmmoIndex,
native int TF2Util_GetPlayerMaxHealth(int client, bool bIgnoreAttributes = false,
bool bIgnoreOverheal = false);

/**
* Returns the player's shoot position.
*/
native void TF2Util_GetPlayerShootPosition(int client, float result[3]);

/**
* Returns whether or not the given entity is a weapon.
*
Expand Down
22 changes: 21 additions & 1 deletion scripting/tf2utils.sp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include <stocksoup/memory>

#define PLUGIN_VERSION "0.8.0"
#define PLUGIN_VERSION "0.9.0"
public Plugin myinfo = {
name = "TF2 Utils",
author = "nosoop",
Expand All @@ -25,6 +25,7 @@ bool g_bDeferredSpeedUpdate[MAXPLAYERS + 1];

Handle g_SDKCallPlayerGetMaxAmmo;
Handle g_SDKCallPlayerTakeHealth;
Handle g_SDKCallPlayerGetShootPosition;

Handle g_SDKCallPlayerSharedGetMaxHealth;

Expand All @@ -51,6 +52,8 @@ public APLRes AskPluginLoad2(Handle self, bool late, char[] error, int maxlen) {
CreateNative("TF2Util_GetWeaponID", Native_GetWeaponID);
CreateNative("TF2Util_GetWeaponMaxClip", Native_GetWeaponMaxClip);

CreateNative("TF2Util_GetPlayerShootPosition", Native_GetPlayerShootPosition);

return APLRes_Success;
}

Expand Down Expand Up @@ -78,6 +81,12 @@ public void OnPluginStart() {
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
g_SDKCallPlayerGetMaxAmmo = EndPrepSDKCall();

StartPrepSDKCall(SDKCall_Player);
PrepSDKCall_SetFromConf(hGameConf, SDKConf_Virtual,
"CBaseCombatCharacter::Weapon_ShootPosition()");
PrepSDKCall_SetReturnInfo(SDKType_Vector, SDKPass_ByValue);
g_SDKCallPlayerGetShootPosition = EndPrepSDKCall();

StartPrepSDKCall(SDKCall_Raw);
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
PrepSDKCall_SetFromConf(hGameConf, SDKConf_Signature,
Expand Down Expand Up @@ -228,6 +237,17 @@ public int Native_GetPlayerWearableCount(Handle plugin, int nParams) {
return GetEntData(client, view_as<int>(offs_CTFPlayer_hMyWearables) + 0x0C);
}

// void(int client, float result[3]);
public int Native_GetPlayerShootPosition(Handle plugin, int nParams) {
int client = GetNativeCell(1);
if (client < 1 || client > MaxClients || !IsClientInGame(client)) {
ThrowNativeError(SP_ERROR_NATIVE, "Client index %d is invalid", client);
}
float vecResult[3];
SDKCall(g_SDKCallPlayerGetShootPosition, client, vecResult);
SetNativeArray(2, vecResult, sizeof(vecResult));
}

// bool(int entity);
public int Native_IsEntityWeapon(Handle plugin, int nParams) {
int entity = GetNativeCell(1);
Expand Down

0 comments on commit 8a0eb55

Please sign in to comment.