From b1216967c036ab46728514c9dea2af63d9e413f2 Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Sat, 28 May 2022 12:34:49 +0300 Subject: [PATCH] Replace MAX_PATH with COMPAT_MAX_PATH --- src/art.cc | 9 +++---- src/art.h | 6 ++--- src/audio_file.cc | 6 ++--- src/automap.cc | 9 ++++--- src/character_editor.cc | 4 +-- src/character_editor.h | 3 ++- src/character_selector.cc | 5 ++-- src/combat.cc | 3 ++- src/combat_ai.cc | 2 +- src/credits.cc | 3 ++- src/critter.cc | 3 ++- src/dbox.cc | 7 +++--- src/dfile.h | 7 +++--- src/electronic_registration.cc | 3 ++- src/endgame.cc | 6 ++--- src/endgame.h | 6 ++--- src/game.cc | 6 ++--- src/game_config.cc | 3 ++- src/game_movie.cc | 5 ++-- src/game_movie.h | 6 ++--- src/game_sound.cc | 45 +++++++++++++++++----------------- src/game_sound.h | 3 ++- src/interface.cc | 3 ++- src/inventory.cc | 3 ++- src/item.cc | 3 ++- src/lips.cc | 3 ++- src/loadsave.cc | 24 +++++++++--------- src/loadsave.h | 14 +++++------ src/main.cc | 3 ++- src/map.cc | 9 +++---- src/map.h | 6 ++--- src/message.cc | 2 +- src/movie.cc | 3 ++- src/movie_effect.cc | 2 +- src/options.cc | 5 ++-- src/perk.cc | 3 ++- src/pipboy.cc | 3 ++- src/platform_compat.h | 6 +++++ src/proto.cc | 12 ++++----- src/proto.h | 6 ++--- src/scripts.cc | 11 +++++---- src/sfall_config.cc | 4 ++- src/skill.cc | 3 ++- src/skilldex.cc | 3 ++- src/sound_effects_list.cc | 2 +- src/stat.cc | 3 ++- src/text_font.cc | 6 ++--- src/trait.cc | 3 ++- src/window.cc | 2 +- src/world_map.cc | 4 +-- src/xfile.cc | 15 ++++++------ src/xfile.h | 4 ++- 52 files changed, 166 insertions(+), 154 deletions(-) diff --git a/src/art.cc b/src/art.cc index a6fcd5a..fc4ab4d 100644 --- a/src/art.cc +++ b/src/art.cc @@ -6,7 +6,6 @@ #include "game_config.h" #include "memory.h" #include "object.h" -#include "platform_compat.h" #include "proto.h" #include @@ -75,7 +74,7 @@ char gArtLanguage[32]; Cache gArtCache; // 0x56C9E4 -char _art_name[MAX_PATH]; +char _art_name[COMPAT_MAX_PATH]; // head_info // 0x56CAE8 @@ -92,7 +91,7 @@ int* gArtCritterFidShoudRunData; // 0x418840 int artInit() { - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; int i; File* stream; char str[200]; @@ -897,7 +896,7 @@ int artCacheGetFileSizeImpl(int fid, int* sizePtr) char* str; char* ptr; int result; - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; bool loaded; int fileSize; @@ -955,7 +954,7 @@ int artCacheReadDataImpl(int fid, int* sizePtr, unsigned char* data) char* str; char* ptr; int result; - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; bool loaded; v4 = -1; diff --git a/src/art.h b/src/art.h index c537fdb..38258f8 100644 --- a/src/art.h +++ b/src/art.h @@ -5,11 +5,9 @@ #include "db.h" #include "heap.h" #include "obj_types.h" +#include "platform_compat.h" #include "proto_types.h" -#define WIN32_LEAN_AND_MEAN -#include - typedef enum Head { HEAD_INVALID, HEAD_MARCUS, @@ -136,7 +134,7 @@ extern int _art_mapper_blank_tile; extern char gArtLanguage[32]; extern Cache gArtCache; -extern char _art_name[MAX_PATH]; +extern char _art_name[COMPAT_MAX_PATH]; extern HeadDescription* gHeadDescriptions; extern int* _anon_alias; extern int* gArtCritterFidShoudRunData; diff --git a/src/audio_file.cc b/src/audio_file.cc index 64a85b4..d9001de 100644 --- a/src/audio_file.cc +++ b/src/audio_file.cc @@ -2,6 +2,7 @@ #include "debug.h" #include "memory_manager.h" +#include "platform_compat.h" #include "sound.h" #include @@ -9,9 +10,6 @@ #include #include -#define WIN32_LEAN_AND_MEAN -#include - // 0x5108C0 AudioFileIsCompressedProc* _queryCompressedFunc_2 = _defaultCompressionFunc__; @@ -41,7 +39,7 @@ int audioFileSoundDecoderReadHandler(int fileHandle, void* buffer, unsigned int // 0x41A88C int audioFileOpen(const char* fname, int flags, ...) { - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; strcpy(path, fname); int compression; diff --git a/src/automap.cc b/src/automap.cc index b2bcf76..6df1686 100644 --- a/src/automap.cc +++ b/src/automap.cc @@ -15,6 +15,7 @@ #include "map.h" #include "memory.h" #include "object.h" +#include "platform_compat.h" #include "text_font.h" #include "window_manager.h" @@ -232,7 +233,7 @@ void automapExit() { char* masterPatchesPath; if (configGetString(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_MASTER_PATCHES_KEY, &masterPatchesPath)) { - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s\\%s\\%s", masterPatchesPath, "MAPS", AUTOMAP_DB); remove(path); } @@ -864,7 +865,7 @@ int automapLoadEntry(int map, int elevation) { gAutomapEntry.compressedData = NULL; - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s\\%s", "MAPS", AUTOMAP_DB); bool success = true; @@ -1039,7 +1040,7 @@ int automapCreate() gAutomapHeader.dataSize = 1925; memcpy(gAutomapHeader.offsets, _defam, sizeof(_defam)); - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s\\%s", "MAPS", AUTOMAP_DB); File* stream = fileOpen(path, "wb"); @@ -1094,7 +1095,7 @@ int _copy_file_data(File* stream1, File* stream2, int length) // 0x41CE74 int automapGetHeader(AutomapHeader** automapHeaderPtr) { - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s\\%s", "MAPS", AUTOMAP_DB); File* stream = fileOpen(path, "rb"); diff --git a/src/character_editor.cc b/src/character_editor.cc index 779f000..021f5f7 100644 --- a/src/character_editor.cc +++ b/src/character_editor.cc @@ -988,7 +988,7 @@ int characterEditorWindowInit() int i; int v1; int v3; - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; int fid; char* str; int len; @@ -3745,7 +3745,7 @@ int _OptionWindow() } } else if (keyCode == 501 || keyCode == KEY_UPPERCASE_L || keyCode == KEY_LOWERCASE_L) { // LOAD - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; path[0] = '\0'; strcat(path, "*."); strcat(path, "GCD"); diff --git a/src/character_editor.h b/src/character_editor.h index b863e47..a562caa 100644 --- a/src/character_editor.h +++ b/src/character_editor.h @@ -11,7 +11,8 @@ #include "stat_defs.h" #include "trait_defs.h" -#define DIALOG_PICKER_NUM_OPTIONS max(PERK_COUNT, TRAIT_COUNT) +// TODO: Should be MAX(PERK_COUNT, TRAIT_COUNT). +#define DIALOG_PICKER_NUM_OPTIONS PERK_COUNT #define TOWN_REPUTATION_COUNT 19 #define ADDICTION_REPUTATION_COUNT 8 diff --git a/src/character_selector.cc b/src/character_selector.cc index 233ae3d..3ad27ab 100644 --- a/src/character_selector.cc +++ b/src/character_selector.cc @@ -14,6 +14,7 @@ #include "object.h" #include "options.h" #include "palette.h" +#include "platform_compat.h" #include "proto.h" #include "skill.h" #include "stat.h" @@ -613,7 +614,7 @@ void characterSelectorWindowFree() // 0x4A7D58 bool characterSelectorWindowRefresh() { - char path[FILENAME_MAX]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s.gcd", gPremadeCharacterDescriptions[gCurrentPremadeCharacter].fileName); if (_proto_dude_init(path) == -1) { debugPrint("\n ** Error in dude init! **\n"); @@ -919,7 +920,7 @@ bool characterSelectorWindowRenderBio() int oldFont = fontGetCurrent(); fontSetCurrent(101); - char path[FILENAME_MAX]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s.bio", gPremadeCharacterDescriptions[gCurrentPremadeCharacter].fileName); File* stream = fileOpen(path, "rt"); diff --git a/src/combat.cc b/src/combat.cc index 5f5eaa9..6d4102c 100644 --- a/src/combat.cc +++ b/src/combat.cc @@ -24,6 +24,7 @@ #include "object.h" #include "perk.h" #include "pipboy.h" +#include "platform_compat.h" #include "proto.h" #include "queue.h" #include "random.h" @@ -1864,7 +1865,7 @@ Attack _explosion_ctd; int combatInit() { int max_action_points; - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; _combat_turn_running = 0; _combatNumTurns = 0; diff --git a/src/combat_ai.cc b/src/combat_ai.cc index 3d42f9b..e32d9ab 100644 --- a/src/combat_ai.cc +++ b/src/combat_ai.cc @@ -3252,7 +3252,7 @@ int aiMessageListInit() return -1; } - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s%s", asc_5186C8, "combatai.msg"); if (!messageListLoad(&gCombatAiMessageList, path)) { diff --git a/src/credits.cc b/src/credits.cc index 34e4270..6ea671a 100644 --- a/src/credits.cc +++ b/src/credits.cc @@ -10,6 +10,7 @@ #include "memory.h" #include "message.h" #include "palette.h" +#include "platform_compat.h" #include "sound.h" #include "text_font.h" #include "window_manager.h" @@ -52,7 +53,7 @@ void creditsOpen(const char* filePath, int backgroundFid, bool useReversedStyle) soundContinueAll(); - char localizedPath[MAX_PATH]; + char localizedPath[COMPAT_MAX_PATH]; if (_message_make_path(localizedPath, filePath)) { gCreditsFile = fileOpen(localizedPath, "rt"); if (gCreditsFile != NULL) { diff --git a/src/critter.cc b/src/critter.cc index 968e5e2..f042c7b 100644 --- a/src/critter.cc +++ b/src/critter.cc @@ -14,6 +14,7 @@ #include "memory.h" #include "object.h" #include "party_member.h" +#include "platform_compat.h" #include "proto.h" #include "queue.h" #include "random.h" @@ -124,7 +125,7 @@ int critterInit() return -1; } - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%sscrname.msg", asc_5186C8); if (!messageListLoad(&gCritterMessageList, path)) { diff --git a/src/dbox.cc b/src/dbox.cc index 2e0b2c7..c4c315a 100644 --- a/src/dbox.cc +++ b/src/dbox.cc @@ -8,6 +8,7 @@ #include "game.h" #include "game_sound.h" #include "message.h" +#include "platform_compat.h" #include "text_font.h" #include "window_manager.h" #include "word_wrap.h" @@ -205,7 +206,7 @@ int showDialogBox(const char* title, const char** body, int bodyLength, int x, i return -1; } - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s%s", asc_5186C8, "DBOX.MSG"); if (!messageListLoad(&messageList, path)) { @@ -303,7 +304,7 @@ int showDialogBox(const char* title, const char** body, int bodyLength, int x, i return -1; } - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s%s", asc_5186C8, "DBOX.MSG"); if (!messageListLoad(&messageList, path)) { @@ -492,7 +493,7 @@ int _save_file_dialog(char* a1, char** fileList, char* fileName, int fileListLen return -1; } - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s%s", asc_5186C8, "DBOX.MSG"); if (!messageListLoad(&messageList, path)) { diff --git a/src/dfile.h b/src/dfile.h index 54e5b2d..64d313b 100644 --- a/src/dfile.h +++ b/src/dfile.h @@ -1,8 +1,7 @@ #ifndef DFILE_H #define DFILE_H -#define WIN32_LEAN_AND_MEAN -#include +#include "platform_compat.h" #include #include @@ -116,13 +115,13 @@ typedef struct DFile { typedef struct DFileFindData { // The name of file that was found during previous search. - char fileName[MAX_PATH]; + char fileName[COMPAT_MAX_PATH]; // The pattern to search. // // This value is set automatically when [dbaseFindFirstEntry] succeeds so // that subsequent calls to [dbaseFindNextEntry] know what to look for. - char pattern[MAX_PATH]; + char pattern[COMPAT_MAX_PATH]; // The index of entry that was found during previous search. // diff --git a/src/electronic_registration.cc b/src/electronic_registration.cc index b81f311..b296000 100644 --- a/src/electronic_registration.cc +++ b/src/electronic_registration.cc @@ -1,6 +1,7 @@ #include "electronic_registration.h" #include "game_config.h" +#include "platform_compat.h" #define WIN32_LEAN_AND_MEAN #include @@ -11,7 +12,7 @@ void runElectronicRegistration() int timesRun = 0; configGetInt(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_TIMES_RUN_KEY, ×Run); if (timesRun > 0 && timesRun < 5) { - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; if (GetModuleFileNameA(NULL, path, sizeof(path)) != 0) { char* pch = strrchr(path, '\\'); if (pch == NULL) { diff --git a/src/endgame.cc b/src/endgame.cc index cde8413..8d81c60 100644 --- a/src/endgame.cc +++ b/src/endgame.cc @@ -87,7 +87,7 @@ char gEndgameDeathEndingFileName[40]; bool gEndgameEndingVoiceOverSpeechLoaded; // 0x570ABC -char gEndgameEndingSubtitlesLocalizedPath[MAX_PATH]; +char gEndgameEndingSubtitlesLocalizedPath[COMPAT_MAX_PATH]; // The flag used to denote voice over speech for current slide has ended. // @@ -580,7 +580,7 @@ void endgameEndingSlideshowWindowFree() // 0x4401A0 void endgameEndingVoiceOverInit(const char* fileBaseName) { - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; // NOTE: Uninline. endgameEndingVoiceOverFree(); @@ -666,7 +666,7 @@ void endgameEndingLoadPalette(int type, int id) } if (strlen(fileName) <= 8) { - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s\\%s.pal", "art\\intrface", fileName); colorPaletteLoad(path); } diff --git a/src/endgame.h b/src/endgame.h index b3a2bdb..b7ae1c7 100644 --- a/src/endgame.h +++ b/src/endgame.h @@ -1,9 +1,7 @@ #ifndef ENDGAME_H #define ENDGAME_H -// Provides [MAX_PATH]. -#define WIN32_LEAN_AND_MEAN -#include +#include "platform_compat.h" typedef enum EndgameDeathEndingReason { // Dude died. @@ -46,7 +44,7 @@ extern int gEndgameDeathEndingsLength; extern char gEndgameDeathEndingFileName[40]; extern bool gEndgameEndingVoiceOverSpeechLoaded; -extern char gEndgameEndingSubtitlesLocalizedPath[MAX_PATH]; +extern char gEndgameEndingSubtitlesLocalizedPath[COMPAT_MAX_PATH]; extern bool gEndgameEndingSpeechEnded; extern EndgameEnding* gEndgameEndings; extern char** gEndgameEndingSubtitles; diff --git a/src/game.cc b/src/game.cc index a023a35..eeeb359 100644 --- a/src/game.cc +++ b/src/game.cc @@ -111,7 +111,7 @@ int _critter_db_handle; // 0x442580 int gameInitWithOptions(const char* windowTitle, bool isMapper, int font, int a4, int argc, char** argv) { - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; if (gameMemoryInit() == -1) { return -1; @@ -725,7 +725,7 @@ int gameHandleKey(int eventCode, bool isInCombatMode) MessageList messageList; if (messageListInit(&messageList)) { - char path[FILENAME_MAX]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s%s", asc_5186C8, "editor.msg"); if (messageListLoad(&messageList, path)) { @@ -1162,7 +1162,7 @@ int gameDbInit() char* main_file_name; char* patch_file_name; int patch_index; - char filename[MAX_PATH]; + char filename[COMPAT_MAX_PATH]; hashing = 0; main_file_name = NULL; diff --git a/src/game_config.cc b/src/game_config.cc index be5041d..b671b4e 100644 --- a/src/game_config.cc +++ b/src/game_config.cc @@ -1,6 +1,7 @@ #include "game_config.h" #include "main.h" +#include "platform_compat.h" #include #include @@ -19,7 +20,7 @@ Config gGameConfig; // probably means it's size is 264 bytes. // // 0x58E978 -char gGameConfigFilePath[FILENAME_MAX]; +char gGameConfigFilePath[COMPAT_MAX_PATH]; // Inits main game config. // diff --git a/src/game_movie.cc b/src/game_movie.cc index afefaf1..8dd2ca3 100644 --- a/src/game_movie.cc +++ b/src/game_movie.cc @@ -11,7 +11,6 @@ #include "movie.h" #include "movie_effect.h" #include "palette.h" -#include "platform_compat.h" #include "text_font.h" #include "widget.h" #include "window_manager.h" @@ -77,7 +76,7 @@ bool gGameMovieFaded = false; unsigned char gGameMoviesSeen[MOVIE_COUNT]; // 0x596C89 -char gGameMovieSubtitlesFilePath[MAX_PATH]; +char gGameMovieSubtitlesFilePath[COMPAT_MAX_PATH]; // gmovie_init // 0x44E5C0 @@ -145,7 +144,7 @@ int gameMoviePlay(int movie, int flags) return -1; } - char movieFilePath[MAX_PATH]; + char movieFilePath[COMPAT_MAX_PATH]; int movieFileSize; bool movieFound = false; diff --git a/src/game_movie.h b/src/game_movie.h index fb574ec..7ca8cb0 100644 --- a/src/game_movie.h +++ b/src/game_movie.h @@ -2,9 +2,7 @@ #define GAME_MOVIE_H #include "db.h" - -#define WIN32_LEAN_AND_MEAN -#include +#include "platform_compat.h" typedef enum GameMovieFlags { GAME_MOVIE_FADE_IN = 0x01, @@ -41,7 +39,7 @@ extern char* gMoviePaletteFilePaths[MOVIE_COUNT]; extern bool gGameMovieIsPlaying; extern bool gGameMovieFaded; -extern char gGameMovieSubtitlesFilePath[MAX_PATH]; +extern char gGameMovieSubtitlesFilePath[COMPAT_MAX_PATH]; extern unsigned char gGameMoviesSeen[MOVIE_COUNT]; int gameMoviesInit(); diff --git a/src/game_sound.cc b/src/game_sound.cc index 937c11d..47eab43 100644 --- a/src/game_sound.cc +++ b/src/game_sound.cc @@ -13,7 +13,6 @@ #include "memory.h" #include "movie.h" #include "object.h" -#include "platform_compat.h" #include "proto.h" #include "queue.h" #include "random.h" @@ -125,7 +124,7 @@ int _detectDevices = -1; int _lastTime_1 = 0; // 0x596EB0 -char _background_fname_copied[MAX_PATH]; +char _background_fname_copied[COMPAT_MAX_PATH]; // 0x596FB5 char _sfx_file_name[13]; @@ -614,7 +613,7 @@ int backgroundSoundLoad(const char* fileName, int a2, int a3, int a4) return -1; } - char path[MAX_PATH + 1]; + char path[COMPAT_MAX_PATH + 1]; if (a3 == 13) { rc = gameSoundFindBackgroundSoundPath(path, fileName); } else if (a3 == 14) { @@ -838,7 +837,7 @@ int speechGetDuration() // 0x450CA0 int speechLoad(const char* fname, int a2, int a3, int a4) { - char path[MAX_PATH + 1]; + char path[COMPAT_MAX_PATH + 1]; if (!gGameSoundInitialized) { return -1; @@ -1064,7 +1063,7 @@ Sound* soundEffectLoad(const char* name, Object* object) ++_gsound_active_effect_counter; - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s%s%s", _sound_sfx_path, name, ".ACM"); if (soundLoad(sound, path) == 0) { @@ -1675,7 +1674,7 @@ int _gsound_background_allocate(Sound** soundPtr, int a2, int a3) int gameSoundFindBackgroundSoundPathWithCopy(char* dest, const char* src) { size_t len = strlen(src) + strlen(".ACM"); - if (strlen(_sound_music_path1) + len > MAX_PATH || strlen(_sound_music_path2) + len > MAX_PATH) { + if (strlen(_sound_music_path1) + len > COMPAT_MAX_PATH || strlen(_sound_music_path2) + len > COMPAT_MAX_PATH) { if (gGameSoundDebugEnabled) { debugPrint("Full background path too long.\n"); } @@ -1687,11 +1686,11 @@ int gameSoundFindBackgroundSoundPathWithCopy(char* dest, const char* src) debugPrint(" finding background sound "); } - char outPath[MAX_PATH]; + char outPath[COMPAT_MAX_PATH]; sprintf(outPath, "%s%s%s", _sound_music_path1, src, ".ACM"); if (_gsound_file_exists_f(outPath)) { - strncpy(dest, outPath, MAX_PATH); - dest[MAX_PATH] = '\0'; + strncpy(dest, outPath, COMPAT_MAX_PATH); + dest[COMPAT_MAX_PATH] = '\0'; return 0; } @@ -1701,7 +1700,7 @@ int gameSoundFindBackgroundSoundPathWithCopy(char* dest, const char* src) gameSoundDeleteOldMusicFile(); - char inPath[MAX_PATH]; + char inPath[COMPAT_MAX_PATH]; sprintf(inPath, "%s%s%s", _sound_music_path2, src, ".ACM"); FILE* inStream = fopen(inPath, "rb"); @@ -1764,8 +1763,8 @@ int gameSoundFindBackgroundSoundPathWithCopy(char* dest, const char* src) strcpy(_background_fname_copied, src); - strncpy(dest, outPath, MAX_PATH); - dest[MAX_PATH] = '\0'; + strncpy(dest, outPath, COMPAT_MAX_PATH); + dest[COMPAT_MAX_PATH] = '\0'; return 0; } @@ -1773,11 +1772,11 @@ int gameSoundFindBackgroundSoundPathWithCopy(char* dest, const char* src) // 0x451E2C int gameSoundFindBackgroundSoundPath(char* dest, const char* src) { - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; int len; len = strlen(src) + strlen(".ACM"); - if (strlen(_sound_music_path1) + len > MAX_PATH || strlen(_sound_music_path2) + len > MAX_PATH) { + if (strlen(_sound_music_path1) + len > COMPAT_MAX_PATH || strlen(_sound_music_path2) + len > COMPAT_MAX_PATH) { if (gGameSoundDebugEnabled) { debugPrint("Full background path too long.\n"); } @@ -1791,8 +1790,8 @@ int gameSoundFindBackgroundSoundPath(char* dest, const char* src) sprintf(path, "%s%s%s", _sound_music_path1, src, ".ACM"); if (_gsound_file_exists_f(path)) { - strncpy(dest, path, MAX_PATH); - dest[MAX_PATH] = '\0'; + strncpy(dest, path, COMPAT_MAX_PATH); + dest[COMPAT_MAX_PATH] = '\0'; return 0; } @@ -1802,8 +1801,8 @@ int gameSoundFindBackgroundSoundPath(char* dest, const char* src) sprintf(path, "%s%s%s", _sound_music_path2, src, ".ACM"); if (_gsound_file_exists_f(path)) { - strncpy(dest, path, MAX_PATH); - dest[MAX_PATH] = '\0'; + strncpy(dest, path, COMPAT_MAX_PATH); + dest[COMPAT_MAX_PATH] = '\0'; return 0; } @@ -1817,9 +1816,9 @@ int gameSoundFindBackgroundSoundPath(char* dest, const char* src) // 0x451F94 int gameSoundFindSpeechSoundPath(char* dest, const char* src) { - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; - if (strlen(_sound_speech_path) + strlen(".acm") > MAX_PATH) { + if (strlen(_sound_speech_path) + strlen(".acm") > COMPAT_MAX_PATH) { if (gGameSoundDebugEnabled) { // FIXME: The message is wrong (notes background path, but here // we're dealing with speech path). @@ -1845,8 +1844,8 @@ int gameSoundFindSpeechSoundPath(char* dest, const char* src) return -1; } - strncpy(dest, path, MAX_PATH); - dest[MAX_PATH] = '\0'; + strncpy(dest, path, COMPAT_MAX_PATH); + dest[COMPAT_MAX_PATH] = '\0'; return 0; } @@ -1856,7 +1855,7 @@ int gameSoundFindSpeechSoundPath(char* dest, const char* src) void gameSoundDeleteOldMusicFile() { if (_background_fname_copied[0] != '\0') { - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s%s%s", "sound\\music\\", _background_fname_copied, ".ACM"); if (remove(path)) { if (gGameSoundDebugEnabled) { diff --git a/src/game_sound.h b/src/game_sound.h index bb23ac8..00be6c8 100644 --- a/src/game_sound.h +++ b/src/game_sound.h @@ -2,6 +2,7 @@ #define GAME_SOUND_H #include "obj_types.h" +#include "platform_compat.h" #include "sound.h" #define WIN32_LEAN_AND_MEAN @@ -71,7 +72,7 @@ extern int gSoundEffectsVolume; extern int _detectDevices; extern int _lastTime_1; -extern char _background_fname_copied[MAX_PATH]; +extern char _background_fname_copied[COMPAT_MAX_PATH]; extern char _sfx_file_name[13]; extern char gBackgroundSoundFileName[270]; diff --git a/src/interface.cc b/src/interface.cc index 337b450..baf62fa 100644 --- a/src/interface.cc +++ b/src/interface.cc @@ -18,6 +18,7 @@ #include "item.h" #include "memory.h" #include "object.h" +#include "platform_compat.h" #include "proto.h" #include "proto_instance.h" #include "proto_types.h" @@ -2318,7 +2319,7 @@ int indicatorBarInit() rc = -1; } - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s%s", asc_5186C8, "intrface.msg"); if (rc != -1) { diff --git a/src/inventory.cc b/src/inventory.cc index 6c670fc..5dd1393 100644 --- a/src/inventory.cc +++ b/src/inventory.cc @@ -23,6 +23,7 @@ #include "map.h" #include "object.h" #include "perk.h" +#include "platform_compat.h" #include "proto.h" #include "proto_instance.h" #include "random.h" @@ -356,7 +357,7 @@ void _inven_reset_dude() // 0x46E73C int inventoryMessageListInit() { - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; if (!messageListInit(&gInventoryMessageList)) return -1; diff --git a/src/item.cc b/src/item.cc index b0fdbc3..9bcb921 100644 --- a/src/item.cc +++ b/src/item.cc @@ -14,6 +14,7 @@ #include "memory.h" #include "object.h" #include "perk.h" +#include "platform_compat.h" #include "proto.h" #include "proto_instance.h" #include "queue.h" @@ -110,7 +111,7 @@ int itemsInit() return -1; } - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s%s", asc_5186C8, "item.msg"); if (!messageListLoad(&gItemsMessageList, path)) { diff --git a/src/lips.cc b/src/lips.cc index fa8b2a0..fb3657f 100644 --- a/src/lips.cc +++ b/src/lips.cc @@ -5,6 +5,7 @@ #include "debug.h" #include "game_sound.h" #include "memory.h" +#include "platform_compat.h" #include "sound.h" #include @@ -393,7 +394,7 @@ int _lips_make_speech() gLipsData.field_14 = NULL; } - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; char* v1 = _lips_fix_string(gLipsData.field_50, sizeof(gLipsData.field_50)); sprintf(path, "%s%s\\%s.%s", "SOUND\\SPEECH\\", _lips_subdir_name, v1, "ACM"); diff --git a/src/loadsave.cc b/src/loadsave.cc index baab366..9cec59a 100644 --- a/src/loadsave.cc +++ b/src/loadsave.cc @@ -190,22 +190,22 @@ unsigned char* gLoadSaveFrmData[LOAD_SAVE_FRM_COUNT]; unsigned char* _snapshot; // 0x6142F0 -char _str2[MAX_PATH]; +char _str2[COMPAT_MAX_PATH]; // 0x6143F4 -char _str0[MAX_PATH]; +char _str0[COMPAT_MAX_PATH]; // 0x6144F8 -char _str1[MAX_PATH]; +char _str1[COMPAT_MAX_PATH]; // 0x6145FC -char _str[MAX_PATH]; +char _str[COMPAT_MAX_PATH]; // 0x614700 unsigned char* gLoadSaveWindowBuffer; // 0x614704 -char _gmpath[MAX_PATH]; +char _gmpath[COMPAT_MAX_PATH]; // 0x614808 File* _flptr; @@ -289,7 +289,7 @@ int lsgSaveGame(int mode) return -1; } - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s%s", asc_5186C8, "LSGAME.MSG"); if (!messageListLoad(&gLoadSaveMessageList, path)) { return -1; @@ -687,7 +687,7 @@ int lsgLoadGame(int mode) return -1; } - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s\\%s", asc_5186C8, "LSGAME.MSG"); if (!messageListLoad(&gLoadSaveMessageList, path)) { return -1; @@ -2132,7 +2132,7 @@ int _GameMap2Slot(File* stream) continue; } - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; if (_proto_list_str(pid, path) != 0) { continue; } @@ -2268,7 +2268,7 @@ int _SlotMap2Game(File* stream) for (int index = 1; index < gPartyMemberDescriptionsLength; index += 1) { int pid = gPartyMemberPids[index]; if (pid != -2) { - char protoPath[MAX_PATH]; + char protoPath[COMPAT_MAX_PATH]; if (_proto_list_str(pid, protoPath) == 0) { const char* basePath = pid >> 24 == OBJ_TYPE_CRITTER ? "PROTO\\CRITTERS" @@ -2429,7 +2429,7 @@ out: // 0x48000C void lsgInit() { - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s\\", "MAPS"); _MapDirErase(path, "SAV"); } @@ -2437,7 +2437,7 @@ void lsgInit() // 0x480040 int _MapDirErase(const char* relativePath, const char* extension) { - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s*.%s", relativePath, extension); char** fileList; @@ -2454,7 +2454,7 @@ int _MapDirErase(const char* relativePath, const char* extension) // 0x4800C8 int _MapDirEraseFile_(const char* a1, const char* a2) { - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s\\%s%s", _patches, a1, a2); if (remove(path) != 0) { diff --git a/src/loadsave.h b/src/loadsave.h index 112742b..747bf99 100644 --- a/src/loadsave.h +++ b/src/loadsave.h @@ -5,9 +5,7 @@ #include "db.h" #include "geometry.h" #include "message.h" - -#define WIN32_LEAN_AND_MEAN -#include +#include "platform_compat.h" #define LOAD_SAVE_DESCRIPTION_LENGTH (30) #define LOAD_SAVE_HANDLER_COUNT (27) @@ -103,12 +101,12 @@ extern int _dbleclkcntr; extern int gLoadSaveWindow; extern unsigned char* gLoadSaveFrmData[LOAD_SAVE_FRM_COUNT]; extern unsigned char* _snapshot; -extern char _str2[MAX_PATH]; -extern char _str0[MAX_PATH]; -extern char _str1[MAX_PATH]; -extern char _str[MAX_PATH]; +extern char _str2[COMPAT_MAX_PATH]; +extern char _str0[COMPAT_MAX_PATH]; +extern char _str1[COMPAT_MAX_PATH]; +extern char _str[COMPAT_MAX_PATH]; extern unsigned char* gLoadSaveWindowBuffer; -extern char _gmpath[MAX_PATH]; +extern char _gmpath[COMPAT_MAX_PATH]; extern File* _flptr; extern int _ls_error_code; extern int gLoadSaveWindowOldFont; diff --git a/src/main.cc b/src/main.cc index 8b0badf..964dd94 100644 --- a/src/main.cc +++ b/src/main.cc @@ -20,6 +20,7 @@ #include "object.h" #include "options.h" #include "palette.h" +#include "platform_compat.h" #include "random.h" #include "scripts.h" #include "sfall_config.h" @@ -510,7 +511,7 @@ int _mainDeathGrabTextFile(const char* fileName, char* dest) language = _aEnglish_2; } - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "text\\%s\\cuts\\%s%s", language, p + 1, ".TXT"); File* stream = fileOpen(path, "rt"); diff --git a/src/map.cc b/src/map.cc index e45a4c8..21350b2 100644 --- a/src/map.cc +++ b/src/map.cc @@ -23,7 +23,6 @@ #include "object.h" #include "palette.h" #include "pipboy.h" -#include "platform_compat.h" #include "proto.h" #include "proto_instance.h" #include "queue.h" @@ -131,7 +130,7 @@ char _scratchStr[40]; // Last map file name. // // 0x631E78 -char _map_path[MAX_PATH]; +char _map_path[COMPAT_MAX_PATH]; // iso_init // 0x481CA0 @@ -261,7 +260,7 @@ void _map_init() } if (messageListInit(&gMapMessageList)) { - char path[FILENAME_MAX]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%smap.msg", asc_5186C8); if (!messageListLoad(&gMapMessageList, path)) { @@ -876,7 +875,7 @@ int mapLoad(File* stream) gMapHeader.field_34 = mapGetIndexByFileName(gMapHeader.name); if ((gMapHeader.flags & 1) == 0) { - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "maps\\%s", gMapHeader.name); char* extension = strstr(path, ".MAP"); @@ -1443,7 +1442,7 @@ int _map_save_in_game(bool a1) // 0x483E28 void mapMakeMapsDirectory() { - char path[FILENAME_MAX]; + char path[COMPAT_MAX_PATH]; char* masterPatchesPath; if (configGetString(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_MASTER_PATCHES_KEY, &masterPatchesPath)) { diff --git a/src/map.h b/src/map.h index cc9ca6f..b658d5b 100644 --- a/src/map.h +++ b/src/map.h @@ -6,9 +6,7 @@ #include "geometry.h" #include "map_defs.h" #include "message.h" - -#define WIN32_LEAN_AND_MEAN -#include +#include "platform_compat.h" #define ORIGINAL_ISO_WINDOW_WIDTH 640 #define ORIGINAL_ISO_WINDOW_HEIGHT 380 @@ -91,7 +89,7 @@ extern MapHeader gMapHeader; extern TileData* _square[ELEVATION_COUNT]; extern int gIsoWindow; extern char _scratchStr[40]; -extern char _map_path[MAX_PATH]; +extern char _map_path[COMPAT_MAX_PATH]; int isoInit(); void isoReset(); diff --git a/src/message.cc b/src/message.cc index e15e5f7..f620a2b 100644 --- a/src/message.cc +++ b/src/message.cc @@ -167,7 +167,7 @@ bool messageListFree(MessageList* messageList) bool messageListLoad(MessageList* messageList, const char* path) { char* language; - char localized_path[FILENAME_MAX]; + char localized_path[COMPAT_MAX_PATH]; File* file_ptr; char num[1024]; char audio[1024]; diff --git a/src/movie.cc b/src/movie.cc index d7477b7..f577cd8 100644 --- a/src/movie.cc +++ b/src/movie.cc @@ -8,6 +8,7 @@ #include "memory_manager.h" #include "movie_effect.h" #include "movie_lib.h" +#include "platform_compat.h" #include "sound.h" #include "text_font.h" #include "window_manager.h" @@ -521,7 +522,7 @@ void movieLoadSubtitles(char* filePath) filePath = gMovieBuildSubtitleFilePathProc(filePath); } - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; strcpy(path, filePath); debugPrint("Opening subtitle file %s\n", path); diff --git a/src/movie_effect.cc b/src/movie_effect.cc index 830243f..807310e 100644 --- a/src/movie_effect.cc +++ b/src/movie_effect.cc @@ -93,7 +93,7 @@ int movieEffectsLoad(const char* filePath) int rc = -1; - char path[FILENAME_MAX]; + char path[COMPAT_MAX_PATH]; strcpy(path, filePath); char* pch = strrchr(path, '.'); diff --git a/src/options.cc b/src/options.cc index 24c2bb3..7819dfc 100644 --- a/src/options.cc +++ b/src/options.cc @@ -14,6 +14,7 @@ #include "grayscale.h" #include "loadsave.h" #include "memory.h" +#include "platform_compat.h" #include "scripts.h" #include "text_font.h" #include "text_object.h" @@ -453,7 +454,7 @@ int optionsWindowInit() return -1; } - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s%s", asc_5186C8, "options.msg"); if (!messageListLoad(&gOptionsMessageList, path)) { return -1; @@ -633,7 +634,7 @@ int showPause(bool a1) return -1; } - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s%s", asc_5186C8, "options.msg"); if (!messageListLoad(&gOptionsMessageList, path)) { // FIXME: Leaking graphics. diff --git a/src/perk.cc b/src/perk.cc index c50aad4..57414a1 100644 --- a/src/perk.cc +++ b/src/perk.cc @@ -6,6 +6,7 @@ #include "memory.h" #include "object.h" #include "party_member.h" +#include "platform_compat.h" #include "skill.h" #include "stat.h" @@ -164,7 +165,7 @@ int perksInit() return -1; } - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s%s", asc_5186C8, "perk.msg"); if (!messageListLoad(&gPerksMessageList, path)) { diff --git a/src/pipboy.cc b/src/pipboy.cc index 1dbb0a1..bd5eac3 100644 --- a/src/pipboy.cc +++ b/src/pipboy.cc @@ -19,6 +19,7 @@ #include "map.h" #include "memory.h" #include "object.h" +#include "platform_compat.h" #include "queue.h" #include "random.h" #include "scripts.h" @@ -315,7 +316,7 @@ int pipboyWindowInit(bool forceRest) return -1; } - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s%s", asc_5186C8, "pipboy.msg"); if (!(messageListLoad(&gPipboyMessageList, path))) { diff --git a/src/platform_compat.h b/src/platform_compat.h index b13b3f6..6c268f9 100644 --- a/src/platform_compat.h +++ b/src/platform_compat.h @@ -4,6 +4,12 @@ // TODO: This is compatibility cross-platform layer. Designed to have minimal // impact on the codebase. Remove once it's no longer needed. +// A naive cross-platform MAX_PATH/PATH_MAX/MAX_PATH drop-in replacement. +// +// TODO: Remove when we migrate to use std::filesystem::path or std::string to +// represent paths across the codebase. +#define COMPAT_MAX_PATH 260 + int compat_stricmp(const char* string1, const char* string2); int compat_strnicmp(const char* string1, const char* string2, size_t size); char* compat_strupr(char* string); diff --git a/src/proto.cc b/src/proto.cc index 972bf5a..46bab71 100644 --- a/src/proto.cc +++ b/src/proto.cc @@ -33,7 +33,7 @@ char _aDrugStatSpecia[] = "Drug Stat (Special)"; char _aNone_1[] = "None"; // 0x51C18C -char _cd_path_base[MAX_PATH]; +char _cd_path_base[COMPAT_MAX_PATH]; // 0x51C290 ProtoList _protoLists[11] = { @@ -173,8 +173,8 @@ char** _critter_stats_list; // 0x49E758 int _proto_list_str(int pid, char* proto_path) { - char path[MAX_PATH]; - char str[MAX_PATH]; + char path[COMPAT_MAX_PATH]; + char str[COMPAT_MAX_PATH]; char* pch; File* stream; int i; @@ -1037,7 +1037,7 @@ int protoInit() char* master_patches; int len; MessageListItem messageListItem; - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; int i; if (!configGetString(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_MASTER_PATCHES_KEY, &master_patches)) { @@ -1215,7 +1215,7 @@ int _proto_header_load() ptr->length = 0; ptr->max_entries_num = 1; - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; strcpy(path, _cd_path_base); strcat(path, _proto_path_base); strcat(path, artGetObjectTypeName(index)); @@ -1654,7 +1654,7 @@ int _proto_save_pid(int pid) // 0x4A1C3C int _proto_load_pid(int pid, Proto** protoPtr) { - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; strcpy(path, _cd_path_base); strcat(path, "proto\\"); diff --git a/src/proto.h b/src/proto.h index 1609bc2..e757336 100644 --- a/src/proto.h +++ b/src/proto.h @@ -5,13 +5,11 @@ #include "message.h" #include "obj_types.h" #include "perk_defs.h" +#include "platform_compat.h" #include "proto_types.h" #include "skill_defs.h" #include "stat_defs.h" -#define WIN32_LEAN_AND_MEAN -#include - typedef enum ItemDataMember { ITEM_DATA_MEMBER_PID = 0, ITEM_DATA_MEMBER_NAME = 1, @@ -97,7 +95,7 @@ typedef enum PrototypeMessage { extern char _aProto_0[]; -extern char _cd_path_base[MAX_PATH]; +extern char _cd_path_base[COMPAT_MAX_PATH]; extern ProtoList _protoLists[11]; extern const size_t _proto_sizes[11]; extern int _protos_been_initialized; diff --git a/src/scripts.cc b/src/scripts.cc index dd183a3..cafade4 100644 --- a/src/scripts.cc +++ b/src/scripts.cc @@ -16,6 +16,7 @@ #include "game_movie.h" #include "memory.h" #include "object.h" +#include "platform_compat.h" #include "proto.h" #include "proto_instance.h" #include "queue.h" @@ -596,7 +597,7 @@ int scriptSetActionBeingUsed(int sid, int value) // 0x4A3B74 Program* scriptsCreateProgramByName(const char* name) { - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; strcpy(path, _cd_path_base); strcat(path, gScriptsBasePath); @@ -1291,7 +1292,7 @@ bool scriptHasProc(int sid, int proc) // 0x4A4D50 int scriptsLoadScriptsList() { - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s%s", "scripts\\", "scripts.lst"); File* stream = fileOpen(path, "rt"); @@ -1477,7 +1478,7 @@ int _scr_reset() int _scr_game_init() { int i; - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; if (!messageListInit(&gScrMessageList)) { debugPrint("\nError initing script message file!"); @@ -1666,7 +1667,7 @@ int _scr_header_load() { _num_script_indexes = 0; - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; strcpy(path, _cd_path_base); strcat(path, gScriptsBasePath); strcat(path, "scripts.lst"); @@ -2590,7 +2591,7 @@ int scriptsGetMessageList(int a1, MessageList** messageListPtr) *pch = '\0'; } - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "dialog\\%s.msg", scriptName); if (!messageListLoad(messageList, path)) { diff --git a/src/sfall_config.cc b/src/sfall_config.cc index fac4faa..5122495 100644 --- a/src/sfall_config.cc +++ b/src/sfall_config.cc @@ -1,5 +1,7 @@ #include "sfall_config.h" +#include "platform_compat.h" + #include #include @@ -21,7 +23,7 @@ bool sfallConfigInit(int argc, char** argv) // Initialize defaults. configSetString(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_STARTING_MAP_KEY, ""); - char path[FILENAME_MAX]; + char path[COMPAT_MAX_PATH]; char* executable = argv[0]; char* ch = strrchr(executable, '\\'); if (ch != NULL) { diff --git a/src/skill.cc b/src/skill.cc index 44c5611..ba01e2f 100644 --- a/src/skill.cc +++ b/src/skill.cc @@ -15,6 +15,7 @@ #include "party_member.h" #include "perk.h" #include "pipboy.h" +#include "platform_compat.h" #include "proto.h" #include "random.h" #include "scripts.h" @@ -96,7 +97,7 @@ int skillsInit() return -1; } - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s%s", asc_5186C8, "skill.msg"); if (!messageListLoad(&gSkillsMessageList, path)) { diff --git a/src/skilldex.cc b/src/skilldex.cc index 3c18c84..28604e7 100644 --- a/src/skilldex.cc +++ b/src/skilldex.cc @@ -12,6 +12,7 @@ #include "map.h" #include "memory.h" #include "object.h" +#include "platform_compat.h" #include "skill.h" #include "text_font.h" #include "window_manager.h" @@ -122,7 +123,7 @@ int skilldexWindowInit() return -1; } - char path[FILENAME_MAX]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s%s", asc_5186C8, "skilldex.msg"); if (!messageListLoad(&gSkilldexMessageList, path)) { diff --git a/src/sound_effects_list.cc b/src/sound_effects_list.cc index 3d6d0e6..8d28162 100644 --- a/src/sound_effects_list.cc +++ b/src/sound_effects_list.cc @@ -50,7 +50,7 @@ bool soundEffectsListIsValidTag(int a1) // 0x4A98F4 int soundEffectsListInit(const char* soundEffectsPath, int a2, int debugLevel) { - char path[FILENAME_MAX]; + char path[COMPAT_MAX_PATH]; // TODO: What for? // memcpy(path, byte_4A97E0, 0xFF); diff --git a/src/stat.cc b/src/stat.cc index 87f434f..84bde62 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -11,6 +11,7 @@ #include "memory.h" #include "object.h" #include "perk.h" +#include "platform_compat.h" #include "proto.h" #include "random.h" #include "scripts.h" @@ -92,7 +93,7 @@ int statsInit() return -1; } - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s%s", asc_5186C8, "stat.msg"); if (!messageListLoad(&gStatsMessageList, path)) { diff --git a/src/text_font.cc b/src/text_font.cc index 54efe4a..e9facec 100644 --- a/src/text_font.cc +++ b/src/text_font.cc @@ -3,13 +3,11 @@ #include "color.h" #include "db.h" #include "memory.h" +#include "platform_compat.h" #include #include -#define WIN32_LEAN_AND_MEAN -#include - // 0x4D5530 FontManager gTextFontManager = { 0, @@ -112,7 +110,7 @@ int textFontLoad(int font) { int rc = -1; - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "font%d.fon", font); // NOTE: Original code is slightly different. It uses deep nesting and diff --git a/src/trait.cc b/src/trait.cc index 43eb1c8..d833315 100644 --- a/src/trait.cc +++ b/src/trait.cc @@ -2,6 +2,7 @@ #include "game.h" #include "object.h" +#include "platform_compat.h" #include "skill.h" #include "stat.h" @@ -42,7 +43,7 @@ int traitsInit() return -1; } - char path[FILENAME_MAX]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s%s", asc_5186C8, "trait.msg"); if (!messageListLoad(&gTraitsMessageList, path)) { diff --git a/src/window.cc b/src/window.cc index d75f398..0db6aff 100644 --- a/src/window.cc +++ b/src/window.cc @@ -498,7 +498,7 @@ void _removeProgramReferences_3(Program* program) // 0x4B9190 void _initWindow(int resolution, int a2) { - char err[MAX_PATH]; + char err[COMPAT_MAX_PATH]; int rc; int i, j; diff --git a/src/world_map.cc b/src/world_map.cc index 6a4ada7..7809233 100644 --- a/src/world_map.cc +++ b/src/world_map.cc @@ -612,7 +612,7 @@ int gEncounterTablesLength; // 0x4BC89C int worldmapInit() { - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; if (_wmGenDataInit() == -1) { return -1; @@ -4028,7 +4028,7 @@ int _wmGrabTileWalkMask(int tile) return -1; } - char path[MAX_PATH]; + char path[COMPAT_MAX_PATH]; sprintf(path, "data\\%s.msk", tileInfo->walkMaskName); File* stream = fileOpen(path, "rb"); diff --git a/src/xfile.cc b/src/xfile.cc index 324766b..e4dd5c3 100644 --- a/src/xfile.cc +++ b/src/xfile.cc @@ -1,7 +1,6 @@ #include "xfile.h" #include "file_find.h" -#include "platform_compat.h" #include #include @@ -60,7 +59,7 @@ XFile* xfileOpen(const char* filePath, const char* mode) char dir[_MAX_DIR]; _splitpath(filePath, drive, dir, NULL, NULL); - char path[FILENAME_MAX]; + char path[COMPAT_MAX_PATH]; if (drive[0] != '\0' || dir[0] == '\\' || dir[0] == '/' || dir[0] == '.') { // [filePath] is an absolute path. Attempt to open as plain stream. stream->file = fopen(filePath, mode); @@ -505,8 +504,8 @@ bool xbaseOpen(const char* path) return true; } - char workingDirectory[FILENAME_MAX]; - if (getcwd(workingDirectory, FILENAME_MAX) == NULL) { + char workingDirectory[COMPAT_MAX_PATH]; + if (getcwd(workingDirectory, COMPAT_MAX_PATH) == NULL) { // FIXME: Leaking xbase and path. return false; } @@ -600,7 +599,7 @@ bool xlistEnumerate(const char* pattern, XListEnumerationHandler* handler, XList dbaseFindClose(xbase->dbase, &dbaseFindData); } } else { - char path[FILENAME_MAX]; + char path[COMPAT_MAX_PATH]; sprintf(path, "%s\\%s", xbase->path, pattern); if (fileFindFirst(path, &directoryFileFindData)) { @@ -704,8 +703,8 @@ void xlistFree(XList* xlist) // 0x4DFFAC int xbaseMakeDirectory(const char* filePath) { - char workingDirectory[FILENAME_MAX]; - if (getcwd(workingDirectory, FILENAME_MAX) == NULL) { + char workingDirectory[COMPAT_MAX_PATH]; + if (getcwd(workingDirectory, COMPAT_MAX_PATH) == NULL) { return -1; } @@ -713,7 +712,7 @@ int xbaseMakeDirectory(const char* filePath) char dir[_MAX_DIR]; _splitpath(filePath, drive, dir, NULL, NULL); - char path[FILENAME_MAX]; + char path[COMPAT_MAX_PATH]; if (drive[0] != '\0' || dir[0] == '\\' || dir[0] == '/' || dir[0] == '.') { // [filePath] is an absolute path. strcpy(path, filePath); diff --git a/src/xfile.h b/src/xfile.h index 50bfd35..c63ebfb 100644 --- a/src/xfile.h +++ b/src/xfile.h @@ -3,6 +3,8 @@ #include "dfile.h" +#include "platform_compat.h" + #include #include @@ -51,7 +53,7 @@ typedef enum XFileEnumerationEntryType { } XFileEnumerationEntryType; typedef struct XListEnumerationContext { - char name[FILENAME_MAX]; + char name[COMPAT_MAX_PATH]; unsigned char type; XList* xlist; } XListEnumerationContext;