Thread: Private Data
View Single Post
Author Message
DS
SourceMod Developer
Join Date: Sep 2004
Location: WI, USA
Old 12-16-2004 , 06:38   Private Data
Reply With Quote #1

I don't know if this is just a "duh" thing to people, but I thought I'd share this anyways. I have found a fairly simple way to access an enitity's private data. This will of course be mod-specific, but for things like money in CS:S it doesn't really matter how that will be read or modified. Anyways this is basically how to do it:

Code:
edict_t *pPlayer;
pPlayer->GetUnknown();
Using that you can access private data like we could in HL1 with pvPrivateData. This may not be the best way to do it, but it certainly is _a_ way that works.

So here is some code that demonstrates some of the offsets I have found already. The offsets will of course change when CS:S is updated, so be aware of that.

Code:
/* Helper functions */
bool is_user_valid(edict_t *pPlayer) {
	if ( !pPlayer || pPlayer->IsFree() || Q_stricmp(pPlayer->GetClassName(), "player") != 0) {
		return false;
	}

	return true;
}

bool is_user_connected(edict_t *pPlayer) {
	IPlayerInfo *info = playerinfomanager->GetPlayerInfo(pPlayer);

	return info->IsConnected();
}

/* Private data functions for CS:S */
int cs_get_user_money(edict_t *pPlayer) {
	if (!is_user_valid(pPlayer) || !is_user_connected(pPlayer))
		return 0;

	return *((int *)pPlayer->GetUnknown() + 863);
}

void cs_set_user_money(edict_t *pPlayer, int amount) {
	if (!is_user_valid(pPlayer) || !is_user_connected(pPlayer))
		return;

	*((int *)pPlayer->GetUnknown() + 863) = amount;
}

bool cs_get_user_buyzone(edict_t *pPlayer) {
	if (!is_user_valid(pPlayer) || !is_user_connected(pPlayer))
		return false;
	
	int flags = *((int *)pPlayer->GetUnknown() + 1130);
	
	if (flags & (1<<8))
		return true;

	return false;
}
Edit: Updated offsets for December 16th update.
DS is offline