From 5f8a74565df19f6e4a8218eeb6b65a81054ed164 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Sat, 6 Jul 2019 05:10:15 +1000 Subject: [PATCH] final fix for crashing --- DivaSound/src/dllmain.cpp | 31 +++---------------------------- DivaSound/src/framework.h | 6 ++++-- 2 files changed, 7 insertions(+), 30 deletions(-) diff --git a/DivaSound/src/dllmain.cpp b/DivaSound/src/dllmain.cpp index 0fba87b..19b5995 100644 --- a/DivaSound/src/dllmain.cpp +++ b/DivaSound/src/dllmain.cpp @@ -199,13 +199,14 @@ void hookedAudioInit(initClass *cls, uint64_t unk, uint64_t unk2) { // setup some variables instead of using the original init function divaAudCls->mixer = new audioMixer(); - divaAudCls->mixer->volume_mutex = new std::mutex(); divaAudCls->mixer->volume_master = 1.0f; divaAudCls->mixer->volume_channels[0] = 1.0f; divaAudCls->mixer->volume_channels[1] = 1.0f; divaAudCls->mixer->volume_channels[2] = 1.0f; divaAudCls->mixer->volume_channels[3] = 1.0f; divaAudCls->mixer->audioClass = divaAudCls; + + mtx_init(&divaAudCls->mixer->volume_mutex, 2); } divaAudioMixCls = divaAudCls->mixer; @@ -213,33 +214,7 @@ void hookedAudioInit(initClass *cls, uint64_t unk, uint64_t unk2) divaAudCls->channels = nChannels; // this could replace stereo patch divaAudCls->rate = 44100; // really does nothing divaAudCls->depth = bitDepth; // setting this to something other than 16 just removes output - - if (!useOldInit) - { - // just trying anything to get stability now - if (FAILED(CoCreateInstance(CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, IID_IMMDeviceEnumerator, (void**)&(divaAudCls->pEnumerator)))) - { - printf("[DivaSound] Dummy WASAPI enumerator creation failed\n"); - SAFE_RELEASE(divaAudCls->pEnumerator); - } - if (FAILED(divaAudCls->pEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &(divaAudCls->pDevice)))) - { - printf("[DivaSound] Dummy WASAPI device creation failed\n"); - SAFE_RELEASE(divaAudCls->pEnumerator); - SAFE_RELEASE(divaAudCls->pDevice); - } - if (FAILED(divaAudCls->pDevice->Activate(IID_IAudioClient, CLSCTX_ALL, NULL, (void**)&(divaAudCls->pAudioClient)))) - { - printf("[DivaSound] Dummy WASAPI device activation failed\n"); - SAFE_RELEASE(divaAudCls->pEnumerator); - SAFE_RELEASE(divaAudCls->pDevice); - SAFE_RELEASE(divaAudCls->pAudioClient); - } - } - if (!useOldInit) - { - //divaAudCls->hCallback = (HANDLE)39; - } + if (useAsio) { diff --git a/DivaSound/src/framework.h b/DivaSound/src/framework.h index cfc8da1..77b9b4e 100644 --- a/DivaSound/src/framework.h +++ b/DivaSound/src/framework.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include #define MINIAUDIO_IMPLEMENTATION #include #include @@ -24,6 +24,8 @@ int (__cdecl* divaAudioAllocMixer)(void* cls, uint64_t unk, uint64_t unk2, int64 // cls is the same as mixer in divaAudioFillbuffer // nFrames is number of audio frames to hold in the mixing buffers (only used when divaAudioFillbuffer is called). Internally this is multiplied by 16 (buffers are built using 32bit floats) +int(__cdecl* mtx_init)(void* mutex, int type) = (int(__cdecl*)(void* mutex, int type))0x14081DEF4; + #pragma pack(push, 1) struct _50 { byte padding00[0x50]; @@ -51,7 +53,7 @@ struct audioMixer { float* mixbuffer; uint64_t mixbuffer_size; - std::mutex* volume_mutex; // not sure if this is pointer or not + void* volume_mutex; // not sure if this is pointer or not float volume_master; float volume_channels[4];