Fixed critical bugs

This commit is contained in:
acidicoala
2023-02-01 01:26:05 +03:00
parent 95ceac3d47
commit 73a05f1d91
10 changed files with 254 additions and 172 deletions

View File

@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.24)
project(SmokeAPI VERSION 2.0.0)
project(SmokeAPI VERSION 2.0.2)
include(KoalaBox/cmake/KoalaBox.cmake)

View File

@@ -8,33 +8,51 @@
// ISteamApps
DLL_EXPORT(bool) SteamAPI_ISteamApps_BIsSubscribedApp(void* self, AppId_t dlcID) {
try {
static const auto app_id = steam_impl::get_app_id_or_throw();
return steam_apps::IsDlcUnlocked(
__func__, 0, dlcID, [&]() {
__func__, app_id, dlcID, [&]() {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamApps_BIsSubscribedApp)
return SteamAPI_ISteamApps_BIsSubscribedApp_o(self, dlcID);
}
);
} catch (const Exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what())
return false;
}
}
DLL_EXPORT(bool) SteamAPI_ISteamApps_BIsDlcInstalled(void* self, AppId_t dlcID) {
try {
static const auto app_id = steam_impl::get_app_id_or_throw();
return steam_apps::IsDlcUnlocked(
__func__, 0, dlcID, [&]() {
__func__, app_id, dlcID, [&]() {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamApps_BIsDlcInstalled)
return SteamAPI_ISteamApps_BIsDlcInstalled_o(self, dlcID);
}
);
} catch (const Exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what())
return false;
}
}
DLL_EXPORT(int) SteamAPI_ISteamApps_GetDLCCount(void* self) {
try {
static const auto app_id = steam_impl::get_app_id_or_throw();
return steam_apps::GetDLCCount(
__func__, 0, [&]() {
__func__, app_id, [&]() {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamApps_GetDLCCount)
return SteamAPI_ISteamApps_GetDLCCount_o(self);
}
);
} catch (const Exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what())
return 0;
}
}
DLL_EXPORT(bool) SteamAPI_ISteamApps_BGetDLCDataByIndex(
@@ -45,11 +63,12 @@ DLL_EXPORT(bool) SteamAPI_ISteamApps_BGetDLCDataByIndex(
char* pchName,
int cchNameBufferSize
) {
try {
static const auto app_id = steam_impl::get_app_id_or_throw();
return steam_apps::GetDLCDataByIndex(
__func__, 0, iDLC, pDlcID, pbAvailable, pchName, cchNameBufferSize,
__func__, app_id, iDLC, pDlcID, pbAvailable, pchName, cchNameBufferSize,
[&]() {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamApps_BGetDLCDataByIndex)
return SteamAPI_ISteamApps_BGetDLCDataByIndex_o(
self, iDLC, pDlcID, pbAvailable, pchName, cchNameBufferSize
);
@@ -58,6 +77,10 @@ DLL_EXPORT(bool) SteamAPI_ISteamApps_BGetDLCDataByIndex(
return SteamAPI_ISteamApps_BIsDlcInstalled(self, dlc_id);
}
);
} catch (const Exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what())
return false;
}
}
// ISteamClient
@@ -68,13 +91,17 @@ DLL_EXPORT(void*) SteamAPI_ISteamClient_GetISteamGenericInterface(
HSteamPipe hSteamPipe,
const char* pchVersion
) {
try {
return steam_client::GetGenericInterface(
__func__, pchVersion, [&]() {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamClient_GetISteamGenericInterface)
return SteamAPI_ISteamClient_GetISteamGenericInterface_o(self, hSteamUser, hSteamPipe, pchVersion);
}
);
} catch (const Exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what())
return nullptr;
}
}
// ISteamInventory
@@ -210,13 +237,8 @@ DLL_EXPORT(EUserHasLicenseForAppResult) SteamAPI_ISteamUser_UserHasLicenseForApp
CSteamID steamID,
AppId_t dlcID
) {
AppId_t app_id;
try {
app_id = steam_impl::get_app_id_or_throw();
} catch (const Exception& e) {
LOG_ERROR("{} -> Error getting app id: {}", __func__, e.what())
}
static const auto app_id = steam_impl::get_app_id_or_throw();
return steam_user::UserHasLicenseForApp(
__func__, app_id, dlcID, [&]() {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamUser_UserHasLicenseForApp)
@@ -224,4 +246,9 @@ DLL_EXPORT(EUserHasLicenseForAppResult) SteamAPI_ISteamUser_UserHasLicenseForApp
return SteamAPI_ISteamUser_UserHasLicenseForApp_o(self, steamID, dlcID);
}
);
} catch (const Exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what())
return k_EUserHasLicenseResultDoesNotHaveLicense;
}
}

