diff --git a/src/Profile.cpp b/src/Profile.cpp index f9dc051c..4f228244 100644 --- 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 @@ BOOL SaveProfile(const char *name) 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 SaveProfile(const char *name) 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 @@ BOOL LoadProfile(const char *name) 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 @@ BOOL LoadProfile(const char *name) InitStar(); ClearValueView(); gCurlyShoot_wait = 0; + return TRUE; } diff --git a/src/Profile.h b/src/Profile.h index 3bbe37bd..7298a230 100644 --- a/src/Profile.h +++ b/src/Profile.h @@ -31,7 +31,7 @@ struct PROFILE unsigned char flags[1000]; }; -BOOL IsProfile(); +BOOL IsProfile(void); BOOL SaveProfile(const char *name); BOOL LoadProfile(const char *name); BOOL InitializeGame(HWND hWnd); diff --git a/src/SelStage.cpp b/src/SelStage.cpp index aa4d3a02..0d176fc4 100644 --- a/src/SelStage.cpp +++ b/src/SelStage.cpp @@ -19,12 +19,13 @@ static int gStageSelectTitleY; 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 AddPermitStage(int index, int event) BOOL SubPermitStage(int index) { int i; + for (i = 0; i < 8; ++i) if (gPermitStage[i].index == index) break; @@ -59,10 +61,8 @@ BOOL SubPermitStage(int index) #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 @@ BOOL SubPermitStage(int index) 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 @@ void MoveStageSelectCursor(void) 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,23 +132,23 @@ void PutStageSelectObject(void) ++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) { 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); } } }