Skip to content

Commit

Permalink
Add native to convert CTFPlayerShared to player
Browse files Browse the repository at this point in the history
  • Loading branch information
nosoop committed Jun 2, 2022
1 parent 11d9756 commit 68b8422
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
6 changes: 6 additions & 0 deletions gamedata/tf2.utils.nosoop.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@
"linux" "3540"
"windows" "3520"
}
"CTFPlayerShared::m_pOuter"
{
// checked in CTFPlayerShared::HasDemoShieldEquipped()
"linux" "400"
"windows" "400"
}
"CTFPlayerShared::m_ConditionData"
{
"linux" "8"
Expand Down
9 changes: 9 additions & 0 deletions scripting/include/tf2utils.inc
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,15 @@ native void TF2Util_UpdatePlayerSpeed(int client, bool immediate = false);
native bool TF2Util_IsPointInRespawnRoom(const float position[3],
int entity = INVALID_ENT_REFERENCE, bool bRestrictToSameTeam = false);

/**
* Given the address of a CTFPlayerShared instance, returns the player associated with it.
*
* Here be dragons.
*
* @param pShared Address of CTFPlayerShared instance.
*/
native int TF2Util_GetPlayerFromSharedAddress(Address pShared);

/**
* Returns the current maximum health of the player.
*/
Expand Down
15 changes: 14 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.18.0"
#define PLUGIN_VERSION "0.19.0"
public Plugin myinfo = {
name = "TF2 Utils",
author = "nosoop",
Expand Down Expand Up @@ -54,6 +54,7 @@ Address offs_CTFPlayer_hMyWearables;

Address offs_CTFPlayerShared_flBurnDuration;
Address offs_CTFPlayerShared_ConditionData;
Address offs_CTFPlayerShared_pOuter;

Address offs_TFCondInfo_flDuration;
Address offs_TFCondInfo_hProvider;
Expand Down Expand Up @@ -106,6 +107,8 @@ public APLRes AskPluginLoad2(Handle self, bool late, char[] error, int maxlen) {

CreateNative("TF2Util_IsPointInRespawnRoom", Native_IsPointInRespawnRoom);

CreateNative("TF2Util_GetPlayerFromSharedAddress", Native_GetPlayerFromSharedAddress);

// deprecated name for backcompat
CreateNative("TF2Util_GetPlayerMaxHealth", Native_GetMaxHealthBoost);

Expand Down Expand Up @@ -231,6 +234,9 @@ public void OnPluginStart() {
offs_CTFPlayerShared_flBurnDuration = GameConfGetAddressOffset(hGameConf,
"CTFPlayerShared::m_flBurnDuration");

offs_CTFPlayerShared_pOuter = GameConfGetAddressOffset(hGameConf,
"CTFPlayerShared::m_pOuter");

sizeof_TFCondInfo = GameConfGetOffset(hGameConf, "sizeof(TFCondInfo_t)");

offs_TFCondInfo_flDuration = GameConfGetAddressOffset(hGameConf,
Expand Down Expand Up @@ -763,6 +769,13 @@ any Native_SetPlayerRespawnTimeOverride(Handle plugin, int numParams) {
return;
}

// int(Address pShared);
any Native_GetPlayerFromSharedAddress(Handle plugin, int numParams) {
Address pShared = GetNativeCell(1);
Address pOuter = DereferencePointer(pShared + offs_CTFPlayerShared_pOuter);
return GetEntityFromAddress(pOuter);
}

bool IsEntityWeapon(int entity) {
if (!IsValidEntity(entity)) {
ThrowNativeError(SP_ERROR_NATIVE, "Entity %d (%d) is invalid", entity,
Expand Down

0 comments on commit 68b8422

Please sign in to comment.