From e34f492418a6ec18c6b24303c31ca043f8e3e143 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 9 Nov 2019 14:39:23 +0000 Subject: [PATCH 01/27] Accuracy fixes for Igor Includes an ASM-accuracy fix I somehow missed before. --- src/NpcAct080.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/NpcAct080.cpp b/src/NpcAct080.cpp index 378a0e18..8a3d0008 100644 --- a/src/NpcAct080.cpp +++ b/src/NpcAct080.cpp @@ -991,6 +991,7 @@ void ActNpc088(NPCHAR *npc) npc->act_wait = 0; npc->xm = 3 * npc->xm / 2; npc->damage = 2; + break; } else { @@ -1081,11 +1082,11 @@ void ActNpc088(NPCHAR *npc) if (++npc->act_wait > 100 && npc->act_wait % 6 == 1) { if (npc->direct == 0) - deg = -120; + deg = 0x88; else - deg = -8; + deg = 0xF8; - deg += (unsigned char)Random(-16, 16); + deg += (unsigned char)Random(-0x10, 0x10); ym = 3 * GetSin(deg); xm = 3 * GetCos(deg); SetNpChar(11, npc->x, npc->y + 0x800, xm, ym, 0, 0, 0x100); From 5026964d98a818cbbeecb40847aa240a669f65e5 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 9 Nov 2019 14:48:11 +0000 Subject: [PATCH 02/27] Fix some more incorrectly-decompiled code --- src/NpcAct260.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NpcAct260.cpp b/src/NpcAct260.cpp index ee855238..2460aa4f 100644 --- a/src/NpcAct260.cpp +++ b/src/NpcAct260.cpp @@ -1292,9 +1292,9 @@ void ActNpc268(NPCHAR *npc) if (++npc->act_wait > 30 && npc->act_wait % 4 == 1) { if (npc->direct == 0) - deg = -120; + deg = 0x88; else - deg = -8; + deg = 0xF8; deg += (unsigned char)Random(-0x10, 0x10); ym = 5 * GetSin(deg); From 266bb13be2d6d91305587b58b450a47628b602cd Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 9 Nov 2019 14:53:34 +0000 Subject: [PATCH 03/27] Compare some pointers to NULL Doesn't affect ASM-accuracy - I just think it looks neater. --- src/Sound.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Sound.cpp b/src/Sound.cpp index f9e159b0..b4de9a0f 100644 --- a/src/Sound.cpp +++ b/src/Sound.cpp @@ -368,10 +368,10 @@ int MakePixToneObject(const PIXTONEPARAMETER *ptp, int ptp_num, int no) { if (!MakePixelWaveData(ptp_pointer, pcm_buffer)) { - if (pcm_buffer) + if (pcm_buffer != NULL) free(pcm_buffer); - if (mixed_pcm_buffer) + if (mixed_pcm_buffer != NULL) free(mixed_pcm_buffer); return -1; From 9df9ea76f6faed58d4a00c90d327ceee485f82bb Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 9 Nov 2019 15:19:34 +0000 Subject: [PATCH 04/27] Deobfuscate some code Still ASM-accurate --- src/NpcAct180.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/NpcAct180.cpp b/src/NpcAct180.cpp index 7d781346..6301150e 100644 --- a/src/NpcAct180.cpp +++ b/src/NpcAct180.cpp @@ -985,8 +985,10 @@ void ActNpc190(NPCHAR *npc) case 10: PlaySoundObject(72, 1); + for (i = 0; i < 8; i++) - SetNpChar(4, npc->x, npc->y + (Random(-8, 8) << 9), Random(-8, -2) << 9, Random(-3, 3) << 9, 0, 0, 0x100); + SetNpChar(4, npc->x, npc->y + (Random(-8, 8) * 0x200), Random(-8, -2) * 0x200, Random(-3, 3) * 0x200, 0, 0, 0x100); + npc->cond = 0; break; @@ -996,8 +998,10 @@ void ActNpc190(NPCHAR *npc) npc->ani_wait = 0; ++npc->ani_no; } + if (npc->ani_no > 1) npc->ani_no = 0; + break; } @@ -1172,9 +1176,9 @@ void ActNpc192(NPCHAR *npc) PlaySoundObject(34, 1); if (npc->direct == 0) - SetCaret(npc->x + 5120, npc->y + 5120, 7, 2); + SetCaret(npc->x + (10 * 0x200), npc->y + (10 * 0x200), 7, 2); else - SetCaret(npc->x - 5120, npc->y + 5120, 7, 0); + SetCaret(npc->x - (10 * 0x200), npc->y + (10 * 0x200), 7, 0); } RECT rcLeft[2] = { From 9c56888ffd17a687953a2a3c79b5feab1843fb30 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 9 Nov 2019 15:40:15 +0000 Subject: [PATCH 05/27] Deobfuscare more values --- src/NpcAct160.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NpcAct160.cpp b/src/NpcAct160.cpp index 636f50f2..4efd9156 100644 --- a/src/NpcAct160.cpp +++ b/src/NpcAct160.cpp @@ -426,10 +426,10 @@ void ActNpc165(NPCHAR *npc) { case 0: npc->act_no = 1; - npc->y += 0x1400; + npc->y += 10 * 0x200; // Fallthrough case 1: - if (npc->direct == 2 && gMC.x > npc->x - 0x4000 && gMC.x < npc->x + 0x4000 && gMC.y > npc->y - 0x2000 && gMC.y < npc->y + 0x2000) + if (npc->direct == 2 && gMC.x > npc->x - (0x20 * 0x200) && gMC.x < npc->x + (0x20 * 0x200) && gMC.y > npc->y - (0x10 * 0x200) && gMC.y < npc->y + (0x10 * 0x200)) npc->ani_no = 1; else npc->ani_no = 0; From fa304081fe7bcab74990eda3eb510befa299a36b Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Tue, 5 Nov 2019 08:41:58 +0100 Subject: [PATCH 06/27] Documentation : Add note about irreproductability of __DATE Signed-off-by: Gabriel Ravier --- src/Generic.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Generic.cpp b/src/Generic.cpp index 6656bd7f..8ea36f46 100644 --- a/src/Generic.cpp +++ b/src/Generic.cpp @@ -27,7 +27,7 @@ void GetCompileDate(int *year, int *month, int *day) months[10] = "Oct"; months[11] = "Nov"; months[12] = "Dec"; - sscanf(__DATE__, "%s %d %d", month_string, day, year); + sscanf(__DATE__, "%s %d %d", month_string, day, year); // The expansion of __DATE__ is not reproductible. We might want to change this for (i = 0; i < 12; ++i) // This being 12 instead of 13 might be a bug, but it works anyway by accident if (!memcmp(&month_string, months[i], 3)) From 073a15b41b2f959341392f988287097fdf14cb78 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Tue, 5 Nov 2019 17:06:06 +0100 Subject: [PATCH 07/27] Documentation : Comment implicit truncation --- src/NpcAct080.cpp | 2 ++ src/NpcAct260.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/NpcAct080.cpp b/src/NpcAct080.cpp index 8a3d0008..0b1f57b2 100644 --- a/src/NpcAct080.cpp +++ b/src/NpcAct080.cpp @@ -1081,6 +1081,8 @@ void ActNpc088(NPCHAR *npc) case 10: if (++npc->act_wait > 100 && npc->act_wait % 6 == 1) { + // The range of unsigned char is [0, 255] so these two values are implicitly truncated (Might be UB ?) + // TODO : Investigate on whether this is erroneous if (npc->direct == 0) deg = 0x88; else diff --git a/src/NpcAct260.cpp b/src/NpcAct260.cpp index 2460aa4f..db398856 100644 --- a/src/NpcAct260.cpp +++ b/src/NpcAct260.cpp @@ -1291,6 +1291,8 @@ void ActNpc268(NPCHAR *npc) case 51: if (++npc->act_wait > 30 && npc->act_wait % 4 == 1) { + // The range of unsigned char is [0, 255] so these two values are implicitly truncated (Might be UB ?) + // TODO : Investigate on whether this is erroneous if (npc->direct == 0) deg = 0x88; else From 347f9282fe1caff5ebca0c76a2de0b47faad630a Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Tue, 5 Nov 2019 17:18:12 +0100 Subject: [PATCH 08/27] Documentation : Commented redundant check Signed-off-by: Gabriel Ravier --- src/NpcHit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NpcHit.cpp b/src/NpcHit.cpp index 70b64399..cbcb85de 100644 --- a/src/NpcHit.cpp +++ b/src/NpcHit.cpp @@ -520,7 +520,7 @@ void LoseNpChar(NPCHAR *npc, BOOL bVanish) // Create value view if (npc->bits & NPC_SHOW_DAMAGE) { - if ((npc->bits & NPC_SHOW_DAMAGE) && npc->damage_view) + if ((npc->bits & NPC_SHOW_DAMAGE) && npc->damage_view) // npc->bits & NPC_SHOW_DAMAGE is already verified at this point, so this is redundant SetValueView(&npc->x, &npc->y, npc->damage_view); if (bVanish) VanishNpChar(npc); From 7ddcbfaa73ffb826fe58f0569692b8d65cf5b4ae Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Mon, 4 Nov 2019 11:27:04 +0100 Subject: [PATCH 09/27] Add note about identical case branches Signed-off-by: Gabriel Ravier --- src/BossX.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BossX.cpp b/src/BossX.cpp index dfa73365..702405e7 100644 --- a/src/BossX.cpp +++ b/src/BossX.cpp @@ -766,7 +766,7 @@ void ActBossChar_MonstX(void) gBoss[1].act_no = 20; gBoss[2].act_no = 20; // Fallthrough - case 503: + case 503: // Exactly identical to case 603 if (++npc->act_wait > 50) { if (npc->x > gMC.x) @@ -803,7 +803,7 @@ void ActBossChar_MonstX(void) gBoss[2].act_no = 40; // Fallthrough - case 603: + case 603: // Exactly identical to case 503 if (++npc->act_wait > 50) { if (npc->x > gMC.x) From 1891591586385a2693f38192d3335daf801cb7c2 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Mon, 4 Nov 2019 11:38:22 +0100 Subject: [PATCH 10/27] Documentation : Document identical case branches in ActBullet Signed-off-by: Gabriel Ravier --- src/Bullet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Bullet.cpp b/src/Bullet.cpp index 3c00fa2f..618f83ae 100644 --- a/src/Bullet.cpp +++ b/src/Bullet.cpp @@ -2352,7 +2352,7 @@ void ActBullet() case 33: ActBullet_SuperBom(&gBul[i], 3); break; - case 34: + case 34: // Identical to case 43 ActBullet_Nemesis(&gBul[i], 1); break; case 35: @@ -2379,7 +2379,7 @@ void ActBullet() case 42: ActBullet_SpurTail(&gBul[i], 3); break; - case 43: + case 43: // Identical to case 34 ActBullet_Nemesis(&gBul[i], 1); break; case 44: From c9e63c769494c1155271468ffb11699862c962b5 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Tue, 5 Nov 2019 11:02:47 +0100 Subject: [PATCH 11/27] Documentation : Document the identical HitMyCharMap case branches --- src/MycHit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MycHit.cpp b/src/MycHit.cpp index c2ddf56a..5a6e86b0 100644 --- a/src/MycHit.cpp +++ b/src/MycHit.cpp @@ -507,7 +507,7 @@ void HitMyCharMap() gMC.flag |= JudgeHitMyCharWater(x + offx[i], y + offy[i]); break; - // Water and water blocks + // Water and water blocks (same as the previous case) case 0x60: gMC.flag |= JudgeHitMyCharWater(x + offx[i], y + offy[i]); break; From 6f0ffe546f2e2303d6564bf8c45ac54638c21152 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Tue, 5 Nov 2019 16:34:58 +0100 Subject: [PATCH 12/27] Documentation : Add note about identical case branches in NpcAct020 Signed-off-by: Gabriel Ravier --- src/NpcAct020.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NpcAct020.cpp b/src/NpcAct020.cpp index b3fcb011..675a3d3f 100644 --- a/src/NpcAct020.cpp +++ b/src/NpcAct020.cpp @@ -306,7 +306,7 @@ void ActNpc025(NPCHAR *npc) break; - case 2: + case 2: // Identical to case 4 if (++npc->act_wait <= 0x40) { npc->y -= 0x200; @@ -328,7 +328,7 @@ void ActNpc025(NPCHAR *npc) break; - case 4: + case 4: // Identical to case 2 if (++npc->act_wait <= 0x40) { npc->y -= 0x200; From 6635cc58ed1fa30dff5d25b8b96bb29e4580068c Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Tue, 5 Nov 2019 17:10:12 +0100 Subject: [PATCH 13/27] Documentation : Comment identical case branches in NpcAct280 --- src/NpcAct280.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NpcAct280.cpp b/src/NpcAct280.cpp index 8c4b18e2..db423240 100644 --- a/src/NpcAct280.cpp +++ b/src/NpcAct280.cpp @@ -747,11 +747,11 @@ void ActNpc284(NPCHAR *npc) npc->act_no = 34; break; - case 0: + case 0: // Identical to case 2 npc->act_no = 32; break; - case 2: + case 2: // Identical to case 0 npc->act_no = 32; break; } From bda9fc391a26457f32b0b648e6bbe1698722eeaa Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Tue, 5 Nov 2019 16:59:53 +0100 Subject: [PATCH 14/27] Documentation : Comment redundant if Signed-off-by: Gabriel Ravier --- src/NpcAct040.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NpcAct040.cpp b/src/NpcAct040.cpp index f53ce803..d133f2c0 100644 --- a/src/NpcAct040.cpp +++ b/src/NpcAct040.cpp @@ -1122,7 +1122,7 @@ void ActNpc051(NPCHAR *npc) npc->tgt_x = npc->x; npc->tgt_y = npc->y; - if (npc->direct == 0) + if (npc->direct == 0) // Completely redundant as both the conditions are the same npc->ym = 0x400; else npc->ym = 0x400; From 6b1f82e78eed80c66ffddcef7938ec2b3c801994 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Mon, 4 Nov 2019 11:40:25 +0100 Subject: [PATCH 15/27] Documentation : Document identical function bodies for InitBullet and ClearBullet Signed-off-by: Gabriel Ravier --- src/Bullet.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Bullet.cpp b/src/Bullet.cpp index 618f83ae..a9095dae 100644 --- a/src/Bullet.cpp +++ b/src/Bullet.cpp @@ -66,6 +66,7 @@ BULLET gBul[BULLET_MAX]; void InitBullet() { + // Identical to ClearBullet for (int i = 0; i < BULLET_MAX; i++) gBul[i].cond = 0; } @@ -110,6 +111,7 @@ void DeleteBullet(int code) void ClearBullet() { + // Identical to InitBullet for (int i = 0; i < BULLET_MAX; i++) gBul[i].cond = 0; } From ab4a265cd9d4c470e4c5e9b4deecfd23a20bcae3 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Tue, 5 Nov 2019 17:28:54 +0100 Subject: [PATCH 16/27] Documentation : Add note about duplicate block of code --- src/Star.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Star.cpp b/src/Star.cpp index a531eddb..51a94bc9 100644 --- a/src/Star.cpp +++ b/src/Star.cpp @@ -96,6 +96,7 @@ void ActStar() if (star[i].ym < -0xA00) star[i].ym = -0xA00; + // Duplicate of the past 8 lines of code if (star[i].xm > 0xA00) star[i].xm = 0xA00; if (star[i].xm < -0xA00) From 32d29eb63ec7a3ca1634696c7df1b3229febc89e Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Tue, 5 Nov 2019 10:48:06 +0100 Subject: [PATCH 17/27] Documentation : Note that the fact 96 is already listed results in the condition always being false --- src/MiniMap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MiniMap.cpp b/src/MiniMap.cpp index 2d2a4beb..c2b3f628 100644 --- a/src/MiniMap.cpp +++ b/src/MiniMap.cpp @@ -64,7 +64,7 @@ void WriteMiniMapLine(int line) a == 83 || a == 84 || a == 87 || - a == 96 || // This is already listed above + a == 96 || // This is already listed above, so that part of the expression is always false a == 112 || a == 115 || a == 116 || From a45592302facace75d4cdddca49546cadf391834 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Tue, 5 Nov 2019 09:49:45 +0100 Subject: [PATCH 18/27] Documentation : Commented the fact that "swPlay % 2" is always true Signed-off-by: Gabriel Ravier --- src/Game.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Game.cpp b/src/Game.cpp index d698f857..de236b25 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -532,7 +532,7 @@ int ModeAction(HWND hWnd) } } - if (swPlay % 2 && g_GameFlags & 1) + if (swPlay % 2 && g_GameFlags & 1) // The "swPlay % 2" part is always true { if (g_GameFlags & 2) ActMyChar(TRUE); @@ -635,7 +635,7 @@ int ModeAction(HWND hWnd) RotationArmsRev(); } - if (swPlay % 2) + if (swPlay % 2) // This is always true { switch (TextScriptProc()) { From 512b2e4951b569925e56ea019caad021ad042095 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Tue, 5 Nov 2019 17:01:21 +0100 Subject: [PATCH 19/27] Documentation : Comment always true condition Signed-off-by: Gabriel Ravier --- src/NpcAct040.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NpcAct040.cpp b/src/NpcAct040.cpp index d133f2c0..3d38462a 100644 --- a/src/NpcAct040.cpp +++ b/src/NpcAct040.cpp @@ -1895,7 +1895,7 @@ void ActNpc058(NPCHAR *npc) break; } - if (npc->act_no) + if (npc->act_no) // This is always true { if (npc->act_wait < 150) ++npc->act_wait; From ffc6e3e75b6938ec388baebff31d183348ff9fe3 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Tue, 5 Nov 2019 17:03:23 +0100 Subject: [PATCH 20/27] Documentation : Comment duplicate line Signed-off-by: Gabriel Ravier --- src/NpcAct100.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NpcAct100.cpp b/src/NpcAct100.cpp index fe7b309d..c56b9d5e 100644 --- a/src/NpcAct100.cpp +++ b/src/NpcAct100.cpp @@ -671,7 +671,7 @@ void ActNpc110(NPCHAR *npc) if (npc->act_wait > 18) { npc->act_no = 1; - npc->act_no = 1; + npc->act_no = 1; // Duplicate line } break; From 17f7f66fc9531e5e31f4886003ed014579c60231 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Tue, 5 Nov 2019 17:23:12 +0100 Subject: [PATCH 21/27] Documentation : Comment an always true expression Signed-off-by: Gabriel Ravier --- src/Sound.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Sound.cpp b/src/Sound.cpp index b4de9a0f..1e35fb1b 100644 --- a/src/Sound.cpp +++ b/src/Sound.cpp @@ -368,10 +368,10 @@ int MakePixToneObject(const PIXTONEPARAMETER *ptp, int ptp_num, int no) { if (!MakePixelWaveData(ptp_pointer, pcm_buffer)) { - if (pcm_buffer != NULL) + if (pcm_buffer != NULL) // This is always true free(pcm_buffer); - if (mixed_pcm_buffer != NULL) + if (mixed_pcm_buffer != NULL) // This is always true free(mixed_pcm_buffer); return -1; From f840be28c71e6605e3ec197a120f1b1aa45b3497 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Tue, 5 Nov 2019 08:19:07 +0100 Subject: [PATCH 22/27] Added better comment for random self-assign in Fade.cpp Signed-off-by: Gabriel Ravier --- src/Fade.cpp | 2 +- src/Organya.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Fade.cpp b/src/Fade.cpp index 9c5986bc..67e15e6b 100644 --- a/src/Fade.cpp +++ b/src/Fade.cpp @@ -76,7 +76,7 @@ void StartFadeIn(signed char dir) } } - x = x; // What + x = x; // x is assigned to itself. Thanks, Pixel. (Most likely, the original code wasn't written the exact same way) } void ProcFade() diff --git a/src/Organya.cpp b/src/Organya.cpp index 24bb6c3c..b7e8fc17 100644 --- a/src/Organya.cpp +++ b/src/Organya.cpp @@ -521,7 +521,7 @@ BOOL OrgData::SetMusicInfo(MUSICINFO *mi, unsigned long flag) for (i = 0; i < MAXMELODY; i++) { info.tdata[i].freq = mi->tdata[i].freq; - info.tdata[i].pipi = info.tdata[i].pipi; + info.tdata[i].pipi = info.tdata[i].pipi; // info.tdata[i].pipi is assigned to itself. Thanks, Pixel. (Most likely, the original code wasn't written the exact same way) } } From 5b18283e5f8dffd4cae6b5b7ef09d67237383db5 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Tue, 5 Nov 2019 11:19:20 +0100 Subject: [PATCH 23/27] Documentation : Made some comments clearer Signed-off-by: Gabriel Ravier --- src/Generic.cpp | 2 +- src/MyChar.cpp | 2 +- src/MycParam.cpp | 2 +- src/NpcAct160.cpp | 2 +- src/NpcAct320.cpp | 8 ++++---- src/Sound.cpp | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Generic.cpp b/src/Generic.cpp index 8ea36f46..7c540e36 100644 --- a/src/Generic.cpp +++ b/src/Generic.cpp @@ -27,7 +27,7 @@ void GetCompileDate(int *year, int *month, int *day) months[10] = "Oct"; months[11] = "Nov"; months[12] = "Dec"; - sscanf(__DATE__, "%s %d %d", month_string, day, year); // The expansion of __DATE__ is not reproductible. We might want to change this + sscanf(__DATE__, "%s %d %d", month_string, day, year); // The expansion of __DATE__ is not reproductible. TODO : Think about changing this to be reproductible for (i = 0; i < 12; ++i) // This being 12 instead of 13 might be a bug, but it works anyway by accident if (!memcmp(&month_string, months[i], 3)) diff --git a/src/MyChar.cpp b/src/MyChar.cpp index c4551183..58e4c114 100644 --- a/src/MyChar.cpp +++ b/src/MyChar.cpp @@ -680,7 +680,7 @@ void ActMyChar_Normal(BOOL bKey) // Change position if (gMC.xm <= resist && gMC.xm >= -resist) { - // Okay, this is getting stupid. Why the HELL is the code written like this? + // This case is completely empty. This is most likely the result of commented code or some other change (so this is most likely inaccurate to the original source) } else { diff --git a/src/MycParam.cpp b/src/MycParam.cpp index 13b882c5..0da79938 100644 --- a/src/MycParam.cpp +++ b/src/MycParam.cpp @@ -135,7 +135,7 @@ void DamageMyChar(int damage) // Lose a whimsical star if (gMC.equip & 0x80 && gMC.star > 0) - gMC.star = (short)gMC.star - 1; // Why the hell is it written this way? + gMC.star = (short)gMC.star - 1; // For some reason, does a cast to short. Probably not accurate to the original source // Lose experience if (gMC.equip & 4) diff --git a/src/NpcAct160.cpp b/src/NpcAct160.cpp index 4efd9156..d1a45646 100644 --- a/src/NpcAct160.cpp +++ b/src/NpcAct160.cpp @@ -70,7 +70,7 @@ void ActNpc160(NPCHAR *npc) case 3: npc->damage = 20; - npc->damage = 0; // Smart code + npc->damage = 0; // Duplicate line if (++npc->act_wait > 24) { diff --git a/src/NpcAct320.cpp b/src/NpcAct320.cpp index 265c065b..1050a198 100644 --- a/src/NpcAct320.cpp +++ b/src/NpcAct320.cpp @@ -142,20 +142,20 @@ void ActNpc321(NPCHAR *npc) break; case 1: - if (gMC.direct == 0) + if (gMC.direct == 0) // Does the same thing whether this is false or true npc->x = npc->pNpc->x; else - npc->x = npc->pNpc->x; // Duplicate derp + npc->x = npc->pNpc->x; direct = 1; npc->y = npc->pNpc->y - 0x1400; break; case 2: - if (gMC.direct == 0) + if (gMC.direct == 0) // Does the same thing whether this is false or true npc->x = npc->pNpc->x; else - npc->x = npc->pNpc->x; // Duplicate derp + npc->x = npc->pNpc->x; direct = 3; npc->y = npc->pNpc->y + 0x1400; diff --git a/src/Sound.cpp b/src/Sound.cpp index 1e35fb1b..2c3b5336 100644 --- a/src/Sound.cpp +++ b/src/Sound.cpp @@ -390,7 +390,7 @@ int MakePixToneObject(const PIXTONEPARAMETER *ptp, int ptp_num, int no) ++ptp_pointer; } - // Maybe this used to be something to prevent audio popping? + // This is self-assignment, so redundant. Maybe this used to be something to prevent audio popping ? mixed_pcm_buffer[0] = mixed_pcm_buffer[0]; mixed_pcm_buffer[sample_count - 1] = mixed_pcm_buffer[sample_count - 1]; From 058881e4eb6379b62551f1dd3a4fca611c01e41e Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Sat, 9 Nov 2019 23:35:58 +0100 Subject: [PATCH 24/27] Documentation : Tried to clarify comment on random conversion to short Signed-off-by: Gabriel Ravier --- src/MycParam.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MycParam.cpp b/src/MycParam.cpp index 0da79938..f2b96e35 100644 --- a/src/MycParam.cpp +++ b/src/MycParam.cpp @@ -135,7 +135,7 @@ void DamageMyChar(int damage) // Lose a whimsical star if (gMC.equip & 0x80 && gMC.star > 0) - gMC.star = (short)gMC.star - 1; // For some reason, does a cast to short. Probably not accurate to the original source + gMC.star = (short)gMC.star - 1; // For some reason, does a cast to short. Might not accurate to the original source (possibly, Pixel was just being careful about int size/conversion, or this is from some weird macro) // Lose experience if (gMC.equip & 4) From 9461b141f1efa82239c7f3045a10f3b1c3b7b5da Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Sat, 9 Nov 2019 23:39:28 +0100 Subject: [PATCH 25/27] Documentation : Removed comment which talks about an issue fixed by commit e34f492418a6ec18c6b24303c31ca043f8e3e143 Signed-off-by: Gabriel Ravier --- src/NpcAct080.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/NpcAct080.cpp b/src/NpcAct080.cpp index 0b1f57b2..8a3d0008 100644 --- a/src/NpcAct080.cpp +++ b/src/NpcAct080.cpp @@ -1081,8 +1081,6 @@ void ActNpc088(NPCHAR *npc) case 10: if (++npc->act_wait > 100 && npc->act_wait % 6 == 1) { - // The range of unsigned char is [0, 255] so these two values are implicitly truncated (Might be UB ?) - // TODO : Investigate on whether this is erroneous if (npc->direct == 0) deg = 0x88; else From f7a3eee9b511301e89ec0d62a83bea218f2e57a2 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Sun, 10 Nov 2019 13:09:05 +0100 Subject: [PATCH 26/27] betterComments : Some stuff for the PR to accurate Signed-off-by: Gabriel Ravier --- src/NpcAct160.cpp | 4 ++-- src/NpcAct260.cpp | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/NpcAct160.cpp b/src/NpcAct160.cpp index d1a45646..606bbee3 100644 --- a/src/NpcAct160.cpp +++ b/src/NpcAct160.cpp @@ -69,8 +69,8 @@ void ActNpc160(NPCHAR *npc) break; case 3: - npc->damage = 20; - npc->damage = 0; // Duplicate line + npc->damage = 20; // Overriden by the following line + npc->damage = 0; if (++npc->act_wait > 24) { diff --git a/src/NpcAct260.cpp b/src/NpcAct260.cpp index db398856..2460aa4f 100644 --- a/src/NpcAct260.cpp +++ b/src/NpcAct260.cpp @@ -1291,8 +1291,6 @@ void ActNpc268(NPCHAR *npc) case 51: if (++npc->act_wait > 30 && npc->act_wait % 4 == 1) { - // The range of unsigned char is [0, 255] so these two values are implicitly truncated (Might be UB ?) - // TODO : Investigate on whether this is erroneous if (npc->direct == 0) deg = 0x88; else From c5d6109df28f967145520aa3be0d8c9e25d51ef9 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sun, 10 Nov 2019 12:17:07 +0000 Subject: [PATCH 27/27] Comment tweaks --- src/MyChar.cpp | 2 +- src/MycParam.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MyChar.cpp b/src/MyChar.cpp index 58e4c114..c79436cf 100644 --- a/src/MyChar.cpp +++ b/src/MyChar.cpp @@ -680,7 +680,7 @@ void ActMyChar_Normal(BOOL bKey) // Change position if (gMC.xm <= resist && gMC.xm >= -resist) { - // This case is completely empty. This is most likely the result of commented code or some other change (so this is most likely inaccurate to the original source) + // This case is completely empty. This is most likely the result of commented-out code or some other change (so this is most likely inaccurate to the original source code) } else { diff --git a/src/MycParam.cpp b/src/MycParam.cpp index f2b96e35..fe5a399b 100644 --- a/src/MycParam.cpp +++ b/src/MycParam.cpp @@ -135,7 +135,7 @@ void DamageMyChar(int damage) // Lose a whimsical star if (gMC.equip & 0x80 && gMC.star > 0) - gMC.star = (short)gMC.star - 1; // For some reason, does a cast to short. Might not accurate to the original source (possibly, Pixel was just being careful about int size/conversion, or this is from some weird macro) + gMC.star = (short)gMC.star - 1; // For some reason, this does a cast to short. Might not be accurate to the original source code (possibly, Pixel was just being careful about int size/conversion, or this is from some weird macro) // Lose experience if (gMC.equip & 4)