Skip to content

Commit 83cec09

Browse files
committed
poc
1 parent 7d96b15 commit 83cec09

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

mod-fix-multiplayer-locks/src/ffi.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ pub unsafe extern "C" fn start() -> u32 {
124124
debug!("Fix operations_network_client_send_pending_operations pending lock");
125125
debug!("Fix operations_network_client_send_pending_operations pending unlock");
126126
let addr: u32 = &try_lock_current_clean as *const _ as _;
127-
debug!("#### {addr}");
127+
debug!("#### {addr:#X}");
128128

129129
0
130130
}
@@ -137,12 +137,12 @@ unsafe extern "stdcall" fn lock_pending() {
137137
}
138138

139139
#[no_mangle]
140-
unsafe extern "stdcall" fn try_lock_pending() -> u32 {
140+
unsafe extern "stdcall" fn try_lock_pending() -> bool {
141141
let thread_id = thread::current().id();
142142
debug!("try_lock_pending {thread_id:?}");
143-
let in_use = crate::try_lock(&crate::PENDING_OPS_LOCK);
144-
debug!("try_lock_pending {thread_id:?} {in_use}");
145-
in_use
143+
let locked = crate::try_lock(&crate::PENDING_OPS_LOCK);
144+
debug!("try_lock_pending {thread_id:?} {locked}");
145+
locked
146146
}
147147

148148
#[no_mangle]
@@ -166,12 +166,12 @@ unsafe extern "stdcall" fn lock_current() {
166166
}
167167

168168
#[no_mangle]
169-
unsafe extern "stdcall" fn try_lock_current() -> u32 {
169+
unsafe extern "stdcall" fn try_lock_current() -> bool {
170170
let thread_id = thread::current().id();
171171
debug!("try_lock_current {thread_id:?}");
172-
let in_use = crate::try_lock(&crate::CURRENT_OPS_LOCK);
173-
debug!("try_lock_current {thread_id:?} {in_use}");
174-
in_use
172+
let locked = crate::try_lock(&crate::CURRENT_OPS_LOCK);
173+
debug!("try_lock_current {thread_id:?} {locked}");
174+
!locked
175175
}
176176

177177
#[no_mangle]

mod-fix-multiplayer-locks/src/lib.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@ pub(crate) fn lock(lock: &AtomicU16) {
1313
}
1414
}
1515

16-
pub(crate) fn try_lock(lock: &AtomicU16) -> u32 {
17-
match lock.compare_exchange(0, 1, Ordering::SeqCst, Ordering::SeqCst) {
18-
Ok(_) => 0,
19-
Err(_) => 1
20-
}
16+
pub(crate) fn try_lock(lock: &AtomicU16) -> bool {
17+
lock.compare_exchange(0, 1, Ordering::SeqCst, Ordering::SeqCst).is_ok()
2118
}
2219

2320
pub(crate) fn unlock(lock: &AtomicU16) {

0 commit comments

Comments
 (0)