mirror of
https://github.com/acidicoala/SmokeAPI.git
synced 2026-01-24 13:32:51 -05:00
Fixed static order init fiasco
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<component name="ProjectRunConfigurationManager">
|
<component name="ProjectRunConfigurationManager">
|
||||||
<configuration default="false" name="linux_exports_generator [32]" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="--input_libs_glob $ProjectFileDir$/res/steamworks/*/binaries/linux32/libsteam_api.so --output_path $ProjectFileDir$/src/generated/32/proxy_exports" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="SmokeAPI" TARGET_NAME="linux_exports_generator" CONFIG_NAME="Debug [64]" RUN_TARGET_PROJECT_NAME="SmokeAPI" RUN_TARGET_NAME="linux_exports_generator">
|
<configuration default="false" name="linux_exports_generator [32]" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="--input_libs_glob $ProjectFileDir$/res/steamworks/*/binaries/linux32/libsteam_api.so --output_path $ProjectFileDir$/src/generated/32/proxy_exports" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="SmokeAPI" TARGET_NAME="linux_exports_generator" CONFIG_NAME="Debug [32]" RUN_TARGET_PROJECT_NAME="SmokeAPI" RUN_TARGET_NAME="linux_exports_generator">
|
||||||
<method v="2">
|
<method v="2">
|
||||||
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
|
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
|
||||||
</method>
|
</method>
|
||||||
|
|||||||
2
KoalaBox
2
KoalaBox
Submodule KoalaBox updated: 57cee7c22b...61454a2dac
@@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
#include "build_config.h"
|
#include "build_config.h"
|
||||||
|
|
||||||
#if defined(KB_WIN)
|
#ifdef KB_WIN
|
||||||
#include "koalabox/win.hpp"
|
#include "koalabox/win.hpp"
|
||||||
#elif defined(KB_LINUX) && defined(KB_32)
|
#elif defined(KB_LINUX) && defined(KB_32)
|
||||||
#include "generated/32/proxy_exports.hpp"
|
#include "generated/32/proxy_exports.hpp"
|
||||||
@@ -64,7 +64,9 @@ namespace {
|
|||||||
|
|
||||||
std::set<std::string> versions;
|
std::set<std::string> versions;
|
||||||
|
|
||||||
const auto rdata_section = kb::lib::get_section_or_throw(steamapi_handle, kb::lib::CONST_STR_SECTION);
|
// On Linux the section name depends on individual lib file, so we can't use generic constants
|
||||||
|
const std::string str_section_name = kb::platform::is_windows ? ".text" : ".rodata.str";
|
||||||
|
const auto rdata_section = kb::lib::get_section_or_throw(steamapi_handle, str_section_name);
|
||||||
const auto rdata = rdata_section.to_string();
|
const auto rdata = rdata_section.to_string();
|
||||||
|
|
||||||
const std::regex pattern(R"(SteamClient\d{3})");
|
const std::regex pattern(R"(SteamClient\d{3})");
|
||||||
@@ -229,16 +231,16 @@ namespace smoke_api {
|
|||||||
|
|
||||||
kb::globals::init_globals(self_module_handle, PROJECT_NAME);
|
kb::globals::init_globals(self_module_handle, PROJECT_NAME);
|
||||||
|
|
||||||
config::instance = kb::config::parse<config::Config>();
|
config::get() = kb::config::parse<config::Config>();
|
||||||
|
|
||||||
if(config::instance.logging) {
|
if(config::get().logging) {
|
||||||
kb::logger::init_file_logger(kb::paths::get_log_path());
|
kb::logger::init_file_logger(kb::paths::get_log_path());
|
||||||
} else {
|
} else {
|
||||||
kb::logger::init_null_logger();
|
kb::logger::init_null_logger();
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_INFO("{} v{}{} | Built at '{}'", PROJECT_NAME, PROJECT_VERSION, VERSION_SUFFIX, __TIMESTAMP__);
|
LOG_INFO("{} v{}{} | Built at '{}'", PROJECT_NAME, PROJECT_VERSION, VERSION_SUFFIX, __TIMESTAMP__);
|
||||||
LOG_DEBUG("Parsed config:\n{}", nlohmann::ordered_json(config::instance).dump(2));
|
LOG_DEBUG("Parsed config:\n{}", nlohmann::ordered_json(config::get()).dump(2));
|
||||||
|
|
||||||
const auto exe_path = kb::lib::get_fs_path(nullptr);
|
const auto exe_path = kb::lib::get_fs_path(nullptr);
|
||||||
const auto exe_name = kb::path::to_str(exe_path.filename());
|
const auto exe_name = kb::path::to_str(exe_path.filename());
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
#include <koalabox/config.hpp>
|
#include <koalabox/config.hpp>
|
||||||
#include <koalabox/io.hpp>
|
|
||||||
#include <koalabox/logger.hpp>
|
#include <koalabox/logger.hpp>
|
||||||
|
|
||||||
#include "smoke_api/config.hpp"
|
#include "smoke_api/config.hpp"
|
||||||
|
|
||||||
namespace smoke_api::config {
|
namespace smoke_api::config {
|
||||||
Config instance; // NOLINT(cert-err58-cpp)
|
Config& get() noexcept {
|
||||||
|
static Config config;
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<DLC> get_extra_dlcs(const uint32_t app_id) {
|
std::vector<DLC> get_extra_dlcs(const uint32_t app_id) {
|
||||||
return DLC::get_dlcs_from_apps(instance.extra_dlcs, app_id);
|
return DLC::get_dlcs_from_apps(get().extra_dlcs, app_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_dlc_unlocked(
|
bool is_dlc_unlocked(
|
||||||
@@ -16,16 +18,16 @@ namespace smoke_api::config {
|
|||||||
const AppId_t dlc_id,
|
const AppId_t dlc_id,
|
||||||
const std::function<bool()>& original_function
|
const std::function<bool()>& original_function
|
||||||
) {
|
) {
|
||||||
auto status = instance.default_app_status;
|
auto status = get().default_app_status;
|
||||||
|
|
||||||
const auto app_id_str = std::to_string(app_id);
|
const auto app_id_str = std::to_string(app_id);
|
||||||
if(instance.override_app_status.contains(app_id_str)) {
|
if(get().override_app_status.contains(app_id_str)) {
|
||||||
status = instance.override_app_status[app_id_str];
|
status = get().override_app_status[app_id_str];
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto dlc_id_str = std::to_string(dlc_id);
|
const auto dlc_id_str = std::to_string(dlc_id);
|
||||||
if(instance.override_dlc_status.contains(dlc_id_str)) {
|
if(get().override_dlc_status.contains(dlc_id_str)) {
|
||||||
status = instance.override_dlc_status[dlc_id_str];
|
status = get().override_dlc_status[dlc_id_str];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_unlocked;
|
bool is_unlocked;
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace smoke_api::config {
|
|||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Config instance;
|
Config& get() noexcept;
|
||||||
|
|
||||||
std::vector<DLC> get_extra_dlcs(AppId_t app_id);
|
std::vector<DLC> get_extra_dlcs(AppId_t app_id);
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,15 @@ namespace {
|
|||||||
/// This means we have to get extra DLC IDs from local config, remote config, or cache.
|
/// This means we have to get extra DLC IDs from local config, remote config, or cache.
|
||||||
constexpr auto MAX_DLC = 64;
|
constexpr auto MAX_DLC = 64;
|
||||||
|
|
||||||
std::map<uint32_t, std::vector<DLC>> app_dlcs; // NOLINT(cert-err58-cpp)
|
auto& get_fully_fetched_apps() {
|
||||||
std::set<uint32_t> fully_fetched; // NOLINT(cert-err58-cpp)
|
static std::set<uint32_t> fully_fetched_apps;
|
||||||
|
return fully_fetched_apps;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto& get_app_dlc_map() {
|
||||||
|
static std::map<uint32_t, std::vector<DLC>> app_dlc_map;
|
||||||
|
return app_dlc_map;
|
||||||
|
}
|
||||||
|
|
||||||
std::string get_app_id_log(const uint32_t app_id) {
|
std::string get_app_id_log(const uint32_t app_id) {
|
||||||
return app_id ? std::format("App ID: {:>8}, ", app_id) : "";
|
return app_id ? std::format("App ID: {:>8}, ", app_id) : "";
|
||||||
@@ -31,13 +38,13 @@ namespace {
|
|||||||
|
|
||||||
if(app_id == 0) {
|
if(app_id == 0) {
|
||||||
LOG_ERROR("{} -> App ID is 0", __func__);
|
LOG_ERROR("{} -> App ID is 0", __func__);
|
||||||
app_dlcs[app_id] = {}; // Dummy value to avoid checking for presence on each access
|
get_app_dlc_map()[app_id] = {}; // Dummy value to avoid checking for presence on each access
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We want to fetch data only once. However, if any of the remote sources have failed
|
// We want to fetch data only once. However, if any of the remote sources have failed
|
||||||
// previously, we want to attempt fetching again.
|
// previously, we want to attempt fetching again.
|
||||||
if(fully_fetched.contains(app_id)) {
|
if(get_fully_fetched_apps().contains(app_id)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,13 +74,13 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(github_dlcs_opt && steam_dlcs_opt) {
|
if(github_dlcs_opt && steam_dlcs_opt) {
|
||||||
fully_fetched.insert(app_id);
|
get_fully_fetched_apps().insert(app_id);
|
||||||
} else {
|
} else {
|
||||||
append_dlcs(smoke_api::cache::get_dlcs(app_id), "disk cache");
|
append_dlcs(smoke_api::cache::get_dlcs(app_id), "disk cache");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache DLCs in memory and cache for future use
|
// Cache DLCs in memory and cache for future use
|
||||||
app_dlcs[app_id] = aggregated_dlcs;
|
get_app_dlc_map()[app_id] = aggregated_dlcs;
|
||||||
|
|
||||||
smoke_api::cache::save_dlcs(app_id, aggregated_dlcs);
|
smoke_api::cache::save_dlcs(app_id, aggregated_dlcs);
|
||||||
}
|
}
|
||||||
@@ -137,12 +144,12 @@ namespace smoke_api::steam_apps {
|
|||||||
|
|
||||||
fetch_and_cache_dlcs(app_id);
|
fetch_and_cache_dlcs(app_id);
|
||||||
|
|
||||||
if(app_dlcs.empty()) {
|
if(get_app_dlc_map().empty()) {
|
||||||
LOG_DEBUG("{} -> No cached DLCs, responding with original count", function_name);
|
LOG_DEBUG("{} -> No cached DLCs, responding with original count", function_name);
|
||||||
return total_count(original_count);
|
return total_count(original_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
return total_count(static_cast<int>(app_dlcs[app_id].size()));
|
return total_count(static_cast<int>(get_app_dlc_map()[app_id].size()));
|
||||||
} catch(const std::exception& e) {
|
} catch(const std::exception& e) {
|
||||||
LOG_ERROR("{} -> Uncaught exception: {}", function_name, e.what());
|
LOG_ERROR("{} -> Uncaught exception: {}", function_name, e.what());
|
||||||
return 0;
|
return 0;
|
||||||
@@ -188,8 +195,8 @@ namespace smoke_api::steam_apps {
|
|||||||
pchName[bytes_to_copy] = '\0'; // Ensure null-termination
|
pchName[bytes_to_copy] = '\0'; // Ensure null-termination
|
||||||
};
|
};
|
||||||
|
|
||||||
if(!app_dlcs.empty() && app_dlcs.contains(app_id)) {
|
if(!get_app_dlc_map().empty() && get_app_dlc_map().contains(app_id)) {
|
||||||
const auto& dlcs = app_dlcs[app_id];
|
const auto& dlcs = get_app_dlc_map()[app_id];
|
||||||
|
|
||||||
if(iDLC >= 0 && iDLC < dlcs.size()) {
|
if(iDLC >= 0 && iDLC < dlcs.size()) {
|
||||||
output_dlc(dlcs[iDLC]);
|
output_dlc(dlcs[iDLC]);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace smoke_api::steam_http {
|
|||||||
try {
|
try {
|
||||||
const auto result = original_function();
|
const auto result = original_function();
|
||||||
|
|
||||||
if(config::instance.log_steam_http) {
|
if(config::get().log_steam_http) {
|
||||||
const std::string_view buffer =
|
const std::string_view buffer =
|
||||||
pBodyDataBuffer && unBufferSize
|
pBodyDataBuffer && unBufferSize
|
||||||
? std::string_view(
|
? std::string_view(
|
||||||
@@ -50,7 +50,7 @@ namespace smoke_api::steam_http {
|
|||||||
try {
|
try {
|
||||||
const auto result = original_function();
|
const auto result = original_function();
|
||||||
|
|
||||||
if(config::instance.log_steam_http) {
|
if(config::get().log_steam_http) {
|
||||||
const std::string_view buffer =
|
const std::string_view buffer =
|
||||||
pBodyDataBuffer && unBufferSize
|
pBodyDataBuffer && unBufferSize
|
||||||
? std::string_view(
|
? std::string_view(
|
||||||
@@ -87,7 +87,7 @@ namespace smoke_api::steam_http {
|
|||||||
try {
|
try {
|
||||||
const auto result = original_function();
|
const auto result = original_function();
|
||||||
|
|
||||||
if(config::instance.log_steam_http) {
|
if(config::get().log_steam_http) {
|
||||||
const std::string_view content_type =
|
const std::string_view content_type =
|
||||||
pchContentType ? pchContentType : "smoke_api::N/A";
|
pchContentType ? pchContentType : "smoke_api::N/A";
|
||||||
|
|
||||||
|
|||||||
@@ -70,11 +70,11 @@ namespace smoke_api::steam_inventory {
|
|||||||
);
|
);
|
||||||
|
|
||||||
static uint32_t original_count = 0;
|
static uint32_t original_count = 0;
|
||||||
const auto injected_count = config::instance.extra_inventory_items.size();
|
const auto injected_count = config::get().extra_inventory_items.size();
|
||||||
|
|
||||||
// Automatically get inventory items from steam
|
// Automatically get inventory items from steam
|
||||||
static std::vector<SteamItemDef_t> auto_inventory_items;
|
static std::vector<SteamItemDef_t> auto_inventory_items;
|
||||||
if(config::instance.auto_inject_inventory) {
|
if(config::get().auto_inject_inventory) {
|
||||||
static std::once_flag inventory_inject_flag;
|
static std::once_flag inventory_inject_flag;
|
||||||
std::call_once(
|
std::call_once(
|
||||||
inventory_inject_flag,
|
inventory_inject_flag,
|
||||||
@@ -126,7 +126,7 @@ namespace smoke_api::steam_inventory {
|
|||||||
|
|
||||||
for(int i = 0; i < injected_count; i++) {
|
for(int i = 0; i < injected_count; i++) {
|
||||||
auto& item = pOutItemsArray[original_count + auto_injected_count + i];
|
auto& item = pOutItemsArray[original_count + auto_injected_count + i];
|
||||||
const auto item_def_id = config::instance.extra_inventory_items[i];
|
const auto item_def_id = config::get().extra_inventory_items[i];
|
||||||
|
|
||||||
item = new_item(item_def_id);
|
item = new_item(item_def_id);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user