Raised This Month: $51 Target: $400
 12% 

Private Data


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:35.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode