mirror of
https://github.com/acidicoala/SmokeAPI.git
synced 2026-01-24 21:42:53 -05:00
Fix proxy mode
This commit is contained in:
@@ -37,9 +37,6 @@ set(SMOKE_API_SOURCES
|
||||
${SMOKE_API_STATIC_SOURCES}
|
||||
src/smoke_api/smoke_api.cpp
|
||||
src/smoke_api/smoke_api.hpp
|
||||
# src/steam_api/exports/steam_api.cpp
|
||||
# src/steam_api/exports/steam_api.hpp
|
||||
# src/steam_api/exports/steam_api_unversioned.cpp
|
||||
src/steam_api/virtuals/isteamapps.cpp
|
||||
src/steam_api/virtuals/isteamclient.cpp
|
||||
src/steam_api/virtuals/isteamgameserver.cpp
|
||||
@@ -99,7 +96,7 @@ configure_linker_exports(
|
||||
TARGET SmokeAPI
|
||||
HEADER_NAME "linker_exports_for_steam_api"
|
||||
FORWARDED_DLL "${STEAMAPI_DLL}_o"
|
||||
INPUT_SOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/steam_api/exports"
|
||||
INPUT_SOURCES_DIR ""
|
||||
DLL_FILES_GLOB "${CMAKE_CURRENT_SOURCE_DIR}/res/steamworks/*/binaries/${STEAM_API_DLL}"
|
||||
)
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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();
|
||||
@@ -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)
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user