mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-05-11 04:56:49 +03:00
Add bounds check for all mesh-related script methods
This commit is contained in:
parent
5350a55af1
commit
189a7165e9
2 changed files with 31 additions and 10 deletions
|
@ -750,37 +750,49 @@ short Moveable::GetStatus() const
|
|||
|
||||
bool Moveable::MeshIsVisible(int meshId) const
|
||||
{
|
||||
if (!MeshExists(meshId))
|
||||
return false;
|
||||
|
||||
return m_item->TestBits(JointBitType::Mesh, meshId);
|
||||
}
|
||||
|
||||
void Moveable::ShowMesh(int meshId)
|
||||
{
|
||||
if (!MeshExists(meshId))
|
||||
return;
|
||||
|
||||
m_item->SetBits(JointBitType::Mesh, meshId);
|
||||
}
|
||||
|
||||
void Moveable::HideMesh(int meshId)
|
||||
{
|
||||
if (!MeshExists(meshId))
|
||||
return;
|
||||
|
||||
m_item->ClearBits(JointBitType::Mesh, meshId);
|
||||
}
|
||||
|
||||
void Moveable::ShatterMesh(int meshId)
|
||||
{
|
||||
if (meshId >= Objects[m_item->ObjectNumber].nmeshes)
|
||||
{
|
||||
TENLog("Specified mesh index does not exist!", LogLevel::Error);
|
||||
if (!MeshExists(meshId))
|
||||
return;
|
||||
}
|
||||
|
||||
ExplodeItemNode(m_item, meshId, 0, 128);
|
||||
}
|
||||
|
||||
bool Moveable::MeshIsSwapped(int meshId) const
|
||||
{
|
||||
if (!MeshExists(meshId))
|
||||
return false;
|
||||
|
||||
return m_item->TestBits(JointBitType::MeshSwap, meshId);
|
||||
}
|
||||
|
||||
void Moveable::SwapMesh(int meshId, int swapSlotId, sol::optional<int> swapMeshIndex)
|
||||
{
|
||||
if (!MeshExists(meshId))
|
||||
return;
|
||||
|
||||
if (!swapMeshIndex.has_value())
|
||||
swapMeshIndex = meshId;
|
||||
|
||||
|
@ -806,12 +818,6 @@ void Moveable::SwapMesh(int meshId, int swapSlotId, sol::optional<int> swapMeshI
|
|||
return;
|
||||
}
|
||||
|
||||
if (meshId >= NUM_LARA_MESHES)
|
||||
{
|
||||
TENLog("Specified mesh index does not exist!", LogLevel::Error);
|
||||
return;
|
||||
}
|
||||
|
||||
lara->MeshPtrs[meshId] = Objects[swapSlotId].meshIndex + swapMeshIndex.value();
|
||||
}
|
||||
else
|
||||
|
@ -820,6 +826,9 @@ void Moveable::SwapMesh(int meshId, int swapSlotId, sol::optional<int> swapMeshI
|
|||
|
||||
void Moveable::UnswapMesh(int meshId)
|
||||
{
|
||||
if (!MeshExists(meshId))
|
||||
return;
|
||||
|
||||
if (m_item->IsLara())
|
||||
{
|
||||
auto* lara = GetLaraInfo(m_item);
|
||||
|
@ -962,3 +971,13 @@ void Moveable::Destroy()
|
|||
Invalidate();
|
||||
}
|
||||
|
||||
bool Moveable::MeshExists(int index) const
|
||||
{
|
||||
if (index < 0 || index >= Objects[m_item->ObjectNumber].nmeshes)
|
||||
{
|
||||
TENLog("Specified mesh index does not exist in moveable '" + m_item->LuaName + "'", LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -109,4 +109,6 @@ private:
|
|||
ItemInfo* m_item;
|
||||
short m_num;
|
||||
bool m_initialised;
|
||||
|
||||
bool MeshExists(int number) const;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue