From 45dfafc1f438bae41882ab5efc4e44a433d29428 Mon Sep 17 00:00:00 2001 From: muhopensores <58393267+muhopensores@users.noreply.github.com> Date: Mon, 16 Dec 2024 13:26:07 +0300 Subject: [PATCH] add dsound version fix #25 --- src/CMakeLists.txt | 26 ++++++++++++++++++++++++-- src/Main.cpp | 34 +++++++++++++++++++++++++++++----- src/Mods.cpp | 18 +++++++++++------- 3 files changed, 64 insertions(+), 14 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c2cffcb..fb6edc5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -148,8 +148,30 @@ target_compile_features(${CMAKE_PROJECT_NAME} PUBLIC cxx_std_17) include_directories(${CMAKE_PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}) set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES OUTPUT_NAME dinput8) -target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC DINPUT_HOOK) +target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC DINPUT_HOOK DINPUT_MODE) if(DEVELOPER_MODE) target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC DEVELOPER) target_compile_options(${CMAKE_PROJECT_NAME} PUBLIC /EHa) -endif() \ No newline at end of file +endif() + +add_library(dsound SHARED + Main.cpp + LicenseStrings.hpp + ${SDK_SRC} + ${MODS_SRC} + ${HOOKS_SRC} + ${IMGUI_SRC} + ${UTILITY_SRC} + ${FRAMEWORK_SRC} +) + +target_link_libraries(dsound PUBLIC imgui minhook glm_static shlwapi D3dx9 d3d9 SDL2main SDL2 meshoptimizer) +target_compile_features(dsound PUBLIC cxx_std_17) + +include_directories(dsound ${CMAKE_CURRENT_SOURCE_DIR}) +set_target_properties(dsound PROPERTIES OUTPUT_NAME dsound) +target_compile_definitions(dsound PUBLIC DSOUND_MODE) +if(DEVELOPER_MODE) + target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC DEVELOPER) + target_compile_options(${CMAKE_PROJECT_NAME} PUBLIC /EHa) +endif() diff --git a/src/Main.cpp b/src/Main.cpp index 649e844..5fb083f 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -10,9 +10,8 @@ static HMODULE g_dinput; static HMODULE g_styleswitcher; -//static Mod* g_renderer_replace{ nullptr }; -#if 1 +#ifdef DINPUT_MODE extern "C" { // DirectInput8Create wrapper for dinput8.dll __declspec(dllexport) HRESULT WINAPI direct_input8_create(HINSTANCE hinst, DWORD dw_version, const IID& riidltf, LPVOID* ppv_out, LPUNKNOWN punk_outer) { @@ -24,6 +23,24 @@ __declspec(dllexport) HRESULT WINAPI direct_input8_create(HINSTANCE hinst, DWORD } #endif +#ifdef DSOUND_MODE +#define DLLPATH "\\\\.\\GLOBALROOT\\SystemRoot\\SysWOW64\\dsound.dll" + +#pragma comment(linker, "/EXPORT:DirectSoundCaptureCreate=" DLLPATH ".DirectSoundCaptureCreate,@6") +#pragma comment(linker, "/EXPORT:DirectSoundCaptureCreate8=" DLLPATH ".DirectSoundCaptureCreate8,@12") +#pragma comment(linker, "/EXPORT:DirectSoundCaptureEnumerateA=" DLLPATH ".DirectSoundCaptureEnumerateA,@7") +#pragma comment(linker, "/EXPORT:DirectSoundCaptureEnumerateW=" DLLPATH ".DirectSoundCaptureEnumerateW,@8") +#pragma comment(linker, "/EXPORT:DirectSoundCreate=" DLLPATH ".DirectSoundCreate,@1") +#pragma comment(linker, "/EXPORT:DirectSoundCreate8=" DLLPATH ".DirectSoundCreate8,@11") +#pragma comment(linker, "/EXPORT:DirectSoundEnumerateA=" DLLPATH ".DirectSoundEnumerateA,@2") +#pragma comment(linker, "/EXPORT:DirectSoundEnumerateW=" DLLPATH ".DirectSoundEnumerateW,@3") +#pragma comment(linker, "/EXPORT:DirectSoundFullDuplexCreate=" DLLPATH ".DirectSoundFullDuplexCreate,@10") +#pragma comment(linker, "/EXPORT:DllCanUnloadNow=" DLLPATH ".DllCanUnloadNow,PRIVATE") +#pragma comment(linker, "/EXPORT:DllGetClassObject=" DLLPATH ".DllGetClassObject,PRIVATE") +#pragma comment(linker, "/EXPORT:GetDeviceID=" DLLPATH ".GetDeviceID,@9") + +#endif + static constexpr uint64_t round_to_pow2_size(uint32_t minimum_size, uint32_t pow2_size) { uint64_t result = (minimum_size + pow2_size - 1) & ~(pow2_size - 1); return result; @@ -53,7 +70,7 @@ void WINAPI startup_thread() { #endif -#if 1 +#ifdef DINPUT_MODE wchar_t buffer[MAX_PATH]{0}; if (GetSystemDirectoryW(buffer, MAX_PATH) != 0) { // Load the original dinput8.dll @@ -68,7 +85,12 @@ void WINAPI startup_thread() { failed(); } g_framework = std::make_unique(); -#else +#endif +#ifdef DSOUND_MODE + g_framework = std::make_unique(); +#ifdef NDEBUG + reframework::setup_exception_handler(); +#endif #endif } @@ -187,7 +209,9 @@ BOOL APIENTRY DllMain(HMODULE handle, DWORD reason, LPVOID reserved) { } if (reason == DLL_PROCESS_DETACH) { FreeLibrary(g_styleswitcher); - FreeLibrary(g_dinput); + if (g_dinput) { + FreeLibrary(g_dinput); + } } return TRUE; } diff --git a/src/Mods.cpp b/src/Mods.cpp index 693f5c2..6d926b5 100644 --- a/src/Mods.cpp +++ b/src/Mods.cpp @@ -28,7 +28,7 @@ //#include "mods/StyleSwitcherInfo.hpp" //#include "mods/CameraHack.hpp" -#define SPEEDRUN_MODE 1 +#define GAMEPLAY_HOOKS 1 // NOTE(): set 0 for speedrunner build Mods::Mods() { @@ -40,7 +40,11 @@ Mods::Mods() } void Mods::load_time_critical_mods() { +#ifdef DINPUT_HOOK m_mods.emplace_back(std::make_unique()); +#else + m_mods.emplace_back(std::make_unique()); +#endif m_mods.emplace_back(std::make_unique()); //m_mods.emplace_back(std::make_unique()); } @@ -49,7 +53,7 @@ void Mods::load_mods() { #if 1 m_mods.emplace_back(std::make_unique()); m_mods.emplace_back(std::make_unique()); -#ifndef SPEEDRUN_MODE +#if GAMEPLAY_HOOKS m_mods.emplace_back(std::make_unique()); m_mods.emplace_back(std::make_unique()); m_mods.emplace_back(std::make_unique()); // NOTE(): dont move this one [5] @@ -59,9 +63,9 @@ void Mods::load_mods() { m_mods.emplace_back(std::make_unique()); m_mods.emplace_back(std::make_unique()); m_mods.emplace_back(std::make_unique()); -#endif // !SPEEDRUN_MODE +#endif // !GAMEPLAY_HOOKS m_mods.emplace_back(std::make_unique()); -#ifndef SPEEDRUN_MODE +#if GAMEPLAY_HOOKS m_mods.emplace_back(std::make_unique()); //NOTE(): dont move this one [8] m_mods.emplace_back(std::make_unique()); //NOTE(): dont move this one [9] m_mods.emplace_back(std::make_unique()); //NOTE(): dont move this one [10] @@ -78,16 +82,16 @@ void Mods::load_mods() { m_mods.emplace_back(std::make_unique()); m_mods.emplace_back(std::make_unique()); m_mods.emplace_back(std::make_unique()); -#endif // !SPEEDRUN_MODE +#endif // !GAMEPLAY_HOOKS //m_mods.emplace_back(std::make_unique()); // crashes half the time on boot, will replace m_mods.emplace_back(std::make_unique()); // ldk -#ifndef SPEEDRUN_MODE +#if GAMEPLAY_HOOKS m_mods.emplace_back(std::make_unique()); #else m_mods.emplace_back(std::make_unique()); -#endif // !SPEEDRUN_MODE +#endif // !GAMEPLAY_HOOKS #endif