Skip to content

Commit

Permalink
Update due to code revision
Browse files Browse the repository at this point in the history
  • Loading branch information
W3lac3 committed Nov 21, 2024
1 parent 07d03b9 commit a28fd7d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
23 changes: 12 additions & 11 deletions Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1112,33 +1112,34 @@ void MixedReadMaterialString(CScriptArgReader& argStream, CClientMaterial*& pMat
//
// Check 4x4 lua table
//
bool IsValidMatrixLuaTable(lua_State* luaVM, uint uiArgIndex)
bool IsValidMatrixLuaTable(lua_State* luaVM, std::uint32_t argIndex) noexcept
{
uint uiRow = 0;
uint uiCell = 0;
std::uint32_t cell = 0;

if (lua_type(luaVM, uiArgIndex) == LUA_TTABLE)
if (lua_type(luaVM, argIndex) == LUA_TTABLE)
{
for (lua_pushnil(luaVM); lua_next(luaVM, uiArgIndex) != 0; lua_pop(luaVM, 1), uiRow++)
lua_pushnil(luaVM);
for (std::uint32_t row = 0; lua_next(luaVM, argIndex) != 0; lua_pop(luaVM, 1), ++row)
{
if (lua_type(luaVM, -1) != LUA_TTABLE)
return false;

uint uiCol = 0;
std::uint32_t col = 0;

for (lua_pushnil(luaVM); lua_next(luaVM, -2) != 0; lua_pop(luaVM, 1), uiCol++, uiCell++)
lua_pushnil(luaVM);
for (; lua_next(luaVM, -2) != 0; lua_pop(luaVM, 1), ++col, ++cell)
{
int iArgumentType = lua_type(luaVM, -1);
if (iArgumentType != LUA_TNUMBER && iArgumentType != LUA_TSTRING)
int argumentType = lua_type(luaVM, -1);
if (argumentType != LUA_TNUMBER && argumentType != LUA_TSTRING)
return false;
}

if (uiCol != 4)
if (col != 4)
return false;
}
}

if (uiRow != 4 || uiCell != 16)
if (cell != 16)
return false;

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ class CScriptArgReader;
void MixedReadDxFontString(CScriptArgReader& argStream, eFontType& outFontType, eFontType defaultFontType, CClientDxFont*& poutDxFontElement);
void MixedReadGuiFontString(CScriptArgReader& argStream, SString& strFontName, const char* szDefaultFontName, CClientGuiFont*& poutGuiFontElement);
void MixedReadMaterialString(CScriptArgReader& argStream, CClientMaterial*& pMaterialElement);
bool IsValidMatrixLuaTable(lua_State* luaVM, uint uiArgIndex);
bool IsValidMatrixLuaTable(lua_State* luaVM, std::uint32_t argIndex) noexcept;
bool ReadMatrix(lua_State* luaVM, uint uiArgIndex, CMatrix& outMatrix);
void MinClientReqCheck(lua_State* luaVM, const char* szVersionReq, const char* szReason);
bool MinClientReqCheck(CScriptArgReader& argStream, const char* szVersionReq, const char* szReason = nullptr);
Expand Down
23 changes: 12 additions & 11 deletions Server/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,33 +649,34 @@ void ReadPregFlags(CScriptArgReader& argStream, pcrecpp::RE_Options& pOptions)
//
// Check 4x4 lua table
//
bool IsValidMatrixLuaTable(lua_State* luaVM, uint uiArgIndex)
bool IsValidMatrixLuaTable(lua_State* luaVM, std::uint32_t argIndex) noexcept
{
uint uiRow = 0;
uint uiCell = 0;
std::uint32_t cell = 0;

if (lua_type(luaVM, uiArgIndex) == LUA_TTABLE)
if (lua_type(luaVM, argIndex) == LUA_TTABLE)
{
for (lua_pushnil(luaVM); lua_next(luaVM, uiArgIndex) != 0; lua_pop(luaVM, 1), uiRow++)
lua_pushnil(luaVM);
for (std::uint32_t row = 0; lua_next(luaVM, argIndex) != 0; lua_pop(luaVM, 1), ++row)
{
if (lua_type(luaVM, -1) != LUA_TTABLE)
return false;

uint uiCol = 0;
std::uint32_t col = 0;

for (lua_pushnil(luaVM); lua_next(luaVM, -2) != 0; lua_pop(luaVM, 1), uiCol++, uiCell++)
lua_pushnil(luaVM);
for (; lua_next(luaVM, -2) != 0; lua_pop(luaVM, 1), ++col, ++cell)
{
int iArgumentType = lua_type(luaVM, -1);
if (iArgumentType != LUA_TNUMBER && iArgumentType != LUA_TSTRING)
int argumentType = lua_type(luaVM, -1);
if (argumentType != LUA_TNUMBER && argumentType != LUA_TSTRING)
return false;
}

if (uiCol != 4)
if (col != 4)
return false;
}
}

if (uiRow != 4 || uiCell != 16)
if (cell != 16)
return false;

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ void MixedReadResourceString(CScriptArgReader& argStream, CResource*& pOutRes
bool StringToBool(const SString& strText);
void MinServerReqCheck(CScriptArgReader& argStream, const char* szVersionReq, const char* szReason);
void ReadPregFlags(CScriptArgReader& argStream, pcrecpp::RE_Options& pOptions);
bool IsValidMatrixLuaTable(lua_State* luaVM, uint uiArgIndex);
bool IsValidMatrixLuaTable(lua_State* luaVM, std::uint32_t argIndex) noexcept;
bool ReadMatrix(lua_State* luaVM, uint uiArgIndex, CMatrix& outMatrix);

//
Expand Down

0 comments on commit a28fd7d

Please sign in to comment.