Skip to content

Commit 5fe5d86

Browse files
authored
Merge pull request #1 from luadebug/refactored-code
Refactored code
2 parents 285cf1b + 6fee2f5 commit 5fe5d86

19 files changed

Lines changed: 472 additions & 636 deletions

Cargo.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
cargo-features = ["edition2024", "profile-rustflags"]
2+
13
[package]
24
name = "rusted-assault-cube"
3-
version = "1.0.0"
4-
edition = "2021"
5+
version = "1.6.0"
6+
edition = "2024"
57
authors = ["luadebug Lin Evelynn lin@sz.cn.eu.org"]
68
publish = false
79

@@ -19,6 +21,9 @@ crate-type = ["cdylib"]
1921
[profile.dev]
2022
debug = true
2123

24+
rustflags = ["-C", "link-arg=-fuse-ld=lld"]
2225
[profile.release]
2326
lto = true
24-
debug = true # Enable debug information for release profile
27+
opt-level = "z"
28+
debug = true # Enable debug information for release profile
29+
rustflags = ["-C", "link-arg=-fuse-ld=lld"]

rust-toolchain.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[toolchain]
2+
channel = "nightly"
3+
components = [ "rustfmt" ]
4+
targets = [ "i686-pc-windows-msvc", "x86_64-pc-windows-msvc" ]

