diff --git a/CMakeLists.txt b/CMakeLists.txt index 66f6477..3d38751 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.24) -project(SmokeAPI VERSION 2.0.5) +project(SmokeAPI VERSION 2.0.51) include(KoalaBox/cmake/KoalaBox.cmake) @@ -69,6 +69,8 @@ set( src/steam_impl/steam_inventory.hpp src/steam_impl/steam_user.cpp src/steam_impl/steam_user.hpp + src/steam_impl/steam_game_server.cpp + src/steam_impl/steam_game_server.hpp src/main.cpp ${GENERATED_LINKER_EXPORTS} ) @@ -101,4 +103,4 @@ configure_output_name(${STEAMAPI_DLL}) configure_include_directories() -target_link_libraries(SmokeAPI PRIVATE KoalaBox) +target_link_libraries(SmokeAPI PRIVATE KoalaBox) \ No newline at end of file diff --git a/src/game_mode/exports/steam_api_flat.cpp b/src/game_mode/exports/steam_api_flat.cpp index 6956107..ce4e5fe 100644 --- a/src/game_mode/exports/steam_api_flat.cpp +++ b/src/game_mode/exports/steam_api_flat.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -252,3 +253,33 @@ DLL_EXPORT(EUserHasLicenseForAppResult) SteamAPI_ISteamUser_UserHasLicenseForApp } } + +// ISteamGameServer + +DLL_EXPORT(EUserHasLicenseForAppResult) SteamAPI_ISteamGameServer_UserHasLicenseForApp( + void* self, + CSteamID steamID, + AppId_t dlcID +) { + try { + /* + Will crash here. + Probably because server only app don't need to init same interfaces used to recover the appID in the client (ISteamUser). + */ + //static const auto app_id = steam_impl::get_app_id_or_throw(); + // TODO : CLEAN THIS BY FINDING A WAY TO GET AppID FROM ISteamGameServer (hooking InitGameServer maybe ?) + static const auto app_id = 0; // Workaround + return steam_game_server::UserHasLicenseForApp( + __func__, app_id, dlcID, [&]() { + GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamGameServer_UserHasLicenseForApp) + + return SteamAPI_ISteamGameServer_UserHasLicenseForApp_o(self, steamID, dlcID); + } + ); + } + catch (const Exception& e) { + LOG_ERROR("{} -> Error: {}", __func__, e.what()) + return k_EUserHasLicenseResultDoesNotHaveLicense; + } + +} \ No newline at end of file diff --git a/src/steam_impl/steam_game_server.cpp b/src/steam_impl/steam_game_server.cpp new file mode 100644 index 0000000..1105b02 --- /dev/null +++ b/src/steam_impl/steam_game_server.cpp @@ -0,0 +1,33 @@ +#include +#include +#include + +namespace steam_game_server { + + EUserHasLicenseForAppResult UserHasLicenseForApp( + const String& function_name, + AppId_t appId, + AppId_t dlcId, + const Function& original_function + ) { + const auto result = original_function(); + + if (result == k_EUserHasLicenseResultNoAuth) { + LOG_WARN("{} -> App ID: {:>8}, Result: NoAuth", function_name, dlcId) + return result; + } + + const auto has_license = smoke_api::config::is_dlc_unlocked( + appId, dlcId, [&]() { + return result == k_EUserHasLicenseResultHasLicense; + } + ); + + LOG_INFO("{} -> App ID: {:>8}, HasLicense: {}", function_name, dlcId, has_license) + + return has_license + ? k_EUserHasLicenseResultHasLicense + : k_EUserHasLicenseResultDoesNotHaveLicense; + } + +} diff --git a/src/steam_impl/steam_game_server.hpp b/src/steam_impl/steam_game_server.hpp new file mode 100644 index 0000000..9d320de --- /dev/null +++ b/src/steam_impl/steam_game_server.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include + +namespace steam_game_server { + + EUserHasLicenseForAppResult UserHasLicenseForApp( + const String& function_name, + AppId_t appId, + AppId_t dlcId, + const Function& original_function + ); + +}