Skip to content

Commit

Permalink
ui doesnt show at startup and remove snd->CreateVox() calls(its borke…
Browse files Browse the repository at this point in the history
…d sometimes)
  • Loading branch information
muhopensores committed Feb 24, 2023
1 parent 3ffb8a1 commit 4985c54
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/ModFramework.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class ModFramework {
bool m_first_frame{ true };
bool m_valid{ false };
bool m_initialized{ false };
bool m_draw_ui{ true };
bool m_draw_ui{ false };
bool m_draw_cursor{ true };
bool m_window_focused{ true };
std::atomic<bool> m_game_data_initialized{ false };
Expand Down
20 changes: 15 additions & 5 deletions src/mods/StyleSwitchFX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ static CPlDante* g_char_ptr = nullptr;
static cCameraCtrl* g_cam_ptr = nullptr;

#pragma comment(lib, "Winmm.lib")

#ifdef SND_HACK
#define SND_CREATE_VOX(name) VoxObj* name()
typedef SND_CREATE_VOX(snd_create_vox);
SND_CREATE_VOX(SndCreateVoxStub) {
return nullptr;
}
static snd_create_vox* SndCreateVox_ = SndCreateVoxStub;
#define SndCreateVox SndCreateVox_
#endif

// TODO(): ability to change vfx that's played ?
static int g_vfx_id = 218;
Expand Down Expand Up @@ -109,8 +110,9 @@ std::optional<std::string> StyleSwitchFX::on_initialize() {
g_char_ptr = (CPlDante*)0x1C8A600;
//g_cam_ptr = (CCameraCtrl*)0x01371978;

m_sound_file_mem = utility::DecompressFileFromMemory(sfx_compressed_data,sfx_compressed_size);
//m_sound_file_mem = utility::DecompressFileFromMemory(sfx_compressed_data,sfx_compressed_size);

#ifdef SND_TODO
HMODULE snd = GetModuleHandle("snd.drv");
if (!snd) {
spdlog::info("[StyleSwitchFX]: snd.drv not found\n");
Expand All @@ -135,11 +137,14 @@ std::optional<std::string> StyleSwitchFX::on_initialize() {
spdlog::info("Got VoxObj from snd.drv! Nice\n");
printf("Got VoxObj from snd.drv! Nice\n");
}
#endif
auto decompressed= utility::DecompressFileFromMemoryWithSize(sfx_compressed_data,sfx_compressed_size);
m_sound_file_mem = std::get<0>(decompressed);
m_sound_file_mem_size = std::get<1>(decompressed);
#ifdef SND_TODO
m_vox->load_mem((unsigned char*)m_sound_file_mem, m_sound_file_mem_size);
m_vox->set_volume(1.0f);
#endif
return Mod::on_initialize();
}

Expand Down Expand Up @@ -168,9 +173,7 @@ void StyleSwitchFX::on_frame() {
if ((g_char_ptr->pad_0000) != 0x744D38) { return; }
if (*current_style != prev_style) {
play_effect(*current_style);
if (g_enable_sound) {
play_sound();
}
play_sound();
prev_style = *current_style;
}
}
Expand All @@ -187,6 +190,7 @@ void StyleSwitchFX::on_draw_ui() {
ImGui::Checkbox("Enable style switch effects", &g_enable_mod);

ImGui::Checkbox("Enable sound effect", &g_enable_sound);
#if SND_TODO
if (m_vox != nullptr) {
static float snd_volume = 1.0f;
if (ImGui::DragFloat("Audio volume", &snd_volume,0.1f,0.0f,10.0f)) {
Expand All @@ -195,6 +199,7 @@ void StyleSwitchFX::on_draw_ui() {
}
ImGui::Checkbox("3D audio effects", &m_3d_audio);
}
#endif

ImGui::Text("Customize style colors");

Expand All @@ -205,6 +210,8 @@ void StyleSwitchFX::on_draw_ui() {

void StyleSwitchFX::play_sound()
{
if (!g_enable_sound) { return; }
#if SND_TODO
if (m_vox) {
cCameraCtrl* camera = Devil3SDK::get_cam_ctrl();
if (!camera || camera == (cCameraCtrl*)-1) { return; };
Expand All @@ -227,6 +234,9 @@ void StyleSwitchFX::play_sound()

}
else {
#endif
PlaySound((LPCSTR)m_sound_file_mem, NULL, SND_MEMORY | SND_ASYNC);
#ifdef SND_TODO
}
#endif
}
4 changes: 2 additions & 2 deletions src/mods/StyleSwitchFX.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ class StyleSwitchFX : public Mod {
void* m_sound_file_mem;
unsigned int m_sound_file_mem_size;
void play_sound();
VoxObj* m_vox = nullptr;
bool m_3d_audio = false;
//VoxObj* //m_vox = nullptr;
//bool m_3d_audio = false;
};

0 comments on commit 4985c54

Please sign in to comment.