Fixed unicode paths

This commit is contained in:
acidicoala
2025-08-24 19:29:54 +05:00
parent e08cf014d1
commit 83d6df449c
11 changed files with 80 additions and 61 deletions

View File

@@ -34,6 +34,7 @@ set(SMOKE_API_STATIC_SOURCES
set(SMOKE_API_SOURCES set(SMOKE_API_SOURCES
${SMOKE_API_STATIC_SOURCES} ${SMOKE_API_STATIC_SOURCES}
src/steam_api/exports/steam_api.cpp src/steam_api/exports/steam_api.cpp
src/steam_api/exports/steam_api.hpp
src/steam_api/exports/steam_api_flat.cpp src/steam_api/exports/steam_api_flat.cpp
src/steam_api/exports/steam_api_internal.cpp src/steam_api/exports/steam_api_internal.cpp
src/steam_api/exports/steam_api_unversioned.cpp src/steam_api/exports/steam_api_unversioned.cpp
@@ -56,11 +57,6 @@ set(SMOKE_API_SOURCES
add_library(SmokeAPI_interface INTERFACE) add_library(SmokeAPI_interface INTERFACE)
# There is a weird MSVC bug where c++23 features are not enabled in x64 builds,
# while they are available in x86. I've no idea what causes this discrepancy,
# but manually setting the MSVC compiler option fixes this issue.
#target_compile_options(SmokeAPI_interface PUBLIC /std:c++latest)
target_include_directories(SmokeAPI_interface INTERFACE target_include_directories(SmokeAPI_interface INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/static>" "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/static>"
) )
@@ -71,17 +67,19 @@ target_link_libraries(SmokeAPI_interface INTERFACE KoalaBox $<TARGET_OBJECTS:Koa
add_library(SmokeAPI_static STATIC ${SMOKE_API_STATIC_SOURCES}) add_library(SmokeAPI_static STATIC ${SMOKE_API_STATIC_SOURCES})
target_link_libraries(SmokeAPI_static PUBLIC SmokeAPI_interface) target_link_libraries(SmokeAPI_static PUBLIC SmokeAPI_interface)
#target_include_directories(SmokeAPI_static PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/static")
### Shared SmokeAPI ### Shared SmokeAPI
add_library(SmokeAPI SHARED ${SMOKE_API_SOURCES}) add_library(SmokeAPI SHARED ${SMOKE_API_SOURCES})
target_link_libraries(SmokeAPI PUBLIC SmokeAPI_interface) target_link_libraries(SmokeAPI PUBLIC SmokeAPI_interface)
set_target_properties(SmokeAPI PROPERTIES RUNTIME_OUTPUT_NAME ${STEAMAPI_DLL}) set_target_properties(SmokeAPI PROPERTIES RUNTIME_OUTPUT_NAME ${STEAMAPI_DLL})
configure_version_resource(SmokeAPI "Free DLC for everyone ʕ ᵔᴥᵔʔ") configure_version_resource(
TARGET SmokeAPI
FILE_DESC "Steamworks DLC unlocker"
ORIG_NAME ${STEAMAPI_DLL}
)
target_include_directories(SmokeAPI PRIVATE target_include_directories(SmokeAPI PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/src" "${CMAKE_CURRENT_SOURCE_DIR}/src"
# "${CMAKE_CURRENT_SOURCE_DIR}/static"
"${CMAKE_CURRENT_BINARY_DIR}") "${CMAKE_CURRENT_BINARY_DIR}")
CPMAddPackage( CPMAddPackage(
@@ -98,7 +96,6 @@ configure_linker_exports(
DLL_FILES_GLOB "${CMAKE_CURRENT_SOURCE_DIR}/res/steamworks/*/binaries/${STEAM_API_DLL}" DLL_FILES_GLOB "${CMAKE_CURRENT_SOURCE_DIR}/res/steamworks/*/binaries/${STEAM_API_DLL}"
) )
# TODO: Why not add other compatible DLLs?
configure_linker_exports( configure_linker_exports(
TARGET SmokeAPI TARGET SmokeAPI
HEADER_NAME "linker_exports_for_version" HEADER_NAME "linker_exports_for_version"

View File

@@ -4,15 +4,18 @@
#include <koalabox/hook.hpp> #include <koalabox/hook.hpp>
#include <koalabox/loader.hpp> #include <koalabox/loader.hpp>
#include <koalabox/logger.hpp> #include <koalabox/logger.hpp>
#include <koalabox/path.hpp>
#include <koalabox/paths.hpp> #include <koalabox/paths.hpp>
#include <koalabox/str.hpp>
#include <koalabox/util.hpp> #include <koalabox/util.hpp>
#include <koalabox/win_util.hpp> #include <koalabox/win.hpp>
#include "build_config.h" #include "build_config.h"
#include "smoke_api.hpp" #include "smoke_api.hpp"
#include "smoke_api/config.hpp" #include "smoke_api/config.hpp"
#include "smoke_api/steamclient/steamclient.hpp" #include "smoke_api/steamclient/steamclient.hpp"
#include "steam_api/exports/steam_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:
@@ -51,7 +54,7 @@ namespace {
void init_proxy_mode() { void init_proxy_mode() {
LOG_INFO("Detected proxy mode"); LOG_INFO("Detected proxy mode");
const auto self_path = kb::paths::get_self_path(); const auto self_path = kb::paths::get_self_dir();
smoke_api::steamapi_module = kb::loader::load_original_library(self_path, STEAMAPI_DLL); smoke_api::steamapi_module = kb::loader::load_original_library(self_path, STEAMAPI_DLL);
} }
@@ -60,16 +63,26 @@ namespace {
kb::hook::init(true); kb::hook::init(true);
const std::vector<std::string> target_libraries{STEAMCLIENT_DLL, STEAMAPI_DLL};
kb::dll_monitor::init_listener( kb::dll_monitor::init_listener(
STEAMCLIENT_DLL, target_libraries,
[](const HMODULE& steamclient_module) { [&](const HMODULE& module_handle, const std::string& library_name) {
kb::hook::detour_or_warn( static auto hook_count = 0U;
steamclient_module,
"CreateInterface",
reinterpret_cast<uintptr_t>(CreateInterface)
);
kb::dll_monitor::shutdown_listener(); if(kb::str::eq(library_name, STEAMCLIENT_DLL)) {
KB_HOOK_DETOUR_MODULE(CreateInterface, module_handle);
hook_count++;
} else if(kb::str::eq(library_name, STEAMAPI_DLL)) {
KB_HOOK_DETOUR_MODULE(SteamAPI_RestartAppIfNecessary, module_handle);
KB_HOOK_DETOUR_MODULE(SteamAPI_Shutdown, module_handle);
hook_count++;
}
if(hook_count == target_libraries.size()) {
kb::dll_monitor::shutdown_listener();
}
} }
); );
} }
@@ -77,9 +90,9 @@ namespace {
namespace smoke_api { namespace smoke_api {
HMODULE steamapi_module = nullptr; HMODULE steamapi_module = nullptr;
bool hook_mode = false;
void init(const HMODULE module_handle) { void init(const HMODULE module_handle) {
// FIXME: IMPORTANT! Non ascii paths in directories will result in init errors
try { try {
kb::globals::init_globals(module_handle, PROJECT_NAME); kb::globals::init_globals(module_handle, PROJECT_NAME);
@@ -93,14 +106,15 @@ namespace smoke_api {
// compilation time stamp only when this file gets recompiled. // compilation time stamp only when this file gets recompiled.
LOG_INFO("{} v{} | Compiled at '{}'", PROJECT_NAME, PROJECT_VERSION, __TIMESTAMP__); LOG_INFO("{} v{} | Compiled at '{}'", PROJECT_NAME, PROJECT_VERSION, __TIMESTAMP__);
const fs::path exe_path = kb::win_util::get_module_file_name_or_throw(nullptr); const auto exe_path = kb::win::get_module_path(nullptr);
const auto exe_name = exe_path.filename().string(); const auto exe_name = kb::path::to_str(exe_path.filename());
LOG_DEBUG("Process name: '{}' [{}-bit]", exe_name, kb::util::BITNESS); LOG_DEBUG("Process name: '{}' [{}-bit]", exe_name, kb::util::BITNESS);
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)) {
hook_mode = true;
init_hook_mode(); init_hook_mode();
} else { } else {
init_proxy_mode(); init_proxy_mode();
@@ -115,7 +129,7 @@ namespace smoke_api {
void shutdown() { void shutdown() {
try { try {
if(steamapi_module != nullptr) { if(steamapi_module != nullptr) {
kb::win_util::free_library(steamapi_module); kb::win::free_library(steamapi_module);
steamapi_module = nullptr; steamapi_module = nullptr;
} }

View File

@@ -20,9 +20,17 @@ constexpr auto STEAM_INVENTORY = "STEAMINVENTORY_INTERFACE_V";
#define MODULE_CALL_CLOSURE(FUNC, ...) \ #define MODULE_CALL_CLOSURE(FUNC, ...) \
[&] { MODULE_CALL(FUNC, __VA_ARGS__); } [&] { MODULE_CALL(FUNC, __VA_ARGS__); }
#define AUTO_CALL(FUNC, ...) \
static const auto _##FUNC = smoke_api::hook_mode \
? KB_HOOK_GET_HOOKED_FN(FUNC) \
: KB_HOOK_GET_MODULE_FN(smoke_api::steamapi_module, FUNC); \
return _##FUNC(__VA_ARGS__)
namespace smoke_api { namespace smoke_api {
extern HMODULE steamapi_module; extern HMODULE steamapi_module;
extern bool hook_mode;
void init(HMODULE module_handle); void init(HMODULE module_handle);
void shutdown(); void shutdown();

View File

@@ -1,23 +1,20 @@
#include <koalabox/logger.hpp> #include <koalabox/logger.hpp>
#include "steam_api/exports/steam_api.hpp"
#include "smoke_api.hpp" #include "smoke_api.hpp"
#include "smoke_api/config.hpp" #include "smoke_api/config.hpp"
// TODO: Support in hook mode DLL_EXPORT(bool) SteamAPI_RestartAppIfNecessary(const AppId_t unOwnAppID) {
DLL_EXPORT(bool) SteamAPI_RestartAppIfNecessary(const uint32_t unOwnAppID) {
if(smoke_api::config::instance.override_app_id != 0) { 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;
} }
// Note: Assumes proxy mode only AUTO_CALL(SteamAPI_RestartAppIfNecessary, unOwnAppID);
MODULE_CALL(SteamAPI_RestartAppIfNecessary, unOwnAppID);
} }
// TODO: Support in hook mode
DLL_EXPORT(void) SteamAPI_Shutdown() { DLL_EXPORT(void) SteamAPI_Shutdown() {
LOG_INFO("{} -> Game requested shutdown", __func__); LOG_INFO("{} -> Game requested shutdown", __func__);
// Note: Assumes proxy mode only AUTO_CALL(SteamAPI_Shutdown);
MODULE_CALL(SteamAPI_Shutdown);
} }

View File

@@ -0,0 +1,8 @@
#pragma once
#include "smoke_api.hpp"
#include "smoke_api/types.hpp"
DLL_EXPORT(bool) SteamAPI_RestartAppIfNecessary(AppId_t unOwnAppID);
DLL_EXPORT(void) SteamAPI_Shutdown();

View File

@@ -3,7 +3,7 @@
#include <koalabox/logger.hpp> #include <koalabox/logger.hpp>
#include <koalabox/util.hpp> #include <koalabox/util.hpp>
#include <koalabox/win_util.hpp> #include <koalabox/win.hpp>
#include "smoke_api.hpp" #include "smoke_api.hpp"
#include "steam_api/steam_client.hpp" #include "steam_api/steam_client.hpp"
@@ -23,7 +23,7 @@ namespace {
if(not version_map.contains(version_prefix)) { if(not version_map.contains(version_prefix)) {
try { try {
const std::string rdata = kb::win_util::get_pe_section_data_or_throw( const std::string rdata = kb::win::get_pe_section_data_or_throw(
smoke_api::steamapi_module, smoke_api::steamapi_module,
".rdata" ".rdata"
); );

View File

@@ -6,7 +6,7 @@
#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.hpp>
#include "smoke_api.hpp" #include "smoke_api.hpp"
#include "virtuals/steam_api_virtuals.hpp" #include "virtuals/steam_api_virtuals.hpp"
@@ -113,7 +113,7 @@ namespace steam_interface {
namespace kb = koalabox; namespace kb = koalabox;
AppId_t get_app_id_or_throw() { AppId_t get_app_id_or_throw() {
const auto app_id_str = kb::win_util::get_env_var("SteamAppId"); const auto app_id_str = kb::win::get_env_var("SteamAppId");
return std::stoi(app_id_str); return std::stoi(app_id_str);
} }

View File

@@ -17,11 +17,7 @@ target_include_directories(BS_thread_pool INTERFACE ${BS_thread_pool_SOURCE_DIR}
### Steamworks Downloader executable ### Steamworks Downloader executable
add_executable(steamworks_downloader steamworks_downloader.cpp) add_executable(steamworks_downloader steamworks_downloader.cpp)
target_link_libraries(steamworks_downloader PRIVATE target_link_libraries(steamworks_downloader PRIVATE KoalaBox)
KoalaBox
cpr # HTTP client
miniz # ZIP library TODO: Use koalabox instead
)
### Steamworks Parser executable ### Steamworks Parser executable

View File

@@ -6,6 +6,7 @@
#include <koalabox/http_client.hpp> #include <koalabox/http_client.hpp>
#include <koalabox/logger.hpp> #include <koalabox/logger.hpp>
#include <koalabox/path.hpp>
#include <koalabox/str.hpp> #include <koalabox/str.hpp>
#include <koalabox/zip.hpp> #include <koalabox/zip.hpp>
@@ -91,10 +92,12 @@ int wmain(const int argc, const wchar_t** argv) { // NOLINT(*-use-internal-linka
const auto steamworks_dir = std::filesystem::current_path() / "steamworks"; const auto steamworks_dir = std::filesystem::current_path() / "steamworks";
// Special case. If there is a directory with a bunch of SDKs downloaded,
// then we can just provide it as a single argument
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 = kb::path::to_str(entry.path().filename());
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)) {

View File

@@ -12,8 +12,8 @@
#include <koalabox/io.hpp> #include <koalabox/io.hpp>
#include <koalabox/logger.hpp> #include <koalabox/logger.hpp>
#include <koalabox/parser.hpp> #include <koalabox/parser.hpp>
#include <koalabox/path.hpp>
#include <koalabox/str.hpp> #include <koalabox/str.hpp>
#include <koalabox/util.hpp>
namespace { namespace {
namespace fs = std::filesystem; namespace fs = std::filesystem;
@@ -123,8 +123,7 @@ namespace {
static std::mutex section; static std::mutex section;
if(not if(not
interface_version.empty() interface_version.empty()
) ) {
{
const std::lock_guard lock(section); const std::lock_guard lock(section);
lookup[interface_version] = current_lookup; lookup[interface_version] = current_lookup;
} }
@@ -150,13 +149,14 @@ namespace {
BS::thread_pool<>& pool BS::thread_pool<>& pool
) { ) {
const auto headers_dir = sdk_path / "headers\\steam"; const auto headers_dir = sdk_path / "headers\\steam";
const auto headers_dir_str = kb::path::to_str(headers_dir);
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/steam' directory: {}", headers_dir_str);
return; return;
} }
LOG_INFO("Parsing SDK: {}", headers_dir.string()); LOG_INFO("Parsing SDK: {}", headers_dir_str);
// 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)) {
@@ -164,7 +164,7 @@ namespace {
const auto task = pool.submit_task( const auto task = pool.submit_task(
[&, header_path] { [&, header_path] {
try { try {
LOG_DEBUG("Parsing header: {}", header_path.string()); LOG_DEBUG("Parsing header: {}", kb::path::to_str(header_path));
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);
@@ -193,21 +193,14 @@ namespace {
// 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 if(not entry.is_directory()) {
entry.is_directory()
)
{
continue; continue;
} }
if(not if(
sdk_filter.empty() not sdk_filter.empty() and
and not sdk_filter.contains(kb::path::to_str(entry.path().filename()))
not sdk_filter ) {
.
contains(entry.path().filename().string())
)
{
continue; continue;
} }
@@ -222,7 +215,10 @@ namespace {
std::ofstream lookup_output(interface_lookup_path); std::ofstream lookup_output(interface_lookup_path);
lookup_output << std::setw(4) << lookup; lookup_output << std::setw(4) << lookup;
LOG_INFO("Interface lookup generated at: {}", fs::absolute(interface_lookup_path).string()); LOG_INFO(
"Interface lookup generated at: {}",
kb::path::to_str(fs::absolute(interface_lookup_path))
);
} }
} }