From 446c7e38771a943ac7b2dd9d5b48478f95d66250 Mon Sep 17 00:00:00 2001 From: goaaats Date: Sat, 6 Dec 2025 15:14:13 +0100 Subject: [PATCH] Some logging, cleanup --- Dalamud.Boot/dllmain.cpp | 26 +++++++++++++++----------- Dalamud.Boot/veh.cpp | 6 +++--- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Dalamud.Boot/dllmain.cpp b/Dalamud.Boot/dllmain.cpp index 2af78092d..687089f82 100644 --- a/Dalamud.Boot/dllmain.cpp +++ b/Dalamud.Boot/dllmain.cpp @@ -336,19 +336,22 @@ HRESULT WINAPI InitializeImpl(LPVOID lpParam, HANDLE hMainThreadContinue) { // This is pretty horrible - CLR just doesn't provide a way for us to handle these events, and the API for it // was pushed back to .NET 11, so we have to hook ReportEventW and catch them ourselves for now. // Ideally all of this will go away once they get to it. - static std::shared_ptr> s_hook; - s_hook = std::make_shared>("advapi32.dll!ReportEventW (global import, hook_clr_report_event)", L"advapi32.dll", "ReportEventW"); - s_hook->set_detour([hook = s_hook.get()]( HANDLE hEventLog, - WORD wType, - WORD wCategory, - DWORD dwEventID, - PSID lpUserSid, - WORD wNumStrings, - DWORD dwDataSize, - LPCWSTR* lpStrings, - LPVOID lpRawData)->BOOL { + static std::shared_ptr> s_report_event_hook; + s_report_event_hook = std::make_shared>( + "advapi32.dll!ReportEventW (global import, hook_clr_report_event)", L"advapi32.dll", "ReportEventW"); + s_report_event_hook->set_detour([hook = s_report_event_hook.get()]( + HANDLE hEventLog, + WORD wType, + WORD wCategory, + DWORD dwEventID, + PSID lpUserSid, + WORD wNumStrings, + DWORD dwDataSize, + LPCWSTR* lpStrings, + LPVOID lpRawData)-> BOOL { // Check for CLR Error Event IDs + // https://github.com/dotnet/runtime/blob/v10.0.0/src/coreclr/vm/eventreporter.cpp#L370 if (dwEventID != 1026 && // ERT_UnhandledException: The process was terminated due to an unhandled exception dwEventID != 1025 && // ERT_ManagedFailFast: The application requested process termination through System.Environment.FailFast dwEventID != 1023 && // ERT_UnmanagedFailFast: The process was terminated due to an internal error in the .NET Runtime @@ -371,6 +374,7 @@ HRESULT WINAPI InitializeImpl(LPVOID lpParam, HANDLE hMainThreadContinue) { return original_ret; }); + logging::I("ReportEventW hook installed."); // ============================== Dalamud ==================================== // diff --git a/Dalamud.Boot/veh.cpp b/Dalamud.Boot/veh.cpp index 24a846e66..25c9b5045 100644 --- a/Dalamud.Boot/veh.cpp +++ b/Dalamud.Boot/veh.cpp @@ -449,9 +449,9 @@ bool veh::remove_handler() return false; } -void veh::raise_external_event(const std::wstring& errorMessage) +void veh::raise_external_event(const std::wstring& info) { - const auto info_size = std::min(errorMessage.size(), std::size(g_external_event_info) - 1); - wcsncpy_s(g_external_event_info, errorMessage.c_str(), info_size); + const auto info_size = std::min(info.size(), std::size(g_external_event_info) - 1); + wcsncpy_s(g_external_event_info, info.c_str(), info_size); RaiseException(CUSTOM_EXCEPTION_EXTERNAL_EVENT, 0, 0, nullptr); }