Skip to content

Commit bd0115d

Browse files
committed
feat: read notes
- multi-target is now supported. - open memory is now on the client side instead of simba - dll version is stored in the memory map as a commit hash
1 parent f23a38f commit bd0115d

File tree

9 files changed

+383
-239
lines changed

9 files changed

+383
-239
lines changed

.github/workflows/build.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,25 @@ env:
1212
NAME_WIN64: waspinput64.dll
1313

1414
jobs:
15+
update_version:
16+
steps:
17+
- name: Get commit hash
18+
id: commit-hash
19+
run: echo "COMMIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
20+
- name: Replace version hash
21+
run: |
22+
HASH=$(git rev-parse --short HEAD)
23+
sed -i "s/^const VERSION: &str = \".*\";/const VERSION: &str = \"${HASH}\";/" src/shared/memory.rs
24+
- name: Commit updated version
25+
run: |
26+
git config --global user.name "Wasp Bot"
27+
git config --global user.email "[email protected]"
28+
git add src/shared/memory.rs
29+
git commit -m "Bump version"
30+
git push
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
1534
build:
1635
runs-on: windows-latest
1736
strategy:

src/client/hooks.rs

Lines changed: 58 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::char::from_u32;
1212
use windows::{
1313
core::{BOOL, PCSTR},
1414
Win32::{
15-
Foundation::{CloseHandle, GetLastError, HWND, LPARAM, LRESULT, WPARAM},
15+
Foundation::{GetLastError, HWND, LPARAM, LRESULT, WPARAM},
1616
Graphics::{
1717
Gdi::HDC,
1818
OpenGL::{glGetIntegerv, GL_VIEWPORT},
@@ -39,21 +39,15 @@ use super::graphics::{
3939
};
4040
use crate::shared::{
4141
memory::{MemoryManager, MEMORY_MANAGER},
42-
windows::{unload_self_dll, WI_CONSOLE, WI_DETACH, WI_MODIFIERS, WI_REMAP},
42+
sync::event_listener,
43+
windows::{WI_CONSOLE, WI_DETACH, WI_MODIFIERS},
4344
};
4445

4546
lazy_static! {
4647
static ref KEYBOARD_MODIFIERS: Mutex<(bool, bool, bool)> = Mutex::new((false, false, false));
4748
static ref LAST_CHAR: Mutex<i32> = Mutex::new(0);
4849
}
4950

50-
pub unsafe extern "system" fn start_thread(lparam: *mut c_void) -> u32 {
51-
open_client_console();
52-
hook_wndproc(lparam as u64);
53-
hook_wgl_swap_buffers();
54-
0
55-
}
56-
5751
pub unsafe fn open_client_console() {
5852
let hwnd = GetConsoleWindow();
5953
if hwnd.0 != null_mut() {
@@ -149,15 +143,6 @@ unsafe extern "system" fn hooked_wndproc(
149143
open_client_console();
150144
return LRESULT(0);
151145
}
152-
WI_REMAP => {
153-
println!("Restarting map.\r\n");
154-
let mut mem_manager = MEMORY_MANAGER.lock().unwrap();
155-
if mem_manager.is_mapped() {
156-
mem_manager.close_map();
157-
}
158-
*mem_manager = MemoryManager::open_map();
159-
return LRESULT(0);
160-
}
161146
WI_MODIFIERS => {
162147
let mut modifiers = KEYBOARD_MODIFIERS.lock().unwrap();
163148
let (shift, ctrl, alt) = &mut *modifiers;
@@ -194,15 +179,9 @@ unsafe extern "system" fn hooked_wndproc(
194179
return LRESULT(0);
195180
}
196181
WI_DETACH => {
197-
let mut mem_manager = MEMORY_MANAGER.lock().unwrap();
198-
unsafe {
199-
unhook_wgl_swap_buffers();
200-
if mem_manager.is_mapped() {
201-
mem_manager.close_map();
202-
}
203-
unhook_wndproc();
204-
};
205-
//unload_self_dll();
182+
unhook_wgl_swap_buffers();
183+
unhook_wndproc();
184+
206185
return LRESULT(0);
207186
}
208187
WM_KEYDOWN => {
@@ -245,7 +224,11 @@ unsafe extern "system" fn hooked_wndproc(
245224
let x = (lparam.0 & 0xFFFF) as u16 as i32;
246225
let y = ((lparam.0 >> 16) & 0xFFFF) as u16 as i32;
247226

248-
let mem_manager = MEMORY_MANAGER.lock().unwrap();
227+
let mem_manager = MEMORY_MANAGER
228+
.get()
229+
.expect("[WaspInput]: Memory manager is not initialized!\r\n")
230+
.lock()
231+
.unwrap();
249232
mem_manager.set_mouse_position(x, y);
250233

251234
WM_MOUSEMOVE
@@ -273,9 +256,11 @@ unsafe fn hook_wndproc(hwnd: u64) {
273256
.enable()
274257
.expect("[WaspInput]: Failed to enable WndProc hook.\r\n");
275258

276-
ORIGINAL_WNDPROC
277-
.set(detour)
278-
.expect("[WaspInput]: Failed to save original WndProc function.\r\n");
259+
if ORIGINAL_WNDPROC.get().is_none() {
260+
ORIGINAL_WNDPROC
261+
.set(detour)
262+
.expect("[WaspInput]: Failed to save original WndProc function.\r\n");
263+
}
279264

280265
println!("[WaspInput]: WndProc successfully hooked.\r\n");
281266
}
@@ -297,7 +282,11 @@ static ORIGINAL_WGL_SWAPBUFFERS: OnceLock<GenericDetour<unsafe extern "system" f
297282
OnceLock::new();
298283

299284
unsafe extern "system" fn hooked_wgl_swap_buffers(hdc: HDC) -> BOOL {
300-
let mem_manager = MEMORY_MANAGER.lock().unwrap();
285+
let mem_manager = MEMORY_MANAGER
286+
.get()
287+
.expect("[WaspInput]: Memory manager is not initialized!\r\n")
288+
.lock()
289+
.unwrap();
301290
let mut viewport = [0, 0, 0, 0];
302291
let mouse = mem_manager.get_mouse_position();
303292

@@ -350,10 +339,19 @@ unsafe fn hook_wgl_swap_buffers() {
350339
ORIGINAL_WGL_SWAPBUFFERS
351340
.set(detour)
352341
.expect("[WaspInput]: Failed to save original wglSwapBuffers function.\r\n");
342+
353343
println!("[WaspInput]: wglSwapBuffers successfully hooked.\r\n");
354344
}
355345

356346
pub unsafe fn unhook_wgl_swap_buffers() {
347+
let mem_manager = MEMORY_MANAGER
348+
.get()
349+
.expect("[WaspInput]: Memory manager is not initialized!\r\n")
350+
.lock()
351+
.unwrap();
352+
353+
mem_manager.clear_overlay();
354+
357355
let detour = ORIGINAL_WGL_SWAPBUFFERS
358356
.get()
359357
.expect("[WaspInput]: wglSwapBuffers hook not found\r\n");
@@ -364,3 +362,31 @@ pub unsafe fn unhook_wgl_swap_buffers() {
364362

365363
println!("[WaspInput]: wglSwapBuffers successfully unhooked.\r\n");
366364
}
365+
366+
//enable...
367+
pub unsafe fn reenable_hooks() {
368+
let wgl_swapbuffers_detour = ORIGINAL_WGL_SWAPBUFFERS
369+
.get()
370+
.expect("[WaspInput]: wglSwapBuffers hook not found\r\n");
371+
372+
wgl_swapbuffers_detour
373+
.enable()
374+
.expect("[WaspInput]: Failed to enable wglSwapBuffers hook.\r\n");
375+
376+
let wndproc_detour = ORIGINAL_WNDPROC
377+
.get()
378+
.expect("[WaspInput]: WndProc hook not found\r\n");
379+
380+
wndproc_detour
381+
.enable()
382+
.expect("[WaspInput]: Failed to enable WndProc hook.\r\n");
383+
}
384+
pub unsafe extern "system" fn start(lparam: *mut c_void) -> u32 {
385+
let _ = MEMORY_MANAGER.set(Mutex::new(MemoryManager::create_map()));
386+
387+
hook_wndproc(lparam as u64);
388+
hook_wgl_swap_buffers();
389+
390+
event_listener(lparam as u64);
391+
0
392+
}

src/lib.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::os::raw::c_char;
33
use std::sync::Mutex;
44

55
use shared::windows::{get_jagrenderview, inject, is_input_enabled, open_console, toggle_input};
6-
use simba::target::TARGET;
6+
use simba::target::{SimbaTarget, TARGETS};
77

88
mod client;
99
mod shared;
@@ -58,11 +58,17 @@ pub extern "C" fn Inject(path: *const c_char, pid: u32) -> bool {
5858
}
5959
};
6060

61-
let mut target = TARGET.lock().unwrap();
62-
target.pid = pid;
63-
target.hwnd = hwnd;
61+
let new_target = SimbaTarget {
62+
pid,
63+
hwnd,
64+
keyboard: [false; 255],
65+
mouse: [false; 3],
66+
};
67+
68+
let mut targets = TARGETS.lock().unwrap();
69+
targets.insert(pid, new_target);
6470

65-
unsafe { inject(module_path, pid, hwnd) }
71+
unsafe { inject(module_path, pid) }
6672
}
6773

6874
#[no_mangle]

src/shared/main.rs

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
use std::{ffi::c_void, ptr::null_mut, sync::OnceLock};
2+
3+
use windows::{
4+
core::BOOL,
5+
Win32::{
6+
Foundation::{FALSE, HINSTANCE, HMODULE, HWND, LPARAM, TRUE, WPARAM},
7+
System::{
8+
LibraryLoader::{DisableThreadLibraryCalls, GetModuleFileNameW},
9+
Threading::{CreateThread, GetCurrentProcessId, THREAD_CREATION_FLAGS},
10+
},
11+
UI::WindowsAndMessaging::PostMessageW,
12+
},
13+
};
14+
15+
use crate::{
16+
client::hooks::start,
17+
shared::{memory::MEMORY_MANAGER, sync::close_event},
18+
simba::target::TARGETS,
19+
};
20+
21+
use super::windows::{get_jagrenderview, WI_DETACH};
22+
23+
pub static mut MODULE: HMODULE = HMODULE(null_mut());
24+
25+
fn client_main(hinst_dll: HINSTANCE, hwnd: HWND, reason: u32) -> BOOL {
26+
match reason {
27+
1 => unsafe {
28+
let _ = DisableThreadLibraryCalls(hinst_dll.into());
29+
30+
let mut buffer = [0u16; 260]; // MAX_PATH
31+
let len = GetModuleFileNameW(Some(MODULE), &mut buffer);
32+
33+
if len > 0 {
34+
let path = String::from_utf16_lossy(&buffer[..len as usize]);
35+
let _ = DLL_NAME.set(path);
36+
}
37+
38+
let _ = CreateThread(
39+
Some(null_mut()),
40+
0,
41+
Some(start),
42+
Some(hwnd.0 as *mut c_void),
43+
THREAD_CREATION_FLAGS(0),
44+
Some(null_mut()),
45+
);
46+
return TRUE;
47+
},
48+
0 => {
49+
let mut mem_manager = MEMORY_MANAGER
50+
.get()
51+
.expect("[WaspInput]: Memory manager is not initialized!\r\n")
52+
.lock()
53+
.unwrap();
54+
55+
unsafe { mem_manager.close_map() };
56+
57+
close_event(hwnd.0 as u64);
58+
println!("[WaspInput]: Detached.\r\n");
59+
TRUE
60+
}
61+
_ => FALSE,
62+
}
63+
}
64+
65+
pub static DLL_NAME: OnceLock<String> = OnceLock::new();
66+
67+
fn simba_main(hinst_dll: HINSTANCE, reason: u32) -> BOOL {
68+
match reason {
69+
1 => {
70+
let _ = unsafe { DisableThreadLibraryCalls(hinst_dll.into()) };
71+
TRUE
72+
}
73+
0 => {
74+
let targets = TARGETS.lock().unwrap();
75+
for target in targets.values() {
76+
let hwnd = HWND(target.hwnd as *mut c_void);
77+
let _ = unsafe { PostMessageW(Some(hwnd), WI_DETACH, WPARAM(0), LPARAM(0)) };
78+
}
79+
80+
TRUE
81+
}
82+
_ => FALSE,
83+
}
84+
}
85+
86+
#[no_mangle]
87+
pub extern "system" fn DllMain(
88+
hinst_dll: HINSTANCE,
89+
fdw_reason: u32,
90+
_lpv_reserved: *mut c_void,
91+
) -> BOOL {
92+
unsafe { MODULE = HMODULE(hinst_dll.0) };
93+
94+
let pid = unsafe { GetCurrentProcessId() };
95+
match get_jagrenderview(pid) {
96+
Some(hwnd) => client_main(hinst_dll, hwnd, fdw_reason),
97+
None => simba_main(hinst_dll, fdw_reason),
98+
}
99+
}
100+
101+
/* pub fn unload_dll() {
102+
let _ = unsafe { FreeLibrary(MODULE) };
103+
}
104+
*/

0 commit comments

Comments
 (0)