ref: 78da025796c62b14166aa04b6f46b191111bd746
parent: a5c09b67f75bfd2ce127bccc59ceedc8e9708db1
parent: 47367614a37f53168eba3bff38b386eb007b4c57
author: Clownacy <Clownacy@users.noreply.github.com>
date: Tue Jun 30 10:09:57 EDT 2020
Merge pull request #130 from GabrielRavier/portableSupportPathsAboveFilenameMax Support paths above PATH_MAX (for portable)
--- a/src/ArmsItem.cpp
+++ b/src/ArmsItem.cpp
@@ -1,6 +1,7 @@
#include "ArmsItem.h"
#include <string.h>
+#include <string>
#include "WindowsWrapper.h"
@@ -414,12 +415,12 @@
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 @@
}
// 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
}
--- 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)
--- a/src/Back.cpp
+++ b/src/Back.cpp
@@ -2,6 +2,7 @@
#include <stddef.h>
#include <stdio.h>
+#include <string>
#include "WindowsWrapper.h"
@@ -25,10 +26,9 @@
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;
--- a/src/Backends/Misc.h
+++ b/src/Backends/Misc.h
@@ -1,5 +1,7 @@
#pragma once
+#include <string>
+
#include "../Attributes.h"
enum
@@ -86,7 +88,7 @@
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);
--- a/src/Backends/Platform/GLFW3.cpp
+++ b/src/Backends/Platform/GLFW3.cpp
@@ -6,6 +6,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <string>
#include <thread>
#include <GLFW/glfw3.h>
@@ -181,7 +182,7 @@
glfwSetWindowSizeCallback(window, WindowSizeCallback);
}
-bool Backend_GetBasePath(char *string_buffer)
+bool Backend_GetBasePath(std::string *string_buffer)
{
(void)string_buffer;
--- a/src/Backends/Platform/Null.cpp
+++ b/src/Backends/Platform/Null.cpp
@@ -1,5 +1,7 @@
#include "../Misc.h"
+#include <string>
+
bool Backend_Init(void)
{
return true;
@@ -15,7 +17,7 @@
}
-bool Backend_GetBasePath(char *string_buffer)
+bool Backend_GetBasePath(std::string *string_buffer)
{
(void)string_buffer;
--- a/src/Backends/Platform/SDL2.cpp
+++ b/src/Backends/Platform/SDL2.cpp
@@ -84,7 +84,7 @@
}
-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.
@@ -91,6 +91,8 @@
// 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 @@
// 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;
--- a/src/Backends/Platform/WiiU.cpp
+++ b/src/Backends/Platform/WiiU.cpp
@@ -3,6 +3,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
+#include <string>
#include <coreinit/thread.h>
#include <padscore/kpad.h>
@@ -54,13 +55,13 @@
}
-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;
--- a/src/Config.cpp
+++ b/src/Config.cpp
@@ -1,6 +1,7 @@
#include <stddef.h>
#include <stdio.h>
#include <string.h>
+#include <string>
#include "WindowsWrapper.h"
@@ -17,11 +18,10 @@
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;
--- a/src/Draw.cpp
+++ b/src/Draw.cpp
@@ -4,6 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <string>
#include "WindowsWrapper.h"
@@ -250,12 +251,11 @@
// 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 @@
}
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 @@
// 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 @@
}
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)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 @@
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)
--- a/src/Ending.cpp
+++ b/src/Ending.cpp
@@ -3,6 +3,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <string>
#include "WindowsWrapper.h"
@@ -216,7 +217,7 @@
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 @@
}
// 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 @@
if (Credit.pData == NULL)
return FALSE;
- fp = fopen(path, "rb");
+ fp = fopen(path.c_str(), "rb");
if (fp == NULL)
{
free(Credit.pData);
--- a/src/Game.cpp
+++ b/src/Game.cpp
@@ -3,6 +3,7 @@
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string>
#include "WindowsWrapper.h"
@@ -701,10 +702,9 @@
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テーブルが読めない");
--- a/src/Generic.cpp
+++ b/src/Generic.cpp
@@ -3,6 +3,7 @@
#include <stddef.h>
#include <stdio.h>
#include <string.h>
+#include <string>
#include "WindowsWrapper.h"
@@ -49,19 +50,19 @@
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,12 +74,10 @@
BOOL IsKeyFile(const char *name)
{
- char path[MAX_PATH];
+ std::string path = gModulePath + '/' + name;
- sprintf(path, "%s/%s", gModulePath, name);
+ FILE *file = fopen(path.c_str(), "rb");
- FILE *file = fopen(path, "rb");
-
if (file == NULL)
return FALSE;
@@ -105,15 +104,15 @@
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;
--- a/src/GenericLoad.cpp
+++ b/src/GenericLoad.cpp
@@ -293,8 +293,9 @@
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;
}
--- a/src/Main.cpp
+++ b/src/Main.cpp
@@ -4,6 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <string>
#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,16 +94,16 @@
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;
}
}
@@ -109,8 +110,7 @@
}
// Get path of the data folder
- strcpy(gDataPath, gModulePath);
- strcat(gDataPath, "/data");
+ gDataPath = gModulePath + "/data";
CONFIG conf;
if (!LoadConfigData(&conf))
--- a/src/Main.h
+++ b/src/Main.h
@@ -1,9 +1,11 @@
#pragma once
+#include <string>
+
#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;
--- a/src/Map.cpp
+++ b/src/Map.cpp
@@ -4,6 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <string>
#include "WindowsWrapper.h"
@@ -29,13 +30,13 @@
{
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 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;
--- a/src/MycParam.cpp
+++ b/src/MycParam.cpp
@@ -1,6 +1,7 @@
#include "MycParam.h"
#include <stdio.h>
+#include <string>
#include "WindowsWrapper.h"
@@ -436,7 +437,7 @@
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))
@@ -443,9 +444,9 @@
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 @@
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 @@
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;
--- a/src/NpChar.cpp
+++ b/src/NpChar.cpp
@@ -3,6 +3,7 @@
#include <stddef.h>
#include <stdio.h>
#include <string.h>
+#include <string>
#include "WindowsWrapper.h"
@@ -59,10 +60,9 @@
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;
--- a/src/Profile.cpp
+++ b/src/Profile.cpp
@@ -3,6 +3,7 @@
#include <stddef.h>
#include <stdio.h>
#include <string.h>
+#include <string>
#include "WindowsWrapper.h"
@@ -28,10 +29,9 @@
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 @@
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 @@
{
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;
--- a/src/SelStage.cpp
+++ b/src/SelStage.cpp
@@ -1,6 +1,7 @@
#include "SelStage.h"
#include <string.h>
+#include <string>
#include "WindowsWrapper.h"
@@ -156,13 +157,13 @@
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 @@
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 @@
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;
}
--- a/src/Stage.cpp
+++ b/src/Stage.cpp
@@ -2,6 +2,7 @@
#include <stdio.h>
#include <string.h>
+#include <string>
#include "WindowsWrapper.h"
@@ -131,8 +132,8 @@
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 @@
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)
--- a/src/TextScr.cpp
+++ b/src/TextScr.cpp
@@ -3,6 +3,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <string>
#include "WindowsWrapper.h"
@@ -124,17 +125,17 @@
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 @@
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 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 @@
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 @@
// 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
--- a/src/TextScr.h
+++ b/src/TextScr.h
@@ -1,11 +1,13 @@
#pragma once
+#include <string>
+
#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 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);
--- a/src/WindowsWrapper.h
+++ b/src/WindowsWrapper.h
@@ -6,8 +6,6 @@
#undef FindResource
#else
-#include <stdio.h>
-
#define RGB(r,g,b) ((r) | ((g) << 8) | ((b) << 16))
typedef bool BOOL;
@@ -22,7 +20,5 @@
long right;
long bottom;
};
-
-#define MAX_PATH FILENAME_MAX
#endif