HelpReading Weapon Ammo

Posts 1–8 of 8 · Page 1 of 1
Reading Weapon Ammo
Hi,

Hoping this is an easy question. I have all of the offsets but I can't seem to read ammo correctly. Right now I'm trying this:

Code:
DWORD myBase = manager->Read<DWORD>(client + dwLocalPlayer);
DWORD weapon = manager->Read<DWORD>(myBase + dwWeapon);
int ammo = manager->Read<int>(weapon + dwAmmo);
Where m_iClip1 is dwAmmo and dwWeapon is m_hActiveWeapon. It's not giving me the right values though. How should I go about reading ammo?
Code:
class CEntity
{
private:
DWORD EntityBase;

public:
CEntity(DWORD);
~CEntity();

DWORD WeaponBase();
int Ammo();
};

CEntity::CEntity(DWORD Base)
{
	EntityBase = Base;
}

CEntity::~CEntity()
{
	EntityBase = NULL;
}

DWORD CEntity::WeaponBase()
{
	return Engine->Read<DWORD>(Variable->modClient.dwBase + Offset->m_dwEntityList + (((Engine->Read<DWORD>(EntityBase + Offset->m_hActiveWeapon) & 0xFFF) - 1) * 0x10));
}

int CEntity::Ammo()
{
	return Engine->Read<int>(WeaponBase() + Offset->m_iClip1);
}

//
// Usage
//

void meme()
{
 for(;;)
 {
  CEntity * pLocal = new CEntity(Server->GetLocalPlayer());
  if (!pLocal)
     return;

  cout << pLocal->Ammo() << endl;

  delete pLocal;
 }
}
ps: Get used to class, better, beautiful and prevent code junk...
Later when you need to create a entity pointer, you just do the same as pLocal but with a different name such as pEntity and instead of using GetLocalPlayer you GetEntityByID(int ID);
And yes, Offset is a pointer to netvar manager.
Quote Originally Posted by PhY'z View Post
Code:
class CEntity
{
private:
DWORD EntityBase;

public:
CEntity(DWORD);
~CEntity();

DWORD WeaponBase();
int Ammo();
};

CEntity::CEntity(DWORD Base)
{
	EntityBase = Base;
}

CEntity::~CEntity()
{
	EntityBase = NULL;
}

DWORD CEntity::WeaponBase()
{
	return Engine->Read<DWORD>(Variable->modClient.dwBase + Offset->m_dwEntityList + (((Engine->Read<DWORD>(EntityBase + Offset->m_hActiveWeapon) & 0xFFF) - 1) * 0x10));
}

int CEntity::Ammo()
{
	return Engine->Read<int>(WeaponBase() + Offset->m_iClip1);
}

//
// Usage
//

void meme()
{
 for(;;)
 {
  CEntity * pLocal = new CEntity(Server->GetLocalPlayer());
  if (!pLocal)
     return;

  cout << pLocal->Ammo() << endl;

  delete pLocal;
 }
}
ps: Get used to class, better, beautiful and prevent code junk...
Later when you need to create a entity pointer, you just do the same as pLocal but with a different name such as pEntity and instead of using GetLocalPlayer you GetEntityByID(int ID);
And yes, Offset is a pointer to netvar manager.
Thanks. I don't think that a simple example like this really requires a class, though... I get enough code reviews at work . On the topic of writing good code, you should avoid unnecessary constructs like this

for( ; ; )
or unreadable forced one-liners like this

return Engine->Read<DWORD>(Variable->modClient.dwBase + Offset->m_dwEntityList + (((Engine->Read<DWORD>(EntityBase + Offset->m_hActiveWeapon) & 0xFFF) - 1) * 0x10));
Quote Originally Posted by xeyerericx View Post
Thanks. I don't think that a simple example like this really requires a class, though... I get enough code reviews at work . On the topic of writing good code, you should avoid unnecessary constructs like this


or unreadable forced one-liners like this
ooooh annihilated, jokes

OT:
The way you're trying to get current weapon is incorrect. m_hActiveWeapon is just a handle that is used to retrieve the weapon entity.
Once you get the weapon entity, that can be used to find the address of m_iClip1.

In short:
Code:
DWORD dwLocalPlayer = g_pMemory->Read<DWORD>(dwClientDLL + m_dwLocalPlayer);
DWORD dwActiveWeapon = g_pMemory->Read<DWORD>(dwLocalPlayer + m_hActiveWeapon);
DWORD dwWeaponEntity = g_pMemory->Read<DWORD>(dwClientDLL + m_dwEntityList + ((dwActiveWeapon & 0xFFF) - 1) * 0x10);
int iClip1 = g_pMemory->Read<int>(dwWeaponEntity + m_iClip1);
One thing though, if you plan to add multiple features that require your local weapon entity, you only need do to it once and preferably in a thread to keep some performance.
Quote Originally Posted by xeyerericx View Post
Thanks. I don't think that a simple example like this really requires a class, though... I get enough code reviews at work . On the topic of writing good code, you should avoid unnecessary constructs like this



or unreadable forced one-liners like this
I don't use ~for~, it was open in vs the old unbreakable source code (old release), so it just came while i was writing.

Well, it is unreadable if you aren`t the owner, as i made it, i know what i did, i`m the only one with it so, feels clean, and makes sense.

This is unreadable: http://fwebde.com/programming/write-unreadable-code/
Quote Originally Posted by PhY'z View Post
Code:
class CEntity
{
private:
DWORD EntityBase;

public:
CEntity(DWORD);
~CEntity();

DWORD WeaponBase();
int Ammo();
};

CEntity::CEntity(DWORD Base)
{
	EntityBase = Base;
}

CEntity::~CEntity()
{
	EntityBase = NULL;
}

DWORD CEntity::WeaponBase()
{
	return Engine->Read<DWORD>(Variable->modClient.dwBase + Offset->m_dwEntityList + (((Engine->Read<DWORD>(EntityBase + Offset->m_hActiveWeapon) & 0xFFF) - 1) * 0x10));
}

int CEntity::Ammo()
{
	return Engine->Read<int>(WeaponBase() + Offset->m_iClip1);
}

//
// Usage
//

void meme()
{
 for(;;)
 {
  CEntity * pLocal = new CEntity(Server->GetLocalPlayer());
  if (!pLocal)
     return;

  cout << pLocal->Ammo() << endl;

  delete pLocal;
 }
}
ps: Get used to class, better, beautiful and prevent code junk...
Later when you need to create a entity pointer, you just do the same as pLocal but with a different name such as pEntity and instead of using GetLocalPlayer you GetEntityByID(int ID);
And yes, Offset is a pointer to netvar manager.
Why do you use source engine class names when you obviously do not use the source engine?
Nah, I prefer engine, some people name it fprocess, I already saw some naming it as "meme"
1 week has passed and no further replies have been made by the OP. Assuming solved.

/Closed.
Posts 1–8 of 8 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us