src/clash_font.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub static clash: [u8; 45660] = [
1+
pub static CLASH: [u8; 45660] = [
22
0x00, 0x01, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x80, 0x00, 0x03, 0x00, 0x70, 0x46, 0x46, 0x54, 0x4D,
33
0x85, 0x07, 0x9D, 0xA1, 0x00, 0x00, 0xB2, 0x40, 0x00, 0x00, 0x00, 0x1C, 0x47, 0x44, 0x45, 0x46,
44
0x15, 0xF4, 0x14, 0x1B, 0x00, 0x00, 0xA3, 0x64, 0x00, 0x00, 0x00, 0x90, 0x47, 0x50, 0x4F, 0x53,

src/draw_utils.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ pub unsafe fn draw_scaling_bar(
1212
y1: f32,
1313
x2: f32,
1414
y2: f32,
15-
width: f32, // Width for the border
1615
value: f32,
1716
max: f32,
1817
color: COLORREF,
@@ -33,7 +32,7 @@ pub unsafe fn draw_scaling_bar(
3332
let old_brush = SelectObject(hdc, border_brush);
3433

3534
// Draw the border rectangle
36-
Rectangle(
35+
let _ = Rectangle(
3736
hdc,
3837
x1 as i32,
3938
y1 as i32,
@@ -43,7 +42,7 @@ pub unsafe fn draw_scaling_bar(
4342

4443
// Restore the old brush
4544
SelectObject(hdc, old_brush);
46-
DeleteObject(border_brush);
45+
let _ = DeleteObject(border_brush);
4746

4847
// Create a brush for the filled area
4948
let fill_brush = CreateSolidBrush(color);
@@ -62,7 +61,7 @@ pub unsafe fn draw_scaling_bar(
6261

6362
// Clean up: restore the old brush and delete the created brush
6463
SelectObject(hdc, old_fill_brush);
65-
DeleteObject(fill_brush);
64+
let _ = DeleteObject(fill_brush);
6665
}
6766

6867
fn draw_filled_rect(hdc: HDC, brush: HBRUSH, x: i32, y: i32, width: i32, height: i32) {
@@ -139,7 +138,7 @@ pub unsafe fn draw_text(hdc: HDC, x: i32, y: i32, ent: &Entity) {
139138
// Clean up: select the old font back into the device context and delete the created font
140139
unsafe {
141140
SelectObject(hdc, old_font);
142-
DeleteObject(font);
141+
let _ = DeleteObject(font);
143142
}
144143

145144
}
@@ -156,9 +155,9 @@ pub unsafe fn draw_circle(hdc: HDC, center: (f32, f32), radius: f32, color: COLO
156155
let bottom = (center.1 + radius) as i32;
157156

158157
// Draw the circle (ellipse with equal width and height)
159-
Ellipse(hdc, left, top, right, bottom);
158+
let _ = Ellipse(hdc, left, top, right, bottom);
160159

161160
// Restore the old brush and delete the created brush
162161
SelectObject(hdc, old_brush);
163-
DeleteObject(brush);
162+
let _ = DeleteObject(brush);
164163
}

src/esp.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::distance;
1515
use crate::draw_utils::{draw_border_box, draw_circle, draw_scaling_bar, draw_text};
1616
use crate::entity::Entity;
1717
use crate::get_window_dimensions::get_window_dimensions;
18-
use crate::misc::{init_mem_patches, player_fields_monitor};
18+
use crate::misc::init_mem_patches;
1919
use crate::offsets::offsets::{ENTITY_LIST_OFFSET, LOCAL_PLAYER_OFFSET, NUMBER_OF_PLAYERS_IN_MATCH_OFFSET, VIEW_MATRIX_ADDR};
2020
use crate::vars::game_vars::{ENTITY_LIST_PTR, FOV, VIEW_MATRIX};
2121
use crate::vars::game_vars::LOCAL_PLAYER;
@@ -26,7 +26,7 @@ use crate::vars::handles::GAME_WINDOW_HANDLE;
2626
use crate::vars::ui_vars::{IS_DRAW_FOV, IS_ESP};
2727
use crate::vec_structures::Vec2;
2828
use crate::world_to_screen::world_to_screen;
29-
29+
#[allow(unused)]
3030
unsafe fn esp_cleanup(
3131
window_handle_hwnd: HWND,
3232
hdc: HDC,
@@ -157,8 +157,8 @@ pub unsafe fn esp_entrypoint() -> Result<(), Box<String>> {
157157
println!("[esp] Window resized to: {}x{}", new_width, new_height);
158158

159159
// Cleanup old resources
160-
DeleteObject(mem_bitmap);
161-
DeleteDC(mem_dc);
160+
let _ = DeleteObject(mem_bitmap);
161+
let _ = DeleteDC(mem_dc);
162162

163163
// Create a new compatible DC and bitmap with the new dimensions
164164
let hdc = GetDC(GAME_WINDOW_HANDLE);
@@ -198,7 +198,6 @@ pub unsafe fn esp_entrypoint() -> Result<(), Box<String>> {
198198
println!("[esp] Entity list ptr not found");
199199
ENTITY_LIST_PTR = *((AC_CLIENT_EXE_HMODULE + ENTITY_LIST_OFFSET) as *const u32);
200200
}
201-
player_fields_monitor();
202201

203202
if !IS_ESP {
204203
println!("[esp] Turning off ESP");
@@ -264,7 +263,6 @@ pub unsafe fn esp_entrypoint() -> Result<(), Box<String>> {
264263
head_screen_pos.y,
265264
feet_screen_pos.x - 15.0,
266265
feet_screen_pos.y,
267-
box_width as f32 * 2.5,
268266
entity.health() as f32,
269267
100.0,
270268
COLORREF(0x0000FF00),

src/game.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use std::ffi::c_void;
2+
3+
use windows::Win32::System::Memory::{PAGE_EXECUTE_READWRITE, PAGE_PROTECTION_FLAGS, VirtualProtect};
4+
25
use crate::offsets::offsets::{BRIGHTNESS, SET_BRIGHTNESS};
36
use crate::vars::handles::AC_CLIENT_EXE_HMODULE;
4-
use windows::Win32::System::Memory::{PAGE_PROTECTION_FLAGS, PAGE_EXECUTE_READWRITE, VirtualProtect};
7+
58
pub unsafe fn c_brightness() -> *mut usize {
69
(AC_CLIENT_EXE_HMODULE + BRIGHTNESS) as *mut usize
710
}
@@ -10,9 +13,9 @@ pub unsafe fn set_brightness() -> *mut usize {
1013
(AC_CLIENT_EXE_HMODULE + SET_BRIGHTNESS) as *mut usize
1114
}
1215

13-
pub unsafe fn set_brightness_toggle(isON: bool)
16+
pub unsafe fn set_brightness_toggle(is_on: bool)
1417
{
15-
if isON
18+
if is_on
1619
{
1720
*c_brightness() = 100;
1821
}

src/get_local_player_hook.rs

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
2+
use std::ptr::null_mut;
3+
use std::thread;
4+
use ilhook::x86::{CallbackOption, Hooker, HookFlags, HookType, Registers};
5+
6+
use crate::entity::Entity;
7+
use crate::offsets::offsets::{AMMO_CARBINE, AMMO_IN_MAGAZINE_CARBINE, AMMO_IN_MAGAZINE_PISTOL, AMMO_IN_MAGAZINE_RIFLE, AMMO_IN_MAGAZINE_SHOTGUN, AMMO_IN_MAGAZINE_SNIPER, AMMO_IN_MAGAZINE_SUBMACHINEGUN, AMMO_PISTOL, AMMO_RIFLE, AMMO_SHOTGUN, AMMO_SNIPER, AMMO_SUBMACHINEGUN, ARMOR_OFFSET_FROM_LOCAL_PLAYER, CARBINE_COOLDOWN, GRENADES_COUNT, HEALTH_OFFSET_FROM_LOCAL_PLAYER, KNIFE_COOLDOWN, PISTOL_COOLDOWN, RIFLE_COOLDOWN, SHOTGUN_COOLDOWN, SNIPER_COOLDOWN, SUBMACHINEGUN_COOLDOWN};
8+
use crate::pattern_mask::PatternMask;
9+
use crate::utils::find_pattern;
10+
use crate::vars::hooks::{LOCAL_PLAYER_HOOK};
11+
use crate::vars::ui_vars::{IS_GRENADES_INFINITE, IS_INFINITE_AMMO, IS_INVULNERABLE, IS_NO_RELOAD};
12+
13+
pub static mut LOCAL_PLAYER_FIELDS_ADDR: * mut usize = null_mut();
14+
15+
// The function to be hooked
16+
#[inline(never)]
17+
pub(crate) unsafe extern "cdecl" fn get_local_player_health(
18+
reg: *mut Registers,
19+
_: usize
20+
) {
21+
LOCAL_PLAYER_FIELDS_ADDR = (*reg).ebx as *mut usize;
22+
if LOCAL_PLAYER_FIELDS_ADDR != null_mut()
23+
{
24+
let local_player_ent = Entity::from_addr(LOCAL_PLAYER_FIELDS_ADDR as usize);
25+
if IS_GRENADES_INFINITE
26+
{
27+
if *((local_player_ent.entity_starts_at_addr + GRENADES_COUNT) as *mut i32) == 0
28+
{
29+
*((local_player_ent.entity_starts_at_addr + GRENADES_COUNT) as *mut i32) = 1;
30+
}
31+
}
32+
if IS_NO_RELOAD
33+
{
34+
*((local_player_ent.entity_starts_at_addr + KNIFE_COOLDOWN) as *mut f32) = 0.0f32;
35+
*((local_player_ent.entity_starts_at_addr + PISTOL_COOLDOWN) as *mut f32) = 0.0f32;
36+
*((local_player_ent.entity_starts_at_addr + CARBINE_COOLDOWN) as *mut f32) = 0.0f32;
37+
*((local_player_ent.entity_starts_at_addr + SHOTGUN_COOLDOWN) as *mut f32) = 0.0f32;
38+
*((local_player_ent.entity_starts_at_addr + SUBMACHINEGUN_COOLDOWN) as *mut f32) = 0.0f32;
39+
*((local_player_ent.entity_starts_at_addr + SNIPER_COOLDOWN) as *mut f32) = 0.0f32;
40+
*((local_player_ent.entity_starts_at_addr + RIFLE_COOLDOWN) as *mut f32) = 0.0f32;
41+
}
42+
if IS_INVULNERABLE
43+
{
44+
*((local_player_ent.entity_starts_at_addr + HEALTH_OFFSET_FROM_LOCAL_PLAYER) as *mut i32) = 1337;
45+
*((local_player_ent.entity_starts_at_addr + ARMOR_OFFSET_FROM_LOCAL_PLAYER) as *mut i32) = 1337;
46+
}
47+
if IS_INFINITE_AMMO
48+
{
49+
*((local_player_ent.entity_starts_at_addr + AMMO_RIFLE) as *mut i32) = 40;
50+
*((local_player_ent.entity_starts_at_addr + AMMO_IN_MAGAZINE_RIFLE) as *mut i32) = 40;
51+
52+
*((local_player_ent.entity_starts_at_addr + AMMO_PISTOL) as *mut i32) = 40;
53+
*((local_player_ent.entity_starts_at_addr + AMMO_IN_MAGAZINE_PISTOL) as *mut i32) = 40;
54+
55+
*((local_player_ent.entity_starts_at_addr + AMMO_CARBINE) as *mut i32) = 40;
56+
*((local_player_ent.entity_starts_at_addr + AMMO_IN_MAGAZINE_CARBINE) as *mut i32) = 40;
57+
58+
*((local_player_ent.entity_starts_at_addr + AMMO_SHOTGUN) as *mut i32) = 40;
59+
*((local_player_ent.entity_starts_at_addr + AMMO_IN_MAGAZINE_SHOTGUN) as *mut i32) = 40;
60+
61+
*((local_player_ent.entity_starts_at_addr + AMMO_SUBMACHINEGUN) as *mut i32) = 40;
62+
*((local_player_ent.entity_starts_at_addr + AMMO_IN_MAGAZINE_SUBMACHINEGUN) as *mut i32) = 40;
63+
64+
*((local_player_ent.entity_starts_at_addr + AMMO_SNIPER) as *mut i32) = 40;
65+
*((local_player_ent.entity_starts_at_addr + AMMO_IN_MAGAZINE_SNIPER) as *mut i32) = 40;
66+
}
67+
}
68+
}
69+
70+
71+
72+
73+
// Example of finding a pattern and setting up the hook
74+
pub fn setup_invul() {
75+
unsafe {
76+
thread::spawn(||
77+
{
78+
/*8B 8B EC 00 00 00 83 F9 19*/
79+
/*8B ? ? ? ? ? 83 F9 19*/
80+
/*x?????xxx*/
81+
let pattern_mask = PatternMask::aob_to_pattern_mask(
82+
"8B ? ? ? ? ? 83 F9 19"
83+
);
84+
85+
println!("[GetLocalPlayerHealthHook] {:#x}", &pattern_mask);
86+
87+
let get_local_player_health_aob = find_pattern("ac_client.exe",
88+
&*pattern_mask.aob_pattern,
89+
&pattern_mask.mask_to_string());
90+
/* &[0x8B, 0x8B, 0xEC, 0x00, 0x00, 0x00, 0x83, 0xF9, 0x19],
91+
"x?????xxx");*/
92+
93+
if let Some(addr) = get_local_player_health_aob {
94+
println!("[get_local_player_hook.rs->setup_invul] local player get current hp pattern found at: {:#x}", addr);
95+
let hooker = Hooker::new(
96+
addr,
97+
HookType::JmpBack(get_local_player_health),
98+
CallbackOption::None,
99+
0,
100+
HookFlags::empty(),
101+
);
102+
let hook_res = hooker.hook();
103+
104+
match hook_res {
105+
Ok(trampoline_hook) => {
106+
*LOCAL_PLAYER_HOOK.lock().unwrap() = Some(trampoline_hook);
107+
println!("[get_local_player_hook.rs->setup_invul] local player get current hp pattern hook succeeded!");
108+
}
109+
Err(e) => {
110+
println!("[get_local_player_hook.rs->setup_invul] local player get current hp pattern hook failed: {:?}", e);
111+
}
112+
}
113+
} else {
114+
println!("[get_local_player_hook.rs->setup_invul] local player get current hp pattern not found");
115+
}
116+
});
117+
}
118+
}

src/lib.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
use std::ffi::c_void;
44

5-
use windows::Win32::Foundation::{BOOL, HMODULE, TRUE};
5+
use windows::Win32::Foundation::{BOOL, CloseHandle, HMODULE, TRUE};
66
use windows::Win32::System::LibraryLoader::DisableThreadLibraryCalls;
77
use windows::Win32::System::SystemServices::{DLL_PROCESS_ATTACH, DLL_PROCESS_DETACH, DLL_THREAD_ATTACH, DLL_THREAD_DETACH};
88
use windows::Win32::System::Threading::{CreateThread, THREAD_CREATION_FLAGS};
99

1010
use vars::handles::CHEAT_DLL_HMODULE;
1111

1212
mod main_thread;
13-
mod trampoline;
13+
1414
mod ui;
1515
mod esp;
1616
mod utils;
@@ -30,9 +30,11 @@ mod angle;
3030
mod getclosestentity;
3131
mod aimbot;
3232
mod misc;
33-
mod triggerbot;
33+
mod triggerbot_hook;
3434
mod game;
3535
mod clash_font;
36+
mod get_local_player_hook;
37+
mod pattern_mask;
3638

3739
#[no_mangle]
3840
#[allow(non_snake_case, unused_variables)]
@@ -45,14 +47,20 @@ extern "system" fn DllMain(
4547
match call_reason {
4648
DLL_PROCESS_ATTACH =>
4749
unsafe {
48-
DisableThreadLibraryCalls(dll_module).expect("[lib] Failed to disable thread library calls");
50+
DisableThreadLibraryCalls(dll_module).
51+
expect("[lib.rs] Failed to disable thread library calls");
4952
CHEAT_DLL_HMODULE = dll_module.0 as isize;
50-
CreateThread(None,
53+
let handle = CreateThread(None,
5154
0,
5255
Some(main_thread::MainThread),
5356
Some(dll_module.0),
5457
THREAD_CREATION_FLAGS(0),
55-
None).expect("[lib] Failed to create thread");
58+
None).expect("[lib.rs] Failed to create thread");
59+
if !handle.0.is_null()
60+
{
61+
CloseHandle(handle).
62+
expect("[lib.rs] Failed to close null handle.");
63+
}
5664
}
5765
DLL_THREAD_ATTACH => (),
5866
DLL_THREAD_DETACH => (),

src/main_thread.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use std::ffi::{c_void, CString};
2+
23
use hudhook::{eject, Hudhook};
34
use hudhook::hooks::opengl3::ImguiOpenGl3Hooks;
45
use hudhook::windows::Win32::Foundation::HINSTANCE;
56
use windows::core::PCSTR;
67
use windows::Win32::System::LibraryLoader::GetModuleHandleA;
78
use windows::Win32::System::Threading::Sleep;
9+
810
use crate::esp::esp_entrypoint;
911
use crate::ui::RenderLoop;
1012
use crate::utils::setup_tracing;

src/memorypatch.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ impl MemoryPatch {
2626
}
2727
}
2828
// Constructor for patching with a buffer and size
29+
#[allow(unused)]
2930
pub fn new(buffer_to_patch: &[u8], size_buffer: usize, location: *mut c_void, size_location: usize) -> Result<Self, Box<dyn Error>> {
3031
if size_buffer > size_location {
3132
return Err("Error on MemoryPatch trying to write buffer bigger than expected".into());
@@ -54,6 +55,7 @@ impl MemoryPatch {
5455
}
5556

5657
// Constructor for patching with a mask
58+
#[allow(unused)]
5759
pub fn new_with_mask(buffer_to_patch: &[u8], mask: &[u8], size_buffer: usize, location: *mut c_void) -> Result<Self, Box<dyn Error>> {
5860
// Allocate memory for patch instructions and original instructions
5961
let patch_instructions = unsafe { alloc(Layout::from_size_align(size_buffer, mem::align_of::<u8>())?) };

0 commit comments

Comments
 (0)