diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index 9c39d1f9..5a897345 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -1,6 +1,7 @@ #include "ArmsItem.h" #include +#include #include "WindowsWrapper.h" @@ -414,12 +415,12 @@ void PutCampObject(void) int CampLoop(void) { - char old_script_path[MAX_PATH]; + std::string old_script_path; RECT rcView = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT}; // Save the current script path (to restore it when we get out of the inventory) - GetTextScriptPath(old_script_path); + old_script_path = GetTextScriptPath(); // Load the inventory script LoadTextScript2("ArmsItem.tsc"); @@ -498,7 +499,7 @@ int CampLoop(void) } // Resume original script - LoadTextScript_Stage(old_script_path); + LoadTextScript_Stage(old_script_path.c_str()); gArmsEnergyX = 32; // Displays weapon rotation animation in case the weapon was changed return enum_ESCRETURN_continue; // Go to game } diff --git a/src/Attributes.h b/src/Attributes.h index 35fcd26f..a6c318b6 100644 --- a/src/Attributes.h +++ b/src/Attributes.h @@ -13,7 +13,6 @@ #ifdef __GNUC__ #define ATTRIBUTE_HOT __attribute__((hot)) -#define ATTRIBUTE_OPTIMIZE(optString) __attribute__((optimize(optString))) #define LIKELY(condition) __builtin_expect((condition), 1) #define UNLIKELY(condition) __builtin_expect((condition), 0) #define PREFETCH(address, isWrite, locality) __builtin_prefetch((address), (isWrite), (locality)) @@ -21,7 +20,6 @@ #else #define ATTRIBUTE_HOT -#define ATTRIBUTE_OPTIMIZE(optString) #define LIKELY(condition) condition #define UNLIKELY(condition) condition #define PREFETCH(address, isWrite, locality) diff --git a/src/Back.cpp b/src/Back.cpp index dab38a48..e011f111 100644 --- a/src/Back.cpp +++ b/src/Back.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "WindowsWrapper.h" @@ -25,10 +26,9 @@ BOOL InitBack(const char *fName, int type) color_black = GetCortBoxColor(RGB(0, 0, 0x10)); // Get width and height - char path[MAX_PATH]; - sprintf(path, "%s/%s.pbm", gDataPath, fName); + std::string path = gDataPath + '/' + fName + ".pbm"; - FILE *fp = fopen(path, "rb"); + 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 103ff98c..1377d88d 100644 --- a/src/Backends/Misc.h +++ b/src/Backends/Misc.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "../Attributes.h" enum @@ -86,7 +88,7 @@ enum bool Backend_Init(void); void Backend_Deinit(void); void Backend_PostWindowCreation(void); -bool Backend_GetBasePath(char *string_buffer); +bool Backend_GetBasePath(std::string *string_buffer); void Backend_HideMouse(void); void Backend_SetWindowIcon(const unsigned char *rgb_pixels, unsigned int width, unsigned int height); void Backend_SetCursor(const unsigned char *rgb_pixels, unsigned int width, unsigned int height); diff --git a/src/Backends/Platform/GLFW3.cpp b/src/Backends/Platform/GLFW3.cpp index e36c3a4e..9c84e8e0 100644 --- a/src/Backends/Platform/GLFW3.cpp +++ b/src/Backends/Platform/GLFW3.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -181,7 +182,7 @@ void Backend_PostWindowCreation(void) glfwSetWindowSizeCallback(window, WindowSizeCallback); } -bool Backend_GetBasePath(char *string_buffer) +bool Backend_GetBasePath(std::string *string_buffer) { (void)string_buffer; diff --git a/src/Backends/Platform/Null.cpp b/src/Backends/Platform/Null.cpp index c4005d9b..19f3f2a2 100644 --- a/src/Backends/Platform/Null.cpp +++ b/src/Backends/Platform/Null.cpp @@ -1,5 +1,7 @@ #include "../Misc.h" +#include + bool Backend_Init(void) { return true; @@ -15,7 +17,7 @@ void Backend_PostWindowCreation(void) } -bool Backend_GetBasePath(char *string_buffer) +bool Backend_GetBasePath(std::string *string_buffer) { (void)string_buffer; diff --git a/src/Backends/Platform/SDL2.cpp b/src/Backends/Platform/SDL2.cpp index 1408b605..1d9e2484 100644 --- a/src/Backends/Platform/SDL2.cpp +++ b/src/Backends/Platform/SDL2.cpp @@ -84,13 +84,15 @@ void Backend_PostWindowCreation(void) } -bool Backend_GetBasePath(char *string_buffer) +bool Backend_GetBasePath(std::string *string_buffer) { #ifdef _WIN32 // SDL_GetBasePath returns a UTF-8 string, but Windows' fopen uses (extended?) ASCII. // This is apparently a problem for accented characters, as they will make fopen fail. // So, instead, we rely on argv[0], as that will put the accented characters in a // format Windows will understand. + (void)string_buffer; + return false; #else char *base_path = SDL_GetBasePath(); @@ -100,7 +102,7 @@ bool Backend_GetBasePath(char *string_buffer) // Trim the trailing '/' size_t base_path_length = strlen(base_path); base_path[base_path_length - 1] = '\0'; - strcpy(string_buffer, base_path); + *string_buffer = base_path; SDL_free(base_path); return true; diff --git a/src/Backends/Platform/WiiU.cpp b/src/Backends/Platform/WiiU.cpp index 578e1df3..f18be654 100644 --- a/src/Backends/Platform/WiiU.cpp +++ b/src/Backends/Platform/WiiU.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -54,13 +55,13 @@ void Backend_PostWindowCreation(void) } -bool Backend_GetBasePath(char *string_buffer) +bool Backend_GetBasePath(std::string *string_buffer) { - strcpy(string_buffer, WHBGetSdCardMountPath()); + *string_buffer = WHBGetSdCardMountPath(); #ifdef JAPANESE - strcat(string_buffer, "/CSE2-portable-jp"); + *string_buffer += "/CSE2-portable-jp"; #else - strcat(string_buffer, "/CSE2-portable-en"); + *string_buffer += "/CSE2-portable-en"; #endif return true; diff --git a/src/Config.cpp b/src/Config.cpp index e2afcb95..02bf5da3 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "WindowsWrapper.h" @@ -17,11 +18,10 @@ BOOL LoadConfigData(CONFIG *conf) memset(conf, 0, sizeof(CONFIG)); // Get path - char path[MAX_PATH]; - sprintf(path, "%s/%s", gModulePath, gConfigName); + std::string path = gModulePath + '/' + gConfigName; // Open file - FILE *fp = fopen(path, "rb"); + FILE *fp = fopen(path.c_str(), "rb"); if (fp == NULL) return FALSE; diff --git a/src/Draw.cpp b/src/Draw.cpp index 7673d59b..e70364ff 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "WindowsWrapper.h" @@ -250,12 +251,11 @@ BOOL MakeSurface_Resource(const char *name, SurfaceID surf_no) // TODO - Inaccurate stack frame BOOL MakeSurface_File(const char *name, SurfaceID surf_no) { - char path[MAX_PATH]; - sprintf(path, "%s/%s.pbm", gDataPath, name); + std::string path = gDataPath + '/' + name + ".pbm"; - if (!IsEnableBitmap(path)) + if (!IsEnableBitmap(path.c_str())) { - ErrorLog(path, 0); + ErrorLog(path.c_str(), 0); return FALSE; } @@ -276,11 +276,11 @@ BOOL MakeSurface_File(const char *name, SurfaceID surf_no) } unsigned int width, height; - unsigned char *image_buffer = DecodeBitmapFromFile(path, &width, &height); + unsigned char *image_buffer = DecodeBitmapFromFile(path.c_str(), &width, &height); if (image_buffer == NULL) { - ErrorLog(path, 1); + ErrorLog(path.c_str(), 1); return FALSE; } @@ -341,12 +341,11 @@ BOOL ReloadBitmap_Resource(const char *name, SurfaceID surf_no) // TODO - Inaccurate stack frame BOOL ReloadBitmap_File(const char *name, SurfaceID surf_no) { - char path[MAX_PATH]; - sprintf(path, "%s/%s.pbm", gDataPath, name); + std::string path = gDataPath + '/' + name + ".pbm"; - if (!IsEnableBitmap(path)) + if (!IsEnableBitmap(path.c_str())) { - ErrorLog(path, 0); + ErrorLog(path.c_str(), 0); return FALSE; } @@ -361,11 +360,11 @@ BOOL ReloadBitmap_File(const char *name, SurfaceID surf_no) } unsigned int width, height; - unsigned char *image_buffer = DecodeBitmapFromFile(path, &width, &height); + unsigned char *image_buffer = DecodeBitmapFromFile(path.c_str(), &width, &height); if (image_buffer == NULL) { - ErrorLog(path, 1); + ErrorLog(path.c_str(), 1); return FALSE; } @@ -647,8 +646,7 @@ void InitTextObject(const char *name) { (void)name; // Unused in this branch - char path[MAX_PATH]; - sprintf(path, "%s/Font/font", gDataPath); + std::string path = gDataPath + "/Font/font"; // Get font size unsigned int width, height; @@ -666,7 +664,7 @@ void InitTextObject(const char *name) break; } - font = LoadFont(path, 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 1a4532ff..130f1836 100644 --- a/src/Ending.cpp +++ b/src/Ending.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "WindowsWrapper.h" @@ -216,7 +217,7 @@ void ReleaseCreditScript(void) BOOL StartCreditScript(void) { FILE *fp; - char path[MAX_PATH]; + std::string path; // Clear previously existing credits data if (Credit.pData != NULL) @@ -226,9 +227,9 @@ BOOL StartCreditScript(void) } // Open file - sprintf(path, "%s/%s", gDataPath, credit_script); + path = gDataPath + '/' + credit_script; - Credit.size = GetFileSizeLong(path); + Credit.size = GetFileSizeLong(path.c_str()); if (Credit.size == -1) return FALSE; @@ -237,7 +238,7 @@ BOOL StartCreditScript(void) if (Credit.pData == NULL) return FALSE; - fp = fopen(path, "rb"); + fp = fopen(path.c_str(), "rb"); if (fp == NULL) { free(Credit.pData); diff --git a/src/Game.cpp b/src/Game.cpp index 3a0608aa..7dd2e57c 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "WindowsWrapper.h" @@ -701,10 +702,9 @@ BOOL Game(void) PlaySoundObject(7, -1); - char path[MAX_PATH]; - sprintf(path, "%s/npc.tbl", gDataPath); + std::string path = gDataPath + "/npc.tbl"; - if (!LoadNpcTable(path)) + if (!LoadNpcTable(path.c_str())) { #ifdef JAPANESE Backend_ShowMessageBox("エラー", "NPCテーブルが読めない"); diff --git a/src/Generic.cpp b/src/Generic.cpp index 5ef2a272..6312bfc1 100644 --- a/src/Generic.cpp +++ b/src/Generic.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "WindowsWrapper.h" @@ -49,19 +50,19 @@ BOOL GetCompileVersion(int *v1, int *v2, int *v3, int *v4) void DeleteLog(void) { - char path[MAX_PATH]; + std::string path; - sprintf(path, "%s/debug.txt", gModulePath); - remove(path); + path = gModulePath + "/debug.txt"; + remove(path.c_str()); } BOOL WriteLog(const char *string, int value1, int value2, int value3) { - char path[MAX_PATH]; + std::string path; FILE *fp; - sprintf(path, "%s/debug.txt", gModulePath); - fp = fopen(path, "a+"); + path = gModulePath + "/debug.txt"; + fp = fopen(path.c_str(), "a+"); if (fp == NULL) return FALSE; @@ -73,11 +74,9 @@ BOOL WriteLog(const char *string, int value1, int value2, int value3) BOOL IsKeyFile(const char *name) { - char path[MAX_PATH]; + std::string path = gModulePath + '/' + name; - sprintf(path, "%s/%s", gModulePath, name); - - FILE *file = fopen(path, "rb"); + FILE *file = fopen(path.c_str(), "rb"); if (file == NULL) return FALSE; @@ -105,15 +104,15 @@ long GetFileSizeLong(const char *path) BOOL ErrorLog(const char *string, int value) { - char path[MAX_PATH]; + std::string path; FILE *fp; - sprintf(path, "%s/%s", gModulePath, "error.log"); + path = gModulePath + "/error.log"; - if (GetFileSizeLong(path) > 0x19000) // Purge the error log if it gets too big, I guess - remove(path); + if (GetFileSizeLong(path.c_str()) > 0x19000) // Purge the error log if it gets too big, I guess + remove(path.c_str()); - fp = fopen(path, "a+"); + fp = fopen(path.c_str(), "a+"); if (fp == NULL) return FALSE; diff --git a/src/GenericLoad.cpp b/src/GenericLoad.cpp index 9f177091..850c799a 100644 --- a/src/GenericLoad.cpp +++ b/src/GenericLoad.cpp @@ -293,8 +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); + // 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 7ecc3e91..e59db1f3 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "WindowsWrapper.h" @@ -25,8 +26,8 @@ #include "Sound.h" #include "Triangle.h" -char gModulePath[MAX_PATH]; -char gDataPath[MAX_PATH]; +std::string gModulePath; +std::string gDataPath; BOOL bFullscreen; BOOL gbUseJoystick = FALSE; @@ -93,24 +94,23 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; // Get executable's path - if (!Backend_GetBasePath(gModulePath)) + if (!Backend_GetBasePath(&gModulePath)) { // Fall back on argv[0] if the backend cannot provide a path - strcpy(gModulePath, argv[0]); + gModulePath = argv[0]; - for (size_t i = strlen(gModulePath);; --i) + for (size_t i = gModulePath.length();; --i) { if (i == 0 || gModulePath[i] == '\\' || gModulePath[i] == '/') { - gModulePath[i] = '\0'; + gModulePath.resize(i); break; } } } // Get path of the data folder - strcpy(gDataPath, gModulePath); - strcat(gDataPath, "/data"); + gDataPath = gModulePath + "/data"; CONFIG conf; if (!LoadConfigData(&conf)) diff --git a/src/Main.h b/src/Main.h index 62d618bd..95753c27 100644 --- a/src/Main.h +++ b/src/Main.h @@ -1,9 +1,11 @@ #pragma once +#include + #include "WindowsWrapper.h" -extern char gModulePath[MAX_PATH]; -extern char gDataPath[MAX_PATH]; +extern std::string gModulePath; +extern std::string gDataPath; extern BOOL bFullscreen; extern BOOL gbUseJoystick; diff --git a/src/Map.cpp b/src/Map.cpp index 6cd6ac3e..e4f33cba 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "WindowsWrapper.h" @@ -29,13 +30,13 @@ BOOL LoadMapData2(const char *path_map) { FILE *fp; char check[3]; - char path[MAX_PATH]; + std::string path; // Get path - sprintf(path, "%s/%s", gDataPath, path_map); + path = gDataPath + '/' + path_map; // Open file - fp = fopen(path, "rb"); + fp = fopen(path.c_str(), "rb"); if (fp == NULL) return FALSE; @@ -69,12 +70,12 @@ BOOL LoadMapData2(const char *path_map) BOOL LoadAttributeData(const char *path_atrb) { FILE *fp; - char path[MAX_PATH]; + std::string path; // Open file - sprintf(path, "%s/%s", gDataPath, path_atrb); + path = gDataPath + '/' + path_atrb; - fp = fopen(path, "rb"); + fp = fopen(path.c_str(), "rb"); if (fp == NULL) return FALSE; diff --git a/src/MycParam.cpp b/src/MycParam.cpp index fe15772e..969f4419 100644 --- a/src/MycParam.cpp +++ b/src/MycParam.cpp @@ -1,6 +1,7 @@ #include "MycParam.h" #include +#include #include "WindowsWrapper.h" @@ -436,16 +437,16 @@ BOOL SaveTimeCounter(void) unsigned char p[4]; REC rec; FILE *fp; - char path[MAX_PATH]; + std::string path; // Quit if player doesn't have the Nikumaru Counter if (!(gMC.equip & EQUIP_NIKUMARU_COUNTER)) return TRUE; // Get last time - sprintf(path, "%s/290.rec", gModulePath); + path = gModulePath + "/290.rec"; - fp = fopen(path, "rb"); + fp = fopen(path.c_str(), "rb"); if (fp != NULL) { // Read data @@ -485,7 +486,7 @@ BOOL SaveTimeCounter(void) rec.counter[i] = p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24); } - fp = fopen(path, "wb"); + fp = fopen(path.c_str(), "wb"); if (fp == NULL) return FALSE; @@ -508,12 +509,12 @@ int LoadTimeCounter(void) unsigned char p[4]; REC rec; FILE *fp; - char path[MAX_PATH]; + std::string path; // Open file - sprintf(path, "%s/290.rec", gModulePath); + path = gModulePath + "/290.rec"; - fp = fopen(path, "rb"); + fp = fopen(path.c_str(), "rb"); if (fp == NULL) return 0; diff --git a/src/NpChar.cpp b/src/NpChar.cpp index d5d7b261..98616622 100644 --- a/src/NpChar.cpp +++ b/src/NpChar.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "WindowsWrapper.h" @@ -59,10 +60,9 @@ BOOL LoadEvent(const char *path_event) char code[4]; EVENT eve; - char path[MAX_PATH]; - sprintf(path, "%s/%s", gDataPath, path_event); + std::string path = gDataPath + '/' + path_event; - fp = fopen(path, "rb"); + fp = fopen(path.c_str(), "rb"); if (fp == NULL) return FALSE; diff --git a/src/Profile.cpp b/src/Profile.cpp index 7d0c9cfa..093ca1ec 100644 --- a/src/Profile.cpp +++ b/src/Profile.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "WindowsWrapper.h" @@ -28,10 +29,9 @@ const char* const gProfileCode = "Do041220"; BOOL IsProfile(void) { - char path[MAX_PATH]; - sprintf(path, "%s/%s", gModulePath, gDefaultName); + std::string path = gModulePath + '/' + gDefaultName; - FILE *file = fopen(path, "rb"); + FILE *file = fopen(path.c_str(), "rb"); if (file == NULL) return FALSE; @@ -45,16 +45,16 @@ BOOL SaveProfile(const char *name) PROFILE profile; const char *FLAG = "FLAG"; - char path[MAX_PATH]; + std::string path; // Get path if (name != NULL) - sprintf(path, "%s/%s", gModulePath, name); + path = gModulePath + '/' + name; else - sprintf(path, "%s/%s", gModulePath, gDefaultName); + path = gModulePath + '/' + gDefaultName; // Open file - fp = fopen(path, "wb"); + fp = fopen(path.c_str(), "wb"); if (fp == NULL) return FALSE; @@ -124,16 +124,16 @@ BOOL LoadProfile(const char *name) { FILE *fp; PROFILE profile; - char path[MAX_PATH]; + std::string path; // Get path if (name != NULL) - sprintf(path, "%s", name); + path = name; else - sprintf(path, "%s/%s", gModulePath, gDefaultName); + path = gModulePath + '/' + gDefaultName; // Open file - fp = fopen(path, "rb"); + fp = fopen(path.c_str(), "rb"); if (fp == NULL) return FALSE; diff --git a/src/SelStage.cpp b/src/SelStage.cpp index 1202ac01..17f68e1f 100644 --- a/src/SelStage.cpp +++ b/src/SelStage.cpp @@ -1,6 +1,7 @@ #include "SelStage.h" #include +#include #include "WindowsWrapper.h" @@ -156,13 +157,13 @@ void PutStageSelectObject(void) int StageSelectLoop(int *p_event) { - char old_script_path[MAX_PATH]; + std::string old_script_path; RECT rcView = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT}; gSelectedStage = 0; BackupSurface(SURFACE_ID_SCREEN_GRAB, &grcFull); - GetTextScriptPath(old_script_path); + old_script_path = GetTextScriptPath(); LoadTextScript2("StageSelect.tsc"); gStageSelectTitleY = (WINDOW_HEIGHT / 2) - 66; StartTextScript(gPermitStage[gSelectedStage].index + 1000); @@ -211,7 +212,7 @@ int StageSelectLoop(int *p_event) else if (gKeyTrg & gKeyCancel) { StopTextScript(); - LoadTextScript_Stage(old_script_path); + LoadTextScript_Stage(old_script_path.c_str()); *p_event = 0; return enum_ESCRETURN_continue; } @@ -222,7 +223,7 @@ int StageSelectLoop(int *p_event) return enum_ESCRETURN_exit; } - LoadTextScript_Stage(old_script_path); + LoadTextScript_Stage(old_script_path.c_str()); *p_event = gPermitStage[gSelectedStage].event; return enum_ESCRETURN_continue; } diff --git a/src/Stage.cpp b/src/Stage.cpp index 21cafa53..b9370f3b 100644 --- a/src/Stage.cpp +++ b/src/Stage.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "WindowsWrapper.h" @@ -131,8 +132,8 @@ const STAGE_TABLE gTMT[95] = { BOOL TransferStage(int no, int w, int x, int y) { - char path[MAX_PATH]; - char path_dir[20]; + std::string path; + std::string path_dir; BOOL bError; // Move character @@ -141,47 +142,47 @@ BOOL TransferStage(int no, int w, int x, int y) bError = FALSE; // Get path - strcpy(path_dir, "Stage"); + path_dir = "Stage"; // Load tileset - sprintf(path, "%s/Prt%s", path_dir, gTMT[no].parts); - if (!ReloadBitmap_File(path, SURFACE_ID_LEVEL_TILESET)) + path = path_dir + "/Prt" + gTMT[no].parts; + if (!ReloadBitmap_File(path.c_str(), SURFACE_ID_LEVEL_TILESET)) bError = TRUE; - sprintf(path, "%s/%s.pxa", path_dir, gTMT[no].parts); - if (!LoadAttributeData(path)) + path = path_dir + '/' + gTMT[no].parts + ".pxa"; + if (!LoadAttributeData(path.c_str())) bError = TRUE; // Load tilemap - sprintf(path, "%s/%s.pxm", path_dir, gTMT[no].map); - if (!LoadMapData2(path)) + path = path_dir + '/' + gTMT[no].map + ".pxm"; + if (!LoadMapData2(path.c_str())) bError = TRUE; // Load NPCs - sprintf(path, "%s/%s.pxe", path_dir, gTMT[no].map); - if (!LoadEvent(path)) + path = path_dir + '/' + gTMT[no].map + ".pxe"; + if (!LoadEvent(path.c_str())) bError = TRUE; // Load script - sprintf(path, "%s/%s.tsc", path_dir, gTMT[no].map); - if (!LoadTextScript_Stage(path)) + path = path_dir + '/' + gTMT[no].map + ".tsc"; + if (!LoadTextScript_Stage(path.c_str())) bError = TRUE; // Load background - sprintf(path, "%s", gTMT[no].back); - if (!InitBack(path, gTMT[no].bkType)) + path = gTMT[no].back; + if (!InitBack(path.c_str(), gTMT[no].bkType)) bError = TRUE; // Get path - strcpy(path_dir, "Npc"); + path_dir = "Npc"; // Load NPC sprite sheets - sprintf(path, "%s/Npc%s", path_dir, gTMT[no].npc); - if (!ReloadBitmap_File(path, SURFACE_ID_LEVEL_SPRITESET_1)) + path = path_dir + "/Npc" + gTMT[no].npc; + if (!ReloadBitmap_File(path.c_str(), SURFACE_ID_LEVEL_SPRITESET_1)) bError = TRUE; - sprintf(path, "%s/Npc%s", path_dir, gTMT[no].boss); - if (!ReloadBitmap_File(path, SURFACE_ID_LEVEL_SPRITESET_2)) + path = path_dir + "/Npc" + gTMT[no].boss; + if (!ReloadBitmap_File(path.c_str(), SURFACE_ID_LEVEL_SPRITESET_2)) bError = TRUE; if (bError) diff --git a/src/TextScr.cpp b/src/TextScr.cpp index 8c9bada9..e3ba2079 100644 --- a/src/TextScr.cpp +++ b/src/TextScr.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "WindowsWrapper.h" @@ -124,17 +125,17 @@ void EncryptionBinaryData2(unsigned char *pData, long size) BOOL LoadTextScript2(const char *name) { FILE *fp; - char path[MAX_PATH]; + std::string path; // Get path - sprintf(path, "%s/%s", gDataPath, name); + path = gDataPath + '/' + name; - gTS.size = GetFileSizeLong(path); + gTS.size = GetFileSizeLong(path.c_str()); if (gTS.size == -1) return FALSE; // Open file - fp = fopen(path, "rb"); + fp = fopen(path.c_str(), "rb"); if (fp == NULL) return FALSE; @@ -144,7 +145,7 @@ BOOL LoadTextScript2(const char *name) fclose(fp); // Set path - strcpy(gTS.path, name); + gTS.path = name; // Decrypt data EncryptionBinaryData2((unsigned char*)gTS.data, gTS.size); @@ -156,18 +157,18 @@ BOOL LoadTextScript2(const char *name) BOOL LoadTextScript_Stage(const char *name) { FILE *fp; - char path[MAX_PATH]; + std::string path; long head_size; long body_size; // Open Head.tsc - sprintf(path, "%s/%s", gDataPath, "Head.tsc"); + path = gDataPath + "/Head.tsc"; - head_size = GetFileSizeLong(path); + head_size = GetFileSizeLong(path.c_str()); if (head_size == -1) return FALSE; - fp = fopen(path, "rb"); + fp = fopen(path.c_str(), "rb"); if (fp == NULL) return FALSE; @@ -178,13 +179,13 @@ BOOL LoadTextScript_Stage(const char *name) fclose(fp); // Open stage's .tsc - sprintf(path, "%s/%s", gDataPath, name); + path = gDataPath + '/' + name; - body_size = GetFileSizeLong(path); + body_size = GetFileSizeLong(path.c_str()); if (body_size == -1) return FALSE; - fp = fopen(path, "rb"); + fp = fopen(path.c_str(), "rb"); if (fp == NULL) return FALSE; @@ -196,15 +197,15 @@ BOOL LoadTextScript_Stage(const char *name) // Set parameters gTS.size = head_size + body_size; - strcpy(gTS.path, name); + gTS.path = name; return TRUE; } // Get current path -void GetTextScriptPath(char *path) +std::string GetTextScriptPath(void) { - strcpy(path, gTS.path); + return gTS.path; } // Get 4 digit number from TSC data diff --git a/src/TextScr.h b/src/TextScr.h index eb87f61f..d73cbdd2 100644 --- a/src/TextScr.h +++ b/src/TextScr.h @@ -1,11 +1,13 @@ #pragma once +#include + #include "WindowsWrapper.h" typedef struct TEXT_SCRIPT { // Path (reload when exit teleporter menu/inventory) - char path[MAX_PATH]; + std::string path; // Script buffer long size; @@ -62,7 +64,7 @@ void EndTextScript(void); void EncryptionBinaryData2(unsigned char *pData, long size); BOOL LoadTextScript2(const char *name); BOOL LoadTextScript_Stage(const char *name); -void GetTextScriptPath(char *path); +std::string GetTextScriptPath(void); BOOL StartTextScript(int no); void StopTextScript(void); void PutTextScript(void); diff --git a/src/WindowsWrapper.h b/src/WindowsWrapper.h index 58eda2c1..50a61ea8 100644 --- a/src/WindowsWrapper.h +++ b/src/WindowsWrapper.h @@ -6,8 +6,6 @@ #undef FindResource #else -#include - #define RGB(r,g,b) ((r) | ((g) << 8) | ((b) << 16)) typedef bool BOOL; @@ -23,6 +21,4 @@ struct RECT long bottom; }; -#define MAX_PATH FILENAME_MAX - #endif