Skip to content

Commit f5e8e69

Browse files
authored
Add collision type check to getColPolygonHeight and setColPolygonHeight (PR #4318, Fixes #4305)
1 parent 9c43977 commit f5e8e69

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

Server/mods/deathmatch/logic/luadefs/CLuaColShapeDefs.cpp

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -805,30 +805,39 @@ int CLuaColShapeDefs::RemoveColPolygonPoint(lua_State* luaVM)
805805
return luaL_error(luaVM, argStream.GetFullErrorMessage());
806806
}
807807

808-
std::tuple<float, float> CLuaColShapeDefs::GetColPolygonHeight(CColPolygon* pColPolygon)
808+
CLuaMultiReturn<float, float> CLuaColShapeDefs::GetColPolygonHeight(CColShape* shape)
809809
{
810-
float fFloor, fCeil;
811-
pColPolygon->GetHeight(fFloor, fCeil);
812-
return std::make_tuple(fFloor, fCeil);
810+
if (shape->GetShapeType() != COLSHAPE_POLYGON)
811+
{
812+
throw std::invalid_argument("Shape must be a polygon");
813+
}
814+
815+
auto* polygon = static_cast<CColPolygon*>(shape);
816+
817+
float floor;
818+
float ceil;
819+
820+
polygon->GetHeight(floor, ceil);
821+
822+
return {floor, ceil};
813823
}
814824

815-
bool CLuaColShapeDefs::SetColPolygonHeight(CColPolygon* pColPolygon, std::variant<bool, float> floor, std::variant<bool, float> ceil)
825+
bool CLuaColShapeDefs::SetColPolygonHeight(CColShape* shape, std::variant<bool, float> floor, std::variant<bool, float> ceil)
816826
{
817-
// bool SetColPolygonHeight ( colshape theColShape, float floor, float ceil )
818-
float fFloor, fCeil;
827+
if (shape->GetShapeType() != COLSHAPE_POLYGON)
828+
{
829+
throw std::invalid_argument("Shape must be a polygon");
830+
}
819831

820-
if (std::holds_alternative<bool>(floor))
821-
fFloor = std::numeric_limits<float>::lowest();
822-
else
823-
fFloor = std::get<float>(floor);
832+
auto* polygon = static_cast<CColPolygon*>(shape);
824833

825-
if (std::holds_alternative<bool>(ceil))
826-
fCeil = std::numeric_limits<float>::max();
827-
else
828-
fCeil = std::get<float>(ceil);
834+
float lowest = std::holds_alternative<bool>(floor) ? std::numeric_limits<float>::lowest() : std::get<float>(floor);
835+
float highest = std::holds_alternative<bool>(ceil) ? std::numeric_limits<float>::max() : std::get<float>(ceil);
829836

830-
if (fFloor > fCeil)
831-
std::swap(fFloor, fCeil);
837+
if (lowest > highest)
838+
{
839+
std::swap(lowest, highest);
840+
}
832841

833-
return CStaticFunctionDefinitions::SetColPolygonHeight(pColPolygon, fFloor, fCeil);
842+
return CStaticFunctionDefinitions::SetColPolygonHeight(polygon, lowest, highest);
834843
}

Server/mods/deathmatch/logic/luadefs/CLuaColShapeDefs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ class CLuaColShapeDefs : public CLuaDefs
4141
LUA_DECLARE(IsInsideColShape);
4242
LUA_DECLARE(GetColShapeType);
4343

44-
static std::tuple<float, float> GetColPolygonHeight(CColPolygon* pColPolygon);
45-
static bool SetColPolygonHeight(CColPolygon* pColPolygon, std::variant<bool, float> floor, std::variant<bool, float> ceil);
44+
static CLuaMultiReturn<float, float> GetColPolygonHeight(CColShape* shape);
45+
static bool SetColPolygonHeight(CColShape* shape, std::variant<bool, float> floor, std::variant<bool, float> ceil);
4646
};

0 commit comments

Comments
 (0)