From e5aa4a3518ac24c62de2b10c4f2b6fce2d427fc3 Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Sun, 30 Oct 2022 09:31:09 +0300 Subject: [PATCH] Fix square tiles initial lookup --- src/object.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/object.cc b/src/object.cc index 9cbf55a..3c09abf 100644 --- a/src/object.cc +++ b/src/object.cc @@ -1497,7 +1497,10 @@ int objectSetLocation(Object* obj, int tile, int elevation, Rect* rect) if (v14 != _obj_last_roof_x || v15 != _obj_last_roof_y || elevation != _obj_last_elev) { int v16 = _square[elevation]->field_0[v14 + 100 * v15]; int v31 = buildFid(OBJ_TYPE_TILE, (v16 >> 16) & 0xFFF, 0, 0, 0); - int v32 = _square[elevation]->field_0[_obj_last_roof_x + 100 * _obj_last_roof_y]; + // CE: Add additional checks for -1 to prevent array lookup at index -101. + int v32 = _obj_last_roof_x != -1 && _obj_last_roof_y != -1 + ? _square[elevation]->field_0[_obj_last_roof_x + 100 * _obj_last_roof_y] + : 0; int v34 = buildFid(OBJ_TYPE_TILE, 1, 0, 0, 0) == v31; if (v34 != _obj_last_is_empty || (((v16 >> 16) & 0xF000) >> 12) != (((v32 >> 16) & 0xF000) >> 12)) {