View File

@@ -1,56 +1,81 @@
#include <game_mode/virtuals/steam_api_virtuals.hpp>
#include <koalabox/util.hpp>
#include <steam_impl/steam_apps.hpp>
#include <steam_impl/steam_impl.hpp>
VIRTUAL(bool) ISteamApps_BIsSubscribedApp(PARAMS(AppId_t appID)) {
VIRTUAL(bool) ISteamApps_BIsSubscribedApp(PARAMS(AppId_t dlc_id)) {
try {
static const auto app_id = steam_impl::get_app_id_or_throw();
return steam_apps::IsDlcUnlocked(
__func__, 0, appID, [&]() {
GET_ORIGINAL_FUNCTION_STEAMAPI(ISteamApps_BIsSubscribedApp)
return ISteamApps_BIsSubscribedApp_o(ARGS(appID));
__func__, app_id, dlc_id, [&]() {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamApps_BIsSubscribedApp)
return ISteamApps_BIsSubscribedApp_o(ARGS(dlc_id));
}
);
} catch (const Exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what())
return false;
}
}
VIRTUAL(bool) ISteamApps_BIsDlcInstalled(PARAMS(AppId_t appID)) {
VIRTUAL(bool) ISteamApps_BIsDlcInstalled(PARAMS(AppId_t dlc_id)) {
try {
static const auto app_id = steam_impl::get_app_id_or_throw();
return steam_apps::IsDlcUnlocked(
__func__, 0, appID, [&]() {
GET_ORIGINAL_FUNCTION_STEAMAPI(ISteamApps_BIsDlcInstalled)
return ISteamApps_BIsDlcInstalled_o(ARGS(appID));
__func__, app_id, dlc_id, [&]() {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamApps_BIsDlcInstalled)
return ISteamApps_BIsDlcInstalled_o(ARGS(dlc_id));
}
);
} catch (const Exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what())
return false;
}
}
VIRTUAL(int) ISteamApps_GetDLCCount(PARAMS()) {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamApps_GetDLCCount)
try {
static const auto app_id = steam_impl::get_app_id_or_throw();
return steam_apps::GetDLCCount(
__func__, 0, [&]() {
__func__, app_id, [&]() {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamApps_GetDLCCount)
return ISteamApps_GetDLCCount_o(ARGS());
}
);
} catch (const Exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what())
return 0;
}
}
VIRTUAL(bool) ISteamApps_BGetDLCDataByIndex(
PARAMS(
int iDLC,
AppId_t* pAppID,
AppId_t* p_dlc_id,
bool* pbAvailable,
char* pchName,
int cchNameBufferSize
)
) {
try {
static const auto app_id = steam_impl::get_app_id_or_throw();
return steam_apps::GetDLCDataByIndex(
__func__, 0, iDLC, pAppID, pbAvailable, pchName, cchNameBufferSize,
__func__, app_id, iDLC, p_dlc_id, pbAvailable, pchName, cchNameBufferSize,
[&]() {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamApps_BGetDLCDataByIndex)
return ISteamApps_BGetDLCDataByIndex_o(
ARGS(iDLC, pAppID, pbAvailable, pchName, cchNameBufferSize)
ARGS(iDLC, p_dlc_id, pbAvailable, pchName, cchNameBufferSize)
);
},
[&](AppId_t dlc_id) {
return ISteamApps_BIsDlcInstalled(ARGS(dlc_id));
}
);
} catch (const Exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what())
return false;
}
}

