Skip to content

Commit

Permalink
Some basic progress
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNormalnij committed May 10, 2022
1 parent da49960 commit 5698387
Show file tree
Hide file tree
Showing 42 changed files with 1,129 additions and 466 deletions.
4 changes: 2 additions & 2 deletions Client/game_sa/CModelInfoSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,7 @@ void CModelInfoSA::SetCustomModel(RpClump* pClump)
return pGame->GetRenderWare()->ReplaceWeaponModel(pClump, static_cast<unsigned short>(m_dwModelID));
case eModelInfoType::VEHICLE:
return pGame->GetRenderWare()->ReplaceVehicleModel(pClump, static_cast<unsigned short>(m_dwModelID));
case eModelInfoType::ATOMIC:
case eModelInfoType::OBJECT:
case eModelInfoType::LOD_ATOMIC:
case eModelInfoType::TIME:
return pGame->GetRenderWare()->ReplaceAllAtomicsInModel(pClump, static_cast<unsigned short>(m_dwModelID));
Expand Down Expand Up @@ -1518,7 +1518,7 @@ void CModelInfoSA::DeallocateModel(void)
case eModelInfoType::PED:
delete reinterpret_cast<CPedModelInfoSAInterface*>(ppModelInfo[m_dwModelID]);
break;
case eModelInfoType::ATOMIC:
case eModelInfoType::OBJECT:
delete reinterpret_cast<CBaseModelInfoSAInterface*>(ppModelInfo[m_dwModelID]);
break;
default:
Expand Down
14 changes: 7 additions & 7 deletions Client/mods/deathmatch/logic/CClientModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "StdInc.h"

