Fix crash on handling wallmounted nodes with invalid param2 (#13487)

This commit is contained in:
savilli
2023-05-18 20:31:04 +02:00
committed by GitHub
parent 35112f2453
commit 5ba70cf5ef
2 changed files with 26 additions and 23 deletions

View File

@ -64,8 +64,10 @@ u8 MapNode::getFaceDir(const NodeDefManager *nodemgr,
f.param_type_2 == CPT2_COLORED_4DIR) f.param_type_2 == CPT2_COLORED_4DIR)
return getParam2() & 0x03; return getParam2() & 0x03;
if (allow_wallmounted && (f.param_type_2 == CPT2_WALLMOUNTED || if (allow_wallmounted && (f.param_type_2 == CPT2_WALLMOUNTED ||
f.param_type_2 == CPT2_COLORED_WALLMOUNTED)) f.param_type_2 == CPT2_COLORED_WALLMOUNTED)) {
return wallmounted_to_facedir[getParam2() & 0x07]; u8 wmountface = MYMIN(getParam2() & 0x07, DWM_COUNT - 1);
return wallmounted_to_facedir[wmountface];
}
return 0; return 0;
} }
@ -73,9 +75,9 @@ u8 MapNode::getWallMounted(const NodeDefManager *nodemgr) const
{ {
const ContentFeatures &f = nodemgr->get(*this); const ContentFeatures &f = nodemgr->get(*this);
if (f.param_type_2 == CPT2_WALLMOUNTED || if (f.param_type_2 == CPT2_WALLMOUNTED ||
f.param_type_2 == CPT2_COLORED_WALLMOUNTED) { f.param_type_2 == CPT2_COLORED_WALLMOUNTED)
return getParam2() & 0x07; return MYMIN(getParam2() & 0x07, DWM_COUNT - 1);
} else if (f.drawtype == NDT_SIGNLIKE || f.drawtype == NDT_TORCHLIKE || else if (f.drawtype == NDT_SIGNLIKE || f.drawtype == NDT_TORCHLIKE ||
f.drawtype == NDT_PLANTLIKE || f.drawtype == NDT_PLANTLIKE ||
f.drawtype == NDT_PLANTLIKE_ROOTED) { f.drawtype == NDT_PLANTLIKE_ROOTED) {
return 1; return 1;
@ -160,7 +162,7 @@ void MapNode::rotateAlongYAxis(const NodeDefManager *nodemgr, Rotation rot)
} }
} else if (cpt2 == CPT2_WALLMOUNTED || } else if (cpt2 == CPT2_WALLMOUNTED ||
cpt2 == CPT2_COLORED_WALLMOUNTED) { cpt2 == CPT2_COLORED_WALLMOUNTED) {
u8 wmountface = (param2 & 7); u8 wmountface = MYMIN(param2 & 0x07, DWM_COUNT - 1);
if (wmountface <= 1) if (wmountface <= 1)
return; return;

View File

@ -22,23 +22,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irrlichttypes.h" #include "irrlichttypes.h"
#include "irr_v3d.h" #include "irr_v3d.h"
extern const v3s16 g_6dirs[6];
extern const v3s16 g_7dirs[7];
extern const v3s16 g_26dirs[26];
// 26th is (0,0,0)
extern const v3s16 g_27dirs[27];
extern const u8 wallmounted_to_facedir[6];
extern const v3s16 wallmounted_dirs[8];
extern const v3s16 facedir_dirs[32];
extern const v3s16 fourdir_dirs[4];
/// Direction in the 6D format. g_27dirs contains corresponding vectors. /// Direction in the 6D format. g_27dirs contains corresponding vectors.
/// Here P means Positive, N stands for Negative. /// Here P means Positive, N stands for Negative.
enum Direction6D { enum Direction6D {
@ -92,4 +75,22 @@ enum DirectionWallmounted {
DWM_XN, DWM_XN,
DWM_ZP, DWM_ZP,
DWM_ZN, DWM_ZN,
DWM_COUNT,
}; };
extern const v3s16 g_6dirs[DWM_COUNT];
extern const v3s16 g_7dirs[7];
extern const v3s16 g_26dirs[26];
// 26th is (0,0,0)
extern const v3s16 g_27dirs[27];
extern const u8 wallmounted_to_facedir[6];
extern const v3s16 wallmounted_dirs[8];
extern const v3s16 facedir_dirs[32];
extern const v3s16 fourdir_dirs[4];