From c8084e84289e454bf9591a3daa8e45a74767773f Mon Sep 17 00:00:00 2001 From: mittorn Date: Thu, 12 Jan 2017 01:26:32 +0200 Subject: [PATCH] Add extended weapon ehandle --- dlls/player.cpp | 6 +++--- dlls/player.h | 10 ++++++---- dlls/weapons.cpp | 4 ++-- dlls/weapons.h | 7 +++++-- dlls/whandle.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 62 insertions(+), 11 deletions(-) create mode 100644 dlls/whandle.h diff --git a/dlls/player.cpp b/dlls/player.cpp index 84c20ad8..8428803e 100644 --- a/dlls/player.cpp +++ b/dlls/player.cpp @@ -92,9 +92,9 @@ TYPEDESCRIPTION CBasePlayer::m_playerSaveData[] = DEFINE_ARRAY( CBasePlayer, m_rgflSuitNoRepeatTime, FIELD_TIME, CSUITNOREPEAT ), DEFINE_FIELD( CBasePlayer, m_lastDamageAmount, FIELD_INTEGER ), - DEFINE_ARRAY( CBasePlayer, m_rgpPlayerItems, FIELD_CLASSPTR, MAX_ITEM_TYPES ), - DEFINE_FIELD( CBasePlayer, m_pActiveItem, FIELD_CLASSPTR ), - DEFINE_FIELD( CBasePlayer, m_pLastItem, FIELD_CLASSPTR ), + DEFINE_ARRAY( CBasePlayer, m_rgpPlayerItems, FIELD_EHANDLE, MAX_ITEM_TYPES ), + DEFINE_FIELD( CBasePlayer, m_pActiveItem, FIELD_EHANDLE ), + DEFINE_FIELD( CBasePlayer, m_pLastItem, FIELD_EHANDLE ), DEFINE_ARRAY( CBasePlayer, m_rgAmmo, FIELD_INTEGER, MAX_AMMO_SLOTS ), DEFINE_FIELD( CBasePlayer, m_idrowndmg, FIELD_INTEGER ), diff --git a/dlls/player.h b/dlls/player.h index 13727506..0751da69 100644 --- a/dlls/player.h +++ b/dlls/player.h @@ -93,6 +93,8 @@ enum PlayerState STATE_POINT_SELECT }; +#include "whandle.h" + class CBasePlayer : public CBaseMonster { public: @@ -173,10 +175,10 @@ public: int m_iClientFOV; // client's known FOV // usable player items - CBasePlayerItem *m_rgpPlayerItems[MAX_ITEM_TYPES]; - CBasePlayerItem *m_pActiveItem; - CBasePlayerItem *m_pClientActiveItem; // client version of the active item - CBasePlayerItem *m_pLastItem; + EHBasePlayerItem m_rgpPlayerItems[MAX_ITEM_TYPES]; + EHBasePlayerItem m_pActiveItem; + EHBasePlayerItem m_pClientActiveItem; // client version of the active item + EHBasePlayerItem m_pLastItem; // shared ammo slots int m_rgAmmo[MAX_AMMO_SLOTS]; diff --git a/dlls/weapons.cpp b/dlls/weapons.cpp index 09a3bbc4..57e80ba9 100644 --- a/dlls/weapons.cpp +++ b/dlls/weapons.cpp @@ -393,7 +393,7 @@ void W_Precache( void ) TYPEDESCRIPTION CBasePlayerItem::m_SaveData[] = { DEFINE_FIELD( CBasePlayerItem, m_pPlayer, FIELD_CLASSPTR ), - DEFINE_FIELD( CBasePlayerItem, m_pNext, FIELD_CLASSPTR ), + DEFINE_FIELD( CBasePlayerItem, m_pNext, FIELD_EHANDLE ), //DEFINE_FIELD( CBasePlayerItem, m_fKnown, FIELD_INTEGER ),Reset to zero on load DEFINE_FIELD( CBasePlayerItem, m_iId, FIELD_INTEGER ), // DEFINE_FIELD( CBasePlayerItem, m_iIdPrimary, FIELD_INTEGER ), @@ -1303,7 +1303,7 @@ TYPEDESCRIPTION CWeaponBox::m_SaveData[] = { DEFINE_ARRAY( CWeaponBox, m_rgAmmo, FIELD_INTEGER, MAX_AMMO_SLOTS ), DEFINE_ARRAY( CWeaponBox, m_rgiszAmmo, FIELD_STRING, MAX_AMMO_SLOTS ), - DEFINE_ARRAY( CWeaponBox, m_rgpPlayerItems, FIELD_CLASSPTR, MAX_ITEM_TYPES ), + DEFINE_ARRAY( CWeaponBox, m_rgpPlayerItems, FIELD_EHANDLE, MAX_ITEM_TYPES ), DEFINE_FIELD( CWeaponBox, m_cAmmoTypes, FIELD_INTEGER ), }; diff --git a/dlls/weapons.h b/dlls/weapons.h index 223fd79a..31f45ea2 100644 --- a/dlls/weapons.h +++ b/dlls/weapons.h @@ -214,6 +214,9 @@ typedef struct int iId; } AmmoInfo; +#include "whandle.h" + + // Items that the player has in their inventory that they can use class CBasePlayerItem : public CBaseAnimating { @@ -262,7 +265,7 @@ public: static AmmoInfo AmmoInfoArray[ MAX_AMMO_SLOTS ]; CBasePlayer *m_pPlayer; - CBasePlayerItem *m_pNext; + EHBasePlayerItem m_pNext; int m_iId; // WEAPON_??? virtual int iItemSlot( void ) { return 0; } // return 0 to MAX_ITEMS_SLOTS, used in hud @@ -453,7 +456,7 @@ public: BOOL PackWeapon( CBasePlayerItem *pWeapon ); BOOL PackAmmo( int iszName, int iCount ); - CBasePlayerItem *m_rgpPlayerItems[MAX_ITEM_TYPES];// one slot for each + EHBasePlayerItem m_rgpPlayerItems[MAX_ITEM_TYPES];// one slot for each int m_rgiszAmmo[MAX_AMMO_SLOTS];// ammo names int m_rgAmmo[MAX_AMMO_SLOTS];// ammo quantities diff --git a/dlls/whandle.h b/dlls/whandle.h new file mode 100644 index 00000000..179297df --- /dev/null +++ b/dlls/whandle.h @@ -0,0 +1,46 @@ +#ifndef WHANDLE_H +#define WHANDLE_H + + + +class CBasePlayerItem; + +class EHBasePlayerItem : public EHANDLE +{ +public: + operator CBasePlayerItem *() + { + return (CBasePlayerItem *)GET_PRIVATE( Get() ); + } + CBasePlayerItem *operator ->() + { + return (CBasePlayerItem *)GET_PRIVATE( Get() ); + } + template + operator T() + { + return (T)GET_PRIVATE( Get() ); + } + template + T *operator = ( T *pEntity ) + { + edict_t *e = NULL; + if( pEntity ) + e = pEntity->edict(); + return (T*)CBaseEntity::Instance( Set ( e ) ); + } + + // handle = NULL correctly + int operator = ( int null1 ) + { + //assert( !null1 ); + Set(0); + return 0; + } + + bool operator !=(EHBasePlayerItem &other) + { + return Get() != other.Get(); + } +}; +#endif \ No newline at end of file