From cde29f0fd077b27320518d7384e2b48964e311c4 Mon Sep 17 00:00:00 2001 From: redpolline <11156324-redpolline@users.noreply.gitlab.com> Date: Wed, 11 Dec 2024 16:52:51 -0500 Subject: [PATCH] Create GOLDBERG_CALLBACK_INTERNAL() macro. This allows the usage of steam callbacks within the emulator itself. --- dll/dll.h | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/dll/dll.h b/dll/dll.h index 1b34715..7e2effd 100644 --- a/dll/dll.h +++ b/dll/dll.h @@ -25,6 +25,72 @@ #define STEAMCLIENT_API static #endif +#define GOLDBERG_CALLBACK_INTERNAL(parent, fname, cb_type) \ + struct GB_CCallbackInternal_ ## fname : private GB_CCallbackInterImp< sizeof(cb_type) > { \ + public: \ + ~GB_CCallbackInternal_ ## fname () { if (m_nCallbackFlags & k_ECallbackFlagsRegistered) { \ + bool ready = false; \ + do { \ + if (global_mutex.try_lock() == true) { \ + Steam_Client * client = get_steam_client(); \ + if (client != NULL) { \ + get_steam_client()->UnregisterCallback(this); \ + ready = true; \ + } \ + global_mutex.unlock(); \ + } \ + } while (!ready); \ + } }\ + GB_CCallbackInternal_ ## fname () {} \ + GB_CCallbackInternal_ ## fname ( const GB_CCallbackInternal_ ## fname & ) {} \ + GB_CCallbackInternal_ ## fname & operator=(const GB_CCallbackInternal_ ## fname &) { return *this; } \ + private: \ + virtual void Run(void *callback) { \ + if (!(m_nCallbackFlags & k_ECallbackFlagsRegistered)) { \ + bool ready = false; \ + do { \ + if (global_mutex.try_lock() == true) { \ + Steam_Client * client = get_steam_client(); \ + if (client != NULL) { \ + client->RegisterCallback(this, cb_type::k_iCallback); \ + ready = true; \ + } \ + global_mutex.unlock(); \ + } \ + } while (!ready); \ + } \ + if (m_nCallbackFlags & k_ECallbackFlagsRegistered) { \ + parent *obj = reinterpret_cast(reinterpret_cast(this) - offsetof(parent, m_steamcallback_ ## fname)); \ + obj->fname(reinterpret_cast(callback)); \ + } \ + } \ + } m_steamcallback_ ## fname ; void fname( cb_type *callback ) + +template +class GB_CCallbackInterImp : protected CCallbackBase +{ + public: + virtual ~GB_CCallbackInterImp() { if (m_nCallbackFlags & k_ECallbackFlagsRegistered) { + bool ready = false; + do { + if (global_mutex.try_lock() == true) { + Steam_Client * client = get_steam_client(); + if (client != NULL) { + get_steam_client()->UnregisterCallback(this); + ready = true; + } + global_mutex.unlock(); + } + } while (!ready); + } } + void SetGameserverFlag() { m_nCallbackFlags |= k_ECallbackFlagsGameServer; } + protected: + friend class CCallbackMgr; + virtual void Run(void *callback) = 0; + virtual void Run( void *callback, bool io_failure, SteamAPICall_t api_fp) { Run(callback); } + virtual int GetCallbackSizeBytes() { return sizeof_cb_type; } +}; + Steam_Client *get_steam_client(); bool steamclient_has_ipv6_functions();