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">
<code_scheme name="Project" version="173">
<option name="AUTODETECT_INDENTS" value="false" />
<Markdown>
<option name="MAX_LINES_AROUND_HEADER" value="0" />
<option name="MAX_LINES_AROUND_BLOCK_ELEMENTS" value="0" />
@@ -17,19 +18,72 @@
<option name="SPACE_BETWEEN_ADJACENT_BRACKETS" value="true" />
</Objective-C>
<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>
<clangFormatSettings>
<option name="ENABLED" value="true" />
</clangFormatSettings>
<editorconfig>
<option name="ENABLED" value="false" />
</editorconfig>
<files>
<extensions>
<pair source="cpp" header="hpp" fileNamingConvention="SNAKE_CASE" />
<pair source="c" header="h" fileNamingConvention="NONE" />
<pair source="cu" header="cuh" fileNamingConvention="NONE" />
<pair source="c" header="h" fileNamingConvention="SNAKE_CASE" />
</extensions>
</files>
<codeStyleSettings language="CMake">

View File

@@ -2,13 +2,19 @@
<dictionary name="project">
<words>
<w>abcdefghijklmnopqrstuvwxyz</w>
<w>acidicoala</w>
<w>ajaxgetdlclist</w>
<w>indicies</w>
<w>inlinentd</w>
<w>isteamapps</w>
<w>isteamclient</w>
<w>isteaminventory</w>
<w>isteamuser</w>
<w>koalabox</w>
<w>koality</w>
<w>koaloader</w>
<w>polyhook</w>
<w>simplecpp</w>
<w>steamapps</w>
<w>wstr</w>
</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.
target_compile_options(SmokeAPI PRIVATE /std:c++latest)
target_include_directories(SmokeAPI PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>")
configure_linker_exports(
TARGET SmokeAPI
HEADER_NAME "linker_exports_for_steam_api"
@@ -93,7 +95,6 @@ configure_output_name(${STEAMAPI_DLL})
configure_include_directories()
target_link_libraries(SmokeAPI PRIVATE KoalaBox)
target_precompile_headers(SmokeAPI REUSE_FROM KoalaBox)
set(B_PRODUCTION_MODE ON)
CPMAddPackage("gh:batterycenter/embed@1.2.19")

View File

@@ -262,7 +262,7 @@ config::: `Debug` or `Release`
For example:
----
.\build.ps1 32 Debug
.\build.ps1 64 Release
----
== 📚 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"
// TODO: Detour in hook mode
DLL_EXPORT(bool) SteamAPI_RestartAppIfNecessary(const uint32_t unOwnAppID) {
if (smoke_api::config::instance.override_app_id != 0) {
DLL_EXPORT(bool) SteamAPI_RestartAppIfNecessary
(
const uint32_t unOwnAppID
)
{
if(smoke_api::config::instance.override_app_id != 0) {
LOG_DEBUG("{} -> {}. Preventing app restart", unOwnAppID, __func__);
return false;
}
@@ -14,7 +18,10 @@ DLL_EXPORT(bool) SteamAPI_RestartAppIfNecessary(const uint32_t unOwnAppID) {
return ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_RestartAppIfNecessary)(unOwnAppID);
}
DLL_EXPORT(void) SteamAPI_Shutdown() {
DLL_EXPORT(void) SteamAPI_Shutdown
(
)
{
LOG_INFO("{} -> Game requested shutdown", __func__);
ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_Shutdown)();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -3,9 +3,7 @@
#include "smoke_api/types.hpp"
namespace api {
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;
}

View File

@@ -6,20 +6,17 @@
constexpr auto KEY_APPS = "apps";
namespace {
AppDlcNameMap get_cached_apps() noexcept {
try {
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());
return {};
}
}
}
namespace smoke_api::cache {
std::vector<DLC> get_dlcs(AppId_t app_id) noexcept {
try {
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();
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());
return {};
@@ -43,11 +40,10 @@ namespace smoke_api::cache {
apps[std::to_string(app_id)] = App{.dlcs = DLC::get_dlc_map_from_vector(dlcs)};
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());
return false;
}
}
}

View File

@@ -3,9 +3,7 @@
#include "types.hpp"
namespace smoke_api::cache {
std::vector<DLC> get_dlcs(AppId_t app_id) 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 kb = koalabox;
namespace fs = std::filesystem;
Config instance; // NOLINT(cert-err58-cpp)
@@ -16,22 +15,25 @@ namespace smoke_api::config {
}
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;
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];
}
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];
}
bool is_unlocked;
switch (status) {
switch(status) {
case AppStatus::UNLOCKED:
is_unlocked = true;
break;
@@ -56,7 +58,10 @@ namespace smoke_api::config {
return is_unlocked;
}
DLL_EXPORT(void) ReloadConfig() {
DLL_EXPORT(void) ReloadConfig
(
)
{
LOG_INFO("Reloading config");
instance = kb::config::parse<Config>();

View File

@@ -3,7 +3,6 @@
#include "smoke_api/types.hpp"
namespace smoke_api::config {
enum class AppStatus {
UNDEFINED,
ORIGINAL,
@@ -11,12 +10,17 @@ namespace smoke_api::config {
LOCKED,
};
NLOHMANN_JSON_SERIALIZE_ENUM(AppStatus, {
{ AppStatus::UNDEFINED, nullptr },
{ AppStatus::ORIGINAL, "original" },
{ AppStatus::UNLOCKED, "unlocked" },
{ AppStatus::LOCKED, "locked" },
})
NLOHMANN_JSON_SERIALIZE_ENUM(
AppStatus,
// @formatter:off
{
{AppStatus::UNDEFINED, nullptr},
{AppStatus::ORIGINAL, "original"},
{AppStatus::UNLOCKED, "unlocked"},
{AppStatus::LOCKED, "locked"},
}
// @formatter:on
)
struct Config {
uint32_t $version = 2;
@@ -30,7 +34,8 @@ namespace smoke_api::config {
std::vector<uint32_t> extra_inventory_items;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(
Config, // NOLINT(misc-const-correctness)
Config,
// NOLINT(misc-const-correctness)
$version,
logging,
default_app_status,
@@ -47,7 +52,13 @@ namespace smoke_api::config {
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 {
HMODULE steamapi_module = nullptr;
HMODULE steamclient_module = nullptr;
}

View File

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

View File

@@ -10,10 +10,10 @@
#include "build_config.h"
#include "smoke_api/smoke_api.hpp"
#include "exports/steamclient.hpp"
#include "smoke_api/config.hpp"
#include "smoke_api/globals.hpp"
#include "smoke_api/smoke_api.hpp"
// Hooking steam_api has shown itself to be less desirable than steamclient
// for the reasons outlined below:
@@ -42,7 +42,7 @@ namespace {
void 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;
}
@@ -64,15 +64,19 @@ namespace {
kb::hook::init(true);
kb::dll_monitor::init_listener(STEAMCLIENT_DLL, [](const HMODULE& library) {
kb::dll_monitor::init_listener(
STEAMCLIENT_DLL,
[](const HMODULE& library) {
globals::steamclient_module = library;
DETOUR_STEAMCLIENT(CreateInterface)
kb::dll_monitor::shutdown_listener();
});
}
);
}
}
namespace smoke_api {
void init(const HMODULE module_handle) {
// 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>();
if (config::instance.logging) {
if(config::instance.logging) {
kb::logger::init_file_logger(kb::paths::get_log_path());
}
@@ -96,27 +100,27 @@ namespace smoke_api {
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();
} else {
init_proxy_mode();
}
LOG_INFO("Initialization complete");
} catch (const std::exception& ex) {
} catch(const std::exception& ex) {
kb::util::panic(fmt::format("Initialization error: {}", ex.what()));
}
}
void shutdown() {
try {
if (globals::steamapi_module != nullptr) {
if(globals::steamapi_module != nullptr) {
kb::win_util::free_library(globals::steamapi_module);
globals::steamapi_module = nullptr;
}
LOG_INFO("Shutdown complete");
} catch (const std::exception& e) {
} catch(const std::exception& e) {
const auto msg = std::format("Shutdown error: {}", e.what());
LOG_ERROR(msg);
}

View File

@@ -1,9 +1,7 @@
#pragma once
namespace smoke_api {
void init(HMODULE module_handle);
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;
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);
for (auto const& [id, name] : app.dlcs) {
for(auto const& [id, name] : app.dlcs) {
dlcs.emplace_back(id, name);
}
}
@@ -18,7 +18,7 @@ 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 map;
for (const auto& dlc : dlcs) {
for(const auto& dlc : dlcs) {
map[dlc.get_id_str()] = dlc.get_name();
}

View File

@@ -71,9 +71,6 @@ constexpr auto STEAM_CLIENT = "SteamClient";
constexpr auto STEAM_USER = "SteamUser";
constexpr auto STEAM_INVENTORY = "STEAMINVENTORY_INTERFACE_V";
// TODO: Delete
constexpr auto CLIENT_ENGINE = "CLIENTENGINE_INTERFACE_VERSION";
using AppId_t = uint32_t;
using SteamInventoryResult_t = uint32_t;
using SteamItemInstanceID_t = uint64_t;
@@ -118,11 +115,11 @@ class DLC {
std::string appid;
std::string name;
public:
public:
explicit DLC() = default;
explicit DLC(std::string appid, std::string name)
: appid{std::move(appid)}, name{std::move(name)} {}
explicit DLC(std::string appid, std::string name) : appid{std::move(appid)},
name{std::move(name)} {}
[[nodiscard]] std::string get_id_str() const {
return appid;

View File

@@ -3,11 +3,11 @@
#include <koalabox/logger.hpp>
#include <koalabox/util.hpp>
#include "steam_interface/steam_apps.hpp"
#include "smoke_api/api.hpp"
#include "smoke_api/cache.hpp"
#include "smoke_api/config.hpp"
#include "smoke_api/types.hpp"
#include "steam_interface/steam_apps.hpp"
namespace {
/// 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;
const std::lock_guard lock(section);
if (app_id == 0) {
if(app_id == 0) {
LOG_ERROR("{} -> App ID is 0", __func__);
app_dlcs[app_id] = {}; // Dummy value to avoid checking for presence on each access
return;
@@ -38,7 +38,7 @@ namespace {
// We want to fetch data only once. However, if any of the remote sources have failed
// previously, we want to attempt fetching again.
if (fully_fetched.contains(app_id)) {
if(fully_fetched.contains(app_id)) {
return;
}
@@ -46,7 +46,10 @@ namespace {
// by aggregating results from all the sources into a single set.
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);
// Append DLCs to 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");
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");
}
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");
}
if (github_dlcs_opt && steam_dlcs_opt) {
if(github_dlcs_opt && steam_dlcs_opt) {
fully_fetched.insert(app_id);
} else {
append_dlcs(smoke_api::cache::get_dlcs(app_id), "disk cache");
@@ -78,7 +81,6 @@ namespace {
}
namespace steam_apps {
bool IsDlcUnlocked(
const std::string& function_name,
AppId_t app_id,
@@ -86,41 +88,58 @@ namespace steam_apps {
const std::function<bool()>& original_function
) {
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;
} catch (const std::exception& e) {
} catch(const std::exception& e) {
LOG_ERROR("Uncaught exception: {}", e.what());
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 {
const auto total_count = [&](int count) {
LOG_INFO("{} -> Responding with DLC count: {}", function_name, count);
return count;
};
if (app_id != 0) {
if(app_id != 0) {
LOG_DEBUG("{} -> App ID: {}", function_name, app_id);
}
const auto original_count = original_function();
LOG_DEBUG("{} -> Original DLC count: {}", function_name, original_count);
if (original_count < MAX_DLC) {
if(original_count < MAX_DLC) {
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);
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());
return 0;
}
@@ -143,7 +162,13 @@ namespace steam_apps {
const auto print_dlc_info = [&](const std::string& tag) {
LOG_INFO(
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
*pDlcId = dlc.get_id();
*pbAvailable = smoke_api::config::is_dlc_unlocked(
app_id, *pDlcId, [&]() {
app_id,
*pDlcId,
[&]() {
return is_originally_unlocked(*pDlcId);
}
);
@@ -161,10 +188,10 @@ namespace steam_apps {
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];
if (iDLC >= 0 && iDLC < dlcs.size()) {
if(iDLC >= 0 && iDLC < dlcs.size()) {
inject_dlc(dlcs[iDLC]);
print_dlc_info("injected");
return true;
@@ -176,9 +203,13 @@ namespace steam_apps {
const auto success = original_function();
if (success) {
if(success) {
*pbAvailable = smoke_api::config::is_dlc_unlocked(
app_id, *pDlcId, [&]() { return *pbAvailable; }
app_id,
*pDlcId,
[&]() {
return *pbAvailable;
}
);
print_dlc_info("original");
} else {
@@ -186,10 +217,9 @@ namespace steam_apps {
}
return success;
} catch (const std::exception& e) {
} catch(const std::exception& e) {
LOG_ERROR("{} -> Uncaught exception: {}", function_name, e.what());
return false;
}
}
}

View File

@@ -3,7 +3,6 @@
#include "smoke_api/types.hpp"
namespace steam_apps {
bool IsDlcUnlocked(
const std::string& function_name,
AppId_t app_id,
@@ -26,7 +25,7 @@ namespace steam_apps {
char* pchName,
int cchNameBufferSize,
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"
namespace steam_client {
void* GetGenericInterface(
const std::string& function_name,
const std::string& interface_version,
@@ -18,5 +17,4 @@ namespace steam_client {
return interface;
}
}

View File

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

View File

@@ -2,20 +2,17 @@
#include <set>
#include <battery/embed.hpp>
#include <polyhook2/Misc.hpp>
#include <koalabox/hook.hpp>
#include <koalabox/logger.hpp>
#include <koalabox/util.hpp>
#include <koalabox/win_util.hpp>
#include "build_config.h"
#include "steam_interface/steam_interface.hpp"
#include "exports/steamclient.hpp"
#include "virtuals/steam_api_virtuals.hpp"
namespace {
struct interface_entry {
// function_name must match the function identifier to be able to call original functions
std::string function_name; // e.g. "ISteamClient_GetISteamApps"
@@ -29,7 +26,6 @@ namespace {
};
std::map<std::string, interface_data> get_virtual_hook_map() {
#define ENTRY(INTERFACE, FUNC) \
{ \
#FUNC, { \
@@ -38,41 +34,44 @@ namespace {
}
return {
{STEAM_CLIENT,
{
STEAM_CLIENT,
interface_data{
.fallback_version = "SteamClient021",
.entry_map =
{
.entry_map = {
ENTRY(ISteamClient, GetISteamApps),
ENTRY(ISteamClient, GetISteamUser),
ENTRY(ISteamClient, GetISteamGenericInterface),
ENTRY(ISteamClient, GetISteamInventory),
}
}},
{STEAM_APPS,
}
},
{
STEAM_APPS,
interface_data{
.fallback_version = "STEAMAPPS_INTERFACE_VERSION008",
.entry_map =
{
.entry_map = {
ENTRY(ISteamApps, BIsSubscribedApp),
ENTRY(ISteamApps, BIsDlcInstalled),
ENTRY(ISteamApps, GetDLCCount),
ENTRY(ISteamApps, BGetDLCDataByIndex),
}
}},
{STEAM_USER,
}
},
{
STEAM_USER,
interface_data{
.fallback_version = "SteamUser023",
.entry_map =
{
.entry_map = {
ENTRY(ISteamUser, UserHasLicenseForApp),
}
}},
{STEAM_INVENTORY,
}
},
{
STEAM_INVENTORY,
interface_data{
.fallback_version = "STEAMINVENTORY_INTERFACE_V003",
.entry_map =
{
.entry_map = {
ENTRY(ISteamInventory, GetResultStatus),
ENTRY(ISteamInventory, GetResultItems),
ENTRY(ISteamInventory, CheckResultSteamID),
@@ -81,7 +80,8 @@ namespace {
ENTRY(ISteamInventory, SerializeResult),
ENTRY(ISteamInventory, GetItemDefinitionIDs),
}
}},
}
},
};
}
@@ -91,12 +91,12 @@ namespace {
}
const nlohmann::json& find_lookup(
const std::string& interface_version, //
const std::string& interface_version,
const std::string& fallback_version
) {
static const auto lookup = read_interface_lookup();
if (lookup.contains(interface_version)) {
if(lookup.contains(interface_version)) {
return lookup[interface_version];
}
@@ -114,14 +114,14 @@ namespace steam_interface {
namespace kb = koalabox;
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
return;
}
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);
return;
}
@@ -130,14 +130,17 @@ namespace steam_interface {
const std::lock_guard guard(section);
static const auto virtual_hook_map = get_virtual_hook_map();
for (const auto& [prefix, data] : virtual_hook_map) {
if (version_string.starts_with(prefix)) {
for(const auto& [prefix, data] : virtual_hook_map) {
if(version_string.starts_with(prefix)) {
const auto& lookup = find_lookup(version_string, data.fallback_version);
for (const auto& [function, entry] : data.entry_map) {
if (lookup.contains(function)) {
for(const auto& [function, entry] : data.entry_map) {
if(lookup.contains(function)) {
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);
}
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() {
TCHAR buffer[32];
GetEnvironmentVariable(TEXT("SteamAppId"), buffer, sizeof(buffer));
return std::stoi(buffer);
const auto app_id_str = kb::win_util::get_env_var("SteamAppId");
return std::stoi(app_id_str);
}
AppId_t get_app_id() {
try {
return get_app_id_or_throw();
} catch (...) {
LOG_ERROR("Failed to get app id");
} catch(const std::exception& e) {
LOG_ERROR("Failed to get app id: {}", e.what());
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"
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();
void hook_virtuals(void* interface, const std::string& version_string);
}

View File

@@ -4,7 +4,6 @@
#include "steam_interface/steam_inventory.hpp"
namespace steam_inventory {
EResult GetResultStatus(
const std::string& function_name,
const SteamInventoryResult_t resultHandle,
@@ -13,7 +12,10 @@ namespace steam_inventory {
const auto status = original_function();
LOG_DEBUG(
"{} -> handle: {}, status: {}", function_name, resultHandle, static_cast<int>(status)
"{} -> handle: {}, status: {}",
function_name,
resultHandle,
static_cast<int>(status)
);
return status;
@@ -25,7 +27,7 @@ namespace steam_inventory {
SteamItemDetails_t* pOutItemsArray,
uint32_t* punOutItemsArraySize,
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;
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);
return success;
}
if (punOutItemsArraySize == nullptr) {
if(punOutItemsArraySize == nullptr) {
LOG_ERROR("{} -> arraySize pointer is null", function_name);
return success;
}
@@ -66,20 +68,23 @@ namespace steam_inventory {
// Automatically get inventory items from steam
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;
std::call_once(inventory_inject_flag, [&] {
std::call_once(
inventory_inject_flag,
[&] {
uint32_t count = 0;
if (get_item_definition_ids(nullptr, &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();
if (not pOutItemsArray) {
if(not pOutItemsArray) {
// If pOutItemsArray is NULL then we must set the array size.
original_count = *punOutItemsArraySize;
*punOutItemsArraySize += auto_injected_count + injected_count;
@@ -91,7 +96,7 @@ namespace steam_inventory {
);
} else {
// 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]);
}
@@ -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];
const auto item_def_id = auto_inventory_items[i];
@@ -113,7 +118,7 @@ namespace steam_inventory {
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];
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();
if (!success) {
if(!success) {
LOG_WARN("{}, Result is false", common_info);
return false;
}
LOG_DEBUG(
"{}, Buffer: '{}'", common_info, std::string(pchValueBuffer, *punValueBufferSizeOut - 1)
"{}, Buffer: '{}'",
common_info,
std::string(pchValueBuffer, *punValueBufferSizeOut - 1)
);
return success;
@@ -180,8 +187,8 @@ namespace steam_inventory {
LOG_DEBUG("{} -> Handle: {}", function_name, fmt::ptr(pResultHandle));
if (success && pInstanceIDs != nullptr) {
for (int i = 0; i < unCountInstanceIDs; i++) {
if(success && pInstanceIDs != nullptr) {
for(int i = 0; i < unCountInstanceIDs; i++) {
LOG_DEBUG(" Index: {}, ItemId: {}", i, pInstanceIDs[i]);
}
}
@@ -198,12 +205,15 @@ namespace steam_inventory {
) {
const auto success = original_function();
if (pOutBuffer != nullptr) {
std::string buffer((char*)pOutBuffer, *punOutBufferSize);
if(pOutBuffer != nullptr) {
std::string buffer((char*) pOutBuffer, *punOutBufferSize);
LOG_DEBUG("{} -> Handle: {}, Buffer: '{}'", function_name, resultHandle, buffer);
} else {
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();
if (!success) {
if(!success) {
LOG_WARN("{} -> Result is false", function_name);
return false;
}
if (punItemDefIDsArraySize) {
if(punItemDefIDsArraySize) {
LOG_DEBUG("{} -> Size: {}", function_name, *punItemDefIDsArraySize);
} else {
return success;
}
if (pItemDefIDs) { // Definitions were copied
for (int i = 0; i < *punItemDefIDsArraySize; i++) {
if(pItemDefIDs) { // Definitions were copied
for(int i = 0; i < *punItemDefIDsArraySize; i++) {
const auto& def = pItemDefIDs[i];
LOG_DEBUG(" Index: {}, ID: {}", i, def);
}

View File

@@ -3,7 +3,6 @@
#include "smoke_api/types.hpp"
namespace steam_inventory {
EResult GetResultStatus(
const std::string& function_name,
SteamInventoryResult_t resultHandle,
@@ -16,7 +15,7 @@ namespace steam_inventory {
SteamItemDetails_t* pOutItemsArray,
uint32_t* punOutItemsArraySize,
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(

View File

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

View File

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

View File

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

View File

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

View File

@@ -4,19 +4,24 @@
#include "virtuals/steam_api_virtuals.hpp"
VIRTUAL(EResult) ISteamInventory_GetResultStatus(PARAMS(SteamInventoryResult_t resultHandle)) {
return steam_inventory::GetResultStatus(__func__, resultHandle, [&] {
return steam_inventory::GetResultStatus(
__func__,
resultHandle,
[&] {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamInventory_GetResultStatus)
return ISteamInventory_GetResultStatus_o(ARGS(resultHandle));
});
}
);
}
VIRTUAL(bool)
ISteamInventory_GetResultItems(PARAMS(
VIRTUAL(bool) ISteamInventory_GetResultItems(
PARAMS(
SteamInventoryResult_t resultHandle,
SteamItemDetails_t* pOutItemsArray,
uint32_t* punOutItemsArraySize
)) {
)
) {
return steam_inventory::GetResultItems(
__func__,
resultHandle,
@@ -32,20 +37,22 @@ ISteamInventory_GetResultItems(PARAMS(
[&](SteamItemDef_t* pItemDefIDs, uint32_t* punItemDefIDsArraySize) {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamInventory_GetItemDefinitionIDs)
return ISteamInventory_GetItemDefinitionIDs_o(ARGS(pItemDefIDs, punItemDefIDsArraySize)
return ISteamInventory_GetItemDefinitionIDs_o(
ARGS(pItemDefIDs, punItemDefIDsArraySize)
);
}
);
}
VIRTUAL(bool)
ISteamInventory_GetResultItemProperty(PARAMS(
VIRTUAL(bool) ISteamInventory_GetResultItemProperty(
PARAMS(
SteamInventoryResult_t resultHandle,
uint32_t unItemIndex,
const char* pchPropertyName,
char* pchValueBuffer,
uint32_t* punValueBufferSizeOut
)) {
)
) {
return steam_inventory::GetResultItemProperty(
__func__,
resultHandle,
@@ -56,38 +63,55 @@ ISteamInventory_GetResultItemProperty(PARAMS(
[&] {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamInventory_GetResultItemProperty)
return ISteamInventory_GetResultItemProperty_o(ARGS(
resultHandle, unItemIndex, pchPropertyName, pchValueBuffer, punValueBufferSizeOut
));
return ISteamInventory_GetResultItemProperty_o(
ARGS(
resultHandle,
unItemIndex,
pchPropertyName,
pchValueBuffer,
punValueBufferSizeOut
)
);
}
);
}
VIRTUAL(bool)
ISteamInventory_CheckResultSteamID(
VIRTUAL(bool) ISteamInventory_CheckResultSteamID(
PARAMS(SteamInventoryResult_t resultHandle, CSteamID steamIDExpected)
) {
return steam_inventory::CheckResultSteamID(__func__, resultHandle, steamIDExpected, [&] {
return steam_inventory::CheckResultSteamID(
__func__,
resultHandle,
steamIDExpected,
[&] {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamInventory_CheckResultSteamID)
return ISteamInventory_CheckResultSteamID_o(ARGS(resultHandle, steamIDExpected));
});
}
);
}
VIRTUAL(bool) ISteamInventory_GetAllItems(PARAMS(SteamInventoryResult_t* pResultHandle)) {
return steam_inventory::GetAllItems(__func__, pResultHandle, [&] {
VIRTUAL(bool) ISteamInventory_GetAllItems(
PARAMS(SteamInventoryResult_t*pResultHandle)
) {
return steam_inventory::GetAllItems(
__func__,
pResultHandle,
[&] {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamInventory_GetAllItems)
return ISteamInventory_GetAllItems_o(ARGS(pResultHandle));
});
}
);
}
VIRTUAL(bool)
ISteamInventory_GetItemsByID(PARAMS(
VIRTUAL(bool) ISteamInventory_GetItemsByID(
PARAMS(
SteamInventoryResult_t* pResultHandle,
const SteamItemInstanceID_t* pInstanceIDs,
uint32_t unCountInstanceIDs
)) {
)
) {
return steam_inventory::GetItemsByID(
__func__,
pResultHandle,
@@ -103,8 +127,7 @@ ISteamInventory_GetItemsByID(PARAMS(
);
}
VIRTUAL(bool)
ISteamInventory_SerializeResult(
VIRTUAL(bool) ISteamInventory_SerializeResult(
PARAMS(SteamInventoryResult_t resultHandle, void* pOutBuffer, uint32_t* punOutBufferSize)
) {
return steam_inventory::SerializeResult(
@@ -122,9 +145,11 @@ ISteamInventory_SerializeResult(
);
}
VIRTUAL(bool)
ISteamInventory_GetItemDefinitionIDs(
PARAMS(SteamItemDef_t* pItemDefIDs, uint32_t* punItemDefIDsArraySize)
VIRTUAL(bool) ISteamInventory_GetItemDefinitionIDs(
PARAMS(
SteamItemDef_t*pItemDefIDs,
uint32_t* punItemDefIDsArraySize
)
) {
return steam_inventory::GetItemDefinitionIDs(
__func__,
@@ -133,7 +158,8 @@ 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,16 +5,22 @@
#include "steam_interface/steam_user.hpp"
#include "virtuals/steam_api_virtuals.hpp"
VIRTUAL(EUserHasLicenseForAppResult)
ISteamUser_UserHasLicenseForApp(PARAMS(CSteamID steamID, AppId_t dlc_id)) {
VIRTUAL (EUserHasLicenseForAppResult) ISteamUser_UserHasLicenseForApp(
PARAMS(CSteamID steamID, AppId_t dlc_id)
) {
try {
static const auto app_id = steam_interface::get_app_id();
return steam_user::UserHasLicenseForApp(__func__, app_id, dlc_id, [&]() {
return steam_user::UserHasLicenseForApp(
__func__,
app_id,
dlc_id,
[&]() {
GET_ORIGINAL_HOOKED_FUNCTION(ISteamUser_UserHasLicenseForApp)
return ISteamUser_UserHasLicenseForApp_o(ARGS(steamID, dlc_id));
});
} catch (const std::exception& e) {
}
);
} catch(const std::exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what());
return k_EUserHasLicenseResultDoesNotHaveLicense;
}

View File

@@ -3,32 +3,62 @@
#include "smoke_api/types.hpp"
// ISteamApps
VIRTUAL(bool) ISteamApps_BIsSubscribedApp(PARAMS(AppId_t));
VIRTUAL(bool) ISteamApps_BIsDlcInstalled(PARAMS(AppId_t));
VIRTUAL(int) ISteamApps_GetDLCCount(PARAMS());
VIRTUAL(bool) ISteamApps_BGetDLCDataByIndex(PARAMS(int, AppId_t*, bool*, char*, int));
VIRTUAL(bool) ISteamApps_BIsSubscribedApp
(PARAMS
(AppId_t)
);
VIRTUAL(bool) ISteamApps_BIsDlcInstalled
(PARAMS
(AppId_t)
);
VIRTUAL(int) ISteamApps_GetDLCCount
(PARAMS());
VIRTUAL(bool) ISteamApps_BGetDLCDataByIndex
(PARAMS(int, AppId_t*, bool*, char*, int));
// ISteamClient
VIRTUAL(void*) ISteamClient_GetISteamApps(PARAMS(HSteamUser, HSteamPipe, const char*));
VIRTUAL(void*) ISteamClient_GetISteamUser(PARAMS(HSteamUser, HSteamPipe, const char*));
VIRTUAL(void*) ISteamClient_GetISteamGenericInterface(PARAMS(HSteamUser, HSteamPipe, const char*));
VIRTUAL(void*) ISteamClient_GetISteamInventory(PARAMS(HSteamUser, HSteamPipe, const char*));
VIRTUAL(void*) ISteamClient_GetISteamApps
(PARAMS(HSteamUser, HSteamPipe, const char*));
VIRTUAL(void*) ISteamClient_GetISteamUser
(PARAMS(HSteamUser, HSteamPipe, const char*));
VIRTUAL(void*) ISteamClient_GetISteamGenericInterface
(PARAMS(HSteamUser, HSteamPipe, const char*));
VIRTUAL(void*) ISteamClient_GetISteamInventory
(PARAMS(HSteamUser, HSteamPipe, const char*));
// ISteamInventory
VIRTUAL(EResult) ISteamInventory_GetResultStatus(PARAMS(SteamInventoryResult_t));
VIRTUAL(bool)
ISteamInventory_GetResultItems(PARAMS(SteamInventoryResult_t, SteamItemDetails_t*, uint32_t*));
VIRTUAL(bool)
ISteamInventory_GetResultItemProperty(
PARAMS(SteamInventoryResult_t, uint32_t, const char*, char*, uint32_t*)
VIRTUAL (EResult) ISteamInventory_GetResultStatus(PARAMS(SteamInventoryResult_t));
VIRTUAL(bool) ISteamInventory_GetResultItems
(
PARAMS(SteamInventoryResult_t, SteamItemDetails_t*, uint32_t*) // @formatter:off
); // @formatter:on
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_GetItemsByID(PARAMS(SteamInventoryResult_t*, const SteamItemInstanceID_t*, uint32_t)
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
)
);
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
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)
### C++ preprocessor library
CPMAddPackage("gh:danmar/simplecpp#1.5.2")
target_include_directories(simplecpp_obj INTERFACE ${simplecpp_SOURCE_DIR})
### Thread pool library
CPMAddPackage(
@@ -34,5 +29,4 @@ add_executable(steamworks_parser steamworks_parser.cpp)
target_link_libraries(steamworks_parser PRIVATE
KoalaBox
BS_thread_pool
simplecpp_obj
)

View File

@@ -24,7 +24,7 @@ namespace {
constexpr auto length = 16;
std::string result;
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)];
}
@@ -41,18 +41,21 @@ namespace {
}
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) {
if (name.starts_with("sdk/public/steam/") && name.ends_with(".h")) {
kb::zip::extract_files(
zip_file_path,
[&](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) {
return unzip_dir / "binaries" / fs::path(name).filename();
}
return fs::path();
});
}
);
}
void download_sdk(const fs::path& steamworks_dir, const std::string_view& version) {
@@ -68,13 +71,12 @@ namespace {
try {
const auto unzip_dir = steamworks_dir / version;
unzip_sdk(zip_file_path, unzip_dir);
} catch (std::exception& e) {
} catch(std::exception& e) {
std::cerr << "Unzip error: " << e.what() << std::endl;
}
fs::remove(zip_file_path);
}
} // namespace
/**
@@ -82,21 +84,21 @@ namespace {
* for further processing by other tools.
*/
int wmain(const int argc, const wchar_t** argv) { // NOLINT(*-use-internal-linkage)
if (argc == 1) {
if(argc == 1) {
print_help();
return 0;
}
const auto steamworks_dir = std::filesystem::current_path() / "steamworks";
if (argc == 2) {
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)) {
if(argc == 2) {
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)) {
const auto filename = entry.path().filename().string();
const std::regex re(R"(steamworks_sdk_(.+)\.zip)");
if (std::smatch match; std::regex_match(filename, match, re)) {
if (match.size() > 1) {
if(std::smatch match; std::regex_match(filename, match, re)) {
if(match.size() > 1) {
const auto& version = match[1].str();
unzip_sdk(entry.path(), steamworks_dir / version);
}
@@ -107,12 +109,12 @@ 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]);
try {
download_sdk(steamworks_dir, version);
} catch (const std::exception& e) {
} catch(const std::exception& e) {
LOG_ERROR("Error downloading SDK '{}'. Reason: {}", version, e.what());
}
}

View File

@@ -3,11 +3,11 @@
#include <filesystem>
#include <fstream>
#include <functional>
#include <set>
#include <BS_thread_pool.hpp>
#include <cpp-tree-sitter.h>
#undef ERROR // Workaround for the ERROR enum defined in simplecpp
#include <simplecpp.h>
#include <nlohmann/json.hpp>
#include <koalabox/io.hpp>
#include <koalabox/logger.hpp>
@@ -20,7 +20,7 @@ namespace {
namespace kb = koalabox;
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);
}
@@ -35,31 +35,39 @@ namespace {
nlohmann::ordered_json current_lookup = {};
std::string interface_version;
kb::parser::walk(root, [&](const auto& current_node) {
kb::parser::walk(
root,
[&](const auto& current_node) {
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;
[[maybe_unused]] int vt_idx = 0;
kb::parser::walk(current_node, [&](const ts::Node& class_node) {
kb::parser::walk(
current_node,
[&](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;
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);
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
@@ -69,17 +77,21 @@ namespace {
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") {
}
);
} 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")
@@ -87,7 +99,7 @@ namespace {
: kb::parser::visit_result::Stop;
}
if (preproc_node.getType() == "preproc_arg") {
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);
@@ -97,70 +109,27 @@ namespace {
}
return kb::parser::visit_result::Continue;
});
} else if (current_type == "translation_unit" || current_type == "preproc_ifdef") {
}
);
} 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
static std::mutex mutex;
if (not interface_version.empty()) {
const std::lock_guard lock(mutex);
static std::mutex section;
if(not
interface_version.empty()
)
{
const std::lock_guard lock(section);
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.
* This function does that in a very naive manner. Stupid, but works.
@@ -175,11 +144,14 @@ namespace {
return processed_contents;
}
void
parse_sdk(const fs::path& sdk_path, nlohmann::ordered_json& lookup, BS::thread_pool<>& pool) {
void parse_sdk(
const fs::path& sdk_path,
nlohmann::ordered_json& lookup,
BS::thread_pool<>& pool
) {
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());
return;
}
@@ -187,25 +159,28 @@ namespace {
LOG_INFO("Parsing SDK: {}", headers_dir.string());
// Go over each file in headers directory
for (const auto& entry : fs::directory_iterator(headers_dir)) {
if (const auto& header_path = entry.path(); header_path.extension() == ".h") {
const auto task = pool.submit_task([&, header_path] {
for(const auto& entry : fs::directory_iterator(headers_dir)) {
if(const auto& header_path = entry.path(); header_path.extension() == ".h") {
const auto task = pool.submit_task(
[&, header_path] {
try {
LOG_DEBUG("Parsing header: {}", header_path.string());
const auto processed_header = manually_preprocess_header(header_path);
parse_header(processed_header, lookup);
} catch (std::exception& e) {
} catch(std::exception& e) {
LOG_CRITICAL(e.what());
exit(-1);
}
});
}
);
}
}
}
void generate_lookup_json(
const fs::path& steamworks_dir, //
const fs::path& steamworks_dir,
//
const std::set<std::string>& sdk_filter
) {
nlohmann::ordered_json lookup;
@@ -217,13 +192,22 @@ namespace {
BS::thread_pool pool(thread_count);
// Go over each steamworks sdk version
for (const auto& entry : fs::directory_iterator(steamworks_dir)) {
if (not entry.is_directory()) {
for(const auto& entry : fs::directory_iterator(steamworks_dir)) {
if(not
entry.is_directory()
)
{
continue;
}
if (not sdk_filter.empty() and
not sdk_filter.contains(entry.path().filename().string())) {
if(not
sdk_filter.empty()
and
not sdk_filter
.
contains(entry.path().filename().string())
)
{
continue;
}
@@ -252,8 +236,8 @@ int wmain(const int argc, const wchar_t* argv[]) { // NOLINT(*-use-internal-link
koalabox::logger::init_console_logger();
std::set<std::string> sdk_filter;
if (argc > 1) {
for (auto i = 1; i < argc; i++) {
if(argc > 1) {
for(auto i = 1; i < argc; i++) {
const auto version = koalabox::str::to_str(argv[i]);
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");
if (!fs::exists(steamworks_dir)) {
if(!fs::exists(steamworks_dir)) {
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);
LOG_INFO("Finished parsing steamworks in {} seconds", elapsed.count());
} catch (std::exception& e) {
} catch(std::exception& e) {
LOG_CRITICAL("Error: {}", e.what());
return 1;
}