Added koalageddon config

This commit is contained in:
acidicoala
2022-12-30 01:44:33 +03:00
parent 941d5d7d8c
commit 636f9186a3
8 changed files with 104 additions and 31 deletions

View File

@@ -18,16 +18,44 @@
namespace smoke_api {
Config config = {}; // NOLINT(cert-err58-cpp)
KoalageddonConfig koalageddon_config = {};
HMODULE original_library = nullptr;
bool is_hook_mode = false;
Path self_directory;
void init_config() {
// TODO: Detect koalageddon mode first, and then fetch config from corresponding directory
config = config_parser::parse<Config>(self_directory / PROJECT_NAME".json");
}
/**
* @return A string representing the source of the config.
*/
String init_koalageddon_config() {
try {
// First try to read a local config override
koalageddon_config = config.koalageddon_config.get<KoalageddonConfig>();
return "local config override";
} catch (const Exception& ex) {
logger->debug("Local config parse exception: {}", ex.what());
}
// TODO: Remote source with local cache
// Finally, fallback on the default config
return "default config bundled in the binary";
}
void init_koalageddon_mode() {
#ifndef _WIN64
logger->info("🐨 Detected Koalageddon mode 💥");
const auto kg_config_source = init_koalageddon_config();
logger->info("Loaded Koalageddon config from the {}", kg_config_source);
dll_monitor::init({VSTDLIB_DLL, STEAMCLIENT_DLL}, [](const HMODULE& library, const String& name) {
original_library = library; // TODO: Is this necessary?
@@ -36,13 +64,14 @@ namespace smoke_api {
DETOUR(Coroutine_Create)
} else if (name == STEAMCLIENT_DLL) {
// Unlocking functions
// TODO: Un-hardcode the pattern
const String pattern("55 8B EC 8B ?? ?? ?? ?? ?? 81 EC ?? ?? ?? ?? 53 FF 15");
auto Log_Interface_address = (FunctionAddress) patcher::find_pattern_address(
win_util::get_module_info(library), "Log_Interface", pattern
auto interface_interceptor_address = (FunctionAddress) patcher::find_pattern_address(
win_util::get_module_info(library),
"SteamClient_Interface_Interceptor",
koalageddon_config.interface_interceptor_pattern
);
if (Log_Interface_address) {
DETOUR_EX(Log_Interface, Log_Interface_address)
if (interface_interceptor_address) {
DETOUR_EX(SteamClient_Interface_Interceptor, interface_interceptor_address)
}
}
});
@@ -91,7 +120,7 @@ namespace smoke_api {
self_directory = loader::get_module_dir(self_module);
config = config_parser::parse<Config>(self_directory / PROJECT_NAME".json");
init_config();
const auto exe_path = Path(win_util::get_module_file_name_or_throw(nullptr));
const auto exe_name = exe_path.filename().string();

View File

@@ -24,8 +24,30 @@
namespace smoke_api {
using namespace koalabox;
struct KoalageddonConfig {
String interface_interceptor_pattern = "55 8B EC 8B ?? ?? ?? ?? ?? 81 EC ?? ?? ?? ?? 53 FF 15";
// Offset values are interpreted according to pointer arithmetic rules, i.e.
// 1 unit offset represents 4 and 8 bytes in 32-bit and 64-bit architectures respectively.
uint32_t callback_interceptor_address_offset = 1;
uint32_t callback_address_offset = 20;
uint32_t callback_data_offset = 0;
uint32_t callback_name_offset = 4;
// We do not use *_WITH_DEFAULT macro to ensure that overriding
// the koalageddon config requires definition of all keys
NLOHMANN_DEFINE_TYPE_INTRUSIVE(
KoalageddonConfig, // NOLINT(misc-const-correctness)
interface_interceptor_pattern,
callback_interceptor_address_offset,
callback_address_offset,
callback_data_offset,
callback_name_offset
)
};
struct Config {
uint32_t $version = 1;
uint32_t $version = 2;
bool logging = false;
bool unlock_all = true;
Set<uint32_t> override;
@@ -33,6 +55,9 @@ namespace smoke_api {
bool auto_inject_inventory = true;
Vector<uint32_t> inventory_items;
// Have to use general json type here since library doesn't support std::optional
nlohmann::json koalageddon_config;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(
Config, $version, // NOLINT(misc-const-correctness)
logging,
@@ -40,12 +65,15 @@ namespace smoke_api {
override,
dlc_ids,
auto_inject_inventory,
inventory_items
inventory_items,
koalageddon_config
)
};
extern Config config;
extern KoalageddonConfig koalageddon_config;
extern HMODULE original_library;
extern bool is_hook_mode;