Reformat project

This commit is contained in:
acidicoala
2025-08-22 22:01:54 +05:00
parent 28650491b2
commit 29b1f66095
47 changed files with 1085 additions and 781 deletions

View File

@@ -1,22 +0,0 @@
---
Language: Cpp
BasedOnStyle: LLVM
Standard: c++20
BreakBeforeBraces: Attach
LineEnding: LF
ColumnLimit: 100
AlignAfterOpenBracket: BlockIndent
IndentWidth: 4
ContinuationIndentWidth: 4
NamespaceIndentation: All
UseTab: Never
PointerAlignment: Left
SortIncludes: true
AllowShortFunctionsOnASingleLine: Empty
FixNamespaceComments: false
ExperimentalAutoDetectBinPacking: false
BinPackParameters: OnePerLine
AllowAllParametersOfDeclarationOnNextLine: true
BinPackArguments: false
AllowAllArgumentsOnNextLine: true

View File

@@ -1,5 +1,6 @@
<component name="ProjectCodeStyleConfiguration"> <component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173"> <code_scheme name="Project" version="173">
<option name="AUTODETECT_INDENTS" value="false" />
<Markdown> <Markdown>
<option name="MAX_LINES_AROUND_HEADER" value="0" /> <option name="MAX_LINES_AROUND_HEADER" value="0" />
<option name="MAX_LINES_AROUND_BLOCK_ELEMENTS" value="0" /> <option name="MAX_LINES_AROUND_BLOCK_ELEMENTS" value="0" />
@@ -17,19 +18,72 @@
<option name="SPACE_BETWEEN_ADJACENT_BRACKETS" value="true" /> <option name="SPACE_BETWEEN_ADJACENT_BRACKETS" value="true" />
</Objective-C> </Objective-C>
<RiderCodeStyleSettings> <RiderCodeStyleSettings>
<option name="/Default/CodeStyle/CodeFormatting/CppClangFormat/EnableClangFormatSupport/@EntryValue" value="true" type="bool" /> <option name="/Default/CodeStyle/CodeFormatting/CppClangFormat/EnableClangFormatSupport/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/EditorConfig/EnableClangFormatSupport/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CppIncludeDirective/SortIncludeDirectives/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CppPreferForwardDeclaration/PreferForwardDeclarations/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CppIncludeDirective/UseRelativePaths/@EntryValue" value="Never" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppCodeStyle/CVQualifiersOrder/@EntryValue" value="VolatileConst" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppCodeStyle/SortDefinitions/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppCodeStyle/BracesInIfStatement/@EntryValue" value="Required" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppCodeStyle/BracesInForStatement/@EntryValue" value="Required" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppCodeStyle/BracesInWhileStatement/@EntryValue" value="Required" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/NAMESPACE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/EXPORT_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TYPE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INVOCABLE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ANONYMOUS_METHOD_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/CASE_BLOCK_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/REQUIRES_EXPRESSION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/OTHER_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/EMPTY_BLOCK_STYLE/@EntryValue" value="TOGETHER" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALLOW_COMMENT_AFTER_LBRACE/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_BLANK_LINES_IN_DECLARATIONS/@EntryValue" value="1" type="long" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_BLANK_LINES_IN_CODE/@EntryValue" value="1" type="long" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_ELSE_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_WHILE_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_CATCH_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SIMPLE_EMBEDDED_STATEMENT_STYLE/@EntryValue" value="LINE_BREAK" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/FUNCTION_DEFINITION_RETURN_TYPE_STYLE/@EntryValue" value="ON_SINGLE_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TOPLEVEL_FUNCTION_DEFINITION_RETURN_TYPE_STYLE/@EntryValue" value="ON_SINGLE_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/FUNCTION_DECLARATION_RETURN_TYPE_STYLE/@EntryValue" value="ON_SINGLE_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TOPLEVEL_FUNCTION_DECLARATION_RETURN_TYPE_STYLE/@EntryValue" value="ON_SINGLE_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/MEMBER_INITIALIZER_LIST_STYLE/@EntryValue" value="ON_SINGLE_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/LINE_BREAK_AFTER_COLON_IN_MEMBER_INITIALIZER_LISTS/@EntryValue" value="ON_SINGLE_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/LINE_BREAK_BEFORE_DEREF_IN_TRAILING_RETURN_TYPES/@EntryValue" value="ON_SINGLE_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/LINE_BREAK_AFTER_DEREF_IN_TRAILING_RETURN_TYPES/@EntryValue" value="ON_SINGLE_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/LINE_BREAK_BEFORE_FUNCTION_TRY_BLOCK/@EntryValue" value="LINE_BREAK" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/LINE_BREAK_AFTER_COMMA_IN_MEMBER_INITIALIZER_LISTS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_USER_LINEBREAKS/@EntryValue" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_LIMIT/@EntryValue" value="100" type="long" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BRACED_INIT_LIST_STYLE/@EntryValue" value="CHOP_IF_LONG" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BASE_CLAUSE_STYLE/@EntryValue" value="CHOP_IF_LONG" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_CTOR_INITIALIZER_STYLE/@EntryValue" value="CHOP_IF_LONG" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_PARAMETERS_STYLE/@EntryValue" value="CHOP_IF_LONG" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_DECLARATION_LPAR/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_DECLARATION_RPAR/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_ARGUMENTS_STYLE/@EntryValue" value="CHOP_IF_LONG" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_INVOCATION_LPAR/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_INVOCATION_RPAR/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_STATEMENT_PARENTHESES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_CAST_EXPRESSION_PARENTHESES/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/USE_CONTINUOUS_LINE_INDENT_IN_EXPRESSION_BRACES/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/LINKAGE_SPECIFICATION_INDENTATION/@EntryValue" value="All" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_EXPRESSION_BRACES/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/OUTDENT_COMMAS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_BINARY_EXPRESSIONS_CHAIN/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INT_ALIGN_ENUM_INITIALIZERS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INT_ALIGN_BITFIELD_SIZES/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SIMPLE_BLOCK_STYLE/@EntryValue" />
</RiderCodeStyleSettings> </RiderCodeStyleSettings>
<clangFormatSettings>
<option name="ENABLED" value="true" />
</clangFormatSettings>
<editorconfig> <editorconfig>
<option name="ENABLED" value="false" /> <option name="ENABLED" value="false" />
</editorconfig> </editorconfig>
<files> <files>
<extensions> <extensions>
<pair source="cpp" header="hpp" fileNamingConvention="SNAKE_CASE" /> <pair source="cpp" header="hpp" fileNamingConvention="SNAKE_CASE" />
<pair source="c" header="h" fileNamingConvention="NONE" /> <pair source="c" header="h" fileNamingConvention="SNAKE_CASE" />
<pair source="cu" header="cuh" fileNamingConvention="NONE" />
</extensions> </extensions>
</files> </files>
<codeStyleSettings language="CMake"> <codeStyleSettings language="CMake">

View File

@@ -2,13 +2,19 @@
<dictionary name="project"> <dictionary name="project">
<words> <words>
<w>abcdefghijklmnopqrstuvwxyz</w> <w>abcdefghijklmnopqrstuvwxyz</w>
<w>acidicoala</w>
<w>ajaxgetdlclist</w>
<w>indicies</w> <w>indicies</w>
<w>inlinentd</w>
<w>isteamapps</w> <w>isteamapps</w>
<w>isteamclient</w> <w>isteamclient</w>
<w>isteaminventory</w> <w>isteaminventory</w>
<w>isteamuser</w> <w>isteamuser</w>
<w>koalabox</w> <w>koalabox</w>
<w>koality</w>
<w>koaloader</w> <w>koaloader</w>
<w>polyhook</w>
<w>simplecpp</w>
<w>steamapps</w> <w>steamapps</w>
<w>wstr</w> <w>wstr</w>
</words> </words>

View File

