From e40747625baf16392801babcb27fd534d3d949b5 Mon Sep 17 00:00:00 2001 From: Diavolo Date: Tue, 16 Aug 2022 15:18:21 +0200 Subject: [PATCH] fix(filesystem): use correct os path length --- src/game/game.hpp | 5 ++++- src/module/file_system.cpp | 12 ++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/game/game.hpp b/src/game/game.hpp index d132116..fb67306 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -196,9 +196,12 @@ namespace game extern int* sys_timeBase; extern unsigned __int64* sys_counterBase; - // PM Global Definitions & Functions + // Global Definitions & Functions constexpr auto JUMP_LAND_SLOWDOWN_TIME = 1800; + constexpr auto MAX_QPATH = 64; + constexpr auto MAX_OSPATH = 256; + // From Quake III, to match game's assembly template constexpr auto VectorScale(T v, R s, T out) { out[0] = v[0] * s; out[1] = v[1] * s; out[2] = v[2] * s; } diff --git a/src/module/file_system.cpp b/src/module/file_system.cpp index e3639d0..7bf6262 100644 --- a/src/module/file_system.cpp +++ b/src/module/file_system.cpp @@ -12,7 +12,7 @@ static utils::hook::detour sys_default_install_path_hook; static const game::native::dvar_t** fs_homepath; static const game::native::dvar_t** fs_debug; -static FILE* file_for_handle(int f) +static FILE* file_for_handle(const int f) { assert(!game::native::fsh[f].zipFile); assert(game::native::fsh[f].handleFiles.file.o); @@ -20,9 +20,9 @@ static FILE* file_for_handle(int f) return game::native::fsh[f].handleFiles.file.o; } -static unsigned int file_write(const void* ptr, unsigned int len, FILE* stream) +static unsigned int file_write(const void* ptr, const unsigned int len, FILE* stream) { - return std::fwrite(ptr, 1, len, stream); + return std::fwrite(ptr, sizeof(char), len, stream); } static FILE* file_open_append_text(const char* filename) @@ -94,7 +94,7 @@ static void build_os_path_for_thread(const char* base, const char* game, const c auto len_base = std::strlen(base); auto len_game = std::strlen(game); auto len_qpath = std::strlen(qpath); - if (len_game + 1 + len_base + len_qpath + 1 >= 256) + if (len_game + 1 + len_base + len_qpath + 1 >= game::native::MAX_OSPATH) { if (thread) { @@ -147,7 +147,7 @@ static int handle_for_file_current_thread() static int open_file_append(const char* filename) { - char ospath[MAX_PATH]{}; + char ospath[game::native::MAX_OSPATH]{}; game::native::FS_CheckFileSystemStarted(); const auto* basepath = (*fs_homepath)->current.string; @@ -203,7 +203,7 @@ static int get_handle_and_open_file(const char* filename, const char* ospath, ga static int open_file_write_to_dir_for_thread(const char* filename, const char* dir, const char* osbasepath, game::native::FsThread thread) { - char ospath[MAX_PATH]{}; + char ospath[game::native::MAX_OSPATH]{}; game::native::FS_CheckFileSystemStarted();