View File

@@ -8,13 +8,17 @@ VIRTUAL(void*) ISteamClient_GetISteamApps(
const char* version
)
) {
try {
return steam_client::GetGenericInterface(
__func__, version, [&]() {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamClient_GetISteamApps)
return ISteamClient_GetISteamApps_o(ARGS(hSteamUser, hSteamPipe, version));
}
);
} catch (const Exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what())
return nullptr;
}
}
VIRTUAL(void*) ISteamClient_GetISteamUser(
@@ -24,6 +28,7 @@ VIRTUAL(void*) ISteamClient_GetISteamUser(
const char* version
)
) {
try {
return steam_client::GetGenericInterface(
__func__, version, [&]() {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamClient_GetISteamUser)
@@ -31,6 +36,10 @@ VIRTUAL(void*) ISteamClient_GetISteamUser(
return ISteamClient_GetISteamUser_o(ARGS(hSteamUser, hSteamPipe, version));
}
);
} catch (const Exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what())
return nullptr;
}
}
VIRTUAL(void*) ISteamClient_GetISteamGenericInterface(
@@ -40,6 +49,7 @@ VIRTUAL(void*) ISteamClient_GetISteamGenericInterface(
const char* pchVersion
)
) {
try {
return steam_client::GetGenericInterface(
__func__, pchVersion, [&]() {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamClient_GetISteamGenericInterface)
@@ -47,6 +57,10 @@ VIRTUAL(void*) ISteamClient_GetISteamGenericInterface(
return ISteamClient_GetISteamGenericInterface_o(ARGS(hSteamUser, hSteamPipe, pchVersion));
}
);
} catch (const Exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what())
return nullptr;
}
}
VIRTUAL(void*) ISteamClient_GetISteamInventory(
@@ -56,6 +70,7 @@ VIRTUAL(void*) ISteamClient_GetISteamInventory(
const char* pchVersion
)
) {
try {
return steam_client::GetGenericInterface(
__func__, pchVersion, [&]() {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamClient_GetISteamInventory)
@@ -63,4 +78,8 @@ VIRTUAL(void*) ISteamClient_GetISteamInventory(
return ISteamClient_GetISteamInventory_o(ARGS(hSteamUser, hSteamPipe, pchVersion));
}
);
} catch (const Exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what())
return nullptr;
}
}

View File

@@ -3,19 +3,18 @@
#include <steam_impl/steam_impl.hpp>
#include <koalabox/logger.hpp>
VIRTUAL(EUserHasLicenseForAppResult) ISteamUser_UserHasLicenseForApp(PARAMS(CSteamID steamID, AppId_t dlcID)) {
AppId_t app_id = 0;
VIRTUAL(EUserHasLicenseForAppResult) ISteamUser_UserHasLicenseForApp(PARAMS(CSteamID steamID, AppId_t dlc_id)) {
try {
app_id = steam_impl::get_app_id_or_throw();
} catch (const Exception& e) {
LOG_ERROR("{} -> Error getting app id: {}", __func__, e.what())
}
static const auto app_id = steam_impl::get_app_id_or_throw();
return steam_user::UserHasLicenseForApp(
__func__, app_id, dlcID, [&]() {
__func__, app_id, dlc_id, [&]() {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamUser_UserHasLicenseForApp)
return ISteamUser_UserHasLicenseForApp_o(ARGS(steamID, dlcID));
return ISteamUser_UserHasLicenseForApp_o(ARGS(steamID, dlc_id));
}
);
} catch (const Exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what())
return k_EUserHasLicenseResultDoesNotHaveLicense;
}
}

View File

