mirror of
https://github.com/acidicoala/SmokeAPI.git
synced 2026-05-04 19:42:15 -04:00
Refactor
This commit is contained in:
@@ -8,18 +8,14 @@
|
||||
#include <koalabox/hook.hpp>
|
||||
#include <koalabox/loader.hpp>
|
||||
#include <koalabox/win_util.hpp>
|
||||
#ifndef _WIN64
|
||||
#include <koalabox/patcher.hpp>
|
||||
#endif
|
||||
|
||||
#define DETOUR_EX(FUNC, ADDRESS) hook::detour_or_warn(ADDRESS, #FUNC, reinterpret_cast<FunctionAddress>(FUNC));
|
||||
#define DETOUR(FUNC) hook::detour_or_warn(original_library, #FUNC, reinterpret_cast<FunctionAddress>(FUNC));
|
||||
#ifndef _WIN64
|
||||
#include <koalageddon/koalageddon.hpp>
|
||||
#endif
|
||||
|
||||
namespace smoke_api {
|
||||
Config config = {}; // NOLINT(cert-err58-cpp)
|
||||
|
||||
KoalageddonConfig koalageddon_config = {};
|
||||
|
||||
HMODULE original_library = nullptr;
|
||||
|
||||
bool is_hook_mode = false;
|
||||
@@ -31,53 +27,6 @@ namespace smoke_api {
|
||||
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;
|
||||
|
||||
if (name == VSTDLIB_DLL) {
|
||||
// Family Sharing functions
|
||||
DETOUR(Coroutine_Create)
|
||||
} else if (name == STEAMCLIENT_DLL) {
|
||||
// Unlocking functions
|
||||
auto interface_interceptor_address = (FunctionAddress) patcher::find_pattern_address(
|
||||
win_util::get_module_info(library),
|
||||
"SteamClient_Interface_Interceptor",
|
||||
koalageddon_config.interface_interceptor_pattern
|
||||
);
|
||||
|
||||
if (interface_interceptor_address) {
|
||||
DETOUR_EX(SteamClient_Interface_Interceptor, interface_interceptor_address)
|
||||
}
|
||||
}
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
void init_proxy_mode() {
|
||||
logger->info("🔀 Detected proxy mode");
|
||||
|
||||
@@ -90,7 +39,7 @@ namespace smoke_api {
|
||||
dll_monitor::init(STEAMCLIENT_DLL, [](const HMODULE& library) {
|
||||
original_library = library;
|
||||
|
||||
DETOUR(CreateInterface)
|
||||
DETOUR_ORIGINAL(CreateInterface)
|
||||
});
|
||||
|
||||
// Hooking steam_api has show itself to be less desirable than steamclient
|
||||
@@ -139,8 +88,9 @@ namespace smoke_api {
|
||||
if (is_hook_mode) {
|
||||
hook::init(true);
|
||||
|
||||
// TODO: Check if it's steam from valve
|
||||
if (util::strings_are_equal(exe_name, "steam.exe") && !util::is_x64()) {
|
||||
init_koalageddon_mode();
|
||||
koalageddon::init();
|
||||
} else {
|
||||
init_hook_mode();
|
||||
}
|
||||
|
||||
@@ -24,58 +24,6 @@
|
||||
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;
|
||||
uint32_t steamclient_interceptor_function_address_offset_one = 0;
|
||||
uint32_t steamclient_interceptor_function_address_offset_two = 2;
|
||||
uint32_t steamclient_interceptor_function_address_offset_two_client_user = 5;
|
||||
uint32_t IClientAppManager_IsAppDlcInstalled_ordinal = 8;
|
||||
uint32_t IClientApps_GetDLCCount_ordinal = 8;
|
||||
uint32_t IClientApps_BGetDLCDataByIndex_ordinal = 9;
|
||||
uint32_t IClientInventory_GetResultStatus_ordinal = 0;
|
||||
uint32_t IClientInventory_GetResultItems_ordinal = 2;
|
||||
uint32_t IClientInventory_GetResultItemProperty_ordinal = 3;
|
||||
uint32_t IClientInventory_CheckResultSteamID_ordinal = 5;
|
||||
uint32_t IClientInventory_GetAllItems_ordinal = 8;
|
||||
uint32_t IClientInventory_GetItemsByID_ordinal = 9;
|
||||
uint32_t IClientInventory_SerializeResult_ordinal = 6;
|
||||
uint32_t IClientInventory_GetItemDefinitionIDs_ordinal = 19;
|
||||
uint32_t IClientUser_IsSubscribedApp_ordinal = 191;
|
||||
|
||||
// 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,
|
||||
steamclient_interceptor_function_address_offset_one,
|
||||
steamclient_interceptor_function_address_offset_two,
|
||||
steamclient_interceptor_function_address_offset_two_client_user,
|
||||
IClientAppManager_IsAppDlcInstalled_ordinal,
|
||||
IClientApps_GetDLCCount_ordinal,
|
||||
IClientApps_BGetDLCDataByIndex_ordinal,
|
||||
IClientInventory_GetResultStatus_ordinal,
|
||||
IClientInventory_GetResultItems_ordinal,
|
||||
IClientInventory_GetResultItemProperty_ordinal,
|
||||
IClientInventory_CheckResultSteamID_ordinal,
|
||||
IClientInventory_GetAllItems_ordinal,
|
||||
IClientInventory_GetItemsByID_ordinal,
|
||||
IClientInventory_SerializeResult_ordinal,
|
||||
IClientInventory_GetItemDefinitionIDs_ordinal,
|
||||
IClientUser_IsSubscribedApp_ordinal
|
||||
)
|
||||
};
|
||||
|
||||
struct Config {
|
||||
uint32_t $version = 2;
|
||||
bool logging = false;
|
||||
@@ -102,8 +50,6 @@ namespace smoke_api {
|
||||
|
||||
extern Config config;
|
||||
|
||||
extern KoalageddonConfig koalageddon_config;
|
||||
|
||||
extern HMODULE original_library;
|
||||
|
||||
extern bool is_hook_mode;
|
||||
|
||||
Reference in New Issue
Block a user