Refactored types

This commit is contained in:
acidicoala
2025-08-23 21:26:49 +05:00
parent dc086e40e0
commit e08cf014d1
19 changed files with 243 additions and 89 deletions

View File

@@ -12,7 +12,7 @@
#include "smoke_api.hpp"
#include "smoke_api/config.hpp"
#include "steamclient/steamclient.hpp"
#include "smoke_api/steamclient/steamclient.hpp"
// Hooking steam_api has shown itself to be less desirable than steamclient
// for the reasons outlined below:

View File

@@ -20,13 +20,6 @@ constexpr auto STEAM_INVENTORY = "STEAMINVENTORY_INTERFACE_V";
#define MODULE_CALL_CLOSURE(FUNC, ...) \
[&] { MODULE_CALL(FUNC, __VA_ARGS__); }
#define HOOKED_CALL(FUNC, ...) \
static const auto _##FUNC = KB_HOOK_GET_HOOKED_FN(smoke_api::steamapi_module, FUNC); \
return _##FUNC(__VA_ARGS__)
#define HOOKED_CALL_CLOSURE(FUNC, ...) \
[&] { HOOKED_CALL(FUNC, __VA_ARGS__); }
namespace smoke_api {
extern HMODULE steamapi_module;

View File

@@ -2,41 +2,6 @@
#include "smoke_api/types.hpp"
/**
* By default, virtual functions are declared with __thiscall
* convention, which is normal since they are class members.
* But it presents an issue for us, since we cannot pass *this
* pointer as a function argument. This is because *this
* pointer is passed via register ECX in __thiscall
* convention. Hence, to resolve this issue we declare our
* hooked functions with __fastcall convention, to trick
* the compiler into reading ECX & EDX registers as 1st
* and 2nd function arguments respectively. Similarly, __fastcall
* makes the compiler push the first argument into the ECX register,
* which mimics the __thiscall calling convention. Register EDX
* is not used anywhere in this case, but we still pass it along
* to conform to the __fastcall convention. This all applies
* to the x86 architecture.
*
* In x86-64 however, there is only one calling convention,
* so __fastcall is simply ignored. However, RDX in this case
* will store the 1st actual argument to the function, so we
* have to omit it from the function signature.
*
* The macros below implement the above-mentioned considerations.
*/
#ifdef _WIN64
#define PARAMS(...) void *RCX, __VA_ARGS__
#define ARGS(...) RCX, __VA_ARGS__
#define THIS RCX
#else
#define PARAMS(...) const void *ECX, const void *EDX, __VA_ARGS__
#define ARGS(...) ECX, EDX, __VA_ARGS__
#define THIS ECX
#endif
#define VIRTUAL(TYPE) __declspec(noinline) TYPE __fastcall // NOLINT(*-macro-parentheses)
// ISteamApps
VIRTUAL(bool) ISteamApps_BIsSubscribedApp(PARAMS(AppId_t));
VIRTUAL(bool) ISteamApps_BIsDlcInstalled(PARAMS(AppId_t));

16
src/steamclient.cpp Normal file
View File

@@ -0,0 +1,16 @@
#include "smoke_api/steamclient/steamclient.hpp"
#include "smoke_api.hpp"
#include "smoke_api/types.hpp"
#include "steam_api/steam_client.hpp"
/**
* SmokeAPI implementation
*/
C_DECL(void*) CreateInterface(const char* interface_version, int* out_result) {
return steam_client::GetGenericInterface(
__func__,
interface_version,
HOOKED_CALL_CLOSURE(CreateInterface, interface_version, out_result)
);
}

View File

@@ -1,15 +0,0 @@
#include <koalabox/hook.hpp>
#include "steamclient.hpp"
#include "smoke_api.hpp"
#include "smoke_api/types.hpp"
#include "steam_api/steam_client.hpp"
C_DECL(void*) CreateInterface(const char* interface_string, int* out_result) {
return steam_client::GetGenericInterface(
__func__,
interface_string,
HOOKED_CALL_CLOSURE(CreateInterface, interface_string, out_result)
);
}

View File

@@ -1,5 +0,0 @@
#pragma once
#define C_DECL(TYPE) extern "C" __declspec(noinline) TYPE __cdecl
C_DECL(void*) CreateInterface(const char* interface_string, int* out_result);