@@ -25,21 +25,14 @@ namespace steam_apps {
* @return boolean indicating if the function was able to successfully fetch DLC IDs from all sources.
*/
void fetch_and_cache_dlcs(AppId_t app_id) {
static std::mutex mutex;
const std::lock_guard<std::mutex> guard(mutex);
static Mutex mutex;
const MutexLockGuard guard(mutex);
if (not app_id) {
// No app id means we are operating in game mode.
// Hence, we need to use utility functions to get app id.
try {
app_id = steam_impl::get_app_id_or_throw();
LOG_INFO("Detected App ID: {}", app_id)
} catch (const Exception& ex) {
LOG_ERROR("Failed to get app ID: {}", ex.what())
if (app_id == 0) {
LOG_ERROR("{} -> App ID is 0", __func__)
app_dlcs[app_id] = {}; // Dummy value to avoid checking for presence on each access
return;
}
}
// We want to fetch data only once. However, if any of the remote sources have failed
// previously, we want to attempt fetching again.
@@ -75,7 +68,6 @@ namespace steam_apps {
}
// Cache DLCs in memory and cache for future use
app_dlcs[app_id] = aggregated_dlcs;
smoke_api::app_cache::save_dlcs(app_id, aggregated_dlcs);

View File

@@ -18,8 +18,8 @@ namespace steam_apps {
);
bool GetDLCDataByIndex(
const String& dlc_id,
AppId_t dlc_ids,
const String& function_name,
AppId_t app_id,
int iDLC,
AppId_t* pDlcId,
bool* pbAvailable,

View File

@@ -2,6 +2,7 @@
#include <steam_impl/steam_apps.hpp>
VIRTUAL(bool) IClientAppManager_IsAppDlcInstalled(PARAMS(AppId_t app_id, AppId_t dlc_id)) {
try {
return steam_apps::IsDlcUnlocked(
__func__, app_id, dlc_id, [&]() {
GET_ORIGINAL_HOOKED_FUNCTION(IClientAppManager_IsAppDlcInstalled)
@@ -9,4 +10,8 @@ VIRTUAL(bool) IClientAppManager_IsAppDlcInstalled(PARAMS(AppId_t app_id, AppId_t
return IClientAppManager_IsAppDlcInstalled_o(ARGS(app_id, dlc_id));
}
);
} catch (const Exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what())
return false;
}
}

View File

@@ -2,6 +2,7 @@
#include <steam_impl/steam_apps.hpp>
VIRTUAL(int) IClientApps_GetDLCCount(PARAMS(AppId_t appId)) {
try {
return steam_apps::GetDLCCount(
__func__, appId, [&]() {
GET_ORIGINAL_HOOKED_FUNCTION(IClientApps_GetDLCCount)
@@ -9,6 +10,10 @@ VIRTUAL(int) IClientApps_GetDLCCount(PARAMS(AppId_t appId)) {
return IClientApps_GetDLCCount_o(ARGS(appId));
}
);
} catch (const Exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what())
return 0;
}
}
VIRTUAL(bool) IClientApps_BGetDLCDataByIndex(
@@ -21,6 +26,7 @@ VIRTUAL(bool) IClientApps_BGetDLCDataByIndex(
int cchNameBufferSize
)
) {
try {
return steam_apps::GetDLCDataByIndex(
__func__, appID, iDLC, pDlcID, pbAvailable, pchName, cchNameBufferSize,
[&]() {
@@ -41,4 +47,8 @@ VIRTUAL(bool) IClientApps_BGetDLCDataByIndex(
return false;
}
);
} catch (const Exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what())
return false;
}
}

View File

@@ -2,6 +2,7 @@
#include <steam_impl/steam_apps.hpp>
VIRTUAL(bool) IClientUser_BIsSubscribedApp(PARAMS(AppId_t dlc_id)) {
try {
const auto* utils_interface = store::steamclient::interface_name_to_address_map["IClientUtils"];
const auto app_id = utils_interface ? IClientUtils_GetAppID(utils_interface, EDX) : 0;
@@ -11,4 +12,8 @@ VIRTUAL(bool) IClientUser_BIsSubscribedApp(PARAMS(AppId_t dlc_id)) {
return IClientUser_BIsSubscribedApp_o(ARGS(dlc_id));
});
} catch (const Exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what())
return false;
}
}