From e70074cf6445ad441de393d7ddfbccc2c19a399d Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 05:07:47 +0000 Subject: [PATCH 01/42] More-accurate ArmsItem.cpp variable arrangement --- src/ArmsItem.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index 96272c24..7ae3279d 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -14,17 +14,18 @@ #include "Sound.h" #include "TextScr.h" -int gArmsEnergyX = 16; +ARMS gArmsData[ARMS_MAX]; +ITEM gItemData[ITEM_MAX]; int gSelectedArms; int gSelectedItem; -ARMS gArmsData[ARMS_MAX]; -ITEM gItemData[ITEM_MAX]; +static int gCampTitleY; /// True if we're in the items section of the inventory (not in the weapons section) (only relevant when the inventory is open) static BOOL gCampActive; -static int gCampTitleY; + +int gArmsEnergyX = 16; void ClearArmsData(void) { @@ -175,6 +176,8 @@ BOOL SubItemData(long code) /// Update the inventory cursor void MoveCampCursor(void) { + BOOL bChange; + // Compute the current amount of weapons and items int arms_num = 0; int item_num = 0; @@ -187,7 +190,7 @@ void MoveCampCursor(void) return; // Empty inventory // True if we're currently changing cursor position - BOOL bChange = FALSE; + bChange = FALSE; if (!gCampActive) { @@ -300,6 +303,8 @@ void MoveCampCursor(void) /// Draw the inventory void PutCampObject(void) { + static unsigned int flash; + int i; /// Rect for the current weapon @@ -347,7 +352,6 @@ void PutCampObject(void) PutBitmap3(&rcView, (WINDOW_WIDTH / 2) - 112, gCampTitleY + 52, &rcTitle2, SURFACE_ID_TEXT_BOX); // Draw arms cursor - static unsigned int flash; ++flash; if (gCampActive == FALSE) @@ -410,7 +414,6 @@ void PutCampObject(void) int CampLoop(void) { - int arms_num; char old_script_path[MAX_PATH]; RECT rcView = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT}; @@ -428,7 +431,7 @@ int CampLoop(void) gSelectedItem = 0; // Compute current amount of weapons - arms_num = 0; + int arms_num = 0; while (gArmsData[arms_num].code != 0) ++arms_num; From 36f203ca1615d54645577348c866b03e0ec7cfcf Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 05:11:43 +0000 Subject: [PATCH 02/42] More-accurate Back.cpp variable arrangement --- src/Back.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Back.cpp b/src/Back.cpp index c5f2de76..5234400f 100644 --- a/src/Back.cpp +++ b/src/Back.cpp @@ -82,8 +82,7 @@ void ActBack(void) void PutBack(int fx, int fy) { - int x; - int y; + int x, y; RECT rect = {0, 0, gBack.partsW, gBack.partsH}; switch (gBack.type) @@ -166,17 +165,14 @@ void PutBack(int fx, int fy) void PutFront(int fx, int fy) { - int x; - int y; - int xpos; - int ypos; - int x_1; - int x_2; - int y_1; - int y_2; + int xpos, ypos; RECT rcWater[2] = {{0, 0, 32, 16}, {0, 16, 32, 48}}; + int x, y; + int x_1, x_2; + int y_1, y_2; + switch (gBack.type) { case 3: From a0813edd2bb26201ffa00942680d77ce910bc057 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 05:15:56 +0000 Subject: [PATCH 03/42] More-accurate Boss.cpp variable arrangement --- src/Boss.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Boss.cpp b/src/Boss.cpp index 49b0c0f5..32abed07 100644 --- a/src/Boss.cpp +++ b/src/Boss.cpp @@ -38,6 +38,8 @@ void PutBossChar(int fx, int fy) char a = 0; int b; + int side; + for (b = BOSS_MAX - 1; b >= 0; --b) { if (gBoss[b].cond & 0x80) @@ -57,7 +59,6 @@ void PutBossChar(int fx, int fy) } } - int side; if (gBoss[b].direct == 0) side = gBoss[b].view.front; else @@ -218,8 +219,8 @@ BOSSFUNCTION gpBossFuncTbl[10] = void ActBossChar(void) { - int bos; int code_char; + int bos; if (!(gBoss[0].cond & 0x80)) return; @@ -235,13 +236,12 @@ void ActBossChar(void) void HitBossMap(void) { + int x, y; + unsigned char atrb[16]; + int judg; int offx[16]; int offy[16]; - unsigned char atrb[16]; - int b; - int j; - int x; - int y; + int b, j; offx[0] = 0; offx[1] = 1; @@ -279,8 +279,6 @@ void HitBossMap(void) for (b = 0; b < BOSS_MAX; ++b) { - int judg; - if (!(gBoss[b].cond & 0x80)) continue; From de7ea5a251b1c4207bd51c44dfc2a6d7f3074e45 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 05:20:36 +0000 Subject: [PATCH 04/42] More-accurate BossAlmo2.cpp variable arrangement --- src/BossAlmo2.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/BossAlmo2.cpp b/src/BossAlmo2.cpp index d79f93fb..266b5540 100644 --- a/src/BossAlmo2.cpp +++ b/src/BossAlmo2.cpp @@ -178,14 +178,14 @@ static void ActBossCharA_Face(NPCHAR *npc) static void ActBossCharA_Mini(NPCHAR *npc) { - int deg; - RECT rect[3] = { {256, 0, 320, 40}, {256, 40, 320, 80}, {256, 80, 320, 120}, }; + int deg; + if (npc->cond == 0) return; @@ -284,16 +284,14 @@ static void ActBossCharA_Hit(NPCHAR *npc) void ActBossChar_Undead(void) { - int i; - int x; - int y; - - static int life; - static unsigned char flash; - NPCHAR *npc = gBoss; + static unsigned char flash; BOOL bShock = FALSE; + int x, y; + int i; + + static int life; switch (npc->act_no) { From 15f9297ec7c5e0230cd6fe03d611801a943274fe Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 05:23:10 +0000 Subject: [PATCH 05/42] More-accurate BossBallos.cpp variable arrangement --- src/BossBallos.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/BossBallos.cpp b/src/BossBallos.cpp index 81b3b33f..f5d39e43 100644 --- a/src/BossBallos.cpp +++ b/src/BossBallos.cpp @@ -135,14 +135,12 @@ static void ActBossChar_HARA(NPCHAR *npc) // "Hara" = "belly" or "stomach" (acco void ActBossChar_Ballos(void) { - static unsigned char flash; - - int i; - int x; - int y; - NPCHAR *npc = gBoss; + static unsigned char flash; + int i; + int x, y; + switch (npc->act_no) { case 0: From 3fdd459ad27a5e587f445587f03fd076262d65fe Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 05:25:24 +0000 Subject: [PATCH 06/42] More-accurate BossFrog.cpp variable arrangement --- src/BossFrog.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/BossFrog.cpp b/src/BossFrog.cpp index 29aa613f..24f1f41e 100644 --- a/src/BossFrog.cpp +++ b/src/BossFrog.cpp @@ -132,10 +132,9 @@ static void ActBossChar02_02(void) // Main boss AI void ActBossChar_Frog(void) { - int i; unsigned char deg; - int ym; - int xm; + int xm, ym; + int i; // Rects 1-4 are for when Balfrog is a frog, 5-8 for when he reverts into Balrog and goes into the ceiling RECT rcLeft[9] = { From d137369a93e9c9c80ccf6769f009e0f799182062 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 05:26:54 +0000 Subject: [PATCH 07/42] More-accurate BossIronH.cpp variable arrangement --- src/BossIronH.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/BossIronH.cpp b/src/BossIronH.cpp index e24822a1..816df71c 100644 --- a/src/BossIronH.cpp +++ b/src/BossIronH.cpp @@ -11,10 +11,9 @@ void ActBossChar_Ironhead(void) { - static unsigned char flash; int i; - NPCHAR *npc = gBoss; + static unsigned char flash; switch (npc->act_no) { From a22f4acd58f64a3ca9f3c3665c5d071429638f6e Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 05:29:21 +0000 Subject: [PATCH 08/42] More-accurate BossPress.cpp variable arrangement --- src/BossPress.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/BossPress.cpp b/src/BossPress.cpp index 067b5507..c219bad6 100644 --- a/src/BossPress.cpp +++ b/src/BossPress.cpp @@ -10,13 +10,11 @@ void ActBossChar_Press(void) { + NPCHAR *npc = gBoss; static unsigned char flash; - int i; int x; - NPCHAR *npc = gBoss; - switch (npc->act_no) { case 0: From c1abe80682e6763a773b9d1e1f4a2669ff6a78ea Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 05:31:03 +0000 Subject: [PATCH 09/42] More-accurate BossTwinD.cpp variable arrangement --- src/BossTwinD.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/BossTwinD.cpp b/src/BossTwinD.cpp index b6c05738..c50d4654 100644 --- a/src/BossTwinD.cpp +++ b/src/BossTwinD.cpp @@ -95,8 +95,7 @@ static void ActBossCharT_DragonBody(NPCHAR *npc) static void ActBossCharT_DragonHead(NPCHAR *npc) { unsigned char deg; - int ym; - int xm; + int xm, ym; RECT rcLeft[4] = { {0, 80, 40, 112}, From 1ea4031de8456683a0a93e2a7ece69f6f8c30858 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 05:34:05 +0000 Subject: [PATCH 10/42] More-accurate BossX.cpp variable-arrangement --- src/BossX.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/BossX.cpp b/src/BossX.cpp index b6d0f6f6..d107a886 100644 --- a/src/BossX.cpp +++ b/src/BossX.cpp @@ -212,8 +212,6 @@ static void ActBossChar03_01(NPCHAR *npc) static void ActBossChar03_02(NPCHAR *npc) { - int direct; - RECT rect[4] = { {0, 128, 72, 160}, {72, 128, 144, 160}, @@ -221,8 +219,8 @@ static void ActBossChar03_02(NPCHAR *npc) {72, 160, 144, 192}, }; - int x; - int y; + int direct; + int x, y; switch (npc->act_no) { @@ -360,9 +358,8 @@ static void ActBossChar03_03(NPCHAR *npc) static void ActBossChar03_04(NPCHAR *npc) { + int xm, ym; unsigned char deg; - int ym; - int xm; RECT rect[8] = { {0, 192, 16, 208}, @@ -436,14 +433,14 @@ static void ActBossChar03_04(NPCHAR *npc) static void ActBossChar03_face(NPCHAR *npc) { - static unsigned char flash; - RECT rect[3] = { {216, 0, 320, 48}, {216, 48, 320, 96}, {216, 144, 320, 192}, }; + static unsigned char flash; + switch (npc->act_no) { case 0: @@ -484,7 +481,6 @@ static void ActBossChar03_face(NPCHAR *npc) void ActBossChar_MonstX(void) { int i; - NPCHAR *npc = gBoss; switch (npc->act_no) From f33b7b386b943bbd087a4ee5d936c45b229dc392 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 05:37:40 +0000 Subject: [PATCH 11/42] More-accurate BulHit.cpp variable arrangement --- src/BulHit.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/BulHit.cpp b/src/BulHit.cpp index 1182687f..b6bb9f56 100644 --- a/src/BulHit.cpp +++ b/src/BulHit.cpp @@ -47,12 +47,12 @@ int JudgeHitBulletBlock(int x, int y, BULLET *bul) int JudgeHitBulletBlock2(int x, int y, unsigned char *atrb, BULLET *bul) { - int i; - int workX; - int workY; - int hit = 0; - BOOL block[4]; + int workX, workY; + int hit, i; + + hit = 0; + if (bul->bbits & 0x40) { for (i = 0; i < 4; ++i) @@ -324,12 +324,11 @@ int JudgeHitBulletTriangleH(int x, int y, BULLET *bul) void HitBulletMap(void) { - int i; - int j; - int x; - int y; + int x, y; unsigned char atrb[4]; + int i, j; + for (i = 0; i < BULLET_MAX; ++i) { int offx[4]; From 25369bcf67126de7ac1d1d9a93f8113c87d9d71f Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 05:51:54 +0000 Subject: [PATCH 12/42] More-accurate Bullet.cpp variable arrangement --- src/Bullet.cpp | 200 +++++++++++++++++++++++++------------------------ 1 file changed, 103 insertions(+), 97 deletions(-) diff --git a/src/Bullet.cpp b/src/Bullet.cpp index b5d472e3..668ec61f 100644 --- a/src/Bullet.cpp +++ b/src/Bullet.cpp @@ -12,56 +12,6 @@ #include "NpChar.h" #include "Sound.h" -BULLET_TABLE gBulTbl[46] = -{ - {0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}}, - {4, 1, 20, 36, 4, 4, 2, 2, {8, 8, 8, 8}}, - {6, 1, 23, 36, 4, 4, 2, 2, {8, 8, 8, 8}}, - {8, 1, 30, 36, 4, 4, 2, 2, {8, 8, 8, 8}}, - {1, 1, 8, 32, 6, 6, 2, 2, {8, 8, 8, 8}}, - {2, 1, 12, 32, 6, 6, 2, 2, {8, 8, 8, 8}}, - {4, 1, 16, 32, 6, 6, 2, 2, {8, 8, 8, 8}}, - {2, 2, 100, 8, 8, 16, 4, 2, {8, 8, 8, 8}}, - {3, 2, 100, 8, 4, 4, 4, 2, {8, 8, 8, 8}}, - {3, 2, 100, 8, 4, 4, 4, 2, {8, 8, 8, 8}}, - {2, 1, 20, 32, 2, 2, 2, 2, {8, 8, 8, 8}}, - {4, 1, 20, 32, 2, 2, 2, 2, {8, 8, 8, 8}}, - {6, 1, 20, 32, 2, 2, 2, 2, {8, 8, 8, 8}}, - {0, 10, 50, 40, 2, 2, 2, 2, {8, 8, 8, 8}}, - {0, 10, 70, 40, 4, 4, 4, 4, {8, 8, 8, 8}}, - {0, 10, 90, 40, 4, 4, 0, 0, {8, 8, 8, 8}}, - {1, 100, 100, 20, 16, 16, 0, 0, {0, 0, 0, 0}}, - {1, 100, 100, 20, 16, 16, 0, 0, {0, 0, 0, 0}}, - {1, 100, 100, 20, 16, 16, 0, 0, {0, 0, 0, 0}}, - {1, 1, 20, 8, 2, 2, 2, 2, {4, 4, 4, 4}}, - {2, 1, 20, 8, 2, 2, 2, 2, {4, 4, 4, 4}}, - {2, 1, 20, 8, 4, 4, 4, 4, {4, 4, 4, 4}}, - {3, 1, 32, 32, 2, 2, 2, 2, {4, 4, 4, 4}}, - {0, 100, 0, 36, 8, 8, 8, 8, {12, 12, 12, 12}}, - {127, 1, 2, 4, 8, 4, 8, 4, {0, 0, 0, 0}}, - {15, 1, 30, 36, 8, 8, 4, 2, {8, 8, 8, 8}}, - {6, 3, 18, 36, 10, 10, 4, 2, {12, 12, 12, 12}}, - {1, 100, 30, 36, 6, 6, 4, 4, {12, 12, 12, 12}}, - {0, 10, 30, 40, 2, 2, 2, 2, {8, 8, 8, 8}}, - {0, 10, 40, 40, 4, 4, 4, 4, {8, 8, 8, 8}}, - {0, 10, 40, 40, 4, 4, 0, 0, {8, 8, 8, 8}}, - {2, 100, 100, 20, 12, 12, 0, 0, {0, 0, 0, 0}}, - {2, 100, 100, 20, 12, 12, 0, 0, {0, 0, 0, 0}}, - {2, 100, 100, 20, 12, 12, 0, 0, {0, 0, 0, 0}}, - {4, 4, 20, 32, 4, 4, 3, 3, {8, 8, 24, 8}}, - {4, 2, 20, 32, 2, 2, 2, 2, {8, 8, 24, 8}}, - {1, 1, 20, 32, 2, 2, 2, 2, {8, 8, 24, 8}}, - {4, 4, 30, 64, 6, 6, 3, 3, {8, 8, 8, 8}}, - {8, 8, 30, 64, 6, 6, 3, 3, {8, 8, 8, 8}}, - {12, 12, 30, 64, 6, 6, 3, 3, {8, 8, 8, 8}}, - {3, 100, 30, 32, 6, 6, 3, 3, {4, 4, 4, 4}}, - {6, 100, 30, 32, 6, 6, 3, 3, {4, 4, 4, 4}}, - {11, 100, 30, 32, 6, 6, 3, 3, {4, 4, 4, 4}}, - {4, 4, 20, 32, 4, 4, 3, 3, {8, 8, 24, 8}}, - {0, 4, 4, 4, 0, 0, 0, 0, {0, 0, 0, 0}}, - {1, 1, 1, 36, 1, 1, 1, 1, {1, 1, 1, 1}} -}; - BULLET gBul[BULLET_MAX]; void InitBullet(void) @@ -150,6 +100,56 @@ void PutBullet(int fx, int fy) } } +BULLET_TABLE gBulTbl[46] = +{ + {0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}}, + {4, 1, 20, 36, 4, 4, 2, 2, {8, 8, 8, 8}}, + {6, 1, 23, 36, 4, 4, 2, 2, {8, 8, 8, 8}}, + {8, 1, 30, 36, 4, 4, 2, 2, {8, 8, 8, 8}}, + {1, 1, 8, 32, 6, 6, 2, 2, {8, 8, 8, 8}}, + {2, 1, 12, 32, 6, 6, 2, 2, {8, 8, 8, 8}}, + {4, 1, 16, 32, 6, 6, 2, 2, {8, 8, 8, 8}}, + {2, 2, 100, 8, 8, 16, 4, 2, {8, 8, 8, 8}}, + {3, 2, 100, 8, 4, 4, 4, 2, {8, 8, 8, 8}}, + {3, 2, 100, 8, 4, 4, 4, 2, {8, 8, 8, 8}}, + {2, 1, 20, 32, 2, 2, 2, 2, {8, 8, 8, 8}}, + {4, 1, 20, 32, 2, 2, 2, 2, {8, 8, 8, 8}}, + {6, 1, 20, 32, 2, 2, 2, 2, {8, 8, 8, 8}}, + {0, 10, 50, 40, 2, 2, 2, 2, {8, 8, 8, 8}}, + {0, 10, 70, 40, 4, 4, 4, 4, {8, 8, 8, 8}}, + {0, 10, 90, 40, 4, 4, 0, 0, {8, 8, 8, 8}}, + {1, 100, 100, 20, 16, 16, 0, 0, {0, 0, 0, 0}}, + {1, 100, 100, 20, 16, 16, 0, 0, {0, 0, 0, 0}}, + {1, 100, 100, 20, 16, 16, 0, 0, {0, 0, 0, 0}}, + {1, 1, 20, 8, 2, 2, 2, 2, {4, 4, 4, 4}}, + {2, 1, 20, 8, 2, 2, 2, 2, {4, 4, 4, 4}}, + {2, 1, 20, 8, 4, 4, 4, 4, {4, 4, 4, 4}}, + {3, 1, 32, 32, 2, 2, 2, 2, {4, 4, 4, 4}}, + {0, 100, 0, 36, 8, 8, 8, 8, {12, 12, 12, 12}}, + {127, 1, 2, 4, 8, 4, 8, 4, {0, 0, 0, 0}}, + {15, 1, 30, 36, 8, 8, 4, 2, {8, 8, 8, 8}}, + {6, 3, 18, 36, 10, 10, 4, 2, {12, 12, 12, 12}}, + {1, 100, 30, 36, 6, 6, 4, 4, {12, 12, 12, 12}}, + {0, 10, 30, 40, 2, 2, 2, 2, {8, 8, 8, 8}}, + {0, 10, 40, 40, 4, 4, 4, 4, {8, 8, 8, 8}}, + {0, 10, 40, 40, 4, 4, 0, 0, {8, 8, 8, 8}}, + {2, 100, 100, 20, 12, 12, 0, 0, {0, 0, 0, 0}}, + {2, 100, 100, 20, 12, 12, 0, 0, {0, 0, 0, 0}}, + {2, 100, 100, 20, 12, 12, 0, 0, {0, 0, 0, 0}}, + {4, 4, 20, 32, 4, 4, 3, 3, {8, 8, 24, 8}}, + {4, 2, 20, 32, 2, 2, 2, 2, {8, 8, 24, 8}}, + {1, 1, 20, 32, 2, 2, 2, 2, {8, 8, 24, 8}}, + {4, 4, 30, 64, 6, 6, 3, 3, {8, 8, 8, 8}}, + {8, 8, 30, 64, 6, 6, 3, 3, {8, 8, 8, 8}}, + {12, 12, 30, 64, 6, 6, 3, 3, {8, 8, 8, 8}}, + {3, 100, 30, 32, 6, 6, 3, 3, {4, 4, 4, 4}}, + {6, 100, 30, 32, 6, 6, 3, 3, {4, 4, 4, 4}}, + {11, 100, 30, 32, 6, 6, 3, 3, {4, 4, 4, 4}}, + {4, 4, 20, 32, 4, 4, 3, 3, {8, 8, 24, 8}}, + {0, 4, 4, 4, 0, 0, 0, 0, {0, 0, 0, 0}}, + {1, 1, 1, 36, 1, 1, 1, 1, {1, 1, 1, 1}} +}; + void SetBullet(int no, int x, int y, int dir) { int i = 0; @@ -246,6 +246,8 @@ void ActBullet_Frontia1(BULLET *bul) void ActBullet_Frontia2(BULLET *bul, int level) { + static unsigned int inc; + if (++bul->count1 > bul->life_count) { bul->cond = 0; @@ -274,7 +276,6 @@ void ActBullet_Frontia2(BULLET *bul, int level) break; } - static unsigned int inc; ++inc; switch (bul->direct) @@ -372,10 +373,6 @@ void ActBullet_Frontia2(BULLET *bul, int level) void ActBullet_PoleStar(BULLET *bul, int level) { - RECT rect1[2]; - RECT rect2[2]; - RECT rect3[2]; - if (++bul->count1 > bul->life_count) { bul->cond = 0; @@ -450,14 +447,20 @@ void ActBullet_PoleStar(BULLET *bul, int level) bul->y += bul->ym; } - SET_RECT(rect1[0], 128, 32, 144, 48) - SET_RECT(rect1[1], 144, 32, 160, 48) + RECT rect1[2] = { + {128, 32, 144, 48}, + {144, 32, 160, 48}, + }; - SET_RECT(rect2[0], 160, 32, 176, 48) - SET_RECT(rect2[1], 176, 32, 192, 48) + RECT rect2[2] = { + {160, 32, 176, 48}, + {176, 32, 192, 48}, + }; - SET_RECT(rect3[0], 128, 48, 144, 64) - SET_RECT(rect3[1], 144, 48, 160, 64) + RECT rect3[2] = { + {128, 48, 144, 64}, + {144, 48, 160, 64}, + }; //Set framerect switch (level) @@ -491,10 +494,6 @@ void ActBullet_PoleStar(BULLET *bul, int level) void ActBullet_FireBall(BULLET *bul, int level) { BOOL bBreak; - RECT rect_left1[4]; - RECT rect_right1[4]; - RECT rect_left2[3]; - RECT rect_right2[3]; if (++bul->count1 > bul->life_count) { @@ -585,23 +584,31 @@ void ActBullet_FireBall(BULLET *bul, int level) PlaySoundObject(34, 1); } - SET_RECT(rect_left1[0], 128, 0, 144, 16) - SET_RECT(rect_left1[1], 144, 0, 160, 16) - SET_RECT(rect_left1[2], 160, 0, 176, 16) - SET_RECT(rect_left1[3], 176, 0, 192, 16) + RECT rect_left1[4] = { + {128, 0, 144, 16}, + {144, 0, 160, 16}, + {160, 0, 176, 16}, + {176, 0, 192, 16}, + }; - SET_RECT(rect_right1[0], 128, 16, 144, 32) - SET_RECT(rect_right1[1], 144, 16, 160, 32) - SET_RECT(rect_right1[2], 160, 16, 176, 32) - SET_RECT(rect_right1[3], 176, 16, 192, 32) + RECT rect_right1[4] = { + {128, 16, 144, 32}, + {144, 16, 160, 32}, + {160, 16, 176, 32}, + {176, 16, 192, 32}, + }; - SET_RECT(rect_left2[0], 192, 16, 208, 32) - SET_RECT(rect_left2[1], 208, 16, 224, 32) - SET_RECT(rect_left2[2], 224, 16, 240, 32) + RECT rect_left2[3] = { + {192, 16, 208, 32}, + {208, 16, 224, 32}, + {224, 16, 240, 32}, + }; - SET_RECT(rect_right2[0], 224, 16, 240, 32) - SET_RECT(rect_right2[1], 208, 16, 224, 32) - SET_RECT(rect_right2[2], 192, 16, 208, 32) + RECT rect_right2[3] = { + {224, 16, 240, 32}, + {208, 16, 224, 32}, + {192, 16, 208, 32}, + }; ++bul->ani_no; @@ -734,6 +741,8 @@ void ActBullet_Missile(BULLET *bul, int level) { BOOL bHit; + static unsigned int inc; + if (++bul->count1 > bul->life_count) { bul->cond = 0; @@ -810,8 +819,6 @@ void ActBullet_Missile(BULLET *bul, int level) break; } - static unsigned int inc; - switch (++inc % 3) { case 0: @@ -992,8 +999,6 @@ void ActBullet_Bom(BULLET *bul, int level) void ActBullet_Bubblin1(BULLET *bul) { - RECT rect[4]; - if (bul->flag & 0x2FF) { bul->cond = 0; @@ -1050,10 +1055,12 @@ void ActBullet_Bubblin1(BULLET *bul) SetCaret(bul->x, bul->y, 15, 0); } - SET_RECT(rect[0], 192, 0, 200, 8) - SET_RECT(rect[1], 200, 0, 208, 8) - SET_RECT(rect[2], 208, 0, 216, 8) - SET_RECT(rect[3], 216, 0, 224, 8) + RECT rect[4] = { + {192, 0, 200, 8}, + {200, 0, 208, 8}, + {208, 0, 216, 8}, + {216, 0, 224, 8}, + }; if (++bul->ani_wait > 3) { @@ -1069,10 +1076,7 @@ void ActBullet_Bubblin1(BULLET *bul) void ActBullet_Bubblin2(BULLET *bul) { - BOOL bDelete; - RECT rect[4]; - - bDelete = FALSE; + BOOL bDelete = FALSE; if (bul->direct == 0 && bul->flag & 1) bDelete = TRUE; @@ -1143,10 +1147,12 @@ void ActBullet_Bubblin2(BULLET *bul) SetCaret(bul->x, bul->y, 15, 0); } - SET_RECT(rect[0], 192, 8, 200, 16) - SET_RECT(rect[1], 200, 8, 208, 16) - SET_RECT(rect[2], 208, 8, 216, 16) - SET_RECT(rect[3], 216, 8, 224, 16) + RECT rect[4] = { + {192, 8, 200, 16}, + {200, 8, 208, 16}, + {208, 8, 216, 16}, + {216, 8, 224, 16}, + }; if (++bul->ani_wait > 3) { @@ -1656,6 +1662,8 @@ void ActBullet_SuperMissile(BULLET *bul, int level) { BOOL bHit; + static unsigned int inc; + if (++bul->count1 > bul->life_count) { bul->cond = 0; @@ -1737,8 +1745,6 @@ void ActBullet_SuperMissile(BULLET *bul, int level) break; } - static unsigned int inc; - switch (++inc % 3) { case 0: From 0ceb8955d2a4f31e752f2e9d04b1a1c0cc55bd8e Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 05:54:44 +0000 Subject: [PATCH 13/42] More-accurate Caret.cpp variable arrangement --- src/Caret.cpp | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/src/Caret.cpp b/src/Caret.cpp index 20ce8381..0e1c178c 100644 --- a/src/Caret.cpp +++ b/src/Caret.cpp @@ -11,6 +11,27 @@ #define CARET_MAX 0x40 CARET gCrt[CARET_MAX]; +CARET_TABLE gCaretTable[18] = { + {0, 0}, + {0x800, 0x800}, + {0x1000, 0x1000}, + {0x1000, 0x1000}, + {0x1000, 0x1000}, + {0x800, 0x800}, + {0x1000, 0x1000}, + {0x800, 0x800}, + {0x1000, 0x1000}, + {0x1000, 0x1000}, + {0x3800, 0x1000}, + {0x800, 0x800}, + {0x2000, 0x2000}, + {0x800, 0x800}, + {0x2800, 0x2800}, + {0x800, 0x800}, + {0x2800, 0x800}, + {0x6800, 0x800} +}; + void InitCaret(void) { memset(gCrt, 0, sizeof(gCrt)); @@ -468,28 +489,6 @@ void ActCaret17(CARET *crt) crt->rect = rcLeft[1]; } -// Tables -CARET_TABLE gCaretTable[18] = { - {0, 0}, - {0x800, 0x800}, - {0x1000, 0x1000}, - {0x1000, 0x1000}, - {0x1000, 0x1000}, - {0x800, 0x800}, - {0x1000, 0x1000}, - {0x800, 0x800}, - {0x1000, 0x1000}, - {0x1000, 0x1000}, - {0x3800, 0x1000}, - {0x800, 0x800}, - {0x2000, 0x2000}, - {0x800, 0x800}, - {0x2800, 0x2800}, - {0x800, 0x800}, - {0x2800, 0x800}, - {0x6800, 0x800} -}; - typedef void (*CARETFUNCTION)(CARET*); CARETFUNCTION gpCaretFuncTbl[] = { From b1dbce8743be53305db50acf72410185352df46c Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 06:05:07 +0000 Subject: [PATCH 14/42] More-accurate Ending.cpp variable arrangement --- src/Ending.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Ending.cpp b/src/Ending.cpp index 70af5dbf..4c99411a 100644 --- a/src/Ending.cpp +++ b/src/Ending.cpp @@ -40,8 +40,8 @@ void ActionStripper(void) // Draw casts void PutStripper(void) { - RECT rc; int s; + RECT rc; for (s = 0; s < MAX_STRIP; ++s) { @@ -69,8 +69,8 @@ void PutStripper(void) // Create a cast object void SetStripper(int x, int y, const char *text, int cast) { - RECT rc; int s; + RECT rc; for (s = 0; s < MAX_STRIP; ++s) if (!(Strip[s].flag & 0x80)) @@ -99,8 +99,8 @@ void SetStripper(int x, int y, const char *text, int cast) // Regenerate cast text void RestoreStripper(void) { - RECT rc; int s; + RECT rc; for (s = 0; s < MAX_STRIP; ++s) { @@ -161,6 +161,8 @@ void ReloadIllust(int a) ReloadBitmap_Resource(name, SURFACE_ID_CREDITS_IMAGE); } +const char *credit_script = "Credit.tsc"; + // Initialize and release credits void InitCreditScript(void) { @@ -179,11 +181,12 @@ void ReleaseCreditScript(void) } } -const char *credit_script = "Credit.tsc"; - // Start playing credits BOOL StartCreditScript(void) { + FILE *fp; + char path[MAX_PATH]; + // Clear previously existing credits data if (Credit.pData != NULL) { @@ -192,7 +195,6 @@ BOOL StartCreditScript(void) } // Open file - char path[MAX_PATH]; sprintf(path, "%s\\%s", gDataPath, credit_script); Credit.size = GetFileSizeLong(path); @@ -204,7 +206,7 @@ BOOL StartCreditScript(void) if (Credit.pData == NULL) return FALSE; - FILE *fp = fopen(path, "rb"); + fp = fopen(path, "rb"); if (fp == NULL) { free(Credit.pData); @@ -441,6 +443,7 @@ void CutCreditIllust(void) // Scene of the island falling int Scene_DownIsland(HWND hWnd, int mode) { + ISLAND_SPRITE sprite; int wait; // Setup background @@ -451,7 +454,6 @@ int Scene_DownIsland(HWND hWnd, int mode) // Setup island RECT rc_sprite = {160, 0, 200, 24}; - ISLAND_SPRITE sprite; sprite.x = 168 * 0x200; sprite.y = 64 * 0x200; From b6d689aaa6415f931068260618c7353c917f072e Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 06:06:54 +0000 Subject: [PATCH 15/42] More-accurate Fade.cpp variable arrangement --- src/Fade.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Fade.cpp b/src/Fade.cpp index 9969a79e..cc8c48ba 100644 --- a/src/Fade.cpp +++ b/src/Fade.cpp @@ -42,8 +42,7 @@ void ClearFade(void) void StartFadeOut(signed char dir) { - int x; - int y; + int x, y; gFade.mode = 2; gFade.count = 0; @@ -62,8 +61,7 @@ void StartFadeOut(signed char dir) void StartFadeIn(signed char dir) { - int x; - int y; + int x, y; gFade.mode = 1; gFade.count = 0; @@ -84,8 +82,7 @@ void StartFadeIn(signed char dir) void ProcFade(void) { - int x; - int y; + int x, y; switch (gFade.mode) { @@ -236,8 +233,7 @@ void ProcFade(void) void PutFade(void) { - int x; - int y; + int x, y; RECT rect; rect.top = 0; From e0a8bd5114d7bfb849229358614a69df9ba50587 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 06:08:23 +0000 Subject: [PATCH 16/42] More-accurate Flash.cpp variable arrangement --- src/Flash.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Flash.cpp b/src/Flash.cpp index 64c3926c..3a606175 100644 --- a/src/Flash.cpp +++ b/src/Flash.cpp @@ -37,7 +37,7 @@ void SetFlash(int x, int y, int mode) void ActFlash_Explosion(int flx, int fly) { - int left, right, top, bottom; + int left, top, right, bottom; switch (flash.act_no) { From fb64e057cac60939f789aabf01e3fd2ac4d9aeff Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 06:09:46 +0000 Subject: [PATCH 17/42] More-accurate Frame.cpp variable arrangement --- src/Frame.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Frame.cpp b/src/Frame.cpp index 000163cd..7d8b5339 100644 --- a/src/Frame.cpp +++ b/src/Frame.cpp @@ -112,12 +112,13 @@ void GetFramePosition(int *fx, int *fy) void SetFramePosition(int fx, int fy) { + short map_w, map_l; + // End quake gFrame.quake = 0; gFrame.quake2 = 0; // Move frame position - short map_w, map_l; GetMapData(0, &map_w, &map_l); gFrame.x = fx; @@ -186,11 +187,12 @@ void SetFramePosition(int fx, int fy) void SetFrameMyChar(void) { - // Move frame position int mc_x, mc_y; + short map_w, map_l; + + // Move frame position GetMyCharPosition(&mc_x, &mc_y); - short map_w, map_l; GetMapData(0, &map_w, &map_l); gFrame.x = mc_x - ((WINDOW_WIDTH / 2) * 0x200); From 34bee5073f013db3b861bcb4596c5394d181dd0a Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 06:23:19 +0000 Subject: [PATCH 18/42] More-accurate Generic.cpp variable arrangement Also found some authentic variable names --- src/Generic.cpp | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/Generic.cpp b/src/Generic.cpp index e6db4928..e6ad9194 100644 --- a/src/Generic.cpp +++ b/src/Generic.cpp @@ -11,26 +11,28 @@ void GetCompileDate(int *year, int *month, int *day) { int i; - const char *months[13]; - char month_string[0x10]; + char strMonth[0x10]; - months[0] = "XXX"; - months[1] = "Jan"; - months[2] = "Feb"; - months[3] = "Mar"; - months[4] = "Apr"; - months[5] = "May"; - months[6] = "Jun"; - months[7] = "Jul"; - months[8] = "Aug"; - months[9] = "Sep"; - 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. TODO : Think about changing this to be reproductible + const char *table[13] = { + "XXX", + "Jan", + "Feb", + "Mar", + "Apr", + "May", + "Jun", + "Jul", + "Aug", + "Sep", + "Oct", + "Nov", + "Dec", + }; + + sscanf(__DATE__, "%s %d %d", strMonth, 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)) + if (!memcmp(&strMonth, table[i], 3)) break; *month = i; @@ -413,14 +415,17 @@ BOOL SaveWindowRect(HWND hWnd, const char *filename) return TRUE; } +const char *extra_text = "(C)Pixel"; + BOOL IsEnableBitmap(const char *path) { + FILE *fp; + long len; char str[16]; - static const char *extra_text = "(C)Pixel"; - const long len = (long)strlen(extra_text); + len = (long)strlen(extra_text); - FILE *fp = fopen(path, "rb"); + fp = fopen(path, "rb"); if (fp == NULL) return FALSE; From bd6f2fe81ded827b26bc3efe6b0b001f8e158ebb Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 06:25:12 +0000 Subject: [PATCH 19/42] More-accurate GenericLoad.cpp variable arrangement --- src/GenericLoad.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/GenericLoad.cpp b/src/GenericLoad.cpp index 92fc3d28..61149717 100644 --- a/src/GenericLoad.cpp +++ b/src/GenericLoad.cpp @@ -155,9 +155,8 @@ static const PIXTONEPARAMETER gPtpTable[139] = BOOL LoadGenericData(void) { - char str[0x40]; - BOOL bError; int pt_size; + BOOL bError; MakeSurface_Resource("PIXEL", SURFACE_ID_PIXEL); @@ -293,6 +292,8 @@ BOOL LoadGenericData(void) pt_size += MakePixToneObject(&gPtpTable[136], 1, 3); pt_size += MakePixToneObject(&gPtpTable[137], 1, 6); pt_size += MakePixToneObject(&gPtpTable[138], 1, 7); + + char str[0x40]; sprintf(str, "PixTone = %d byte", pt_size); // There must have been some kind of console print function here or something return TRUE; From d83665ff2af66813350aef8ebb6850e9e3aaf5e2 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 06:29:04 +0000 Subject: [PATCH 20/42] More-accurate Main.cpp variable arrangement --- src/Main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Main.cpp b/src/Main.cpp index 757575fb..68d793bb 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -27,14 +27,14 @@ LRESULT __stdcall WindowProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lPa char gModulePath[MAX_PATH]; char gDataPath[MAX_PATH]; -int gJoystickButtonTable[8]; - HWND ghWnd; BOOL bFullscreen; BOOL gbUseJoystick = FALSE; -static BOOL bFps = FALSE; +int gJoystickButtonTable[8]; + static BOOL bActive = TRUE; +static BOOL bFps = FALSE; static HANDLE hObject; static HANDLE hMutex; From 86412f052815b1f714370ff77bf24c05ee88cba2 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 06:40:58 +0000 Subject: [PATCH 21/42] More-accurate Map.cpp variable arrangement --- src/Map.cpp | 75 ++++++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/src/Map.cpp b/src/Map.cpp index f16ccc78..0657e620 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -16,7 +16,7 @@ MAP_DATA gMap; -static const char *code_pxma = "PXM"; +const char *code_pxma = "PXM"; BOOL InitMapData2(void) { @@ -26,19 +26,19 @@ BOOL InitMapData2(void) BOOL LoadMapData2(const char *path_map) { - unsigned char dum; + FILE *fp; + char check[3]; + char path[MAX_PATH]; // Get path - char path[MAX_PATH]; sprintf(path, "%s\\%s", gDataPath, path_map); // Open file - FILE *fp = fopen(path, "rb"); + fp = fopen(path, "rb"); if (fp == NULL) return FALSE; // Make sure file begins with "PXM" - char check[3]; fread(check, 1, 3, fp); if (memcmp(check, code_pxma, 3)) @@ -47,6 +47,7 @@ BOOL LoadMapData2(const char *path_map) return FALSE; } + unsigned char dum; fread(&dum, 1, 1, fp); // Get width and height // This fails on big-endian hardware, and platforms where short is not two bytes long. @@ -67,11 +68,13 @@ BOOL LoadMapData2(const char *path_map) BOOL LoadAttributeData(const char *path_atrb) { - // Open file + FILE *fp; char path[MAX_PATH]; + + // Open file sprintf(path, "%s\\%s", gDataPath, path_atrb); - FILE *fp = fopen(path, "rb"); + fp = fopen(path, "rb"); if (fp == NULL) return FALSE; @@ -105,10 +108,12 @@ void GetMapData(unsigned char **data, short *mw, short *ml) unsigned char GetAttribute(int x, int y) { + size_t a; + if (x < 0 || y < 0 || x >= gMap.width || y >= gMap.length) return 0; - const size_t a = *(gMap.data + x + (y * gMap.width)); // Yes, the original code really does do this instead of a regular array access + a = *(gMap.data + x + (y * gMap.width)); // Yes, the original code really does do this instead of a regular array access return gMap.atrb[a]; } @@ -139,21 +144,17 @@ BOOL ChangeMapParts(int x, int y, unsigned char no) void PutStage_Back(int fx, int fy) { - int num_y; - int put_x; - int put_y; - int i; - int j; - int offset; - int atrb; + int i, j; RECT rect; - int num_x; + int offset; // Get range to draw - num_x = ((WINDOW_WIDTH + (16 - 1)) / 16) + 1; - num_y = ((WINDOW_HEIGHT + (16 - 1)) / 16) + 1; - put_x = ((fx / 0x200) + 8) / 16; - put_y = ((fy / 0x200) + 8) / 16; + int num_x = ((WINDOW_WIDTH + (16 - 1)) / 16) + 1; + int num_y = ((WINDOW_HEIGHT + (16 - 1)) / 16) + 1; + int put_x = ((fx / 0x200) + 8) / 16; + int put_y = ((fy / 0x200) + 8) / 16; + + int atrb; for (j = put_y; j < put_y + num_y; ++j) { @@ -180,21 +181,17 @@ void PutStage_Back(int fx, int fy) void PutStage_Front(int fx, int fy) { RECT rcSnack = {256, 48, 272, 64}; - int num_y; - int put_x; - int put_y; - int j; - int i; - int offset; - int atrb; + int i, j; RECT rect; - int num_x; + int offset; // Get range to draw - num_x = ((WINDOW_WIDTH + (16 - 1)) / 16) + 1; - num_y = ((WINDOW_HEIGHT + (16 - 1)) / 16) + 1; - put_x = ((fx / 0x200) + 8) / 16; - put_y = ((fy / 0x200) + 8) / 16; + int num_x = ((WINDOW_WIDTH + (16 - 1)) / 16) + 1; + int num_y = ((WINDOW_HEIGHT + (16 - 1)) / 16) + 1; + int put_x = ((fx / 0x200) + 8) / 16; + int put_y = ((fy / 0x200) + 8) / 16; + + int atrb; for (j = put_y; j < put_y + num_y; ++j) { @@ -223,18 +220,20 @@ void PutStage_Front(int fx, int fy) void PutMapDataVector(int fx, int fy) { + int i, j; + RECT rect; + int offset; + + int num_x; int num_y; int put_x; int put_y; - int i; - int j; - int offset; + + static unsigned char count = 0; + int atrb; - RECT rect; - int num_x; // Animate the wind - static unsigned char count = 0; count += 2; // Get range to draw From 295e70ded843f11151b84f91b8bce4ddeab5dcb6 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 06:43:04 +0000 Subject: [PATCH 22/42] Correct a misnamed variable --- src/MapName.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/MapName.cpp b/src/MapName.cpp index d0f57bf5..f464d40b 100644 --- a/src/MapName.cpp +++ b/src/MapName.cpp @@ -129,9 +129,9 @@ void StartMapName(void) void RestoreMapName(void) { - int len = (int)strlen(gMapName.name); + int a = (int)strlen(gMapName.name); CortBox2(&rc, 0, SURFACE_ID_ROOM_NAME); - PutText2(((160 - (len * 6)) / 2) + 6, 1, gMapName.name, RGB(0x11, 0x00, 0x22), SURFACE_ID_ROOM_NAME); - PutText2(((160 - (len * 6)) / 2) + 6, 0, gMapName.name, RGB(0xFF, 0xFF, 0xFE), SURFACE_ID_ROOM_NAME); + PutText2(((160 - (a * 6)) / 2) + 6, 1, gMapName.name, RGB(0x11, 0x00, 0x22), SURFACE_ID_ROOM_NAME); + PutText2(((160 - (a * 6)) / 2) + 6, 0, gMapName.name, RGB(0xFF, 0xFF, 0xFE), SURFACE_ID_ROOM_NAME); } From 7c33b0ac5f40118d59629b6b711cb7c782262eea Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 06:47:55 +0000 Subject: [PATCH 23/42] More-accurate MiniMap.cpp variable arrangement --- src/MiniMap.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/MiniMap.cpp b/src/MiniMap.cpp index a5bb3d1c..e79a2af4 100644 --- a/src/MiniMap.cpp +++ b/src/MiniMap.cpp @@ -14,8 +14,6 @@ #include "MyChar.h" #include "Stage.h" -char gMapping[0x80]; - void WriteMiniMapLine(int line) { int x; @@ -77,16 +75,17 @@ void WriteMiniMapLine(int line) int MiniMapLoop(void) { - int f; - int line; - unsigned char my_wait; - - RECT rcMiniMap; + int f, line; RECT rcView; + RECT rcMiniMap; + int my_x; + int my_y; + unsigned char my_wait; RECT my_rect = {0, 57, 1, 58}; - int my_x = ((gMC.x / 0x200) + 8) / 16; - int my_y = ((gMC.y / 0x200) + 8) / 16; + + my_x = ((gMC.x / 0x200) + 8) / 16; + my_y = ((gMC.y / 0x200) + 8) / 16; for (f = 0; f <= 8; ++f) { @@ -211,6 +210,8 @@ int MiniMapLoop(void) return enum_ESCRETURN_continue; } +char gMapping[0x80]; + BOOL IsMapping(void) { if (!gMapping[gStageNo]) From f0273ecf3f0df7f8b9ee232de87af3cb789c699c Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 06:52:36 +0000 Subject: [PATCH 24/42] More-accurate MyChar.cpp variable arrangement --- src/MyChar.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/MyChar.cpp b/src/MyChar.cpp index 583a87b8..57b5dc20 100644 --- a/src/MyChar.cpp +++ b/src/MyChar.cpp @@ -19,9 +19,6 @@ MYCHAR gMC; -int noise_no; -unsigned int noise_freq; - void InitMyChar(void) { memset(&gMC, 0, sizeof(MYCHAR)); @@ -253,8 +250,7 @@ void ActMyChar_Normal(BOOL bKey) int dash2; int resist; - int a; - int x; + int a, x; if (gMC.cond & 2) return; @@ -933,6 +929,8 @@ int GetUnitMyChar(void) void SetMyCharDirect(unsigned char dir) { + int i; + if (dir == 3) { gMC.cond |= 1; @@ -947,8 +945,6 @@ void SetMyCharDirect(unsigned char dir) } else { - int i; - for (i = 0; i < NPC_MAX; ++i) if (gNPC[i].code_event == dir) break; @@ -990,6 +986,9 @@ void ResetCheck(void) gMC.cond &= ~1; } +int noise_no; +unsigned int noise_freq; + void SetNoise(int no, int freq) { noise_freq = freq; From 24b36ccda8e33dd7520040bd8b3a95c1067cf873 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 06:57:03 +0000 Subject: [PATCH 25/42] More-accurate MycHit.cpp variable arrangement --- src/MycHit.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/MycHit.cpp b/src/MycHit.cpp index 138ef4c1..77cfe04d 100644 --- a/src/MycHit.cpp +++ b/src/MycHit.cpp @@ -409,10 +409,12 @@ int JudgeHitMyCharVectDown(int x, int y) void HitMyCharMap(void) { + int x, y; int i; + unsigned char atrb[4]; - int x = gMC.x / 0x10 / 0x200; - int y = gMC.y / 0x10 / 0x200; + x = gMC.x / 0x10 / 0x200; + y = gMC.y / 0x10 / 0x200; int offx[4]; int offy[4]; @@ -427,7 +429,6 @@ void HitMyCharMap(void) offy[2] = 1; offy[3] = 1; - unsigned char atrb[4]; for (i = 0; i < 4; ++i) { atrb[i] = GetAttribute(x + offx[i], y + offy[i]); @@ -666,13 +667,13 @@ unsigned char JudgeHitMyCharNPC3(NPCHAR *npc) int JudgeHitMyCharNPC4(NPCHAR *npc) { // TODO: comment this + int hit = 0; + + float fy1; float fx1; float fx2; - float fy1; float fy2; - int hit = 0; - if (npc->x > gMC.x) fx1 = (float)(npc->x - gMC.x); else @@ -768,7 +769,6 @@ int JudgeHitMyCharNPC4(NPCHAR *npc) void HitMyCharNpChar(void) { int i; - int hit = 0; if (!(gMC.cond & 0x80) || gMC.cond & 2) @@ -859,7 +859,6 @@ void HitMyCharNpChar(void) void HitMyCharBoss(void) { int b; - int hit = 0; if (!(gMC.cond & 0x80) || gMC.cond & 2) From e978543dad27684e72e607bf11c54fc822ebb631 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 07:05:26 +0000 Subject: [PATCH 26/42] More-accurate MycParam.cpp variable arrangement --- src/MycParam.cpp | 56 +++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/src/MycParam.cpp b/src/MycParam.cpp index 74d17afa..5581ce4c 100644 --- a/src/MycParam.cpp +++ b/src/MycParam.cpp @@ -34,8 +34,6 @@ ARMS_LEVEL gArmsLevelTable[14] = {{40, 60, 200}} }; -int time_count; - void AddExpMyChar(int x) { int lv = gArmsData[gSelectedArms].level - 1; @@ -93,9 +91,11 @@ void ZeroExpMyChar(void) BOOL IsMaxExpMyChar(void) { + int arms_code; + if (gArmsData[gSelectedArms].level == 3) { - int arms_code = gArmsData[gSelectedArms].code; + arms_code = gArmsData[gSelectedArms].code; if (gArmsData[gSelectedArms].exp >= gArmsLevelTable[arms_code].exp[2]) return TRUE; @@ -232,15 +232,7 @@ void AddMaxLifeMyChar(int val) void PutArmsEnergy(BOOL flash) { - RECT rcExpBox; - RECT rcExpVal; - RECT rcExpMax; - RECT rcExpFlash; - - int lv; - int arms_code; - int exp_now; - int exp_next; + static unsigned char add_flash; RECT rcPer = {72, 48, 80, 56}; RECT rcLv = {80, 80, 96, 88}; @@ -272,15 +264,15 @@ void PutArmsEnergy(BOOL flash) PutBitmap3(&rcView, gArmsEnergyX, 32, &rcLv, SURFACE_ID_TEXT_BOX); PutNumber4(gArmsEnergyX - 8, 32, gArmsData[gSelectedArms].level, FALSE); - SET_RECT(rcExpBox, 0, 72, 40, 80) - SET_RECT(rcExpVal, 0, 80, 0, 88) - SET_RECT(rcExpMax, 40, 72, 80, 80) - SET_RECT(rcExpFlash, 40, 80, 80, 88) + RECT rcExpBox = {0, 72, 40, 80}; + RECT rcExpVal = {0, 80, 0, 88}; + RECT rcExpMax = {40, 72, 80, 80}; + RECT rcExpFlash = {40, 80, 80, 88}; - lv = gArmsData[gSelectedArms].level - 1; - arms_code = gArmsData[gSelectedArms].code; - exp_now = gArmsData[gSelectedArms].exp; - exp_next = gArmsLevelTable[arms_code].exp[lv]; + int lv = gArmsData[gSelectedArms].level - 1; + int arms_code = gArmsData[gSelectedArms].code; + int exp_now = gArmsData[gSelectedArms].exp; + int exp_next = gArmsLevelTable[arms_code].exp[lv]; PutBitmap3(&rcView, gArmsEnergyX + 24, 32, &rcExpBox, SURFACE_ID_TEXT_BOX); @@ -298,7 +290,6 @@ void PutArmsEnergy(BOOL flash) PutBitmap3(&rcView, gArmsEnergyX + 24, 32, &rcExpVal, SURFACE_ID_TEXT_BOX); } - static unsigned char add_flash; if (gMC.exp_wait && ((add_flash++ / 2) % 2)) PutBitmap3(&rcView, gArmsEnergyX + 24, 32, &rcExpFlash, SURFACE_ID_TEXT_BOX); } @@ -307,10 +298,9 @@ void PutActiveArmsList(void) { int x; int a; - int arms_num; RECT rect = {0, 0, 0, 16}; - arms_num = 0; + int arms_num = 0; while (gArmsData[arms_num].code != 0) ++arms_num; @@ -396,6 +386,8 @@ void PutMyAir(int x, int y) } } +int time_count; + void PutTimeCounter(int x, int y) { RECT rcTime[3] = { @@ -436,20 +428,20 @@ void PutTimeCounter(int x, int y) BOOL SaveTimeCounter(void) { - unsigned char *p; int i; - + unsigned char *p; REC rec; + FILE *fp; + char path[MAX_PATH]; // Quit if player doesn't have the Nikumaru Counter if (!(gMC.equip & 0x100)) return TRUE; // Get last time - char path[MAX_PATH]; sprintf(path, "%s\\290.rec", gModulePath); - FILE *fp = fopen(path, "rb"); + fp = fopen(path, "rb"); if (fp) { // Read data @@ -491,19 +483,19 @@ BOOL SaveTimeCounter(void) int LoadTimeCounter(void) { - unsigned char *p; int i; + unsigned char *p; + REC rec; + FILE *fp; + char path[MAX_PATH]; // Open file - char path[MAX_PATH]; sprintf(path, "%s\\290.rec", gModulePath); - FILE *fp = fopen(path, "rb"); + fp = fopen(path, "rb"); if (!fp) return 0; - REC rec; - // Read data fread(&rec, sizeof(REC), 1, fp); fclose(fp); From 6d400cfcd41adcfd1e24dc9256b54e0494c261ab Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 07:06:02 +0000 Subject: [PATCH 27/42] Minor code style tweak --- src/MycParam.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/MycParam.cpp b/src/MycParam.cpp index 5581ce4c..8bba62f1 100644 --- a/src/MycParam.cpp +++ b/src/MycParam.cpp @@ -516,9 +516,7 @@ int LoadTimeCounter(void) time_count = 0; return 0; } - else - { - time_count = rec.counter[0]; - return time_count; - } + + time_count = rec.counter[0]; + return time_count; } From 6e20f4cc154a4dd502029519bdb91102f4683c02 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 07:10:30 +0000 Subject: [PATCH 28/42] More-accurate NpcAct000.cpp variable arrangement --- src/NpcAct000.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/NpcAct000.cpp b/src/NpcAct000.cpp index 9e23ec8f..901e0691 100644 --- a/src/NpcAct000.cpp +++ b/src/NpcAct000.cpp @@ -917,8 +917,7 @@ void ActNpc009(NPCHAR *npc) void ActNpc010(NPCHAR *npc) { unsigned char deg; - int ym; - int xm; + int xm, ym; switch (npc->act_no) { @@ -1075,8 +1074,7 @@ void ActNpc011(NPCHAR *npc) void ActNpc012(NPCHAR *npc) { int i; - int x; - int y; + int x, y; switch (npc->act_no) { @@ -1429,14 +1427,14 @@ void ActNpc013(NPCHAR *npc) // Santa's Key void ActNpc014(NPCHAR *npc) { - int i; - RECT rect[3] = { {192, 0, 208, 16}, {208, 0, 224, 16}, {224, 0, 240, 16}, }; + int i; + switch (npc->act_no) { case 0: @@ -1474,14 +1472,14 @@ void ActNpc014(NPCHAR *npc) // Chest (closed) void ActNpc015(NPCHAR *npc) { - int i; - RECT rcLeft[3] = { {240, 0, 256, 16}, {256, 0, 272, 16}, {272, 0, 288, 16}, }; + int i; + switch (npc->act_no) { case 0: @@ -1533,8 +1531,6 @@ void ActNpc015(NPCHAR *npc) // Save point void ActNpc016(NPCHAR *npc) { - int i; - RECT rect[8] = { {96, 16, 112, 32}, {112, 16, 128, 32}, @@ -1546,6 +1542,8 @@ void ActNpc016(NPCHAR *npc) {208, 16, 224, 32}, }; + int i; + switch (npc->act_no) { case 0: From affaf25e5c26b00e2e2126b391f40e0775c30328 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 20:35:15 +0000 Subject: [PATCH 29/42] Sorted out the other NPCs' variables too --- src/NpcAct020.cpp | 5 ++--- src/NpcAct040.cpp | 9 ++++----- src/NpcAct060.cpp | 4 ++-- src/NpcAct080.cpp | 3 +-- src/NpcAct100.cpp | 8 +++++--- src/NpcAct120.cpp | 3 +-- src/NpcAct140.cpp | 10 ++++------ src/NpcAct160.cpp | 3 +-- src/NpcAct180.cpp | 7 +++---- src/NpcAct200.cpp | 7 +++---- src/NpcAct220.cpp | 4 ++-- src/NpcAct240.cpp | 13 +++++++------ src/NpcAct260.cpp | 22 ++++++++-------------- src/NpcAct280.cpp | 17 +++++------------ src/NpcAct300.cpp | 20 ++++++++++---------- src/NpcAct320.cpp | 6 +++--- src/NpcAct340.cpp | 14 ++++++-------- 17 files changed, 67 insertions(+), 88 deletions(-) diff --git a/src/NpcAct020.cpp b/src/NpcAct020.cpp index 8aa60869..831de00a 100644 --- a/src/NpcAct020.cpp +++ b/src/NpcAct020.cpp @@ -1096,10 +1096,9 @@ void ActNpc035(NPCHAR *npc) // Balrog (hover) void ActNpc036(NPCHAR *npc) { - unsigned char deg; - int ym; - int xm; int i; + unsigned char deg; + int xm, ym; switch (npc->act_no) { diff --git a/src/NpcAct040.cpp b/src/NpcAct040.cpp index efa1b44e..05ba33f5 100644 --- a/src/NpcAct040.cpp +++ b/src/NpcAct040.cpp @@ -118,6 +118,8 @@ void ActNpc041(NPCHAR *npc) // Sue void ActNpc042(NPCHAR *npc) { + int n; + RECT rcLeft[13] = { {0, 0, 16, 16}, {16, 0, 32, 16}, @@ -150,8 +152,6 @@ void ActNpc042(NPCHAR *npc) {160, 48, 176, 64}, }; - int n; - switch (npc->act_no) { case 0: @@ -870,8 +870,7 @@ void ActNpc048(NPCHAR *npc) void ActNpc049(NPCHAR *npc) { unsigned char deg; - int ym; - int xm; + int xm, ym; if (npc->act_no >= 10 && npc->pNpc->code_char == 3) { @@ -1916,8 +1915,8 @@ void ActNpc058(NPCHAR *npc) if ((++npc->count2 % 8) == 0 && npc->x < gMC.x + (160 * 0x200) && npc->x > gMC.x - (160 * 0x200)) // TODO: Maybe do something about this for widescreen { unsigned char deg; - int ym; int xm; + int ym; deg = GetArktan(npc->x - gMC.x, npc->y - gMC.y); deg += (unsigned char)Random(-6, 6); diff --git a/src/NpcAct060.cpp b/src/NpcAct060.cpp index c9ab0083..df3569e2 100644 --- a/src/NpcAct060.cpp +++ b/src/NpcAct060.cpp @@ -199,6 +199,8 @@ void ActNpc060(NPCHAR *npc) // King void ActNpc061(NPCHAR *npc) { + int i; + RECT rcLeft[11] = { {224, 32, 240, 48}, {240, 32, 256, 48}, @@ -227,8 +229,6 @@ void ActNpc061(NPCHAR *npc) {112, 32, 128, 48}, }; - int i; - switch (npc->act_no) { case 0: diff --git a/src/NpcAct080.cpp b/src/NpcAct080.cpp index 03183775..35c8d9cb 100644 --- a/src/NpcAct080.cpp +++ b/src/NpcAct080.cpp @@ -877,8 +877,7 @@ void ActNpc088(NPCHAR *npc) { int i; unsigned char deg; - int xm; - int ym; + int xm, ym; RECT rcLeft[12] = { {0, 0, 40, 40}, diff --git a/src/NpcAct100.cpp b/src/NpcAct100.cpp index 0c7ec627..2ee69c83 100644 --- a/src/NpcAct100.cpp +++ b/src/NpcAct100.cpp @@ -1068,14 +1068,14 @@ void ActNpc113(NPCHAR *npc) // Press void ActNpc114(NPCHAR *npc) { - int i; - RECT rcLeft[3] = { {144, 112, 160, 136}, {160, 112, 176, 136}, {176, 112, 192, 136}, }; + int i; + switch (npc->act_no) { case 0: @@ -1521,6 +1521,8 @@ void ActNpc117(NPCHAR *npc) // Curly (boss) void ActNpc118(NPCHAR *npc) { + BOOL bUpper; + RECT rcLeft[9] = { {0, 32, 32, 56}, {32, 32, 64, 56}, @@ -1545,7 +1547,7 @@ void ActNpc118(NPCHAR *npc) {160, 56, 192, 80}, }; - BOOL bUpper = FALSE; + bUpper = FALSE; if (npc->direct == 0 && npc->x < gMC.x) bUpper = TRUE; diff --git a/src/NpcAct120.cpp b/src/NpcAct120.cpp index 0d8c1f05..1e0516e5 100644 --- a/src/NpcAct120.cpp +++ b/src/NpcAct120.cpp @@ -1090,8 +1090,7 @@ void ActNpc134(NPCHAR *npc) void ActNpc135(NPCHAR *npc) { unsigned char deg; - int ym; - int xm; + int xm, ym; RECT rcLeft[2] = { {256, 32, 288, 64}, diff --git a/src/NpcAct140.cpp b/src/NpcAct140.cpp index 607fc47d..d2f71171 100644 --- a/src/NpcAct140.cpp +++ b/src/NpcAct140.cpp @@ -764,9 +764,8 @@ void ActNpc146(NPCHAR *npc) // Critter (purple) void ActNpc147(NPCHAR *npc) { + int xm, ym; unsigned char deg; - int xm; - int ym; RECT rcLeft[6] = { {0, 96, 16, 112}, @@ -1349,7 +1348,7 @@ void ActNpc152(NPCHAR *npc) npc->rect = rc; } -static const RECT grcKitL[21] = { +const RECT grcKitL[21] = { {0, 0, 24, 24}, {24, 0, 48, 24}, {48, 0, 72, 24}, @@ -1373,7 +1372,7 @@ static const RECT grcKitL[21] = { {96, 48, 120, 72} }; -static const RECT grcKitR[21] = { +const RECT grcKitR[21] = { {0, 24, 24, 48}, {24, 24, 48, 48}, {48, 24, 72, 48}, @@ -1624,8 +1623,7 @@ void ActNpc154(NPCHAR *npc) void ActNpc155(NPCHAR *npc) { unsigned char deg; - int ym; - int xm; + int xm, ym; if (npc->x > gMC.x + (((WINDOW_WIDTH / 2) + 160) * 0x200) || npc->x < gMC.x - (((WINDOW_WIDTH / 2) + 160) * 0x200) || npc->y > gMC.y + (((WINDOW_HEIGHT / 2) + 120) * 0x200) || npc->y < gMC.y - (((WINDOW_HEIGHT / 2) + 120) * 0x200)) return; diff --git a/src/NpcAct160.cpp b/src/NpcAct160.cpp index fa556095..a4dc6f80 100644 --- a/src/NpcAct160.cpp +++ b/src/NpcAct160.cpp @@ -1071,8 +1071,7 @@ void ActNpc172(NPCHAR *npc) void ActNpc173(NPCHAR *npc) { unsigned char deg; - int xm; - int ym; + int xm, ym; RECT rcLeft[4] = { {0, 128, 24, 152}, diff --git a/src/NpcAct180.cpp b/src/NpcAct180.cpp index 2d362ff3..8e3651c6 100644 --- a/src/NpcAct180.cpp +++ b/src/NpcAct180.cpp @@ -19,8 +19,7 @@ // Curly AI void ActNpc180(NPCHAR *npc) { - int xx; - int yy; + int xx, yy; RECT rcLeft[11] = { {0, 96, 16, 112}, @@ -978,13 +977,13 @@ void ActNpc189(NPCHAR *npc) // Broken robot void ActNpc190(NPCHAR *npc) { - int i; - RECT rect[2] = { {192, 32, 208, 48}, {208, 32, 224, 48}, }; + int i; + switch (npc->act_no) { case 0: diff --git a/src/NpcAct200.cpp b/src/NpcAct200.cpp index 61219dc2..2fdd8be7 100644 --- a/src/NpcAct200.cpp +++ b/src/NpcAct200.cpp @@ -17,8 +17,7 @@ void ActNpc200(NPCHAR *npc) { unsigned char deg; - int ym; - int xm; + int xm, ym; RECT rcLeft[6] = { {0, 0, 40, 40}, @@ -475,8 +474,8 @@ void ActNpc206(NPCHAR *npc) case 3: switch (npc->act_wait) { - // Interestingly, this NPC counts down at 60 frames per second, - // while the NPC322 (Deleet), counts at 50. + // Interestingly, this NPC counts down at 60 frames + // per second, while NPC322 (Deleet) counts at 50. case 60 * 0: SetNpChar(207, npc->x + (16 * 0x200), npc->y + (4 * 0x200), 0, 0, 0, NULL, 0x100); break; diff --git a/src/NpcAct220.cpp b/src/NpcAct220.cpp index d51fbfe7..07628d3a 100644 --- a/src/NpcAct220.cpp +++ b/src/NpcAct220.cpp @@ -1129,11 +1129,11 @@ void ActNpc236(NPCHAR *npc) // Gunfish projectile void ActNpc237(NPCHAR *npc) { + RECT rc = {312, 32, 320, 40}; + int i; BOOL bHit; - RECT rc = {312, 32, 320, 40}; - switch (npc->act_no) { case 0: diff --git a/src/NpcAct240.cpp b/src/NpcAct240.cpp index 957aff0e..a92a310e 100644 --- a/src/NpcAct240.cpp +++ b/src/NpcAct240.cpp @@ -318,12 +318,14 @@ void ActNpc243(NPCHAR *npc) // Lava drop void ActNpc244(NPCHAR *npc) { + RECT rc = {96, 0, 104, 16}; + BOOL bHit; + int i; - RECT rc = {96, 0, 104, 16}; npc->ym += 0x40; - BOOL bHit = FALSE; + bHit = FALSE; if (npc->flag & 0xFF) bHit = TRUE; @@ -411,14 +413,14 @@ void ActNpc245(NPCHAR *npc) // Press (proximity) void ActNpc246(NPCHAR *npc) { - int i; - RECT rcLeft[3] = { {144, 112, 160, 136}, {160, 112, 176, 136}, {176, 112, 192, 136}, }; + int i; + switch (npc->act_no) { case 0: @@ -504,8 +506,7 @@ void ActNpc246(NPCHAR *npc) void ActNpc247(NPCHAR *npc) { unsigned char deg; - int ym; - int xm; + int xm, ym; RECT rcLeft[9] = { {0, 0, 16, 16}, diff --git a/src/NpcAct260.cpp b/src/NpcAct260.cpp index 485c1267..fe7e81e2 100644 --- a/src/NpcAct260.cpp +++ b/src/NpcAct260.cpp @@ -186,8 +186,7 @@ void ActNpc262(NPCHAR *npc) void ActNpc263(NPCHAR *npc) { int deg; - int xm; - int ym; + int xm, ym; RECT rcLeft[9] = { {0, 0, 24, 32}, @@ -469,9 +468,8 @@ void ActNpc263(NPCHAR *npc) // Doctor red wave (projectile) void ActNpc264(NPCHAR *npc) { - unsigned char deg; - RECT rc = {288, 0, 304, 16}; + unsigned char deg; if (npc->x < 0 || npc->x > gMap.width * 0x10 * 0x200) { @@ -597,8 +595,7 @@ void ActNpc267(NPCHAR *npc) {40, 160, 80, 208}, }; - int ym; - int xm; + int xm, ym; int i; switch (npc->act_no) @@ -1133,8 +1130,7 @@ void ActNpc267(NPCHAR *npc) void ActNpc268(NPCHAR *npc) { unsigned char deg; - int ym; - int xm; + int xm, ym; RECT rcLeft[10] = { {0, 0, 40, 40}, @@ -1631,8 +1627,7 @@ void ActNpc274(NPCHAR *npc) }; unsigned char deg; - int ym; - int xm; + int xm, ym; switch (npc->act_no) { @@ -1825,8 +1820,7 @@ void ActNpc276(NPCHAR *npc) }; unsigned char deg; - int ym; - int xm; + int xm, ym; switch (npc->act_no) { @@ -2158,13 +2152,13 @@ void ActNpc278(NPCHAR *npc) // Falling block (large) void ActNpc279(NPCHAR *npc) { - int i; - RECT rc[2] = { {0, 16, 32, 48}, {16, 0, 32, 16}, }; + int i; + switch (npc->act_no) { case 0: diff --git a/src/NpcAct280.cpp b/src/NpcAct280.cpp index 76d89476..111902e3 100644 --- a/src/NpcAct280.cpp +++ b/src/NpcAct280.cpp @@ -129,6 +129,7 @@ void ActNpc281(NPCHAR *npc) // Mini Undead Core (active) void ActNpc282(NPCHAR *npc) { + // Yes, Pixel spelt this wrong (should be 'rc') RECT tc[3] = { {256, 80, 320, 120}, {256, 0, 320, 40}, @@ -203,9 +204,7 @@ void ActNpc282(NPCHAR *npc) // Misery (transformed) void ActNpc283(NPCHAR *npc) { - int x; - int y; - int direct; + int x, y, direct; RECT rcLeft[11] = { {0, 64, 32, 96}, @@ -966,6 +965,7 @@ void ActNpc284(NPCHAR *npc) void ActNpc285(NPCHAR *npc) { RECT rc = {232, 104, 248, 120}; + unsigned char deg; if (npc->x < 0 || npc->x > gMap.width * 0x10 * 0x200) { @@ -973,8 +973,6 @@ void ActNpc285(NPCHAR *npc) return; } - unsigned char deg; - switch (npc->act_no) { case 0: @@ -1422,9 +1420,7 @@ void ActNpc293(NPCHAR *npc) // Quake + falling block generator void ActNpc294(NPCHAR *npc) { - int x; - int y; - int dir; + int x, y, dir; switch (npc->act_no) { @@ -1567,10 +1563,7 @@ void ActNpc295(NPCHAR *npc) // Cloud generator void ActNpc296(NPCHAR *npc) { - int x; - int y; - int dir; - int pri; + int x, y, dir, pri; if (++npc->act_wait > 16) { diff --git a/src/NpcAct300.cpp b/src/NpcAct300.cpp index fa1feaef..3ee8e87e 100644 --- a/src/NpcAct300.cpp +++ b/src/NpcAct300.cpp @@ -35,6 +35,8 @@ void ActNpc300(NPCHAR *npc) // Fish missile (Misery) void ActNpc301(NPCHAR *npc) { + int dir; + RECT rect[8] = { {144, 0, 160, 16}, {160, 0, 176, 16}, @@ -46,8 +48,6 @@ void ActNpc301(NPCHAR *npc) {192, 16, 208, 32}, }; - int dir; - switch (npc->act_no) { case 0: @@ -102,6 +102,8 @@ void ActNpc301(NPCHAR *npc) // Camera focus marker void ActNpc302(NPCHAR *npc) { + int n; + switch (npc->act_no) { case 10: @@ -143,18 +145,16 @@ void ActNpc302(NPCHAR *npc) if (npc->direct != 0) { - int i; - - for (i = 0xAA; i < 0x200; ++i) + for (n = 0xAA; n < 0x200; ++n) { - if (gNPC[i].cond & 0x80 && gNPC[i].code_event == npc->direct) + if (gNPC[n].cond & 0x80 && gNPC[n].code_event == npc->direct) { - npc->pNpc = &gNPC[i]; + npc->pNpc = &gNPC[n]; break; } } - if (i == 0x200) + if (n == 0x200) { npc->cond = 0; break; @@ -401,6 +401,8 @@ void ActNpc307(NPCHAR *npc) // Stumpy void ActNpc308(NPCHAR *npc) { + unsigned char deg; + RECT rcLeft[2] = { {128, 112, 144, 128}, {144, 112, 160, 128}, @@ -411,8 +413,6 @@ void ActNpc308(NPCHAR *npc) {144, 128, 160, 144}, }; - unsigned char deg; - switch (npc->act_no) { case 0: diff --git a/src/NpcAct320.cpp b/src/NpcAct320.cpp index 7e1cb3c9..89e6f621 100644 --- a/src/NpcAct320.cpp +++ b/src/NpcAct320.cpp @@ -220,7 +220,7 @@ void ActNpc322(NPCHAR *npc) switch (npc->act_wait) { // Interestingly, this NPC counts down at 50 frames per second, - // while the NPC206 (the Egg Corridor Counter Bomb), counts at 60. + // while NPC206 (the Egg Corridor Counter Bomb), counts at 60. case 50 * 0: SetNpChar(207, npc->x + (4 * 0x200), npc->y, 0, 0, 0, NULL, 0x180); break; @@ -801,14 +801,14 @@ void ActNpc331(NPCHAR *npc) // Ballos shockwave void ActNpc332(NPCHAR *npc) { - int xm; - RECT rc[3] = { {144, 96, 168, 120}, {168, 96, 192, 120}, {192, 96, 216, 120}, }; + int xm; + switch (npc->act_no) { case 0: diff --git a/src/NpcAct340.cpp b/src/NpcAct340.cpp index 3b174ef5..32918b9a 100644 --- a/src/NpcAct340.cpp +++ b/src/NpcAct340.cpp @@ -592,7 +592,6 @@ void ActNpc341(NPCHAR *npc) void ActNpc342(NPCHAR *npc) { static int flash; - unsigned char deg; RECT rc[3] = { {240, 48, 280, 88}, @@ -600,6 +599,8 @@ void ActNpc342(NPCHAR *npc) {280, 48, 320, 88}, }; + unsigned char deg; + if (npc->act_no < 1000 && npc->pNpc->act_no >= 1000) npc->act_no = 1000; @@ -905,8 +906,6 @@ void ActNpc344(NPCHAR *npc) // Ballos skull projectile void ActNpc345(NPCHAR *npc) { - int i; - RECT rc[4] = { {128, 176, 144, 192}, {144, 176, 160, 192}, @@ -914,6 +913,8 @@ void ActNpc345(NPCHAR *npc) {176, 176, 192, 192}, }; + int i; + switch (npc->act_no) { case 0: @@ -974,9 +975,8 @@ void ActNpc345(NPCHAR *npc) // Ballos 4 orbiting platform void ActNpc346(NPCHAR *npc) { - unsigned char deg; - RECT rc = {240, 0, 272, 16}; + unsigned char deg; if (npc->act_no < 1000 && npc->pNpc->act_no >= 1000) npc->act_no = 1000; @@ -1724,9 +1724,7 @@ void ActNpc353(NPCHAR *npc) // Invisible deathtrap wall void ActNpc354(NPCHAR *npc) { - int i; - int x; - int y; + int i, x, y; switch (npc->act_no) { From 63e855c7fa89701ac571c7d3952a2a7875b1371d Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 20:48:21 +0000 Subject: [PATCH 30/42] More-accurate NpChar.cpp variable arrangement --- src/NpChar.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/NpChar.cpp b/src/NpChar.cpp index 64a02467..c0ee42d7 100644 --- a/src/NpChar.cpp +++ b/src/NpChar.cpp @@ -52,14 +52,13 @@ void SetUniqueParameter(NPCHAR *npc) BOOL LoadEvent(const char *path_event) { + int i, n; FILE *fp; int count; - int i; - int n; - EVENT eve; - char path[MAX_PATH]; char code[4]; + EVENT eve; + char path[MAX_PATH]; sprintf(path, "%s\\%s", gDataPath, path_event); fp = fopen(path, "rb"); @@ -189,8 +188,10 @@ void SetDestroyNpCharUp(int x, int y, int w, int num) void SetExpObjects(int x, int y, int exp) { + int n; int sub_exp; - int n = 0x100; + + n = 0x100; while (exp) { while (n < NPC_MAX && gNPC[n].cond) @@ -310,8 +311,10 @@ BOOL SetLifeObject(int x, int y, int val) void VanishNpChar(NPCHAR *npc) { - int x = npc->x; - int y = npc->y; + int x, y; + + x = npc->x; + y = npc->y; memset(npc, 0, sizeof(NPCHAR)); npc->count1 = 0; npc->x = x; @@ -329,12 +332,12 @@ void PutNpChar(int fx, int fy) int n; signed char a = 0; + int side; + for (n = 0; n < NPC_MAX; ++n) { if (gNPC[n].cond & 0x80) { - int side; - if (gNPC[n].shock) { a = 2 * ((gNPC[n].shock / 2) % 2) - 1; @@ -367,12 +370,13 @@ void PutNpChar(int fx, int fy) void ActNpChar(void) { int i; + int code_char; for (i = 0; i < NPC_MAX; ++i) { if (gNPC[i].cond & 0x80) { - int code_char = gNPC[i].code_char; + code_char = gNPC[i].code_char; gpNpcFuncTbl[code_char](&gNPC[i]); From ce4373481b4b67cc98ef6d3b908fd0188c328891 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 20:52:58 +0000 Subject: [PATCH 31/42] More-accurate NpcHit.cpp variable arrangement --- src/NpcHit.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/NpcHit.cpp b/src/NpcHit.cpp index e99bb028..9095cd97 100644 --- a/src/NpcHit.cpp +++ b/src/NpcHit.cpp @@ -264,15 +264,15 @@ void JudgeHitNpCharWater(NPCHAR *npc, int x, int y) npc->flag |= hit; } -void HitNpCharMap() +void HitNpCharMap(void) { - int judg, x, y; + int x, y; + int judg; int offx[9]; int offy[9]; - int i; - int j; + int i, j; offx[0] = 0; offx[1] = 1; @@ -460,6 +460,8 @@ void HitNpCharMap() void LoseNpChar(NPCHAR *npc, BOOL bVanish) { + int val; + // Play death sound PlaySoundObject(npc->destroy_voice, 1); @@ -482,8 +484,6 @@ void LoseNpChar(NPCHAR *npc, BOOL bVanish) // Create drop if (npc->exp != 0) { - int val; - switch (Random(1, 5)) { case 1: @@ -534,8 +534,7 @@ void LoseNpChar(NPCHAR *npc, BOOL bVanish) void HitNpCharBullet(void) { - int n; - int b; + int n, b; BOOL bHit; for (n = 0; n < NPC_MAX; ++n) From 718cb714ee39d818c3c6a181ac64ff3310644dfc Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 20:58:46 +0000 Subject: [PATCH 32/42] More-accurate NpcTbl.cpp variable arrangement For some reason, the Linux debug data notes a 2000-line gap before any declarations. Might be the SDL header or something. --- src/NpcTbl.cpp | 122 ++++++++++++++++++++++++------------------------- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/src/NpcTbl.cpp b/src/NpcTbl.cpp index 30aaba59..cf37082a 100644 --- a/src/NpcTbl.cpp +++ b/src/NpcTbl.cpp @@ -9,67 +9,6 @@ #include "Generic.h" #include "NpcAct.h" -NPC_TABLE *gNpcTable; - -BOOL LoadNpcTable(const char *path) -{ - FILE *fp; - int n; - int num; - size_t size; - - size = GetFileSizeLong(path); // TODO - Investigate whether GetFileSizeLong actually returns an unsigned long or not - if (size == INVALID_FILE_SIZE) - return FALSE; - - num = (int)(size / 0x18); - - gNpcTable = (NPC_TABLE*)malloc(num * sizeof(NPC_TABLE)); - if (gNpcTable == NULL) - return FALSE; - - fp = fopen(path, "rb"); - if (fp == NULL) - { - free(gNpcTable); - gNpcTable = NULL; - return FALSE; - } - - for (n = 0; n < num; ++n) // bits - fread(&gNpcTable[n].bits, 2, 1, fp); - for (n = 0; n < num; ++n) // life - fread(&gNpcTable[n].life, 2, 1, fp); - for (n = 0; n < num; ++n) // surf - fread(&gNpcTable[n].surf, 1, 1, fp); - for (n = 0; n < num; ++n) // destroy_voice - fread(&gNpcTable[n].destroy_voice, 1, 1, fp); - for (n = 0; n < num; ++n) // hit_voice - fread(&gNpcTable[n].hit_voice, 1, 1, fp); - for (n = 0; n < num; ++n) // size - fread(&gNpcTable[n].size, 1, 1, fp); - for (n = 0; n < num; ++n) // exp - fread(&gNpcTable[n].exp, 4, 1, fp); - for (n = 0; n < num; ++n) // damage - fread(&gNpcTable[n].damage, 4, 1, fp); - for (n = 0; n < num; ++n) // hit - fread(&gNpcTable[n].hit, 4, 1, fp); - for (n = 0; n < num; ++n) // view - fread(&gNpcTable[n].view, 4, 1, fp); - - fclose(fp); - return TRUE; -} - -void ReleaseNpcTable(void) -{ - if (gNpcTable != NULL) - { - free(gNpcTable); - gNpcTable = NULL; - } -} - // Npc function table const NPCFUNCTION gpNpcFuncTbl[361] = { ActNpc000, @@ -434,3 +373,64 @@ const NPCFUNCTION gpNpcFuncTbl[361] = { ActNpc359, ActNpc360, }; + +NPC_TABLE *gNpcTable; + +BOOL LoadNpcTable(const char *path) +{ + FILE *fp; + int n; + size_t size; + int num; + + size = GetFileSizeLong(path); // TODO - Investigate whether GetFileSizeLong actually returns an unsigned long or not + if (size == INVALID_FILE_SIZE) + return FALSE; + + num = (int)(size / 0x18); + + gNpcTable = (NPC_TABLE*)malloc(num * sizeof(NPC_TABLE)); + if (gNpcTable == NULL) + return FALSE; + + fp = fopen(path, "rb"); + if (fp == NULL) + { + free(gNpcTable); + gNpcTable = NULL; + return FALSE; + } + + for (n = 0; n < num; ++n) // bits + fread(&gNpcTable[n].bits, 2, 1, fp); + for (n = 0; n < num; ++n) // life + fread(&gNpcTable[n].life, 2, 1, fp); + for (n = 0; n < num; ++n) // surf + fread(&gNpcTable[n].surf, 1, 1, fp); + for (n = 0; n < num; ++n) // destroy_voice + fread(&gNpcTable[n].destroy_voice, 1, 1, fp); + for (n = 0; n < num; ++n) // hit_voice + fread(&gNpcTable[n].hit_voice, 1, 1, fp); + for (n = 0; n < num; ++n) // size + fread(&gNpcTable[n].size, 1, 1, fp); + for (n = 0; n < num; ++n) // exp + fread(&gNpcTable[n].exp, 4, 1, fp); + for (n = 0; n < num; ++n) // damage + fread(&gNpcTable[n].damage, 4, 1, fp); + for (n = 0; n < num; ++n) // hit + fread(&gNpcTable[n].hit, 4, 1, fp); + for (n = 0; n < num; ++n) // view + fread(&gNpcTable[n].view, 4, 1, fp); + + fclose(fp); + return TRUE; +} + +void ReleaseNpcTable(void) +{ + if (gNpcTable != NULL) + { + free(gNpcTable); + gNpcTable = NULL; + } +} From 5abf8a887833b3e9fa97845ac43f2d56eadd853f Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 21:38:34 +0000 Subject: [PATCH 33/42] More-accurate Organya.cpp variable arrangement Also found some authentic variable names --- src/Organya.cpp | 118 +++++++++++++++++++++++------------------------- 1 file changed, 57 insertions(+), 61 deletions(-) diff --git a/src/Organya.cpp b/src/Organya.cpp index 2fb1d3c7..8b4bb41c 100644 --- a/src/Organya.cpp +++ b/src/Organya.cpp @@ -117,16 +117,8 @@ typedef struct OrgData BOOL InitMusicData(const char *path); } ORGDATA; -ORGDATA org_data; - LPDIRECTSOUNDBUFFER lpORGANBUFFER[8][8][2] = {NULL}; -int gTrackVol[MAXTRACK]; -int gOrgVolume = 100; -BOOL bFadeout = FALSE; -BOOL g_mute[MAXTRACK]; // Used by the debug Mute menu - - ///////////////////////////////////////////// //■オルガーニャ■■■■■■■■■■■■/////// (Organya) ///////////////////// @@ -139,7 +131,7 @@ typedef struct short oct_size; } OCTWAVE; -static const OCTWAVE oct_wave[8] = +OCTWAVE oct_wave[8] = { { 256, 1, 4 }, // 0 Oct { 256, 2, 8 }, // 1 Oct @@ -151,7 +143,7 @@ static const OCTWAVE oct_wave[8] = { 8,128, 32 }, // 7 Oct }; -static WAVEFORMATEX format_tbl2 = {WAVE_FORMAT_PCM, 1, 22050, 22050, 1, 8, 0}; // 22050HzのFormat +WAVEFORMATEX format_tbl2 = {WAVE_FORMAT_PCM, 1, 22050, 22050, 1, 8, 0}; // 22050HzのFormat // In the original source code, format_tbl2 was a raw array of bytes, as seen below // BYTE format_tbl2[] = {0x01,0x00,0x01,0x00,0x22,0x56,0x00,0x00,0x22,0x56,0x00,0x00,0x01,0x00,0x08,0x00,0x00,0x00}; // 22050HzのFormat @@ -240,7 +232,7 @@ BOOL MakeSoundObject8(signed char *wavep, signed char track, signed char pipi) return TRUE; } -static const short freq_tbl[12] = {262, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494}; +short freq_tbl[12] = {262, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494}; void ChangeOrganFrequency(unsigned char key, signed char track, long a) { @@ -252,7 +244,8 @@ void ChangeOrganFrequency(unsigned char key, signed char track, long a) lpORGANBUFFER[track][j][i]->SetFrequency(((oct_wave[j].wave_size * freq_tbl[key]) * oct_wave[j].oct_par) / 8 + (a - 1000)); // 1000を+αのデフォルト値とする (1000 is the default value for + α) } -const short pan_tbl[13] = {0, 43, 86, 129, 172, 215, 256, 297, 340, 383, 426, 469, 512}; +BOOL g_mute[MAXTRACK]; // Used by the debug Mute menu +short pan_tbl[13] = {0, 43, 86, 129, 172, 215, 256, 297, 340, 383, 426, 469, 512}; unsigned char old_key[MAXTRACK] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // 再生中の音 (Sound being played) unsigned char key_on[MAXTRACK]; // キースイッチ (Key switch) unsigned char key_twin[MAXTRACK]; // 今使っているキー(連続時のノイズ防止の為に二つ用意) (Currently used keys (prepared for continuous noise prevention)) @@ -456,11 +449,11 @@ void PlayDramObject(unsigned char key, int mode, signed char track) } } +ORGDATA org_data; + OrgData::OrgData(void) { - int i; - - for (i = 0; i < MAXTRACK; i++) + for (int i = 0; i < MAXTRACK; i++) { info.tdata[i].note_list = NULL; info.tdata[i].note_p = NULL; @@ -477,8 +470,7 @@ void OrgData::InitOrgData(void) info.repeat_x = info.dot * info.line * 0; info.end_x = info.dot * info.line * 255; - int i; - for (i = 0; i < MAXTRACK; i++) + for (int i = 0; i < MAXTRACK; i++) { info.tdata[i].freq = 1000; info.tdata[i].wave_no = 0; @@ -597,8 +589,8 @@ void OrgData::ReleaseNote(void) } } -static const char pass[7] = "Org-01"; -static const char pass2[7] = "Org-02"; // Pipi +char pass[7] = "Org-01"; +char pass2[7] = "Org-02"; // Pipi BOOL OrgData::InitMusicData(const char *path) { @@ -765,9 +757,9 @@ BOOL QuitMMTimer(); /*■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■*/ //グローバル変数 (Global variable) /*■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■*/ -static UINT ExactTime = 13; // 最小精度 (Minimum accuracy) -static UINT TimerID; -static BOOL nameless_flag; +UINT ExactTime = 13; // 最小精度 (Minimum accuracy) +UINT TimerID; +BOOL nameless_flag; /*■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■*/ // タイマー精度を設定する。 (Set timer accuracy.) @@ -872,37 +864,41 @@ BOOL QuitMMTimer(void) } // Play data -long play_p; -NOTELIST *play_np[MAXTRACK]; +long PlayPos; // Called 'play_p' in the source code release +NOTELIST *np[MAXTRACK]; long now_leng[MAXMELODY]; +int Volume = 100; +int TrackVol[MAXTRACK]; +BOOL bFadeout = FALSE; + void OrgData::PlayData(void) { int i; // Handle fading out - if (bFadeout && gOrgVolume) - gOrgVolume -= 2; - if (gOrgVolume < 0) - gOrgVolume = 0; + if (bFadeout && Volume) + Volume -= 2; + if (Volume < 0) + Volume = 0; // メロディの再生 (Play melody) for (i = 0; i < MAXMELODY; i++) { - if (play_np[i] != NULL && play_p == play_np[i]->x) + if (np[i] != NULL && PlayPos == np[i]->x) { - if (!g_mute[i] && play_np[i]->y != KEYDUMMY) // 音が来た。 (The sound has come.) + if (!g_mute[i] && np[i]->y != KEYDUMMY) // 音が来た。 (The sound has come.) { - PlayOrganObject(play_np[i]->y, -1, i, info.tdata[i].freq); - now_leng[i] = play_np[i]->length; + PlayOrganObject(np[i]->y, -1, i, info.tdata[i].freq); + now_leng[i] = np[i]->length; } - if (play_np[i]->pan != PANDUMMY) - ChangeOrganPan(play_np[i]->y, play_np[i]->pan, i); - if (play_np[i]->volume != VOLDUMMY) - gTrackVol[i] = play_np[i]->volume; + if (np[i]->pan != PANDUMMY) + ChangeOrganPan(np[i]->y, np[i]->pan, i); + if (np[i]->volume != VOLDUMMY) + TrackVol[i] = np[i]->volume; - play_np[i] = play_np[i]->to; // 次の音符を指す (Points to the next note) + np[i] = np[i]->to; // 次の音符を指す (Points to the next note) } if (now_leng[i] == 0) @@ -911,36 +907,36 @@ void OrgData::PlayData(void) if (now_leng[i] > 0) now_leng[i]--; - if (play_np[i]) - ChangeOrganVolume(play_np[i]->y, gTrackVol[i] * gOrgVolume / 0x7F, i); + if (np[i]) + ChangeOrganVolume(np[i]->y, TrackVol[i] * Volume / 0x7F, i); } // ドラムの再生 (Drum playback) for (i = MAXMELODY; i < MAXTRACK; i++) { - if (play_np[i] != NULL && play_p == play_np[i]->x) // 音が来た。 (The sound has come.) + if (np[i] != NULL && PlayPos == np[i]->x) // 音が来た。 (The sound has come.) { - if (play_np[i]->y != KEYDUMMY && !g_mute[i]) // ならす (Tame) - PlayDramObject(play_np[i]->y, 1, i - MAXMELODY); + if (np[i]->y != KEYDUMMY && !g_mute[i]) // ならす (Tame) + PlayDramObject(np[i]->y, 1, i - MAXMELODY); - if (play_np[i]->pan != PANDUMMY) - ChangeDramPan(play_np[i]->pan, i - MAXMELODY); - if (play_np[i]->volume != VOLDUMMY) - gTrackVol[i] = play_np[i]->volume; + if (np[i]->pan != PANDUMMY) + ChangeDramPan(np[i]->pan, i - MAXMELODY); + if (np[i]->volume != VOLDUMMY) + TrackVol[i] = np[i]->volume; - play_np[i] = play_np[i]->to; // 次の音符を指す (Points to the next note) + np[i] = np[i]->to; // 次の音符を指す (Points to the next note) } - if (play_np[i]) - ChangeDramVolume(gTrackVol[i] * gOrgVolume / 0x7F, i - MAXMELODY); + if (np[i]) + ChangeDramVolume(TrackVol[i] * Volume / 0x7F, i - MAXMELODY); } // Looping - play_p++; - if (play_p >= info.end_x) + PlayPos++; + if (PlayPos >= info.end_x) { - play_p = info.repeat_x; - SetPlayPointer(play_p); + PlayPos = info.repeat_x; + SetPlayPointer(PlayPos); } } @@ -948,12 +944,12 @@ void OrgData::SetPlayPointer(long x) { for (int i = 0; i < MAXTRACK; i++) { - play_np[i] = info.tdata[i].note_list; - while (play_np[i] != NULL && play_np[i]->x < x) - play_np[i] = play_np[i]->to; // 見るべき音符を設定 (Set note to watch) + np[i] = info.tdata[i].note_list; + while (np[i] != NULL && np[i]->x < x) + np[i] = np[i]->to; // 見るべき音符を設定 (Set note to watch) } - play_p = x; + PlayPos = x; } // Start and end organya @@ -979,7 +975,7 @@ BOOL LoadOrganya(const char *name) if (!org_data.InitMusicData(name)) return FALSE; - gOrgVolume = 100; + Volume = 100; bFadeout = 0; #ifdef FIX_BUGS @@ -995,7 +991,7 @@ void SetOrganyaPosition(unsigned int x) return; org_data.SetPlayPointer(x); - gOrgVolume = 100; + Volume = 100; bFadeout = FALSE; } @@ -1004,7 +1000,7 @@ unsigned int GetOrganyaPosition(void) if (lpDS == NULL) return 0; - return play_p; + return PlayPos; } void PlayOrganyaMusic(void) @@ -1025,7 +1021,7 @@ BOOL ChangeOrganyaVolume(signed int volume) if (volume < 0 || volume > 100) return FALSE; - gOrgVolume = volume; + Volume = volume; return TRUE; } From 10a014dabda1d525f0e51eef2084f268f33c046e Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 21:45:43 +0000 Subject: [PATCH 34/42] More-accurate PixTone.cpp variable arrangement Also added the Linux port's optimisation, for anyone that's curious --- src/PixTone.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/PixTone.cpp b/src/PixTone.cpp index de7df605..efb28f4b 100644 --- a/src/PixTone.cpp +++ b/src/PixTone.cpp @@ -6,11 +6,13 @@ #include "WindowsWrapper.h" -static signed char gWaveModelTable[6][0x100]; +signed char gWaveModelTable[6][0x100]; void MakeWaveTables(void) { - int i, a; + int i; + + int a; // Sine wave for (i = 0; i < 0x100; ++i) @@ -59,24 +61,28 @@ void MakeWaveTables(void) gWaveModelTable[5][i] = (signed char)(rand() & 0xFF) / 2; } +//BOOL wave_tables_made; + BOOL MakePixelWaveData(const PIXTONEPARAMETER *ptp, unsigned char *pData) { int i; - double dEnvelope; + int a, b, c, d; + double dPitch; double dMain; double dVolume; - double d1; - double d2; - double d3; - int a; - int b; - int c; - int d; + + double dEnvelope; signed char envelopeTable[0x100]; + double d1, d2, d3; + // The Linux port added a cute optimisation here, where MakeWaveTables is only called once during the game's execution - MakeWaveTables(); + //if (wave_tables_made != TRUE) + //{ + MakeWaveTables(); + // wave_tables_made = TRUE; + //} memset(envelopeTable, 0, sizeof(envelopeTable)); From 74cd1b047358e3c946fa6ac382ef97d06312c39d Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 21:50:36 +0000 Subject: [PATCH 35/42] More-accurate Profile.cpp variable arrangement --- src/Profile.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Profile.cpp b/src/Profile.cpp index c28c51aa..4c5035f9 100644 --- a/src/Profile.cpp +++ b/src/Profile.cpp @@ -27,11 +27,9 @@ const char *gProfileCode = "Do041220"; BOOL IsProfile(void) { char path[MAX_PATH]; - HANDLE hFile; - sprintf(path, "%s\\%s", gModulePath, gDefaultName); - hFile = CreateFileA(path, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + HANDLE hFile = CreateFileA(path, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) return FALSE; @@ -41,9 +39,10 @@ BOOL IsProfile(void) BOOL SaveProfile(const char *name) { - PROFILE profile; FILE *fp; + PROFILE profile; const char *FLAG = "FLAG"; + char path[MAX_PATH]; // Get path @@ -89,9 +88,9 @@ BOOL SaveProfile(const char *name) BOOL LoadProfile(const char *name) { - char path[MAX_PATH]; - PROFILE profile; FILE *fp; + PROFILE profile; + char path[MAX_PATH]; // Get path if (name != NULL) From cef901792ba2b7791c573d60cfd906ee4c13e5bb Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 21:53:21 +0000 Subject: [PATCH 36/42] More-accurate SelStage.cpp variable arrangement --- src/SelStage.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/SelStage.cpp b/src/SelStage.cpp index 3acb41df..221301fc 100644 --- a/src/SelStage.cpp +++ b/src/SelStage.cpp @@ -14,8 +14,8 @@ PERMIT_STAGE gPermitStage[8]; -static int gSelectedStage; -static int gStageSelectTitleY; +int gSelectedStage; +int gStageSelectTitleY; void ClearPermitStage(void) { @@ -107,6 +107,9 @@ void PutStageSelectObject(void) { static unsigned int flash; + int i; + RECT rcStage; + RECT rcView = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT}; RECT rcCur[2] = { @@ -116,10 +119,8 @@ void PutStageSelectObject(void) RECT rcTitle1 = {80, 64, 144, 72}; - int i; int stage_num; int stage_x; - RECT rcStage; if (gStageSelectTitleY > (WINDOW_HEIGHT / 2) - 74) --gStageSelectTitleY; From e459364a33054107d5a74800e90a94f4809cae5b Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 21:58:35 +0000 Subject: [PATCH 37/42] More-accurate Shoot.cpp variable arrangement --- src/Shoot.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Shoot.cpp b/src/Shoot.cpp index 3b2a639e..64bf7788 100644 --- a/src/Shoot.cpp +++ b/src/Shoot.cpp @@ -11,7 +11,6 @@ #include "Sound.h" int empty; -int spur_charge; void ShootBullet_Frontia1(int level) { @@ -250,6 +249,7 @@ void ShootBullet_FireBall(int level) void ShootBullet_Machinegun1(int level) { int bul_no; + static int wait; if (CountArmsBullet(4) > 4) return; @@ -355,7 +355,6 @@ void ShootBullet_Machinegun1(int level) } else { - static int wait = 0; ++wait; if (gMC.equip & 8) @@ -896,6 +895,8 @@ void ShootBullet_Nemesis(int level) } } +int spur_charge; + void ResetSpurCharge(void) { spur_charge = 0; @@ -906,9 +907,9 @@ void ResetSpurCharge(void) void ShootBullet_Spur(int level) { - static BOOL bMax; - BOOL bShot; int bul_no; + BOOL bShot; + static BOOL bMax; bShot = FALSE; @@ -1058,11 +1059,12 @@ void ShootBullet_Spur(int level) void ShootBullet(void) { + static int soft_rensha; // 'rensha' is Japanese for 'rapid-fire', apparently + if (empty != 0) --empty; // Only let the player shoot every 4 frames - static int soft_rensha; // 'rensha' is Japanese for 'rapid-fire', apparently if (soft_rensha != 0) --soft_rensha; From 32d635581aede7a4ba1fec9c96790b56ac103081 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 22:03:49 +0000 Subject: [PATCH 38/42] Sound.cpp variable arrangement tweaks Not much can be done for this file, considering how heavily it was modified in the Linux port. While I was here, I noted the unused .wav loading function. --- src/Sound.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Sound.cpp b/src/Sound.cpp index 5e15e9a1..c98a3606 100644 --- a/src/Sound.cpp +++ b/src/Sound.cpp @@ -131,6 +131,8 @@ BOOL InitSoundObject(LPCSTR resname, int no) return TRUE; } +// Completely unused function for loading a .wav file as a sound effect. +// Some say that sounds heard in CS Beta footage don't sound like PixTone... BOOL LoadSoundObject(LPCSTR file_name, int no) { char path[MAX_PATH]; @@ -290,12 +292,11 @@ int MakePixToneObject(const PIXTONEPARAMETER *ptp, int ptp_num, int no) unsigned long data_bytes; } WavHeader; - int i; - int j; + int sample_count; + int i, j; DSBUFFERDESC dsbd; WavHeader wav_header; const PIXTONEPARAMETER *ptp_pointer; - int sample_count; unsigned char *pcm_buffer; unsigned char *mixed_pcm_buffer; From 3f2d5c3e25644aec0ddffa38f77c9ea985aea5f7 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 22:08:10 +0000 Subject: [PATCH 39/42] More-accurate Stage.cpp variable arrangement --- src/Stage.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Stage.cpp b/src/Stage.cpp index 69046217..42733d0c 100644 --- a/src/Stage.cpp +++ b/src/Stage.cpp @@ -27,6 +27,9 @@ #endif int gStageNo; +MusicID gMusicNo; +unsigned int gOldPos; +MusicID gOldNo; // Note: Pixel made numerous capitalisation errors when making this table. // This isn't a problem for Windows, because of its case-insensitive filesystem. @@ -130,9 +133,9 @@ const STAGE_TABLE gTMT[95] = { BOOL TransferStage(int no, int w, int x, int y) { - BOOL bError; - char path_dir[20]; char path[MAX_PATH]; + char path_dir[20]; + BOOL bError; // Move character SetMyCharPosition(x * 0x10 * 0x200, y * 0x10 * 0x200); @@ -248,10 +251,6 @@ const char *gMusicTable[42] = { "WHITE" }; -MusicID gMusicNo; -unsigned int gOldPos; -MusicID gOldNo; - void ChangeMusic(MusicID no) { if (no != MUS_SILENCE && no == gMusicNo) From 5adc06536bcfe53d8af62dcb7925ac0e37279ec7 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 22:13:37 +0000 Subject: [PATCH 40/42] More-accurate Triangle.cpp variable arrangement --- src/Triangle.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Triangle.cpp b/src/Triangle.cpp index 7afa7f65..435a997a 100644 --- a/src/Triangle.cpp +++ b/src/Triangle.cpp @@ -8,14 +8,12 @@ short gTan[0x21]; void InitTriangleTable(void) { int i; - float a; - float b; // Sine for (i = 0; i < 0x100; ++i) - { gSin[i] = (int)(sin(i * 6.2831998 / 256.0) * 512.0); - } + + float a, b; // Tangent for (i = 0; i < 0x21; ++i) @@ -39,8 +37,8 @@ int GetCos(unsigned char deg) unsigned char GetArktan(int x, int y) { - unsigned char a; short k; + unsigned char a; x *= -1; y *= -1; From cb4bd02ab5149b879affe3ec5c5d7258b1e5294e Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 22:20:22 +0000 Subject: [PATCH 41/42] More-accurate ValueView.cpp variable arrangement Finally done with this --- src/ValueView.cpp | 64 +++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/src/ValueView.cpp b/src/ValueView.cpp index 57b5601a..0813bad9 100644 --- a/src/ValueView.cpp +++ b/src/ValueView.cpp @@ -19,17 +19,11 @@ void ClearValueView(void) void SetValueView(int *px, int *py, int value) { - int index; BOOL minus; int v; - int width; - int dig[4]; - int fig[4]; - BOOL sw; + + int index; int i; - RECT rect[20]; - RECT rcPlus; - RECT rcMinus; for (i = 0; i < VALUEVIEW_MAX; ++i) { @@ -77,6 +71,8 @@ void SetValueView(int *px, int *py, int value) // Get width v = value; + int width; + if (value > 999) width = 40; else if (value > 99) @@ -95,28 +91,32 @@ void SetValueView(int *px, int *py, int value) gVV[index].rect.right = 40; gVV[index].rect.bottom = 8 * (index + 1); - SET_RECT(rect[0], 0, 56, 8, 64); - SET_RECT(rect[1], 8, 56, 16, 64); - SET_RECT(rect[2], 16, 56, 24, 64); - SET_RECT(rect[3], 24, 56, 32, 64); - SET_RECT(rect[4], 32, 56, 40, 64); - SET_RECT(rect[5], 40, 56, 48, 64); - SET_RECT(rect[6], 48, 56, 56, 64); - SET_RECT(rect[7], 56, 56, 64, 64); - SET_RECT(rect[8], 64, 56, 72, 64); - SET_RECT(rect[9], 72, 56, 80, 64); - SET_RECT(rect[10], 0, 64, 8, 72); - SET_RECT(rect[11], 8, 64, 16, 72); - SET_RECT(rect[12], 16, 64, 24, 72); - SET_RECT(rect[13], 24, 64, 32, 72); - SET_RECT(rect[14], 32, 64, 40, 72); - SET_RECT(rect[15], 40, 64, 48, 72); - SET_RECT(rect[16], 48, 64, 56, 72); - SET_RECT(rect[17], 56, 64, 64, 72); - SET_RECT(rect[18], 64, 64, 72, 72); - SET_RECT(rect[19], 72, 64, 80, 72); + RECT rect[20] = { + {0, 56, 8, 64}, + {8, 56, 16, 64}, + {16, 56, 24, 64}, + {24, 56, 32, 64}, + {32, 56, 40, 64}, + {40, 56, 48, 64}, + {48, 56, 56, 64}, + {56, 56, 64, 64}, + {64, 56, 72, 64}, + {72, 56, 80, 64}, + {0, 64, 8, 72}, + {8, 64, 16, 72}, + {16, 64, 24, 72}, + {24, 64, 32, 72}, + {32, 64, 40, 72}, + {40, 64, 48, 72}, + {48, 64, 56, 72}, + {56, 64, 64, 72}, + {64, 64, 72, 72}, + {72, 64, 80, 72}, + }; // Get digits + int dig[4]; + int fig[4]; dig[0] = 1; dig[1] = 10; dig[2] = 100; @@ -133,10 +133,10 @@ void SetValueView(int *px, int *py, int value) } } - sw = FALSE; + BOOL sw = FALSE; - SET_RECT(rcPlus, 32, 48, 40, 56); - SET_RECT(rcMinus, 40, 48, 48, 56); + RECT rcPlus = {32, 48, 40, 56}; + RECT rcMinus = {40, 48, 48, 56}; // Draw value CortBox2(&gVV[index].rect, 0x000000, SURFACE_ID_VALUE_VIEW); @@ -182,8 +182,8 @@ void ActValueView(void) void PutValueView(int flx, int fly) { - int v; int offset_x; + int v; for (v = 0; v < VALUEVIEW_MAX; ++v) { From a5df6ebc72e0b2529e6d420058da266587373c89 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 7 Jan 2020 23:15:33 +0000 Subject: [PATCH 42/42] Remove SET_RECT macro I should probably remove WindowsWrapper.h from this branch now, and just make files use windows.h directly. --- src/WindowsWrapper.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/WindowsWrapper.h b/src/WindowsWrapper.h index 47810b8d..40235a3d 100644 --- a/src/WindowsWrapper.h +++ b/src/WindowsWrapper.h @@ -1,9 +1,3 @@ #pragma once #include - -#define SET_RECT(rect, l, t, r, b) \ - rect.left = l; \ - rect.top = t; \ - rect.right = r; \ - rect.bottom = b;