-
-
Notifications
You must be signed in to change notification settings - Fork 454
/
Copy pathCLuaModelDefs.cpp
93 lines (78 loc) · 3.3 KB
/
CLuaModelDefs.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*****************************************************************************
*
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: mods/shared_logic/luadefs/CLuaModelDefs.cpp
* PURPOSE: Lua model definitions class
*
* Multi Theft Auto is available from http://www.multitheftauto.com/
*
*****************************************************************************/
#include "StdInc.h"
#include <lua/CLuaFunctionParser.h>
#include "CLodModels.h"
#include "CClientObjectManager.h"
#include "CClientBuildingManager.h"
void CLuaModelDefs::LoadFunctions()
{
constexpr static const std::pair<const char*, lua_CFunction> functions[]{
// Util func
{"isValidModel", ArgumentParser<IsValidModel>},
// LOD funcs
{"getModelLowLOD", ArgumentParser<GetModelLowLOD>},
{"getModelHighLOD", ArgumentParser<GetModelHighLOD>},
{"setModelLOD", ArgumentParser<SetModelLOD>},
{"resetModelLODByHigh", ArgumentParser<ResetModelLODByHigh>},
{"resetModelLODByLow", ArgumentParser<ResetModelLODByLow>},
{"resetAllModelLOD", ArgumentParser<ResetAllModelLOD>},
};
// Add functions
for (const auto& [name, func] : functions)
CLuaCFunctions::AddFunction(name, func);
}
bool CLuaModelDefs::IsValidModel(std::string modelPurpose, std::uint32_t id)
{
if (modelPurpose == "object")
return CClientObjectManager::IsValidModel(id);
else if (modelPurpose == "weapon")
return CClientPedManager::IsValidWeaponModel(id);
else if (modelPurpose == "upgrade")
return CVehicleUpgrades::IsUpgrade(id);
else if (modelPurpose == "building")
return CClientBuildingManager::IsValidModel(id);
else if (modelPurpose == "vehicle")
return CClientVehicleManager::IsValidModel(id);
else if (modelPurpose == "ped" || modelPurpose == "player")
return CClientPlayerManager::IsValidModel(id);
throw std::invalid_argument("Invalid model purpose passed, expected [object, weapon, upgrade, building, vehicle, ped, player]");
}
std::variant<bool, std::uint32_t> CLuaModelDefs::GetModelLowLOD(std::uint32_t hLODModel) noexcept
{
return CLodModels::GetModelLowLOD(hLODModel);
}
std::variant<bool, std::uint32_t> CLuaModelDefs::GetModelHighLOD(std::uint32_t lLODModel) noexcept
{
return CLodModels::GetModelHighLOD(lLODModel);
}
bool CLuaModelDefs::SetModelLOD(std::string modelPurpose, std::uint32_t hLODModel, std::uint32_t lLODModel)
{
if (!(modelPurpose == "object" || modelPurpose == "building"))
throw std::invalid_argument("Invalid model purpose passed, the only options for LOD are 'object' or 'building'");
if (!IsValidModel(modelPurpose, hLODModel))
throw std::invalid_argument("Invalid High-LOD model ID passed");
if (!IsValidModel(modelPurpose, lLODModel))
throw std::invalid_argument("Invalid Low-LOD model ID passed");
return CLodModels::SetModelLOD(hLODModel, lLODModel);
}
bool CLuaModelDefs::ResetModelLODByHigh(std::uint32_t hLODModel) noexcept
{
return CLodModels::ResetModelLODByHigh(hLODModel);
}
bool CLuaModelDefs::ResetModelLODByLow(std::uint32_t hLODModel) noexcept
{
return CLodModels::ResetModelLODByLow(hLODModel);
}
void CLuaModelDefs::ResetAllModelLOD() noexcept
{
CLodModels::ResetAllModelLOD();
}