From 0df697d5ee9a8f5f5858cf8a3bc475c31d81206a Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sun, 27 Sep 2020 20:07:06 +0100 Subject: [PATCH 1/8] Add a TODO --- src/Ending.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ending.cpp b/src/Ending.cpp index 18695022..99973efd 100644 --- a/src/Ending.cpp +++ b/src/Ending.cpp @@ -176,7 +176,7 @@ void ActionIllust(void) void PutIllust(void) { RECT rcIllust = {0, 0, 160, 240}; -#if WINDOW_WIDTH != 320 || WINDOW_HEIGHT != 240 +#if WINDOW_WIDTH != 320 || WINDOW_HEIGHT != 240 // TODO - Move this to CSE2EX // Widescreen edit RECT rcClip = {(WINDOW_WIDTH - 320) / 2, 0, WINDOW_WIDTH, WINDOW_HEIGHT}; PutBitmap3(&rcClip, (Illust.x / 0x200) + ((WINDOW_WIDTH - 320) / 2), (WINDOW_HEIGHT - 240) / 2, &rcIllust, SURFACE_ID_CREDITS_IMAGE); From d1dc861bc3aaa98f86fa0b45297a3f044cf97486 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sun, 27 Sep 2020 20:08:51 +0100 Subject: [PATCH 2/8] Another TODO --- src/Ending.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Ending.cpp b/src/Ending.cpp index 99973efd..efdee914 100644 --- a/src/Ending.cpp +++ b/src/Ending.cpp @@ -247,13 +247,14 @@ BOOL StartCreditScript(void) // Read data fread(Credit.pData, 1, Credit.size, fp); - EncryptionBinaryData2((unsigned char*)Credit.pData, Credit.size); #ifdef FIX_MAJOR_BUGS // The original game forgot to close the file fclose(fp); #endif + EncryptionBinaryData2((unsigned char*)Credit.pData, Credit.size); + // Reset credits Credit.offset = 0; Credit.wait = 0; @@ -263,7 +264,7 @@ BOOL StartCreditScript(void) // Modify cliprect grcGame.left = WINDOW_WIDTH / 2; -#if WINDOW_WIDTH != 320 || WINDOW_HEIGHT != 240 +#if WINDOW_WIDTH != 320 || WINDOW_HEIGHT != 240 // TODO - Move to CSE2EX // These three are non-vanilla: for wide/tallscreen support grcGame.right = ((WINDOW_WIDTH - 320) / 2) + 320; grcGame.top = (WINDOW_HEIGHT - 240) / 2; From 80d5691a7eb4f6b7fb808565db691f4e4997f702 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sun, 27 Sep 2020 20:12:12 +0100 Subject: [PATCH 3/8] Clean-up some code --- src/Ending.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Ending.cpp b/src/Ending.cpp index efdee914..0edbbf4f 100644 --- a/src/Ending.cpp +++ b/src/Ending.cpp @@ -283,10 +283,10 @@ BOOL StartCreditScript(void) // Get number from text (4 digit) static int GetScriptNumber(const char *text) { - return (text[0] - '0') * 1000 + - (text[1] - '0') * 100 + - (text[2] - '0') * 10 + - text[3] - '0'; + return (text[0] - '0') * 1000 + + (text[1] - '0') * 100 + + (text[2] - '0') * 10 + + (text[3] - '0') * 1; } // Parse credits From 2ab0ff2455a2f25dd4c8d49195fd1d1362692f4a Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sun, 27 Sep 2020 20:35:58 +0100 Subject: [PATCH 4/8] Document Ending.cpp a little --- src/Ending.cpp | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/Ending.cpp b/src/Ending.cpp index 0edbbf4f..d5013219 100644 --- a/src/Ending.cpp +++ b/src/Ending.cpp @@ -304,7 +304,7 @@ static void ActionCredit_Read(void) { case '[': // Create cast // Get the range for the cast text - ++Credit.offset; + Credit.offset += 1; a = Credit.offset; @@ -322,26 +322,26 @@ static void ActionCredit_Read(void) memcpy(text, &Credit.pData[Credit.offset], len); text[len] = 0; - // Get cast id + // Get cast ID Credit.offset = a; len = GetScriptNumber(&Credit.pData[++Credit.offset]); // Create cast object - SetStripper(Credit.start_x, (WINDOW_HEIGHT * 0x200) + (8 * 0x200), text, len); + SetStripper(Credit.start_x, (WINDOW_HEIGHT + 8) * 0x200, text, len); // Change offset Credit.offset += 4; return; case '-': // Wait for X amount of frames - ++Credit.offset; + Credit.offset += 1; Credit.wait = GetScriptNumber(&Credit.pData[Credit.offset]); Credit.offset += 4; Credit.mode = 2; return; case '+': // Change casts x-position - ++Credit.offset; + Credit.offset += 1; Credit.start_x = GetScriptNumber(&Credit.pData[Credit.offset]) * 0x200; Credit.offset += 4; return; @@ -351,19 +351,19 @@ static void ActionCredit_Read(void) return; case '!': // Change music - ++Credit.offset; + Credit.offset += 1; a = GetScriptNumber(&Credit.pData[Credit.offset]); Credit.offset += 4; ChangeMusic((MusicID)a); return; case '~': // Start fading out music - ++Credit.offset; + Credit.offset += 1; SetOrganyaFadeout(); return; case 'j': // Jump to label - ++Credit.offset; + Credit.offset += 1; // Get number b = GetScriptNumber(&Credit.pData[Credit.offset]); @@ -372,25 +372,25 @@ static void ActionCredit_Read(void) Credit.offset += 4; // Jump to specific label - if (1) + if (1) // This appears to be a hacked-up duplicate of some code from the below 'f' condition { while (Credit.offset < Credit.size) { if (Credit.pData[Credit.offset] == 'l') { - // What is this - a = GetScriptNumber(&Credit.pData[++Credit.offset]); + Credit.offset += 1; + a = GetScriptNumber(&Credit.pData[Credit.offset]); Credit.offset += 4; + if (b == a) break; } - else if (IsShiftJIS(Credit.pData[Credit.offset])) - { - Credit.offset += 2; - } else { - ++Credit.offset; + if (IsShiftJIS(Credit.pData[Credit.offset])) + Credit.offset += 2; + else + Credit.offset += 1; } } } @@ -398,7 +398,7 @@ static void ActionCredit_Read(void) return; case 'f': // Flag jump - ++Credit.offset; + Credit.offset += 1; // Read numbers XXXX:YYYY a = GetScriptNumber(&Credit.pData[Credit.offset]); @@ -414,18 +414,19 @@ static void ActionCredit_Read(void) { if (Credit.pData[Credit.offset] == 'l') { - a = GetScriptNumber(&Credit.pData[++Credit.offset]); + Credit.offset += 1; + a = GetScriptNumber(&Credit.pData[Credit.offset]); Credit.offset += 4; + if (b == a) break; } - else if (IsShiftJIS(Credit.pData[Credit.offset])) - { - Credit.offset += 2; - } else { - ++Credit.offset; + if (IsShiftJIS(Credit.pData[Credit.offset])) + Credit.offset += 2; + else + Credit.offset += 1; } } } @@ -433,7 +434,7 @@ static void ActionCredit_Read(void) default: // Progress through file - ++Credit.offset; + Credit.offset += 1; break; } } From 69eed6a9662a4e41d2bdc6674a218b1d39a123f1 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sun, 27 Sep 2020 20:45:08 +0100 Subject: [PATCH 5/8] More documentation --- src/Ending.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Ending.cpp b/src/Ending.cpp index d5013219..037a7444 100644 --- a/src/Ending.cpp +++ b/src/Ending.cpp @@ -18,6 +18,13 @@ #include "Stage.h" #include "TextScr.h" +enum ILLUSTRATION_ACTION +{ + ILLUSTRATION_ACTION_IDLE, + ILLUSTRATION_ACTION_SLIDE_IN, + ILLUSTRATION_ACTION_SLIDE_OUT +}; + struct CREDIT { long size; @@ -39,7 +46,7 @@ struct STRIP struct ILLUSTRATION { - int act_no; + ILLUSTRATION_ACTION act_no; int x; }; @@ -154,18 +161,18 @@ void ActionIllust(void) { switch (Illust.act_no) { - case 0: // Off-screen to the left + case ILLUSTRATION_ACTION_IDLE: // Off-screen to the left Illust.x = -160 * 0x200; break; - case 1: // Move in from the left + case ILLUSTRATION_ACTION_SLIDE_IN: // Move in from the left Illust.x += 40 * 0x200; if (Illust.x > 0) Illust.x = 0; break; - case 2: // Move out from the right - Illust.x -= 0x5000; + case ILLUSTRATION_ACTION_SLIDE_OUT: // Move out from the right + Illust.x -= 40 * 0x200; if (Illust.x < -160 * 0x200) Illust.x = -160 * 0x200; break; @@ -260,7 +267,7 @@ BOOL StartCreditScript(void) Credit.wait = 0; Credit.mode = 1; Illust.x = -160 * 0x200; - Illust.act_no = 0; + Illust.act_no = ILLUSTRATION_ACTION_IDLE; // Modify cliprect grcGame.left = WINDOW_WIDTH / 2; @@ -464,13 +471,13 @@ void ActionCredit(void) void SetCreditIllust(int a) { ReloadIllust(a); - Illust.act_no = 1; + Illust.act_no = ILLUSTRATION_ACTION_SLIDE_IN; } // Slide illustration off-screen void CutCreditIllust(void) { - Illust.act_no = 2; + Illust.act_no = ILLUSTRATION_ACTION_SLIDE_OUT; } // Scene of the island falling From 59aeae07f85c2f8adc15c0fa4dd76f7c810173e5 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sun, 27 Sep 2020 20:57:24 +0100 Subject: [PATCH 6/8] More documentation --- src/Ending.cpp | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/Ending.cpp b/src/Ending.cpp index 037a7444..2b1ee342 100644 --- a/src/Ending.cpp +++ b/src/Ending.cpp @@ -18,6 +18,13 @@ #include "Stage.h" #include "TextScr.h" +enum CREDIT_MODE +{ + CREDIT_MODE_STOP, + CREDIT_MODE_SCROLL_READ, + CREDIT_MODE_SCROLL_WAIT +}; + enum ILLUSTRATION_ACTION { ILLUSTRATION_ACTION_IDLE, @@ -31,7 +38,7 @@ struct CREDIT char *pData; int offset; int wait; - int mode; + CREDIT_MODE mode; int start_x; }; @@ -68,10 +75,10 @@ void ActionStripper(void) for (s = 0; s < MAX_STRIP; ++s) { // Move up - if (Strip[s].flag & 0x80 && Credit.mode) + if (Strip[s].flag & 0x80 && Credit.mode != CREDIT_MODE_STOP) Strip[s].y -= 0x100; // Get removed when off-screen - if (Strip[s].y <= -0x2000) + if (Strip[s].y <= -16 * 0x200) Strip[s].flag = 0; } } @@ -265,7 +272,7 @@ BOOL StartCreditScript(void) // Reset credits Credit.offset = 0; Credit.wait = 0; - Credit.mode = 1; + Credit.mode = CREDIT_MODE_SCROLL_READ; Illust.x = -160 * 0x200; Illust.act_no = ILLUSTRATION_ACTION_IDLE; @@ -327,11 +334,12 @@ static void ActionCredit_Read(void) // Copy the text to the cast text memcpy(text, &Credit.pData[Credit.offset], len); - text[len] = 0; + text[len] = '\0'; // Get cast ID Credit.offset = a; - len = GetScriptNumber(&Credit.pData[++Credit.offset]); + Credit.offset += 1; + len = GetScriptNumber(&Credit.pData[Credit.offset]); // Create cast object SetStripper(Credit.start_x, (WINDOW_HEIGHT + 8) * 0x200, text, len); @@ -344,7 +352,7 @@ static void ActionCredit_Read(void) Credit.offset += 1; Credit.wait = GetScriptNumber(&Credit.pData[Credit.offset]); Credit.offset += 4; - Credit.mode = 2; + Credit.mode = CREDIT_MODE_SCROLL_WAIT; return; case '+': // Change casts x-position @@ -354,7 +362,7 @@ static void ActionCredit_Read(void) return; case '/': // Stop credits - Credit.mode = 0; + Credit.mode = CREDIT_MODE_STOP; return; case '!': // Change music @@ -456,13 +464,13 @@ void ActionCredit(void) // Update script, or if waiting, decrement the wait value switch (Credit.mode) { - case 1: + case CREDIT_MODE_SCROLL_READ: ActionCredit_Read(); break; - case 2: + case CREDIT_MODE_SCROLL_WAIT: if (--Credit.wait <= 0) - Credit.mode = 1; + Credit.mode = CREDIT_MODE_SCROLL_READ; break; } } @@ -519,24 +527,24 @@ int Scene_DownIsland(HWND hWnd, int mode) { case 0: // Move down - sprite.y += 0x33; + sprite.y += 0x200 / 10; break; case 1: if (wait < 350) { // Move down at normal speed - sprite.y += 0x33; + sprite.y += 0x200 / 10; } else if (wait < 500) { // Move down slower - sprite.y += 0x19; + sprite.y += 0x200 / 20; } else if (wait < 600) { // Move down slow - sprite.y += 0xC; + sprite.y += 0x200 / 40; } else if (wait == 750) { From 97a042dcc00821c17852fe728588d04edb91a242 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sun, 27 Sep 2020 21:12:39 +0100 Subject: [PATCH 7/8] Deobfuscate some values --- src/BossOhm.cpp | 6 +++--- src/MyChar.cpp | 22 +++++++++++----------- src/NpcAct020.cpp | 2 +- src/NpcAct120.cpp | 2 +- src/NpcAct180.cpp | 6 +++--- src/NpcAct260.cpp | 2 +- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/BossOhm.cpp b/src/BossOhm.cpp index a04bbf98..4f94ed4c 100644 --- a/src/BossOhm.cpp +++ b/src/BossOhm.cpp @@ -263,9 +263,9 @@ void ActBossChar_Omega(void) if (gBoss[0].act_wait > 20 && gBoss[0].act_wait < 80 && !(gBoss[0].act_wait % 3)) { if (Random(0, 9) < 8) - SetNpChar(48, gBoss[0].x, gBoss[0].y - (16 * 0x200), Random(-0x100, 0x100), -0x333, 0, NULL, 0x100); + SetNpChar(48, gBoss[0].x, gBoss[0].y - (16 * 0x200), Random(-0x100, 0x100), -0x10 * 0x200 / 10, 0, NULL, 0x100); else - SetNpChar(48, gBoss[0].x, gBoss[0].y - (16 * 0x200), Random(-0x100, 0x100), -0x333, 2, NULL, 0x100); + SetNpChar(48, gBoss[0].x, gBoss[0].y - (16 * 0x200), Random(-0x100, 0x100), -0x10 * 0x200 / 10, 2, NULL, 0x100); PlaySoundObject(39, SOUND_MODE_PLAY); } @@ -384,7 +384,7 @@ void ActBossChar_Omega(void) if (gBoss[0].act_wait < 30 && gBoss[0].act_wait % 5 == 0) { - SetNpChar(48, gBoss[0].x, gBoss[0].y - (16 * 0x200), Random(-341, 341), -0x333, 0, NULL, 0x100); + SetNpChar(48, gBoss[0].x, gBoss[0].y - (16 * 0x200), Random(-341, 341), -0x10 * 0x200 / 10, 0, NULL, 0x100); PlaySoundObject(39, SOUND_MODE_PLAY); } diff --git a/src/MyChar.cpp b/src/MyChar.cpp index 0d90b194..fda96f28 100644 --- a/src/MyChar.cpp +++ b/src/MyChar.cpp @@ -259,14 +259,14 @@ void ActMyChar_Normal(BOOL bKey) if (gMC.flag & 0x100) { - max_dash = 0x196; - max_move = 0x2FF; - gravity1 = 0x28; - gravity2 = 0x10; - jump = 0x280; - dash1 = 0x2A; - dash2 = 0x10; - resist = 0x19; + max_dash = 0x32C / 2; + max_move = 0x5FF / 2; + gravity1 = 0x50 / 2; + gravity2 = 0x20 / 2; + jump = 0x500 / 2; + dash1 = 0x200 / 6 / 2; + dash2 = 0x200 / 16 / 2; + resist = 0x200 / 10 / 2; } else { @@ -275,9 +275,9 @@ void ActMyChar_Normal(BOOL bKey) gravity1 = 0x50; gravity2 = 0x20; jump = 0x500; - dash1 = 0x55; - dash2 = 0x20; - resist = 0x33; + dash1 = 0x200 / 6; + dash2 = 0x200 / 16; + resist = 0x200 / 10; } // Don't create "?" effect diff --git a/src/NpcAct020.cpp b/src/NpcAct020.cpp index ef5e26d8..ce231857 100644 --- a/src/NpcAct020.cpp +++ b/src/NpcAct020.cpp @@ -1241,7 +1241,7 @@ void ActNpc036(NPCHAR *npc) if (npc->act_no != 5) { - npc->ym += 0x33; + npc->ym += 0x200 / 10; if (npc->x < gMC.x) npc->direct = 2; diff --git a/src/NpcAct120.cpp b/src/NpcAct120.cpp index f8b3ce1d..313942ed 100644 --- a/src/NpcAct120.cpp +++ b/src/NpcAct120.cpp @@ -1203,7 +1203,7 @@ void ActNpc135(NPCHAR *npc) npc->direct = 2; } - npc->ym += 0x33; + npc->ym += 0x200 / 10; if (npc->ym > 0x5FF) npc->ym = 0x5FF; diff --git a/src/NpcAct180.cpp b/src/NpcAct180.cpp index c7646495..43b440c0 100644 --- a/src/NpcAct180.cpp +++ b/src/NpcAct180.cpp @@ -271,13 +271,13 @@ void ActNpc180(NPCHAR *npc) #else if (npc->flag && 5) #endif - npc->ym += 0x10; + npc->ym += 0x200 / 32; else - npc->ym += 0x33; + npc->ym += 0x200 / 10; } else { - npc->ym += 0x33; + npc->ym += 0x200 / 10; } } diff --git a/src/NpcAct260.cpp b/src/NpcAct260.cpp index f58b5c3b..7ee88d28 100644 --- a/src/NpcAct260.cpp +++ b/src/NpcAct260.cpp @@ -1320,7 +1320,7 @@ void ActNpc268(NPCHAR *npc) break; } - npc->ym += 0x33; + npc->ym += 0x200 / 10; if (npc->ym > 0x5FF) npc->ym = 0x5FF; From 0730bb74eff37e5cd2640eded4a11dd2f0a70003 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sun, 27 Sep 2020 22:02:45 +0100 Subject: [PATCH 8/8] More cleanup --- src/MiniMap.cpp | 70 +++++++++++++++++++++++++----------------------- src/MycParam.cpp | 2 +- src/SelStage.cpp | 3 ++- 3 files changed, 39 insertions(+), 36 deletions(-) diff --git a/src/MiniMap.cpp b/src/MiniMap.cpp index 0bd30e53..f919c80c 100644 --- a/src/MiniMap.cpp +++ b/src/MiniMap.cpp @@ -34,39 +34,39 @@ void WriteMiniMapLine(int line) // No switch here. if (a == 0) Surface2Surface(x, line, &rcLevel[0], SURFACE_ID_MAP, SURFACE_ID_TEXT_BOX); - else if (a == 68 || - a == 1 || - a == 64 || - a == 128 || - a == 129 || - a == 130 || - a == 131 || - a == 81 || - a == 82 || - a == 85 || - a == 86 || - a == 2 || - a == 96 || - a == 113 || - a == 114 || - a == 117 || - a == 118 || - a == 160 || - a == 161 || - a == 162 || - a == 163) + else if (a == 68 || + a == 1 || + a == 64 || + a == 128 || + a == 129 || + a == 130 || + a == 131 || + a == 81 || + a == 82 || + a == 85 || + a == 86 || + a == 2 || + a == 96 || + a == 113 || + a == 114 || + a == 117 || + a == 118 || + a == 160 || + a == 161 || + a == 162 || + a == 163) Surface2Surface(x, line, &rcLevel[1], SURFACE_ID_MAP, SURFACE_ID_TEXT_BOX); - else if (a == 67 || - a == 99 || - a == 80 || - a == 83 || - a == 84 || - a == 87 || - a == 96 || // This is already listed above, so that part of the expression is always false - a == 112 || - a == 115 || - a == 116 || - a == 119) + else if (a == 67 || + a == 99 || + a == 80 || + a == 83 || + a == 84 || + a == 87 || + a == 96 || // This is already listed above, so this part of the expression is always false + a == 112 || + a == 115 || + a == 116 || + a == 119) Surface2Surface(x, line, &rcLevel[2], SURFACE_ID_MAP, SURFACE_ID_TEXT_BOX); else Surface2Surface(x, line, &rcLevel[3], SURFACE_ID_MAP, SURFACE_ID_TEXT_BOX); @@ -123,8 +123,10 @@ int MiniMapLoop(void) rcMiniMap.top = 0; rcMiniMap.bottom = gMap.length; - rcView.right = --rcView.left + gMap.width + 2; - rcView.bottom = --rcView.top + gMap.length + 2; + rcView.left -= 1; + rcView.right = rcView.left + gMap.width + 2; + rcView.top -= 1; + rcView.bottom = rcView.top + gMap.length + 2; CortBox2(&rcMiniMap, 0, SURFACE_ID_MAP); line = 0; diff --git a/src/MycParam.cpp b/src/MycParam.cpp index fd02d7d9..f2872935 100644 --- a/src/MycParam.cpp +++ b/src/MycParam.cpp @@ -173,7 +173,7 @@ void DamageMyChar(int damage) { PlaySoundObject(17, SOUND_MODE_PLAY); gMC.cond = 0; - SetDestroyNpChar(gMC.x, gMC.y, 0x1400, 0x40); + SetDestroyNpChar(gMC.x, gMC.y, 10 * 0x200, 0x40); StartTextScript(40); } } diff --git a/src/SelStage.cpp b/src/SelStage.cpp index c54b2d0c..3abf32b5 100644 --- a/src/SelStage.cpp +++ b/src/SelStage.cpp @@ -211,7 +211,8 @@ int StageSelectLoop(int *p_event) StopTextScript(); break; } - else if (gKeyTrg & gKeyCancel) + + if (gKeyTrg & gKeyCancel) { StopTextScript(); LoadTextScript_Stage(old_script_path);