From e91bd0afff5b6da0f7ad20d3724698b60a3c42ce Mon Sep 17 00:00:00 2001 From: Cleverson Date: Tue, 19 Dec 2023 14:42:00 -0300 Subject: [PATCH] Fixed CSSDK and MetaMod SDK Fixed CSSDK and MetaMod SDK --- AccuracyFix/include/cssdk/dlls/API/CSEntity.h | 6 +- AccuracyFix/include/cssdk/dlls/API/CSPlayer.h | 41 ++- .../include/cssdk/dlls/API/CSPlayerItem.h | 1 + .../include/cssdk/dlls/API/CSPlayerWeapon.h | 18 +- AccuracyFix/include/cssdk/dlls/gamerules.h | 2 +- .../include/cssdk/dlls/regamedll_api.h | 135 +++++++++- .../include/cssdk/public/interface.cpp | 8 + AccuracyFix/include/cssdk/public/interface.h | 2 + AccuracyFix/include/cssdk/public/utlarray.h | 235 ++++++++++++++++++ 9 files changed, 430 insertions(+), 18 deletions(-) create mode 100644 AccuracyFix/include/cssdk/public/utlarray.h diff --git a/AccuracyFix/include/cssdk/dlls/API/CSEntity.h b/AccuracyFix/include/cssdk/dlls/API/CSEntity.h index 8f03b7c..aa8de82 100644 --- a/AccuracyFix/include/cssdk/dlls/API/CSEntity.h +++ b/AccuracyFix/include/cssdk/dlls/API/CSEntity.h @@ -36,6 +36,7 @@ class CCSEntity CCSEntity() : m_pContainingEntity(nullptr) { + m_ucDmgPenetrationLevel = 0; } virtual ~CCSEntity() {} @@ -45,12 +46,15 @@ class CCSEntity public: CBaseEntity *m_pContainingEntity; + unsigned char m_ucDmgPenetrationLevel; // penetration level of the damage caused by the inflictor + entvars_t *m_pevLastInflictor; private: #if defined(_MSC_VER) #pragma region reserve_data_Region #endif - int CCSEntity_Reserve[0x1000]; + char CCSEntity_Reserve[0x3FF7]; + virtual void func_reserve1() {}; virtual void func_reserve2() {}; virtual void func_reserve3() {}; diff --git a/AccuracyFix/include/cssdk/dlls/API/CSPlayer.h b/AccuracyFix/include/cssdk/dlls/API/CSPlayer.h index 3f63d5c..3495ee2 100644 --- a/AccuracyFix/include/cssdk/dlls/API/CSPlayer.h +++ b/AccuracyFix/include/cssdk/dlls/API/CSPlayer.h @@ -30,6 +30,7 @@ #include #include +#include enum WeaponInfiniteAmmoMode { @@ -52,9 +53,21 @@ class CCSPlayer: public CCSMonster m_bAutoBunnyHopping(false), m_bMegaBunnyJumping(false), m_bPlantC4Anywhere(false), - m_bSpawnProtectionEffects(false) + m_bSpawnProtectionEffects(false), + m_flJumpHeight(0), + m_flLongJumpHeight(0), + m_flLongJumpForce(0), + m_flDuckSpeedMultiplier(0), + m_iUserID(-1) { m_szModel[0] = '\0'; + + // Resets the kill history for this player + for (int i = 0; i < MAX_CLIENTS; i++) + { + m_iNumKilledByUnanswered[i] = 0; + m_bPlayerDominated[i] = false; + } } virtual bool IsConnected() const = 0; @@ -64,8 +77,8 @@ class CCSPlayer: public CCSMonster virtual CBaseEntity *GiveNamedItemEx(const char *pszName) = 0; virtual void GiveDefaultItems() = 0; virtual void GiveShield(bool bDeploy = true) = 0; - virtual void DropShield(bool bDeploy = true) = 0; - virtual void DropPlayerItem(const char *pszItemName) = 0; + virtual CBaseEntity *DropShield(bool bDeploy = true) = 0; + virtual CBaseEntity *DropPlayerItem(const char *pszItemName) = 0; virtual bool RemoveShield() = 0; virtual void RemoveAllItems(bool bRemoveSuit) = 0; virtual bool RemovePlayerItem(const char* pszItemName) = 0; @@ -106,11 +119,6 @@ class CCSPlayer: public CCSMonster virtual void OnSpawnEquip(bool addDefault = true, bool equipGame = true) = 0; virtual void SetScoreboardAttributes(CBasePlayer *destination = nullptr) = 0; - void ResetVars(); - - void OnSpawn(); - void OnKilled(); - CBasePlayer *BasePlayer() const; public: @@ -138,6 +146,23 @@ class CCSPlayer: public CCSMonster bool m_bMegaBunnyJumping; bool m_bPlantC4Anywhere; bool m_bSpawnProtectionEffects; + double m_flJumpHeight; + double m_flLongJumpHeight; + double m_flLongJumpForce; + double m_flDuckSpeedMultiplier; + + int m_iUserID; + struct CDamageRecord_t + { + float flDamage = 0.0f; + float flFlashDurationTime = 0.0f; + int userId = -1; + }; + using DamageList_t = CUtlArray; + DamageList_t m_DamageList; // A unified array of recorded damage that includes giver and taker in each entry + DamageList_t &GetDamageList() { return m_DamageList; } + int m_iNumKilledByUnanswered[MAX_CLIENTS]; // [0-31] how many unanswered kills this player has been dealt by each other player + bool m_bPlayerDominated[MAX_CLIENTS]; // [0-31] array of state per other player whether player is dominating other players }; // Inlines diff --git a/AccuracyFix/include/cssdk/dlls/API/CSPlayerItem.h b/AccuracyFix/include/cssdk/dlls/API/CSPlayerItem.h index 74abc0b..e4bec45 100644 --- a/AccuracyFix/include/cssdk/dlls/API/CSPlayerItem.h +++ b/AccuracyFix/include/cssdk/dlls/API/CSPlayerItem.h @@ -39,6 +39,7 @@ class CCSPlayerItem: public CCSAnimating } virtual void SetItemInfo(ItemInfo *pInfo) = 0; + virtual int GetItemInfo(ItemInfo *pInfo) = 0; CBasePlayerItem *BasePlayerItem() const; diff --git a/AccuracyFix/include/cssdk/dlls/API/CSPlayerWeapon.h b/AccuracyFix/include/cssdk/dlls/API/CSPlayerWeapon.h index 70317c9..837347c 100644 --- a/AccuracyFix/include/cssdk/dlls/API/CSPlayerWeapon.h +++ b/AccuracyFix/include/cssdk/dlls/API/CSPlayerWeapon.h @@ -28,19 +28,33 @@ #pragma once +enum SecondaryAtkState : uint8_t +{ + WEAPON_SECONDARY_ATTACK_NONE = 0, + WEAPON_SECONDARY_ATTACK_SET, + WEAPON_SECONDARY_ATTACK_BLOCK +}; + class CBasePlayerWeapon; class CCSPlayerWeapon: public CCSPlayerItem { + DECLARE_CLASS_TYPES(CCSPlayerWeapon, CCSPlayerItem); public: CCSPlayerWeapon() : - m_bHasSecondaryAttack(false) + m_iStateSecondaryAttack(WEAPON_SECONDARY_ATTACK_NONE) { } + virtual BOOL DefaultDeploy(char *szViewModel, char *szWeaponModel, int iAnim, char *szAnimExt, int skiplocal = 0) = 0; + virtual int DefaultReload(int iClipSize, int iAnim, float fDelay) = 0; + virtual bool DefaultShotgunReload(int iAnim, int iStartAnim, float fDelay, float fStartDelay, const char *pszReloadSound1 = nullptr, const char *pszReloadSound2 = nullptr) = 0; + virtual void KickBack(float up_base, float lateral_base, float up_modifier, float lateral_modifier, float up_max, float lateral_max, int direction_change) = 0; + virtual void SendWeaponAnim(int iAnim, int skiplocal = 0) = 0; + CBasePlayerWeapon *BasePlayerWeapon() const; public: - bool m_bHasSecondaryAttack; + SecondaryAtkState m_iStateSecondaryAttack; float m_flBaseDamage; }; diff --git a/AccuracyFix/include/cssdk/dlls/gamerules.h b/AccuracyFix/include/cssdk/dlls/gamerules.h index 6778601..d0781be 100644 --- a/AccuracyFix/include/cssdk/dlls/gamerules.h +++ b/AccuracyFix/include/cssdk/dlls/gamerules.h @@ -531,7 +531,7 @@ class CHalfLifeMultiplay: public CGameRules // check if the scenario has been won/lost virtual void CheckWinConditions() = 0; virtual void RemoveGuns() = 0; - virtual void GiveC4() = 0; + virtual CBasePlayer *GiveC4() = 0; virtual void ChangeLevel() = 0; virtual void GoToIntermission() = 0; diff --git a/AccuracyFix/include/cssdk/dlls/regamedll_api.h b/AccuracyFix/include/cssdk/dlls/regamedll_api.h index e971ef5..762d06d 100644 --- a/AccuracyFix/include/cssdk/dlls/regamedll_api.h +++ b/AccuracyFix/include/cssdk/dlls/regamedll_api.h @@ -36,6 +36,7 @@ #include #include #include +#include #include #define REGAMEDLL_API_VERSION_MAJOR 5 @@ -237,10 +238,6 @@ typedef IHookChainRegistry IReGameHookRegistry typedef IHookChain IReGameHook_PM_AirMove; typedef IHookChainRegistry IReGameHookRegistry_PM_AirMove; -// PM_LadderMove hook -typedef IHookChain IReGameHook_PM_LadderMove; -typedef IHookChainRegistry IReGameHookRegistry_PM_LadderMove; - // HandleMenu_ChooseAppearance hook typedef IHookChain IReGameHook_HandleMenu_ChooseAppearance; typedef IHookChainRegistry IReGameHookRegistry_HandleMenu_ChooseAppearance; @@ -342,8 +339,8 @@ typedef IHookChain IReGameHook_CSGameRules_RemoveGuns; typedef IHookChainRegistry IReGameHookRegistry_CSGameRules_RemoveGuns; // CHalfLifeMultiplay::GiveC4 hook -typedef IHookChain IReGameHook_CSGameRules_GiveC4; -typedef IHookChainRegistry IReGameHookRegistry_CSGameRules_GiveC4; +typedef IHookChain IReGameHook_CSGameRules_GiveC4; +typedef IHookChainRegistry IReGameHookRegistry_CSGameRules_GiveC4; // CHalfLifeMultiplay::ChangeLevel hook typedef IHookChain IReGameHook_CSGameRules_ChangeLevel; @@ -529,6 +526,102 @@ typedef IHookChainRegistryClass IReGameHookRegistry_CBa typedef IHookChain IReGameHook_FreeGameRules; typedef IHookChainRegistry IReGameHookRegistry_FreeGameRules; +// PM_LadderMove hook +typedef IHookChain IReGameHook_PM_LadderMove; +typedef IHookChainRegistry IReGameHookRegistry_PM_LadderMove; + +// PM_WaterJump hook +typedef IHookChain IReGameHook_PM_WaterJump; +typedef IHookChainRegistry IReGameHookRegistry_PM_WaterJump; + +// PM_CheckWaterJump hook +typedef IHookChain IReGameHook_PM_CheckWaterJump; +typedef IHookChainRegistry IReGameHookRegistry_PM_CheckWaterJump; + +// PM_Jump hook +typedef IHookChain IReGameHook_PM_Jump; +typedef IHookChainRegistry IReGameHookRegistry_PM_Jump; + +// PM_Duck hook +typedef IHookChain IReGameHook_PM_Duck; +typedef IHookChainRegistry IReGameHookRegistry_PM_Duck; + +// PM_UnDuck hook +typedef IHookChain IReGameHook_PM_UnDuck; +typedef IHookChainRegistry IReGameHookRegistry_PM_UnDuck; + +// PM_PlayStepSound hook +typedef IHookChain IReGameHook_PM_PlayStepSound; +typedef IHookChainRegistry IReGameHookRegistry_PM_PlayStepSound; + +// PM_AirAccelerate hook +typedef IHookChain IReGameHook_PM_AirAccelerate; +typedef IHookChainRegistry IReGameHookRegistry_PM_AirAccelerate; + +// ClearMultiDamage hook +typedef IHookChain IReGameHook_ClearMultiDamage; +typedef IHookChainRegistry IReGameHookRegistry_ClearMultiDamage; + +// AddMultiDamage hook +typedef IHookChain IReGameHook_AddMultiDamage; +typedef IHookChainRegistry IReGameHookRegistry_AddMultiDamage; + +// ApplyMultiDamage hook +typedef IHookChain IReGameHook_ApplyMultiDamage; +typedef IHookChainRegistry IReGameHookRegistry_ApplyMultiDamage; + +// BuyItem hook +typedef IHookChain IReGameHook_BuyItem; +typedef IHookChainRegistry IReGameHookRegistry_BuyItem; + +// CHalfLifeMultiplay::Think hook +typedef IHookChain IReGameHook_CSGameRules_Think; +typedef IHookChainRegistry IReGameHookRegistry_CSGameRules_Think; + +// CHalfLifeMultiplay::TeamFull hook +typedef IHookChain IReGameHook_CSGameRules_TeamFull; +typedef IHookChainRegistry IReGameHookRegistry_CSGameRules_TeamFull; + +// CHalfLifeMultiplay::TeamStacked hook +typedef IHookChain IReGameHook_CSGameRules_TeamStacked; +typedef IHookChainRegistry IReGameHookRegistry_CSGameRules_TeamStacked; + +// CHalfLifeMultiplay::PlayerGotWeapon hook +typedef IHookChain IReGameHook_CSGameRules_PlayerGotWeapon; +typedef IHookChainRegistry IReGameHookRegistry_CSGameRules_PlayerGotWeapon; + +// CBotManager::OnEvent hook +typedef IHookChain IReGameHook_CBotManager_OnEvent; +typedef IHookChainRegistry IReGameHookRegistry_CBotManager_OnEvent; + +// CBasePlayer::CheckTimeBasedDamage hook +typedef IHookChainClass IReGameHook_CBasePlayer_CheckTimeBasedDamage; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_CheckTimeBasedDamage; + +// CBasePlayer::EntSelectSpawnPoint hook +typedef IHookChainClass IReGameHook_CBasePlayer_EntSelectSpawnPoint; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_EntSelectSpawnPoint; + +// CBasePlayerWeapon::ItemPostFrame hook +typedef IHookChainClass IReGameHook_CBasePlayerWeapon_ItemPostFrame; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayerWeapon_ItemPostFrame; + +// CBasePlayerWeapon::KickBack hook +typedef IHookChainClass IReGameHook_CBasePlayerWeapon_KickBack; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayerWeapon_KickBack; + +// CBasePlayerWeapon::SendWeaponAnim hook +typedef IHookChainClass IReGameHook_CBasePlayerWeapon_SendWeaponAnim; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayerWeapon_SendWeaponAnim; + +// CHalfLifeMultiplay::SendDeathMessage hook +typedef IHookChain IReGameHook_CSGameRules_SendDeathMessage; +typedef IHookChainRegistry IReGameHookRegistry_CSGameRules_SendDeathMessage; + +// CBasePlayer::PlayerDeathThink hook +typedef IHookChainClass IReGameHook_CBasePlayer_PlayerDeathThink; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_PlayerDeathThink; + class IReGameHookchains { public: virtual ~IReGameHookchains() {} @@ -665,6 +758,30 @@ class IReGameHookchains { virtual IReGameHookRegistry_FreeGameRules *FreeGameRules() = 0; virtual IReGameHookRegistry_PM_LadderMove *PM_LadderMove() = 0; + virtual IReGameHookRegistry_PM_WaterJump *PM_WaterJump() = 0; + virtual IReGameHookRegistry_PM_CheckWaterJump *PM_CheckWaterJump() = 0; + virtual IReGameHookRegistry_PM_Jump *PM_Jump() = 0; + virtual IReGameHookRegistry_PM_Duck *PM_Duck() = 0; + virtual IReGameHookRegistry_PM_UnDuck *PM_UnDuck() = 0; + virtual IReGameHookRegistry_PM_PlayStepSound *PM_PlayStepSound() = 0; + virtual IReGameHookRegistry_PM_AirAccelerate *PM_AirAccelerate() = 0; + virtual IReGameHookRegistry_ClearMultiDamage *ClearMultiDamage() = 0; + virtual IReGameHookRegistry_AddMultiDamage *AddMultiDamage() = 0; + virtual IReGameHookRegistry_ApplyMultiDamage *ApplyMultiDamage() = 0; + virtual IReGameHookRegistry_BuyItem *BuyItem() = 0; + virtual IReGameHookRegistry_CSGameRules_Think *CSGameRules_Think() = 0; + virtual IReGameHookRegistry_CSGameRules_TeamFull *CSGameRules_TeamFull() = 0; + virtual IReGameHookRegistry_CSGameRules_TeamStacked *CSGameRules_TeamStacked() = 0; + virtual IReGameHookRegistry_CSGameRules_PlayerGotWeapon *CSGameRules_PlayerGotWeapon() = 0; + virtual IReGameHookRegistry_CBotManager_OnEvent *CBotManager_OnEvent() = 0; + virtual IReGameHookRegistry_CBasePlayer_CheckTimeBasedDamage *CBasePlayer_CheckTimeBasedDamage() = 0; + virtual IReGameHookRegistry_CBasePlayer_EntSelectSpawnPoint *CBasePlayer_EntSelectSpawnPoint() = 0; + virtual IReGameHookRegistry_CBasePlayerWeapon_ItemPostFrame *CBasePlayerWeapon_ItemPostFrame() = 0; + virtual IReGameHookRegistry_CBasePlayerWeapon_KickBack *CBasePlayerWeapon_KickBack() = 0; + virtual IReGameHookRegistry_CBasePlayerWeapon_SendWeaponAnim *CBasePlayerWeapon_SendWeaponAnim() = 0; + virtual IReGameHookRegistry_CSGameRules_SendDeathMessage *CSGameRules_SendDeathMessage() = 0; + + virtual IReGameHookRegistry_CBasePlayer_PlayerDeathThink *CBasePlayer_PlayerDeathThink() = 0; }; struct ReGameFuncs_t { @@ -685,6 +802,12 @@ struct ReGameFuncs_t { void (*UTIL_RestartOther)(const char *szClassname); void (*UTIL_ResetEntities)(); void (*UTIL_RemoveOther)(const char *szClassname, int nCount); + void (*UTIL_DecalTrace)(TraceResult *pTrace, int decalNumber); + void (*UTIL_Remove)(CBaseEntity *pEntity); + int (*AddAmmoNameToAmmoRegistry)(const char *szAmmoname); + void (*TextureTypePlaySound)(TraceResult *ptr, Vector vecSrc, Vector vecEnd, int iBulletType); + class CWeaponBox *(*CreateWeaponBox)(CBasePlayerItem *pItem, CBasePlayer *pPlayerOwner, const char *modelName, Vector &origin, Vector &angles, Vector &velocity, float lifeTime, bool packAmmo); + class CGrenade *(*SpawnGrenade)(WeaponIdType weaponId, entvars_t *pevOwner, Vector &vecSrc, Vector &vecThrow, float time, int iTeam, unsigned short usEvent); }; class IReGameApi { diff --git a/AccuracyFix/include/cssdk/public/interface.cpp b/AccuracyFix/include/cssdk/public/interface.cpp index e6de1be..de0a184 100644 --- a/AccuracyFix/include/cssdk/public/interface.cpp +++ b/AccuracyFix/include/cssdk/public/interface.cpp @@ -121,6 +121,14 @@ void *Sys_GetProcAddress(void *pModuleHandle, const char *pName) return GetProcAddress((HMODULE)pModuleHandle, pName); } +// Purpose: Returns a module handle by its name. +// Input : pModuleName - module name +// Output : the module handle or NULL in case of an error +CSysModule *Sys_GetModuleHandle(const char *pModuleName) +{ + return reinterpret_cast(GetModuleHandle(pModuleName)); +} + // Purpose: Loads a DLL/component from disk and returns a handle to it // Input : *pModuleName - filename of the component // Output : opaque handle to the module (hides system dependency) diff --git a/AccuracyFix/include/cssdk/public/interface.h b/AccuracyFix/include/cssdk/public/interface.h index 0aeaca4..abe45b5 100644 --- a/AccuracyFix/include/cssdk/public/interface.h +++ b/AccuracyFix/include/cssdk/public/interface.h @@ -114,6 +114,8 @@ extern CreateInterfaceFn Sys_GetFactory(const char *pModuleName); // load/unload components class CSysModule; +extern CSysModule *Sys_GetModuleHandle(const char *pModuleName); + // Load & Unload should be called in exactly one place for each module // The factory for that module should be passed on to dependent components for // proper versioning. diff --git a/AccuracyFix/include/cssdk/public/utlarray.h b/AccuracyFix/include/cssdk/public/utlarray.h new file mode 100644 index 0000000..6bdb413 --- /dev/null +++ b/AccuracyFix/include/cssdk/public/utlarray.h @@ -0,0 +1,235 @@ +/* +* +* Copyright (c) 1996-2002, Valve LLC. All rights reserved. +* +* This product contains software technology licensed from Id +* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. +* All Rights Reserved. +* +* Use, distribution, and modification of this source code and/or resulting +* object code is restricted to non-commercial enhancements to products from +* Valve LLC. All other use, distribution, or modification is prohibited +* without written permission from Valve LLC. +* +*/ + +#pragma once + +// A growable array class that maintains a free list and keeps elements +// in the same location +#include "tier0/platform.h" +#include "tier0/dbg.h" + +#define FOR_EACH_ARRAY(vecName, iteratorName)\ + for (int iteratorName = 0; (vecName).IsUtlArray && iteratorName < (vecName).Count(); iteratorName++) + +#define FOR_EACH_ARRAY_BACK(vecName, iteratorName)\ + for (int iteratorName = (vecName).Count() - 1; (vecName).IsUtlArray && iteratorName >= 0; iteratorName--) + +template +class CUtlArray +{ +public: + typedef T ElemType_t; + enum { IsUtlArray = true }; // Used to match this at compiletime + + CUtlArray(); + CUtlArray(T *pMemory, size_t count); + ~CUtlArray(); + + CUtlArray &operator=(const CUtlArray &other); + CUtlArray(CUtlArray const &vec); + + // element access + T &operator[](int i); + const T &operator[](int i) const; + T &Element(int i); + const T &Element(int i) const; + T &Random(); + const T &Random() const; + + T *Base(); + const T *Base() const; + + // Returns the number of elements in the array, NumAllocated() is included for consistency with UtlVector + int Count() const; + int NumAllocated() const; + + // Is element index valid? + bool IsValidIndex(int i) const; + static int InvalidIndex(); + + void CopyArray(const T *pArray, size_t count); + + void Clear(); + void RemoveAll(); + void Swap(CUtlArray< T, MAX_SIZE> &vec); + + // Finds an element (element needs operator== defined) + int Find(const T &src) const; + void FillWithValue(const T &src); + + bool HasElement(const T &src) const; + +protected: + T m_Memory[MAX_SIZE]; +}; + +// Constructor +template +inline CUtlArray::CUtlArray() +{ +} + +template +inline CUtlArray::CUtlArray(T *pMemory, size_t count) +{ + CopyArray(pMemory, count); +} + +// Destructor +template +inline CUtlArray::~CUtlArray() +{ +} + +template +inline CUtlArray &CUtlArray::operator=(const CUtlArray &other) +{ + if (this != &other) + { + for (size_t n = 0; n < MAX_SIZE; n++) + m_Memory[n] = other.m_Memory[n]; + } + + return *this; +} + +template +inline CUtlArray::CUtlArray(CUtlArray const &vec) +{ + for (size_t n = 0; n < MAX_SIZE; n++) + m_Memory[n] = vec.m_Memory[n]; +} + +template +inline T *CUtlArray::Base() +{ + return &m_Memory[0]; +} + +template +inline const T *CUtlArray::Base() const +{ + return &m_Memory[0]; +} + +// Element access +template +inline T &CUtlArray::operator[](int i) +{ + Assert(IsValidIndex(i)); + return m_Memory[i]; +} + +template +inline const T &CUtlArray::operator[](int i) const +{ + Assert(IsValidIndex(i)); + return m_Memory[i]; +} + +template +inline T &CUtlArray::Element(int i) +{ + Assert(IsValidIndex(i)); + return m_Memory[i]; +} + +template +inline const T &CUtlArray::Element(int i) const +{ + Assert(IsValidIndex(i)); + return m_Memory[i]; +} + +// Count +template +inline int CUtlArray::Count() const +{ + return (int)MAX_SIZE; +} + +template +inline int CUtlArray::NumAllocated() const +{ + return (int)MAX_SIZE; +} + +// Is element index valid? +template +inline bool CUtlArray::IsValidIndex(int i) const +{ + return (i >= 0) && (i < MAX_SIZE); +} + +// Returns in invalid index +template +inline int CUtlArray::InvalidIndex() +{ + return -1; +} + +template +void CUtlArray::CopyArray(const T *pArray, size_t count) +{ + Assert(count < MAX_SIZE); + + for (size_t n = 0; n < count; n++) + m_Memory[n] = pArray[n]; +} + +template +void CUtlArray::Clear() +{ + Q_memset(m_Memory, 0, MAX_SIZE * sizeof(T)); +} + +template +void CUtlArray::RemoveAll() +{ + Clear(); +} + +template +void CUtlArray::Swap(CUtlArray< T, MAX_SIZE> &vec) +{ + for (size_t n = 0; n < MAX_SIZE; n++) + SWAP(m_Memory[n], vec.m_Memory[n]); +} + +// Finds an element (element needs operator== defined) +template +int CUtlArray::Find(const T &src) const +{ + for (int i = 0; i < Count(); i++) + { + if (Element(i) == src) + return i; + } + + return -1; +} + +template +void CUtlArray::FillWithValue(const T &src) +{ + for (int i = 0; i < Count(); i++) + Element(i) = src; +} + +template +bool CUtlArray::HasElement(const T &src) const +{ + return (Find(src) >= 0); +}