From 064765a95ed9c88cb420c673b5af8d65a134f46b Mon Sep 17 00:00:00 2001 From: zero318 Date: Sat, 15 Jun 2024 17:40:14 -0400 Subject: [PATCH] Fix steam integration, build_str warnings, and minor oversights --- thcrap/src/build_str.h | 33 ++++++++++++++------------------- thcrap/src/ntdll.h | 4 ++++ thcrap/src/steam.cpp | 2 +- thcrap/src/xpcompat.cpp | 5 ++++- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/thcrap/src/build_str.h b/thcrap/src/build_str.h index 4937ae33..381c9157 100644 --- a/thcrap/src/build_str.h +++ b/thcrap/src/build_str.h @@ -18,10 +18,6 @@ extern "C++" { #include #include -#pragma warning(push) -// MSVC is imagining things -#pragma warning(disable : 4305) - template> || std::is_same_v>, bool> = true, typename ... StrsT> static constexpr TH_FORCEINLINE T* build_str(T* buffer, const S& cur_str, StrsT&&... next_strs); template && std::is_same_v>, T> && std::is_integral_v && !std::is_same_v, bool> = true, typename ... StrsT> @@ -41,7 +37,7 @@ static constexpr TH_FORCEINLINE T* build_str(T* buffer, const S& cur_str, L cur_ buffer[i] = cur_str.data()[i]; } buffer += cur_len; - if constexpr (sizeof...(StrsT)) { + if constexpr ((bool)sizeof...(StrsT)) { return build_str(buffer, std::forward(next_strs)...); } else { if constexpr (null_terminate) { @@ -58,7 +54,7 @@ static constexpr TH_FORCEINLINE T* build_str(T* buffer, const S& cur_str, StrsT& buffer[i] = cur_str.data()[i]; } buffer += cur_len; - if constexpr (sizeof...(StrsT)) { + if constexpr ((bool)sizeof...(StrsT)) { return build_str(buffer, std::forward(next_strs)...); } else { if constexpr (null_terminate) { @@ -73,7 +69,7 @@ static constexpr TH_FORCEINLINE T* build_str(T* buffer, P cur_str, L cur_len, St buffer[i] = cur_str[i]; } buffer += cur_len; - if constexpr (sizeof...(StrsT)) { + if constexpr ((bool)sizeof...(StrsT)) { return build_str(buffer, std::forward(next_strs)...); } else { if constexpr (null_terminate) { @@ -84,7 +80,7 @@ static constexpr TH_FORCEINLINE T* build_str(T* buffer, P cur_str, L cur_len, St } template && std::is_same_v>, T>, bool>, typename ... StrsT> static constexpr TH_FORCEINLINE T* build_str(T* buffer, P cur_str, StrsT&&... next_strs) { - size_t length; + size_t length = 0; if constexpr (std::is_same_v) { length = strlen(cur_str); } else if constexpr (std::is_same_v) { @@ -94,7 +90,7 @@ static constexpr TH_FORCEINLINE T* build_str(T* buffer, P cur_str, StrsT&&... ne buffer[i] = cur_str[i]; } buffer += length; - if constexpr (sizeof...(StrsT)) { + if constexpr ((bool)sizeof...(StrsT)) { return build_str(buffer, std::forward(next_strs)...); } else { if constexpr (null_terminate) { @@ -110,7 +106,7 @@ static constexpr TH_FORCEINLINE T* build_str(T* buffer, const T(&cur_str)[N], L buffer[i] = cur_str[i]; } buffer += cur_len; - if constexpr (sizeof...(StrsT)) { + if constexpr ((bool)sizeof...(StrsT)) { return build_str(buffer, std::forward(next_strs)...); } else { if constexpr (null_terminate) { @@ -127,7 +123,7 @@ static constexpr TH_FORCEINLINE T* build_str(T* buffer, const T(&cur_str)[N], St buffer[i] = cur_str[i]; } buffer += N - 1; - if constexpr (sizeof...(StrsT)) { + if constexpr ((bool)sizeof...(StrsT)) { return build_str(buffer, std::forward(next_strs)...); } else { if constexpr (null_terminate) { @@ -139,7 +135,7 @@ static constexpr TH_FORCEINLINE T* build_str(T* buffer, const T(&cur_str)[N], St template static constexpr TH_FORCEINLINE T* build_str(T* buffer, T cur_char, StrsT&&... next_strs) { *buffer++ = cur_char; - if constexpr (sizeof...(StrsT)) { + if constexpr ((bool)sizeof...(StrsT)) { return build_str(buffer, std::forward(next_strs)...); } else { if constexpr (null_terminate) { @@ -162,7 +158,7 @@ static constexpr TH_FORCEINLINE size_t alloc_str_calc_len(size_t length, T cur_c template> || std::is_same_v>) && std::is_integral_v && !std::is_same_v, bool>, typename ... StrsT> static constexpr TH_FORCEINLINE size_t alloc_str_calc_len(size_t length, const S& cur_str, L cur_len, StrsT&&... next_strs) { length += cur_len; - if constexpr (sizeof...(StrsT)) { + if constexpr ((bool)sizeof...(StrsT)) { return alloc_str_calc_len(length, std::forward(next_strs)...); } else { return length; @@ -171,7 +167,7 @@ static constexpr TH_FORCEINLINE size_t alloc_str_calc_len(size_t length, const S template> || std::is_same_v>, bool>, typename ... StrsT> static constexpr TH_FORCEINLINE size_t alloc_str_calc_len(size_t length, const S& cur_str, StrsT&&... next_strs) { length += cur_str.length(); - if constexpr (sizeof...(StrsT)) { + if constexpr ((bool)sizeof...(StrsT)) { return alloc_str_calc_len(length, std::forward(next_strs)...); } else { return length; @@ -180,7 +176,7 @@ static constexpr TH_FORCEINLINE size_t alloc_str_calc_len(size_t length, const S template && std::is_same_v>, T> && std::is_integral_v && !std::is_same_v, bool>, typename ... StrsT> static constexpr TH_FORCEINLINE size_t alloc_str_calc_len(size_t length, P cur_str, L cur_len, StrsT&&... next_strs) { length += cur_len; - if constexpr (sizeof...(StrsT)) { + if constexpr ((bool)sizeof...(StrsT)) { return alloc_str_calc_len(length, std::forward(next_strs)...); } else { return length; @@ -189,7 +185,7 @@ static constexpr TH_FORCEINLINE size_t alloc_str_calc_len(size_t length, P cur_s template && !std::is_same_v, bool>, typename ... StrsT> static constexpr TH_FORCEINLINE size_t alloc_str_calc_len(size_t length, const T(&cur_str)[N], L cur_len, StrsT&&... next_strs) { length += cur_len; - if constexpr (sizeof...(StrsT)) { + if constexpr ((bool)sizeof...(StrsT)) { return alloc_str_calc_len(length, std::forward(next_strs)...); } else { return length; @@ -198,7 +194,7 @@ static constexpr TH_FORCEINLINE size_t alloc_str_calc_len(size_t length, const T template static constexpr TH_FORCEINLINE size_t alloc_str_calc_len(size_t length, const T(&cur_str)[N], StrsT&&... next_strs) { length += N - 1; // Assume this is coming from a string literal - if constexpr (sizeof...(StrsT)) { + if constexpr ((bool)sizeof...(StrsT)) { return alloc_str_calc_len(length, std::forward(next_strs)...); } else { return length; @@ -207,7 +203,7 @@ static constexpr TH_FORCEINLINE size_t alloc_str_calc_len(size_t length, const T template static constexpr TH_FORCEINLINE size_t alloc_str_calc_len(size_t length, T cur_char, StrsT&&... next_strs) { ++length; - if constexpr (sizeof...(StrsT)) { + if constexpr ((bool)sizeof...(StrsT)) { return alloc_str_calc_len(length, std::forward(next_strs)...); } else { return length; @@ -378,6 +374,5 @@ TH_CALLER_FREE static constexpr TH_FORCEINLINE T* alloc_str(StrsT&&... strs) { VLA(type, name, name##_len); \ (void)sprintf(name, (format), __VA_ARGS__) -#pragma warning(pop) } #endif diff --git a/thcrap/src/ntdll.h b/thcrap/src/ntdll.h index 6f36fa24..7b58d5a6 100644 --- a/thcrap/src/ntdll.h +++ b/thcrap/src/ntdll.h @@ -13,8 +13,12 @@ typedef LONG NTSTATUS; typedef LONG_PTR KPRIORITY; +#ifndef STATUS_SUCCESS #define STATUS_SUCCESS ((NTSTATUS)0L) +#endif +#ifndef STATUS_INVALID_INFO_CLASS #define STATUS_INVALID_INFO_CLASS ((NTSTATUS)0xC0000003L) +#endif // Tests whether or not a handle represents a "datafile" library load #define LDR_IS_DATAFILE(x) (((ULONG_PTR)(x)) & (ULONG_PTR)1) diff --git a/thcrap/src/steam.cpp b/thcrap/src/steam.cpp index 2578e696..67c209f1 100644 --- a/thcrap/src/steam.cpp +++ b/thcrap/src/steam.cpp @@ -61,7 +61,7 @@ extern "C" TH_EXPORT void steam_mod_post_init(void) } // Got AppID? - if (!appid.empty()) { + if (appid.empty()) { return; } diff --git a/thcrap/src/xpcompat.cpp b/thcrap/src/xpcompat.cpp index 568527fe..1d1a354f 100644 --- a/thcrap/src/xpcompat.cpp +++ b/thcrap/src/xpcompat.cpp @@ -85,7 +85,10 @@ HRESULT STDAPICALLTYPE PathMatchSpecExU_xp(LPCSTR pszFile, LPCSTR pszSpec, DWORD } static void initialize_path_match_spec_ex() { - HMODULE shlwapi_module = LoadLibraryW(L"shlwapi.dll"); + HMODULE shlwapi_module = GetModuleHandleW(L"shlwapi.dll"); + if unexpected(!shlwapi_module) { + shlwapi_module = LoadLibraryW(L"shlwapi.dll"); + } if (void* func_ex_w = (void*)GetProcAddress(shlwapi_module, "PathMatchSpecExW")) { PathMatchSpecExW_func = (PathMatchSpecExW_t)func_ex_w; PathMatchSpecExU_func = &PathMatchSpecExU;