From cfc53081ff38a7a0e29cc0b89644760a7ade33a1 Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 23 Nov 2023 18:53:04 +0100 Subject: Replace audio event fetching with hook (#603) Takes the previous audio event code, which relied on reading out a register using masm, and replaces it with a new hook. Adapted from NorthstarPrime https://github.com/F1F7Y/NorthstarPrime Co-authored-by: F1F7Y --- NorthstarDLL/CMakeLists.txt | 1 - NorthstarDLL/audio_asm.asm | 8 -------- NorthstarDLL/client/audio.cpp | 33 +++++++++++---------------------- 3 files changed, 11 insertions(+), 31 deletions(-) delete mode 100644 NorthstarDLL/audio_asm.asm diff --git a/NorthstarDLL/CMakeLists.txt b/NorthstarDLL/CMakeLists.txt index 5c275887..d238f61f 100644 --- a/NorthstarDLL/CMakeLists.txt +++ b/NorthstarDLL/CMakeLists.txt @@ -148,7 +148,6 @@ add_library(NorthstarDLL SHARED "util/version.h" "util/wininfo.cpp" "util/wininfo.h" - "audio_asm.asm" "dllmain.cpp" "dllmain.h" "ns_version.h" diff --git a/NorthstarDLL/audio_asm.asm b/NorthstarDLL/audio_asm.asm deleted file mode 100644 index 1b2d3f8d..00000000 --- a/NorthstarDLL/audio_asm.asm +++ /dev/null @@ -1,8 +0,0 @@ -public Audio_GetParentEvent - -.code -Audio_GetParentEvent proc - mov rax, r12 - ret -Audio_GetParentEvent endp -end diff --git a/NorthstarDLL/client/audio.cpp b/NorthstarDLL/client/audio.cpp index 66d34404..aa32e390 100644 --- a/NorthstarDLL/client/audio.cpp +++ b/NorthstarDLL/client/audio.cpp @@ -10,11 +10,7 @@ AUTOHOOK_INIT() -extern "C" -{ - // should be called only in LoadSampleMetadata_Hook - extern void* __fastcall Audio_GetParentEvent(); -} +static const char* pszAudioEventName; ConVar* Cvar_mileslog_enable; ConVar* Cvar_ns_print_played_sounds; @@ -366,32 +362,16 @@ bool ShouldPlayAudioEvent(const char* eventName, const std::shared_ptrGetInt() > 0) spdlog::info("[AUDIO] Playing event {}", eventName); @@ -490,6 +470,15 @@ bool __declspec(noinline) __fastcall LoadSampleMetadata_Internal( return res; } +// clang-format off +AUTOHOOK(sub_1800294C0, mileswin64.dll + 0x294C0, +void*, __fastcall, (void* a1, void* a2)) +// clang-format on +{ + pszAudioEventName = reinterpret_cast((*((__int64*)a2 + 6))); + return sub_1800294C0(a1, a2); +} + // clang-format off AUTOHOOK(MilesLog, client.dll + 0x57DAD0, void, __fastcall, (int level, const char* string)) -- cgit v1.2.3