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

Getting players weapon & offset question


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Chrisber
AlliedModders Donor
Join Date: Jul 2007
Location: localhost
Old 07-26-2010 , 15:02   Getting players weapon & offset question
Reply With Quote #1

Hey.
Currently I'm trying to get the pointer of CBaseCombatWeapon of the players current weapon. I couldn't find ANY solution for this, the only way I know is to get the players name using IPlayerInfo::GetWeaponName().

Second question: I've tried to build a function that returns an offset for a named property. The code base is from this forum but I couldn't find the post anymore. Problem is, that I can only access the topmost property. Example:
Code:
CBoneFollower:
    baseclass:
        AnimTimeMustBeFirst:
            m_flAnimTime: 1088400916 (int) [124]
        m_flSimulationTime: 1088400916 (int) [128]
        m_vecOrigin: (-1216, 133, 1.03125) (vector) [716]
        m_nModelIndex: -65420 (int) [114]
        m_Collision:
            m_vecMins: (-16, -16, 0) (vector) [328]
            m_vecMaxs: (16, 16, 62) (vector) [340]
            m_nSolidType: 2 (int) [361]
            m_usSolidFlags: 4456464 (int) [356]
            m_nSurroundType: 512 (int) [360]
            m_triggerBloat: 0 (int) [362]
            m_vecSpecifiedSurroundingMins: (0, 0, 0) (vector) [364]
            m_vecSpecifiedSurroundingMaxs: (0, 0, 0) (vector) [376]
        m_nRenderFX: 7602176 (int) [112]
        m_nRenderMode: -16747520 (int) [113]
        m_fEffects: 0 (int) [192]
        m_clrRender: -1 (int) [116]
        m_iTeamNum: 3 (int) [440]
        m_CollisionGroup: 5 (int) [420]
        m_flElasticity: 1 (float) [560]
        m_flShadowCastDistance: 0 (float) [428]
        m_hOwnerEntity: -1 (int) [412]
        m_hEffectEntity: -1 (int) [416]
        moveparent: -1 (int) [308]
        m_iParentAttachment: -16776704 (int) [305]
        movetype: -65534 (int) [306]
        movecollide: -256 (int) [307]
        m_angRotation: (0, 0, 0) (vector) [728]
        m_iTextureFrameIndex: 65792 (int) [604]
        predictable_id:
            m_PredictableID: 0 (int) [136]
            m_bIsPlayerSimulated: 0 (int) [756]
        m_bSimulatedEveryTick: 257 (int) [605]
        m_bAnimatedEveryTick: 1 (int) [606]
        m_bAlternateSorting: 0 (int) [607]
    m_modelIndex: 0 (int) [768]
    m_solidIndex: 0 (int) [772]
My function:
Code:
nt CPropData::Find(const string &strClass, const string &strName)
{
    map<string, map<string, int>>::iterator it = this->m_Cache.find(strClass);

    if (it != this->m_Cache.end())
    {
        map<string, int>::iterator it2 = it->second.find(strName);

        if (it2 != it->second.end())
        {
            return it2->second;
        }
    }

    ServerClass *pClass = pServer->GetAllServerClasses();

    while (pClass)
    {
        if (strClass == pClass->GetName())
        {
            return this->Search(pClass->m_pTable, strClass, strName, 0);
        }

        pClass = pClass->m_pNext;
    }

    return -1;
}

int CPropData::Search(SendTable *pTable, const string &strClass, const string &strName, int iOffset)
{
    int iProps = pTable->GetNumProps();

    for (int i = 0; i < iProps; i++)
    {
        SendProp *pProp = pTable->GetProp(i);

        if (pProp->GetName() && strName == pProp->GetName())
        {
            iOffset += pProp->GetOffset();
            this->m_Cache[strClass][strName] = iOffset;

            return iOffset;
        }
        else if (pProp->GetDataTable())
        {
            int iNew = this->Search(pProp->GetDataTable(), strClass, strName, iOffset + pProp->GetOffset());

            if (iNew != -1)
            {
                return iNew;
            }
        }
    }

    return -1;
}
How would code a function that also accepts full phrases, like "CBoneFollower.baseclass.AnimTimeMustBeFirst. m_flAnimTime"?

Thanks for your answers!
Chrisber is offline
sn4k3
Senior Member
Join Date: Nov 2005
Old 07-26-2010 , 20:47   Re: Getting players weapon & offset question
Reply With Quote #2

dont know if it helps:
vfuncs can easily get weapon slot

