Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
TracerDS committed Jan 15, 2024
1 parent e2c1789 commit f401d77
Show file tree
Hide file tree
Showing 37 changed files with 1,784 additions and 1,874 deletions.
72 changes: 27 additions & 45 deletions Client/mods/deathmatch/logic/CClientPickupManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@
#include "StdInc.h"
#include <game/CPickups.h>

using std::list;

static const SFixedArray<unsigned short, 47> g_usWeaponModels = {{
static const SFixedArray<std::uint16_t, 47> g_usWeaponModels = {{
0, 331, 333, 334, 335, 336, 337, 338, 339, 341, // 9
321, 322, 323, 0, 325, 326, 342, 343, 344, 0, // 19
0, 0, 346, 347, 348, 349, 350, 351, 352, 353, // 29
355, 356, 372, 357, 358, 359, 360, 361, 362, 363, // 39
364, 365, 366, 367, 368, 369, 371 // 46
}};

unsigned int CClientPickupManager::m_uiPickupCount = 0;
std::uint32_t CClientPickupManager::m_uiPickupCount = 0;

CClientPickupManager::CClientPickupManager(CClientManager* pManager)
{
Expand All @@ -42,22 +40,17 @@ CClientPickup* CClientPickupManager::Get(ElementID ID)
// Grab the element with the given id. Check its type.
CClientEntity* pEntity = CElementIDs::GetElement(ID);
if (pEntity && pEntity->GetType() == CCLIENTPICKUP)
{
return static_cast<CClientPickup*>(pEntity);
}

return NULL;
return nullptr;
}

void CClientPickupManager::DeleteAll()
{
// Delete each pickup
m_bDontRemoveFromList = true;
list<CClientPickup*>::const_iterator iter = m_List.begin();
for (; iter != m_List.end(); iter++)
{
delete *iter;
}
for (const auto& pPickup : m_List)
delete pPickup;

m_bDontRemoveFromList = false;

Expand All @@ -67,14 +60,10 @@ void CClientPickupManager::DeleteAll()

bool CClientPickupManager::Exists(CClientPickup* pPickup)
{
list<CClientPickup*>::const_iterator iter = m_List.begin();
for (; iter != m_List.end(); iter++)
{
if (*iter == pPickup)
{
for (const auto& pEntry : m_List)
if (pEntry == pPickup)
return true;
}
}

return false;
}

Expand All @@ -84,62 +73,55 @@ void CClientPickupManager::SetPickupProcessingDisabled(bool bDisabled)
m_bPickupProcessingDisabled = bDisabled;
}

bool CClientPickupManager::IsValidPickupID(unsigned short usPickupID)
bool CClientPickupManager::IsValidPickupID(std::uint16_t usPickupID)
{
return (usPickupID > 0 && usPickupID != 13 && usPickupID != 19 && usPickupID != 20 && usPickupID != 21 && usPickupID <= 46 || usPickupID == 1240 ||
usPickupID == 1242);
}

bool CClientPickupManager::IsValidWeaponID(unsigned short usWeaponID)
bool CClientPickupManager::IsValidWeaponID(std::uint16_t usWeaponID)
{
return (usWeaponID > 0 && usWeaponID != 13 && usWeaponID != 19 && usWeaponID != 20 && usWeaponID != 21 && usWeaponID <= 46);
}

bool CClientPickupManager::IsPickupLimitReached()
{
// Max 600 pickups
return (m_uiPickupCount >= 64);
return m_uiPickupCount >= 64;
}

unsigned short CClientPickupManager::GetWeaponModel(unsigned int uiWeaponID)
std::uint16_t CClientPickupManager::GetWeaponModel(std::uint32_t uiWeaponID) noexcept
{
if (uiWeaponID <= 46)
{
return g_usWeaponModels[uiWeaponID];
}

return 0;
return uiWeaponID <= 46 ? g_usWeaponModels[uiWeaponID] : 0;
}

void CClientPickupManager::RemoveFromList(CClientPickup* pPickup)
{
if (!m_bDontRemoveFromList)
{
if (!m_List.empty())
m_List.remove(pPickup);
}
if (m_bDontRemoveFromList)
return;

if (!m_List.empty())
m_List.remove(pPickup);
}

void CClientPickupManager::RestreamPickups(unsigned short usModel)
void CClientPickupManager::RestreamPickups(std::uint16_t usModel)
{
for (std::list<CClientPickup*>::const_iterator iter = IterBegin(); iter != IterEnd(); iter++)
for (const auto& pPickup : m_List)
{
CClientPickup* pPickup = *iter;
if (!pPickup->IsStreamedIn() || pPickup->GetModel() != usModel)
continue;

if (pPickup->IsStreamedIn() && pPickup->GetModel() == usModel)
{
pPickup->StreamOutForABit();
}
pPickup->StreamOutForABit();
}
}

void CClientPickupManager::RestreamAllPickups()
{
for (auto& pPickup : m_List)
{
if (pPickup->IsStreamedIn())
{
pPickup->StreamOutForABit();
}
if (!pPickup->IsStreamedIn())
continue;

pPickup->StreamOutForABit();
}
}
25 changes: 14 additions & 11 deletions Client/mods/deathmatch/logic/CClientPickupManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,30 @@ class CClientPickupManager
friend class CClientPickup;

public:
unsigned int Count() { return static_cast<unsigned int>(m_List.size()); };
std::size_t Count() const noexcept { return m_List.size(); };
static CClientPickup* Get(ElementID ID);

void DeleteAll();
bool Exists(CClientPickup* pPickup);

std::list<CClientPickup*>::const_iterator IterBegin() { return m_List.begin(); };
std::list<CClientPickup*>::const_iterator IterEnd() { return m_List.end(); };
std::list<CClientPickup*>::iterator begin() noexcept { return m_List.begin(); };
std::list<CClientPickup*>::iterator end() noexcept { return m_List.end(); };

bool IsPickupProcessingDisabled() { return m_bPickupProcessingDisabled; };
std::list<CClientPickup*>::const_iterator begin() const noexcept { return m_List.cbegin(); };
std::list<CClientPickup*>::const_iterator end() const noexcept { return m_List.cend(); };

bool IsPickupProcessingDisabled() const noexcept { return m_bPickupProcessingDisabled; };
void SetPickupProcessingDisabled(bool bDisabled);

static bool IsValidPickupID(unsigned short usPickupID);
static bool IsValidWeaponID(unsigned short usWeaponID);
static bool IsValidPickupID(std::uint16_t usPickupID);
static bool IsValidWeaponID(std::uint16_t usWeaponID);

static unsigned short GetWeaponModel(unsigned int uiWeaponID);
static unsigned short GetHealthModel() { return 1240; };
static unsigned short GetArmorModel() { return 1242; };
static std::uint16_t GetWeaponModel(std::uint32_t uiWeaponID) noexcept;
constexpr static std::uint16_t GetHealthModel() noexcept { return 1240; };
constexpr static std::uint16_t GetArmorModel() noexcept { return 1242; };

static bool IsPickupLimitReached();
void RestreamPickups(unsigned short usModel);
void RestreamPickups(std::uint16_t usModel);
void RestreamAllPickups();

private:
Expand All @@ -57,5 +60,5 @@ class CClientPickupManager
bool m_bDontRemoveFromList;

bool m_bPickupProcessingDisabled;
static unsigned int m_uiPickupCount;
static std::uint32_t m_uiPickupCount;
};
7 changes: 5 additions & 2 deletions Server/core/CExceptionInformation_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ void CExceptionInformation_Impl::Set(unsigned int iCode, _EXCEPTION_POINTERS* pE
*
* @return <code>true</code> if successful, <code>false</code> otherwise.
*/
bool CExceptionInformation_Impl::GetModule(char* szOutputBuffer, int nOutputNameLength, void** ppModuleBaseAddress)
{
bool CExceptionInformation_Impl::GetModule(
char* szOutputBuffer,
int nOutputNameLength,
void** ppModuleBaseAddress
) const noexcept {
HMODULE hModule;

if (!szOutputBuffer)
Expand Down
2 changes: 1 addition & 1 deletion Server/core/CExceptionInformation_Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CExceptionInformation_Impl : public CExceptionInformation

std::uint32_t GetCode() const noexcept { return m_uiCode; };
void* GetAddress() const noexcept { return m_pAddress; };
bool GetModule(char* szModuleName, int nOutputNameLength, void** ppModuleBaseAddress);
bool GetModule(char* szModuleName, int nOutputNameLength, void** ppModuleBaseAddress) const noexcept;
virtual const char* GetModulePathName() const noexcept { return m_szModulePathName; };
virtual const char* GetModuleBaseName() const noexcept { return m_szModuleBaseName; };
virtual std::uint32_t GetAddressModuleOffset() const noexcept { return m_uiAddressModuleOffset; };
Expand Down
2 changes: 1 addition & 1 deletion Server/core/CModManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ bool CModManagerImpl::RequestLoad(const char* szModName)
return false;
}

SString CModManagerImpl::GetAbsolutePath(const char* szRelative)
SString CModManagerImpl::GetAbsolutePath(const char* szRelative) const noexcept
{
return SString("%s/%s", m_strModPath.c_str(), szRelative);
}
Expand Down
2 changes: 1 addition & 1 deletion Server/core/CModManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CModManagerImpl : public CModManager

const char* GetServerPath() const noexcept { return m_strServerPath; };
const char* GetModPath() const noexcept { return m_strModPath; };
virtual SString GetAbsolutePath(const char* szRelative);
virtual SString GetAbsolutePath(const char* szRelative) const noexcept;

bool IsModLoaded() const noexcept;
CServerBase* GetCurrentMod();
Expand Down
2 changes: 1 addition & 1 deletion Server/core/CServerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ CXML* CServerImpl::GetXML()
return m_pXML;
}

SString CServerImpl::GetAbsolutePath(const char* szRelative)
SString CServerImpl::GetAbsolutePath(const char* szRelative) const noexcept
{
return PathJoin(m_strServerPath, szRelative);
}
Expand Down
4 changes: 2 additions & 2 deletions Server/core/CServerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class CServerImpl : public CServerInterface
CModManager* GetModManager();
CXML* GetXML();

const char* GetServerModPath() { return m_strServerModPath; };
SString GetAbsolutePath(const char* szRelative);
const char* GetServerModPath() const noexcept { return m_strServerModPath; };
SString GetAbsolutePath(const char* szRelative) const noexcept;

void Printf(const char* szText, ...);
bool IsRequestingExit();
Expand Down
16 changes: 8 additions & 8 deletions Server/dbconmy/CDatabaseConnectionMySql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ class CDatabaseConnectionMySql : public CDatabaseConnection

// CDatabaseConnection
virtual bool IsValid() const noexcept;
virtual const SString& GetLastErrorMessage();
virtual uint GetLastErrorCode() const noexcept;
virtual const SString& GetLastErrorMessage() const noexcept;
virtual std::uint32_t GetLastErrorCode() const noexcept;
virtual void AddRef();
virtual void Release();
virtual bool Query(const SString& strQuery, CRegistryResult& registryResult);
virtual void Flush();
virtual int GetShareCount() const noexcept { return m_iRefCount; }

// CDatabaseConnectionMySql
void SetLastError(uint uiCode, const SString& strMessage);
void SetLastError(std::uint32_t uiCode, const SString& strMessage);
bool QueryInternal(const SString& strQuery, CRegistryResult& registryResult);
void BeginAutomaticTransaction();
void EndAutomaticTransaction();
Expand All @@ -50,7 +50,7 @@ class CDatabaseConnectionMySql : public CDatabaseConnection
MYSQL* m_handle;
bool m_bOpened;
SString m_strLastErrorMessage;
uint m_uiLastErrorCode;
std::uint32_t m_uiLastErrorCode;
int m_bAutomaticReconnect;
int m_bAutomaticTransactionsEnabled;
bool m_bInAutomaticTransaction;
Expand Down Expand Up @@ -191,7 +191,7 @@ bool CDatabaseConnectionMySql::IsValid() const noexcept
// Only valid when IsValid() or Query() returns false
//
///////////////////////////////////////////////////////////////
const SString& CDatabaseConnectionMySql::GetLastErrorMessage()
const SString& CDatabaseConnectionMySql::GetLastErrorMessage() const noexcept
{
return m_strLastErrorMessage;
}
Expand All @@ -203,7 +203,7 @@ const SString& CDatabaseConnectionMySql::GetLastErrorMessage()
// Only valid when IsValid() or Query() returns false
//
///////////////////////////////////////////////////////////////
uint CDatabaseConnectionMySql::GetLastErrorCode() const noexcept
std::uint32_t CDatabaseConnectionMySql::GetLastErrorCode() const noexcept
{
return m_uiLastErrorCode;
}
Expand All @@ -215,7 +215,7 @@ uint CDatabaseConnectionMySql::GetLastErrorCode() const noexcept
//
//
///////////////////////////////////////////////////////////////
void CDatabaseConnectionMySql::SetLastError(uint uiCode, const SString& strMessage)
void CDatabaseConnectionMySql::SetLastError(std::uint32_t uiCode, const SString& strMessage)
{
m_uiLastErrorCode = uiCode;
m_strLastErrorMessage = strMessage;
Expand Down Expand Up @@ -257,7 +257,7 @@ bool CDatabaseConnectionMySql::QueryInternal(const SString& strQuery, CRegistryR
{
MYSQL_RES* res = mysql_store_result(m_handle);

pResult->uiNumAffectedRows = static_cast<uint>(mysql_affected_rows(m_handle));
pResult->uiNumAffectedRows = static_cast<std::uint32_t>(mysql_affected_rows(m_handle));
pResult->ullLastInsertId = mysql_insert_id(m_handle);

if (res)
Expand Down
Loading

0 comments on commit f401d77

Please sign in to comment.