Fix proxy mode

This commit is contained in:
acidicoala
2025-09-04 23:49:54 +05:00
parent 141a0bcc58
commit 61ff1df065
4 changed files with 1 additions and 240 deletions

View File

@@ -1,98 +0,0 @@
// Not included in project due atm due to lack of usage
#include <koalabox/logger.hpp>
#include "steam_api/exports/steam_api.hpp"
#include "smoke_api/config.hpp"
#include "smoke_api/smoke_api.hpp"
#define AUTO_CALL_RETURN(FUNC, ...) \
static const auto _##FUNC = smoke_api::hook_mode \
? KB_HOOK_GET_HOOKED_FN(FUNC) \
: KB_WIN_GET_PROC(smoke_api::steamapi_module, FUNC); \
return _##FUNC(__VA_ARGS__)
#define AUTO_CALL_RESULT(FUNC, ...) \
static const auto _##FUNC = smoke_api::hook_mode \
? KB_HOOK_GET_HOOKED_FN(FUNC) \
: KB_WIN_GET_PROC(smoke_api::steamapi_module, FUNC); \
const auto result = _##FUNC(__VA_ARGS__)
DLL_EXPORT(bool) SteamAPI_Init() {
LOG_INFO(__func__);
AUTO_CALL_RESULT(SteamAPI_Init);
LOG_INFO("{} -> result: {}", __func__, result);
return result;
}
DLL_EXPORT(bool) SteamAPI_InitSafe() {
LOG_INFO(__func__);
AUTO_CALL_RESULT(SteamAPI_InitSafe);
LOG_INFO("{} -> result: {}", __func__, result);
return result;
}
DLL_EXPORT(ESteamAPIInitResult) SteamAPI_InitFlat(const SteamErrMsg* pOutErrMsg) {
LOG_INFO(__func__);
AUTO_CALL_RESULT(SteamAPI_InitFlat, pOutErrMsg);
const auto error_message = pOutErrMsg && *pOutErrMsg
? std::string_view(*pOutErrMsg)
: "";
LOG_INFO(
"{} -> result: {}, error_message: {}",
__func__,
result,
error_message
);
return result;
}
DLL_EXPORT(ESteamAPIInitResult) SteamInternal_SteamAPI_Init(
const char* pszInternalCheckInterfaceVersions,
const SteamErrMsg* pOutErrMsg
) {
LOG_INFO(__func__);
AUTO_CALL_RESULT(SteamInternal_SteamAPI_Init, pszInternalCheckInterfaceVersions, pOutErrMsg);
const auto error_message = pOutErrMsg && *pOutErrMsg
? std::string_view(*pOutErrMsg)
: "";
LOG_INFO(
"{} -> pszInternalCheckInterfaceVersions: {}, result: {}, error_message: {}",
__func__,
pszInternalCheckInterfaceVersions,
result,
error_message
);
return result;
}
DLL_EXPORT(bool) SteamAPI_RestartAppIfNecessary(const AppId_t unOwnAppID) {
LOG_INFO(__func__);
AUTO_CALL_RESULT(SteamAPI_RestartAppIfNecessary, unOwnAppID);
LOG_INFO("{} -> unOwnAppID: {}, result: {}", __func__, unOwnAppID, result);
// Restart can be suppressed if needed
return result;
}
DLL_EXPORT(void) SteamAPI_Shutdown() {
LOG_INFO("{} -> Game requested shutdown", __func__);
AUTO_CALL_RETURN(SteamAPI_Shutdown);
}

View File

@@ -1,24 +0,0 @@
// Not included in project due atm due to lack of usage
#pragma once
#include "smoke_api/smoke_api.hpp"
#include "smoke_api/types.hpp"
using ESteamAPIInitResult = uint32_t;
using SteamErrMsg = char[1024];
DLL_EXPORT(bool) SteamAPI_Init();
DLL_EXPORT(bool) SteamAPI_InitSafe();
DLL_EXPORT(ESteamAPIInitResult) SteamAPI_InitFlat(const SteamErrMsg* pOutErrMsg);
DLL_EXPORT(ESteamAPIInitResult) SteamInternal_SteamAPI_Init(
const char* pszInternalCheckInterfaceVersions,
const SteamErrMsg* pOutErrMsg
);
DLL_EXPORT(bool) SteamAPI_RestartAppIfNecessary(AppId_t unOwnAppID);
DLL_EXPORT(void) SteamAPI_Shutdown();

View File

@@ -1,114 +0,0 @@
#include <map>
#include <regex>
#include <koalabox/logger.hpp>
#include <koalabox/win.hpp>
#include "smoke_api/smoke_api.hpp"
#include "steam_api/steam_client.hpp"
namespace {
namespace kb = koalabox;
/**
* Searches the `.rdata` section of the original dll for the full interface version string
* Results are cached for performance.
*/
std::string get_versioned_interface(
const std::string& version_prefix,
const std::string& fallback
) {
static std::map<std::string, std::string> version_map;
if(version_map.contains(version_prefix)) {
return version_map.at(version_prefix);
}
try {
const auto section = kb::win::get_pe_section_or_throw(
smoke_api::steamapi_module,
".rdata"
);
const auto rdata = std::string(
reinterpret_cast<const char*>(section.start_address),
section.size
);
const std::regex regex(version_prefix + "\\d{3}");
if(std::smatch match; std::regex_search(rdata, match, regex)) {
version_map[version_prefix] = match[0];
} else {
throw std::runtime_error(std::format("No match found for '{}'", version_prefix));
}
} catch(const std::exception& ex) {
LOG_ERROR(
"Failed to get versioned interface: {}."
"Falling back to version {}",
ex.what(),
fallback
);
version_map[version_prefix] = version_prefix + fallback;
}
return version_map.at(version_prefix);
}
}
// TODO: Do we really need to proxy them?
#define MODULE_CALL_CLOSURE(FUNC, ...) \
[&] { \
static const auto _##FUNC = KB_WIN_GET_PROC(smoke_api::steamapi_module, FUNC); \
return _##FUNC(__VA_ARGS__); \
}
DLL_EXPORT(void*) SteamApps() {
static auto version = get_versioned_interface(STEAM_APPS, "002");
return steam_client::GetGenericInterface(
__func__,
version,
MODULE_CALL_CLOSURE(SteamApps)
);
}
DLL_EXPORT(void*) SteamClient() {
static auto version = get_versioned_interface(STEAM_CLIENT, "006");
return steam_client::GetGenericInterface(
__func__,
version,
MODULE_CALL_CLOSURE(SteamClient)
);
}
DLL_EXPORT(void*) SteamHTTP() {
static auto version = get_versioned_interface(STEAM_HTTP, "003");
return steam_client::GetGenericInterface(
__func__,
version,
MODULE_CALL_CLOSURE(SteamHTTP)
);
}
DLL_EXPORT(void*) SteamInventory() {
static auto version = get_versioned_interface(STEAM_INVENTORY, "001");
return steam_client::GetGenericInterface(
__func__,
version,
MODULE_CALL_CLOSURE(SteamInventory)
);
}
DLL_EXPORT(void*) SteamUser() {
static auto version = get_versioned_interface(STEAM_USER, "012");
return steam_client::GetGenericInterface(
__func__,
version,
MODULE_CALL_CLOSURE(SteamUser)
);
}