CClientModel::CClientModel(CClientManager* pManager, int iModelID, eClientModelType eModelType)
CClientModel::CClientModel(CClientManager* pManager, int iModelID, eModelInfoType eModelType)
{
m_pManager = pManager;
m_iModelID = iModelID;
Expand Down Expand Up @@ -40,17 +40,17 @@ bool CClientModel::Allocate(ushort usParentID)

switch (m_eModelType)
{
case eClientModelType::PED:
case eModelInfoType::PED:
pModelInfo->MakePedModel("PSYCHO");
return true;
case eClientModelType::OBJECT:
case eModelInfoType::OBJECT:
if (g_pClientGame->GetObjectManager()->IsValidModel(usParentID))
{
pModelInfo->MakeObjectModel(usParentID);
return true;
}
break;
case eClientModelType::VEHICLE:
case eModelInfoType::VEHICLE:
if (g_pClientGame->GetVehicleManager()->IsValidModel(usParentID))
{
pModelInfo->MakeVehicleAutomobile(usParentID);
Expand Down Expand Up @@ -99,15 +99,15 @@ void CClientModel::RestoreEntitiesUsingThisModel()

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

unloadModelsAndCallEvents(pPedManager->IterBegin(), pPedManager->IterEnd(), 0, [](auto& element) { element.SetModel(0); });
break;
}
case eClientModelType::OBJECT:
case eModelInfoType::OBJECT:
{
const auto& objects = &g_pClientGame->GetManager()->GetObjectManager()->GetObjects();
unsigned short usParentID = g_pGame->GetModelInfo(m_iModelID)->GetParentID();
Expand All @@ -123,7 +123,7 @@ void CClientModel::RestoreEntitiesUsingThisModel()
g_pClientGame->GetManager()->GetColModelManager()->RestoreModel(m_iModelID);
break;
}
case eClientModelType::VEHICLE:
case eModelInfoType::VEHICLE:
{
CClientVehicleManager* pVehicleManager = g_pClientGame->GetManager()->GetVehicleManager();
unsigned short usParentID = g_pGame->GetModelInfo(m_iModelID)->GetParentID();
Expand Down
13 changes: 3 additions & 10 deletions Client/mods/deathmatch/logic/CClientModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ class CClientModel;

#include <list>

enum class eClientModelType
{
PED,
OBJECT,
VEHICLE,
};

class CResource;
class CClientManager;

Expand All @@ -29,11 +22,11 @@ class CClientModel final
friend class CClientModelManager;

public:
CClientModel(CClientManager* pManager, int iModelID, eClientModelType eModelType);
CClientModel(CClientManager* pManager, int iModelID, eModelInfoType eModelType);
~CClientModel(void);

int GetModelID(void) const { return m_iModelID; };
eClientModelType GetModelType(void) const { return m_eModelType; };
eModelInfoType GetModelType(void) const { return m_eModelType; };
bool Allocate(ushort usParentID);
bool Deallocate(void);
void RestoreEntitiesUsingThisModel();
Expand All @@ -44,7 +37,7 @@ class CClientModel final
CClientManager* m_pManager;

int m_iModelID;
eClientModelType m_eModelType;
eModelInfoType m_eModelType;
bool m_bAllocatedByUs = false;
CResource* m_pParentResource = nullptr; // Resource that allocated model
};
18 changes: 17 additions & 1 deletion Client/mods/deathmatch/logic/CClientModelManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ std::shared_ptr<CClientModel> CClientModelManager::FindModelByID(int iModelID)
return nullptr;
}

std::vector<std::shared_ptr<CClientModel>> CClientModelManager::GetModelsByType(eClientModelType type, const unsigned int minModelID)
std::vector<std::shared_ptr<CClientModel>> CClientModelManager::GetModelsByType(eModelInfoType type, const unsigned int minModelID)
{
std::vector<std::shared_ptr<CClientModel>> found;
found.reserve(m_modelCount);
Expand All @@ -109,3 +109,19 @@ void CClientModelManager::DeallocateModelsAllocatedByResource(CResource* pResour
Remove(m_Models[i]);
}
}

void CClientModelManager::AllocateModelFromParent(uint32_t uiNewModelID, uint32_t uiParentModelID)
{
eModelInfoType eModelType = g_pGame->GetModelInfo(uiParentModelID)->GetModelType();

std::shared_ptr<CClientModel> pModel = FindModelByID(uiNewModelID);
if (pModel == nullptr)
pModel = std::make_shared<CClientModel>(g_pClientGame->GetManager(), uiNewModelID, eModelType);

Add(pModel);

if (pModel->Allocate(uiParentModelID))
return;

assert("Can not allocateModel");
}
4 changes: 3 additions & 1 deletion Client/mods/deathmatch/logic/CClientModelManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ class CClientModelManager

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

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

void DeallocateModelsAllocatedByResource(CResource* pResource);
void AllocateModelFromParent(uint32_t usModelID, uint32_t usParentModel);


private:
std::unique_ptr<std::shared_ptr<CClientModel>[]> m_Models;
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CClientObjectManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ bool CClientObjectManager::IsValidModel(unsigned long ulObjectModel)
return false;

eModelInfoType eType = pModelInfo->GetModelType();
return (eType == eModelInfoType::CLUMP || eType == eModelInfoType::ATOMIC || eType == eModelInfoType::WEAPON || eType == eModelInfoType::TIME);
return (eType == eModelInfoType::CLUMP || eType == eModelInfoType::OBJECT || eType == eModelInfoType::WEAPON || eType == eModelInfoType::TIME);
}

bool CClientObjectManager::IsBreakableModel(unsigned long ulObjectModel)
Expand Down
45 changes: 34 additions & 11 deletions Client/mods/deathmatch/logic/CPacketHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,19 @@ void CPacketHandler::Packet_ServerJoined(NetBitStreamInterface& bitStream)
bitStream.ReadString(strExternalHTTPDownloadURL);
}

if (bitStream.Can(eBitStreamVersion::SimpleModelAllocationg))
{
uint32_t modelsCount = 0;
bitStream.Read(modelsCount);
for (int i = 0; i < modelsCount; i++)
{
uint32_t usModelID, usParentID;
bitStream.Read(usModelID);
bitStream.Read(usParentID);
g_pClientGame->GetManager()->GetModelManager()->AllocateModelFromParent(usModelID, usParentID);
}
}

