Skip to content

Commit

Permalink
SDK: Fix FName::to_string failure/crash edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Nov 28, 2023
1 parent 1dfa994 commit 260be8e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 10 additions & 1 deletion shared/sdk/FName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,16 @@ std::optional<FName::ToStringFn> inlined_find_to_string() try {
}

if (result) {
SPDLOG_INFO("FName::get_to_string (inlined alternative): result={:x}", (uintptr_t)*result);
const auto stdio_dll = GetModuleHandleW(L"api-ms-win-crt-stdio-l1-1-0.dll");
const auto vswprintf_func = stdio_dll != nullptr ? GetProcAddress(stdio_dll, "__stdio_common_vswprintf") : nullptr;

// Double checking that the function we just found isn't sprintf.
if (vswprintf_func != nullptr && utility::find_pointer_in_path((uintptr_t)*result, vswprintf_func, false)) {
SPDLOG_ERROR("FName::get_to_string (inlined): Wrong function found, vswprintf");
result = std::nullopt;
} else {
SPDLOG_INFO("FName::get_to_string (inlined alternative): result={:x}", (uintptr_t)*result);
}
} else {
SPDLOG_ERROR("FName::get_to_string (inlined alternative): Failed to find ToString function");
}
Expand Down
4 changes: 4 additions & 0 deletions shared/sdk/FName.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ struct FName {
using ToStringFn = TArray<wchar_t>* (*)(const FName*, TArray<wchar_t>*);
static std::optional<ToStringFn> get_to_string();

FName()
{

}
FName(std::wstring_view name, EFindName find_type = EFindName::Add);
std::wstring to_string() const;

Expand Down

0 comments on commit 260be8e

Please sign in to comment.