From 260be8e65a3100a073e82f886d5d6ea6cdcef1b3 Mon Sep 17 00:00:00 2001 From: praydog Date: Mon, 27 Nov 2023 22:43:53 -0800 Subject: [PATCH] SDK: Fix FName::to_string failure/crash edge case --- shared/sdk/FName.cpp | 11 ++++++++++- shared/sdk/FName.hpp | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/shared/sdk/FName.cpp b/shared/sdk/FName.cpp index c9a52e03..1199a9e2 100644 --- a/shared/sdk/FName.cpp +++ b/shared/sdk/FName.cpp @@ -264,7 +264,16 @@ std::optional 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"); } diff --git a/shared/sdk/FName.hpp b/shared/sdk/FName.hpp index 59dc2e8a..ea139f19 100644 --- a/shared/sdk/FName.hpp +++ b/shared/sdk/FName.hpp @@ -19,6 +19,10 @@ struct FName { using ToStringFn = TArray* (*)(const FName*, TArray*); static std::optional get_to_string(); + FName() + { + + } FName(std::wstring_view name, EFindName find_type = EFindName::Add); std::wstring to_string() const;