Skip to content

Commit

Permalink
Fixed critical bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
acidicoala committed Jan 31, 2023
1 parent 95ceac3 commit 73a05f1
Show file tree
Hide file tree
Showing 10 changed files with 258 additions and 176 deletions.
2 changes: 1 addition & 1 deletion 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.0)
project(SmokeAPI VERSION 2.0.2)

include(KoalaBox/cmake/KoalaBox.cmake)

Expand Down
129 changes: 78 additions & 51 deletions src/game_mode/exports/steam_api_flat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,51 @@
// ISteamApps

DLL_EXPORT(bool) SteamAPI_ISteamApps_BIsSubscribedApp(void* self, AppId_t dlcID) {
return steam_apps::IsDlcUnlocked(
__func__, 0, dlcID, [&]() {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamApps_BIsSubscribedApp)

return SteamAPI_ISteamApps_BIsSubscribedApp_o(self, dlcID);
}
);
try {
static const auto app_id = steam_impl::get_app_id_or_throw();
return steam_apps::IsDlcUnlocked(
__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) {
return steam_apps::IsDlcUnlocked(
__func__, 0, dlcID, [&]() {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamApps_BIsDlcInstalled)

return SteamAPI_ISteamApps_BIsDlcInstalled_o(self, dlcID);
}
);
try {
static const auto app_id = steam_impl::get_app_id_or_throw();
return steam_apps::IsDlcUnlocked(
__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) {
return steam_apps::GetDLCCount(
__func__, 0, [&]() {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamApps_GetDLCCount)

return SteamAPI_ISteamApps_GetDLCCount_o(self);
}
);
try {
static const auto app_id = steam_impl::get_app_id_or_throw();
return steam_apps::GetDLCCount(
__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(
Expand All @@ -45,19 +63,24 @@ DLL_EXPORT(bool) SteamAPI_ISteamApps_BGetDLCDataByIndex(
char* pchName,
int cchNameBufferSize
) {
return steam_apps::GetDLCDataByIndex(
__func__, 0, iDLC, pDlcID, pbAvailable, pchName, cchNameBufferSize,
[&]() {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamApps_BGetDLCDataByIndex)

return SteamAPI_ISteamApps_BGetDLCDataByIndex_o(
self, iDLC, pDlcID, pbAvailable, pchName, cchNameBufferSize
);
},
[&](AppId_t dlc_id) {
return SteamAPI_ISteamApps_BIsDlcInstalled(self, dlc_id);
}
);
try {
static const auto app_id = steam_impl::get_app_id_or_throw();
return steam_apps::GetDLCDataByIndex(
__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
);
},
[&](AppId_t dlc_id) {
return SteamAPI_ISteamApps_BIsDlcInstalled(self, dlc_id);
}
);
} catch (const Exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what())
return false;
}
}

// ISteamClient
Expand All @@ -68,13 +91,17 @@ DLL_EXPORT(void*) SteamAPI_ISteamClient_GetISteamGenericInterface(
HSteamPipe hSteamPipe,
const char* pchVersion
) {
return steam_client::GetGenericInterface(
__func__, pchVersion, [&]() {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamClient_GetISteamGenericInterface)

return SteamAPI_ISteamClient_GetISteamGenericInterface_o(self, hSteamUser, hSteamPipe, 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
Expand Down Expand Up @@ -210,18 +237,18 @@ 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();
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)

return SteamAPI_ISteamUser_UserHasLicenseForApp_o(self, steamID, dlcID);
}
);
} catch (const Exception& e) {
LOG_ERROR("{} -> Error getting app id: {}", __func__, e.what())
LOG_ERROR("{} -> Error: {}", __func__, e.what())
return k_EUserHasLicenseResultDoesNotHaveLicense;
}

return steam_user::UserHasLicenseForApp(
__func__, app_id, dlcID, [&]() {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamUser_UserHasLicenseForApp)

return SteamAPI_ISteamUser_UserHasLicenseForApp_o(self, steamID, dlcID);
}
);
}
93 changes: 59 additions & 34 deletions src/game_mode/virtuals/isteamapps.cpp
Original file line number Diff line number Diff line change
@@ -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)) {
return steam_apps::IsDlcUnlocked(
__func__, 0, appID, [&]() {
GET_ORIGINAL_FUNCTION_STEAMAPI(ISteamApps_BIsSubscribedApp)
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__, 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 ISteamApps_BIsSubscribedApp_o(ARGS(appID));
}
);
return false;
}
}

