From 5af6dfe3ffcfda3bf9fc5393b9df8c93720e8063 Mon Sep 17 00:00:00 2001 From: ashrafsdrop Date: Tue, 24 Nov 2026 22:23:38 +0600 Subject: [PATCH] XNetworking: wire UDP port change callbacks and UTF-16 security queries (cherry picked from commit 64a33ec757c1da0963a6821cd59995b8efabe946) --- crates/victory-hle/src/modules/xnetworking.rs | 101 +++++++++++++++--- 1 file changed, 85 insertions(+), 16 deletions(-) diff --git a/crates/victory-hle/src/modules/xnetworking.rs b/crates/victory-hle/src/modules/xnetworking.rs index c0b21a3..01bc552 100644 --- a/crates/victory-hle/src/modules/xnetworking.rs +++ b/crates/victory-hle/src/modules/xnetworking.rs @@ -79,6 +79,14 @@ extern "system" fn udp_port_result(_: This, block: *mut AsyncBlock, out: *mut u1 static SECURITY: u8 = 0; +fn wide(text: *const u16) -> Option { + // SAFETY: the title passes a NUL-terminated UTF-16 string or null. + (!text.is_null()).then(|| unsafe { + let len = (0..).take_while(|&i| *text.add(i) != 0).count(); + String::from_utf16_lossy(std::slice::from_raw_parts(text, len)) + }) +} + /// The allow list comes from the service: unreachable offline. extern "system" fn security_info_async( _: This, @@ -91,6 +99,17 @@ extern "system" fn security_info_async( ); xasync::finished(block, (&raw const SECURITY).cast(), UNREACHABLE) } +extern "system" fn security_info_utf16_async( + _: This, + url: *const u16, + block: *mut AsyncBlock, +) -> HRESULT { + tracing::debug!( + url = wide(url).unwrap_or_default(), + "security information (utf16): offline" + ); + xasync::finished(block, (&raw const SECURITY).cast(), UNREACHABLE) +} extern "system" fn security_info_size(_: This, block: *mut AsyncBlock, out: *mut usize) -> HRESULT { xasync::XAsyncGetResultSize(block, out) } @@ -124,7 +143,7 @@ extern "system" fn connectivity_hint(_: This, out: *mut ConnectivityHint) -> HRE put(out, OFFLINE) } -/// The hint never changes offline, so the callback never runs. +/// The hint and preferred port never change offline, so callbacks never run. extern "system" fn register( _: This, _queue: *const c_void, @@ -142,21 +161,21 @@ static VTABLE: Methods<18> = Methods([ missing::<0> as *const (), add_ref as *const (), add_ref as *const (), - udp_port as *const (), // 0x18 - udp_port_async as *const (), // 0x20 - udp_port_result as *const (), // 0x28 - missing::<6> as *const (), // 0x30 port changed - missing::<7> as *const (), // 0x38 - security_info_async as *const (), // 0x40 - security_info_size as *const (), // 0x48 - security_info_result as *const (), // 0x50 - missing::<11> as *const (), // 0x58 the same for UTF-16 URLs - missing::<12> as *const (), // 0x60 - missing::<13> as *const (), // 0x68 - verify_certificate as *const (), // 0x70 - connectivity_hint as *const (), // 0x78 - register as *const (), // 0x80 hint changed (never) - unregister as *const (), // 0x88 + udp_port as *const (), // 0x18 + udp_port_async as *const (), // 0x20 + udp_port_result as *const (), // 0x28 + register as *const (), // 0x30 port changed (never) + unregister as *const (), // 0x38 + security_info_async as *const (), // 0x40 + security_info_size as *const (), // 0x48 + security_info_result as *const (), // 0x50 + security_info_utf16_async as *const (), // 0x58 + security_info_size as *const (), // 0x60 + security_info_result as *const (), // 0x68 + verify_certificate as *const (), // 0x70 + connectivity_hint as *const (), // 0x78 + register as *const (), // 0x80 hint changed (never) + unregister as *const (), // 0x88 ]); #[cfg(test)] @@ -192,6 +211,28 @@ mod tests { assert_eq!(method::(&OBJECT, 0x28)(this, &mut b, &mut port), S_OK); assert_eq!(port, 3074); + type Register = extern "system" fn( + This, + *const c_void, + *mut c_void, + *const c_void, + *mut u64, + ) -> HRESULT; + type Unregister = extern "system" fn(This, u64, bool) -> bool; + let mut token = 0; + assert_eq!( + method::(&OBJECT, 0x30)( + this, + std::ptr::null(), + std::ptr::null_mut(), + std::ptr::null(), + &mut token, + ), + S_OK + ); + assert_ne!(token, 0); + assert!(method::(&OBJECT, 0x38)(this, token, false)); + type Url = extern "system" fn(This, *const c_char, *mut AsyncBlock) -> HRESULT; type Size = extern "system" fn(This, *mut AsyncBlock, *mut usize) -> HRESULT; let mut b = block(); @@ -206,5 +247,33 @@ mod tests { method::(&OBJECT, 0x48)(this, &mut b, &mut size), UNREACHABLE ); + + type UrlUtf16 = extern "system" fn(This, *const u16, *mut AsyncBlock) -> HRESULT; + let mut b = block(); + let url_utf16: Vec = "https://example.invalid/\0".encode_utf16().collect(); + assert_eq!( + method::(&OBJECT, 0x58)(this, url_utf16.as_ptr(), &mut b), + S_OK + ); + assert_eq!(xasync::XAsyncGetStatus(&mut b, true), UNREACHABLE); + let mut size = 0; + assert_eq!( + method::(&OBJECT, 0x60)(this, &mut b, &mut size), + UNREACHABLE + ); + + token = 0; + assert_eq!( + method::(&OBJECT, 0x80)( + this, + std::ptr::null(), + std::ptr::null_mut(), + std::ptr::null(), + &mut token, + ), + S_OK + ); + assert_ne!(token, 0); + assert!(method::(&OBJECT, 0x88)(this, token, false)); } }