diff --git a/src/unrealsdk/commands.cpp b/src/unrealsdk/commands.cpp index 11518a9..06f882a 100644 --- a/src/unrealsdk/commands.cpp +++ b/src/unrealsdk/commands.cpp @@ -81,7 +81,7 @@ namespace impl { #ifndef UNREALSDK_IMPORTING bool is_command_valid(std::wstring_view line, bool direct_user_input) { - if (direct_user_input && commands.find(NEXT_LINE) != commands.end()) { + if (direct_user_input && commands.contains(NEXT_LINE)) { return true; } auto non_space = std::ranges::find_if_not(line, &std::iswspace); diff --git a/src/unrealsdk/game/bl1/bl1.cpp b/src/unrealsdk/game/bl1/bl1.cpp index e824f5a..355564d 100644 --- a/src/unrealsdk/game/bl1/bl1.cpp +++ b/src/unrealsdk/game/bl1/bl1.cpp @@ -43,7 +43,7 @@ void BL1Hook::post_init(void) { namespace { -#if defined(__MINGW32__) +#ifdef __MINGW32__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wattributes" // thiscall on non-class #endif @@ -59,7 +59,7 @@ const constinit Pattern<11> GNATIVES_SIG{ typedef void(__thiscall* fframe_step_func)(UObject*, FFrame*, void*); fframe_step_func** fframe_step_gnatives; -#if defined(__MINGW32__) +#ifdef __MINGW32__ #pragma GCC diagnostic pop #endif @@ -78,7 +78,7 @@ void BL1Hook::fframe_step(FFrame* frame, UObject* obj, void* param) const { namespace { -#if defined(__MINGW32__) +#ifdef __MINGW32__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wattributes" // thiscall on non-class #endif @@ -115,7 +115,7 @@ typedef void(__thiscall* fname_init_func)(FName* name, fname_init_func fname_init_ptr = nullptr; -#if defined(__MINGW32__) +#ifdef __MINGW32__ #pragma GCC diagnostic pop #endif diff --git a/src/unrealsdk/game/bl1/memory.cpp b/src/unrealsdk/game/bl1/memory.cpp index 5eabfad..c1c399d 100644 --- a/src/unrealsdk/game/bl1/memory.cpp +++ b/src/unrealsdk/game/bl1/memory.cpp @@ -13,7 +13,7 @@ namespace unrealsdk::game { namespace { -#if defined(__MINGW32__) +#ifdef __MINGW32__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wattributes" // thiscall on non-class #endif @@ -29,7 +29,7 @@ struct FMalloc { FMallocVFtable* vftable; }; -#if defined(__MINGW32__) +#ifdef __MINGW32__ #pragma GCC diagnostic pop #endif diff --git a/src/unrealsdk/game/bl1/object.cpp b/src/unrealsdk/game/bl1/object.cpp index 2d0d54a..a9c5e41 100644 --- a/src/unrealsdk/game/bl1/object.cpp +++ b/src/unrealsdk/game/bl1/object.cpp @@ -68,7 +68,7 @@ UObject* BL1Hook::construct_object(UClass* cls, namespace { -#if defined(__MINGW32__) +#ifdef __MINGW32__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wattributes" // thiscall on non-class #endif @@ -78,7 +78,7 @@ typedef void(__thiscall* get_path_name_func)(const UObject* self, const UObject* stop_outer, ManagedFString* str); -#if defined(__MINGW32__) +#ifdef __MINGW32__ #pragma GCC diagnostic pop #endif diff --git a/src/unrealsdk/game/bl1/steamdrm.cpp b/src/unrealsdk/game/bl1/steamdrm.cpp index 13d7ff7..6954352 100644 --- a/src/unrealsdk/game/bl1/steamdrm.cpp +++ b/src/unrealsdk/game/bl1/steamdrm.cpp @@ -36,7 +36,7 @@ void GetStartupInfoA_hook(LPSTARTUPINFOA lpStartupInfo) { return; } - const std::lock_guard lock{ready_mutex}; + const std::scoped_lock lock{ready_mutex}; ready.store(true); ready_cv.notify_all(); } diff --git a/src/unrealsdk/game/bl2/bl2.cpp b/src/unrealsdk/game/bl2/bl2.cpp index 6ea61fc..7ae7d9a 100644 --- a/src/unrealsdk/game/bl2/bl2.cpp +++ b/src/unrealsdk/game/bl2/bl2.cpp @@ -42,7 +42,7 @@ void BL2Hook::post_init(void) { inject_console(); } -#if defined(__MINGW32__) +#ifdef __MINGW32__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wattributes" // thiscall on non-class #endif @@ -114,7 +114,7 @@ void BL2Hook::ftext_as_culture_invariant(unreal::FText* /*text*/, #pragma endregion -#if defined(__MINGW32__) +#ifdef __MINGW32__ #pragma GCC diagnostic pop #endif diff --git a/src/unrealsdk/game/bl2/memory.cpp b/src/unrealsdk/game/bl2/memory.cpp index e15b7c9..9863e7c 100644 --- a/src/unrealsdk/game/bl2/memory.cpp +++ b/src/unrealsdk/game/bl2/memory.cpp @@ -13,7 +13,7 @@ namespace unrealsdk::game { namespace { -#if defined(__MINGW32__) +#ifdef __MINGW32__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wattributes" // thiscall on non-class #endif @@ -29,7 +29,7 @@ struct FMalloc { FMallocVFtable* vftable; }; -#if defined(__MINGW32__) +#ifdef __MINGW32__ #pragma GCC diagnostic pop #endif diff --git a/src/unrealsdk/game/bl2/object.cpp b/src/unrealsdk/game/bl2/object.cpp index e52de5a..6939644 100644 --- a/src/unrealsdk/game/bl2/object.cpp +++ b/src/unrealsdk/game/bl2/object.cpp @@ -80,7 +80,7 @@ UObject* BL2Hook::construct_object(UClass* cls, namespace { -#if defined(__MINGW32__) +#ifdef __MINGW32__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wattributes" // thiscall on non-class #endif @@ -90,7 +90,7 @@ typedef void(__thiscall* get_path_name_func)(const UObject* self, const UObject* stop_outer, ManagedFString* str); -#if defined(__MINGW32__) +#ifdef __MINGW32__ #pragma GCC diagnostic pop #endif diff --git a/src/unrealsdk/game/tps/tps.cpp b/src/unrealsdk/game/tps/tps.cpp index 69531dd..caf807a 100644 --- a/src/unrealsdk/game/tps/tps.cpp +++ b/src/unrealsdk/game/tps/tps.cpp @@ -9,7 +9,7 @@ using namespace unrealsdk::unreal; namespace unrealsdk::game { -#if defined(__MINGW32__) +#ifdef __MINGW32__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wattributes" // thiscall on non-class #endif @@ -23,7 +23,7 @@ void TPSHook::fname_init(FName* name, const wchar_t* str, int32_t number) const reinterpret_cast(this->fname_init_ptr)(name, str, number, 1, 1, 0); } -#if defined(__MINGW32__) +#ifdef __MINGW32__ #pragma GCC diagnostic pop #endif diff --git a/src/unrealsdk/hook_manager.cpp b/src/unrealsdk/hook_manager.cpp index 8266915..fc139bf 100644 --- a/src/unrealsdk/hook_manager.cpp +++ b/src/unrealsdk/hook_manager.cpp @@ -137,7 +137,7 @@ std::mutex log_all_calls_stream_mutex{}; void log_all_calls(bool should_log) { // Only keep this file stream open while we need it if (should_log) { - const std::lock_guard lock(log_all_calls_stream_mutex); + const std::scoped_lock lock(log_all_calls_stream_mutex); log_all_calls_stream.open( utils::get_this_dll().parent_path() / config::get_str("unrealsdk.log_all_calls_file").value_or("unrealsdk.calls.tsv"), @@ -147,7 +147,7 @@ void log_all_calls(bool should_log) { should_log_all_calls = should_log; if (!should_log) { - const std::lock_guard lock(log_all_calls_stream_mutex); + const std::scoped_lock lock(log_all_calls_stream_mutex); log_all_calls_stream.close(); } } @@ -432,7 +432,7 @@ std::shared_ptr preprocess_hook(std::wstring_view source, func_name = func->get_path_name(); auto obj_name = obj->get_path_name(); - const std::lock_guard lock(log_all_calls_stream_mutex); + const std::scoped_lock lock(log_all_calls_stream_mutex); log_all_calls_stream << source << L'\t' << func_name << L'\t' << obj_name << L'\n'; } } diff --git a/src/unrealsdk/logging.cpp b/src/unrealsdk/logging.cpp index 7d0e9c6..f9c7671 100644 --- a/src/unrealsdk/logging.cpp +++ b/src/unrealsdk/logging.cpp @@ -67,7 +67,7 @@ std::vector all_log_callbacks{}; } { - const std::lock_guard callback_lock(callback_mutex); + const std::scoped_lock callback_lock(callback_mutex); while (!pending_messages.empty()) { auto msg = std::move(pending_messages.front()); pending_messages.pop(); @@ -289,7 +289,7 @@ void enqueue_log_msg(uint64_t unix_time_ms, size_t location_size, int line) { { - const std::lock_guard lock(pending_messages_mutex); + const std::scoped_lock lock(pending_messages_mutex); pending_messages.emplace(unix_time_ms, level, msg, msg_size, location, location_size, line); } pending_messages_available.notify_all(); @@ -305,13 +305,13 @@ bool set_console_level(Level level) { } void add_callback(log_callback callback) { - const std::lock_guard lock(callback_mutex); + const std::scoped_lock lock(callback_mutex); all_log_callbacks.push_back(callback); } void remove_callback(log_callback callback) { - const std::lock_guard lock(callback_mutex); + const std::scoped_lock lock(callback_mutex); auto [begin, end] = std::ranges::remove(all_log_callbacks, callback); all_log_callbacks.erase(begin, end); diff --git a/src/unrealsdk/unreal/structs/fframe.cpp b/src/unrealsdk/unreal/structs/fframe.cpp index 215ec74..2dfb10f 100644 --- a/src/unrealsdk/unreal/structs/fframe.cpp +++ b/src/unrealsdk/unreal/structs/fframe.cpp @@ -9,6 +9,7 @@ namespace unrealsdk::unreal { uint8_t* FFrame::extract_current_args(WrappedStruct& args) { auto args_addr = reinterpret_cast(args.base.get()); + // NOLINTNEXTLINE(misc-const-correctness) - see llvm/llvm-project#157320 uint8_t* original_code = this->Code; for (auto prop = reinterpret_cast(args.type->Children()); diff --git a/src/unrealsdk/unreal/structs/fscriptdelegate.cpp b/src/unrealsdk/unreal/structs/fscriptdelegate.cpp index 8275a98..5bbf49b 100644 --- a/src/unrealsdk/unreal/structs/fscriptdelegate.cpp +++ b/src/unrealsdk/unreal/structs/fscriptdelegate.cpp @@ -64,7 +64,7 @@ void FScriptDelegate::validate_signature(const std::optional& fun // Since delegates store the function name, make sure we can find this function again from just // it's name { - UFunction* func_from_find = nullptr; + const UFunction* func_from_find = nullptr; try { func_from_find = func->object->Class()->find_func_and_validate(func->func->Name()); } catch (const std::invalid_argument&) { diff --git a/src/unrealsdk/unreal/structs/fstring.cpp b/src/unrealsdk/unreal/structs/fstring.cpp index 7506984..86ea5bc 100644 --- a/src/unrealsdk/unreal/structs/fstring.cpp +++ b/src/unrealsdk/unreal/structs/fstring.cpp @@ -74,8 +74,10 @@ UnmanagedFString::operator std::wstring() const { return std::wstring{this->operator std::wstring_view()}; } UnmanagedFString::operator std::wstring_view() const { + // You'd think data == nullptr implies size == 0, but occasionally during game shutdown I've + // seen otherwise. auto size = this->size(); - if (size == 0) { + if (size == 0 || this->data == nullptr) { return L""; } diff --git a/src/unrealsdk/unrealsdk_main.cpp b/src/unrealsdk/unrealsdk_main.cpp index ddfe88a..0a7bc08 100644 --- a/src/unrealsdk/unrealsdk_main.cpp +++ b/src/unrealsdk/unrealsdk_main.cpp @@ -45,7 +45,7 @@ std::unordered_set unreal_allocations{}; #endif bool init(const std::function(void)>& game_getter) { - const std::lock_guard lock(init_mutex); + const std::scoped_lock lock(init_mutex); if (hook_instance != nullptr) { return false; @@ -75,12 +75,12 @@ bool init(const std::function(void)>& game_g } UNREALSDK_CAPI([[nodiscard]] bool, is_initialized) { - const std::lock_guard lock(init_mutex); + const std::scoped_lock lock(init_mutex); return hook_instance != nullptr; } UNREALSDK_CAPI([[nodiscard]] bool, is_console_ready) { - return hook_instance && hook_instance->is_console_ready(); + return is_initialized() && hook_instance->is_console_ready(); } UNREALSDK_CAPI([[nodiscard]] const GObjects*, gobjects) {