@@ -72,6 +72,8 @@ add_library(SmokeAPI SHARED ${SMOKE_API_SOURCES} ${VERSION_RESOURCE})
# but manually setting the MSVC compiler option fixes this issue. # but manually setting the MSVC compiler option fixes this issue.
target_compile_options(SmokeAPI PRIVATE /std:c++latest) target_compile_options(SmokeAPI PRIVATE /std:c++latest)
target_include_directories(SmokeAPI PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>")
configure_linker_exports( configure_linker_exports(
TARGET SmokeAPI TARGET SmokeAPI
HEADER_NAME "linker_exports_for_steam_api" HEADER_NAME "linker_exports_for_steam_api"
@@ -93,7 +95,6 @@ configure_output_name(${STEAMAPI_DLL})
configure_include_directories() configure_include_directories()
target_link_libraries(SmokeAPI PRIVATE KoalaBox) target_link_libraries(SmokeAPI PRIVATE KoalaBox)
target_precompile_headers(SmokeAPI REUSE_FROM KoalaBox)
set(B_PRODUCTION_MODE ON) set(B_PRODUCTION_MODE ON)
CPMAddPackage("gh:batterycenter/embed@1.2.19") CPMAddPackage("gh:batterycenter/embed@1.2.19")

View File

@@ -262,7 +262,7 @@ config::: `Debug` or `Release`
For example: For example:
---- ----
.\build.ps1 32 Debug .\build.ps1 64 Release
---- ----
== 📚 Open-Source libraries == 📚 Open-Source libraries

View File

@@ -1 +0,0 @@
This directory contains dummy headers used by the `simplecpp` preprocessor

View File

View File

View File

View File

View File

@@ -5,8 +5,12 @@
#include "smoke_api/globals.hpp" #include "smoke_api/globals.hpp"
// TODO: Detour in hook mode // TODO: Detour in hook mode
DLL_EXPORT(bool) SteamAPI_RestartAppIfNecessary(const uint32_t unOwnAppID) { DLL_EXPORT(bool) SteamAPI_RestartAppIfNecessary
if (smoke_api::config::instance.override_app_id != 0) { (
const uint32_t unOwnAppID
)
{
if(smoke_api::config::instance.override_app_id != 0) {
LOG_DEBUG("{} -> {}. Preventing app restart", unOwnAppID, __func__); LOG_DEBUG("{} -> {}. Preventing app restart", unOwnAppID, __func__);
return false; return false;
} }
@@ -14,7 +18,10 @@ DLL_EXPORT(bool) SteamAPI_RestartAppIfNecessary(const uint32_t unOwnAppID) {
return ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_RestartAppIfNecessary)(unOwnAppID); return ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_RestartAppIfNecessary)(unOwnAppID);
} }
DLL_EXPORT(void) SteamAPI_Shutdown() { DLL_EXPORT(void) SteamAPI_Shutdown
(
)
{
LOG_INFO("{} -> Game requested shutdown", __func__); LOG_INFO("{} -> Game requested shutdown", __func__);
ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_Shutdown)(); ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_Shutdown)();

View File

@@ -11,77 +11,115 @@
// ISteamApps // ISteamApps
DLL_EXPORT(bool) SteamAPI_ISteamApps_BIsSubscribedApp(void* self, AppId_t dlcID) { DLL_EXPORT(bool) SteamAPI_ISteamApps_BIsSubscribedApp
(
void *self, AppId_t dlcID
)
{
try { try {
static const auto app_id = steam_interface::get_app_id(); static const auto app_id = steam_interface::get_app_id();
return steam_apps::IsDlcUnlocked( return steam_apps::IsDlcUnlocked(
__func__, app_id, dlcID, [&] { __func__,
app_id,
dlcID,
[&] {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamApps_BIsSubscribedApp) GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamApps_BIsSubscribedApp)
return SteamAPI_ISteamApps_BIsSubscribedApp_o(self, dlcID); return SteamAPI_ISteamApps_BIsSubscribedApp_o(self, dlcID);
} }
); );
} catch (const std::exception& e) { } catch(const std::exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what()); LOG_ERROR("{} -> Error: {}", __func__, e.what());
return false; return false;
} }
} }
DLL_EXPORT(bool) SteamAPI_ISteamApps_BIsDlcInstalled(void* self, AppId_t dlcID) { DLL_EXPORT(bool) SteamAPI_ISteamApps_BIsDlcInstalled
(
void *self, AppId_t dlcID
)
{
try { try {
static const auto app_id = steam_interface::get_app_id(); static const auto app_id = steam_interface::get_app_id();
return steam_apps::IsDlcUnlocked( return steam_apps::IsDlcUnlocked(
__func__, app_id, dlcID, [&] { __func__,
app_id,
dlcID,
[&] {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamApps_BIsDlcInstalled) GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamApps_BIsDlcInstalled)
return SteamAPI_ISteamApps_BIsDlcInstalled_o(self, dlcID); return SteamAPI_ISteamApps_BIsDlcInstalled_o(self, dlcID);
} }
); );
} catch (const std::exception& e) { } catch(const std::exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what()); LOG_ERROR("{} -> Error: {}", __func__, e.what());
return false; return false;
} }
} }
DLL_EXPORT(int) SteamAPI_ISteamApps_GetDLCCount(void* self) { DLL_EXPORT(int) SteamAPI_ISteamApps_GetDLCCount
(
void* self
)
{
try { try {
static const auto app_id = steam_interface::get_app_id(); static const auto app_id = steam_interface::get_app_id();
return steam_apps::GetDLCCount( return steam_apps::GetDLCCount(
__func__, app_id, [&] { __func__,
app_id,
[&] {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamApps_GetDLCCount) GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamApps_GetDLCCount)
return SteamAPI_ISteamApps_GetDLCCount_o(self); return SteamAPI_ISteamApps_GetDLCCount_o(self);
} }
); );
} catch (const std::exception& e) { } catch(const std::exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what()); LOG_ERROR("{} -> Error: {}", __func__, e.what());
return 0; return 0;
} }
} }
DLL_EXPORT(bool) SteamAPI_ISteamApps_BGetDLCDataByIndex( DLL_EXPORT(bool) SteamAPI_ISteamApps_BGetDLCDataByIndex
void* self, (
int iDLC,
AppId_t* pDlcID, void *self,
bool* pbAvailable,
char* pchName, int iDLC,
int cchNameBufferSize AppId_t*pDlcID,
) {
bool *pbAvailable,
char *pchName,
int cchNameBufferSize
)
{
try { try {
static const auto app_id = steam_interface::get_app_id(); static const auto app_id = steam_interface::get_app_id();
return steam_apps::GetDLCDataByIndex( return steam_apps::GetDLCDataByIndex(
__func__, app_id, iDLC, pDlcID, pbAvailable, pchName, cchNameBufferSize, __func__,
app_id,
iDLC,
pDlcID,
pbAvailable,
pchName,
cchNameBufferSize,
[&] { [&] {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamApps_BGetDLCDataByIndex) GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamApps_BGetDLCDataByIndex)
return SteamAPI_ISteamApps_BGetDLCDataByIndex_o( return SteamAPI_ISteamApps_BGetDLCDataByIndex_o(
self, iDLC, pDlcID, pbAvailable, pchName, cchNameBufferSize self,
iDLC,
pDlcID,
pbAvailable,
pchName,
cchNameBufferSize
); );
}, },
[&](AppId_t dlc_id) { [&](AppId_t dlc_id) {
return SteamAPI_ISteamApps_BIsDlcInstalled(self, dlc_id); return SteamAPI_ISteamApps_BIsDlcInstalled(self, dlc_id);
} }
); );
} catch (const std::exception& e) { } catch(const std::exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what()); LOG_ERROR("{} -> Error: {}", __func__, e.what());
return false; return false;
} }
@@ -89,20 +127,31 @@ DLL_EXPORT(bool) SteamAPI_ISteamApps_BGetDLCDataByIndex(
// ISteamClient // ISteamClient
DLL_EXPORT(void*) SteamAPI_ISteamClient_GetISteamGenericInterface( DLL_EXPORT(void*) SteamAPI_ISteamClient_GetISteamGenericInterface
void* self, (
void *self,
HSteamUser hSteamUser, HSteamUser hSteamUser,
HSteamPipe hSteamPipe, HSteamPipe hSteamPipe,
const char* pchVersion
) { const char* pchVersion
)
{
try { try {
return steam_client::GetGenericInterface( return steam_client::GetGenericInterface(
__func__, pchVersion, [&] { __func__,
pchVersion,
[&] {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamClient_GetISteamGenericInterface) GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamClient_GetISteamGenericInterface)
return SteamAPI_ISteamClient_GetISteamGenericInterface_o(self, hSteamUser, hSteamPipe, pchVersion); return SteamAPI_ISteamClient_GetISteamGenericInterface_o(
self,
hSteamUser,
hSteamPipe,
pchVersion
);
} }
); );
} catch (const std::exception& e) { } catch(const std::exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what()); LOG_ERROR("{} -> Error: {}", __func__, e.what());
return nullptr; return nullptr;
} }
@@ -110,12 +159,14 @@ DLL_EXPORT(void*) SteamAPI_ISteamClient_GetISteamGenericInterface(
// ISteamInventory // ISteamInventory
DLL_EXPORT(EResult) SteamAPI_ISteamInventory_GetResultStatus( DLL_EXPORT (EResult) SteamAPI_ISteamInventory_GetResultStatus(
void* self, void* self,
SteamInventoryResult_t resultHandle SteamInventoryResult_t resultHandle
) { ) {
return steam_inventory::GetResultStatus( return steam_inventory::GetResultStatus(
__func__, resultHandle, [&] { __func__,
resultHandle,
[&] {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamInventory_GetResultStatus) GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamInventory_GetResultStatus)
return SteamAPI_ISteamInventory_GetResultStatus_o(self, resultHandle); return SteamAPI_ISteamInventory_GetResultStatus_o(self, resultHandle);
@@ -123,80 +174,138 @@ DLL_EXPORT(EResult) SteamAPI_ISteamInventory_GetResultStatus(
); );
} }
DLL_EXPORT(bool) SteamAPI_ISteamInventory_GetItemDefinitionIDs( DLL_EXPORT(bool) SteamAPI_ISteamInventory_GetItemDefinitionIDs
void* self, (
SteamItemDef_t* pItemDefIDs,
uint32_t* punItemDefIDsArraySize
) { void *self,
SteamItemDef_t*pItemDefIDs,
uint32_t*punItemDefIDsArraySize
)
{
return steam_inventory::GetItemDefinitionIDs( return steam_inventory::GetItemDefinitionIDs(
__func__, pItemDefIDs, punItemDefIDsArraySize, [&] { __func__,
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamInventory_GetItemDefinitionIDs) pItemDefIDs,
punItemDefIDsArraySize,
return SteamAPI_ISteamInventory_GetItemDefinitionIDs_o(self, pItemDefIDs, punItemDefIDsArraySize);
}
);
}
DLL_EXPORT(bool) SteamAPI_ISteamInventory_GetResultItems(
void* self,
SteamInventoryResult_t resultHandle,
SteamItemDetails_t* pOutItemsArray,
uint32_t* punOutItemsArraySize
) {
return steam_inventory::GetResultItems(
__func__, resultHandle, pOutItemsArray, punOutItemsArraySize,
[&] { [&] {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamInventory_GetResultItems)
return SteamAPI_ISteamInventory_GetResultItems_o(self, resultHandle, pOutItemsArray, punOutItemsArraySize);
},
[&](SteamItemDef_t* pItemDefIDs, uint32_t* punItemDefIDsArraySize) {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamInventory_GetItemDefinitionIDs) GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamInventory_GetItemDefinitionIDs)
return SteamAPI_ISteamInventory_GetItemDefinitionIDs_o(self, pItemDefIDs, punItemDefIDsArraySize); return SteamAPI_ISteamInventory_GetItemDefinitionIDs_o(
} self,
); pItemDefIDs,
} punItemDefIDsArraySize
DLL_EXPORT(bool) SteamAPI_ISteamInventory_GetResultItemProperty(
void* self,
SteamInventoryResult_t resultHandle,
uint32_t unItemIndex,
const char* pchPropertyName,
char* pchValueBuffer,
uint32_t* punValueBufferSizeOut
) {
return steam_inventory::GetResultItemProperty(
__func__, resultHandle, unItemIndex, pchPropertyName, pchValueBuffer, punValueBufferSizeOut, [&] {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamInventory_GetResultItemProperty)
return SteamAPI_ISteamInventory_GetResultItemProperty_o(
self, resultHandle, unItemIndex, pchPropertyName, pchValueBuffer, punValueBufferSizeOut
); );
} }
); );
} }
DLL_EXPORT(bool) SteamAPI_ISteamInventory_CheckResultSteamID( DLL_EXPORT(bool) SteamAPI_ISteamInventory_GetResultItems
void* self, (
SteamInventoryResult_t resultHandle,
CSteamID steamIDExpected
) {
return steam_inventory::CheckResultSteamID(
__func__, resultHandle, steamIDExpected, [&] {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamInventory_CheckResultSteamID)
return SteamAPI_ISteamInventory_CheckResultSteamID_o(self, resultHandle, steamIDExpected);
void *self,
SteamInventoryResult_t resultHandle,
SteamItemDetails_t*pOutItemsArray,
uint32_t*punOutItemsArraySize
)
{
return steam_inventory::GetResultItems(
__func__,
resultHandle,
pOutItemsArray,
punOutItemsArraySize,
[&] {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamInventory_GetResultItems)
return SteamAPI_ISteamInventory_GetResultItems_o(
self,
resultHandle,
pOutItemsArray,
punOutItemsArraySize
);
},
[&](SteamItemDef_t* pItemDefIDs, uint32_t* punItemDefIDsArraySize) {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamInventory_GetItemDefinitionIDs)
return SteamAPI_ISteamInventory_GetItemDefinitionIDs_o(
self,
pItemDefIDs,
punItemDefIDsArraySize
);
} }
); );
} }
DLL_EXPORT(bool) SteamAPI_ISteamInventory_GetAllItems( DLL_EXPORT(bool) SteamAPI_ISteamInventory_GetResultItemProperty
void* self, (
SteamInventoryResult_t* pResultHandle
) { void *self,
SteamInventoryResult_t resultHandle,
uint32_t unItemIndex,
const char *pchPropertyName,
char *pchValueBuffer,
uint32_t*punValueBufferSizeOut
)
{
return steam_inventory::GetResultItemProperty(
__func__,
resultHandle,
unItemIndex,
pchPropertyName,
pchValueBuffer,
punValueBufferSizeOut,
[&] {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamInventory_GetResultItemProperty)
return SteamAPI_ISteamInventory_GetResultItemProperty_o(
self,
resultHandle,
unItemIndex,
pchPropertyName,
pchValueBuffer,
punValueBufferSizeOut
);
}
);
}
DLL_EXPORT(bool) SteamAPI_ISteamInventory_CheckResultSteamID
(
void *self,
SteamInventoryResult_t resultHandle,
CSteamID steamIDExpected
)
{
return steam_inventory::CheckResultSteamID(
__func__,
resultHandle,
steamIDExpected,
[&] {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamInventory_CheckResultSteamID)
return SteamAPI_ISteamInventory_CheckResultSteamID_o(
self,
resultHandle,
steamIDExpected
);
}
);
}
DLL_EXPORT(bool) SteamAPI_ISteamInventory_GetAllItems
(
void *self,
SteamInventoryResult_t*pResultHandle
)
{
return steam_inventory::GetAllItems( return steam_inventory::GetAllItems(
__func__, pResultHandle, [&] { __func__,
pResultHandle,
[&] {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamInventory_GetAllItems) GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamInventory_GetAllItems)
return SteamAPI_ISteamInventory_GetAllItems_o(self, pResultHandle); return SteamAPI_ISteamInventory_GetAllItems_o(self, pResultHandle);
@@ -204,55 +313,83 @@ DLL_EXPORT(bool) SteamAPI_ISteamInventory_GetAllItems(
); );
} }
DLL_EXPORT(bool) SteamAPI_ISteamInventory_GetItemsByID( DLL_EXPORT(bool) SteamAPI_ISteamInventory_GetItemsByID
void* self, (
SteamInventoryResult_t* pResultHandle,
const SteamItemInstanceID_t* pInstanceIDs, void *self,
SteamInventoryResult_t*pResultHandle,
const SteamItemInstanceID_t *pInstanceIDs,
uint32_t unCountInstanceIDs uint32_t unCountInstanceIDs
) { )
{
return steam_inventory::GetItemsByID( return steam_inventory::GetItemsByID(
__func__, pResultHandle, pInstanceIDs, unCountInstanceIDs, [&] { __func__,
pResultHandle,
pInstanceIDs,
unCountInstanceIDs,
[&] {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamInventory_GetItemsByID) GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamInventory_GetItemsByID)
return SteamAPI_ISteamInventory_GetItemsByID_o(self, pResultHandle, pInstanceIDs, unCountInstanceIDs); return SteamAPI_ISteamInventory_GetItemsByID_o(
self,
pResultHandle,
pInstanceIDs,
unCountInstanceIDs
);
} }
); );
} }
DLL_EXPORT(bool) SteamAPI_ISteamInventory_SerializeResult( DLL_EXPORT(bool) SteamAPI_ISteamInventory_SerializeResult
void* self, (
void *self,
SteamInventoryResult_t resultHandle, SteamInventoryResult_t resultHandle,
void* pOutBuffer,
uint32_t* punOutBufferSize void *pOutBuffer,
) { uint32_t*punOutBufferSize
)
{
return steam_inventory::SerializeResult( return steam_inventory::SerializeResult(
__func__, resultHandle, pOutBuffer, punOutBufferSize, [&] { __func__,
resultHandle,
pOutBuffer,
punOutBufferSize,
[&] {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamInventory_SerializeResult) GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamInventory_SerializeResult)
return SteamAPI_ISteamInventory_SerializeResult_o(self, resultHandle, pOutBuffer, punOutBufferSize); return SteamAPI_ISteamInventory_SerializeResult_o(
self,
resultHandle,
pOutBuffer,
punOutBufferSize
);
} }
); );
} }
// ISteamUser // ISteamUser
DLL_EXPORT(EUserHasLicenseForAppResult) SteamAPI_ISteamUser_UserHasLicenseForApp( DLL_EXPORT (EUserHasLicenseForAppResult) SteamAPI_ISteamUser_UserHasLicenseForApp(
void* self, void* self,
CSteamID steamID, CSteamID steamID,
AppId_t dlcID AppId_t dlcID
) { ) {
try { try {
static const auto app_id = steam_interface::get_app_id(); static const auto app_id = steam_interface::get_app_id();
return steam_user::UserHasLicenseForApp( return steam_user::UserHasLicenseForApp(
__func__, app_id, dlcID, [&] { __func__,
app_id,
dlcID,
[&] {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamUser_UserHasLicenseForApp) GET_ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_ISteamUser_UserHasLicenseForApp)
return SteamAPI_ISteamUser_UserHasLicenseForApp_o(self, steamID, dlcID); return SteamAPI_ISteamUser_UserHasLicenseForApp_o(self, steamID, dlcID);
} }
); );
} catch (const std::exception& e) { } catch(const std::exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what()); LOG_ERROR("{} -> Error: {}", __func__, e.what());
return k_EUserHasLicenseResultDoesNotHaveLicense; return k_EUserHasLicenseResultDoesNotHaveLicense;
} }
}
}

View File

@@ -4,18 +4,37 @@
#include "smoke_api/types.hpp" #include "smoke_api/types.hpp"
#include "steam_interface/steam_client.hpp" #include "steam_interface/steam_client.hpp"
DLL_EXPORT(void*) SteamInternal_FindOrCreateUserInterface(HSteamUser hSteamUser, const char* version) { DLL_EXPORT(void*) SteamInternal_FindOrCreateUserInterface
return steam_client::GetGenericInterface(__func__, version, [&] { (
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamInternal_FindOrCreateUserInterface) HSteamUser hSteamUser
,
const char* version
)
{
return steam_client::GetGenericInterface(
__func__,
version,
[&] {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamInternal_FindOrCreateUserInterface)
return SteamInternal_FindOrCreateUserInterface_o(hSteamUser, version); return SteamInternal_FindOrCreateUserInterface_o(hSteamUser, version);
}); }
);
} }
DLL_EXPORT(void*) SteamInternal_CreateInterface(const char* version) { DLL_EXPORT(void*) SteamInternal_CreateInterface
return steam_client::GetGenericInterface(__func__, version, [&] { (
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamInternal_CreateInterface)
const char* version
)
{
return steam_client::GetGenericInterface(
__func__,
version,
[&] {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamInternal_CreateInterface)
return SteamInternal_CreateInterface_o(version); return SteamInternal_CreateInterface_o(version);
}); }
} );
}

View File

@@ -10,30 +10,35 @@
#include "steam_interface/steam_client.hpp" #include "steam_interface/steam_client.hpp"
namespace { namespace {
/** /**
* Searches the `.rdata` section of the original dll for the full interface version string * Searches the `.rdata` section of the original dll for the full interface version string
* Results are cached for performance. * Results are cached for performance.
*/ */
std::string std::string get_versioned_interface(
get_versioned_interface(const std::string& version_prefix, const std::string& fallback) { const std::string& version_prefix,
const std::string& fallback
) {
static std::map<std::string, std::string> version_map; static std::map<std::string, std::string> version_map;
if (not version_map.contains(version_prefix)) { if(not
version_map.contains(version_prefix)
)
{
try { try {
const std::string rdata = koalabox::win_util::get_pe_section_data_or_throw( const std::string rdata = koalabox::win_util::get_pe_section_data_or_throw(
globals::steamapi_module, ".rdata" globals::steamapi_module,
".rdata"
); );
const std::regex regex(version_prefix + "\\d{3}"); const std::regex regex(version_prefix + "\\d{3}");
std::smatch match; std::smatch match;
if (std::regex_search(rdata, match, regex)) { if(std::regex_search(rdata, match, regex)) {
version_map[version_prefix] = match[0]; version_map[version_prefix] = match[0];
return version_map[version_prefix]; return version_map[version_prefix];
} }
throw koalabox::util::exception("No match found for '{}'", version_prefix); throw koalabox::util::exception("No match found for '{}'", version_prefix);
} catch (const std::exception& ex) { } catch(const std::exception& ex) {
LOG_ERROR( LOG_ERROR(
"Failed to get versioned interface: {}." "Failed to get versioned interface: {}."
"Falling back to version {}", "Falling back to version {}",
@@ -49,42 +54,70 @@ namespace {
} }
} }
DLL_EXPORT(void*) SteamClient() { DLL_EXPORT(void*) SteamClient
(
)
{
static auto version = get_versioned_interface(STEAM_CLIENT, "006"); static auto version = get_versioned_interface(STEAM_CLIENT, "006");
return steam_client::GetGenericInterface(__func__, version, [&] { return steam_client::GetGenericInterface(
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamClient) __func__,
version,
[&] {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamClient)
return SteamClient_o(); return SteamClient_o();
}); }
);
} }
DLL_EXPORT(void*) SteamApps() { DLL_EXPORT(void*) SteamApps
(
)
{
static auto version = get_versioned_interface(STEAM_APPS, "002"); static auto version = get_versioned_interface(STEAM_APPS, "002");
return steam_client::GetGenericInterface(__func__, version, [&]() { return steam_client::GetGenericInterface(
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamApps) __func__,
version,
[&]() {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamApps)
return SteamApps_o(); return SteamApps_o();
}); }
);
} }
DLL_EXPORT(void*) SteamUser() { DLL_EXPORT(void*) SteamUser
(
)
{
static auto version = get_versioned_interface(STEAM_USER, "012"); static auto version = get_versioned_interface(STEAM_USER, "012");
return steam_client::GetGenericInterface(__func__, version, [&] { return steam_client::GetGenericInterface(
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamUser) __func__,
version,
[&] {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamUser)
return SteamUser_o(); return SteamUser_o();
}); }
);
} }
DLL_EXPORT(void*) SteamInventory() { DLL_EXPORT(void*) SteamInventory
(
)
{
static auto version = get_versioned_interface(STEAM_INVENTORY, "001"); static auto version = get_versioned_interface(STEAM_INVENTORY, "001");
return steam_client::GetGenericInterface(__func__, version, [&] { return steam_client::GetGenericInterface(
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamInventory) __func__,
version,
[&] {
GET_ORIGINAL_FUNCTION_STEAMAPI(SteamInventory)
return SteamInventory_o(); return SteamInventory_o();
}); }
} );
}

