Skip to content

Commit

Permalink
hack to make custom snd driver stop sounds on exiting cCustomize screen
Browse files Browse the repository at this point in the history
  • Loading branch information
muhopensores committed Jan 2, 2023
1 parent 7aa7257 commit 85d34d4
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
6 changes: 6 additions & 0 deletions build_vs2022_debug.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mkdir build86
cd build86
cmake .. -G "Visual Studio 17 2022" -A "Win32"
cmake --build . --config Debug
cd ..
PAUSE
6 changes: 6 additions & 0 deletions build_vs2022_release.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mkdir build86
cd build86
cmake .. -G "Visual Studio 17 2022" -A "Win32"
cmake --build . --config Release
cd ..
PAUSE
32 changes: 32 additions & 0 deletions src/mods/AudioStutterFix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,34 @@ void AudioStutterFix::on_draw_ui() {
};
}
#else
#include "sdk/VoxObj.hpp"

struct Devil3BgmChannels {
// NOTE(): initialized in dmc3se.exe WinMain
VoxObj* channel[4];
size_t num_channels;
};
Devil3BgmChannels* game_snd_channels{ nullptr };
FunctionHook* cCustomize_hack{ nullptr }; // cCustomize screen doesnt stop the bgm for some reason
uintptr_t c_cusomize_return = 0x00444190; // dmc3se.exe+44190 - 85 F6 - test esi,esi

static void stop_sound() {
if (!game_snd_channels) { return; }
/*for (size_t i = 0; i < game_snd_channels->num_channels; i++) {
}*/
game_snd_channels->channel[0]->pause();
}

__declspec(naked) void c_cusomize_detour() {
__asm {
pushad
call stop_sound
popad
push 0000017Ah
jmp DWORD PTR [c_cusomize_return]
}
}

std::optional<std::string> AudioStutterFix::on_initialize() {

Expand Down Expand Up @@ -229,6 +257,10 @@ std::optional<std::string> AudioStutterFix::on_initialize() {
m_disable_sleep1 = new Patch(0x00404987, bytes, true);
m_disable_sleep2 = new Patch(0x00404998, bytes, true);

game_snd_channels = (Devil3BgmChannels*)0x0832DBC;
cCustomize_hack = new FunctionHook(0x0044418B, &c_cusomize_detour);
cCustomize_hack->create();

return Mod::on_initialize();
}

Expand Down

0 comments on commit 85d34d4

Please sign in to comment.