2022-06-02 04:14:44 -04:00
|
|
|
#include <std_include.hpp>
|
|
|
|
|
|
|
|
#include "game.hpp"
|
2022-06-02 07:49:43 -04:00
|
|
|
|
2023-02-18 13:13:13 -05:00
|
|
|
#include <utils/finally.hpp>
|
|
|
|
|
2022-06-02 07:49:43 -04:00
|
|
|
namespace game
|
|
|
|
{
|
2023-02-13 15:50:19 -05:00
|
|
|
namespace
|
2022-06-02 07:49:43 -04:00
|
|
|
{
|
2023-02-13 15:50:19 -05:00
|
|
|
const utils::nt::library& get_host_library()
|
2022-06-02 07:49:43 -04:00
|
|
|
{
|
2023-02-13 15:50:19 -05:00
|
|
|
static const auto host_library = []
|
2022-06-02 07:49:43 -04:00
|
|
|
{
|
2023-02-13 15:50:19 -05:00
|
|
|
utils::nt::library host{};
|
|
|
|
if (!host || host == utils::nt::library::get_by_address(get_base))
|
|
|
|
{
|
|
|
|
throw std::runtime_error("Invalid host application");
|
|
|
|
}
|
2023-01-01 15:46:36 -05:00
|
|
|
|
2023-02-13 15:50:19 -05:00
|
|
|
return host;
|
|
|
|
}();
|
2023-01-01 15:51:04 -05:00
|
|
|
|
2023-02-13 15:50:19 -05:00
|
|
|
return host_library;
|
|
|
|
}
|
2023-01-01 15:46:36 -05:00
|
|
|
}
|
2022-10-28 16:16:14 -04:00
|
|
|
|
2023-01-01 15:46:36 -05:00
|
|
|
size_t get_base()
|
|
|
|
{
|
2023-01-02 07:57:00 -05:00
|
|
|
static const auto base = reinterpret_cast<size_t>(get_host_library().get_ptr());
|
2022-11-11 11:19:26 -05:00
|
|
|
return base;
|
2022-10-28 16:16:14 -04:00
|
|
|
}
|
2023-01-01 15:46:36 -05:00
|
|
|
|
|
|
|
bool is_server()
|
|
|
|
{
|
2023-01-02 07:57:00 -05:00
|
|
|
static const auto server = get_host_library().get_optional_header()->CheckSum == 0x14C28B4;
|
2023-01-01 15:46:36 -05:00
|
|
|
return server;
|
|
|
|
}
|
2023-02-18 13:13:13 -05:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2022-06-02 07:49:43 -04:00
|
|
|
}
|