Skip to content

Commit 5698387

Browse files
committed
Some basic progress
1 parent da49960 commit 5698387

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1129
-466
lines changed

Client/game_sa/CModelInfoSA.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ void CModelInfoSA::SetCustomModel(RpClump* pClump)
12421242
return pGame->GetRenderWare()->ReplaceWeaponModel(pClump, static_cast<unsigned short>(m_dwModelID));
12431243
case eModelInfoType::VEHICLE:
12441244
return pGame->GetRenderWare()->ReplaceVehicleModel(pClump, static_cast<unsigned short>(m_dwModelID));
1245-
case eModelInfoType::ATOMIC:
1245+
case eModelInfoType::OBJECT:
12461246
case eModelInfoType::LOD_ATOMIC:
12471247
case eModelInfoType::TIME:
12481248
return pGame->GetRenderWare()->ReplaceAllAtomicsInModel(pClump, static_cast<unsigned short>(m_dwModelID));
@@ -1518,7 +1518,7 @@ void CModelInfoSA::DeallocateModel(void)
15181518
case eModelInfoType::PED:
15191519
delete reinterpret_cast<CPedModelInfoSAInterface*>(ppModelInfo[m_dwModelID]);
15201520
break;
1521-
case eModelInfoType::ATOMIC:
1521+
case eModelInfoType::OBJECT:
15221522
delete reinterpret_cast<CBaseModelInfoSAInterface*>(ppModelInfo[m_dwModelID]);
15231523
break;
15241524
default:

Client/mods/deathmatch/logic/CClientModel.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include "StdInc.h"
1212

