Consistency: Replace GETEDICT, INDEXENT2 and others things with HLTypeConversion in hamsandwich module

This commit is contained in:
Arkshine
2015-10-07 17:31:28 +02:00
parent bf5fdc2b5c
commit 6f301b5cea
20 changed files with 252 additions and 407 deletions

View File

@ -9,7 +9,8 @@
#ifndef _HL_CONVERSION_TYPE_H_
#define _HL_CONVERSION_TYPE_H_
#include "amxxmodule.h"
#include <stddef.h> // size_t
#include <extdll.h> // edict_t, etc.
template <typename T> static inline T& ref_pdata(void *pPrivateData, int offset, int element = 0)
{
@ -98,7 +99,7 @@ class HLTypeConversion
void* id_to_cbase(int index)
{
edict_t *pEdict = id_to_edict(index);
auto pEdict = id_to_edict(index);
return pEdict ? pEdict->pvPrivateData : nullptr;
}
@ -126,7 +127,7 @@ class HLTypeConversion
entvars_t* id_to_entvars(int index)
{
edict_t *pEdict = id_to_edict(index);
auto pEdict = id_to_edict(index);
return pEdict ? VARS(pEdict) : nullptr;
}
@ -147,19 +148,23 @@ class HLTypeConversion
return entvars_to_id(cbase_to_entvar(cbase));
}
public:
size_t get_pev()
{
return m_PevOffset;
}
private:
void search_pev()
{
entvars_t *pev = VARS(m_FirstEdict);
byte *privateData = reinterpret_cast<byte*>(m_FirstEdict->pvPrivateData);
auto pev = VARS(m_FirstEdict);
auto privateData = reinterpret_cast<byte*>(m_FirstEdict->pvPrivateData);
for (size_t i = 0; i < 0xFFF; ++i)
{
entvars_t *val = *(reinterpret_cast<entvars_t**>(privateData + i));
if (val == pev)
if (*reinterpret_cast<entvars_t**>(privateData + i) == pev)
{
m_PevOffset = i;
return;