Skip to content

Commit ed2abb3

Browse files
PirulaxStrixG
andauthored
Fix #1436: getValidPedModels() to include engineRequestModel skins as well (#1437)
* fixed * made changes as suggested by sbx * Apply suggestions from code review Co-authored-by: Nikita Obrekht <[email protected]>
1 parent b2b7ef9 commit ed2abb3

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

Client/mods/deathmatch/logic/CClientModel.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ class CClientModel
2828
CClientModel(CClientManager* pManager, int iModelID, eClientModelType eModelType);
2929
~CClientModel(void);
3030

31-
int GetModelID(void) { return m_iModelID; };
32-
eClientModelType GetModelType(void) { return m_eModelType; };
31+
int GetModelID(void) const { return m_iModelID; };
32+
eClientModelType GetModelType(void) const { return m_eModelType; };
3333
bool Allocate(void);
3434
bool Deallocate(void);
3535
void SetParentResource(CResource* pResource) { m_pParentResource = pResource; }
36-
CResource* GetParentResource(void) { return m_pParentResource; }
36+
CResource* GetParentResource(void) const { return m_pParentResource; }
3737

3838
protected:
3939
CClientManager* m_pManager;

Client/mods/deathmatch/logic/CClientModelManager.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ void CClientModelManager::RemoveAll(void)
3030
{
3131
Remove(m_Models[i]);
3232
}
33+
m_modelCount = 0;
3334
}
3435

3536
void CClientModelManager::Add(CClientModel* pModel)
@@ -40,13 +41,15 @@ void CClientModelManager::Add(CClientModel* pModel)
4041
return;
4142
}
4243
m_Models[pModel->GetModelID()] = pModel;
44+
m_modelCount++;
4345
}
4446

4547
bool CClientModelManager::Remove(CClientModel* pModel)
4648
{
4749
if (pModel && m_Models[pModel->GetModelID()] != nullptr)
4850
{
4951
m_Models[pModel->GetModelID()] = nullptr;
52+
m_modelCount--;
5053
return true;
5154
}
5255
return false;
@@ -74,6 +77,22 @@ CClientModel* CClientModelManager::FindModelByID(int iModelID)
7477
return nullptr;
7578
}
7679

80+
std::vector<CClientModel*> CClientModelManager::GetModelsByType(const eClientModelType type, const unsigned int minModelID)
81+
{
82+
std::vector<CClientModel*> found;
83+
found.reserve(m_modelCount);
84+
85+
for (int i = minModelID; i < MAX_MODEL_ID; i++)
86+
{
87+
CClientModel* model = m_Models[i];
88+
if (model && model->GetModelType() == type)
89+
{
90+
found.push_back(model);
91+
}
92+
}
93+
return found;
94+
}
95+
7796
void CClientModelManager::DeallocateModelsAllocatedByResource(CResource* pResource)
7897
{
7998
for (ushort i = 0; i < MAX_MODEL_ID; i++)

Client/mods/deathmatch/logic/CClientModelManager.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class CClientModelManager;
1313
#pragma once
1414

1515
#include <list>
16+
#include <vector>
1617
#include "CClientModel.h"
1718

1819
#define MAX_MODEL_ID 20000
@@ -34,8 +35,12 @@ class CClientModelManager
3435

3536
CClientModel* FindModelByID(int iModelID);
3637

38+
std::vector<CClientModel*> CClientModelManager::GetModelsByType(const eClientModelType type, const unsigned int minModelID = 0);
39+
40+
3741
void DeallocateModelsAllocatedByResource(CResource* pResource);
3842

3943
private:
4044
CClientModel* m_Models[MAX_MODEL_ID];
45+
unsigned int m_modelCount = 0;
4146
};

Client/mods/deathmatch/logic/lua/CLuaFunctionDefs.Util.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ int CLuaFunctionDefs::GetValidPedModels(lua_State* luaVM)
1414
{
1515
int iIndex = 0;
1616
lua_newtable(luaVM);
17+
18+
// Gather GTASA default skins
1719
for (int i = 0; i <= 312; i++)
1820
{
1921
if (CClientPlayerManager::IsValidModel(i))
@@ -24,6 +26,15 @@ int CLuaFunctionDefs::GetValidPedModels(lua_State* luaVM)
2426
}
2527
}
2628

29+
// Gather our custom skin model IDs allocated with engineRequestModel
30+
// (there might be some < 313 as well, and since we don't want duplicates, we start at 313, others are already included by the loop above)
31+
for (const CClientModel* model : m_pManager->GetModelManager()->GetModelsByType(eClientModelType::CCLIENTMODELPED, 313))
32+
{
33+
lua_pushnumber(luaVM, ++iIndex);
34+
lua_pushnumber(luaVM, model->GetModelID());
35+
lua_settable(luaVM, -3);
36+
}
37+
2738
return 1;
2839
}
2940

0 commit comments

Comments
 (0)