Add Basic support for ISteamGameServer_UserHasLicenseForApp

pull/1/head
Zeper 1 year ago
parent 4b337a981e
commit cac0311ea6

@ -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)

@ -2,6 +2,7 @@
#include <steam_impl/steam_client.hpp>
#include <steam_impl/steam_inventory.hpp>
#include <steam_impl/steam_user.hpp>
#include <steam_impl/steam_game_server.hpp>
#include <steam_impl/steam_impl.hpp>
#include <koalabox/logger.hpp>
@ -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;
}
}

@ -0,0 +1,33 @@
#include <steam_impl/steam_game_server.hpp>
#include <smoke_api/config.hpp>
#include <koalabox/logger.hpp>
namespace steam_game_server {
EUserHasLicenseForAppResult UserHasLicenseForApp(
const String& function_name,
AppId_t appId,
AppId_t dlcId,
const Function<EUserHasLicenseForAppResult()>& 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;
}
}

@ -0,0 +1,14 @@
#pragma once
#include <core/types.hpp>
namespace steam_game_server {
EUserHasLicenseForAppResult UserHasLicenseForApp(
const String& function_name,
AppId_t appId,
AppId_t dlcId,
const Function<EUserHasLicenseForAppResult()>& original_function
);
}
Loading…
Cancel
Save