Code:
// get weapon name from entity
char *getBaseCombatWeaponToStr(CBaseCombatWeapon *weapon)
{
	if (!weapon) return NULL;

	edict_t *pEntity = gameents->BaseEntityToEdict(weapon);
	if (!IsEntitySafe(pEntity)) return NULL;

	return const_cast<char*>(pEntity->GetClassName());
}

CBaseCombatWeapon *SVFuncsLib::Weapon_GetSlot(CBaseEntity *pBase, int weapon_slot)
{
	int iOffset = GetOffset(0, "CBaseCombatCharacter::Weapon_GetSlot", GamePlayer);
	if (iOffset == -1 || !pBase) return NULL;
	VFUNC_1(pBase, iOffset, return, CBaseCombatWeapon *, int, weapon_slot); 
}
to accept CBoneFollower.baseclass.AnimTimeMustBeFirst. m_flAnimTime
you can use the following, code by BAILOPAN

Code:
// Split 'CBasePlayer.m_iHealth' into ClassName = CBasePlayer, Property = m_iHealth
bool LIB_PROP_CLASS::SplitCombinedProp(const char *source, char *ClassName, char *Property)
{
	int length = strlen(source);

	bool found_split = false;
	int j = 0;

	for (int i = 0; i < length; i++)
	{
		if (found_split)
		{
			Property[j] = source[i];
			j++;
		}
		else
		{
			ClassName[i] = source[i];
		}

		if (!found_split)
		{
			if (source[i] == '.')
			{
				ClassName[i] = '\0';
				found_split = true;
			}
		}
	}

	if (!found_split) return false;

	return true;
}

/**
* Searches for a named Server Class.
*
* @param name		Name of the top-level server class.
* @return 		Server class matching the name, or NULL if none found.
*/
ServerClass *LIB_PROP_CLASS::UTIL_FindServerClass(const char *name)
{
	ServerClass *pClass = server->GetAllServerClasses();
	while (pClass)
	{
		if (strcmp(pClass->m_pNetworkName, name) == 0)
			return pClass;
		pClass = pClass->m_pNext;
	}
	return NULL;
}

/*
* Recursively looks through a send table for a given named property.
*
* @param pTable	Send table to browse.
* @param name		Property to search for.
* @return 		SendProp pointer on success, NULL on failure.
*/
SendProp *LIB_PROP_CLASS::UTIL_FindSendProp(SendTable *pTable, const char *name)
{
	int count = pTable->GetNumProps();
	SendProp *pProp;
	for (int i = 0; i < count; i++)
	{
		pProp = pTable->GetProp(i);
		if (strcmp(pProp->GetName(), name) == 0)
			return pProp;
		if (pProp->GetDataTable())
		{
			if ((pProp=UTIL_FindSendProp(pProp->GetDataTable(), name)) != NULL)
				return pProp;
		}
	}
	return NULL;
}

int LIB_PROP_CLASS::FindPropOffset(const char *combinedprop)
{
	char ClassName[256] = "";
	char Property[256] = "";
	if(!SplitCombinedProp(combinedprop, ClassName, Property)) return 0;
	return FindPropOffset(ClassName, Property);
}

int LIB_PROP_CLASS::FindPropOffset(const char *ClassName, const char *Property)
{
	if(!ClassName) return 0; // No data
	if(!Property) return FindPropOffset(ClassName); // Maybe a combined prop?

	FOR_EACH_VEC(vec_props, i)
	{
		if(LIB_STRING_CLASS::FStrEq(vec_props[i].classname, ClassName) && LIB_STRING_CLASS::FStrEq(vec_props[i].propertyname, Property))
		{
			return vec_props[i].offset;
		}
	}
	ServerClass *sc = UTIL_FindServerClass(ClassName);
	if(!sc)	return 0;

	SendProp *pProp = UTIL_FindSendProp(sc->m_pTable, Property);
	if(!pProp)	return 0;
	CProperty cprop;
	cprop.classname = ClassName;
	cprop.propertyname = Property;
	cprop.offset = pProp->GetOffset();
	cprop.bits = pProp->m_nBits;
	cprop.is_signed = pProp->IsSigned();
	cprop.var_type = pProp->GetType();
	vec_props.AddToTail(cprop);
	return cprop.offset;
}
note ignore all cprop codding, it was my modifications, just remove.
to use it:

Code:
float LIB_PROP_CLASS::Prop_GetFloat(edict_t *pEntity, const char *ClassName, const char *Property)
{
	int offset = FindPropOffset(ClassName, Property);
	if(!offset) return -1;
	unsigned char *ptr = (unsigned char *) pEntity->GetUnknown() + offset;
	float *sptr = (float *) ptr;
	return *sptr;
}

