From 7a5bae58ec7fde46be2e333315ce732412439209 Mon Sep 17 00:00:00 2001 From: Detanup01 <91248446+Detanup01@users.noreply.github.com> Date: Sun, 29 Dec 2024 15:37:55 +0100 Subject: [PATCH 1/8] Add starter pdk --- pdk/pdk.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ pdk/pdk.h | 20 ++++++++++++++++++ premake5.lua | 3 +++ 3 files changed, 82 insertions(+) create mode 100644 pdk/pdk.cpp create mode 100644 pdk/pdk.h diff --git a/pdk/pdk.cpp b/pdk/pdk.cpp new file mode 100644 index 00000000..32f000f5 --- /dev/null +++ b/pdk/pdk.cpp @@ -0,0 +1,59 @@ +#include "pdk.h" + +/// +/// Registering from the Maker +/// +/// +/// +/// 0 for success, 1 if failed +int PDK::RegisterInterface(InterfaceMaker interfaceMakePtr, const char* interfaceVersion) +{ + if (interfaceMakePtr == NULL) + return 1; + if (interfaceVersion == NULL) + return 1; + if (!client_known_interfaces.count(interfaceVersion)) + return 1; + interfaceMap.insert(std::make_pair(interfaceMakePtr, interfaceVersion)); + return 0; +} + +/// +/// Unregistering from the Maker +/// +/// +/// 0 for success, 1 if failed +int PDK::UnRegisterInterface(InterfaceMaker interfaceMakePtr) +{ + if (interfaceMakePtr == NULL) + return 1; + + interfaceMap.erase(interfaceMakePtr); + return 0; +} + +void* PDK::MakeInterface(HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char* interfaceVersion) +{ + for (const auto& [key, value] : interfaceMap) + { + if (strstr(interfaceVersion, value) == 0) + { + auto maker = (InterfaceMaker)key; + return maker(hSteamUser, hSteamPipe); + } + } + return nullptr; +} + + +void* TestCreate(HSteamUser hSteamUser, HSteamPipe hSteamPipe) +{ + return nullptr; +} + +void Register() +{ + // Which one should be good? idk + //PDK::RegisterInterface(TestCreate, "STEAMAPPLIST_INTERFACE_VERSION001"); + //PDK::RegisterInterface(&TestCreate, "STEAMAPPLIST_INTERFACE_VERSION001"); +} diff --git a/pdk/pdk.h b/pdk/pdk.h new file mode 100644 index 00000000..983316ce --- /dev/null +++ b/pdk/pdk.h @@ -0,0 +1,20 @@ +#ifndef PDK_INCLUDE_H +#define PDK_INCLUDE_H + +#include "dll/base.h" +#include "dll/client_known_interfaces.h" + +typedef void* (__cdecl* InterfaceMaker)(HSteamUser hSteamUser, HSteamPipe hSteamPipe); + +class PDK +{ + static inline std::map interfaceMap; +public: + + static int RegisterInterface(InterfaceMaker interfaceMakePtr, const char* interfaceVersion); + static int UnRegisterInterface(InterfaceMaker interfaceMakePtr); + static void* MakeInterface(HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char* interfaceVersion); +}; + + +#endif //PDK_INCLUDE_H diff --git a/premake5.lua b/premake5.lua index 2a0684d8..fe54bddc 100644 --- a/premake5.lua +++ b/premake5.lua @@ -197,6 +197,7 @@ local common_include = { 'crash_printer', 'sdk', "overlay_experimental", + "pdk" } local x32_deps_include = { @@ -243,6 +244,8 @@ local common_files = { "helpers/common_helpers.cpp", "helpers/common_helpers/**", -- helpers/dbg_log "helpers/dbg_log.cpp", "helpers/dbg_log/**", + -- pdk + "pdk/**", } local overlay_files = { From af46e8c0e80efd684f9e8221bcc7085c64f31c99 Mon Sep 17 00:00:00 2001 From: Detanup01 <91248446+Detanup01@users.noreply.github.com> Date: Mon, 20 Jan 2025 15:19:18 +0100 Subject: [PATCH 2/8] add simple example plugin --- example_plugin/main.cpp | 13 +++++++++++++ generate_win_premake.bat | 2 ++ pdk/pdk.cpp | 32 +++++++++++++++++++++----------- pdk/pdk.h | 32 +++++++++++++++++++++++++++++++- premake5.lua | 37 +++++++++++++++++++++++++++++++++++++ 5 files changed, 104 insertions(+), 12 deletions(-) create mode 100644 example_plugin/main.cpp create mode 100644 generate_win_premake.bat diff --git a/example_plugin/main.cpp b/example_plugin/main.cpp new file mode 100644 index 00000000..ff37c057 --- /dev/null +++ b/example_plugin/main.cpp @@ -0,0 +1,13 @@ +#include "pdk.h" + +#define EXPORT extern "C" __declspec( dllexport ) + +EXPORT void GBE_Load() +{ + +} + +EXPORT void GBE_UnLoad() +{ + +} diff --git a/generate_win_premake.bat b/generate_win_premake.bat new file mode 100644 index 00000000..2e637eef --- /dev/null +++ b/generate_win_premake.bat @@ -0,0 +1,2 @@ +set "CMAKE_GENERATOR=Visual Studio 17 2022" +call "third-party\common\win\premake\premake5.exe" --file="premake5.lua" --genproto --dosstub --winrsrc --winsign --os=windows vs2022 \ No newline at end of file diff --git a/pdk/pdk.cpp b/pdk/pdk.cpp index 32f000f5..1819579f 100644 --- a/pdk/pdk.cpp +++ b/pdk/pdk.cpp @@ -1,11 +1,22 @@ #include "pdk.h" +#include "dll/client_known_interfaces.h" + +typedef void (*__cdecl PluginCall)(); + +void PDK::LoadPlugin(HMODULE handle) +{ + PluginCall load = (PluginCall)GetProcAddress(handle, "GBE_Load"); + load(); + PRINT_DEBUG("Loaded crack file"); +} + +void PDK::UnloLoadPlugin(HMODULE handle) +{ + PluginCall load = (PluginCall)GetProcAddress(handle, "GBE_UnLoad"); + load(); + PRINT_DEBUG("Loaded crack file"); +} -/// -/// Registering from the Maker -/// -/// -/// -/// 0 for success, 1 if failed int PDK::RegisterInterface(InterfaceMaker interfaceMakePtr, const char* interfaceVersion) { if (interfaceMakePtr == NULL) @@ -18,11 +29,6 @@ int PDK::RegisterInterface(InterfaceMaker interfaceMakePtr, const char* interfac return 0; } -/// -/// Unregistering from the Maker -/// -/// -/// 0 for success, 1 if failed int PDK::UnRegisterInterface(InterfaceMaker interfaceMakePtr) { if (interfaceMakePtr == NULL) @@ -45,6 +51,10 @@ void* PDK::MakeInterface(HSteamUser hSteamUser, HSteamPipe hSteamPipe, const cha return nullptr; } +int PDK::GetPDKVersion() +{ + return 1; +} void* TestCreate(HSteamUser hSteamUser, HSteamPipe hSteamPipe) { diff --git a/pdk/pdk.h b/pdk/pdk.h index 983316ce..5c3c408a 100644 --- a/pdk/pdk.h +++ b/pdk/pdk.h @@ -2,18 +2,48 @@ #define PDK_INCLUDE_H #include "dll/base.h" -#include "dll/client_known_interfaces.h" typedef void* (__cdecl* InterfaceMaker)(HSteamUser hSteamUser, HSteamPipe hSteamPipe); + class PDK { static inline std::map interfaceMap; + + + static void LoadPlugin(HMODULE handle); + static void UnloLoadPlugin(HMODULE handle); public: + /// + /// Registering from the Maker + /// + /// + /// + /// 0 for success, 1 if failed static int RegisterInterface(InterfaceMaker interfaceMakePtr, const char* interfaceVersion); + + /// + /// Unregistering from the Maker + /// + /// + /// 0 for success, 1 if failed static int UnRegisterInterface(InterfaceMaker interfaceMakePtr); + + /// + /// Make Registered interface + /// + /// + /// + /// + /// nullptr if not found, a vaild pointer to the interface static void* MakeInterface(HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char* interfaceVersion); + + /// + /// Get PDK Version + /// + /// + static int GetPDKVersion(); }; diff --git a/premake5.lua b/premake5.lua index fe54bddc..a7f36db6 100644 --- a/premake5.lua +++ b/premake5.lua @@ -1577,4 +1577,41 @@ project "test_crash_printer_sa_sigaction" end -- End LINUX ONLY TARGETS +-- Project example_plugin +project "example_plugin" + kind "SharedLib" + location "%{wks.location}/%{prj.name}" + targetdir("build/" .. os_iden .. "/%{_ACTION}/%{cfg.buildcfg}/example_plugin") + targetname "example_plugin_%{cfg.platform}" + + -- include dir + --------- + -- common include dir + -- x32 include dir + filter { "platforms:x32", } + includedirs { + x32_deps_include, + } + + -- x64 include dir + filter { "platforms:x64", } + includedirs { + x64_deps_include, + } + + + -- common source & header files + --------- + filter {} -- reset the filter and remove all active keywords + files { -- added to all filters, later defines will be appended + -- dll/ + --"dll/dll/*.h", + -- pdk + "pdk/*.h", + 'example_plugin/**' + } + + +-- End example_plugin + -- End Workspace From d7fe629407f8b9190ed1cf7d6fc338a09661b7f7 Mon Sep 17 00:00:00 2001 From: Detanup01 <91248446+Detanup01@users.noreply.github.com> Date: Thu, 6 Feb 2025 12:44:50 +0100 Subject: [PATCH 3/8] fix linux related void* insert and stuff add real logic to example plugin. --- example_plugin/main.cpp | 21 +++++++++++++++++++-- pdk/pdk.cpp | 20 ++++---------------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/example_plugin/main.cpp b/example_plugin/main.cpp index ff37c057..d7e2d2b0 100644 --- a/example_plugin/main.cpp +++ b/example_plugin/main.cpp @@ -1,13 +1,30 @@ #include "pdk.h" +#define PRINT_DEBUG_PLUGIN(a, ...) do {FILE *t = fopen("example_debug.txt", "a"); fprintf(t, "%u " a, GetCurrentThreadId(), __VA_ARGS__); fclose(t);} while (0) + #define EXPORT extern "C" __declspec( dllexport ) EXPORT void GBE_Load() { - + PRINT_DEBUG_PLUGIN("GBE_Load"); + PRINT_DEBUG_PLUGIN("Version of PDK: %d", PDK::GetPDKVersion()); + // Which one should be good? idk + //PDK::RegisterInterface(TestCreate, "STEAMAPPLIST_INTERFACE_VERSION001"); + int success = PDK::RegisterInterface(&TestCreate, "STEAMAPPLIST_INTERFACE_VERSION001"); + PRINT_DEBUG_PLUGIN("Finished registering interfaces! Is Success: %d", success); } EXPORT void GBE_UnLoad() { - + PRINT_DEBUG_PLUGIN("GBE_UnLoad"); + int success = PDK::UnRegisterInterface(&TestCreate); + PRINT_DEBUG_PLUGIN("Finished registering interfaces! Is Success: %d", success); } + + +void* TestCreate(HSteamUser hSteamUser, HSteamPipe hSteamPipe) +{ + PRINT_DEBUG_PLUGIN("Test create with STEAMAPPLIST_INTERFACE_VERSION001"); + PRINT_DEBUG_PLUGIN("Args: %d %d", hSteamUser, hSteamPipe); + return nullptr; +} \ No newline at end of file diff --git a/pdk/pdk.cpp b/pdk/pdk.cpp index 1819579f..a37fa798 100644 --- a/pdk/pdk.cpp +++ b/pdk/pdk.cpp @@ -7,14 +7,14 @@ void PDK::LoadPlugin(HMODULE handle) { PluginCall load = (PluginCall)GetProcAddress(handle, "GBE_Load"); load(); - PRINT_DEBUG("Loaded crack file"); + PRINT_DEBUG("Loaded plugin file"); } void PDK::UnloLoadPlugin(HMODULE handle) { PluginCall load = (PluginCall)GetProcAddress(handle, "GBE_UnLoad"); load(); - PRINT_DEBUG("Loaded crack file"); + PRINT_DEBUG("Loaded plugin file"); } int PDK::RegisterInterface(InterfaceMaker interfaceMakePtr, const char* interfaceVersion) @@ -25,7 +25,7 @@ int PDK::RegisterInterface(InterfaceMaker interfaceMakePtr, const char* interfac return 1; if (!client_known_interfaces.count(interfaceVersion)) return 1; - interfaceMap.insert(std::make_pair(interfaceMakePtr, interfaceVersion)); + interfaceMap.insert(std::make_pair((void*)interfaceMakePtr, interfaceVersion)); return 0; } @@ -34,7 +34,7 @@ int PDK::UnRegisterInterface(InterfaceMaker interfaceMakePtr) if (interfaceMakePtr == NULL) return 1; - interfaceMap.erase(interfaceMakePtr); + interfaceMap.erase((void*)interfaceMakePtr); return 0; } @@ -55,15 +55,3 @@ int PDK::GetPDKVersion() { return 1; } - -void* TestCreate(HSteamUser hSteamUser, HSteamPipe hSteamPipe) -{ - return nullptr; -} - -void Register() -{ - // Which one should be good? idk - //PDK::RegisterInterface(TestCreate, "STEAMAPPLIST_INTERFACE_VERSION001"); - //PDK::RegisterInterface(&TestCreate, "STEAMAPPLIST_INTERFACE_VERSION001"); -} From e02c94271b282f64724bddae7ca2674df022f803 Mon Sep 17 00:00:00 2001 From: Detanup01 <91248446+Detanup01@users.noreply.github.com> Date: Thu, 6 Feb 2025 18:26:14 +0100 Subject: [PATCH 4/8] fixing code for linux. add auto load if exists add check if null. --- dll/base.cpp | 20 ++++++++++++++------ pdk/pdk.cpp | 26 ++++++++++++++++++++++---- pdk/pdk.h | 4 ++-- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/dll/base.cpp b/dll/base.cpp index d268ed33..961afd12 100644 --- a/dll/base.cpp +++ b/dll/base.cpp @@ -279,7 +279,7 @@ unsigned int file_size_(const std::string &full_path) #ifdef EMU_EXPERIMENTAL_BUILD - +#include "pdk/pdk.h" static std::vector loaded_libs{}; static void load_dlls() @@ -295,7 +295,8 @@ static void load_dlls() std::string path(Local_Storage::get_game_settings_path() + "load_dlls" + PATH_SEPARATOR); std::vector paths(Local_Storage::get_filenames_path(path)); - for (auto & p: paths) { + for (auto & p: paths) + { std::string full_path(path + p); if (!common_helpers::ends_with_i(full_path, LIB_EXTENSION)) continue; @@ -307,10 +308,14 @@ static void load_dlls() dlopen(full_path.c_str(), RTLD_NOW | RTLD_LOCAL); #endif - if (lib_handle != nullptr) { + if (lib_handle != nullptr) + { loaded_libs.push_back(reinterpret_cast(lib_handle)); + PDK::LoadPlugin(lib_handle); PRINT_DEBUG(" LOADED"); - } else { + } + else + { #ifdef __WINDOWS__ PRINT_DEBUG(" FAILED, error code 0x%X", GetLastError()); #else @@ -322,7 +327,9 @@ static void load_dlls() static void unload_dlls() { - for (auto lib_handle : loaded_libs) { + for (auto lib_handle : loaded_libs) + { + PDK::UnloLoadPlugin(lib_handle); #ifdef __WINDOWS__ FreeLibrary(reinterpret_cast(lib_handle)); #else @@ -333,7 +340,8 @@ static void unload_dlls() #ifdef __WINDOWS__ -struct ips_test { +struct ips_test +{ uint32_t ip_from; uint32_t ip_to; }; diff --git a/pdk/pdk.cpp b/pdk/pdk.cpp index a37fa798..04f7ccd1 100644 --- a/pdk/pdk.cpp +++ b/pdk/pdk.cpp @@ -3,16 +3,34 @@ typedef void (*__cdecl PluginCall)(); -void PDK::LoadPlugin(HMODULE handle) +void PDK::LoadPlugin(void* handle) { - PluginCall load = (PluginCall)GetProcAddress(handle, "GBE_Load"); +#ifdef __WINDOWS__ + HMODULE mod = reinterpret_cast(handle); + PluginCall load = (PluginCall)GetProcAddress(mod, "GBE_Load"); +#else + PluginCall load = (PluginCall)dlsym(mod, "GBE_Load"); +#endif + if (load == NULL) + { + return; + } load(); PRINT_DEBUG("Loaded plugin file"); } -void PDK::UnloLoadPlugin(HMODULE handle) +void PDK::UnloLoadPlugin(void* handle) { - PluginCall load = (PluginCall)GetProcAddress(handle, "GBE_UnLoad"); +#ifdef __WINDOWS__ + HMODULE mod = reinterpret_cast(handle); + PluginCall load = (PluginCall)GetProcAddress(mod, "GBE_UnLoad"); +#else + PluginCall load = (PluginCall)dlsym(mod, "GBE_UnLoad"); +#endif + if (load == NULL) + { + return; + } load(); PRINT_DEBUG("Loaded plugin file"); } diff --git a/pdk/pdk.h b/pdk/pdk.h index 5c3c408a..f37eb10f 100644 --- a/pdk/pdk.h +++ b/pdk/pdk.h @@ -11,8 +11,8 @@ class PDK static inline std::map interfaceMap; - static void LoadPlugin(HMODULE handle); - static void UnloLoadPlugin(HMODULE handle); + static void LoadPlugin(void* handle); + static void UnloLoadPlugin(void* handle); public: /// From 2f145f79bbc5d038fd6b9d6c659ca4fe4709ac11 Mon Sep 17 00:00:00 2001 From: Detanup01 <91248446+Detanup01@users.noreply.github.com> Date: Thu, 6 Feb 2025 18:38:03 +0100 Subject: [PATCH 5/8] fix pdk path --- dll/base.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dll/base.cpp b/dll/base.cpp index 961afd12..330ee33b 100644 --- a/dll/base.cpp +++ b/dll/base.cpp @@ -279,7 +279,7 @@ unsigned int file_size_(const std::string &full_path) #ifdef EMU_EXPERIMENTAL_BUILD -#include "pdk/pdk.h" +#include "../pdk/pdk.h" static std::vector loaded_libs{}; static void load_dlls() From cca591912750c84fbfcff979680b57ad7f17f5fe Mon Sep 17 00:00:00 2001 From: Detanup01 <91248446+Detanup01@users.noreply.github.com> Date: Thu, 6 Feb 2025 19:13:47 +0100 Subject: [PATCH 6/8] fix typo, make load and unload public (for now) --- dll/base.cpp | 2 +- pdk/pdk.cpp | 2 +- pdk/pdk.h | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/dll/base.cpp b/dll/base.cpp index 330ee33b..bd4f5c7e 100644 --- a/dll/base.cpp +++ b/dll/base.cpp @@ -329,7 +329,7 @@ static void unload_dlls() { for (auto lib_handle : loaded_libs) { - PDK::UnloLoadPlugin(lib_handle); + PDK::UnLoadPlugin(lib_handle); #ifdef __WINDOWS__ FreeLibrary(reinterpret_cast(lib_handle)); #else diff --git a/pdk/pdk.cpp b/pdk/pdk.cpp index 04f7ccd1..4b5f1b98 100644 --- a/pdk/pdk.cpp +++ b/pdk/pdk.cpp @@ -19,7 +19,7 @@ void PDK::LoadPlugin(void* handle) PRINT_DEBUG("Loaded plugin file"); } -void PDK::UnloLoadPlugin(void* handle) +void PDK::UnLoadPlugin(void* handle) { #ifdef __WINDOWS__ HMODULE mod = reinterpret_cast(handle); diff --git a/pdk/pdk.h b/pdk/pdk.h index f37eb10f..89829226 100644 --- a/pdk/pdk.h +++ b/pdk/pdk.h @@ -10,10 +10,9 @@ class PDK { static inline std::map interfaceMap; - - static void LoadPlugin(void* handle); - static void UnloLoadPlugin(void* handle); public: + static void LoadPlugin(void* handle); + static void UnLoadPlugin(void* handle); /// /// Registering from the Maker From 8ca74a6c6c98cffae1427fce1d4f4d84e2c0306d Mon Sep 17 00:00:00 2001 From: Detanup01 <91248446+Detanup01@users.noreply.github.com> Date: Thu, 6 Feb 2025 19:43:44 +0100 Subject: [PATCH 7/8] fix linux (hopefully) --- pdk/pdk.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pdk/pdk.cpp b/pdk/pdk.cpp index 4b5f1b98..c495e665 100644 --- a/pdk/pdk.cpp +++ b/pdk/pdk.cpp @@ -9,7 +9,7 @@ void PDK::LoadPlugin(void* handle) HMODULE mod = reinterpret_cast(handle); PluginCall load = (PluginCall)GetProcAddress(mod, "GBE_Load"); #else - PluginCall load = (PluginCall)dlsym(mod, "GBE_Load"); + PluginCall load = (PluginCall)dlsym(handle, "GBE_Load"); #endif if (load == NULL) { @@ -25,7 +25,7 @@ void PDK::UnLoadPlugin(void* handle) HMODULE mod = reinterpret_cast(handle); PluginCall load = (PluginCall)GetProcAddress(mod, "GBE_UnLoad"); #else - PluginCall load = (PluginCall)dlsym(mod, "GBE_UnLoad"); + PluginCall load = (PluginCall)dlsym(handle, "GBE_UnLoad"); #endif if (load == NULL) { From 3024ec7b2daf068c94e9cdb7b6058d490956ef4b Mon Sep 17 00:00:00 2001 From: Detanup01 <91248446+Detanup01@users.noreply.github.com> Date: Sat, 8 Feb 2025 15:51:33 +0100 Subject: [PATCH 8/8] add pdk interface maker in interface getter. --- dll/steam_client_interface_getter.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/dll/steam_client_interface_getter.cpp b/dll/steam_client_interface_getter.cpp index bd1d946a..a59ea825 100644 --- a/dll/steam_client_interface_getter.cpp +++ b/dll/steam_client_interface_getter.cpp @@ -317,6 +317,11 @@ ISteamMatchmakingServers *Steam_Client::GetISteamMatchmakingServers( HSteamUser report_missing_impl_and_exit(pchVersion, EMU_FUNC_NAME); } + +#ifdef EMU_EXPERIMENTAL_BUILD +#include "../pdk/pdk.h" +#endif + // returns the a generic interface void *Steam_Client::GetISteamGenericInterface( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) { @@ -335,6 +340,17 @@ void *Steam_Client::GetISteamGenericInterface( HSteamUser hSteamUser, HSteamPipe } } + // !! PDK !! +#ifdef EMU_EXPERIMENTAL_BUILD + void* pdk_interface = PDK::MakeInterface(hSteamUser, hSteamPipe, pchVersion); + if (pdk_interface != NULL) + { + return pdk_interface; + } +#endif + // !! PDK !! + + // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // NOTE: you must try to read the one with the most characters first // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!