Skip to content

Instantly share code, notes, and snippets.

@nosoop
Last active November 20, 2019 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nosoop/ae174270c86a29a08f4af2795df71921 to your computer and use it in GitHub Desktop.
Save nosoop/ae174270c86a29a08f4af2795df71921 to your computer and use it in GitHub Desktop.
// 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