From 81d672e1583e564a798f92c58ac4766af08503e4 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Thu, 6 Feb 2020 11:52:49 +0100 Subject: [PATCH] Fixed a bunch of npc->cond = 0 bugs --- src/Bullet.cpp | 3 +++ src/Caret.cpp | 12 ++++++++++++ src/NpcAct120.cpp | 9 +++++++++ src/NpcAct140.cpp | 1 + src/NpcAct180.cpp | 3 +++ 5 files changed, 28 insertions(+) diff --git a/src/Bullet.cpp b/src/Bullet.cpp index 668ec61f..e269b077 100644 --- a/src/Bullet.cpp +++ b/src/Bullet.cpp @@ -1621,7 +1621,10 @@ void ActBullet_Edge(BULLET *bul) bul->damage = 1; if (bul->ani_no > 4) + { bul->cond = 0; + return; // Prevent UB at rc[bul->ani_no] when bul->ani_no == 5 + } break; } diff --git a/src/Caret.cpp b/src/Caret.cpp index be61ba2d..e436942d 100644 --- a/src/Caret.cpp +++ b/src/Caret.cpp @@ -73,7 +73,10 @@ void ActCaret01(CARET *crt) { crt->ani_wait = 0; if (++crt->ani_no > 3) + { crt->cond = 0; + return; // Prevent UB at rc[crt->ani_no] when crt->ani_no == 4 + } } if (crt->direct == 0) @@ -245,7 +248,10 @@ void ActCaret07(CARET *crt) crt->ani_wait = 0; if (++crt->ani_no > 6) + { crt->cond = 0; + return; // Prevent UB at rcLeft[crt->ani_no] when crt->ani_no == 6 + } } crt->rect = rcLeft[crt->ani_no]; @@ -449,7 +455,10 @@ void ActCaret14(CARET *crt) crt->ani_wait = 0; if (++crt->ani_no > 4) + { crt->cond = 0; + return; // Prevent UB at rect[crt->ani_no] when crt->ani_no == 5 + } } crt->rect = rect[crt->ani_no]; @@ -469,7 +478,10 @@ void ActCaret15(CARET *crt) crt->ani_wait = 0; if (++crt->ani_no > 3) + { crt->cond = 0; + return; // Prevent UB at rcLeft[crt->ani_no] when crt->ani_no == 4 + } } crt->rect = rcLeft[crt->ani_no]; diff --git a/src/NpcAct120.cpp b/src/NpcAct120.cpp index 1e0516e5..2f61bf63 100644 --- a/src/NpcAct120.cpp +++ b/src/NpcAct120.cpp @@ -585,7 +585,10 @@ void ActNpc127(NPCHAR *npc) { npc->ani_wait = 0; if (++npc->ani_no > 2) + { npc->cond = 0; + return; // Prevent UB at rc[npc->ani_no] when npc->ani_no == 3 + } } if (npc->direct == 0) @@ -646,7 +649,10 @@ void ActNpc128(NPCHAR *npc) } if (++npc->ani_no > 4) + { npc->cond = 0; + return; // Prevent UB at rc[npc->ani_no] when npc->ani_no == 5 + } switch (npc->direct) { @@ -697,7 +703,10 @@ void ActNpc129(NPCHAR *npc) npc->ani_wait = 0; if (++npc->ani_no > 2) + { npc->cond = 0; + return; // Prevent UB at rect[(npc->direct * 3) + npc->ani_no] when npc->direct == 5 and npc->ani_no == 3 + } } npc->y += npc->ym; diff --git a/src/NpcAct140.cpp b/src/NpcAct140.cpp index d2f71171..b76a1b79 100644 --- a/src/NpcAct140.cpp +++ b/src/NpcAct140.cpp @@ -753,6 +753,7 @@ void ActNpc146(NPCHAR *npc) { SetDestroyNpChar(npc->x, npc->y, 0x1000, 8); npc->cond = 0; + return; // Prevent UB at rect[npc->ani_no] when npc->ani_no == 5 } break; diff --git a/src/NpcAct180.cpp b/src/NpcAct180.cpp index 8e3651c6..76f27294 100644 --- a/src/NpcAct180.cpp +++ b/src/NpcAct180.cpp @@ -1426,7 +1426,10 @@ void ActNpc199(NPCHAR *npc) } if (npc->ani_no > 4) + { npc->cond = 0; + return; // Prevent UB at rect[npc->ani_no] when npc->ani_no == 5 + } npc->x += npc->xm; npc->y += npc->ym;