AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Coding MM:S Plugins & SM Extensions (https://forums.alliedmods.net/forumdisplay.php?f=75)
-   -   Private Data (https://forums.alliedmods.net/showthread.php?t=36917)

DS 12-16-2004 06:38

Private Data
 
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.

Fruchtzwerg 12-16-2004 06:53

I haven't seen any user message Money to update the money on the client side. How do you update the money client side?

DS 12-16-2004 06:57

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.

Geesu 12-16-2004 07:40

nice work :) Did you just guess offsets to see what they do ?

DS 12-16-2004 07:48

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.

vancelorgin 12-16-2004 10:55

Avoid like the plague.

Just kidding - gj :D

Geesu 12-19-2004 15:50

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

Fruchtzwerg 12-19-2004 17:33

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.

Geesu 12-19-2004 17:46

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?

DS 12-19-2004 19:34

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)


All times are GMT -4. The time now is 14:36.

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