View File

@@ -5,9 +5,13 @@
#include "steam_interface/steam_client.hpp" #include "steam_interface/steam_client.hpp"
C_DECL(void*) CreateInterface(const char* interface_string, int* out_result) { C_DECL(void*) CreateInterface(const char* interface_string, int* out_result) {
return steam_client::GetGenericInterface(__func__, interface_string, [&] { return steam_client::GetGenericInterface(
GET_ORIGINAL_HOOKED_FUNCTION(CreateInterface) __func__,
interface_string,
[&] {
GET_ORIGINAL_HOOKED_FUNCTION(CreateInterface)
return CreateInterface_o(interface_string, out_result); return CreateInterface_o(interface_string, out_result);
}); }
);
} }

View File

@@ -5,10 +5,11 @@
#include "linker_exports_for_version.h" #include "linker_exports_for_version.h"
EXTERN_C [[maybe_unused]] BOOL WINAPI EXTERN_C [[maybe_unused]] BOOL WINAPI
DllMain(const HMODULE module_handle, const DWORD reason, LPVOID) { DllMain(const HMODULE module_handle, const DWORD reason, LPVOID) {
if (reason == DLL_PROCESS_ATTACH) { if(reason == DLL_PROCESS_ATTACH) {
smoke_api::init(module_handle); smoke_api::init(module_handle);
} else if (reason == DLL_PROCESS_DETACH) { } else if(reason == DLL_PROCESS_DETACH) {
smoke_api::shutdown(); smoke_api::shutdown();
} }

View File

@@ -1,30 +1,31 @@
#include <koalabox/http_client.hpp> #include <koalabox/http_client.hpp>
#include <koalabox/logger.hpp> #include <koalabox/logger.hpp>
#include "smoke_api/types.hpp"
#include "smoke_api/api.hpp" #include "smoke_api/api.hpp"
#include "smoke_api/types.hpp"
namespace api { namespace api {
struct SteamResponse { struct SteamResponse {
uint32_t success = 0; uint32_t success = 0;
std::vector<DLC> dlcs; std::vector<DLC> dlcs;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT( NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(
SteamResponse, success, dlcs SteamResponse,
success,
dlcs
) // NOLINT(misc-const-correctness) ) // NOLINT(misc-const-correctness)
}; };
std::optional<std::vector<DLC>> fetch_dlcs_from_github(AppId_t app_id) noexcept { std::optional<std::vector<DLC>> fetch_dlcs_from_github(AppId_t app_id) noexcept {
try { try {
const auto* url = "https://raw.githubusercontent.com/acidicoala/public-entitlements/" constexpr auto url = "https://raw.githubusercontent.com/"
"main/steam/v2/dlc.json"; "acidicoala/public-entitlements/main/steam/v2/dlc.json";
const auto json = koalabox::http_client::get_json(url); const auto json = koalabox::http_client::get_json(url);
const auto response = json.get<AppDlcNameMap>(); const auto response = json.get<AppDlcNameMap>();
return DLC::get_dlcs_from_apps(response, app_id); return DLC::get_dlcs_from_apps(response, app_id);
} catch (const nlohmann::json::exception& e) { } catch(const nlohmann::json::exception& e) {
LOG_ERROR("Failed to fetch dlc list from GitHub: {}", e.what()); LOG_ERROR("Failed to fetch DLC list from GitHub: {}", e.what());
return std::nullopt; return std::nullopt;
} }
} }
@@ -37,17 +38,16 @@ namespace api {
fmt::format("https://store.steampowered.com/dlc/{}/ajaxgetdlclist", app_id); fmt::format("https://store.steampowered.com/dlc/{}/ajaxgetdlclist", app_id);
const auto json = koalabox::http_client::get_json(url); const auto json = koalabox::http_client::get_json(url);
const auto response = json.get<SteamResponse>(); const auto [success, dlcs] = json.get<SteamResponse>();
if (response.success != 1) { if(success != 1) {
throw std::runtime_error("Web API responded with 'success' != 1"); throw std::runtime_error("Web API responded with 'success' != 1");
} }
return response.dlcs; return dlcs;
} catch (const std::exception& e) { } catch(const std::exception& e) {
LOG_ERROR("Failed to fetch dlc list from Steam: {}", e.what()); LOG_ERROR("Failed to fetch dlc list from Steam: {}", e.what());
return std::nullopt; return std::nullopt;
} }
} }
}
}

View File

@@ -3,9 +3,7 @@
#include "smoke_api/types.hpp" #include "smoke_api/types.hpp"
namespace api { namespace api {
std::optional<std::vector<DLC>> fetch_dlcs_from_github(AppId_t app_id) noexcept; std::optional<std::vector<DLC>> fetch_dlcs_from_github(AppId_t app_id) noexcept;
std::optional<std::vector<DLC>> fetch_dlcs_from_steam(AppId_t app_id) noexcept; std::optional<std::vector<DLC>> fetch_dlcs_from_steam(AppId_t app_id) noexcept;
} }

View File

