ref: f8d4ae7014f18105de8ebe54667c2c1f15505df5
parent: 666269029dbd79b2fdbe46131d853af9b2801cdf
author: Clownacy <Clownacy@users.noreply.github.com>
date: Tue May 7 09:52:50 EDT 2019
Made Stage.cpp ASM-accurate
--- a/msvc2003/devilution/comparer-config.toml
+++ b/msvc2003/devilution/comparer-config.toml
@@ -615,6 +615,18 @@
addr = 0x420640
[[func]]
+name = "TransferStage"
+addr = 0x420BE0
+
+[[func]]
+name = "ChangeMusic"
+addr = 0x420EE0
+
+[[func]]
+name = "ReCallMusic"
+addr = 0x420F50
+
+[[func]]
name = "InitStar"
addr = 0x420FA0
--- a/src/NpChar.cpp
+++ b/src/NpChar.cpp
@@ -53,7 +53,7 @@
npc->view.bottom = gNpcTable[code].view.bottom << 9;
}
-bool LoadEvent(const char *path_event)
+BOOL LoadEvent(const char *path_event)
{
char path[PATH_LENGTH];
sprintf(path, "%s/%s", gDataPath, path_event);
@@ -60,7 +60,7 @@
FILE *fp = fopen(path, "rb");
if (fp == NULL)
- return false;
+ return FALSE;
//Read "PXE" check
char code[4];
@@ -71,7 +71,7 @@
// The original game forgot to close the file here
fclose(fp);
#endif
- return false;
+ return FALSE;
}
//Get amount of NPCs
@@ -128,7 +128,7 @@
}
fclose(fp);
- return true;
+ return TRUE;
}
void SetNpChar(int code_char, int x, int y, int xm, int ym, int dir, NPCHAR *npc, int start_index)
@@ -235,7 +235,7 @@
}
}
-bool SetBulletObject(int x, int y, int val)
+BOOL SetBulletObject(int x, int y, int val)
{
int tamakazu_ari[10];
@@ -254,7 +254,7 @@
}
if (!t)
- return false;
+ return FALSE;
n = Random(1, 10 * t);
int bullet_no = tamakazu_ari[n % t];
@@ -272,14 +272,14 @@
gNPC[n].bits = gNpcTable[gNPC[n].code_char].bits;
gNPC[n].exp = val;
SetUniqueParameter(&gNPC[n]);
- return true;
+ return TRUE;
}
}
- return false;
+ return FALSE;
}
-bool SetLifeObject(int x, int y, int val)
+BOOL SetLifeObject(int x, int y, int val)
{
for (int n = 0x100; n < NPC_MAX; n++)
{
@@ -294,11 +294,11 @@
gNPC[n].bits = gNpcTable[gNPC[n].code_char].bits;
gNPC[n].exp = val;
SetUniqueParameter(&gNPC[n]);
- return true;
+ return TRUE;
}
}
- return false;
+ return FALSE;
}
void VanishNpChar(NPCHAR *npc)
--- a/src/NpChar.h
+++ b/src/NpChar.h
@@ -83,13 +83,13 @@
extern int gSuperYpos;
void InitNpChar();
-bool LoadEvent(const char *path_event);
+BOOL LoadEvent(const char *path_event);
void SetNpChar(int code_char, int x, int y, int xm, int ym, int dir, NPCHAR *npc, int start_index);
void SetDestroyNpChar(int x, int y, int w, int num);
void SetDestroyNpCharUp(int x, int y, int w, int num);
void SetExpObjects(int x, int y, int exp);
-bool SetBulletObject(int x, int y, int val);
-bool SetLifeObject(int x, int y, int val);
+BOOL SetBulletObject(int x, int y, int val);
+BOOL SetLifeObject(int x, int y, int val);
void VanishNpChar(NPCHAR *npc);
void PutNpChar(int fx, int fy);
void ActNpChar();
--- a/src/Stage.cpp
+++ b/src/Stage.cpp
@@ -132,7 +132,7 @@
BOOL TransferStage(int no, int w, int x, int y)
{
//Move character
- SetMyCharPosition(x << 13, y << 13);
+ SetMyCharPosition(x * 0x10 * 0x200, y * 0x10 * 0x200);
BOOL bError = FALSE;
@@ -166,7 +166,7 @@
bError = TRUE;
//Load background
- strcpy(path, gTMT[no].back);
+ sprintf(path, "%s", gTMT[no].back);
if (!InitBack(path, gTMT[no].bkType))
bError = TRUE;
@@ -183,28 +183,21 @@
bError = TRUE;
if (bError)
- {
- printf("Failed to load stage %d\n", no);
return FALSE;
- }
- else
- {
- //Load map name
- ReadyMapName(gTMT[no].name);
- StartTextScript(w);
- SetFrameMyChar();
- ClearBullet();
- InitCaret();
- ClearValueView();
- ResetQuake();
- InitBossChar(gTMT[no].boss_no);
- ResetFlash();
- gStageNo = no;
- return TRUE;
- }
+ //Load map name
+ ReadyMapName(gTMT[no].name);
- return FALSE;
+ StartTextScript(w);
+ SetFrameMyChar();
+ ClearBullet();
+ InitCaret();
+ ClearValueView();
+ ResetQuake();
+ InitBossChar(gTMT[no].boss_no);
+ ResetFlash();
+ gStageNo = no;
+ return TRUE;
}
//Music
@@ -264,22 +257,22 @@
void ChangeMusic(int no)
{
- if (!no || no != gMusicNo)
- {
- //Stop and keep track of old song
- gOldPos = GetOrganyaPosition();
- gOldNo = gMusicNo;
- StopOrganyaMusic();
+ if (no && no == gMusicNo)
+ return;
- //Load .org
- LoadOrganya(gMusicTable[no]);
+ //Stop and keep track of old song
+ gOldPos = GetOrganyaPosition();
+ gOldNo = gMusicNo;
+ StopOrganyaMusic();
- //Reset position, volume, and then play the song
- ChangeOrganyaVolume(100);
- SetOrganyaPosition(0);
- PlayOrganyaMusic();
- gMusicNo = no;
- }
+ //Load .org
+ LoadOrganya(gMusicTable[no]);
+
+ //Reset position, volume, and then play the song
+ ChangeOrganyaVolume(100);
+ SetOrganyaPosition(0);
+ PlayOrganyaMusic();
+ gMusicNo = no;
}
void ReCallMusic()
--- a/src/TextScr.cpp
+++ b/src/TextScr.cpp
@@ -112,7 +112,7 @@
}
//Load generic .tsc
-bool LoadTextScript2(const char *name)
+BOOL LoadTextScript2(const char *name)
{
//Get path
char path[260];
@@ -120,12 +120,12 @@
gTS.size = GetFileSizeLong(path);
if (gTS.size == -1)
- return false;
+ return FALSE;
//Open file
FILE *fp = fopen(path, "rb");
if (fp == NULL)
- return false;
+ return FALSE;
//Read data
fread(gTS.data, 1, gTS.size, fp);
@@ -137,11 +137,11 @@
//Decrypt data
EncryptionBinaryData2((uint8_t*)gTS.data, gTS.size);
- return true;
+ return TRUE;
}
//Load stage .tsc
-bool LoadTextScript_Stage(const char *name)
+BOOL LoadTextScript_Stage(const char *name)
{
//Open Head.tsc
char path[PATH_LENGTH];
@@ -149,11 +149,11 @@
long head_size = GetFileSizeLong(path);
if (head_size == -1)
- return false;
+ return FALSE;
FILE *fp = fopen(path, "rb");
if (fp == NULL)
- return false;
+ return FALSE;
//Read Head.tsc
fread(gTS.data, 1, head_size, fp);
@@ -166,11 +166,11 @@
long body_size = GetFileSizeLong(path);
if (body_size == -1)
- return false;
+ return FALSE;
fp = fopen(path, "rb");
if (fp == NULL)
- return false;
+ return FALSE;
//Read stage's tsc
fread(&gTS.data[head_size], 1, body_size, fp);
@@ -181,7 +181,7 @@
//Set parameters
gTS.size = head_size + body_size;
strcpy(gTS.path, name);
- return true;
+ return TRUE;
}
//Get current path
--- a/src/TextScr.h
+++ b/src/TextScr.h
@@ -60,8 +60,8 @@
BOOL InitTextScript2();
void EndTextScript();
void EncryptionBinaryData2(uint8_t *pData, int size);
-bool LoadTextScript2(const char *name);
-bool LoadTextScript_Stage(const char *name);
+BOOL LoadTextScript2(const char *name);
+BOOL LoadTextScript_Stage(const char *name);
void GetTextScriptPath(char *path);
BOOL StartTextScript(int no);
void StopTextScript();