Some logging, cleanup

This commit is contained in:
goaaats 2025-12-06 15:14:13 +01:00
parent e09c43b8de
commit 446c7e3877
2 changed files with 18 additions and 14 deletions

View file

@ -336,9 +336,11 @@ 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 // 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. // 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. // Ideally all of this will go away once they get to it.
static std::shared_ptr<hooks::global_import_hook<decltype(ReportEventW)>> s_hook; static std::shared_ptr<hooks::global_import_hook<decltype(ReportEventW)>> s_report_event_hook;
s_hook = std::make_shared<hooks::global_import_hook<decltype(ReportEventW)>>("advapi32.dll!ReportEventW (global import, hook_clr_report_event)", L"advapi32.dll", "ReportEventW"); s_report_event_hook = std::make_shared<hooks::global_import_hook<decltype(ReportEventW)>>(
s_hook->set_detour([hook = s_hook.get()]( HANDLE hEventLog, "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 wType,
WORD wCategory, WORD wCategory,
DWORD dwEventID, DWORD dwEventID,
@ -349,6 +351,7 @@ HRESULT WINAPI InitializeImpl(LPVOID lpParam, HANDLE hMainThreadContinue) {
LPVOID lpRawData)-> BOOL { LPVOID lpRawData)-> BOOL {
// Check for CLR Error Event IDs // 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 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 != 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 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; return original_ret;
}); });
logging::I("ReportEventW hook installed.");
// ============================== Dalamud ==================================== // // ============================== Dalamud ==================================== //

View file

@ -449,9 +449,9 @@ bool veh::remove_handler()
return false; 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); const auto info_size = std::min(info.size(), std::size(g_external_event_info) - 1);
wcsncpy_s(g_external_event_info, errorMessage.c_str(), info_size); wcsncpy_s(g_external_event_info, info.c_str(), info_size);
RaiseException(CUSTOM_EXCEPTION_EXTERNAL_EVENT, 0, 0, nullptr); RaiseException(CUSTOM_EXCEPTION_EXTERNAL_EVENT, 0, 0, nullptr);
} }