@@ -6,20 +6,17 @@
constexpr auto KEY_APPS = "apps"; constexpr auto KEY_APPS = "apps";
namespace { namespace {
AppDlcNameMap get_cached_apps() noexcept { AppDlcNameMap get_cached_apps() noexcept {
try { try {
return koalabox::cache::get(KEY_APPS).get<AppDlcNameMap>(); return koalabox::cache::get(KEY_APPS).get<AppDlcNameMap>();
} catch (const std::exception& e) { } catch(const std::exception& e) {
LOG_WARN("Failed to get cached apps: {}", e.what()); LOG_WARN("Failed to get cached apps: {}", e.what());
return {}; return {};
} }
} }
} }
namespace smoke_api::cache { namespace smoke_api::cache {
std::vector<DLC> get_dlcs(AppId_t app_id) noexcept { std::vector<DLC> get_dlcs(AppId_t app_id) noexcept {
try { try {
LOG_DEBUG("Reading cached DLC IDs for the app: {}", app_id); LOG_DEBUG("Reading cached DLC IDs for the app: {}", app_id);
@@ -27,7 +24,7 @@ namespace smoke_api::cache {
const auto apps = get_cached_apps(); const auto apps = get_cached_apps();
return DLC::get_dlcs_from_apps(apps, app_id); return DLC::get_dlcs_from_apps(apps, app_id);
} catch (const std::exception& e) { } catch(const std::exception& e) {
LOG_ERROR("Error reading DLCs from disk cache: ", e.what()); LOG_ERROR("Error reading DLCs from disk cache: ", e.what());
return {}; return {};
@@ -43,11 +40,10 @@ namespace smoke_api::cache {
apps[std::to_string(app_id)] = App{.dlcs = DLC::get_dlc_map_from_vector(dlcs)}; apps[std::to_string(app_id)] = App{.dlcs = DLC::get_dlc_map_from_vector(dlcs)};
return koalabox::cache::put(KEY_APPS, nlohmann::json(apps)); return koalabox::cache::put(KEY_APPS, nlohmann::json(apps));
} catch (const std::exception& e) { } catch(const std::exception& e) {
LOG_ERROR("Error saving DLCs to disk cache: {}", e.what()); LOG_ERROR("Error saving DLCs to disk cache: {}", e.what());
return false; return false;
} }
} }
}
}

View File

@@ -3,9 +3,7 @@
#include "types.hpp" #include "types.hpp"
namespace smoke_api::cache { namespace smoke_api::cache {
std::vector<DLC> get_dlcs(AppId_t app_id) noexcept; std::vector<DLC> get_dlcs(AppId_t app_id) noexcept;
bool save_dlcs(AppId_t app_id, const std::vector<DLC>& dlcs) noexcept; bool save_dlcs(AppId_t app_id, const std::vector<DLC>& dlcs) noexcept;
} }

View File

@@ -7,7 +7,6 @@
namespace smoke_api::config { namespace smoke_api::config {
namespace kb = koalabox; namespace kb = koalabox;
namespace fs = std::filesystem;
Config instance; // NOLINT(cert-err58-cpp) Config instance; // NOLINT(cert-err58-cpp)
@@ -16,22 +15,25 @@ namespace smoke_api::config {
} }
bool is_dlc_unlocked( bool is_dlc_unlocked(
AppId_t app_id, AppId_t dlc_id, const std::function<bool()>& original_function AppId_t app_id,
AppId_t dlc_id,
const std::function<bool()>& original_function
) { ) {
auto status = instance.default_app_status; auto status = instance.default_app_status;
const auto app_id_str = std::to_string(app_id); const auto app_id_str = std::to_string(app_id);
if (instance.override_app_status.contains(app_id_str)) { if(instance.override_app_status.contains(app_id_str)) {
status = instance.override_app_status[app_id_str]; status = instance.override_app_status[app_id_str];
} }
const auto dlc_id_str = std::to_string(dlc_id); const auto dlc_id_str = std::to_string(dlc_id);
if (instance.override_dlc_status.contains(dlc_id_str)) { if(instance.override_dlc_status.contains(dlc_id_str)) {
status = instance.override_dlc_status[dlc_id_str]; status = instance.override_dlc_status[dlc_id_str];
} }
bool is_unlocked; bool is_unlocked;
switch (status) {
switch(status) {
case AppStatus::UNLOCKED: case AppStatus::UNLOCKED:
is_unlocked = true; is_unlocked = true;
break; break;
@@ -56,9 +58,12 @@ namespace smoke_api::config {
return is_unlocked; return is_unlocked;
} }
DLL_EXPORT(void) ReloadConfig() { DLL_EXPORT(void) ReloadConfig
(
)
{
LOG_INFO("Reloading config"); LOG_INFO("Reloading config");
instance = kb::config::parse<Config>(); instance = kb::config::parse<Config>();
} }
} }

View File

@@ -3,7 +3,6 @@
#include "smoke_api/types.hpp" #include "smoke_api/types.hpp"
namespace smoke_api::config { namespace smoke_api::config {
enum class AppStatus { enum class AppStatus {
UNDEFINED, UNDEFINED,
ORIGINAL, ORIGINAL,
@@ -11,12 +10,17 @@ namespace smoke_api::config {
LOCKED, LOCKED,
}; };
NLOHMANN_JSON_SERIALIZE_ENUM(AppStatus, { NLOHMANN_JSON_SERIALIZE_ENUM(
{ AppStatus::UNDEFINED, nullptr }, AppStatus,
{ AppStatus::ORIGINAL, "original" }, // @formatter:off
{ AppStatus::UNLOCKED, "unlocked" }, {
{ AppStatus::LOCKED, "locked" }, {AppStatus::UNDEFINED, nullptr},
}) {AppStatus::ORIGINAL, "original"},
{AppStatus::UNLOCKED, "unlocked"},
{AppStatus::LOCKED, "locked"},
}
// @formatter:on
)
struct Config { struct Config {
uint32_t $version = 2; uint32_t $version = 2;
@@ -30,7 +34,8 @@ namespace smoke_api::config {
std::vector<uint32_t> extra_inventory_items; std::vector<uint32_t> extra_inventory_items;
NLOHMANN_DEFINE_TYPE_INTRUSIVE( NLOHMANN_DEFINE_TYPE_INTRUSIVE(
Config, // NOLINT(misc-const-correctness) Config,
// NOLINT(misc-const-correctness)
$version, $version,
logging, logging,
default_app_status, default_app_status,
@@ -47,7 +52,13 @@ namespace smoke_api::config {
std::vector<DLC> get_extra_dlcs(AppId_t app_id); std::vector<DLC> get_extra_dlcs(AppId_t app_id);
bool is_dlc_unlocked(uint32_t app_id, uint32_t dlc_id, const std::function<bool()>& original_function); bool is_dlc_unlocked(
uint32_t app_id,
uint32_t dlc_id,
const std::function<bool()>& original_function
);
DLL_EXPORT(void) ReloadConfig(); DLL_EXPORT(void) ReloadConfig
} (
);
}

View File

@@ -1,6 +1,4 @@
namespace globals { namespace globals {
HMODULE steamapi_module = nullptr; HMODULE steamapi_module = nullptr;
HMODULE steamclient_module = nullptr; HMODULE steamclient_module = nullptr;
} }

View File

@@ -1,8 +1,6 @@
#pragma once #pragma once
namespace globals { namespace globals {
extern HMODULE steamclient_module; extern HMODULE steamclient_module;
extern HMODULE steamapi_module; extern HMODULE steamapi_module;
} }

View File

@@ -10,10 +10,10 @@
#include "build_config.h" #include "build_config.h"
#include "smoke_api/smoke_api.hpp"
#include "exports/steamclient.hpp" #include "exports/steamclient.hpp"
#include "smoke_api/config.hpp" #include "smoke_api/config.hpp"
#include "smoke_api/globals.hpp" #include "smoke_api/globals.hpp"
#include "smoke_api/smoke_api.hpp"
// Hooking steam_api has shown itself to be less desirable than steamclient // Hooking steam_api has shown itself to be less desirable than steamclient
// for the reasons outlined below: // for the reasons outlined below:
@@ -37,12 +37,12 @@ namespace {
namespace kb = koalabox; namespace kb = koalabox;
namespace fs = std::filesystem; namespace fs = std::filesystem;
#define DETOUR_STEAMCLIENT(FUNC) \ #define DETOUR_STEAMCLIENT(FUNC) \
kb::hook::detour_or_warn(globals::steamclient_module, #FUNC, reinterpret_cast<uintptr_t>(FUNC)); kb::hook::detour_or_warn(globals::steamclient_module, #FUNC, reinterpret_cast<uintptr_t>(FUNC));
void override_app_id() { void override_app_id() {
const auto override_app_id = smoke_api::config::instance.override_app_id; const auto override_app_id = smoke_api::config::instance.override_app_id;
if (override_app_id == 0) { if(override_app_id == 0) {
return; return;
} }
@@ -64,15 +64,19 @@ namespace {
kb::hook::init(true); kb::hook::init(true);
kb::dll_monitor::init_listener(STEAMCLIENT_DLL, [](const HMODULE& library) { kb::dll_monitor::init_listener(
globals::steamclient_module = library; STEAMCLIENT_DLL,
[](const HMODULE& library) {
globals::steamclient_module = library;
DETOUR_STEAMCLIENT(CreateInterface) DETOUR_STEAMCLIENT(CreateInterface)
kb::dll_monitor::shutdown_listener(); kb::dll_monitor::shutdown_listener();
}); }
);
} }
} }
namespace smoke_api { namespace smoke_api {
void init(const HMODULE module_handle) { void init(const HMODULE module_handle) {
// FIXME: IMPORTANT! Non ascii paths in directories will result in init errors // FIXME: IMPORTANT! Non ascii paths in directories will result in init errors
@@ -81,7 +85,7 @@ namespace smoke_api {
config::instance = kb::config::parse<config::Config>(); config::instance = kb::config::parse<config::Config>();
if (config::instance.logging) { if(config::instance.logging) {
kb::logger::init_file_logger(kb::paths::get_log_path()); kb::logger::init_file_logger(kb::paths::get_log_path());
} }
@@ -96,31 +100,31 @@ namespace smoke_api {
override_app_id(); override_app_id();
if (kb::hook::is_hook_mode(module_handle, STEAMAPI_DLL)) { if(kb::hook::is_hook_mode(module_handle, STEAMAPI_DLL)) {
init_hook_mode(); init_hook_mode();
} else { } else {
init_proxy_mode(); init_proxy_mode();
} }
LOG_INFO("Initialization complete"); LOG_INFO("Initialization complete");
} catch (const std::exception& ex) { } catch(const std::exception& ex) {
kb::util::panic(fmt::format("Initialization error: {}", ex.what())); kb::util::panic(fmt::format("Initialization error: {}", ex.what()));
} }
} }
void shutdown() { void shutdown() {
try { try {
if (globals::steamapi_module != nullptr) { if(globals::steamapi_module != nullptr) {
kb::win_util::free_library(globals::steamapi_module); kb::win_util::free_library(globals::steamapi_module);
globals::steamapi_module = nullptr; globals::steamapi_module = nullptr;
} }
LOG_INFO("Shutdown complete"); LOG_INFO("Shutdown complete");
} catch (const std::exception& e) { } catch(const std::exception& e) {
const auto msg = std::format("Shutdown error: {}", e.what()); const auto msg = std::format("Shutdown error: {}", e.what());
LOG_ERROR(msg); LOG_ERROR(msg);
} }
kb::logger::shutdown(); kb::logger::shutdown();
} }
} }

View File

@@ -1,9 +1,7 @@
#pragma once #pragma once
namespace smoke_api { namespace smoke_api {
void init(HMODULE module_handle); void init(HMODULE module_handle);
void shutdown(); void shutdown();
} }

View File

@@ -4,10 +4,10 @@ std::vector<DLC> DLC::get_dlcs_from_apps(const AppDlcNameMap& apps, AppId_t app_
std::vector<DLC> dlcs; std::vector<DLC> dlcs;
const auto app_id_str = std::to_string(app_id); const auto app_id_str = std::to_string(app_id);
if (apps.contains(app_id_str)) { if(apps.contains(app_id_str)) {
const auto& app = apps.at(app_id_str); const auto& app = apps.at(app_id_str);
for (auto const& [id, name] : app.dlcs) { for(auto const& [id, name] : app.dlcs) {
dlcs.emplace_back(id, name); dlcs.emplace_back(id, name);
} }
} }
@@ -18,9 +18,9 @@ std::vector<DLC> DLC::get_dlcs_from_apps(const AppDlcNameMap& apps, AppId_t app_
DlcNameMap DLC::get_dlc_map_from_vector(const std::vector<DLC>& dlcs) { DlcNameMap DLC::get_dlc_map_from_vector(const std::vector<DLC>& dlcs) {
DlcNameMap map; DlcNameMap map;
for (const auto& dlc : dlcs) { for(const auto& dlc : dlcs) {
map[dlc.get_id_str()] = dlc.get_name(); map[dlc.get_id_str()] = dlc.get_name();
} }
return map; return map;
} }

View File

@@ -71,9 +71,6 @@ constexpr auto STEAM_CLIENT = "SteamClient";
constexpr auto STEAM_USER = "SteamUser"; constexpr auto STEAM_USER = "SteamUser";
constexpr auto STEAM_INVENTORY = "STEAMINVENTORY_INTERFACE_V"; constexpr auto STEAM_INVENTORY = "STEAMINVENTORY_INTERFACE_V";
// TODO: Delete
constexpr auto CLIENT_ENGINE = "CLIENTENGINE_INTERFACE_VERSION";
using AppId_t = uint32_t; using AppId_t = uint32_t;
using SteamInventoryResult_t = uint32_t; using SteamInventoryResult_t = uint32_t;
using SteamItemInstanceID_t = uint64_t; using SteamItemInstanceID_t = uint64_t;
@@ -92,7 +89,7 @@ struct SteamItemDetails_t {
// results from UserHasLicenseForApp // results from UserHasLicenseForApp
enum EUserHasLicenseForAppResult { enum EUserHasLicenseForAppResult {
k_EUserHasLicenseResultHasLicense = 0, // User has a license for specified app k_EUserHasLicenseResultHasLicense = 0, // User has a license for specified app
k_EUserHasLicenseResultDoesNotHaveLicense = 1, k_EUserHasLicenseResultDoesNotHaveLicense = 1,
// User does not have a license for the specified app // User does not have a license for the specified app
k_EUserHasLicenseResultNoAuth = 2, // User has not been authenticated k_EUserHasLicenseResultNoAuth = 2, // User has not been authenticated
@@ -118,11 +115,11 @@ class DLC {
std::string appid; std::string appid;
std::string name; std::string name;
public: public:
explicit DLC() = default; explicit DLC() = default;
explicit DLC(std::string appid, std::string name) explicit DLC(std::string appid, std::string name) : appid{std::move(appid)},
: appid{std::move(appid)}, name{std::move(name)} {} name{std::move(name)} {}
[[nodiscard]] std::string get_id_str() const { [[nodiscard]] std::string get_id_str() const {
return appid; return appid;

View File

@@ -3,11 +3,11 @@
#include <koalabox/logger.hpp> #include <koalabox/logger.hpp>
#include <koalabox/util.hpp> #include <koalabox/util.hpp>
#include "steam_interface/steam_apps.hpp"
#include "smoke_api/api.hpp" #include "smoke_api/api.hpp"
#include "smoke_api/cache.hpp" #include "smoke_api/cache.hpp"
#include "smoke_api/config.hpp" #include "smoke_api/config.hpp"
#include "smoke_api/types.hpp" #include "smoke_api/types.hpp"
#include "steam_interface/steam_apps.hpp"
namespace { namespace {
/// Steamworks may max GetDLCCount value at 64, depending on how much unowned DLCs the user has. /// Steamworks may max GetDLCCount value at 64, depending on how much unowned DLCs the user has.
@@ -30,7 +30,7 @@ namespace {
static std::mutex section; static std::mutex section;
const std::lock_guard lock(section); const std::lock_guard lock(section);
if (app_id == 0) { if(app_id == 0) {
LOG_ERROR("{} -> App ID is 0", __func__); LOG_ERROR("{} -> App ID is 0", __func__);
app_dlcs[app_id] = {}; // Dummy value to avoid checking for presence on each access app_dlcs[app_id] = {}; // Dummy value to avoid checking for presence on each access
return; return;
@@ -38,7 +38,7 @@ namespace {
// We want to fetch data only once. However, if any of the remote sources have failed // We want to fetch data only once. However, if any of the remote sources have failed
// previously, we want to attempt fetching again. // previously, we want to attempt fetching again.
if (fully_fetched.contains(app_id)) { if(fully_fetched.contains(app_id)) {
return; return;
} }
@@ -46,7 +46,10 @@ namespace {
// by aggregating results from all the sources into a single set. // by aggregating results from all the sources into a single set.
std::vector<DLC> aggregated_dlcs; std::vector<DLC> aggregated_dlcs;
const auto append_dlcs = [&](const std::vector<DLC>& dlc_list, const std::string& source_name) { const auto append_dlcs = [&](
const std::vector<DLC>& dlc_list,
const std::string& source_name
) {
LOG_DEBUG("App ID {} has {} DLCs defined in {}", app_id, dlc_list.size(), source_name); LOG_DEBUG("App ID {} has {} DLCs defined in {}", app_id, dlc_list.size(), source_name);
// Append DLCs to aggregated DLCs // Append DLCs to aggregated DLCs
std::ranges::copy(dlc_list, std::back_inserter(aggregated_dlcs)); std::ranges::copy(dlc_list, std::back_inserter(aggregated_dlcs));
@@ -55,16 +58,16 @@ namespace {
append_dlcs(smoke_api::config::get_extra_dlcs(app_id), "local config"); append_dlcs(smoke_api::config::get_extra_dlcs(app_id), "local config");
const auto github_dlcs_opt = api::fetch_dlcs_from_github(app_id); const auto github_dlcs_opt = api::fetch_dlcs_from_github(app_id);
if (github_dlcs_opt) { if(github_dlcs_opt) {
append_dlcs(*github_dlcs_opt, "GitHub repository"); append_dlcs(*github_dlcs_opt, "GitHub repository");
} }
const auto steam_dlcs_opt = api::fetch_dlcs_from_steam(app_id); const auto steam_dlcs_opt = api::fetch_dlcs_from_steam(app_id);
if (steam_dlcs_opt) { if(steam_dlcs_opt) {
append_dlcs(*steam_dlcs_opt, "Steam API"); append_dlcs(*steam_dlcs_opt, "Steam API");
} }
if (github_dlcs_opt && steam_dlcs_opt) { if(github_dlcs_opt && steam_dlcs_opt) {
fully_fetched.insert(app_id); fully_fetched.insert(app_id);
} else { } else {
append_dlcs(smoke_api::cache::get_dlcs(app_id), "disk cache"); append_dlcs(smoke_api::cache::get_dlcs(app_id), "disk cache");
@@ -78,7 +81,6 @@ namespace {
} }
namespace steam_apps { namespace steam_apps {
bool IsDlcUnlocked( bool IsDlcUnlocked(
const std::string& function_name, const std::string& function_name,
AppId_t app_id, AppId_t app_id,
@@ -86,41 +88,58 @@ namespace steam_apps {
const std::function<bool()>& original_function const std::function<bool()>& original_function
) { ) {
try { try {
const auto unlocked = smoke_api::config::is_dlc_unlocked(app_id, dlc_id, original_function); const auto unlocked = smoke_api::config::is_dlc_unlocked(
app_id,
dlc_id,
original_function
);
LOG_INFO("{} -> {}DLC ID: {:>8}, Unlocked: {}", function_name, get_app_id_log(app_id), dlc_id, unlocked); LOG_INFO(
"{} -> {}DLC ID: {:>8}, Unlocked: {}",
function_name,
get_app_id_log(app_id),
dlc_id,
unlocked
);
return unlocked; return unlocked;
} catch (const std::exception& e) { } catch(const std::exception& e) {
LOG_ERROR("Uncaught exception: {}", e.what()); LOG_ERROR("Uncaught exception: {}", e.what());
return false; return false;
} }
} }
int GetDLCCount(const std::string& function_name, const AppId_t app_id, const std::function<int()>& original_function) { int GetDLCCount(
const std::string& function_name,
const AppId_t app_id,
const std::function<int()>& original_function
) {
try { try {
const auto total_count = [&](int count) { const auto total_count = [&](int count) {
LOG_INFO("{} -> Responding with DLC count: {}", function_name, count); LOG_INFO("{} -> Responding with DLC count: {}", function_name, count);
return count; return count;
}; };
if (app_id != 0) { if(app_id != 0) {
LOG_DEBUG("{} -> App ID: {}", function_name, app_id); LOG_DEBUG("{} -> App ID: {}", function_name, app_id);
} }
const auto original_count = original_function(); const auto original_count = original_function();
LOG_DEBUG("{} -> Original DLC count: {}", function_name, original_count); LOG_DEBUG("{} -> Original DLC count: {}", function_name, original_count);
if (original_count < MAX_DLC) { if(original_count < MAX_DLC) {
return total_count(original_count); return total_count(original_count);
} }
LOG_DEBUG("Game has {} or more DLCs. Fetching DLCs from remote sources.", original_count); LOG_DEBUG(
"Game has {} or more DLCs. Fetching DLCs from remote sources.",
original_count
);
fetch_and_cache_dlcs(app_id); fetch_and_cache_dlcs(app_id);
return total_count(static_cast<int>(app_dlcs[app_id].size())); return total_count(static_cast<int>(app_dlcs[app_id].size()));
} catch (const std::exception& e) { } catch(const std::exception& e) {
LOG_ERROR("Uncaught exception: {}", function_name, e.what()); LOG_ERROR("Uncaught exception: {}", function_name, e.what());
return 0; return 0;
} }
@@ -143,7 +162,13 @@ namespace steam_apps {
const auto print_dlc_info = [&](const std::string& tag) { const auto print_dlc_info = [&](const std::string& tag) {
LOG_INFO( LOG_INFO(
R"({} -> [{:^12}] {}index: {:>3}, DLC ID: {:>8}, available: {:5}, name: "{}")", R"({} -> [{:^12}] {}index: {:>3}, DLC ID: {:>8}, available: {:5}, name: "{}")",
function_name, tag, get_app_id_log(app_id), iDLC, *pDlcId, *pbAvailable, pchName function_name,
tag,
get_app_id_log(app_id),
iDLC,
*pDlcId,
*pbAvailable,
pchName
); );
}; };
@@ -151,7 +176,9 @@ namespace steam_apps {
// Fill the output pointers // Fill the output pointers
*pDlcId = dlc.get_id(); *pDlcId = dlc.get_id();
*pbAvailable = smoke_api::config::is_dlc_unlocked( *pbAvailable = smoke_api::config::is_dlc_unlocked(
app_id, *pDlcId, [&]() { app_id,
*pDlcId,
[&]() {
return is_originally_unlocked(*pDlcId); return is_originally_unlocked(*pDlcId);
} }
); );
@@ -161,10 +188,10 @@ namespace steam_apps {
memcpy_s(pchName, cchNameBufferSize, name.c_str(), name.size()); memcpy_s(pchName, cchNameBufferSize, name.c_str(), name.size());
}; };
if (app_dlcs.contains(app_id)) { if(app_dlcs.contains(app_id)) {
const auto& dlcs = app_dlcs[app_id]; const auto& dlcs = app_dlcs[app_id];
if (iDLC >= 0 && iDLC < dlcs.size()) { if(iDLC >= 0 && iDLC < dlcs.size()) {
inject_dlc(dlcs[iDLC]); inject_dlc(dlcs[iDLC]);
print_dlc_info("injected"); print_dlc_info("injected");
return true; return true;
@@ -176,9 +203,13 @@ namespace steam_apps {
const auto success = original_function(); const auto success = original_function();
if (success) { if(success) {
*pbAvailable = smoke_api::config::is_dlc_unlocked( *pbAvailable = smoke_api::config::is_dlc_unlocked(
app_id, *pDlcId, [&]() { return *pbAvailable; } app_id,
*pDlcId,
[&]() {
return *pbAvailable;
}
); );
print_dlc_info("original"); print_dlc_info("original");
} else { } else {
@@ -186,10 +217,9 @@ namespace steam_apps {
} }
return success; return success;
} catch (const std::exception& e) { } catch(const std::exception& e) {
LOG_ERROR("{} -> Uncaught exception: {}", function_name, e.what()); LOG_ERROR("{} -> Uncaught exception: {}", function_name, e.what());
return false; return false;
} }
} }
} }

View File

@@ -3,7 +3,6 @@
#include "smoke_api/types.hpp" #include "smoke_api/types.hpp"
namespace steam_apps { namespace steam_apps {
bool IsDlcUnlocked( bool IsDlcUnlocked(
const std::string& function_name, const std::string& function_name,
AppId_t app_id, AppId_t app_id,
@@ -26,7 +25,7 @@ namespace steam_apps {
char* pchName, char* pchName,
int cchNameBufferSize, int cchNameBufferSize,
const std::function<bool()>& original_function, const std::function<bool()>& original_function,
const std::function<bool(AppId_t)>& is_originally_unlocked // Aux function to resolve original dlc status const std::function<bool(AppId_t)>& is_originally_unlocked
// Aux function to resolve original dlc status
); );
} }

View File

@@ -4,7 +4,6 @@
#include "steam_interface/steam_interface.hpp" #include "steam_interface/steam_interface.hpp"
namespace steam_client { namespace steam_client {
void* GetGenericInterface( void* GetGenericInterface(
const std::string& function_name, const std::string& function_name,
const std::string& interface_version, const std::string& interface_version,
@@ -18,5 +17,4 @@ namespace steam_client {
return interface; return interface;
} }
} }

View File

@@ -3,11 +3,9 @@
#include "smoke_api/types.hpp" #include "smoke_api/types.hpp"
namespace steam_client { namespace steam_client {
void* GetGenericInterface( void* GetGenericInterface(
const std::string& function_name, const std::string& function_name,
const std::string& interface_version, const std::string& interface_version,
const std::function<void*()>& original_function const std::function<void*()>& original_function
); );
} }

View File

@@ -2,23 +2,20 @@
#include <set> #include <set>
#include <battery/embed.hpp> #include <battery/embed.hpp>
#include <polyhook2/Misc.hpp>
#include <koalabox/hook.hpp> #include <koalabox/hook.hpp>
#include <koalabox/logger.hpp> #include <koalabox/logger.hpp>
#include <koalabox/util.hpp> #include <koalabox/util.hpp>
#include <koalabox/win_util.hpp> #include <koalabox/win_util.hpp>
#include "build_config.h"
#include "steam_interface/steam_interface.hpp" #include "steam_interface/steam_interface.hpp"
#include "exports/steamclient.hpp"
#include "virtuals/steam_api_virtuals.hpp" #include "virtuals/steam_api_virtuals.hpp"
namespace { namespace {
struct interface_entry { struct interface_entry {
// function_name must match the function identifier to be able to call original functions // function_name must match the function identifier to be able to call original functions
std::string function_name; // e.g. "ISteamClient_GetISteamApps" std::string function_name; // e.g. "ISteamClient_GetISteamApps"
uintptr_t function_address; // e.g. ISteamClient_GetISteamApps uintptr_t function_address; // e.g. ISteamClient_GetISteamApps
}; };
@@ -29,7 +26,6 @@ namespace {
}; };
std::map<std::string, interface_data> get_virtual_hook_map() { std::map<std::string, interface_data> get_virtual_hook_map() {
#define ENTRY(INTERFACE, FUNC) \ #define ENTRY(INTERFACE, FUNC) \
{ \ { \
#FUNC, { \ #FUNC, { \
@@ -38,50 +34,54 @@ namespace {
} }
return { return {
{STEAM_CLIENT, {
interface_data{ STEAM_CLIENT,
.fallback_version = "SteamClient021", interface_data{
.entry_map = .fallback_version = "SteamClient021",
{ .entry_map = {
ENTRY(ISteamClient, GetISteamApps), ENTRY(ISteamClient, GetISteamApps),
ENTRY(ISteamClient, GetISteamUser), ENTRY(ISteamClient, GetISteamUser),
ENTRY(ISteamClient, GetISteamGenericInterface), ENTRY(ISteamClient, GetISteamGenericInterface),
ENTRY(ISteamClient, GetISteamInventory), ENTRY(ISteamClient, GetISteamInventory),
} }
}}, }
{STEAM_APPS, },
interface_data{ {
.fallback_version = "STEAMAPPS_INTERFACE_VERSION008", STEAM_APPS,
.entry_map = interface_data{
{ .fallback_version = "STEAMAPPS_INTERFACE_VERSION008",
ENTRY(ISteamApps, BIsSubscribedApp), .entry_map = {
ENTRY(ISteamApps, BIsDlcInstalled), ENTRY(ISteamApps, BIsSubscribedApp),
ENTRY(ISteamApps, GetDLCCount), ENTRY(ISteamApps, BIsDlcInstalled),
ENTRY(ISteamApps, BGetDLCDataByIndex), ENTRY(ISteamApps, GetDLCCount),
} ENTRY(ISteamApps, BGetDLCDataByIndex),
}}, }
{STEAM_USER, }
interface_data{ },
.fallback_version = "SteamUser023", {
.entry_map = STEAM_USER,
{ interface_data{
ENTRY(ISteamUser, UserHasLicenseForApp), .fallback_version = "SteamUser023",
} .entry_map = {
}}, ENTRY(ISteamUser, UserHasLicenseForApp),
{STEAM_INVENTORY, }
interface_data{ }
.fallback_version = "STEAMINVENTORY_INTERFACE_V003", },
.entry_map = {
{ STEAM_INVENTORY,
ENTRY(ISteamInventory, GetResultStatus), interface_data{
ENTRY(ISteamInventory, GetResultItems), .fallback_version = "STEAMINVENTORY_INTERFACE_V003",
ENTRY(ISteamInventory, CheckResultSteamID), .entry_map = {
ENTRY(ISteamInventory, GetAllItems), ENTRY(ISteamInventory, GetResultStatus),
ENTRY(ISteamInventory, GetItemsByID), ENTRY(ISteamInventory, GetResultItems),
ENTRY(ISteamInventory, SerializeResult), ENTRY(ISteamInventory, CheckResultSteamID),
ENTRY(ISteamInventory, GetItemDefinitionIDs), ENTRY(ISteamInventory, GetAllItems),
} ENTRY(ISteamInventory, GetItemsByID),
}}, ENTRY(ISteamInventory, SerializeResult),
ENTRY(ISteamInventory, GetItemDefinitionIDs),
}
}
},
}; };
} }
@@ -91,12 +91,12 @@ namespace {
} }
const nlohmann::json& find_lookup( const nlohmann::json& find_lookup(
const std::string& interface_version, // const std::string& interface_version,
const std::string& fallback_version const std::string& fallback_version
) { ) {
static const auto lookup = read_interface_lookup(); static const auto lookup = read_interface_lookup();
if (lookup.contains(interface_version)) { if(lookup.contains(interface_version)) {
return lookup[interface_version]; return lookup[interface_version];
} }
@@ -114,14 +114,14 @@ namespace steam_interface {
namespace kb = koalabox; namespace kb = koalabox;
void hook_virtuals(void* interface, const std::string& version_string) { void hook_virtuals(void* interface, const std::string& version_string) {
if (interface == nullptr) { if(interface == nullptr) {
// Game has tried to use an interface before initializing steam api // Game has tried to use an interface before initializing steam api
return; return;
} }
static std::set<void*> processed_interfaces; static std::set<void*> processed_interfaces;
if (processed_interfaces.contains(interface)) { if(processed_interfaces.contains(interface)) {
LOG_DEBUG("Interface {} at {} has already been processed.", version_string, interface); LOG_DEBUG("Interface {} at {} has already been processed.", version_string, interface);
return; return;
} }
@@ -130,14 +130,17 @@ namespace steam_interface {
const std::lock_guard guard(section); const std::lock_guard guard(section);
static const auto virtual_hook_map = get_virtual_hook_map(); static const auto virtual_hook_map = get_virtual_hook_map();
for (const auto& [prefix, data] : virtual_hook_map) { for(const auto& [prefix, data] : virtual_hook_map) {
if (version_string.starts_with(prefix)) { if(version_string.starts_with(prefix)) {
const auto& lookup = find_lookup(version_string, data.fallback_version); const auto& lookup = find_lookup(version_string, data.fallback_version);
for (const auto& [function, entry] : data.entry_map) { for(const auto& [function, entry] : data.entry_map) {
if (lookup.contains(function)) { if(lookup.contains(function)) {
kb::hook::swap_virtual_func( kb::hook::swap_virtual_func(
interface, entry.function_name, lookup[function], entry.function_address interface,
entry.function_name,
lookup[function],
entry.function_address
); );
} }
} }
@@ -149,93 +152,17 @@ namespace steam_interface {
processed_interfaces.insert(interface); processed_interfaces.insert(interface);
} }
HSteamPipe get_steam_pipe_or_throw() {
// TODO: Is there a more elegant way of getting steam pipe?
const auto& steam_api_module = koalabox::win_util::get_module_handle_or_throw(STEAMAPI_DLL);
void* GetHSteamPipe_address;
try {
GetHSteamPipe_address = (void*)koalabox::win_util::get_proc_address_or_throw(
steam_api_module, "SteamAPI_GetHSteamPipe"
);
} catch (...) {
GetHSteamPipe_address = (void*)koalabox::win_util::get_proc_address_or_throw(
steam_api_module, "GetHSteamPipe"
);
}
typedef HSteamPipe(__cdecl * GetHSteamPipe_t)();
const auto GetHSteamPipe_o = (GetHSteamPipe_t)GetHSteamPipe_address;
return GetHSteamPipe_o();
}
template <typename F> F get_virtual_function(void* interface, int ordinal) {
auto* v_table = (void***)interface;
return (F)(*v_table)[ordinal];
}
template <typename F, typename... Args>
auto call_virtual_function(void* interface, F function, Args... args) {
#ifdef _WIN64
void* RCX = interface;
#else
void* ECX = interface;
void* EDX = nullptr;
#endif
return function(ARGS(args...));
}
// TODO: Test if this actually works!!!
AppId_t get_app_id_or_throw() { AppId_t get_app_id_or_throw() {
TCHAR buffer[32]; const auto app_id_str = kb::win_util::get_env_var("SteamAppId");
GetEnvironmentVariable(TEXT("SteamAppId"), buffer, sizeof(buffer)); return std::stoi(app_id_str);
return std::stoi(buffer);
} }
AppId_t get_app_id() { AppId_t get_app_id() {
try { try {
return get_app_id_or_throw(); return get_app_id_or_throw();
} catch (...) { } catch(const std::exception& e) {
LOG_ERROR("Failed to get app id"); LOG_ERROR("Failed to get app id: {}", e.what());
return 0; return 0;
} }
/*// Get CreateInterface
const auto& steam_client_module =
koalabox::win_util::get_module_handle_or_throw(STEAMCLIENT_DLL);
auto* CreateInterface_address = (void*)koalabox::win_util::get_proc_address_or_throw(
steam_client_module, "CreateInterface"
);
auto* CreateInterface_o = PLH::FnCast(CreateInterface_address, CreateInterface);
// Get ISteamClient
int result;
auto* i_steam_client = CreateInterface_o("SteamClient006", &result);
if (i_steam_client == nullptr) {
throw koalabox::util::exception(
"Failed to obtain SteamClient006 interface. Result: {}", result
);
}
// Get GetISteamUtils
typedef void***(__fastcall * GetISteamUtils_t)(
PARAMS(HSteamPipe hSteamPipe, const char* version)
);
const auto steam_utils_ordinal = steam_client_ordinal_map["ISteamClient_GetISteamUtils"][6];
const auto GetISteamUtils_o =
get_virtual_function<GetISteamUtils_t>(i_steam_client, steam_utils_ordinal);
// Get ISteamUtils
const auto steam_pipe = get_steam_pipe_or_throw();
auto* i_steam_utils =
call_virtual_function(i_steam_client, GetISteamUtils_o, steam_pipe, "SteamUtils002");
// Get GetAppID
typedef uint32_t(__fastcall * GetAppID_t)(PARAMS());
const auto get_app_id_ordinal = steam_utils_ordinal_map["ISteamUtils_GetAppID"][2];
const auto GetAppID_o = get_virtual_function<GetAppID_t>(i_steam_utils, get_app_id_ordinal);
return call_virtual_function(i_steam_utils, GetAppID_o);*/
} }
} }

View File

@@ -3,11 +3,9 @@
#include "smoke_api/types.hpp" #include "smoke_api/types.hpp"
namespace steam_interface { namespace steam_interface {
void hook_virtuals(void* interface, const std::string& version_string);
AppId_t get_app_id_or_throw(); AppId_t get_app_id_or_throw();
AppId_t get_app_id(); AppId_t get_app_id();
void hook_virtuals(void* interface, const std::string& version_string);
} }

View File

@@ -4,7 +4,6 @@
#include "steam_interface/steam_inventory.hpp" #include "steam_interface/steam_inventory.hpp"
namespace steam_inventory { namespace steam_inventory {
EResult GetResultStatus( EResult GetResultStatus(
const std::string& function_name, const std::string& function_name,
const SteamInventoryResult_t resultHandle, const SteamInventoryResult_t resultHandle,
@@ -13,7 +12,10 @@ namespace steam_inventory {
const auto status = original_function(); const auto status = original_function();
LOG_DEBUG( LOG_DEBUG(
"{} -> handle: {}, status: {}", function_name, resultHandle, static_cast<int>(status) "{} -> handle: {}, status: {}",
function_name,
resultHandle,
static_cast<int>(status)
); );
return status; return status;
@@ -25,7 +27,7 @@ namespace steam_inventory {
SteamItemDetails_t* pOutItemsArray, SteamItemDetails_t* pOutItemsArray,
uint32_t* punOutItemsArraySize, uint32_t* punOutItemsArraySize,
const std::function<bool()>& original_function, const std::function<bool()>& original_function,
const std::function<bool(SteamItemDef_t*, uint32_t*)>& get_item_definition_ids const std::function<bool(SteamItemDef_t *, uint32_t *)>& get_item_definition_ids
) { ) {
static std::mutex section; static std::mutex section;
const std::lock_guard<std::mutex> guard(section); const std::lock_guard<std::mutex> guard(section);
@@ -43,12 +45,12 @@ namespace steam_inventory {
); );
}; };
if (not success) { if(not success) {
LOG_DEBUG("{} -> original result is false", function_name); LOG_DEBUG("{} -> original result is false", function_name);
return success; return success;
} }
if (punOutItemsArraySize == nullptr) { if(punOutItemsArraySize == nullptr) {
LOG_ERROR("{} -> arraySize pointer is null", function_name); LOG_ERROR("{} -> arraySize pointer is null", function_name);
return success; return success;
} }
@@ -66,20 +68,23 @@ namespace steam_inventory {
// Automatically get inventory items from steam // Automatically get inventory items from steam
static std::vector<SteamItemDef_t> auto_inventory_items; static std::vector<SteamItemDef_t> auto_inventory_items;
if (smoke_api::config::instance.auto_inject_inventory) { if(smoke_api::config::instance.auto_inject_inventory) {
static std::once_flag inventory_inject_flag; static std::once_flag inventory_inject_flag;
std::call_once(inventory_inject_flag, [&] { std::call_once(
uint32_t count = 0; inventory_inject_flag,
if (get_item_definition_ids(nullptr, &count)) { [&] {
auto_inventory_items.resize(count); uint32_t count = 0;
get_item_definition_ids(auto_inventory_items.data(), &count); if(get_item_definition_ids(nullptr, &count)) {
auto_inventory_items.resize(count);
get_item_definition_ids(auto_inventory_items.data(), &count);
}
} }
}); );
} }
const auto auto_injected_count = auto_inventory_items.size(); const auto auto_injected_count = auto_inventory_items.size();
if (not pOutItemsArray) { if(not pOutItemsArray) {
// If pOutItemsArray is NULL then we must set the array size. // If pOutItemsArray is NULL then we must set the array size.
original_count = *punOutItemsArraySize; original_count = *punOutItemsArraySize;
*punOutItemsArraySize += auto_injected_count + injected_count; *punOutItemsArraySize += auto_injected_count + injected_count;
@@ -91,7 +96,7 @@ namespace steam_inventory {
); );
} else { } else {
// Otherwise, we modify the array // Otherwise, we modify the array
for (int i = 0; i < original_count; i++) { for(int i = 0; i < original_count; i++) {
print_item("original", pOutItemsArray[i]); print_item("original", pOutItemsArray[i]);
} }
@@ -104,7 +109,7 @@ namespace steam_inventory {
}; };
}; };
for (int i = 0; i < auto_injected_count; i++) { for(int i = 0; i < auto_injected_count; i++) {
auto& item = pOutItemsArray[original_count + i]; auto& item = pOutItemsArray[original_count + i];
const auto item_def_id = auto_inventory_items[i]; const auto item_def_id = auto_inventory_items[i];
@@ -113,7 +118,7 @@ namespace steam_inventory {
print_item("auto-injected", item); print_item("auto-injected", item);
} }
for (int i = 0; i < injected_count; i++) { for(int i = 0; i < injected_count; i++) {
auto& item = pOutItemsArray[original_count + auto_injected_count + i]; auto& item = pOutItemsArray[original_count + auto_injected_count + i];
const auto item_def_id = smoke_api::config::instance.extra_inventory_items[i]; const auto item_def_id = smoke_api::config::instance.extra_inventory_items[i];
@@ -145,13 +150,15 @@ namespace steam_inventory {
const auto success = original_function(); const auto success = original_function();
if (!success) { if(!success) {
LOG_WARN("{}, Result is false", common_info); LOG_WARN("{}, Result is false", common_info);
return false; return false;
} }
LOG_DEBUG( LOG_DEBUG(
"{}, Buffer: '{}'", common_info, std::string(pchValueBuffer, *punValueBufferSizeOut - 1) "{}, Buffer: '{}'",
common_info,
std::string(pchValueBuffer, *punValueBufferSizeOut - 1)
); );
return success; return success;
@@ -180,8 +187,8 @@ namespace steam_inventory {
LOG_DEBUG("{} -> Handle: {}", function_name, fmt::ptr(pResultHandle)); LOG_DEBUG("{} -> Handle: {}", function_name, fmt::ptr(pResultHandle));
if (success && pInstanceIDs != nullptr) { if(success && pInstanceIDs != nullptr) {
for (int i = 0; i < unCountInstanceIDs; i++) { for(int i = 0; i < unCountInstanceIDs; i++) {
LOG_DEBUG(" Index: {}, ItemId: {}", i, pInstanceIDs[i]); LOG_DEBUG(" Index: {}, ItemId: {}", i, pInstanceIDs[i]);
} }
} }
@@ -198,12 +205,15 @@ namespace steam_inventory {
) { ) {
const auto success = original_function(); const auto success = original_function();
if (pOutBuffer != nullptr) { if(pOutBuffer != nullptr) {
std::string buffer((char*)pOutBuffer, *punOutBufferSize); std::string buffer((char*) pOutBuffer, *punOutBufferSize);
LOG_DEBUG("{} -> Handle: {}, Buffer: '{}'", function_name, resultHandle, buffer); LOG_DEBUG("{} -> Handle: {}, Buffer: '{}'", function_name, resultHandle, buffer);
} else { } else {
LOG_DEBUG( LOG_DEBUG(
"{} -> Handle: {}, Size: '{}'", function_name, resultHandle, *punOutBufferSize "{} -> Handle: {}, Size: '{}'",
function_name,
resultHandle,
*punOutBufferSize
); );
} }
@@ -218,19 +228,19 @@ namespace steam_inventory {
) { ) {
const auto success = original_function(); const auto success = original_function();
if (!success) { if(!success) {
LOG_WARN("{} -> Result is false", function_name); LOG_WARN("{} -> Result is false", function_name);
return false; return false;
} }
if (punItemDefIDsArraySize) { if(punItemDefIDsArraySize) {
LOG_DEBUG("{} -> Size: {}", function_name, *punItemDefIDsArraySize); LOG_DEBUG("{} -> Size: {}", function_name, *punItemDefIDsArraySize);
} else { } else {
return success; return success;
} }
if (pItemDefIDs) { // Definitions were copied if(pItemDefIDs) { // Definitions were copied
for (int i = 0; i < *punItemDefIDsArraySize; i++) { for(int i = 0; i < *punItemDefIDsArraySize; i++) {
const auto& def = pItemDefIDs[i]; const auto& def = pItemDefIDs[i];
LOG_DEBUG(" Index: {}, ID: {}", i, def); LOG_DEBUG(" Index: {}, ID: {}", i, def);
} }
@@ -257,4 +267,4 @@ namespace steam_inventory {
return true; return true;
} }
} }

View File

@@ -3,7 +3,6 @@
#include "smoke_api/types.hpp" #include "smoke_api/types.hpp"
namespace steam_inventory { namespace steam_inventory {
EResult GetResultStatus( EResult GetResultStatus(
const std::string& function_name, const std::string& function_name,
SteamInventoryResult_t resultHandle, SteamInventoryResult_t resultHandle,
@@ -16,7 +15,7 @@ namespace steam_inventory {
SteamItemDetails_t* pOutItemsArray, SteamItemDetails_t* pOutItemsArray,
uint32_t* punOutItemsArraySize, uint32_t* punOutItemsArraySize,
const std::function<bool()>& original_function, const std::function<bool()>& original_function,
const std::function<bool(SteamItemDef_t*, uint32_t*)>& get_item_definition_ids const std::function<bool(SteamItemDef_t *, uint32_t *)>& get_item_definition_ids
); );
bool GetResultItemProperty( bool GetResultItemProperty(
@@ -64,4 +63,4 @@ namespace steam_inventory {
CSteamID steamIDExpected, CSteamID steamIDExpected,
const std::function<bool()>& original_function const std::function<bool()>& original_function
); );
} }

View File

@@ -4,7 +4,6 @@
#include "steam_interface/steam_user.hpp" #include "steam_interface/steam_user.hpp"
namespace steam_user { namespace steam_user {
EUserHasLicenseForAppResult UserHasLicenseForApp( EUserHasLicenseForAppResult UserHasLicenseForApp(
const std::string& function_name, const std::string& function_name,
AppId_t appId, AppId_t appId,
@@ -13,19 +12,23 @@ namespace steam_user {
) { ) {
const auto result = original_function(); const auto result = original_function();
if (result == k_EUserHasLicenseResultNoAuth) { if(result == k_EUserHasLicenseResultNoAuth) {
LOG_WARN("{} -> App ID: {:>8}, Result: NoAuth", function_name, dlcId); LOG_WARN("{} -> App ID: {:>8}, Result: NoAuth", function_name, dlcId);
return result; return result;
} }
const auto has_license = smoke_api::config::is_dlc_unlocked(appId, dlcId, [&]() { const auto has_license = smoke_api::config::is_dlc_unlocked(
return result == k_EUserHasLicenseResultHasLicense; appId,
}); dlcId,
[&]() {
return result == k_EUserHasLicenseResultHasLicense;
}
);
LOG_INFO("{} -> App ID: {:>8}, HasLicense: {}", function_name, dlcId, has_license); LOG_INFO("{} -> App ID: {:>8}, HasLicense: {}", function_name, dlcId, has_license);
return has_license ? k_EUserHasLicenseResultHasLicense return has_license
: k_EUserHasLicenseResultDoesNotHaveLicense; ? k_EUserHasLicenseResultHasLicense
: k_EUserHasLicenseResultDoesNotHaveLicense;
} }
}
}

View File

@@ -3,12 +3,10 @@
#include "smoke_api/types.hpp" #include "smoke_api/types.hpp"
namespace steam_user { namespace steam_user {
EUserHasLicenseForAppResult UserHasLicenseForApp( EUserHasLicenseForAppResult UserHasLicenseForApp(
const std::string& function_name, const std::string& function_name,
AppId_t appId, AppId_t appId,
AppId_t dlcId, AppId_t dlcId,
const std::function<EUserHasLicenseForAppResult()>& original_function const std::function<EUserHasLicenseForAppResult()>& original_function
); );
}
}

View File

@@ -9,11 +9,16 @@
VIRTUAL(bool) ISteamApps_BIsSubscribedApp(PARAMS(AppId_t dlc_id)) { VIRTUAL(bool) ISteamApps_BIsSubscribedApp(PARAMS(AppId_t dlc_id)) {
try { try {
static const auto app_id = steam_interface::get_app_id(); static const auto app_id = steam_interface::get_app_id();
return steam_apps::IsDlcUnlocked(__func__, app_id, dlc_id, [&] { return steam_apps::IsDlcUnlocked(
GET_ORIGINAL_HOOKED_FUNCTION(ISteamApps_BIsSubscribedApp) __func__,
return ISteamApps_BIsSubscribedApp_o(ARGS(dlc_id)); app_id,
}); dlc_id,
} catch (const std::exception& e) { [&] {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamApps_BIsSubscribedApp)
return ISteamApps_BIsSubscribedApp_o(ARGS(dlc_id));
}
);
} catch(const std::exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what()); LOG_ERROR("{} -> Error: {}", __func__, e.what());
return false; return false;
@@ -23,11 +28,16 @@ VIRTUAL(bool) ISteamApps_BIsSubscribedApp(PARAMS(AppId_t dlc_id)) {
VIRTUAL(bool) ISteamApps_BIsDlcInstalled(PARAMS(AppId_t dlc_id)) { VIRTUAL(bool) ISteamApps_BIsDlcInstalled(PARAMS(AppId_t dlc_id)) {
try { try {
static const auto app_id = steam_interface::get_app_id(); static const auto app_id = steam_interface::get_app_id();
return steam_apps::IsDlcUnlocked(__func__, app_id, dlc_id, [&] { return steam_apps::IsDlcUnlocked(
GET_ORIGINAL_HOOKED_FUNCTION(ISteamApps_BIsDlcInstalled) __func__,
return ISteamApps_BIsDlcInstalled_o(ARGS(dlc_id)); app_id,
}); dlc_id,
} catch (const std::exception& e) { [&] {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamApps_BIsDlcInstalled)
return ISteamApps_BIsDlcInstalled_o(ARGS(dlc_id));
}
);
} catch(const std::exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what()); LOG_ERROR("{} -> Error: {}", __func__, e.what());
return false; return false;
@@ -37,20 +47,29 @@ VIRTUAL(bool) ISteamApps_BIsDlcInstalled(PARAMS(AppId_t dlc_id)) {
VIRTUAL(int) ISteamApps_GetDLCCount(PARAMS()) { VIRTUAL(int) ISteamApps_GetDLCCount(PARAMS()) {
try { try {
static const auto app_id = steam_interface::get_app_id(); static const auto app_id = steam_interface::get_app_id();
return steam_apps::GetDLCCount(__func__, app_id, [&] { return steam_apps::GetDLCCount(
GET_ORIGINAL_HOOKED_FUNCTION(ISteamApps_GetDLCCount) __func__,
return ISteamApps_GetDLCCount_o(ARGS()); app_id,
}); [&] {
} catch (const std::exception& e) { GET_ORIGINAL_HOOKED_FUNCTION(ISteamApps_GetDLCCount)
return ISteamApps_GetDLCCount_o(ARGS());
}
);
} catch(const std::exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what()); LOG_ERROR("{} -> Error: {}", __func__, e.what());
return 0; return 0;
} }
} }
VIRTUAL(bool) VIRTUAL(bool) ISteamApps_BGetDLCDataByIndex(
ISteamApps_BGetDLCDataByIndex( PARAMS(
PARAMS(int iDLC, AppId_t* p_dlc_id, bool* pbAvailable, char* pchName, int cchNameBufferSize) int iDLC,
AppId_t* p_dlc_id,
bool* pbAvailable,
char* pchName,
int cchNameBufferSize
)
) { ) {
try { try {
static const auto app_id = steam_interface::get_app_id(); static const auto app_id = steam_interface::get_app_id();
@@ -68,9 +87,11 @@ ISteamApps_BGetDLCDataByIndex(
ARGS(iDLC, p_dlc_id, pbAvailable, pchName, cchNameBufferSize) ARGS(iDLC, p_dlc_id, pbAvailable, pchName, cchNameBufferSize)
); );
}, },
[&](AppId_t dlc_id) { return ISteamApps_BIsDlcInstalled(ARGS(dlc_id)); } [&](AppId_t dlc_id) {
return ISteamApps_BIsDlcInstalled(ARGS(dlc_id));
}
); );
} catch (const std::exception& e) { } catch(const std::exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what()); LOG_ERROR("{} -> Error: {}", __func__, e.what());
return false; return false;
} }

View File

@@ -4,64 +4,103 @@
#include "steam_interface/steam_client.hpp" #include "steam_interface/steam_client.hpp"
#include "virtuals/steam_api_virtuals.hpp" #include "virtuals/steam_api_virtuals.hpp"
VIRTUAL(void*) VIRTUAL(void*) ISteamClient_GetISteamApps
ISteamClient_GetISteamApps(PARAMS(HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char* version)
(
PARAMS(
HSteamUser hSteamUser,
HSteamPipe hSteamPipe,
const char* version
)
) { ) {
try { try {
return steam_client::GetGenericInterface(__func__, version, [&] { return steam_client::GetGenericInterface(
GET_ORIGINAL_HOOKED_FUNCTION(ISteamClient_GetISteamApps) __func__,
return ISteamClient_GetISteamApps_o(ARGS(hSteamUser, hSteamPipe, version)); version,
}); [&] {
} catch (const std::exception& e) { GET_ORIGINAL_HOOKED_FUNCTION(ISteamClient_GetISteamApps)
return ISteamClient_GetISteamApps_o(ARGS(hSteamUser, hSteamPipe, version));
}
);
} catch(const std::exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what()); LOG_ERROR("{} -> Error: {}", __func__, e.what());
return nullptr; return nullptr;
} }
} }
VIRTUAL(void*) VIRTUAL(void*) ISteamClient_GetISteamUser
ISteamClient_GetISteamUser(PARAMS(HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char* version)
(
PARAMS(
HSteamUser hSteamUser,
HSteamPipe hSteamPipe,
const char* version
)
) { ) {
try { try {
return steam_client::GetGenericInterface(__func__, version, [&] { return steam_client::GetGenericInterface(
GET_ORIGINAL_HOOKED_FUNCTION(ISteamClient_GetISteamUser) __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 std::exception& e) { );
} catch(const std::exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what()); LOG_ERROR("{} -> Error: {}", __func__, e.what());
return nullptr; return nullptr;
} }
} }
VIRTUAL(void*) VIRTUAL(void*) ISteamClient_GetISteamGenericInterface
ISteamClient_GetISteamGenericInterface(
PARAMS(HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char* pchVersion) (
PARAMS(
HSteamUser hSteamUser,
HSteamPipe hSteamPipe,
const char* pchVersion
)
) { ) {
try { try {
return steam_client::GetGenericInterface(__func__, pchVersion, [&] { return steam_client::GetGenericInterface(
GET_ORIGINAL_HOOKED_FUNCTION(ISteamClient_GetISteamGenericInterface) __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 std::exception& e) { }
);
} catch(const std::exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what()); LOG_ERROR("{} -> Error: {}", __func__, e.what());
return nullptr; return nullptr;
} }
} }
VIRTUAL(void*) VIRTUAL(void*) ISteamClient_GetISteamInventory
ISteamClient_GetISteamInventory(
PARAMS(HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char* pchVersion) (
PARAMS(
HSteamUser hSteamUser,
HSteamPipe hSteamPipe,
const char* pchVersion
)
) { ) {
try { try {
return steam_client::GetGenericInterface(__func__, pchVersion, [&] { return steam_client::GetGenericInterface(
GET_ORIGINAL_HOOKED_FUNCTION(ISteamClient_GetISteamInventory) __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 std::exception& e) { );
} catch(const std::exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what()); LOG_ERROR("{} -> Error: {}", __func__, e.what());
return nullptr; return nullptr;
} }
} }

View File

@@ -4,19 +4,24 @@
#include "virtuals/steam_api_virtuals.hpp" #include "virtuals/steam_api_virtuals.hpp"
VIRTUAL(EResult) ISteamInventory_GetResultStatus(PARAMS(SteamInventoryResult_t resultHandle)) { VIRTUAL(EResult) ISteamInventory_GetResultStatus(PARAMS(SteamInventoryResult_t resultHandle)) {
return steam_inventory::GetResultStatus(__func__, resultHandle, [&] { return steam_inventory::GetResultStatus(
GET_ORIGINAL_HOOKED_FUNCTION(ISteamInventory_GetResultStatus) __func__,
resultHandle,
[&] {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamInventory_GetResultStatus)
return ISteamInventory_GetResultStatus_o(ARGS(resultHandle)); return ISteamInventory_GetResultStatus_o(ARGS(resultHandle));
}); }
);
} }
VIRTUAL(bool) VIRTUAL(bool) ISteamInventory_GetResultItems(
ISteamInventory_GetResultItems(PARAMS( PARAMS(
SteamInventoryResult_t resultHandle, SteamInventoryResult_t resultHandle,
SteamItemDetails_t* pOutItemsArray, SteamItemDetails_t* pOutItemsArray,
uint32_t* punOutItemsArraySize uint32_t* punOutItemsArraySize
)) { )
) {
return steam_inventory::GetResultItems( return steam_inventory::GetResultItems(
__func__, __func__,
resultHandle, resultHandle,
@@ -32,20 +37,22 @@ ISteamInventory_GetResultItems(PARAMS(
[&](SteamItemDef_t* pItemDefIDs, uint32_t* punItemDefIDsArraySize) { [&](SteamItemDef_t* pItemDefIDs, uint32_t* punItemDefIDsArraySize) {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamInventory_GetItemDefinitionIDs) GET_ORIGINAL_HOOKED_FUNCTION(ISteamInventory_GetItemDefinitionIDs)
return ISteamInventory_GetItemDefinitionIDs_o(ARGS(pItemDefIDs, punItemDefIDsArraySize) return ISteamInventory_GetItemDefinitionIDs_o(
ARGS(pItemDefIDs, punItemDefIDsArraySize)
); );
} }
); );
} }
VIRTUAL(bool) VIRTUAL(bool) ISteamInventory_GetResultItemProperty(
ISteamInventory_GetResultItemProperty(PARAMS( PARAMS(
SteamInventoryResult_t resultHandle, SteamInventoryResult_t resultHandle,
uint32_t unItemIndex, uint32_t unItemIndex,
const char* pchPropertyName, const char* pchPropertyName,
char* pchValueBuffer, char* pchValueBuffer,
uint32_t* punValueBufferSizeOut uint32_t* punValueBufferSizeOut
)) { )
) {
return steam_inventory::GetResultItemProperty( return steam_inventory::GetResultItemProperty(
__func__, __func__,
resultHandle, resultHandle,
@@ -56,38 +63,55 @@ ISteamInventory_GetResultItemProperty(PARAMS(
[&] { [&] {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamInventory_GetResultItemProperty) GET_ORIGINAL_HOOKED_FUNCTION(ISteamInventory_GetResultItemProperty)
return ISteamInventory_GetResultItemProperty_o(ARGS( return ISteamInventory_GetResultItemProperty_o(
resultHandle, unItemIndex, pchPropertyName, pchValueBuffer, punValueBufferSizeOut ARGS(
)); resultHandle,
unItemIndex,
pchPropertyName,
pchValueBuffer,
punValueBufferSizeOut
)
);
} }
); );
} }
VIRTUAL(bool) VIRTUAL(bool) ISteamInventory_CheckResultSteamID(
ISteamInventory_CheckResultSteamID(
PARAMS(SteamInventoryResult_t resultHandle, CSteamID steamIDExpected) PARAMS(SteamInventoryResult_t resultHandle, CSteamID steamIDExpected)
) { ) {
return steam_inventory::CheckResultSteamID(__func__, resultHandle, steamIDExpected, [&] { return steam_inventory::CheckResultSteamID(
GET_ORIGINAL_HOOKED_FUNCTION(ISteamInventory_CheckResultSteamID) __func__,
resultHandle,
steamIDExpected,
[&] {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamInventory_CheckResultSteamID)
return ISteamInventory_CheckResultSteamID_o(ARGS(resultHandle, steamIDExpected)); return ISteamInventory_CheckResultSteamID_o(ARGS(resultHandle, steamIDExpected));
}); }
);
} }
VIRTUAL(bool) ISteamInventory_GetAllItems(PARAMS(SteamInventoryResult_t* pResultHandle)) { VIRTUAL(bool) ISteamInventory_GetAllItems(
return steam_inventory::GetAllItems(__func__, pResultHandle, [&] { PARAMS(SteamInventoryResult_t*pResultHandle)
GET_ORIGINAL_HOOKED_FUNCTION(ISteamInventory_GetAllItems) ) {
return steam_inventory::GetAllItems(
__func__,
pResultHandle,
[&] {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamInventory_GetAllItems)
return ISteamInventory_GetAllItems_o(ARGS(pResultHandle)); return ISteamInventory_GetAllItems_o(ARGS(pResultHandle));
}); }
);
} }
VIRTUAL(bool) VIRTUAL(bool) ISteamInventory_GetItemsByID(
ISteamInventory_GetItemsByID(PARAMS( PARAMS(
SteamInventoryResult_t* pResultHandle, SteamInventoryResult_t* pResultHandle,
const SteamItemInstanceID_t* pInstanceIDs, const SteamItemInstanceID_t* pInstanceIDs,
uint32_t unCountInstanceIDs uint32_t unCountInstanceIDs
)) { )
) {
return steam_inventory::GetItemsByID( return steam_inventory::GetItemsByID(
__func__, __func__,
pResultHandle, pResultHandle,
@@ -103,8 +127,7 @@ ISteamInventory_GetItemsByID(PARAMS(
); );
} }
VIRTUAL(bool) VIRTUAL(bool) ISteamInventory_SerializeResult(
ISteamInventory_SerializeResult(
PARAMS(SteamInventoryResult_t resultHandle, void* pOutBuffer, uint32_t* punOutBufferSize) PARAMS(SteamInventoryResult_t resultHandle, void* pOutBuffer, uint32_t* punOutBufferSize)
) { ) {
return steam_inventory::SerializeResult( return steam_inventory::SerializeResult(
@@ -122,9 +145,11 @@ ISteamInventory_SerializeResult(
); );
} }
VIRTUAL(bool) VIRTUAL(bool) ISteamInventory_GetItemDefinitionIDs(
ISteamInventory_GetItemDefinitionIDs( PARAMS(
PARAMS(SteamItemDef_t* pItemDefIDs, uint32_t* punItemDefIDsArraySize) SteamItemDef_t*pItemDefIDs,
uint32_t* punItemDefIDsArraySize
)
) { ) {
return steam_inventory::GetItemDefinitionIDs( return steam_inventory::GetItemDefinitionIDs(
__func__, __func__,
@@ -133,7 +158,8 @@ ISteamInventory_GetItemDefinitionIDs(
[&] { [&] {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamInventory_GetItemDefinitionIDs) GET_ORIGINAL_HOOKED_FUNCTION(ISteamInventory_GetItemDefinitionIDs)
return ISteamInventory_GetItemDefinitionIDs_o(ARGS(pItemDefIDs, punItemDefIDsArraySize) return ISteamInventory_GetItemDefinitionIDs_o(
ARGS(pItemDefIDs, punItemDefIDsArraySize)
); );
} }
); );

View File

@@ -5,17 +5,23 @@
#include "steam_interface/steam_user.hpp" #include "steam_interface/steam_user.hpp"
#include "virtuals/steam_api_virtuals.hpp" #include "virtuals/steam_api_virtuals.hpp"
VIRTUAL(EUserHasLicenseForAppResult) VIRTUAL (EUserHasLicenseForAppResult) ISteamUser_UserHasLicenseForApp(
ISteamUser_UserHasLicenseForApp(PARAMS(CSteamID steamID, AppId_t dlc_id)) { PARAMS(CSteamID steamID, AppId_t dlc_id)
) {
try { try {
static const auto app_id = steam_interface::get_app_id(); static const auto app_id = steam_interface::get_app_id();
return steam_user::UserHasLicenseForApp(__func__, app_id, dlc_id, [&]() { return steam_user::UserHasLicenseForApp(
GET_ORIGINAL_HOOKED_FUNCTION(ISteamUser_UserHasLicenseForApp) __func__,
app_id,
dlc_id,
[&]() {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamUser_UserHasLicenseForApp)
return ISteamUser_UserHasLicenseForApp_o(ARGS(steamID, dlc_id)); return ISteamUser_UserHasLicenseForApp_o(ARGS(steamID, dlc_id));
}); }
} catch (const std::exception& e) { );
} catch(const std::exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what()); LOG_ERROR("{} -> Error: {}", __func__, e.what());
return k_EUserHasLicenseResultDoesNotHaveLicense; return k_EUserHasLicenseResultDoesNotHaveLicense;
} }
} }

View File

@@ -3,32 +3,62 @@
#include "smoke_api/types.hpp" #include "smoke_api/types.hpp"
// ISteamApps // ISteamApps
VIRTUAL(bool) ISteamApps_BIsSubscribedApp(PARAMS(AppId_t)); VIRTUAL(bool) ISteamApps_BIsSubscribedApp
VIRTUAL(bool) ISteamApps_BIsDlcInstalled(PARAMS(AppId_t)); (PARAMS
VIRTUAL(int) ISteamApps_GetDLCCount(PARAMS()); (AppId_t)
VIRTUAL(bool) ISteamApps_BGetDLCDataByIndex(PARAMS(int, AppId_t*, bool*, char*, int)); );
VIRTUAL(bool) ISteamApps_BIsDlcInstalled
(PARAMS
(AppId_t)
);
VIRTUAL(int) ISteamApps_GetDLCCount
(PARAMS());
VIRTUAL(bool) ISteamApps_BGetDLCDataByIndex
(PARAMS(int, AppId_t*, bool*, char*, int));
// ISteamClient // ISteamClient
VIRTUAL(void*) ISteamClient_GetISteamApps(PARAMS(HSteamUser, HSteamPipe, const char*)); VIRTUAL(void*) ISteamClient_GetISteamApps
VIRTUAL(void*) ISteamClient_GetISteamUser(PARAMS(HSteamUser, HSteamPipe, const char*)); (PARAMS(HSteamUser, HSteamPipe, const char*));
VIRTUAL(void*) ISteamClient_GetISteamGenericInterface(PARAMS(HSteamUser, HSteamPipe, const char*)); VIRTUAL(void*) ISteamClient_GetISteamUser
VIRTUAL(void*) ISteamClient_GetISteamInventory(PARAMS(HSteamUser, HSteamPipe, const char*)); (PARAMS(HSteamUser, HSteamPipe, const char*));
VIRTUAL(void*) ISteamClient_GetISteamGenericInterface
(PARAMS(HSteamUser, HSteamPipe, const char*));
VIRTUAL(void*) ISteamClient_GetISteamInventory
(PARAMS(HSteamUser, HSteamPipe, const char*));
// ISteamInventory // ISteamInventory
VIRTUAL(EResult) ISteamInventory_GetResultStatus(PARAMS(SteamInventoryResult_t)); VIRTUAL (EResult) ISteamInventory_GetResultStatus(PARAMS(SteamInventoryResult_t));
VIRTUAL(bool) VIRTUAL(bool) ISteamInventory_GetResultItems
ISteamInventory_GetResultItems(PARAMS(SteamInventoryResult_t, SteamItemDetails_t*, uint32_t*)); (
VIRTUAL(bool) PARAMS(SteamInventoryResult_t, SteamItemDetails_t*, uint32_t*) // @formatter:off
ISteamInventory_GetResultItemProperty( ); // @formatter:on
PARAMS(SteamInventoryResult_t, uint32_t, const char*, char*, uint32_t*)
VIRTUAL(bool) ISteamInventory_GetResultItemProperty
(
PARAMS(SteamInventoryResult_t, uint32_t, const char*, char*, uint32_t*) // @formatter:off
); // @formatter:on
VIRTUAL(bool) ISteamInventory_GetAllItems
(PARAMS(SteamInventoryResult_t*));
VIRTUAL(bool) ISteamInventory_GetItemsByID
(
PARAMS(
SteamInventoryResult_t*,
const SteamItemInstanceID_t*,
uint32_t
)
); );
VIRTUAL(bool) ISteamInventory_GetAllItems(PARAMS(SteamInventoryResult_t*)); VIRTUAL(bool) ISteamInventory_SerializeResult
VIRTUAL(bool) (PARAMS(SteamInventoryResult_t, void*, uint32_t*));
ISteamInventory_GetItemsByID(PARAMS(SteamInventoryResult_t*, const SteamItemInstanceID_t*, uint32_t) VIRTUAL(bool) ISteamInventory_GetItemDefinitionIDs
(PARAMS(SteamItemDef_t*, uint32_t*));
VIRTUAL(bool) ISteamInventory_CheckResultSteamID
(
PARAMS
(SteamInventoryResult_t
,
CSteamID
)
); );
VIRTUAL(bool) ISteamInventory_SerializeResult(PARAMS(SteamInventoryResult_t, void*, uint32_t*));
VIRTUAL(bool) ISteamInventory_GetItemDefinitionIDs(PARAMS(SteamItemDef_t*, uint32_t*));
VIRTUAL(bool) ISteamInventory_CheckResultSteamID(PARAMS(SteamInventoryResult_t, CSteamID));
// ISteamUser // ISteamUser
VIRTUAL(EUserHasLicenseForAppResult) ISteamUser_UserHasLicenseForApp(PARAMS(CSteamID, AppId_t)); VIRTUAL (EUserHasLicenseForAppResult) ISteamUser_UserHasLicenseForApp(PARAMS(CSteamID, AppId_t));

View File

@@ -2,11 +2,6 @@ cmake_minimum_required(VERSION 3.24)
project(smoke-api-tools LANGUAGES CXX) project(smoke-api-tools LANGUAGES CXX)
### C++ preprocessor library
CPMAddPackage("gh:danmar/simplecpp#1.5.2")
target_include_directories(simplecpp_obj INTERFACE ${simplecpp_SOURCE_DIR})
### Thread pool library ### Thread pool library
CPMAddPackage( CPMAddPackage(
@@ -34,5 +29,4 @@ add_executable(steamworks_parser steamworks_parser.cpp)
target_link_libraries(steamworks_parser PRIVATE target_link_libraries(steamworks_parser PRIVATE
KoalaBox KoalaBox
BS_thread_pool BS_thread_pool
simplecpp_obj
) )

View File

@@ -15,8 +15,8 @@ namespace {
std::string generate_random_string() { std::string generate_random_string() {
static constexpr char charset[] = "0123456789" static constexpr char charset[] = "0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"; "abcdefghijklmnopqrstuvwxyz";
thread_local std::mt19937_64 rng{std::random_device{}()}; thread_local std::mt19937_64 rng{std::random_device{}()};
thread_local std::uniform_int_distribution<std::size_t> dist(0, sizeof(charset) - 2); thread_local std::uniform_int_distribution<std::size_t> dist(0, sizeof(charset) - 2);
@@ -24,7 +24,7 @@ namespace {
constexpr auto length = 16; constexpr auto length = 16;
std::string result; std::string result;
result.reserve(length); result.reserve(length);
for (std::size_t i = 0; i < length; ++i) { for(std::size_t i = 0; i < length; ++i) {
result += charset[dist(rng)]; result += charset[dist(rng)];
} }
@@ -33,26 +33,29 @@ namespace {
void print_help() { void print_help() {
std::cout << "Steamworks SDK downloader for SmokeAPI v1.0" << std::endl std::cout << "Steamworks SDK downloader for SmokeAPI v1.0" << std::endl
<< "Usage: steamworks_downloader version1 version2 ... versionN" << std::endl << "Usage: steamworks_downloader version1 version2 ... versionN" << std::endl
<< "Example: steamworks_downloader 100 158a 162" << std::endl << "Example: steamworks_downloader 100 158a 162" << std::endl
<< "Alternative usage: steamworks_downloader C:/path/to/downloaded_sdk/" << "Alternative usage: steamworks_downloader C:/path/to/downloaded_sdk/"
<< "SDK version list available at: " << "SDK version list available at: "
<< "https://partner.steamgames.com/downloads/list" << std::endl; << "https://partner.steamgames.com/downloads/list" << std::endl;
} }
void unzip_sdk(const fs::path& zip_file_path, const fs::path& unzip_dir) { void unzip_sdk(const fs::path& zip_file_path, const fs::path& unzip_dir) {
kb::zip::extract_files(zip_file_path, [&](const std::string& name, const bool) { kb::zip::extract_files(
if (name.starts_with("sdk/public/steam/") && name.ends_with(".h")) { zip_file_path,
return unzip_dir / "headers/steam" / fs::path(name).filename(); [&](const std::string& name, const bool) {
} if(name.starts_with("sdk/public/steam/") && name.ends_with(".h")) {
return unzip_dir / "headers/steam" / fs::path(name).filename();
}
if (name.starts_with("sdk/redistributable_bin/") && name.ends_with(".dll") && if(name.starts_with("sdk/redistributable_bin/") && name.ends_with(".dll") &&
name.find("steam_api") != std::string::npos) { name.find("steam_api") != std::string::npos) {
return unzip_dir / "binaries" / fs::path(name).filename(); return unzip_dir / "binaries" / fs::path(name).filename();
} }
return fs::path(); return fs::path();
}); }
);
} }
void download_sdk(const fs::path& steamworks_dir, const std::string_view& version) { void download_sdk(const fs::path& steamworks_dir, const std::string_view& version) {
@@ -68,13 +71,12 @@ namespace {
try { try {
const auto unzip_dir = steamworks_dir / version; const auto unzip_dir = steamworks_dir / version;
unzip_sdk(zip_file_path, unzip_dir); unzip_sdk(zip_file_path, unzip_dir);
} catch (std::exception& e) { } catch(std::exception& e) {
std::cerr << "Unzip error: " << e.what() << std::endl; std::cerr << "Unzip error: " << e.what() << std::endl;
} }
fs::remove(zip_file_path); fs::remove(zip_file_path);
} }
} // namespace } // namespace
/** /**
@@ -82,21 +84,21 @@ namespace {
* for further processing by other tools. * for further processing by other tools.
*/ */
int wmain(const int argc, const wchar_t** argv) { // NOLINT(*-use-internal-linkage) int wmain(const int argc, const wchar_t** argv) { // NOLINT(*-use-internal-linkage)
if (argc == 1) { if(argc == 1) {
print_help(); print_help();
return 0; return 0;
} }
const auto steamworks_dir = std::filesystem::current_path() / "steamworks"; const auto steamworks_dir = std::filesystem::current_path() / "steamworks";
if (argc == 2) { if(argc == 2) {
if (const auto cdn_dir = kb::str::to_str(argv[1]); fs::is_directory(cdn_dir)) { if(const auto cdn_dir = kb::str::to_str(argv[1]); fs::is_directory(cdn_dir)) {
for (const auto& entry : fs::directory_iterator(cdn_dir)) { for(const auto& entry : fs::directory_iterator(cdn_dir)) {
const auto filename = entry.path().filename().string(); const auto filename = entry.path().filename().string();
const std::regex re(R"(steamworks_sdk_(.+)\.zip)"); const std::regex re(R"(steamworks_sdk_(.+)\.zip)");
if (std::smatch match; std::regex_match(filename, match, re)) { if(std::smatch match; std::regex_match(filename, match, re)) {
if (match.size() > 1) { if(match.size() > 1) {
const auto& version = match[1].str(); const auto& version = match[1].str();
unzip_sdk(entry.path(), steamworks_dir / version); unzip_sdk(entry.path(), steamworks_dir / version);
} }
@@ -107,13 +109,13 @@ int wmain(const int argc, const wchar_t** argv) { // NOLINT(*-use-internal-linka
} }
} }
for (auto i = 1; i < argc; i++) { for(auto i = 1; i < argc; i++) {
const auto version = kb::str::to_str(argv[i]); const auto version = kb::str::to_str(argv[i]);
try { try {
download_sdk(steamworks_dir, version); download_sdk(steamworks_dir, version);
} catch (const std::exception& e) { } catch(const std::exception& e) {
LOG_ERROR("Error downloading SDK '{}'. Reason: {}", version, e.what()); LOG_ERROR("Error downloading SDK '{}'. Reason: {}", version, e.what());
} }
} }
} }

View File

@@ -3,11 +3,11 @@
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
#include <functional> #include <functional>
#include <set>
#include <BS_thread_pool.hpp> #include <BS_thread_pool.hpp>
#include <cpp-tree-sitter.h> #include <cpp-tree-sitter.h>
#undef ERROR // Workaround for the ERROR enum defined in simplecpp #include <nlohmann/json.hpp>
#include <simplecpp.h>
#include <koalabox/io.hpp> #include <koalabox/io.hpp>
#include <koalabox/logger.hpp> #include <koalabox/logger.hpp>
@@ -20,7 +20,7 @@ namespace {
namespace kb = koalabox; namespace kb = koalabox;
std::string_view unquote_if_quoted(const std::string_view& s) { std::string_view unquote_if_quoted(const std::string_view& s) {
if (s.size() >= 2 && s.front() == '"' && s.back() == '"') { if(s.size() >= 2 && s.front() == '"' && s.back() == '"') {
return s.substr(1, s.size() - 2); return s.substr(1, s.size() - 2);
} }
@@ -35,132 +35,101 @@ namespace {
nlohmann::ordered_json current_lookup = {}; nlohmann::ordered_json current_lookup = {};
std::string interface_version; std::string interface_version;
kb::parser::walk(root, [&](const auto& current_node) { kb::parser::walk(
const auto current_type = current_node.getType(); root,
const auto current_value = current_node.getSourceRange(source); [&](const auto& current_node) {
const auto current_sexpr = current_node.getSExpr(); const auto current_type = current_node.getType();
const auto current_value = current_node.getSourceRange(source);
const auto current_sexpr = current_node.getSExpr();
if (current_type == "class_specifier") { if(current_type == "class_specifier") {
std::string interface_name; std::string interface_name;
[[maybe_unused]] int vt_idx = 0; [[maybe_unused]] int vt_idx = 0;
kb::parser::walk(current_node, [&](const ts::Node& class_node) { kb::parser::walk(
const auto type = class_node.getType(); current_node,
const auto value = class_node.getSourceRange(source); [&](const ts::Node& class_node) {
const auto type = class_node.getType();
const auto value = class_node.getSourceRange(source);
if (type == "type_identifier" && interface_name.empty()) { if(type == "type_identifier" && interface_name.empty()) {
interface_name = value; interface_name = value;
LOG_DEBUG("Found interface: {}", interface_name); LOG_DEBUG("Found interface: {}", interface_name);
return kb::parser::visit_result::Continue;
}
if (type == "field_declaration" && value.starts_with("virtual ")) {
if (value.starts_with("virtual ")) {
kb::parser::walk(class_node, [&](const ts::Node& decl_node) {
if (decl_node.getType() == "field_identifier") {
const auto function_name = decl_node.getSourceRange(source);
// Note: This doesn't take into account overloaded functions.
// However, so far this project hasn't had any need to hook such
// functions. Hence, no fixes have been implemented so far.
current_lookup[function_name] = vt_idx++;
return kb::parser::visit_result::Stop;
}
return kb::parser::visit_result::Continue; return kb::parser::visit_result::Continue;
}); }
if(type == "field_declaration" && value.starts_with("virtual ")) {
if(value.starts_with("virtual ")) {
kb::parser::walk(
class_node,
[&](const ts::Node& decl_node) {
if(decl_node.getType() == "field_identifier") {
const auto function_name = decl_node.getSourceRange(
source
);
// Note: This doesn't take into account overloaded functions.
// However, so far this project hasn't had any need to hook such
// functions. Hence, no fixes have been implemented so far.
current_lookup[function_name] = vt_idx++;
return kb::parser::visit_result::Stop;
}
return kb::parser::visit_result::Continue;
}
);
}
return kb::parser::visit_result::SkipChildren;
}
return kb::parser::visit_result::Continue;
} }
);
} else if(current_type == "preproc_def") {
kb::parser::walk(
current_node,
[&](const ts::Node& preproc_node) {
if(preproc_node.getType() == "identifier") {
const auto identifier = preproc_node.getSourceRange(source);
return kb::parser::visit_result::SkipChildren; return identifier.ends_with("INTERFACE_VERSION")
} ? kb::parser::visit_result::Continue
: kb::parser::visit_result::Stop;
}
if(preproc_node.getType() == "preproc_arg") {
const auto quoted_version = preproc_node.getSourceRange(source);
const auto trimmed_version = koalabox::str::trim(quoted_version);
interface_version = unquote_if_quoted(trimmed_version);
LOG_DEBUG("Interface version: {}", interface_version);
return kb::parser::visit_result::Stop;
}
return kb::parser::visit_result::Continue;
}
);
} else if(current_type == "translation_unit" || current_type == "preproc_ifdef") {
return kb::parser::visit_result::Continue; return kb::parser::visit_result::Continue;
}); }
} else if (current_type == "preproc_def") {
kb::parser::walk(current_node, [&](const ts::Node& preproc_node) {
if (preproc_node.getType() == "identifier") {
const auto identifier = preproc_node.getSourceRange(source);
return identifier.ends_with("INTERFACE_VERSION") return kb::parser::visit_result::SkipChildren;
? kb::parser::visit_result::Continue
: kb::parser::visit_result::Stop;
}
if (preproc_node.getType() == "preproc_arg") {
const auto quoted_version = preproc_node.getSourceRange(source);
const auto trimmed_version = koalabox::str::trim(quoted_version);
interface_version = unquote_if_quoted(trimmed_version);
LOG_DEBUG("Interface version: {}", interface_version);
return kb::parser::visit_result::Stop;
}
return kb::parser::visit_result::Continue;
});
} else if (current_type == "translation_unit" || current_type == "preproc_ifdef") {
return kb::parser::visit_result::Continue;
} }
);
return kb::parser::visit_result::SkipChildren;
});
// Save the findings // Save the findings
static std::mutex mutex; static std::mutex section;
if (not interface_version.empty()) { if(not
const std::lock_guard lock(mutex); interface_version.empty()
)
{
const std::lock_guard lock(section);
lookup[interface_version] = current_lookup; lookup[interface_version] = current_lookup;
} }
} }
/**
* Turns out that preprocessing headers using a proper C++ preprocessor
* significantly complicates AST parsing down the line.
* To make matters worse, it also removes macro definitions with interface version string.
* Hence, this function should not be used in practice.
* It remains here for reference purposes only.
*/
[[maybe_unused]] std::string preprocess_header(const fs::path& header_path) {
auto files = std::vector<std::string>();
static simplecpp::DUI dui{};
dui.removeComments = true;
// For stdlib headers
dui.includePaths.emplace_back("dummy/");
// For headers includes via "steam/*" path
dui.includePaths.emplace_back(header_path.parent_path().parent_path().string());
dui.defines.emplace_back("VALVE_CALLBACK_PACK_LARGE");
simplecpp::OutputList output_list;
simplecpp::TokenList raw_token_list(header_path.string(), files, &output_list);
raw_token_list.removeComments();
simplecpp::FileDataCache cache;
simplecpp::TokenList output_token_list(files);
simplecpp::preprocess(output_token_list, raw_token_list, files, cache, dui, &output_list);
simplecpp::cleanup(cache);
for (const simplecpp::Output& output : output_list) {
if (output.type == simplecpp::Output::MISSING_HEADER) {
LOG_WARN(
"Place missing empty header at: " + fs::absolute(fs::path("dummy")).string()
);
}
const auto msg = std::format(
"msg = {}, line={}, col={}, type = {}",
output.msg,
output.location.line,
output.location.col,
static_cast<int>(output.type)
);
throw std::runtime_error(msg);
}
return output_token_list.stringify();
}
/** /**
* Certain Steam macros break C++ AST parser, if left unprocessed. * Certain Steam macros break C++ AST parser, if left unprocessed.
* This function does that in a very naive manner. Stupid, but works. * This function does that in a very naive manner. Stupid, but works.
@@ -175,11 +144,14 @@ namespace {
return processed_contents; return processed_contents;
} }
void void parse_sdk(
parse_sdk(const fs::path& sdk_path, nlohmann::ordered_json& lookup, BS::thread_pool<>& pool) { const fs::path& sdk_path,
nlohmann::ordered_json& lookup,
BS::thread_pool<>& pool
) {
const auto headers_dir = sdk_path / "headers\\steam"; const auto headers_dir = sdk_path / "headers\\steam";
if (not fs::exists(headers_dir)) { if(not fs::exists(headers_dir)) {
LOG_WARN("Warning: SDK missing 'headers' directory: {}", headers_dir.string()); LOG_WARN("Warning: SDK missing 'headers' directory: {}", headers_dir.string());
return; return;
} }
@@ -187,25 +159,28 @@ namespace {
LOG_INFO("Parsing SDK: {}", headers_dir.string()); LOG_INFO("Parsing SDK: {}", headers_dir.string());
// Go over each file in headers directory // Go over each file in headers directory
for (const auto& entry : fs::directory_iterator(headers_dir)) { for(const auto& entry : fs::directory_iterator(headers_dir)) {
if (const auto& header_path = entry.path(); header_path.extension() == ".h") { if(const auto& header_path = entry.path(); header_path.extension() == ".h") {
const auto task = pool.submit_task([&, header_path] { const auto task = pool.submit_task(
try { [&, header_path] {
LOG_DEBUG("Parsing header: {}", header_path.string()); try {
LOG_DEBUG("Parsing header: {}", header_path.string());
const auto processed_header = manually_preprocess_header(header_path); const auto processed_header = manually_preprocess_header(header_path);
parse_header(processed_header, lookup); parse_header(processed_header, lookup);
} catch (std::exception& e) { } catch(std::exception& e) {
LOG_CRITICAL(e.what()); LOG_CRITICAL(e.what());
exit(-1); exit(-1);
}
} }
}); );
} }
} }
} }
void generate_lookup_json( void generate_lookup_json(
const fs::path& steamworks_dir, // const fs::path& steamworks_dir,
//
const std::set<std::string>& sdk_filter const std::set<std::string>& sdk_filter
) { ) {
nlohmann::ordered_json lookup; nlohmann::ordered_json lookup;
@@ -217,13 +192,22 @@ namespace {
BS::thread_pool pool(thread_count); BS::thread_pool pool(thread_count);
// Go over each steamworks sdk version // Go over each steamworks sdk version
for (const auto& entry : fs::directory_iterator(steamworks_dir)) { for(const auto& entry : fs::directory_iterator(steamworks_dir)) {
if (not entry.is_directory()) { if(not
entry.is_directory()
)
{
continue; continue;
} }
if (not sdk_filter.empty() and if(not
not sdk_filter.contains(entry.path().filename().string())) { sdk_filter.empty()
and
not sdk_filter
.
contains(entry.path().filename().string())
)
{
continue; continue;
} }
@@ -252,8 +236,8 @@ int wmain(const int argc, const wchar_t* argv[]) { // NOLINT(*-use-internal-link
koalabox::logger::init_console_logger(); koalabox::logger::init_console_logger();
std::set<std::string> sdk_filter; std::set<std::string> sdk_filter;
if (argc > 1) { if(argc > 1) {
for (auto i = 1; i < argc; i++) { for(auto i = 1; i < argc; i++) {
const auto version = koalabox::str::to_str(argv[i]); const auto version = koalabox::str::to_str(argv[i]);
sdk_filter.insert(version); sdk_filter.insert(version);
} }
@@ -261,7 +245,7 @@ int wmain(const int argc, const wchar_t* argv[]) { // NOLINT(*-use-internal-link
const auto steamworks_dir = fs::path("steamworks"); const auto steamworks_dir = fs::path("steamworks");
if (!fs::exists(steamworks_dir)) { if(!fs::exists(steamworks_dir)) {
throw std::exception("Expected to find 'steamworks' in current working directory."); throw std::exception("Expected to find 'steamworks' in current working directory.");
} }
@@ -271,7 +255,7 @@ int wmain(const int argc, const wchar_t* argv[]) { // NOLINT(*-use-internal-link
const auto elapsed = duration_cast<std::chrono::seconds>(end - start); const auto elapsed = duration_cast<std::chrono::seconds>(end - start);
LOG_INFO("Finished parsing steamworks in {} seconds", elapsed.count()); LOG_INFO("Finished parsing steamworks in {} seconds", elapsed.count());
} catch (std::exception& e) { } catch(std::exception& e) {
LOG_CRITICAL("Error: {}", e.what()); LOG_CRITICAL("Error: {}", e.what());
return 1; return 1;
} }