Prop_GetFloat(pEntity, "CBoneFollower", "m_flAnimTime");
OR
Prop_GetFloat(pEntity, "CBoneFollower.m_flAnimTime", NULL);

Last edited by sn4k3; 07-26-2010 at 20:51.
sn4k3 is offline
Send a message via MSN to sn4k3
Chrisber
AlliedModders Donor
Join Date: Jul 2007
Location: localhost
Old 07-27-2010 , 06:21   Re: Getting players weapon & offset question
Reply With Quote #3

Yeah, thanks.
I know that I can use Weapon_GetSlot, but how I would know whats the players current slot? I want his active weapon he's currently holding.

Chris
Chrisber is offline
sn4k3
Senior Member
Join Date: Nov 2005
Old 07-27-2010 , 09:08   Re: Getting players weapon & offset question
Reply With Quote #4

Quote:
Originally Posted by Chrisber View Post
Yeah, thanks.
I know that I can use Weapon_GetSlot, but how I would know whats the players current slot? I want his active weapon he's currently holding.

Chris
hum i dont know what it do but:

Code:
85	CBaseEntity::MyCombatWeaponPointer(void)
448	CCSPlayer::CSAnim_GetActiveWeapon(void)
inside HL2 sdk search for 'MyCombatWeaponPointer' and see what it do

EDIT:

you may find the offset for this:

Quote:
virtual C_BaseCombatWeapon *GetActiveWeapon( void ) const;

Last edited by sn4k3; 07-27-2010 at 09:20.
sn4k3 is offline
Send a message via MSN to sn4k3
Chrisber
AlliedModders Donor
Join Date: Jul 2007
Location: localhost
Old 07-27-2010 , 19:48   Re: Getting players weapon & offset question
Reply With Quote #5

Hey.
85 CBaseEntity::MyCombatWeaponPointer(void)
448 CCSPlayer::CSAnim_GetActiveWeapon(void)
They just return pointers to valid entities, but it seems that this isn't the weapon (pEntity->GetClassname() is NULL and m_iClip1 is always zero :/).

For the other method I can't find any vfunc. Shit..

Chris & thanks anyway
Chrisber is offline
sn4k3
Senior Member
Join Date: Nov 2005
Old 07-27-2010 , 19:51   Re: Getting players weapon & offset question
Reply With Quote #6

hum try that offset: m_hActiveWeapon
if dont work as prop try as dmap
sn4k3 is offline
Send a message via MSN to sn4k3
Chrisber
AlliedModders Donor
Join Date: Jul 2007
Location: localhost
Old 07-27-2010 , 20:17   Re: Getting players weapon & offset question
Reply With Quote #7

Doesn't crash, m_iClip1 is always zero and pEntity->GetClassname is still empty (not null).

Chris
Chrisber is offline
sn4k3
Senior Member
Join Date: Nov 2005
Old 07-27-2010 , 20:21   Re: Getting players weapon & offset question
Reply With Quote #8

Quote:
Originally Posted by Chrisber View Post
Doesn't crash, m_iClip1 is always zero and pEntity->GetClassname is still empty (not null).

Chris
hum i'm out of ideas, m_hActiveWeapon is what EST used in old CSS to get active weapon
try dump props
sn4k3 is offline
Send a message via MSN to sn4k3
Chrisber
AlliedModders Donor
Join Date: Jul 2007
Location: localhost
Old 07-28-2010 , 12:02   Re: Getting players weapon & offset question
Reply With Quote #9

Hi.
Tried that already. Do you know how to resolve it?
I do it the following way:

Code:
CBaseCombatWeapon *pWeapon = *(pWeapon*)((unsigned long)pEntity + offs);
Thanks.
Chrisber is offline
sn4k3
Senior Member
Join Date: Nov 2005
Old 07-28-2010 , 12:57   Re: Getting players weapon & offset question
Reply With Quote #10

Quote:
Originally Posted by Chrisber View Post
Hi.
Tried that already. Do you know how to resolve it?
I do it the following way:

Code:
CBaseCombatWeapon *pWeapon = *(pWeapon*)((unsigned long)pEntity + offs);
Thanks.
hum i think it is a handle, or maybe an index?
try get as int and print to console

EDIT:
try that:

Code:
unsigned char *ptr = (unsigned char *) pEntity->GetUnknown() + offset;
CBaseCombatWeapon *pWeapon = (CBaseCombatWeapon *)ptr;

Last edited by sn4k3; 07-28-2010 at 13:19.
sn4k3 is offline
Send a message via MSN to sn4k3
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 10:33.


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