Skip to content

Commit

Permalink
chore: update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
progre committed May 27, 2024
1 parent ec61e83 commit 939c61c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ winres = "0.1"

[dependencies]
encoding_rs = "0.8.31"
windows = { version = "0.43.0", features = [
windows = { version = "0.56.0", features = [
"Win32_Devices_HumanInterfaceDevice",
"Win32_Foundation",
"Win32_Media_Multimedia",
Expand Down
60 changes: 27 additions & 33 deletions src/dinput8_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use std::{
ffi::c_void,
fs::File,
mem::{size_of, transmute},
ptr::addr_of_mut,
};

use encoding_rs::SHIFT_JIS;
use windows::{
core::{IUnknown, Interface, GUID, HRESULT, HSTRING, PCWSTR},
s,
core::{s, IUnknown, Interface, GUID, HRESULT, HSTRING, PCWSTR},
Win32::{
Devices::HumanInterfaceDevice::{
IDirectInput8A, IDirectInput8W, IDirectInputDevice8A, IDirectInputDevice8W, DIJOYSTATE,
Expand Down Expand Up @@ -162,18 +162,16 @@ extern "system" fn i_direct_input_8_a_create_device_hook(
unsafe {
let direct_input_device = *out_direct_input_device;
let vtable = *(direct_input_device as *const _);
setup_method_hook(
vtable,
9,
i_direct_input_device_8_a_get_device_state_hook as _,
&mut ORIGINAL_I_DIRECT_INPUT_DEVICE_8_A_GET_DEVICE_STATE,
);
setup_method_hook(
vtable,
13,
i_direct_input_device_8_a_set_cooperative_level_hook as _,
&mut ORIGINAL_I_DIRECT_INPUT_DEVICE_8_A_SET_COOPERATIVE_LEVEL,
);

let hooked_method_addr = i_direct_input_device_8_a_get_device_state_hook as _;
let original_method_addr =
&mut *addr_of_mut!(ORIGINAL_I_DIRECT_INPUT_DEVICE_8_A_GET_DEVICE_STATE);
setup_method_hook(vtable, 9, hooked_method_addr, original_method_addr);

let hooked_method_addr = i_direct_input_device_8_a_set_cooperative_level_hook as _;
let original_method_addr =
&mut *addr_of_mut!(ORIGINAL_I_DIRECT_INPUT_DEVICE_8_A_SET_COOPERATIVE_LEVEL);
setup_method_hook(vtable, 13, hooked_method_addr, original_method_addr);
}
}

Expand Down Expand Up @@ -202,12 +200,10 @@ extern "system" fn i_direct_input_8_w_create_device_hook(
unsafe {
let direct_input_device = *out_direct_input_device;
let vtable = *(direct_input_device as *const _);
setup_method_hook(
vtable,
9,
i_direct_input_device_8_w_get_device_state_hook as _,
&mut ORIGINAL_I_DIRECT_INPUT_DEVICE_8_W_GET_DEVICE_STATE,
);
let hooked_method_addr = i_direct_input_device_8_w_get_device_state_hook as _;
let original_method_addr =
&mut *addr_of_mut!(ORIGINAL_I_DIRECT_INPUT_DEVICE_8_W_GET_DEVICE_STATE);
setup_method_hook(vtable, 9, hooked_method_addr, original_method_addr);
}
}

Expand Down Expand Up @@ -242,12 +238,10 @@ pub extern "system" fn DirectInput8Create(
unsafe {
let direct_input = *out;
let vtable = *(direct_input as *const _);
setup_method_hook(
vtable,
3,
i_direct_input_8_a_create_device_hook as _,
&mut ORIGINAL_I_DIRECT_INPUT_8_A_CREATE_DEVICE,
);
let hooked_method_addr = i_direct_input_8_a_create_device_hook as _;
let original_method_addr =
&mut *addr_of_mut!(ORIGINAL_I_DIRECT_INPUT_8_A_CREATE_DEVICE);
setup_method_hook(vtable, 3, hooked_method_addr, original_method_addr);
}
}
}
Expand All @@ -256,12 +250,10 @@ pub extern "system" fn DirectInput8Create(
unsafe {
let direct_input = *out;
let vtable = *(direct_input as *const _);
setup_method_hook(
vtable,
3,
i_direct_input_8_w_create_device_hook as _,
&mut ORIGINAL_I_DIRECT_INPUT_8_W_CREATE_DEVICE,
);
let hooked_method_addr = i_direct_input_8_w_create_device_hook as _;
let original_method_addr =
&mut *addr_of_mut!(ORIGINAL_I_DIRECT_INPUT_8_W_CREATE_DEVICE);
setup_method_hook(vtable, 3, hooked_method_addr, original_method_addr);
}
}
}
Expand All @@ -278,7 +270,9 @@ pub fn setup() {
PCWSTR::from_raw(buf.as_ptr()).to_string().unwrap()
};
let dll_path = format!("{}\\dinput8.dll", system_directory);
let dll_instance = unsafe { LoadLibraryW(PCWSTR::from(&HSTRING::from(dll_path))) }.unwrap();
let dll_instance =
unsafe { LoadLibraryW(PCWSTR::from_raw(HSTRING::from(dll_path).as_wide().as_ptr())) }
.unwrap();

if dll_instance.is_invalid() {
panic!();
Expand Down
8 changes: 7 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ mod modify_state;

use std::ffi::c_void;

use windows::Win32::{Foundation::HINSTANCE, System::SystemServices::DLL_PROCESS_ATTACH};
use windows::Win32::{
Foundation::HINSTANCE,
System::{Console::AllocConsole, SystemServices::DLL_PROCESS_ATTACH},
};

#[no_mangle]
pub extern "system" fn DllMain(
Expand All @@ -12,6 +15,9 @@ pub extern "system" fn DllMain(
_reserved: *const c_void,
) -> bool {
if reason == DLL_PROCESS_ATTACH {
if cfg!(debug_assertions) {
let _ = unsafe { AllocConsole() };
}
dinput8_hook::setup();
}
true
Expand Down

0 comments on commit 939c61c

Please sign in to comment.