Skip to content

Commit

Permalink
Merge pull request #8 from TotemArts/feature/update-dependencies
Browse files Browse the repository at this point in the history
Update to new dependencies
  • Loading branch information
SonnyX authored Nov 22, 2023
2 parents 242f0d8 + 44edb26 commit 515cddd
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 36 deletions.
14 changes: 8 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "renxhook"
version = "0.1.0"
edition = "2018"
edition = "2021"

[lib]
name = "dinput8"
Expand All @@ -11,19 +11,18 @@ crate-type = ["cdylib"]

[dependencies]
anyhow = "1.0.51"
detour = { git = "https://github.com/Hpmason/detour-rs", branch = "fix-nightly1.67.0-changes" }
retour = { version = "0.3", features = ["static-detour"] }
lazy_static = "1.4.0"
libloading = "0.7.2"
libloading = "0.8.1"
sha2 = "0.10.0"
widestring = "1.0.2"
zerocopy = "0.6.1"
zerocopy = "0.7.26"
paste = "1.0.11"
region = "3.0.0"

[dependencies.windows]
version = "0.43.0"
version = "0.52.0"
features = [
"interface",
"implement",
"Data_Xml_Dom",
"Win32_Devices_HumanInterfaceDevice",
Expand All @@ -40,3 +39,6 @@ features = [
"Win32_Media_Audio_XAudio2",
"Win32_Media_Multimedia",
]

[dependencies.windows-interface]
version = "0.52.0"
2 changes: 1 addition & 1 deletion src/dinput8.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! This module handles functionality related to the original dinput8.dll
use windows::{
core::{IUnknown, Interface, GUID, HRESULT},
core::{IUnknown, ComInterface, GUID, HRESULT},
Win32::{
Devices::HumanInterfaceDevice::{CLSID_DirectInput8, IDirectInput8A, IDirectInput8W},
Foundation::{E_NOINTERFACE, HINSTANCE, S_OK},
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ fn dll_attach() -> anyhow::Result<()> {
let module = unsafe { GetModuleHandleA(None) }.context("failed to get module handle")?;

let exe_slice = get_module_slice(
&get_module_information(process, module).expect("Failed to get module information for UDK"),
&get_module_information(process, module.into()).expect("Failed to get module information for UDK"),
);

// Now that we're attached, let's hash the UDK executable.
// If the hash does not match what we think it should be, do not attach detours.
let exe_filename = get_module_filename(process, module)?;
let exe_filename = get_module_filename(process, module.into())?;

let mut exe = std::fs::File::open(exe_filename)?;
let hash = {
Expand Down
2 changes: 1 addition & 1 deletion src/udk_xaudio.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! This module contains functionality related to UDK XAudio hooks.
use anyhow::Context;
use detour::static_detour;
use retour::static_detour;

use crate::get_udk_slice;
use crate::udk_log::{log, LogType};
Expand Down
54 changes: 28 additions & 26 deletions src/xaudio27.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use windows::core::{implement, interface, IUnknown, IUnknown_Vtbl, GUID, HRESULT};
use windows::core::{implement, IUnknown, IUnknown_Vtbl, GUID, HRESULT};
use windows_interface::interface;
use windows::Win32::Foundation::{BOOL, E_FAIL, S_OK};
use windows::Win32::Media::Audio::XAudio2::{
IXAudio2, IXAudio2MasteringVoice, IXAudio2SourceVoice, IXAudio2SubmixVoice, IXAudio2Voice,
Expand All @@ -13,15 +14,16 @@ use windows::Win32::System::SystemInformation::NTDDI_WIN10;

use paste::paste;
use std::ffi::c_void;
use std::mem::ManuallyDrop;
use widestring::{WideCStr, WideChar};

use crate::udk_log;

fn debug_log(msg: std::fmt::Arguments) {
fn log_warning(msg: std::fmt::Arguments) {
let msg = std::fmt::format(msg);

// Log to the UDK.
udk_log::log(udk_log::LogType::Init, &msg);
udk_log::log(udk_log::LogType::Warning, &msg);

// Only bother logging when debug assertions are on.
#[cfg(debug_assertions)]
Expand Down Expand Up @@ -49,23 +51,23 @@ fn wstr_array<const N: usize>(src: &WideCStr) -> [u16; N] {

macro_rules! todo_log {
() => {
debug_log(std::format_args!(
"HOOK: unimplemented: {}:{}",
log_warning(std::format_args!(
"XAudio27 HOOK: unimplemented: {}:{}",
file!(),
line!()
));
};
($fmt:expr) => {
debug_log(std::format_args!(
concat!("HOOK: unimplemented: {}:{}: ", $fmt),
log_warning(std::format_args!(
concat!("XAudio27 HOOK: unimplemented: {}:{}: ", $fmt),
file!(),
line!(),
));
};

($fmt:expr, $($args:tt),*) => {
debug_log(std::format_args!(
concat!("HOOK: unimplemented: {}:{}: ", $fmt),
log_warning(std::format_args!(
concat!("XAudio27 HOOK: unimplemented: {}:{}: ", $fmt),
file!(),
line!(),
$($args),*
Expand Down Expand Up @@ -102,11 +104,11 @@ macro_rules! impl_iface {
}
impl ::core::convert::From<$implementation> for $iface {
fn from(this: $implementation) -> Self {
const VTABLE: <$iface as ::windows::core::Vtable>::Vtable =
<$iface as ::windows::core::Vtable>::Vtable::new::<$implementation>();
const VTABLE: <$iface as ::windows::core::Interface>::Vtable =
<$iface as ::windows::core::Interface>::Vtable::new::<$implementation>();

let this = [<$implementation _Impl>]::new(this);
let mut this = ::std::boxed::Box::into_raw(::std::boxed::Box::new(this));
let this = ::std::boxed::Box::into_raw(::std::boxed::Box::new(this));

let container = ::windows::core::ScopedHeap {
vtable: &VTABLE as *const _ as *const _,
Expand All @@ -126,8 +128,8 @@ macro_rules! impl_iface {
}
}
impl ::windows::core::AsImpl<$implementation> for $iface {
fn as_impl(&self) -> &$implementation {
let this = ::windows::core::Vtable::as_raw(self);
unsafe fn as_impl(&self) -> &$implementation {
let this = ::windows::core::Interface::as_raw(self);
unsafe {
let this = (this as *mut *mut ::core::ffi::c_void).sub(0 + 0)
as *mut [<$implementation _Impl>];
Expand Down Expand Up @@ -559,12 +561,12 @@ unsafe fn translate_send_list(sends: *const XAudio27VoiceSends) -> Vec<XAUDIO2_S

sends_out.push(XAUDIO2_SEND_DESCRIPTOR {
Flags: send.Flags,
pOutputVoice: Some(inner_voice),
pOutputVoice: ManuallyDrop::new(Some(inner_voice)),
})
} else {
sends_out.push(XAUDIO2_SEND_DESCRIPTOR {
Flags: send.Flags,
pOutputVoice: None,
pOutputVoice: ManuallyDrop::new(None),
})
}
}
Expand Down Expand Up @@ -872,7 +874,7 @@ impl IXAudio27MasteringVoice_Impl for XAudio27MasteringVoiceWrapper {
}

unsafe fn GetEffectState(&self, effect_index: u32, enabled_out: *mut BOOL) {
self.0.GetEffectState(effect_index, enabled_out).into()
*enabled_out = self.0.GetEffectState(effect_index).into()
}

unsafe fn SetEffectParameters(
Expand Down Expand Up @@ -909,7 +911,7 @@ impl IXAudio27MasteringVoice_Impl for XAudio27MasteringVoiceWrapper {
}

unsafe fn GetFilterParameters(&self, parameters: *mut XAUDIO2_FILTER_PARAMETERS) {
self.0.GetFilterParameters(parameters)
*parameters = self.0.GetFilterParameters()
}

unsafe fn SetOutputFilterParameters(
Expand All @@ -935,7 +937,7 @@ impl IXAudio27MasteringVoice_Impl for XAudio27MasteringVoiceWrapper {
}

unsafe fn GetVolume(&self, volume: *mut f32) {
self.0.GetVolume(volume)
*volume = self.0.GetVolume()
}

unsafe fn SetChannelVolumes(
Expand Down Expand Up @@ -1017,7 +1019,7 @@ impl IXAudio27SubmixVoice_Impl for XAudio27SubmixVoiceWrapper {
}

unsafe fn GetEffectState(&self, effect_index: u32, enabled_out: *mut BOOL) {
self.0.GetEffectState(effect_index, enabled_out).into()
*enabled_out = self.0.GetEffectState(effect_index).into()
}

unsafe fn SetEffectParameters(
Expand Down Expand Up @@ -1054,7 +1056,7 @@ impl IXAudio27SubmixVoice_Impl for XAudio27SubmixVoiceWrapper {
}

unsafe fn GetFilterParameters(&self, parameters: *mut XAUDIO2_FILTER_PARAMETERS) {
self.0.GetFilterParameters(parameters)
*parameters = self.0.GetFilterParameters()
}

unsafe fn SetOutputFilterParameters(
Expand All @@ -1080,7 +1082,7 @@ impl IXAudio27SubmixVoice_Impl for XAudio27SubmixVoiceWrapper {
}

unsafe fn GetVolume(&self, volume: *mut f32) {
self.0.GetVolume(volume)
*volume = self.0.GetVolume()
}

unsafe fn SetChannelVolumes(
Expand Down Expand Up @@ -1176,7 +1178,7 @@ impl IXAudio27SourceVoice_Impl for XAudio27SourceVoiceWrapper {
}

unsafe fn GetEffectState(&self, effect_index: u32, enabled_out: *mut BOOL) {
self.0.GetEffectState(effect_index, enabled_out).into()
*enabled_out = self.0.GetEffectState(effect_index).into()
}

unsafe fn SetEffectParameters(
Expand Down Expand Up @@ -1213,7 +1215,7 @@ impl IXAudio27SourceVoice_Impl for XAudio27SourceVoiceWrapper {
}

unsafe fn GetFilterParameters(&self, parameters: *mut XAUDIO2_FILTER_PARAMETERS) {
self.0.GetFilterParameters(parameters)
*parameters = self.0.GetFilterParameters()
}

unsafe fn SetOutputFilterParameters(
Expand All @@ -1239,7 +1241,7 @@ impl IXAudio27SourceVoice_Impl for XAudio27SourceVoiceWrapper {
}

unsafe fn GetVolume(&self, volume: *mut f32) {
self.0.GetVolume(volume)
*volume = self.0.GetVolume()
}

unsafe fn SetChannelVolumes(
Expand Down Expand Up @@ -1337,7 +1339,7 @@ impl IXAudio27SourceVoice_Impl for XAudio27SourceVoiceWrapper {
}

unsafe fn GetFrequencyRatio(&self, ratio: *mut f32) {
self.0.GetFrequencyRatio(ratio)
*ratio = self.0.GetFrequencyRatio()
}

unsafe fn SetSourceSampleRate(&self, new_sample_rate: u32) -> HRESULT {
Expand Down

0 comments on commit 515cddd

Please sign in to comment.