-
-
Save nosoop/ae174270c86a29a08f4af2795df71921 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// read data from the underlying cutlvector | |
// offset found in inner loop in CTFPlayer::GetEquippedWearableForLoadoutSlot (linux) | |
static int offs_CTFPlayer_hMyWearables = 0xDD4; | |
/** | |
* Returns the length of the wearable list. | |
*/ | |
int GetPlayerWearableVectorLength(int client) { | |
return GetEntData(client, offs_CTFPlayer_hMyWearables + 0x0C); | |
} | |
/** | |
* Returns the wearable entity from the player's wearable list in the specified index. | |
*/ | |
int GetPlayerWearable(int client, int index) { | |
Address pData = DereferencePointer(GetEntityAddress(client) | |
+ view_as<Address>(offs_CTFPlayer_hMyWearables)); | |
return LoadEntityHandleFromAddress(pData + view_as<Address>(0x04 * index)); | |
} | |
/** | |
* Reads a value stored in a memory address and returns it as an address. | |
* This currently assumes a 32-bit platform. | |
* | |
* @param addr Address to a memory location. | |
* @return The value stored in the given address as an Address. | |
*/ | |
stock Address DereferencePointer(Address addr) { | |
// maybe someday we'll do 64-bit addresses | |
return view_as<Address>(LoadFromAddress(addr, NumberType_Int32)); | |
} | |
/** | |
* Retrieves an entity index from a raw entity handle address. | |
* | |
* Note that SourceMod's entity conversion routine is an implementation detail that may change. | |
* | |
* @param addr Address to a memory location. | |
* @return Entity index, or -1 if not valid. | |
*/ | |
stock int LoadEntityHandleFromAddress(Address addr) { | |
return EntRefToEntIndex(LoadFromAddress(addr, NumberType_Int32) | (1 << 31)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment