Skip to content

Commit 68b8422

Browse files
committed
Add native to convert CTFPlayerShared to player
1 parent 11d9756 commit 68b8422

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

gamedata/tf2.utils.nosoop.txt

+6
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@
116116
"linux" "3540"
117117
"windows" "3520"
118118
}
119+
"CTFPlayerShared::m_pOuter"
120+
{
121+
// checked in CTFPlayerShared::HasDemoShieldEquipped()
122+
"linux" "400"
123+
"windows" "400"
124+
}
119125
"CTFPlayerShared::m_ConditionData"
120126
{
121127
"linux" "8"

scripting/include/tf2utils.inc

+9
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,15 @@ native void TF2Util_UpdatePlayerSpeed(int client, bool immediate = false);
319319
native bool TF2Util_IsPointInRespawnRoom(const float position[3],
320320
int entity = INVALID_ENT_REFERENCE, bool bRestrictToSameTeam = false);
321321

322+
/**
323+
* Given the address of a CTFPlayerShared instance, returns the player associated with it.
324+
*
325+
* Here be dragons.
326+
*
327+
* @param pShared Address of CTFPlayerShared instance.
328+
*/
329+
native int TF2Util_GetPlayerFromSharedAddress(Address pShared);
330+
322331
/**
323332
* Returns the current maximum health of the player.
324333
*/

scripting/tf2utils.sp

+14-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include <stocksoup/memory>
1313

14-
#define PLUGIN_VERSION "0.18.0"
14+
#define PLUGIN_VERSION "0.19.0"
1515
public Plugin myinfo = {
1616
name = "TF2 Utils",
1717
author = "nosoop",
@@ -54,6 +54,7 @@ Address offs_CTFPlayer_hMyWearables;
5454

5555
Address offs_CTFPlayerShared_flBurnDuration;
5656
Address offs_CTFPlayerShared_ConditionData;
57+
Address offs_CTFPlayerShared_pOuter;
5758

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

107108
CreateNative("TF2Util_IsPointInRespawnRoom", Native_IsPointInRespawnRoom);
108109

110+
CreateNative("TF2Util_GetPlayerFromSharedAddress", Native_GetPlayerFromSharedAddress);
111+
109112
// deprecated name for backcompat
110113
CreateNative("TF2Util_GetPlayerMaxHealth", Native_GetMaxHealthBoost);
111114

@@ -231,6 +234,9 @@ public void OnPluginStart() {
231234
offs_CTFPlayerShared_flBurnDuration = GameConfGetAddressOffset(hGameConf,
232235
"CTFPlayerShared::m_flBurnDuration");
233236

237+
offs_CTFPlayerShared_pOuter = GameConfGetAddressOffset(hGameConf,
238+
"CTFPlayerShared::m_pOuter");
239+
234240
sizeof_TFCondInfo = GameConfGetOffset(hGameConf, "sizeof(TFCondInfo_t)");
235241

236242
offs_TFCondInfo_flDuration = GameConfGetAddressOffset(hGameConf,
@@ -763,6 +769,13 @@ any Native_SetPlayerRespawnTimeOverride(Handle plugin, int numParams) {
763769
return;
764770
}
765771

772+
// int(Address pShared);
773+
any Native_GetPlayerFromSharedAddress(Handle plugin, int numParams) {
774+
Address pShared = GetNativeCell(1);
775+
Address pOuter = DereferencePointer(pShared + offs_CTFPlayerShared_pOuter);
776+
return GetEntityFromAddress(pOuter);
777+
}
778+
766779
bool IsEntityWeapon(int entity) {
767780
if (!IsValidEntity(entity)) {
768781
ThrowNativeError(SP_ERROR_NATIVE, "Entity %d (%d) is invalid", entity,

0 commit comments

Comments
 (0)