Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions crates/victory-hle/src/modules/gameinput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1013,14 +1013,16 @@ extern "system" fn key_state(this: *const Reading, count: u32, out: *mut KeyStat
n as u32
}
extern "system" fn gamepad_state(this: *const Reading, out: *mut PadState) -> bool {
match &reading(this).value {
Value::Pad(state) if !out.is_null() => {
// SAFETY: checked non-null.
unsafe { out.write(*state) };
true
}
_ => false,
if out.is_null() {
return false;
}
let (state, is_gamepad) = match &reading(this).value {
Value::Pad(state) => (*state, true),
Value::Keys(_) => (PadState::default(), false),
};
// SAFETY: the title passes writable storage for the state.
unsafe { out.write(state) };
is_gamepad
}
/// Kinds our devices do not have: no count, no state.
extern "system" fn nothing(_: *const c_void) -> usize {
Expand Down Expand Up @@ -1508,8 +1510,9 @@ mod tests {
release(r);

let r = current(hub, GAMEPAD_KIND, FALLBACK).unwrap();
let mut state = pad(r);
assert_eq!(
pad(r),
state,
PadState {
buttons: A,
left_y: 1.0,
Expand All @@ -1521,6 +1524,11 @@ mod tests {
release(r);
// A keyboard reading is no gamepad reading.
assert_eq!(current(hub, GAMEPAD_KIND, KEYBOARD), Err(READING_NOT_FOUND));
let r = current(hub, KEYBOARD_KIND, KEYBOARD).unwrap();
let get = slot::<extern "system" fn(*const Reading, *mut PadState) -> bool, _>(r, 0xb0);
assert!(!get(r, &mut state));
assert_eq!(state, PadState::default());
release(r);
}

#[test]
Expand Down