shithub: cstory

Download patch

ref: 15f711b2ec2717b55867eeced1e4e376827bc1bb
parent: 9468659b4331fd2aaad48613c676c8650d2af555
author: Clownacy <Clownacy@users.noreply.github.com>
date: Wed Nov 13 20:42:06 EST 2019

ASM-accuracy improvement for Profile.cpp

I don't know how I missed an entire function before

--- a/src/Profile.cpp
+++ b/src/Profile.cpp
@@ -24,16 +24,18 @@
 const char *gDefaultName = "Profile.dat";
 const char *gProfileCode = "Do041220";
 
-BOOL IsProfile()
+BOOL IsProfile(void)
 {
 	char path[MAX_PATH];
+	HANDLE hFile;
+
 	sprintf(path, "%s\\%s", gModulePath, gDefaultName);
 
-	FILE *fp = fopen(path, "rb");
-	if (fp == NULL)
+	hFile = CreateFileA(path, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+	if (hFile == INVALID_HANDLE_VALUE)
 		return FALSE;
 
-	fclose(fp);
+	CloseHandle(hFile);
 	return TRUE;
 }
 
@@ -45,7 +47,7 @@
 	char path[MAX_PATH];
 
 	// Get path
-	if (name)
+	if (name != NULL)
 		sprintf(path, "%s\\%s", gModulePath, name);
 	else
 		sprintf(path, "%s\\%s", gModulePath, gDefaultName);
@@ -87,18 +89,18 @@
 
 BOOL LoadProfile(const char *name)
 {
-	// Get path
 	char path[MAX_PATH];
+	PROFILE profile;
+	FILE *fp;
 
-	if (name)
+	// Get path
+	if (name != NULL)
 		sprintf(path, "%s", name);
 	else
 		sprintf(path, "%s\\%s", gModulePath, gDefaultName);
 
 	// Open file
-	PROFILE profile;
-
-	FILE *fp = fopen(path, "rb");
+	fp = fopen(path, "rb");
 	if (fp == NULL)
 		return FALSE;
 
@@ -148,9 +150,9 @@
 	gMC.x = profile.x;
 	gMC.y = profile.y;
 
-	gMC.rect_arms.left = 24 * (gArmsData[gSelectedArms].code % 10);
+	gMC.rect_arms.left = (gArmsData[gSelectedArms].code % 10) * 24;
 	gMC.rect_arms.right = gMC.rect_arms.left + 24;
-	gMC.rect_arms.top = 32 * (gArmsData[gSelectedArms].code / 10);
+	gMC.rect_arms.top = (gArmsData[gSelectedArms].code / 10) * 32;
 	gMC.rect_arms.bottom = gMC.rect_arms.top + 16;
 
 	// Reset stuff
@@ -162,6 +164,7 @@
 	InitStar();
 	ClearValueView();
 	gCurlyShoot_wait = 0;
+
 	return TRUE;
 }
 
--- a/src/Profile.h
+++ b/src/Profile.h
@@ -31,7 +31,7 @@
 	unsigned char flags[1000];
 };
 
-BOOL IsProfile();
+BOOL IsProfile(void);
 BOOL SaveProfile(const char *name);
 BOOL LoadProfile(const char *name);
 BOOL InitializeGame(HWND hWnd);
--- a/src/SelStage.cpp
+++ b/src/SelStage.cpp
@@ -19,12 +19,13 @@
 
 void ClearPermitStage(void)
 {
-	memset(gPermitStage, 0, 0x40);
+	memset(gPermitStage, 0, sizeof(gPermitStage));
 }
 
 BOOL AddPermitStage(int index, int event)
 {
 	int i = 0;
+
 	while (i < 8)
 	{
 		if (gPermitStage[i].index == index)
@@ -48,6 +49,7 @@
 BOOL SubPermitStage(int index)
 {
 	int i;
+
 	for (i = 0; i < 8; ++i)
 		if (gPermitStage[i].index == index)
 			break;
@@ -59,10 +61,8 @@
 #endif
 		return FALSE;
 
-	for (i += 1; i < 8; ++i)
-	{
+	for (++i; i < 8; ++i)
 		gPermitStage[i - 1] = gPermitStage[i];
-	}
 
 	gPermitStage[i - 1].index = 0;
 	gPermitStage[i - 1].event = 0;
@@ -72,11 +72,14 @@
 
 void MoveStageSelectCursor(void)
 {
-	int stage_num = 0;
+	int stage_num;
+	int stage_x;
+
+	stage_num = 0;
 	while (gPermitStage[stage_num].index != 0)
 		++stage_num;
 
-	int stage_x = (WINDOW_WIDTH - 40 * stage_num) / 2;	// Unused
+	stage_x = (WINDOW_WIDTH - (stage_num * 40)) / 2;	// Unused
 
 	if (stage_num == 0)
 		return;
@@ -93,10 +96,10 @@
 	if (gSelectedStage > stage_num - 1)
 		gSelectedStage = 0;
 
-	if ((gKeyLeft | gKeyRight) & gKeyTrg)
+	if (gKeyTrg & (gKeyLeft | gKeyRight))
 		StartTextScript(gPermitStage[gSelectedStage].index + 1000);
 
-	if ((gKeyLeft | gKeyRight) & gKeyTrg)
+	if (gKeyTrg & (gKeyLeft | gKeyRight))
 		PlaySoundObject(1, 1);
 }
 
@@ -129,11 +132,11 @@
 
 	++flash;
 
-	if (stage_num)
+	if (stage_num != 0)
 	{
-		stage_x = (WINDOW_WIDTH - 40 * stage_num) / 2;
+		stage_x = (WINDOW_WIDTH - (stage_num * 40)) / 2;
 
-		PutBitmap3(&rcView, stage_x + 40 * gSelectedStage, (WINDOW_HEIGHT / 2) - 56, &rcCur[(flash >> 1) % 2], SURFACE_ID_TEXT_BOX);
+		PutBitmap3(&rcView, stage_x + (gSelectedStage * 40), (WINDOW_HEIGHT / 2) - 56, &rcCur[flash / 2 % 2], SURFACE_ID_TEXT_BOX);
 
 		for (i = 0; i < 8; ++i)
 		{
@@ -140,12 +143,12 @@
 			if (gPermitStage[i].index == 0)
 				break;
 
-			rcStage.left = 32 * (gPermitStage[i].index % 8);
+			rcStage.left = (gPermitStage[i].index % 8) * 32;
 			rcStage.right = rcStage.left + 32;
-			rcStage.top = 16 * (gPermitStage[i].index / 8);
+			rcStage.top = (gPermitStage[i].index / 8) * 16;
 			rcStage.bottom = rcStage.top + 16;
 
-			PutBitmap3(&rcView, stage_x + 40 * i, (WINDOW_HEIGHT / 2) - 56, &rcStage, SURFACE_ID_STAGE_ITEM);
+			PutBitmap3(&rcView, stage_x + (i * 40), (WINDOW_HEIGHT / 2) - 56, &rcStage, SURFACE_ID_STAGE_ITEM);
 		}
 	}
 }