From 21ce390a53976acabc83a7db05d6407fa14fad73 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 18 Feb 2023 19:13:13 +0100 Subject: [PATCH] Add support for appdata path --- src/client/game/game.cpp | 24 ++++++++++++++++++++++++ src/client/game/game.hpp | 2 ++ 2 files changed, 26 insertions(+) diff --git a/src/client/game/game.cpp b/src/client/game/game.cpp index 18ca63bf..0fb8f24a 100644 --- a/src/client/game/game.cpp +++ b/src/client/game/game.cpp @@ -2,6 +2,8 @@ #include "game.hpp" +#include + namespace game { namespace @@ -34,4 +36,26 @@ namespace game static const auto server = get_host_library().get_optional_header()->CheckSum == 0x14C28B4; return server; } + + std::filesystem::path get_appdata_path() + { + static const auto appdata_path = [] + { + PWSTR path; + if (FAILED(SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, nullptr, &path))) + { + throw std::runtime_error("Failed to read APPDATA path!"); + } + + auto _ = utils::finally([&path] + { + CoTaskMemFree(path); + }); + + static auto appdata = std::filesystem::path(path) / "boiii"; + return appdata; + }(); + + return appdata_path; + } } diff --git a/src/client/game/game.hpp b/src/client/game/game.hpp index 02e6fa59..2a825538 100644 --- a/src/client/game/game.hpp +++ b/src/client/game/game.hpp @@ -73,6 +73,8 @@ namespace game size_t address_{}; size_t server_address_{}; }; + + std::filesystem::path get_appdata_path(); } inline size_t operator"" _g(const size_t val)