ref: f3d073affe8a2d7e3eaef95b69423089b0c3f83e
parent: 25085ca6dea737e5349e9017939ec5b0fb6b9c03
author: Clownacy <Clownacy@users.noreply.github.com>
date: Fri May 10 16:40:58 EDT 2019
Made Profile.cpp mostly ASM-accurate The original code used MessageBoxA, but we haven't ported any of the WinAPI stuff yet, so there's no hWnd available.
--- a/msvc2003/devilution/comparer-config.toml
+++ b/msvc2003/devilution/comparer-config.toml
@@ -571,6 +571,22 @@
addr = 0x41CB10
[[func]]
+name = "IsProfile"
+addr = 0x41CFC0
+
+[[func]]
+name = "SaveProfile"
+addr = 0x41D040
+
+[[func]]
+name = "LoadProfile"
+addr = 0x41D260
+
+[[func]]
+name = "InitializeGame"
+addr = 0x41D550
+
+[[func]]
name = "ShootBullet_Frontia1"
addr = 0x41DBD0
--- a/src/Game.cpp
+++ b/src/Game.cpp
@@ -49,7 +49,7 @@
int g_GameFlags;
int gCounter;
-bool bContinue;
+BOOL bContinue;
int Random(int min, int max)
{
@@ -405,7 +405,7 @@
}
int char_y;
- if (bContinue == 1)
+ if (bContinue == TRUE)
char_y = (WINDOW_HEIGHT + 54) / 2;
else
char_y = (WINDOW_HEIGHT + 14) / 2;
--- a/src/Profile.cpp
+++ b/src/Profile.cpp
@@ -5,6 +5,8 @@
#include <stdio.h>
#include <string.h>
+#include "SDL.h"
+
#include "WindowsWrapper.h"
#include "ArmsItem.h"
@@ -27,7 +29,7 @@
const char *gDefaultName = "Profile.dat";
const char *gProfileCode = "Do041220";
-bool IsProfile()
+BOOL IsProfile()
{
char path[PATH_LENGTH];
sprintf(path, "%s/%s", gModulePath, gDefaultName);
@@ -34,17 +36,20 @@
FILE *fp = fopen(path, "rb");
if (fp == NULL)
- return false;
+ return FALSE;
fclose(fp);
- return true;
+ return TRUE;
}
-bool SaveProfile(const char *name)
+BOOL SaveProfile(const char *name)
{
- //Get path
+ PROFILE profile;
+ FILE *fp;
+ char *FLAG = "FLAG";
char path[PATH_LENGTH];
+ //Get path
if (name)
sprintf(path, "%s/%s", gModulePath, name);
else
@@ -51,16 +56,14 @@
sprintf(path, "%s/%s", gModulePath, gDefaultName);
//Open file
- PROFILE profile;
-
- FILE *fp = fopen(path, "wb");
+ fp = fopen(path, "wb");
if (fp == NULL)
- return false;
+ return FALSE;
//Set up profile
memset(&profile, 0, sizeof(PROFILE));
memcpy(profile.code, gProfileCode, sizeof(profile.code));
- memcpy(profile.FLAG, "FLAG", sizeof(profile.FLAG));
+ memcpy(profile.FLAG, FLAG, sizeof(profile.FLAG));
profile.stage = gStageNo;
profile.music = gMusicNo;
profile.x = gMC.x;
@@ -81,6 +84,9 @@
memcpy(profile.flags, gFlagNPC, sizeof(profile.flags));
//Write to file
+#ifdef NONPORTABLE
+ fwrite(&profile, sizeof(PROFILE), 1, fp);
+#else
fwrite(profile.code, 8, 1, fp);
File_WriteLE32(profile.stage, fp);
File_WriteLE32(profile.music, fp);
@@ -112,20 +118,21 @@
File_WriteLE32(profile.permitstage[stage].event, fp);
}
fwrite(profile.permit_mapping, 0x80, 1, fp);
- fwrite("FLAG", 4, 1, fp);
+ fwrite(FLAG, 4, 1, fp);
fwrite(profile.flags, 1000, 1, fp);
+#endif
fclose(fp);
- return true;
+ return TRUE;
}
-bool LoadProfile(const char *name)
+BOOL LoadProfile(const char *name)
{
//Get path
char path[PATH_LENGTH];
if (name)
- strcpy(path, name);
+ sprintf(path, "%s", name);
else
sprintf(path, "%s/%s", gModulePath, gDefaultName);
@@ -134,7 +141,7 @@
FILE *fp = fopen(path, "rb");
if (fp == NULL)
- return false;
+ return FALSE;
//Check header code
fread(profile.code, 8, 1, fp);
@@ -143,11 +150,15 @@
#ifdef FIX_BUGS
fclose(fp); // The original game forgets to close the file
#endif
- return false;
+ return FALSE;
}
//Read data
- fseek(fp, 0, SEEK_SET); //Pixel epic redundant code 😎😎😎
+ fseek(fp, 0, SEEK_SET);
+ memset(&profile, 0, sizeof(PROFILE));
+#ifdef NONPORTABLE
+ fread(&profile, sizeof(PROFILE), 1, fp);
+#else
fread(profile.code, 8, 1, fp);
profile.stage = File_ReadLE32(fp);
profile.music = File_ReadLE32(fp);
@@ -181,6 +192,7 @@
fread(profile.permit_mapping, 0x80, 1, fp);
fread(profile.FLAG, 4, 1, fp);
fread(profile.flags, 1000, 1, fp);
+#endif
fclose(fp);
//Set things
@@ -198,7 +210,7 @@
ChangeMusic(profile.music);
InitMyChar();
if (!TransferStage(profile.stage, 0, 0, 1))
- return false;
+ return FALSE;
//Set character properties
gMC.equip = profile.equip;
@@ -227,10 +239,10 @@
InitStar();
ClearValueView();
gCurlyShoot_wait = 0;
- return true;
+ return TRUE;
}
-bool InitializeGame()
+BOOL InitializeGame()
{
InitMyChar();
gSelectedArms = 0;
@@ -242,7 +254,24 @@
StartMapping();
InitFlags();
if (!TransferStage(13, 200, 10, 8))
- return false;
+ {
+ // TODO - restore this when hWnd is available
+/*#if defined(NONPORTABLE) && defined(WINDOWS)
+#ifdef JAPANESE
+ MessageBoxA(hWnd, "�X�e�[�W�̓ǂݍ��݂Ɏ��s", "�G���[", MB_OK);
+#else
+ MessageBoxA(hWnd, "Failed to load stage", "Error", MB_OK);
+#endif
+#else*/
+#ifdef JAPANESE
+ SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "�G���[", "�X�e�[�W�̓ǂݍ��݂Ɏ��s", NULL);
+#else
+ SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Failed to load stage", NULL);
+#endif
+//#endif
+ return FALSE;
+ }
+
ClearFade();
SetFrameMyChar();
SetFrameTargetMyChar(16);
@@ -252,5 +281,5 @@
gCurlyShoot_wait = 0;
SetFadeMask();
SetFrameTargetMyChar(16);
- return true;
+ return TRUE;
}
--- a/src/Profile.h
+++ b/src/Profile.h
@@ -2,6 +2,8 @@
#include <stdint.h>
+#include "WindowsWrapper.h"
+
#include "ArmsItem.h"
#include "SelStage.h"
@@ -30,7 +32,7 @@
uint8_t flags[1000];
};
-bool IsProfile();
-bool SaveProfile(const char *name);
-bool LoadProfile(const char *name);
-bool InitializeGame();
+BOOL IsProfile();
+BOOL SaveProfile(const char *name);
+BOOL LoadProfile(const char *name);
+BOOL InitializeGame();