//
// Add servers to use
//
Expand Down Expand Up @@ -3186,17 +3199,27 @@ void CPacketHandler::Packet_EntityAdd(NetBitStreamInterface& bitStream)
bitStream.Read(&rotationDegrees);

// Read out the vehicle value as a char, then convert
unsigned char ucModel = 0xFF;
bitStream.Read(ucModel);

// The server appears to subtract 400 from the vehicle id before
// sending it to us, as to allow the value to fit into an unsigned
// char.
//
// Too bad this was never documented.
//
// --slush
unsigned short usModel = ucModel + 400;
unsigned short usModel = 0xFFFF;

if (bitStream.Can(eBitStreamVersion::SimpleModelAllocationg))
{
bitStream.Read(usModel);
}
else
{
// The server appears to subtract 400 from the vehicle id before
// sending it to us, as to allow the value to fit into an unsigned
// char.
//
// Too bad this was never documented.
//
// --slush
unsigned char ucModel = 0xFF;

bitStream.Read(ucModel);
unsigned short usModel = ucModel + 400;
}

if (!CClientVehicleManager::IsValidModel(usModel))
{
RaiseEntityAddError(39);
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/lua/CLuaFunctionDefs.Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int CLuaFunctionDefs::GetValidPedModels(lua_State* luaVM)

// Gather our custom skin model IDs allocated with engineRequestModel
// (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)
for (const auto& model : m_pManager->GetModelManager()->GetModelsByType(eClientModelType::PED, 313))
for (const auto& model : m_pManager->GetModelManager()->GetModelsByType(eModelInfoType::PED, 313))
{
lua_pushnumber(luaVM, ++iIndex);
lua_pushnumber(luaVM, model->GetModelID());
Expand Down
8 changes: 4 additions & 4 deletions Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,10 +661,10 @@ ADD_ENUM(SURFACE_ADHESION_GROUP_SAND, "sand")
ADD_ENUM(SURFACE_ADHESION_GROUP_WET, "wet")
IMPLEMENT_ENUM_END("surface-adhesion-group")

IMPLEMENT_ENUM_CLASS_BEGIN(eClientModelType)
ADD_ENUM(eClientModelType::PED, "ped")
ADD_ENUM(eClientModelType::OBJECT, "object")
ADD_ENUM(eClientModelType::VEHICLE, "vehicle")
IMPLEMENT_ENUM_CLASS_BEGIN(eModelInfoType)
ADD_ENUM(eModelInfoType::PED, "ped")
ADD_ENUM(eModelInfoType::OBJECT, "object")
ADD_ENUM(eModelInfoType::VEHICLE, "vehicle")
IMPLEMENT_ENUM_CLASS_END("client-model-type")

// Sound effects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ DECLARE_ENUM(eSurfaceBulletEffect);
DECLARE_ENUM(eSurfaceWheelEffect);
DECLARE_ENUM(eSurfaceSkidMarkType);
DECLARE_ENUM(eSurfaceAdhesionGroup);
DECLARE_ENUM_CLASS(eClientModelType);
DECLARE_ENUM_CLASS(eModelInfoType);
DECLARE_ENUM(eSoundEffectType);
DECLARE_ENUM_CLASS(eSoundEffectParams::Chorus);
DECLARE_ENUM_CLASS(eSoundEffectParams::Compressor);
Expand Down
8 changes: 4 additions & 4 deletions Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ int CLuaEngineDefs::EngineRestoreModel(lua_State* luaVM)

int CLuaEngineDefs::EngineRequestModel(lua_State* luaVM)
{
eClientModelType eModelType;
eModelInfoType eModelType;

CScriptArgReader argStream(luaVM);
argStream.ReadEnumString(eModelType);
Expand Down Expand Up @@ -608,13 +608,13 @@ int CLuaEngineDefs::EngineRequestModel(lua_State* luaVM)
{
switch (eModelType)
{
case eClientModelType::PED:
case eModelInfoType::PED:
usParentID = 7; // male01
break;
case eClientModelType::OBJECT:
case eModelInfoType::OBJECT:
usParentID = 1337; // BinNt07_LA (trash can)
break;
case eClientModelType::VEHICLE:
case eModelInfoType::VEHICLE:
usParentID = VT_LANDSTAL;
break;
default:
Expand Down
29 changes: 29 additions & 0 deletions Client/mods/deathmatch/logic/rpc/CModelRPCs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto v1.0
* LICENSE: See LICENSE in the top level directory
* FILE: mods/deathmatch/logic/rpc/CMarkerRPCs.cpp
* PURPOSE: Marker remote procedure calls
*
* Multi Theft Auto is available from http://www.multitheftauto.com/
*
*****************************************************************************/

#include <StdInc.h>
#include "CModelRPCs.h"

void CModelRPCs::LoadFunctions()
{
AddHandler(ALLOCATE_MODEL_FROM_PARENT, AllocateModelFromParent, "AllocateModelFromParent");
}

void CModelRPCs::AllocateModelFromParent(NetBitStreamInterface& bitStream)
{
uint32_t uiNewModelID;
uint32_t uiParentModelID;

if (bitStream.Read(uiNewModelID) && bitStream.Read(uiParentModelID))
{
m_pManager->GetModelManager()->AllocateModelFromParent(uiNewModelID, uiParentModelID);
}
}
22 changes: 22 additions & 0 deletions Client/mods/deathmatch/logic/rpc/CModelRPCs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto v1.0
* LICENSE: See LICENSE in the top level directory
* FILE: mods/deathmatch/logic/rpc/CMarkerRPCs.h
* PURPOSE: Header for marker RPC class
*
* Multi Theft Auto is available from http://www.multitheftauto.com/
*
*****************************************************************************/

#pragma once

#include "CRPCFunctions.h"

class CModelRPCs : public CRPCFunctions
{
public:
static void LoadFunctions();

DECLARE_RPC(AllocateModelFromParent);
};
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/rpc/CRPCFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "CWaterRPCs.h"
#include "CWorldRPCs.h"
#include "CColShapeRPCs.h"
#include "CModelRPCs.h"

CClientManager* CRPCFunctions::m_pManager;
CClientCamera* CRPCFunctions::m_pCamera;
Expand Down Expand Up @@ -100,6 +101,7 @@ void CRPCFunctions::AddHandlers()
CWaterRPCs::LoadFunctions();
CWorldRPCs::LoadFunctions();
CColShapeRPCs::LoadFunctions();
CModelRPCs::LoadFunctions();
}

void CRPCFunctions::AddHandler(unsigned char ucID, pfnRPCHandler Callback, const char* szName)
Expand Down
3 changes: 2 additions & 1 deletion Client/sdk/game/CModelInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class CBoundingBox

enum class eModelInfoType : unsigned char
{
ATOMIC = 1,
INVALID = 0,
OBJECT = 1,
TIME = 3,
WEAPON = 4,
CLUMP = 5,
Expand Down
9 changes: 9 additions & 0 deletions Server/mods/deathmatch/StdInc.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ struct SAclRequest;
#include "luadefs/CLuaVoiceDefs.h"
#include "luadefs/CLuaWaterDefs.h"
#include "luadefs/CLuaWorldDefs.h"
#include "luadefs/CLuaModelDefs.h"

// Lua includes
#include "lua/LuaCommon.h"
Expand Down Expand Up @@ -302,6 +303,14 @@ struct SAclRequest;

#include "CStaticFunctionDefinitions.h"

// Serverside model includes
#include "models/CModelBase.h"
#include "models/CModelAtomic.h"
#include "models/CModelVehicle.h"
#include "models/CModelManager.h"
#include "models/CModelLoader.h"
#include "models/CModelVehicle.h"

// Utility includes
#include "utils/CZipMaker.h"

Expand Down
Loading

0 comments on commit 5698387

Please sign in to comment.