Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Basic support for ISteamGameServer_UserHasLicenseForApp #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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}
)
Expand Down Expand Up @@ -101,4 +103,4 @@ configure_output_name(${STEAMAPI_DLL})

configure_include_directories()

target_link_libraries(SmokeAPI PRIVATE KoalaBox)
target_link_libraries(SmokeAPI PRIVATE KoalaBox)
31 changes: 31 additions & 0 deletions src/game_mode/exports/steam_api_flat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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;
}

}
33 changes: 33 additions & 0 deletions src/steam_impl/steam_game_server.cpp
Original file line number Diff line number Diff line change
@@ -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;
}

}
14 changes: 14 additions & 0 deletions src/steam_impl/steam_game_server.hpp
Original file line number Diff line number Diff line change
@@ -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
);

}