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

Private Data


Post New Thread Reply   
 
Thread Tools Display Modes
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
Fruchtzwerg
Member
Join Date: Dec 2004
Old 12-16-2004 , 06:53  
Reply With Quote #2

I haven't seen any user message Money to update the money on the client side. How do you update the money client side?
__________________
Fruchtzwerg is offline
DS
SourceMod Developer
Join Date: Sep 2004
Location: WI, USA
Old 12-16-2004 , 06:57  
Reply With Quote #3

Oh I forgot to mention that. Well there is no Money message like on the old CS. I thought I was going to have do some ugly hack to get it to update the HUD. But apparently just changing the data in itself will update the HUD anyways. I would guess that the game must check the value continuously and update it when the money value has changed.

Oh yes, and one other thing. These offsets are for a Windows machine. I'm not sure yet if it's simply going to be a +5 under Linux or not as I wasn't able to test this on a Linux machine yet.
DS is offline
Geesu
Veteran Member
Join Date: Mar 2004
Location: Cincinnati, OH
Old 12-16-2004 , 07:40  
Reply With Quote #4

nice work Did you just guess offsets to see what they do ?
__________________
Need war3ft help? DO NOT PM ME... Check the forums
Geesu is offline
Send a message via AIM to Geesu Send a message via MSN to Geesu
DS
SourceMod Developer
Join Date: Sep 2004
Location: WI, USA
Old 12-16-2004 , 07:48  
Reply With Quote #5

Well I did more than guessing, heh. I did a dump of offsets like I do trying to find offsets under HL1. It's not very polished code, but it's what I used:

Code:
int value = 0;
char *msg = new char[64];
for (int i = 0; i <= 2000; i++) {
	value = *((int *)pEntity->GetUnknown() + i);
	sprintf(msg, "%d: %d\n", i, value);
	engine->LogPrint(msg);
}
delete[] msg;
I'm not really sure what data range I should be checking for just yet, but that's something to experiment with.
DS is offline
vancelorgin
Senior Member
Join Date: Dec 2004
Location: san frandisco
Old 12-16-2004 , 10:55  
Reply With Quote #6

Avoid like the plague.

Just kidding - gj
vancelorgin is offline
Geesu
Veteran Member
Join Date: Mar 2004
Location: Cincinnati, OH
Old 12-19-2004 , 15:50  
Reply With Quote #7

OK I found these when playing around:

Quote:
// Health Value: 39
// Money: 863
// Ammo left in clip : 402
I wouldn't recommend setting the health above 1023, very weird stuff happens. You're health doesn't even show and you get put in the ground a little but can still walk, very strange
__________________
Need war3ft help? DO NOT PM ME... Check the forums
Geesu is offline
Send a message via AIM to Geesu Send a message via MSN to Geesu
Fruchtzwerg
Member
Join Date: Dec 2004
Old 12-19-2004 , 17:33  
Reply With Quote #8

Quote:
Originally Posted by Pimp Daddy
I wouldn't recommend setting the health above 1023, very weird stuff happens. You're health doesn't even show and you get put in the ground a little but can still walk, very strange
Thats because you changed another value too, maybe health is not an int, but an short.
__________________
Fruchtzwerg is offline
Geesu
Veteran Member
Join Date: Mar 2004
Location: Cincinnati, OH
Old 12-19-2004 , 17:46  
Reply With Quote #9

ok here is a question... lets say I get an offset and it contains like

(1<<1) | (1<<2) | (1<<3)

And I just want to set the (1<<1) to 0 ((0<<1))...

How would I do this?
__________________
Need war3ft help? DO NOT PM ME... Check the forums
Geesu is offline
Send a message via AIM to Geesu Send a message via MSN to Geesu
DS
SourceMod Developer
Join Date: Sep 2004
Location: WI, USA
Old 12-19-2004 , 19:34  
Reply With Quote #10

Quote:
Originally Posted by Pimp Daddy
ok here is a question... lets say I get an offset and it contains like

(1<<1) | (1<<2) | (1<<3)

And I just want to set the (1<<1) to 0 ((0<<1))...

How would I do this?
The ~ (bitwise not) is what's needed to remove a flag.

So assuming (int) offsetValue has been set prior to this:
offsetValue &= ~(1<<1)
DS is offline
Reply


Thread Tools
Display Modes

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 06:35.


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