diff --git a/src/Back.cpp b/src/Back.cpp index 09f9bbaf..e011f111 100644 --- a/src/Back.cpp +++ b/src/Back.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "WindowsWrapper.h" @@ -25,7 +26,9 @@ BOOL InitBack(const char *fName, int type) color_black = GetCortBoxColor(RGB(0, 0, 0x10)); // Get width and height - FILE *fp = fopen((gDataPath + '/' + fName + ".pbm").c_str(), "rb"); + std::string path = gDataPath + '/' + fName + ".pbm"; + + FILE *fp = fopen(path.c_str(), "rb"); if (fp == NULL) return FALSE; diff --git a/src/Backends/Misc.h b/src/Backends/Misc.h index 9fcddc26..1377d88d 100644 --- a/src/Backends/Misc.h +++ b/src/Backends/Misc.h @@ -1,8 +1,9 @@ #pragma once -#include "../Attributes.h" #include +#include "../Attributes.h" + enum { // Based on US QWERTY diff --git a/src/Backends/Platform/GLFW3.cpp b/src/Backends/Platform/GLFW3.cpp index 83fd83f2..9c84e8e0 100644 --- a/src/Backends/Platform/GLFW3.cpp +++ b/src/Backends/Platform/GLFW3.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include diff --git a/src/Backends/Platform/Null.cpp b/src/Backends/Platform/Null.cpp index a3988631..19f3f2a2 100644 --- a/src/Backends/Platform/Null.cpp +++ b/src/Backends/Platform/Null.cpp @@ -1,4 +1,5 @@ #include "../Misc.h" + #include bool Backend_Init(void) diff --git a/src/Backends/Platform/WiiU.cpp b/src/Backends/Platform/WiiU.cpp index af727ad4..28dc8d8e 100644 --- a/src/Backends/Platform/WiiU.cpp +++ b/src/Backends/Platform/WiiU.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -57,10 +58,11 @@ void Backend_PostWindowCreation(void) bool Backend_GetBasePath(std::string *string_buffer) { #ifdef JAPANESE - *string_buffer = std::string{WHBGetSdCardMountPath()} + "/CSE-portable-jp"; + *string_buffer = std::string{WHBGetSdCardMountPath()} + "/CSE2-portable-jp"; #else - *string_buffer = std::string{WHBGetSdCardMountPath()} + "/CSE-portable-en"; + *string_buffer = std::string{WHBGetSdCardMountPath()} + "/CSE2-portable-en"; #endif + return true; } diff --git a/src/Config.cpp b/src/Config.cpp index 3b4f4443..52a26456 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "WindowsWrapper.h" @@ -17,7 +18,9 @@ BOOL LoadConfigData(CONFIG *conf) memset(conf, 0, sizeof(CONFIG)); // Open file - FILE *fp = fopen((gModulePath + '/' + gConfigName).c_str(), "rb"); + std::string path = gModulePath + '/' + gConfigName; + + FILE *fp = fopen(path.c_str(), "rb"); if (fp == NULL) return FALSE; diff --git a/src/Draw.cpp b/src/Draw.cpp index 91333b9b..e70364ff 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "WindowsWrapper.h" @@ -250,7 +251,7 @@ BOOL MakeSurface_Resource(const char *name, SurfaceID surf_no) // TODO - Inaccurate stack frame BOOL MakeSurface_File(const char *name, SurfaceID surf_no) { - auto path = gDataPath + '/' + name + ".pbm"; + std::string path = gDataPath + '/' + name + ".pbm"; if (!IsEnableBitmap(path.c_str())) { @@ -340,7 +341,7 @@ BOOL ReloadBitmap_Resource(const char *name, SurfaceID surf_no) // TODO - Inaccurate stack frame BOOL ReloadBitmap_File(const char *name, SurfaceID surf_no) { - auto path = gDataPath + '/' + name + ".pbm"; + std::string path = gDataPath + '/' + name + ".pbm"; if (!IsEnableBitmap(path.c_str())) { @@ -376,6 +377,7 @@ BOOL ReloadBitmap_File(const char *name, SurfaceID surf_no) FreeBitmap(image_buffer); surface_metadata[surf_no].type = SURFACE_SOURCE_FILE; strcpy(surface_metadata[surf_no].name, name); + return TRUE; } @@ -644,6 +646,8 @@ void InitTextObject(const char *name) { (void)name; // Unused in this branch + std::string path = gDataPath + "/Font/font"; + // Get font size unsigned int width, height; @@ -660,7 +664,7 @@ void InitTextObject(const char *name) break; } - font = LoadFont((gDataPath + "/Font/font").c_str(), width, height); + font = LoadFont(path.c_str(), width, height); } void PutText(int x, int y, const char *text, unsigned long color) diff --git a/src/Ending.cpp b/src/Ending.cpp index 9314664e..130f1836 100644 --- a/src/Ending.cpp +++ b/src/Ending.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "WindowsWrapper.h" @@ -216,6 +217,7 @@ void ReleaseCreditScript(void) BOOL StartCreditScript(void) { FILE *fp; + std::string path; // Clear previously existing credits data if (Credit.pData != NULL) @@ -225,7 +227,8 @@ BOOL StartCreditScript(void) } // Open file - auto path = gDataPath + '/' + credit_script; + path = gDataPath + '/' + credit_script; + Credit.size = GetFileSizeLong(path.c_str()); if (Credit.size == -1) return FALSE; diff --git a/src/Game.cpp b/src/Game.cpp index 9914e669..7dd2e57c 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "WindowsWrapper.h" @@ -701,7 +702,9 @@ BOOL Game(void) PlaySoundObject(7, -1); - if (!LoadNpcTable((gDataPath + "/npc.tbl").c_str())) + std::string path = gDataPath + "/npc.tbl"; + + if (!LoadNpcTable(path.c_str())) { #ifdef JAPANESE Backend_ShowMessageBox("エラー", "NPCテーブルが読めない"); diff --git a/src/Generic.cpp b/src/Generic.cpp index c62e8c57..64dd00d9 100644 --- a/src/Generic.cpp +++ b/src/Generic.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "WindowsWrapper.h" @@ -49,12 +50,18 @@ BOOL GetCompileVersion(int *v1, int *v2, int *v3, int *v4) void DeleteLog(void) { - remove((gModulePath + "/debug.txt").c_str()); + std::string path = gModulePath + "/debug.txt"; + remove(path.c_str()); } BOOL WriteLog(const char *string, int value1, int value2, int value3) { - FILE *fp = fopen((gModulePath + "/debug.txt").c_str(), "a+"); + std::string path; + FILE *fp; + + path = gModulePath + "/debug.txt"; + fp = fopen(path.c_str(), "a+"); + if (fp == NULL) return FALSE; @@ -65,7 +72,10 @@ BOOL WriteLog(const char *string, int value1, int value2, int value3) BOOL IsKeyFile(const char *name) { - FILE *file = fopen((gModulePath + '/' + name).c_str(), "rb"); + std::string path = gModulePath + '/' + name; + + FILE *file = fopen(path.c_str(), "rb"); + if (file == NULL) return FALSE; @@ -93,12 +103,15 @@ long GetFileSizeLong(const char *path) BOOL ErrorLog(const char *string, int value) { - auto path = gModulePath + "/error.log"; + std::string path; + FILE *fp; + + path = gModulePath + "/error.log"; if (GetFileSizeLong(path.c_str()) > 0x19000) // Purge the error log if it gets too big, I guess remove(path.c_str()); - FILE *fp = fopen(path.c_str(), "a+"); + fp = fopen(path.c_str(), "a+"); if (fp == NULL) return FALSE; diff --git a/src/GenericLoad.cpp b/src/GenericLoad.cpp index 5eaad31d..850c799a 100644 --- a/src/GenericLoad.cpp +++ b/src/GenericLoad.cpp @@ -293,10 +293,9 @@ BOOL LoadGenericData(void) pt_size += MakePixToneObject(&gPtpTable[137], 1, 6); pt_size += MakePixToneObject(&gPtpTable[138], 1, 7); - /* - * char str[0x40]; - * sprintf(str, "PixTone = %d byte", pt_size); - * // There must have been some kind of console print function here or something - */ + // Commented-out, since ints *technically* have an undefined length + // char str[0x40]; + // sprintf(str, "PixTone = %d byte", pt_size); + // There must have been some kind of console print function here or something return TRUE; } diff --git a/src/Main.cpp b/src/Main.cpp index 8bbd7375..e59db1f3 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "WindowsWrapper.h" @@ -327,7 +328,7 @@ int main(int argc, char *argv[]) if (!Flip_SystemTask()) { Backend_Deinit(); - return EXIT_FAILURE; + return EXIT_SUCCESS; } // Initialize sound diff --git a/src/Main.h b/src/Main.h index ace8799a..95753c27 100644 --- a/src/Main.h +++ b/src/Main.h @@ -1,8 +1,9 @@ #pragma once -#include "WindowsWrapper.h" #include +#include "WindowsWrapper.h" + extern std::string gModulePath; extern std::string gDataPath; diff --git a/src/Map.cpp b/src/Map.cpp index 7ebfa675..e4f33cba 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "WindowsWrapper.h" @@ -27,10 +28,15 @@ BOOL InitMapData2(void) BOOL LoadMapData2(const char *path_map) { + FILE *fp; char check[3]; + std::string path; + + // Get path + path = gDataPath + '/' + path_map; // Open file - FILE *fp = fopen((gDataPath + '/' + path_map).c_str(), "rb"); + fp = fopen(path.c_str(), "rb"); if (fp == NULL) return FALSE; @@ -63,8 +69,13 @@ BOOL LoadMapData2(const char *path_map) BOOL LoadAttributeData(const char *path_atrb) { + FILE *fp; + std::string path; + // Open file - FILE *fp = fopen((gDataPath + '/' + path_atrb).c_str(), "rb"); + path = gDataPath + '/' + path_atrb; + + fp = fopen(path.c_str(), "rb"); if (fp == NULL) return FALSE; diff --git a/src/MycParam.cpp b/src/MycParam.cpp index 8d3119f2..969f4419 100644 --- a/src/MycParam.cpp +++ b/src/MycParam.cpp @@ -1,6 +1,7 @@ #include "MycParam.h" #include +#include #include "WindowsWrapper.h" @@ -435,15 +436,17 @@ BOOL SaveTimeCounter(void) int i; unsigned char p[4]; REC rec; + FILE *fp; + std::string path; // Quit if player doesn't have the Nikumaru Counter if (!(gMC.equip & EQUIP_NIKUMARU_COUNTER)) return TRUE; // Get last time - auto path = gModulePath + "/290.rec"; + path = gModulePath + "/290.rec"; - FILE *fp = fopen(path.c_str(), "rb"); + fp = fopen(path.c_str(), "rb"); if (fp != NULL) { // Read data @@ -505,9 +508,13 @@ int LoadTimeCounter(void) int i; unsigned char p[4]; REC rec; + FILE *fp; + std::string path; // Open file - FILE *fp = fopen((gModulePath + "/290.rec").c_str(), "rb"); + path = gModulePath + "/290.rec"; + + fp = fopen(path.c_str(), "rb"); if (fp == NULL) return 0; diff --git a/src/NpChar.cpp b/src/NpChar.cpp index 55a01d55..98616622 100644 --- a/src/NpChar.cpp +++ b/src/NpChar.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "WindowsWrapper.h" @@ -54,11 +55,14 @@ void InitNpChar(void) BOOL LoadEvent(const char *path_event) { int i, n; + FILE *fp; int count; char code[4]; EVENT eve; - FILE *fp = fopen((gDataPath + '/' + path_event).c_str(), "rb"); + std::string path = gDataPath + '/' + path_event; + + fp = fopen(path.c_str(), "rb"); if (fp == NULL) return FALSE; diff --git a/src/Profile.cpp b/src/Profile.cpp index 8642df63..dae0d570 100644 --- a/src/Profile.cpp +++ b/src/Profile.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "WindowsWrapper.h" @@ -28,7 +29,9 @@ const char* const gProfileCode = "Do041220"; BOOL IsProfile(void) { - FILE *file = fopen((gModulePath + '/' + gDefaultName).c_str(), "rb"); + std::string path = gModulePath + '/' + gDefaultName; + + FILE *file = fopen(path.c_str(), "rb"); if (file == NULL) return FALSE; @@ -38,15 +41,24 @@ BOOL IsProfile(void) BOOL SaveProfile(const char *name) { + FILE *fp; + PROFILE profile; const char *FLAG = "FLAG"; + std::string path; + + // Get path + if (name != NULL) + path = gModulePath + '/' + name; + else + path = gModulePath + '/' + gDefaultName; + // Open file - FILE *fp = fopen((gModulePath + '/' + ((name != NULL) ? name : gDefaultName)).c_str(), "wb"); + fp = fopen(path.c_str(), "wb"); if (fp == NULL) return FALSE; // Set up profile - PROFILE profile; memset(&profile, 0, sizeof(PROFILE)); memcpy(profile.code, gProfileCode, sizeof(profile.code)); memcpy(profile.FLAG, FLAG, sizeof(profile.FLAG)); @@ -110,15 +122,18 @@ BOOL SaveProfile(const char *name) BOOL LoadProfile(const char *name) { - PROFILE profile; - - // Open file FILE *fp; - if (name != NULL) - fp = fopen(name, "rb"); - else - fp = fopen((gModulePath + '/' + gDefaultName).c_str(), "rb"); + PROFILE profile; + std::string path; + // Get path + if (name != NULL) + path = name; + else + path = gModulePath + '/' + gDefaultName; + + // Open file + fp = fopen(path.c_str(), "rb"); if (fp == NULL) return FALSE; diff --git a/src/SelStage.cpp b/src/SelStage.cpp index 8686fb8e..17f68e1f 100644 --- a/src/SelStage.cpp +++ b/src/SelStage.cpp @@ -1,6 +1,7 @@ #include "SelStage.h" #include +#include #include "WindowsWrapper.h" @@ -156,11 +157,13 @@ void PutStageSelectObject(void) int StageSelectLoop(int *p_event) { + std::string old_script_path; + RECT rcView = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT}; gSelectedStage = 0; BackupSurface(SURFACE_ID_SCREEN_GRAB, &grcFull); - auto old_script_path = GetTextScriptPath(); + old_script_path = GetTextScriptPath(); LoadTextScript2("StageSelect.tsc"); gStageSelectTitleY = (WINDOW_HEIGHT / 2) - 66; StartTextScript(gPermitStage[gSelectedStage].index + 1000); diff --git a/src/Stage.cpp b/src/Stage.cpp index c2caf013..5e9f89ce 100644 --- a/src/Stage.cpp +++ b/src/Stage.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "WindowsWrapper.h" @@ -131,6 +132,8 @@ const STAGE_TABLE gTMT[95] = { BOOL TransferStage(int no, int w, int x, int y) { + std::string path; + std::string path_dir; BOOL bError; // Move character @@ -138,40 +141,47 @@ BOOL TransferStage(int no, int w, int x, int y) bError = FALSE; + // Get path + path_dir = "Stage"; + // Load tileset - auto path = std::string{"Stage/Prt"} + gTMT[no].parts; + path = path_dir + "/Prt" + gTMT[no].parts; if (!ReloadBitmap_File(path.c_str(), SURFACE_ID_LEVEL_TILESET)) bError = TRUE; - path = std::string{"Stage/"} + gTMT[no].parts + ".pxa"; + path = path_dir + "Stage/" + gTMT[no].parts + ".pxa"; if (!LoadAttributeData(path.c_str())) bError = TRUE; // Load tilemap - path = std::string{"Stage/"} + gTMT[no].map + ".pxm"; + path = path_dir + "Stage/" + gTMT[no].map + ".pxm"; if (!LoadMapData2(path.c_str())) bError = TRUE; // Load NPCs - path = std::string{"Stage/"} + gTMT[no].map + ".pxe"; + path = path_dir + "Stage/" + gTMT[no].map + ".pxe"; if (!LoadEvent(path.c_str())) bError = TRUE; // Load script - path = std::string{"Stage/"} + gTMT[no].map + ".tsc"; + path = path_dir + "Stage/" + gTMT[no].map + ".tsc"; if (!LoadTextScript_Stage(path.c_str())) bError = TRUE; // Load background - if (!InitBack(gTMT[no].back, gTMT[no].bkType)) + path = gTMT[no].back; + if (!InitBack(path.c_str(), gTMT[no].bkType)) bError = TRUE; + // Get path + path_dir = "Npc"; + // Load NPC sprite sheets - path = std::string{"Npc/Npc"} + gTMT[no].npc; + path = path_dir + "/Npc" + gTMT[no].npc; if (!ReloadBitmap_File(path.c_str(), SURFACE_ID_LEVEL_SPRITESET_1)) bError = TRUE; - path = std::string{"Npc/Npc"} + gTMT[no].boss; + path = path_dir + "/Npc" + gTMT[no].boss; if (!ReloadBitmap_File(path.c_str(), SURFACE_ID_LEVEL_SPRITESET_2)) bError = TRUE; diff --git a/src/TextScr.cpp b/src/TextScr.cpp index e0fd8150..e3ba2079 100644 --- a/src/TextScr.cpp +++ b/src/TextScr.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "WindowsWrapper.h" @@ -124,9 +125,10 @@ void EncryptionBinaryData2(unsigned char *pData, long size) BOOL LoadTextScript2(const char *name) { FILE *fp; + std::string path; // Get path - auto path = gDataPath + '/' + name; + path = gDataPath + '/' + name; gTS.size = GetFileSizeLong(path.c_str()); if (gTS.size == -1) @@ -155,11 +157,13 @@ BOOL LoadTextScript2(const char *name) BOOL LoadTextScript_Stage(const char *name) { FILE *fp; + std::string path; long head_size; long body_size; // Open Head.tsc - auto path = gDataPath + "/Head.tsc"; + path = gDataPath + "/Head.tsc"; + head_size = GetFileSizeLong(path.c_str()); if (head_size == -1) return FALSE; @@ -176,6 +180,7 @@ BOOL LoadTextScript_Stage(const char *name) // Open stage's .tsc path = gDataPath + '/' + name; + body_size = GetFileSizeLong(path.c_str()); if (body_size == -1) return FALSE; @@ -198,7 +203,7 @@ BOOL LoadTextScript_Stage(const char *name) } // Get current path -std::string GetTextScriptPath() +std::string GetTextScriptPath(void) { return gTS.path; } @@ -1277,13 +1282,11 @@ int TextScriptProc(void) } else { - // The size of str_0 is the size of the format string (includes null terminator so that's the space we'll be using for ours) + the 3 chars from the format string + char str_0[0x40]; #ifdef JAPANESE - char str_0[sizeof("不明のコード:<") + (sizeof(char) * 3)]; sprintf(str_0, "不明のコード:<%c%c%c", gTS.data[gTS.p_read + 1], gTS.data[gTS.p_read + 2], gTS.data[gTS.p_read + 3]); Backend_ShowMessageBox("エラー", str_0); #else - char str_0[sizeof("Unknown code:<%c%c%c") + (sizeof(char) * 3)]; sprintf(str_0, "Unknown code:<%c%c%c", gTS.data[gTS.p_read + 1], gTS.data[gTS.p_read + 2], gTS.data[gTS.p_read + 3]); Backend_ShowMessageBox("Error", str_0); #endif diff --git a/src/TextScr.h b/src/TextScr.h index 0f74c0fa..d73cbdd2 100644 --- a/src/TextScr.h +++ b/src/TextScr.h @@ -1,8 +1,9 @@ #pragma once -#include "WindowsWrapper.h" #include +#include "WindowsWrapper.h" + typedef struct TEXT_SCRIPT { // Path (reload when exit teleporter menu/inventory) @@ -63,7 +64,7 @@ void EndTextScript(void); void EncryptionBinaryData2(unsigned char *pData, long size); BOOL LoadTextScript2(const char *name); BOOL LoadTextScript_Stage(const char *name); -std::string GetTextScriptPath(); +std::string GetTextScriptPath(void); BOOL StartTextScript(int no); void StopTextScript(void); void PutTextScript(void);