From 95bf860a632109c9923138997a2c9c4210a1839e Mon Sep 17 00:00:00 2001 From: m Date: Fri, 14 Oct 2022 14:02:18 -0500 Subject: [PATCH] add root folder IO --- src/client/component/io.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/client/component/io.cpp b/src/client/component/io.cpp index ffedbe0f..28b05131 100644 --- a/src/client/component/io.cpp +++ b/src/client/component/io.cpp @@ -13,12 +13,15 @@ #include #include +#include #include namespace io { namespace { + bool use_root_folder = false; + void check_path(const std::filesystem::path& path) { if (path.generic_string().find("..") != std::string::npos) @@ -30,8 +33,15 @@ namespace io std::string convert_path(const std::filesystem::path& path) { check_path(path); - static const auto fs_game = game::Dvar_FindVar("fs_game"); + if (use_root_folder) + { + static const auto fs_base_game = game::Dvar_FindVar("fs_basepath"); + const std::filesystem::path fs_base_game_path(fs_base_game->current.string); + return (fs_base_game_path / path).generic_string(); + } + + static const auto fs_game = game::Dvar_FindVar("fs_game"); if (fs_game->current.string && fs_game->current.string != ""s) { const std::filesystem::path fs_game_path(fs_game->current.string); @@ -47,6 +57,12 @@ namespace io public: void post_unpack() override { + use_root_folder = utils::flags::has_flag("io_game_dir"); + if (use_root_folder) + { + console::warn("WARNING: GSC has access to your game folder. To prevent possible malicious code, remove this flag."); + } + gsc::function::add("fileexists", [](const gsc::function_args& args) { const auto path = convert_path(args[0].as());