13-
CClientModel::CClientModel(CClientManager* pManager, int iModelID, eClientModelType eModelType)
13+
CClientModel::CClientModel(CClientManager* pManager, int iModelID, eModelInfoType eModelType)
1414
{
1515
m_pManager = pManager;
1616
m_iModelID = iModelID;
@@ -40,17 +40,17 @@ bool CClientModel::Allocate(ushort usParentID)
4040

4141
switch (m_eModelType)
4242
{
43-
case eClientModelType::PED:
43+
case eModelInfoType::PED:
4444
pModelInfo->MakePedModel("PSYCHO");
4545
return true;
46-
case eClientModelType::OBJECT:
46+
case eModelInfoType::OBJECT:
4747
if (g_pClientGame->GetObjectManager()->IsValidModel(usParentID))
4848
{
4949
pModelInfo->MakeObjectModel(usParentID);
5050
return true;
5151
}
5252
break;
53-
case eClientModelType::VEHICLE:
53+
case eModelInfoType::VEHICLE:
5454
if (g_pClientGame->GetVehicleManager()->IsValidModel(usParentID))
5555
{
5656
pModelInfo->MakeVehicleAutomobile(usParentID);
@@ -99,15 +99,15 @@ void CClientModel::RestoreEntitiesUsingThisModel()
9999

100100
switch (m_eModelType)
101101
{
102-
case eClientModelType::PED:
102+
case eModelInfoType::PED:
103103
{
104104
// If some ped is using this ID, change him to CJ
105105
CClientPedManager* pPedManager = g_pClientGame->GetManager()->GetPedManager();
106106

107107
unloadModelsAndCallEvents(pPedManager->IterBegin(), pPedManager->IterEnd(), 0, [](auto& element) { element.SetModel(0); });
108108
break;
109109
}
110-
case eClientModelType::OBJECT:
110+
case eModelInfoType::OBJECT:
111111
{
112112
const auto& objects = &g_pClientGame->GetManager()->GetObjectManager()->GetObjects();
113113
unsigned short usParentID = g_pGame->GetModelInfo(m_iModelID)->GetParentID();
@@ -123,7 +123,7 @@ void CClientModel::RestoreEntitiesUsingThisModel()
123123
g_pClientGame->GetManager()->GetColModelManager()->RestoreModel(m_iModelID);
124124
break;
125125
}
126-
case eClientModelType::VEHICLE:
126+
case eModelInfoType::VEHICLE:
127127
{
128128
CClientVehicleManager* pVehicleManager = g_pClientGame->GetManager()->GetVehicleManager();
129129
unsigned short usParentID = g_pGame->GetModelInfo(m_iModelID)->GetParentID();

Client/mods/deathmatch/logic/CClientModel.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@ class CClientModel;
1414

1515
#include <list>
1616

17-
enum class eClientModelType
18-
{
19-
PED,
20-
OBJECT,
21-
VEHICLE,
22-
};
23-
2417
class CResource;
2518
class CClientManager;
2619

@@ -29,11 +22,11 @@ class CClientModel final
2922
friend class CClientModelManager;
3023

3124
public:
32-
CClientModel(CClientManager* pManager, int iModelID, eClientModelType eModelType);
25+
CClientModel(CClientManager* pManager, int iModelID, eModelInfoType eModelType);
3326
~CClientModel(void);
3427

3528
int GetModelID(void) const { return m_iModelID; };
36-
eClientModelType GetModelType(void) const { return m_eModelType; };
29+
eModelInfoType GetModelType(void) const { return m_eModelType; };
3730
bool Allocate(ushort usParentID);
3831
bool Deallocate(void);
3932
void RestoreEntitiesUsingThisModel();
@@ -44,7 +37,7 @@ class CClientModel final
4437
CClientManager* m_pManager;
4538

4639
int m_iModelID;
47-
eClientModelType m_eModelType;
40+
eModelInfoType m_eModelType;
4841
bool m_bAllocatedByUs = false;
4942
CResource* m_pParentResource = nullptr; // Resource that allocated model
5043
};

Client/mods/deathmatch/logic/CClientModelManager.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ std::shared_ptr<CClientModel> CClientModelManager::FindModelByID(int iModelID)
8383
return nullptr;
8484
}
8585

86-
std::vector<std::shared_ptr<CClientModel>> CClientModelManager::GetModelsByType(eClientModelType type, const unsigned int minModelID)
86+
std::vector<std::shared_ptr<CClientModel>> CClientModelManager::GetModelsByType(eModelInfoType type, const unsigned int minModelID)
8787
{
8888
std::vector<std::shared_ptr<CClientModel>> found;
8989
found.reserve(m_modelCount);
@@ -109,3 +109,19 @@ void CClientModelManager::DeallocateModelsAllocatedByResource(CResource* pResour
109109
Remove(m_Models[i]);
110110
}
111111
}
112+
113+
void CClientModelManager::AllocateModelFromParent(uint32_t uiNewModelID, uint32_t uiParentModelID)
114+
{
115+
eModelInfoType eModelType = g_pGame->GetModelInfo(uiParentModelID)->GetModelType();
116+
117+
std::shared_ptr<CClientModel> pModel = FindModelByID(uiNewModelID);
118+
if (pModel == nullptr)
119+
pModel = std::make_shared<CClientModel>(g_pClientGame->GetManager(), uiNewModelID, eModelType);
120+
121+
Add(pModel);
122+
123+
if (pModel->Allocate(uiParentModelID))
124+
return;
125+
126+
assert("Can not allocateModel");
127+
}

Client/mods/deathmatch/logic/CClientModelManager.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ class CClientModelManager
3434

3535
std::shared_ptr<CClientModel> FindModelByID(int iModelID);
3636

37-
std::vector<std::shared_ptr<CClientModel>> GetModelsByType(eClientModelType type, const unsigned int minModelID = 0);
37+
std::vector<std::shared_ptr<CClientModel>> GetModelsByType(eModelInfoType type, const unsigned int minModelID = 0);
3838

3939
void DeallocateModelsAllocatedByResource(CResource* pResource);
40+
void AllocateModelFromParent(uint32_t usModelID, uint32_t usParentModel);
41+
4042

4143
private:
4244
std::unique_ptr<std::shared_ptr<CClientModel>[]> m_Models;

Client/mods/deathmatch/logic/CClientObjectManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ bool CClientObjectManager::IsValidModel(unsigned long ulObjectModel)
110110
return false;
111111

112112
eModelInfoType eType = pModelInfo->GetModelType();
113-
return (eType == eModelInfoType::CLUMP || eType == eModelInfoType::ATOMIC || eType == eModelInfoType::WEAPON || eType == eModelInfoType::TIME);
113+
return (eType == eModelInfoType::CLUMP || eType == eModelInfoType::OBJECT || eType == eModelInfoType::WEAPON || eType == eModelInfoType::TIME);
114114
}
115115

116116
bool CClientObjectManager::IsBreakableModel(unsigned long ulObjectModel)

Client/mods/deathmatch/logic/CPacketHandler.cpp

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,19 @@ void CPacketHandler::Packet_ServerJoined(NetBitStreamInterface& bitStream)
409409
bitStream.ReadString(strExternalHTTPDownloadURL);
410410
}
411411

412+
if (bitStream.Can(eBitStreamVersion::SimpleModelAllocationg))
413+
{
414+
uint32_t modelsCount = 0;
415+
bitStream.Read(modelsCount);
416+
for (int i = 0; i < modelsCount; i++)
417+
{
418+
uint32_t usModelID, usParentID;
419+
bitStream.Read(usModelID);
420+
bitStream.Read(usParentID);
421+
g_pClientGame->GetManager()->GetModelManager()->AllocateModelFromParent(usModelID, usParentID);
422+
}
423+
}
424+
412425
//
413426
// Add servers to use
414427
//
@@ -3186,17 +3199,27 @@ void CPacketHandler::Packet_EntityAdd(NetBitStreamInterface& bitStream)
31863199
bitStream.Read(&rotationDegrees);
31873200

31883201
// Read out the vehicle value as a char, then convert
3189-
unsigned char ucModel = 0xFF;
3190-
bitStream.Read(ucModel);
3191-
3192-
// The server appears to subtract 400 from the vehicle id before
3193-
// sending it to us, as to allow the value to fit into an unsigned
3194-
// char.
3195-
//
3196-
// Too bad this was never documented.
3197-
//
3198-
// --slush
3199-
unsigned short usModel = ucModel + 400;
3202+
unsigned short usModel = 0xFFFF;
3203+
3204+
if (bitStream.Can(eBitStreamVersion::SimpleModelAllocationg))
3205+
{
3206+
bitStream.Read(usModel);
3207+
}
3208+
else
3209+
{
3210+
// The server appears to subtract 400 from the vehicle id before
3211+
// sending it to us, as to allow the value to fit into an unsigned
3212+
// char.
3213+
//
3214+
// Too bad this was never documented.
3215+
//
3216+
// --slush
3217+
unsigned char ucModel = 0xFF;
3218+
3219+
bitStream.Read(ucModel);
3220+
unsigned short usModel = ucModel + 400;
3221+
}
3222+
32003223
if (!CClientVehicleManager::IsValidModel(usModel))
32013224
{
32023225
RaiseEntityAddError(39);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ int CLuaFunctionDefs::GetValidPedModels(lua_State* luaVM)
2828

2929
// Gather our custom skin model IDs allocated with engineRequestModel
3030
// (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 auto& model : m_pManager->GetModelManager()->GetModelsByType(eClientModelType::PED, 313))
31+
for (const auto& model : m_pManager->GetModelManager()->GetModelsByType(eModelInfoType::PED, 313))
3232
{
3333
lua_pushnumber(luaVM, ++iIndex);
3434
lua_pushnumber(luaVM, model->GetModelID());

Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -661,10 +661,10 @@ ADD_ENUM(SURFACE_ADHESION_GROUP_SAND, "sand")
661661
ADD_ENUM(SURFACE_ADHESION_GROUP_WET, "wet")
662662
IMPLEMENT_ENUM_END("surface-adhesion-group")
663663

664-
IMPLEMENT_ENUM_CLASS_BEGIN(eClientModelType)
665-
ADD_ENUM(eClientModelType::PED, "ped")
666-
ADD_ENUM(eClientModelType::OBJECT, "object")
667-
ADD_ENUM(eClientModelType::VEHICLE, "vehicle")
664+
IMPLEMENT_ENUM_CLASS_BEGIN(eModelInfoType)
665+
ADD_ENUM(eModelInfoType::PED, "ped")
666+
ADD_ENUM(eModelInfoType::OBJECT, "object")
667+
ADD_ENUM(eModelInfoType::VEHICLE, "vehicle")
668668
IMPLEMENT_ENUM_CLASS_END("client-model-type")
669669

670670
// Sound effects

Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ DECLARE_ENUM(eSurfaceBulletEffect);
6565
DECLARE_ENUM(eSurfaceWheelEffect);
6666
DECLARE_ENUM(eSurfaceSkidMarkType);
6767
DECLARE_ENUM(eSurfaceAdhesionGroup);
68-
DECLARE_ENUM_CLASS(eClientModelType);
68+
DECLARE_ENUM_CLASS(eModelInfoType);
6969
DECLARE_ENUM(eSoundEffectType);
7070
DECLARE_ENUM_CLASS(eSoundEffectParams::Chorus);
7171
DECLARE_ENUM_CLASS(eSoundEffectParams::Compressor);

Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ int CLuaEngineDefs::EngineRestoreModel(lua_State* luaVM)
580580

581581
int CLuaEngineDefs::EngineRequestModel(lua_State* luaVM)
582582
{
583-
eClientModelType eModelType;
583+
eModelInfoType eModelType;
584584

585585
CScriptArgReader argStream(luaVM);
586586
argStream.ReadEnumString(eModelType);
@@ -608,13 +608,13 @@ int CLuaEngineDefs::EngineRequestModel(lua_State* luaVM)
608608
{
609609
switch (eModelType)
610610
{
611-
case eClientModelType::PED:
611+
case eModelInfoType::PED:
612612
usParentID = 7; // male01
613613
break;
614-
case eClientModelType::OBJECT:
614+
case eModelInfoType::OBJECT:
615615
usParentID = 1337; // BinNt07_LA (trash can)
616616
break;
617-
case eClientModelType::VEHICLE:
617+
case eModelInfoType::VEHICLE:
618618
usParentID = VT_LANDSTAL;
619619
break;
620620
default:
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*****************************************************************************
2+
*
3+
* PROJECT: Multi Theft Auto v1.0
4+
* LICENSE: See LICENSE in the top level directory
5+
* FILE: mods/deathmatch/logic/rpc/CMarkerRPCs.cpp
6+
* PURPOSE: Marker remote procedure calls
7+
*
8+
* Multi Theft Auto is available from http://www.multitheftauto.com/
9+
*
10+
*****************************************************************************/
11+
12+
#include <StdInc.h>
13+
#include "CModelRPCs.h"
14+
15+
void CModelRPCs::LoadFunctions()
16+
{
17+
AddHandler(ALLOCATE_MODEL_FROM_PARENT, AllocateModelFromParent, "AllocateModelFromParent");
18+
}
19+
20+
void CModelRPCs::AllocateModelFromParent(NetBitStreamInterface& bitStream)
21+
{
22+
uint32_t uiNewModelID;
23+
uint32_t uiParentModelID;
24+
25+
if (bitStream.Read(uiNewModelID) && bitStream.Read(uiParentModelID))
26+
{
27+
m_pManager->GetModelManager()->AllocateModelFromParent(uiNewModelID, uiParentModelID);
28+
}
29+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*****************************************************************************
2+
*
3+
* PROJECT: Multi Theft Auto v1.0
4+
* LICENSE: See LICENSE in the top level directory
5+
* FILE: mods/deathmatch/logic/rpc/CMarkerRPCs.h
6+
* PURPOSE: Header for marker RPC class
7+
*
8+
* Multi Theft Auto is available from http://www.multitheftauto.com/
9+
*
10+
*****************************************************************************/
11+
12+
#pragma once
13+
14+
#include "CRPCFunctions.h"
15+
16+
class CModelRPCs : public CRPCFunctions
17+
{
18+
public:
19+
static void LoadFunctions();
20+
21+
DECLARE_RPC(AllocateModelFromParent);
22+
};

Client/mods/deathmatch/logic/rpc/CRPCFunctions.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "CWaterRPCs.h"
3232
#include "CWorldRPCs.h"
3333
#include "CColShapeRPCs.h"
34+
#include "CModelRPCs.h"
3435

3536
CClientManager* CRPCFunctions::m_pManager;
3637
CClientCamera* CRPCFunctions::m_pCamera;
@@ -100,6 +101,7 @@ void CRPCFunctions::AddHandlers()
100101
CWaterRPCs::LoadFunctions();
101102
CWorldRPCs::LoadFunctions();
102103
CColShapeRPCs::LoadFunctions();
104+
CModelRPCs::LoadFunctions();
103105
}
104106

105107
void CRPCFunctions::AddHandler(unsigned char ucID, pfnRPCHandler Callback, const char* szName)

Client/sdk/game/CModelInfo.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class CBoundingBox
3131

3232
enum class eModelInfoType : unsigned char
3333
{
34-
ATOMIC = 1,
34+
INVALID = 0,
35+
OBJECT = 1,
3536
TIME = 3,
3637
WEAPON = 4,
3738
CLUMP = 5,

Server/mods/deathmatch/StdInc.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ struct SAclRequest;
147147
#include "luadefs/CLuaVoiceDefs.h"
148148
#include "luadefs/CLuaWaterDefs.h"
149149
#include "luadefs/CLuaWorldDefs.h"
150+
#include "luadefs/CLuaModelDefs.h"
150151

151152
// Lua includes
152153
#include "lua/LuaCommon.h"
@@ -302,6 +303,14 @@ struct SAclRequest;
302303

303304
#include "CStaticFunctionDefinitions.h"
304305

306+
// Serverside model includes
307+
#include "models/CModelBase.h"
308+
#include "models/CModelAtomic.h"
309+
#include "models/CModelVehicle.h"
310+
#include "models/CModelManager.h"
311+
#include "models/CModelLoader.h"
312+
#include "models/CModelVehicle.h"
313+
305314
// Utility includes
306315
#include "utils/CZipMaker.h"
307316

0 commit comments

Comments
 (0)