Skip to content

Commit

Permalink
add dsound version fix #25
Browse files Browse the repository at this point in the history
  • Loading branch information
muhopensores committed Dec 16, 2024
1 parent 1330920 commit 45dfafc
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 14 deletions.
26 changes: 24 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
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()
34 changes: 29 additions & 5 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -68,7 +85,12 @@ void WINAPI startup_thread() {
failed();
}
g_framework = std::make_unique<ModFramework>();
#else
#endif
#ifdef DSOUND_MODE
g_framework = std::make_unique<ModFramework>();
#ifdef NDEBUG
reframework::setup_exception_handler();
#endif
#endif
}

Expand Down Expand Up @@ -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;
}
18 changes: 11 additions & 7 deletions src/Mods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -40,7 +40,11 @@ Mods::Mods()
}

void Mods::load_time_critical_mods() {
#ifdef DINPUT_HOOK
m_mods.emplace_back(std::make_unique<GamepadsFix>());
#else
m_mods.emplace_back(std::make_unique<Mod>());
#endif
m_mods.emplace_back(std::make_unique<CustomAlolcator>());
//m_mods.emplace_back(std::make_unique<YourMod>());
}
Expand All @@ -49,7 +53,7 @@ void Mods::load_mods() {
#if 1
m_mods.emplace_back(std::make_unique<QuicksilverShader>());
m_mods.emplace_back(std::make_unique<AudioStutterFix>());
#ifndef SPEEDRUN_MODE
#if GAMEPLAY_HOOKS
m_mods.emplace_back(std::make_unique<InertiaThings>());
m_mods.emplace_back(std::make_unique<StyleSwitchFX>());
m_mods.emplace_back(std::make_unique<PracticeMode>()); // NOTE(): dont move this one [5]
Expand All @@ -59,9 +63,9 @@ void Mods::load_mods() {
m_mods.emplace_back(std::make_unique<Mod>());
m_mods.emplace_back(std::make_unique<Mod>());
m_mods.emplace_back(std::make_unique<Mod>());
#endif // !SPEEDRUN_MODE
#endif // !GAMEPLAY_HOOKS
m_mods.emplace_back(std::make_unique<UIButton>());
#ifndef SPEEDRUN_MODE
#if GAMEPLAY_HOOKS
m_mods.emplace_back(std::make_unique<InputLog>()); //NOTE(): dont move this one [8]
m_mods.emplace_back(std::make_unique<DebugDraw>()); //NOTE(): dont move this one [9]
m_mods.emplace_back(std::make_unique<RgTimer>()); //NOTE(): dont move this one [10]
Expand All @@ -78,16 +82,16 @@ void Mods::load_mods() {
m_mods.emplace_back(std::make_unique<Mod>());
m_mods.emplace_back(std::make_unique<Mod>());
m_mods.emplace_back(std::make_unique<Mod>());
#endif // !SPEEDRUN_MODE
#endif // !GAMEPLAY_HOOKS

//m_mods.emplace_back(std::make_unique<StyleSwitcherInfo>()); // crashes half the time on boot, will replace
m_mods.emplace_back(std::make_unique<EnemySpawnRate>()); // ldk

#ifndef SPEEDRUN_MODE
#if GAMEPLAY_HOOKS
m_mods.emplace_back(std::make_unique<AreaJump>());
#else
m_mods.emplace_back(std::make_unique<Mod>());
#endif // !SPEEDRUN_MODE
#endif // !GAMEPLAY_HOOKS


#endif
Expand Down

0 comments on commit 45dfafc

Please sign in to comment.