Raised This Month: $ Target: $400
 0% 

Calling SetGravity in CBaseEntity


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
el hippo
Member
Join Date: Jan 2006
Location: Texas
Old 09-17-2006 , 23:20   Calling SetGravity in CBaseEntity
Reply With Quote #1

Warning: I am a total noob when it comes to C++ virtual functions and vtables. So please don't be too hard on me.

I have searched the internet (using all the nice search engines) and these forums without any luck. I can call things like Teleport and EyeAngles using the vtable offsets described by L Duke at http://wiki.tcwonline.org/index.php/...%28SourceMM%29 . I have also used the dlsym method of hooking functions in linux. Unfortunately both of these fail to give me access to CBaseEntity::SetGravity().

My guess is that the SetGravity function is not assessable because it is not virtual. I am assuming that I have to do the variable offset method to access and set the gravity. Unfortunately I have no idea how to come up with this offset.

Any help would be greatly appreciated.

Hippo
el hippo is offline
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 09-18-2006 , 04:34   Re: Calling SetGravity in CBaseEntity
Reply With Quote #2

Quote:
Originally Posted by el hippo View Post
My guess is that the SetGravity function is not assessable because it is not virtual. I am assuming that I have to do the variable offset method to access and set the gravity. Unfortunately I have no idea how to come up with this offset.

Any help would be greatly appreciated.

Hippo
Search for signature scanning, its how you will need to access this function!
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
L. Duke
Veteran Member
Join Date: Apr 2005
Location: Walla Walla
Old 09-18-2006 , 10:44   Re: Calling SetGravity in CBaseEntity
Reply With Quote #3

SetGravity(float) is just an inline that changes m_flGravity so a sig scan wouldn't help. I was using it directly until the last update, but now I'm using the data description map to get the offset.

Code:
void UTIL_SetGravity(edict_t *pEntity, float Gravity)
{
    //CBasePlayer *pPlayer = (CBasePlayer *)pEntity->GetUnknown()->GetBaseEntity();
    //pPlayer->SetGravity(Gravity);
    
    static int GravityOffset = 0;

    if (GravityOffset==0)
    {
        datamap_t *dmap = gVFunc.GetDataDescMap(pEntity->GetUnknown()->GetBaseEntity());
        if (dmap)
        {
            GravityOffset = UTIL_FindOffsetDMap(dmap, "m_flGravity");
        }
        else
        {
            META_LOG(g_PLAPI, "*** error *** did not obtain datamap\n");
        }
    }

    if (GravityOffset!=0)
    {
        *(float *)((char *)pEntity->GetUnknown()->GetBaseEntity() + GravityOffset ) = Gravity;
    }
    else
    {
        META_LOG(g_PLAPI, "*** error *** could not find GravityOffset\n");
    }

}
L. Duke is offline
Knagg0
SourceMod Donor
Join Date: Dec 2005
Location: Germany
Old 09-18-2006 , 11:39   Re: Calling SetGravity in CBaseEntity
Reply With Quote #4

And this is what you need:

Code:
typedescription_t *FindFieldByName(const char *fieldname, datamap_t *dmap) {

	int c = dmap->dataNumFields;

	for(int i = 0; i < c; i++) {

		typedescription_t *td = &dmap->dataDesc[i];

		if(td->fieldType == FIELD_VOID) continue;

		if(td->fieldType == FIELD_EMBEDDED) {
			typedescription_t *ret = FindFieldByName(fieldname, td->td);
			if(ret) return ret;
		}

		if(!stricmp(td->fieldName, fieldname)) return td;
	}

	if(dmap->baseMap) return FindFieldByName( fieldname, dmap->baseMap );

	return NULL;
}

int UTIL_FindOffsetDMap(datamap_t *dmap, const char *fieldname) {

	typedescription_t *td = FindFieldByName(fieldname, dmap);
	if(td) return td->fieldOffset[0];

	return 0;
}
Knagg0 is offline
el hippo
Member
Join Date: Jan 2006
Location: Texas
Old 09-18-2006 , 18:54   Re: Calling SetGravity in CBaseEntity
Reply With Quote #5

L Duke & Knagg,

Thanks for all the help. Your hints and code examples worked perfectly. I always wondered what the datamap was for.

Hippo
el hippo is offline
Reply



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 13:14.


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