diff --git a/entity2/entitysystem.cpp b/entity2/entitysystem.cpp new file mode 100644 index 00000000..862ef976 --- /dev/null +++ b/entity2/entitysystem.cpp @@ -0,0 +1,40 @@ +#include "const.h" +#include "entity2/entitysystem.h" + +CBaseEntity* CEntitySystem::GetBaseEntity(CEntityIndex entnum) +{ + if (entnum.Get() <= -1 || entnum.Get() >= (MAX_TOTAL_ENTITIES - 1)) + return nullptr; + + CEntityIdentity* pChunkToUse = m_EntityList.m_pIdentityChunks[entnum.Get() / MAX_ENTITIES_IN_LIST]; + if (!pChunkToUse) + return nullptr; + + CEntityIdentity* pIdentity = &pChunkToUse[entnum.Get() % MAX_ENTITIES_IN_LIST]; + if (!pIdentity) + return nullptr; + + if (pIdentity->m_EHandle.GetEntryIndex() != entnum.Get()) + return nullptr; + + return dynamic_cast(pIdentity->m_pInstance); +} + +CBaseEntity* CEntitySystem::GetBaseEntity(const CEntityHandle& hEnt) +{ + if (!hEnt.IsValid()) + return nullptr; + + CEntityIdentity* pChunkToUse = m_EntityList.m_pIdentityChunks[hEnt.GetEntryIndex() / MAX_ENTITIES_IN_LIST]; + if (!pChunkToUse) + return nullptr; + + CEntityIdentity* pIdentity = &pChunkToUse[hEnt.GetEntryIndex() % MAX_ENTITIES_IN_LIST]; + if (!pIdentity) + return nullptr; + + if (pIdentity->m_EHandle != hEnt) + return nullptr; + + return dynamic_cast(pIdentity->m_pInstance); +} \ No newline at end of file diff --git a/game/client/in_forcefeedback.cpp b/game/client/in_forcefeedback.cpp index 936ef2fd..a3a7d181 100644 --- a/game/client/in_forcefeedback.cpp +++ b/game/client/in_forcefeedback.cpp @@ -1,10 +1,10 @@ -//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. ======= +//====== Copyright � 1996-2004, Valve Corporation, All rights reserved. ======= // // Purpose: Force feeback OS level handlers // //============================================================================= #include -#include "basehandle.h" +#include "entityhandle.h" #include "UtlVector.h" #include "usercmd.h" #include "cdll_client_int.h" diff --git a/game/client/in_joystick.cpp b/game/client/in_joystick.cpp index 9a88af3a..da0454fc 100644 --- a/game/client/in_joystick.cpp +++ b/game/client/in_joystick.cpp @@ -7,7 +7,7 @@ // $NoKeywords: $ //===========================================================================// #include "cbase.h" -#include "basehandle.h" +#include "entityhandle.h" #include "utlvector.h" #include "cdll_client_int.h" #include "cdll_util.h" diff --git a/game/client/in_mouse.cpp b/game/client/in_mouse.cpp index e6f07e10..45e3c127 100644 --- a/game/client/in_mouse.cpp +++ b/game/client/in_mouse.cpp @@ -15,7 +15,7 @@ #include "hud.h" #include "cdll_int.h" #include "kbutton.h" -#include "basehandle.h" +#include "entityhandle.h" #include "usercmd.h" #include "input.h" #include "iviewrender.h" diff --git a/game/client/in_trackir.cpp b/game/client/in_trackir.cpp index 07910891..60bc14fd 100644 --- a/game/client/in_trackir.cpp +++ b/game/client/in_trackir.cpp @@ -1,4 +1,4 @@ -//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============// +//========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============// // // Purpose: TrackIR handling function // @@ -21,7 +21,7 @@ #include "vphysics_interface.h" #include #include -#include "basehandle.h" +#include "entityhandle.h" #include "ehandle.h" #include "utlvector.h" #include "cdll_client_int.h" diff --git a/game/server/baseentity.h b/game/server/baseentity.h index 4f8345cb..25f3fe57 100644 --- a/game/server/baseentity.h +++ b/game/server/baseentity.h @@ -11,6 +11,12 @@ #pragma once #endif +#include "entityidentity.h" +class CBaseEntity : public CEntityInstance +{ +}; + +#if 0 #define TEAMNUM_NUM_BITS 6 #include @@ -2906,4 +2912,6 @@ FORCEINLINE bool EntityNamesMatch( const char *pszQuery, string_t nameToMatch ) return false; } +#endif + #endif // BASEENTITY_H diff --git a/game/shared/ehandle.h b/game/shared/ehandle.h index 185ec210..6bece5c2 100644 --- a/game/shared/ehandle.h +++ b/game/shared/ehandle.h @@ -1,4 +1,4 @@ -//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============// +//========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============// // // Purpose: // @@ -11,36 +11,24 @@ #pragma once #endif -#if defined( _DEBUG ) && defined( GAME_DLL ) -#include "tier0/dbg.h" -#include "cbase.h" -#endif - - -#include "const.h" -#include "basehandle.h" -#include "entitylist_base.h" - - -class IHandleEntity; - +#include "entityhandle.h" +#include "entity2/entitysystem.h" // -------------------------------------------------------------------------------------------------- // // Game-code CBaseHandle implementation. // -------------------------------------------------------------------------------------------------- // -inline IHandleEntity* CBaseHandle::Get() const +inline IHandleEntity* CEntityHandle::Get() const { - extern CBaseEntityList *g_pEntityList; - return g_pEntityList->LookupEntity( *this ); + extern CEntitySystem *g_pEntitySystem; + return g_pEntitySystem->GetBaseEntity( *this ); } - // -------------------------------------------------------------------------------------------------- // // CHandle. // -------------------------------------------------------------------------------------------------- // template< class T > -class CHandle : public CBaseHandle +class CHandle : public CEntityHandle { public: diff --git a/game/shared/entitylist_base.h b/game/shared/entitylist_base.h index 1158f3f0..962afd40 100644 --- a/game/shared/entitylist_base.h +++ b/game/shared/entitylist_base.h @@ -1,4 +1,4 @@ -//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============// +//========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============// // // Purpose: // @@ -12,7 +12,7 @@ #include "const.h" -#include "basehandle.h" +#include "entityhandle.h" #include "tier1/utllinkedlist.h" #include "ihandleentity.h" diff --git a/game/shared/sharedvar.h b/game/shared/sharedvar.h index bd276a1d..e9d2558d 100644 --- a/game/shared/sharedvar.h +++ b/game/shared/sharedvar.h @@ -1,4 +1,4 @@ -//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============// +//========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============// // // Purpose: // @@ -13,7 +13,7 @@ #include "convar.h" #include "ispsharedmemory.h" -#include "basehandle.h" +#include "entityhandle.h" #include "isaverestore.h" diff --git a/public/basehandle.h b/public/basehandle.h deleted file mode 100644 index 30ff49a8..00000000 --- a/public/basehandle.h +++ /dev/null @@ -1,206 +0,0 @@ -//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -//=============================================================================// - -#ifndef BASEHANDLE_H -#define BASEHANDLE_H -#ifdef _WIN32 -#pragma once -#endif - - -#include "const.h" -#include "tier0/dbg.h" - - -class IHandleEntity; - -// Represents EHANDLE2 class -// TODO: GAMMACASE: Replace old CBaseHandle with this -class CEntityHandle -{ -public: - union - { - uint32 m_Index; - struct - { - uint32 m_EntityIndex : 15; - uint32 m_Serial : 17; - } m_Parts; - }; -}; - -// -------------------------------------------------------------------------------------------------- // -// CBaseHandle. -// -------------------------------------------------------------------------------------------------- // - -class CBaseHandle -{ -friend class CBaseEntityList; - -public: - - CBaseHandle(); - CBaseHandle( const CBaseHandle &other ); - CBaseHandle( unsigned long value ); - CBaseHandle( int iEntry, int iSerialNumber ); - - void Init( int iEntry, int iSerialNumber ); - void Term(); - - // Even if this returns true, Get() still can return return a non-null value. - // This just tells if the handle has been initted with any values. - bool IsValid() const; - - int GetEntryIndex() const; - int GetSerialNumber() const; - - int ToInt() const; - bool operator !=( const CBaseHandle &other ) const; - bool operator ==( const CBaseHandle &other ) const; - bool operator ==( const IHandleEntity* pEnt ) const; - bool operator !=( const IHandleEntity* pEnt ) const; - bool operator <( const CBaseHandle &other ) const; - bool operator <( const IHandleEntity* pEnt ) const; - - // Assign a value to the handle. - const CBaseHandle& operator=( const IHandleEntity *pEntity ); - const CBaseHandle& Set( const IHandleEntity *pEntity ); - - // Use this to dereference the handle. - // Note: this is implemented in game code (ehandle.h) - IHandleEntity* Get() const; - - -protected: - // The low NUM_SERIAL_BITS hold the index. If this value is less than MAX_EDICTS, then the entity is networkable. - // The high NUM_SERIAL_NUM_BITS bits are the serial number. - unsigned long m_Index; -}; - - -#include "ihandleentity.h" - - -inline CBaseHandle::CBaseHandle() -{ - m_Index = INVALID_EHANDLE_INDEX; -} - -inline CBaseHandle::CBaseHandle( const CBaseHandle &other ) -{ - m_Index = other.m_Index; -} - -inline CBaseHandle::CBaseHandle( unsigned long value ) -{ - m_Index = value; -} - -inline CBaseHandle::CBaseHandle( int iEntry, int iSerialNumber ) -{ - Init( iEntry, iSerialNumber ); -} - -inline void CBaseHandle::Init( int iEntry, int iSerialNumber ) -{ - Assert( iEntry >= 0 && (iEntry & ENT_ENTRY_MASK) == iEntry); - Assert( iSerialNumber >= 0 && iSerialNumber < (1 << NUM_SERIAL_NUM_BITS) ); - - m_Index = iEntry | (iSerialNumber << NUM_SERIAL_NUM_SHIFT_BITS); -} - -inline void CBaseHandle::Term() -{ - m_Index = INVALID_EHANDLE_INDEX; -} - -inline bool CBaseHandle::IsValid() const -{ - return m_Index != INVALID_EHANDLE_INDEX; -} - -inline int CBaseHandle::GetEntryIndex() const -{ - // There is a hack here: due to a bug in the original implementation of the - // entity handle system, an attempt to look up an invalid entity index in - // certain cirumstances might fall through to the the mask operation below. - // This would mask an invalid index to be in fact a lookup of entity number - // NUM_ENT_ENTRIES, so invalid ent indexes end up actually looking up the - // last slot in the entities array. Since this slot is always empty, the - // lookup returns NULL and the expected behavior occurs through this unexpected - // route. - // A lot of code actually depends on this behavior, and the bug was only exposed - // after a change to NUM_SERIAL_NUM_BITS increased the number of allowable - // static props in the world. So the if-stanza below detects this case and - // retains the prior (bug-submarining) behavior. - if ( !IsValid() ) - return NUM_ENT_ENTRIES-1; - return m_Index & ENT_ENTRY_MASK; -} - -inline int CBaseHandle::GetSerialNumber() const -{ - return m_Index >> NUM_SERIAL_NUM_SHIFT_BITS; -} - -inline int CBaseHandle::ToInt() const -{ - return (int)m_Index; -} - -inline bool CBaseHandle::operator !=( const CBaseHandle &other ) const -{ - return m_Index != other.m_Index; -} - -inline bool CBaseHandle::operator ==( const CBaseHandle &other ) const -{ - return m_Index == other.m_Index; -} - -inline bool CBaseHandle::operator ==( const IHandleEntity* pEnt ) const -{ - return Get() == pEnt; -} - -inline bool CBaseHandle::operator !=( const IHandleEntity* pEnt ) const -{ - return Get() != pEnt; -} - -inline bool CBaseHandle::operator <( const CBaseHandle &other ) const -{ - return m_Index < other.m_Index; -} - -inline bool CBaseHandle::operator <( const IHandleEntity *pEntity ) const -{ - unsigned long otherIndex = (pEntity) ? pEntity->GetRefEHandle().m_Index : INVALID_EHANDLE_INDEX; - return m_Index < otherIndex; -} - -inline const CBaseHandle& CBaseHandle::operator=( const IHandleEntity *pEntity ) -{ - return Set( pEntity ); -} - -inline const CBaseHandle& CBaseHandle::Set( const IHandleEntity *pEntity ) -{ - if ( pEntity ) - { - *this = pEntity->GetRefEHandle(); - } - else - { - m_Index = INVALID_EHANDLE_INDEX; - } - - return *this; -} - - -#endif // BASEHANDLE_H diff --git a/public/cmodel.h b/public/cmodel.h index b86a4423..400dcefd 100644 --- a/public/cmodel.h +++ b/public/cmodel.h @@ -1,4 +1,4 @@ -//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============// +//========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============// // // Purpose: // @@ -15,7 +15,7 @@ #include "trace.h" #include "tier0/dbg.h" -#include "basehandle.h" +#include "entityhandle.h" struct edict_t; struct model_t; diff --git a/public/const.h b/public/const.h index 94c179d7..5bd74bf3 100644 --- a/public/const.h +++ b/public/const.h @@ -1,4 +1,4 @@ -//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============// +//========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============// // // Purpose: // @@ -74,7 +74,7 @@ #define NUM_ENT_ENTRIES (1 << NUM_ENT_ENTRY_BITS) #define INVALID_EHANDLE_INDEX 0xFFFFFFFF -#define NUM_SERIAL_NUM_BITS 16 // (32 - NUM_ENT_ENTRY_BITS) +#define NUM_SERIAL_NUM_BITS 17 // (32 - NUM_ENT_ENTRY_BITS) #define NUM_SERIAL_NUM_SHIFT_BITS (32 - NUM_SERIAL_NUM_BITS) #define ENT_ENTRY_MASK (( 1 << NUM_SERIAL_NUM_BITS) - 1) diff --git a/public/engine/IEngineTrace.h b/public/engine/IEngineTrace.h index efe43a26..1ad3dbf7 100644 --- a/public/engine/IEngineTrace.h +++ b/public/engine/IEngineTrace.h @@ -1,4 +1,4 @@ -//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============// +//========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============// // // Purpose: // @@ -12,7 +12,7 @@ #pragma once #endif -#include "basehandle.h" +#include "entityhandle.h" #include "utlvector.h" //need CUtlVector for IEngineTrace::GetBrushesIn*() #include "mathlib/vector4d.h" #include "bspflags.h" diff --git a/public/engine/IStaticPropMgr.h b/public/engine/IStaticPropMgr.h index 2ffeb7b2..654e0d09 100644 --- a/public/engine/IStaticPropMgr.h +++ b/public/engine/IStaticPropMgr.h @@ -1,4 +1,4 @@ -//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======// +//===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======// // // Purpose: // @@ -14,7 +14,7 @@ #include "interface.h" #include "mathlib/vector.h" #include "utlvector.h" -#include "basehandle.h" +#include "entityhandle.h" //----------------------------------------------------------------------------- diff --git a/public/entity2/concreteentitylist.h b/public/entity2/concreteentitylist.h new file mode 100644 index 00000000..0274ee76 --- /dev/null +++ b/public/entity2/concreteentitylist.h @@ -0,0 +1,27 @@ +#ifndef CONCRETEENTITYLIST_H +#define CONCRETEENTITYLIST_H + +#include "entityidentity.h" + +class CConcreteEntityList +{ + struct CList + { + CEntityIdentity* m_pHead; + CEntityIdentity* m_pTail; + uint64 unk; + }; +public: + CEntityIdentity* m_pIdentityChunks[MAX_ENTITY_LISTS]; + CEntityIdentity* m_pFirstActiveEntity; // 512 + CConcreteEntityList::CList m_usedList; // 520 + CConcreteEntityList::CList m_dormantList; // 544 + CConcreteEntityList::CList m_freeNetworkableList; // 568 + CConcreteEntityList::CList m_freeNonNetworkableList; // 592 + uint32 m_nNetworkableEntityLimit; // 0x268 + uint32 m_nNonNetworkableEntityLimit; // 0x26c + uint32 m_nMaxPlayers; + CBitVec<16384> m_PVSBits; +}; + +#endif // CONCRETEENTITYLIST_H \ No newline at end of file diff --git a/public/entity2/entitycomponent.h b/public/entity2/entitycomponent.h new file mode 100644 index 00000000..82e3d463 --- /dev/null +++ b/public/entity2/entitycomponent.h @@ -0,0 +1,26 @@ +#ifndef ENTITYCOMPONENT_H +#define ENTITYCOMPONENT_H + +#if _WIN32 +#pragma once +#endif + + +#include +#include "tier1/utlsymbollarge.h" + +class CEntityComponent +{ +private: + uint8 unknown[0x8]; // 0x0 +}; + +class CScriptComponent : public CEntityComponent +{ +private: + uint8 unknown[0x28]; // 0x8 +public: + CUtlSymbolLarge m_scriptClassName; // 0x30 +}; + +#endif // ENTITYCOMPONENT_H \ No newline at end of file diff --git a/public/entity2/entityidentity.h b/public/entity2/entityidentity.h index 6711d551..38c53abd 100644 --- a/public/entity2/entityidentity.h +++ b/public/entity2/entityidentity.h @@ -5,11 +5,72 @@ #pragma once #endif -class CEntityIdentity +#define MAX_ENTITIES_IN_LIST 512 +#define MAX_ENTITY_LISTS 64 // 0x3F +#define MAX_TOTAL_ENTITIES MAX_ENTITIES_IN_LIST * MAX_ENTITY_LISTS // 0x8000 + +#include "eiface.h" +#include "entitycomponent.h" +#include "entityhandle.h" + +class CEntityIdentity; + +struct ChangeAccessorFieldPathIndex_t +{ + int16 m_Value; +}; + +typedef CUtlStringToken WorldGroupId_t; + +class CEntityInstance : public IHandleEntity { public: + // MNetworkDisable + CUtlSymbolLarge m_iszPrivateVScripts; // 0x8 + // MNetworkEnable + // MNetworkPriority "56" + CEntityIdentity* m_pEntity; // 0x10 +private: + void* m_hPrivateScope; // 0x18 - CEntityPrivateScriptScope + uint8 unknown[0x8]; // 0x20 +public: + // MNetworkEnable + // MNetworkDisable + CScriptComponent* m_CScriptComponent; // 0x28 +}; + +// Size: 0x78 +class CEntityIdentity +{ +public: + CEntityInstance* m_pInstance; // 0x0 +private: + void* m_pClass; // 0x8 - CEntityClass +public: + CEntityHandle m_EHandle; // 0x10 + int32 m_nameStringableIndex; // 0x14 + CUtlSymbolLarge m_name; // 0x18 + CUtlSymbolLarge m_designerName; // 0x20 private: + uint64 m_hPublicScope; // 0x28 - CEntityPublicScriptScope +public: + uint32 m_flags; // 0x30 +private: + SpawnGroupHandle_t m_hSpawnGroup; // 0x34 +public: + WorldGroupId_t m_worldGroupId; // 0x38 + uint32 m_fDataObjectTypes; // 0x3c + ChangeAccessorFieldPathIndex_t m_PathIndex; // 0x40 +private: + uint16 m_Padding; // 0x42 + void* m_pAttributes; // 0x48 - CUtlObjectAttributeTable + void* m_pRenderAttrs; // 0x50 - CRenderAttributesDoubleBuffered +public: + CEntityIdentity* m_pPrev; // 0x58 + CEntityIdentity* m_pNext; // 0x60 + CEntityIdentity* m_pPrevByClass; // 0x68 + CEntityIdentity* m_pNextByClass; // 0x70 }; #endif // ENTITYIDENTITY_H \ No newline at end of file diff --git a/public/entity2/entitysystem.h b/public/entity2/entitysystem.h new file mode 100644 index 00000000..4075b48f --- /dev/null +++ b/public/entity2/entitysystem.h @@ -0,0 +1,181 @@ +#ifndef ENTITYSYSTEM_H +#define ENTITYSYSTEM_H + +#include "tier0/platform.h" +#include "tier1/utlmemory.h" +#include "tier1/utlvector.h" +#include "tier1/utldict.h" +#include "entityhandle.h" +#include "baseentity.h" +#include "eiface.h" +#include "concreteentitylist.h" +#include "entitydatainstantiator.h" + +class CEntityKeyValues; +class IEntityResourceManifest; +class IEntityPrecacheConfiguration; +class IEntityResourceManifestBuilder; +class ISpawnGroupEntityFilter; + +typedef void (*EntityResourceManifestCreationCallback_t)(struct IEntityResourceManifest*, void*); + +enum SpawnGroupEntityFilterType_t +{ + SPAWN_GROUP_ENTITY_FILTER_FALLBACK = 0x0, + SPAWN_GROUP_ENTITY_FILTER_MOD_SPECIFIC = 0x1, +}; + +enum ClearEntityDatabaseMode_t +{ + CED_NORMAL = 0x0, + CED_NETWORKEDONLY_AND_DONTCLEARSTRINGPOOL = 0x1, +}; + +enum ActivateType_t +{ + ACTIVATE_TYPE_INITIAL_CREATION = 0x0, + ACTIVATE_TYPE_DATAUPDATE_CREATION = 0x1, + ACTIVATE_TYPE_ONRESTORE = 0x2, +}; + +enum DataUpdateType_t +{ + DATA_UPDATE_CREATED = 0x0, + DATA_UPDATE_DATATABLE_CHANGED = 0x1, +}; + +enum EntityDormancyType_t +{ + ENTITY_NOT_DORMANT = 0x0, + ENTITY_DORMANT = 0x1, + ENTITY_SUSPENDED = 0x2, +}; + +struct EntityNotification_t +{ + CEntityIdentity* m_pEntity; +}; + +struct EntityDormancyChange_t : EntityNotification_t +{ + EntityDormancyType_t m_nPrevDormancyType; + EntityDormancyType_t m_nNewDormancyType; +}; + +struct EntitySpawnInfo_t : EntityNotification_t +{ + const CEntityKeyValues* m_pKeyValues; +}; + +struct EntityActivation_t : EntityNotification_t +{ +}; + +struct EntityDeletion_t : EntityNotification_t +{ +}; + +struct PostDataUpdateInfo_t : EntityNotification_t +{ + DataUpdateType_t m_updateType; +}; + + +struct CEntityPrecacheContext +{ + const CEntityKeyValues* m_pKeyValues; + IEntityPrecacheConfiguration* m_pConfig; + IEntityResourceManifest* m_pManifest; +}; + +class IEntityListener +{ +public: + virtual void OnEntityCreated(CBaseEntity* pEntity) {}; + virtual void OnEntitySpawned(CBaseEntity* pEntity) {}; + virtual void OnEntityDeleted(CBaseEntity* pEntity) {}; +}; + +struct CEntityResourceManifestLock +{ + IEntityResourceManifestBuilder* m_pBuilder; + matrix3x4a_t m_vSpawnGroupOffset; + SpawnGroupHandle_t m_hSpawnGroup; + IEntityPrecacheConfiguration* m_pConfig; + IEntityResourceManifest* m_pManifest; + bool m_bIsLocked; + bool m_bPrecacheEnable; +}; + +abstract_class IEntityResourceManifestBuilder +{ +public: + virtual void BuildResourceManifest(EntityResourceManifestCreationCallback_t callback, void* pContext, IEntityPrecacheConfiguration* pConfig, IEntityResourceManifest* pResourceManifest) = 0; + virtual void BuildResourceManifest(const char* pManifestNameOrGroupName, IEntityPrecacheConfiguration* pConfig, IEntityResourceManifest* pResourceManifest) = 0; + virtual void BuildResourceManifest(SpawnGroupHandle_t hSpawnGroup, const CUtlVector >* pEntityKeyValues, const char* pFilterName, IEntityPrecacheConfiguration* pConfig, IEntityResourceManifest* pResourceManifest) = 0; + virtual void BuildResourceManifest(SpawnGroupHandle_t hSpawnGroup, int nEntityKeyValueCount, const CEntityKeyValues** ppEntityKeyValues, IEntityPrecacheConfiguration* pConfig, IEntityResourceManifest* pResourceManifest) = 0; + virtual void UnknownFunc004() = 0; // Another BuildResourceManifest function in 2018, but it is quite different now + virtual void BuildResourceManifestForEntity(uint64 unknown1, IEntityPrecacheConfiguration* pConfig, IEntityResourceManifest* pResourceManifest, uint64 unknown2) = 0; + virtual void InvokePrecacheCallback(void* hResource /* ResourceHandle_t */, const EntitySpawnInfo_t* const info, IEntityPrecacheConfiguration* pConfig, IEntityResourceManifest* pResourceManifest, char* unk, void* callback /* SecondaryPrecacheMemberCallback_t */) = 0; + virtual void AddRefKeyValues(const CEntityKeyValues* pKeyValues) = 0; + virtual void ReleaseKeyValues(const CEntityKeyValues* pKeyValues) = 0; + virtual void LockResourceManifest(bool bLock, CEntityResourceManifestLock* const context) = 0; +}; + + +// Size: 0x1510 (from constructor) +class CEntitySystem : public IEntityResourceManifestBuilder +{ +public: + virtual ~CEntitySystem() = 0; + virtual void ClearEntityDatabase(ClearEntityDatabaseMode_t eMode) = 0; + virtual void FindEntityProcedural(const char* szName, CEntityInstance* pSearchingEntity, CEntityInstance* pActivator, CEntityInstance* pCaller) = 0; + virtual void OnEntityParentChanged(CEntityInstance* pEntity, CEntityInstance* pNewParent) = 0; // empty function + virtual void OnAddEntity(CEntityInstance* pEnt, CEntityHandle handle) = 0; // empty function + virtual void OnRemoveEntity(CEntityInstance* pEnt, CEntityHandle handle) = 0; // empty function + virtual int GetSpawnGroupWorldId(SpawnGroupHandle_t hSpawnGroup) = 0; // returns 0 + virtual void Spawn(int nCount, const EntitySpawnInfo_t* pInfo) = 0; + virtual void Activate(int nCount, const EntityActivation_t* pActivates, ActivateType_t activateType) = 0; + virtual void PostDataUpdate(int nCount, const PostDataUpdateInfo_t *pInfo) = 0; + virtual void OnSetDormant(int nCount, const EntityDormancyChange_t* pInfo, bool bNotifyAddedToPVS) = 0; + virtual void UpdateOnRemove(int nCount, const EntityDeletion_t *pDeletion) = 0; + +public: + CBaseEntity* GetBaseEntity(CEntityIndex entnum); + + CBaseEntity* GetBaseEntity(const CEntityHandle& hEnt); + +private: + IEntityResourceManifest* m_pCurrentManifest; +public: + CConcreteEntityList m_EntityList; + // CConcreteEntityList seems to be correct but m_CallQueue supposedly starts at offset 2664, which is... impossible? + // Based on CEntitySystem::CEntitySystem found via string "MaxNonNetworkableEntities" + uint8 unk2696[0xa88]; +}; + +// Size: 0x1580 (from constructor) +class CGameEntitySystem : public CEntitySystem +{ + struct SpawnGroupEntityFilterInfo_t + { + ISpawnGroupEntityFilter* m_pFilter; + SpawnGroupEntityFilterType_t m_nType; + }; + //typedef SpawnGroupEntityFilterInfo_t CUtlMap::ElemType_t; + + +public: + virtual ~CGameEntitySystem() = 0; + +public: + int m_iMaxNetworkedEntIndex; + int m_iNetworkedEntCount; + int m_iNonNetworkedSavedEntCount; + // int m_iNumEdicts; // This is no longer referenced in the server binary + CUtlDict m_spawnGroupEntityFilters; + CUtlVector > m_entityListeners; + uint8 unk5480[0x18]; +}; + +#endif // ENTITYSYSTEM_H \ No newline at end of file diff --git a/public/entityhandle.h b/public/entityhandle.h new file mode 100644 index 00000000..776237bd --- /dev/null +++ b/public/entityhandle.h @@ -0,0 +1,164 @@ +//========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//=============================================================================// + +#ifndef ENTITYHANDLE_H +#define ENTITYHANDLE_H +#ifdef _WIN32 +#pragma once +#endif + +#include "const.h" +#include "ihandleentity.h" + + +class CEntityHandle +{ +public: + CEntityHandle(); + CEntityHandle(const CEntityHandle& other); + CEntityHandle(uint32 value); + CEntityHandle(int iEntry, int iSerialNumber); + + void Init(int iEntry, int iSerialNumber); + void Term(); + + bool IsValid() const; + + int GetEntryIndex() const; + int GetSerialNumber() const; + + bool operator !=(const CEntityHandle& other) const; + bool operator ==(const CEntityHandle& other) const; + bool operator ==(const IHandleEntity* pEnt) const; + bool operator !=(const IHandleEntity* pEnt) const; + bool operator <(const CEntityHandle& other) const; + bool operator <(const IHandleEntity* pEnt) const; + + // Assign a value to the handle. + const CEntityHandle& operator=(const IHandleEntity* pEntity); + const CEntityHandle& Set(const IHandleEntity* pEntity); + + // Use this to dereference the handle. + // Note: this is implemented in game code (ehandle.h) + IHandleEntity* Get() const; + +protected: + union + { + uint32 m_Index; + struct + { + uint32 m_EntityIndex : 15; + uint32 m_Serial : 17; + } m_Parts; + }; +}; + + +inline CEntityHandle::CEntityHandle() +{ + m_Index = INVALID_EHANDLE_INDEX; +} + +inline CEntityHandle::CEntityHandle(const CEntityHandle& other) +{ + m_Index = other.m_Index; +} + +inline CEntityHandle::CEntityHandle(uint32 value) +{ + m_Index = value; +} + +inline CEntityHandle::CEntityHandle(int iEntry, int iSerialNumber) +{ + Init(iEntry, iSerialNumber); +} + +inline void CEntityHandle::Init(int iEntry, int iSerialNumber) +{ + m_Parts.m_EntityIndex = iEntry; + m_Parts.m_Serial = iSerialNumber; +} + +inline void CEntityHandle::Term() +{ + m_Index = INVALID_EHANDLE_INDEX; +} + +inline bool CEntityHandle::IsValid() const +{ + return m_Index != INVALID_EHANDLE_INDEX; +} + +inline int CEntityHandle::GetEntryIndex() const +{ + if (IsValid()) + { + return m_Parts.m_EntityIndex; + } + + return -1; +} + +inline int CEntityHandle::GetSerialNumber() const +{ + return m_Parts.m_Serial; +} + +inline bool CEntityHandle::operator !=(const CEntityHandle& other) const +{ + return m_Index != other.m_Index; +} + +inline bool CEntityHandle::operator ==(const CEntityHandle& other) const +{ + return m_Index == other.m_Index; +} + +inline bool CEntityHandle::operator ==(const IHandleEntity* pEnt) const +{ + return Get() == pEnt; +} + +inline bool CEntityHandle::operator !=(const IHandleEntity* pEnt) const +{ + return Get() != pEnt; +} + +inline bool CEntityHandle::operator <(const CEntityHandle& other) const +{ + return m_Index < other.m_Index; +} + +inline bool CEntityHandle::operator <(const IHandleEntity* pEntity) const +{ + unsigned long otherIndex = (pEntity) ? pEntity->GetRefEHandle().m_Index : INVALID_EHANDLE_INDEX; + return m_Index < otherIndex; +} + +inline const CEntityHandle& CEntityHandle::operator=(const IHandleEntity* pEntity) +{ + return Set(pEntity); +} + +inline const CEntityHandle& CEntityHandle::Set(const IHandleEntity* pEntity) +{ + if (pEntity) + { + *this = pEntity->GetRefEHandle(); + } + else + { + m_Index = INVALID_EHANDLE_INDEX; + } + + return *this; +} + +#endif // ENTITYHANDLE_H + +typedef CEntityHandle CBaseHandle; \ No newline at end of file diff --git a/public/ihandleentity.h b/public/ihandleentity.h index daf711fc..38ad2425 100644 --- a/public/ihandleentity.h +++ b/public/ihandleentity.h @@ -1,4 +1,4 @@ -//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============// +//========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============// // // Purpose: // @@ -10,26 +10,16 @@ #pragma once #endif - -class CBaseHandle; - +class CEntityHandle; // An IHandleEntity-derived class can go into an entity list and use ehandles. class IHandleEntity { + virtual void Schema_DynamicBinding(void**) = 0; public: - virtual ~IHandleEntity() {} - virtual void SetRefEHandle( const CBaseHandle &handle ) = 0; - virtual const CBaseHandle& GetRefEHandle() const = 0; -#ifdef _X360 - IHandleEntity() : - m_bIsStaticProp( false ) - { - } - - bool m_bIsStaticProp; -#endif + virtual ~IHandleEntity() = 0; + virtual const CEntityHandle GetRefEHandle() const = 0; }; -#endif // IHANDLEENTITY_H +#endif // IHANDLEENTITY_H \ No newline at end of file diff --git a/public/networkvar.h b/public/networkvar.h index b7cc5371..4862ddc2 100644 --- a/public/networkvar.h +++ b/public/networkvar.h @@ -15,7 +15,7 @@ #include "convar.h" #if defined( CLIENT_DLL ) || defined( GAME_DLL ) - #include "basehandle.h" + #include "entityhandle.h" #endif #if defined( COMPILER_MSVC ) diff --git a/public/toolframework/itoolentity.h b/public/toolframework/itoolentity.h index b8ff1ff9..45ae72d7 100644 --- a/public/toolframework/itoolentity.h +++ b/public/toolframework/itoolentity.h @@ -1,4 +1,4 @@ -//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======= +//====== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======= // // Purpose: // @@ -13,7 +13,7 @@ #include "tier0/interface.h" #include "tier1/utlvector.h" #include "Color.h" -#include "basehandle.h" +#include "entityhandle.h" #include "iclientrenderable.h" #include "engine/ishadowmgr.h" #include "engine/ivmodelinfo.h" diff --git a/public/variant.h b/public/variant.h index 53b30018..861d5cf7 100644 --- a/public/variant.h +++ b/public/variant.h @@ -11,13 +11,10 @@ #include "vector4d.h" #include "Color.h" #include "entity2/entityidentity.h" -#include "basehandle.h" +#include "entityhandle.h" #include "tier1/bufferstring.h" #include "tier1/utlscratchmemory.h" -// Forward declaration -class CEntityInstance; - // Non-implemented classes/structs struct ResourceBindingBase_t; typedef const ResourceBindingBase_t *ResourceHandle_t;