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 <filip.bartos07@proton.me>
This commit is contained in:
parent
17217a3968
commit
cfc53081ff
|
@ -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"
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
public Audio_GetParentEvent
|
||||
|
||||
.code
|
||||
Audio_GetParentEvent proc
|
||||
mov rax, r12
|
||||
ret
|
||||
Audio_GetParentEvent endp
|
||||
end
|
|
@ -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_ptr<EventOver
|
|||
return true; // good to go
|
||||
}
|
||||
|
||||
// forward declare
|
||||
bool __declspec(noinline) __fastcall LoadSampleMetadata_Internal(
|
||||
uintptr_t parentEvent, void* sample, void* audioBuffer, unsigned int audioBufferLength, int audioType);
|
||||
|
||||
// DO NOT TOUCH THIS FUNCTION
|
||||
// The actual logic of it in a separate function (forcefully not inlined) to preserve the r12 register, which holds the event pointer.
|
||||
// clang-format off
|
||||
AUTOHOOK(LoadSampleMetadata, mileswin64.dll + 0xF110,
|
||||
bool, __fastcall, (void* sample, void* audioBuffer, unsigned int audioBufferLength, int audioType))
|
||||
// clang-format on
|
||||
{
|
||||
uintptr_t parentEvent = (uintptr_t)Audio_GetParentEvent();
|
||||
|
||||
// Raw source, used for voice data only
|
||||
if (audioType == 0)
|
||||
return LoadSampleMetadata(sample, audioBuffer, audioBufferLength, audioType);
|
||||
|
||||
return LoadSampleMetadata_Internal(parentEvent, sample, audioBuffer, audioBufferLength, audioType);
|
||||
}
|
||||
|
||||
// DO NOT INLINE THIS FUNCTION
|
||||
// See comment below.
|
||||
bool __declspec(noinline) __fastcall LoadSampleMetadata_Internal(
|
||||
uintptr_t parentEvent, void* sample, void* audioBuffer, unsigned int audioBufferLength, int audioType)
|
||||
{
|
||||
char* eventName = (char*)parentEvent + 0x110;
|
||||
const char* eventName = pszAudioEventName;
|
||||
|
||||
if (Cvar_ns_print_played_sounds->GetInt() > 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<const char*>((*((__int64*)a2 + 6)));
|
||||
return sub_1800294C0(a1, a2);
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
AUTOHOOK(MilesLog, client.dll + 0x57DAD0,
|
||||
void, __fastcall, (int level, const char* string))
|
||||
|
|
Loading…
Reference in New Issue