VIRTUAL(bool) ISteamApps_BIsDlcInstalled(PARAMS(AppId_t appID)) {
return steam_apps::IsDlcUnlocked(
__func__, 0, appID, [&]() {
GET_ORIGINAL_FUNCTION_STEAMAPI(ISteamApps_BIsDlcInstalled)
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__, 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 ISteamApps_BIsDlcInstalled_o(ARGS(appID));
}
);
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__, app_id, [&]() {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamApps_GetDLCCount)
return ISteamApps_GetDLCCount_o(ARGS());
}
);
} catch (const Exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what())

return steam_apps::GetDLCCount(
__func__, 0, [&]() {
return ISteamApps_GetDLCCount_o(ARGS());
}
);
return 0;
}
}

VIRTUAL(bool) ISteamApps_BGetDLCDataByIndex(
PARAMS(
int iDLC,
AppId_t* pAppID,
AppId_t* p_dlc_id,
bool* pbAvailable,
char* pchName,
int cchNameBufferSize
)
) {
return steam_apps::GetDLCDataByIndex(
__func__, 0, iDLC, pAppID, pbAvailable, pchName, cchNameBufferSize,
[&]() {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamApps_BGetDLCDataByIndex)

return ISteamApps_BGetDLCDataByIndex_o(
ARGS(iDLC, pAppID, pbAvailable, pchName, cchNameBufferSize)
);
},
[&](AppId_t dlc_id) {
return ISteamApps_BIsDlcInstalled(ARGS(dlc_id));
}
);
try {
static const auto app_id = steam_impl::get_app_id_or_throw();
return steam_apps::GetDLCDataByIndex(
__func__, app_id, iDLC, p_dlc_id, pbAvailable, pchName, cchNameBufferSize,
[&]() {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamApps_BGetDLCDataByIndex)
return ISteamApps_BGetDLCDataByIndex_o(
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;
}
}
69 changes: 44 additions & 25 deletions src/game_mode/virtuals/isteamclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ VIRTUAL(void*) ISteamClient_GetISteamApps(
const char* version
)
) {
return steam_client::GetGenericInterface(
__func__, version, [&]() {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamClient_GetISteamApps)

return ISteamClient_GetISteamApps_o(ARGS(hSteamUser, hSteamPipe, 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(
Expand All @@ -24,13 +28,18 @@ VIRTUAL(void*) ISteamClient_GetISteamUser(
const char* version
)
) {
return steam_client::GetGenericInterface(
__func__, version, [&]() {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamClient_GetISteamUser)
try {
return steam_client::GetGenericInterface(
__func__, version, [&]() {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamClient_GetISteamUser)

return ISteamClient_GetISteamUser_o(ARGS(hSteamUser, hSteamPipe, version));
}
);
return ISteamClient_GetISteamUser_o(ARGS(hSteamUser, hSteamPipe, version));
}
);
} catch (const Exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what())
return nullptr;
}
}

VIRTUAL(void*) ISteamClient_GetISteamGenericInterface(
Expand All @@ -40,13 +49,18 @@ VIRTUAL(void*) ISteamClient_GetISteamGenericInterface(
const char* pchVersion
)
) {
return steam_client::GetGenericInterface(
__func__, pchVersion, [&]() {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamClient_GetISteamGenericInterface)
try {
return steam_client::GetGenericInterface(
__func__, pchVersion, [&]() {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamClient_GetISteamGenericInterface)

return ISteamClient_GetISteamGenericInterface_o(ARGS(hSteamUser, hSteamPipe, pchVersion));
}
);
return ISteamClient_GetISteamGenericInterface_o(ARGS(hSteamUser, hSteamPipe, pchVersion));
}
);
} catch (const Exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what())
return nullptr;
}
}

VIRTUAL(void*) ISteamClient_GetISteamInventory(
Expand All @@ -56,11 +70,16 @@ VIRTUAL(void*) ISteamClient_GetISteamInventory(
const char* pchVersion
)
) {
return steam_client::GetGenericInterface(
__func__, pchVersion, [&]() {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamClient_GetISteamInventory)
try {
return steam_client::GetGenericInterface(
__func__, pchVersion, [&]() {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamClient_GetISteamInventory)

return ISteamClient_GetISteamInventory_o(ARGS(hSteamUser, hSteamPipe, pchVersion));
}
);
return ISteamClient_GetISteamInventory_o(ARGS(hSteamUser, hSteamPipe, pchVersion));
}
);
} catch (const Exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what())
return nullptr;
}
}
Loading

0 comments on commit 73a05f1

Please sign in to comment.