Skip to content

Commit

Permalink
Merge pull request #1 from luadebug/refactored-code
Browse files Browse the repository at this point in the history
Refactored code
  • Loading branch information
luadebug authored Jul 27, 2024
2 parents 285cf1b + 6fee2f5 commit 5fe5d86
Show file tree
Hide file tree
Showing 19 changed files with 472 additions and 636 deletions.
11 changes: 8 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
cargo-features = ["edition2024", "profile-rustflags"]

[package]
name = "rusted-assault-cube"
version = "1.0.0"
edition = "2021"
version = "1.6.0"
edition = "2024"
authors = ["luadebug Lin Evelynn [email protected]"]
publish = false

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

rustflags = ["-C", "link-arg=-fuse-ld=lld"]
[profile.release]
lto = true
debug = true # Enable debug information for release profile
opt-level = "z"
debug = true # Enable debug information for release profile
rustflags = ["-C", "link-arg=-fuse-ld=lld"]
4 changes: 4 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[toolchain]
channel = "nightly"
components = [ "rustfmt" ]
targets = [ "i686-pc-windows-msvc", "x86_64-pc-windows-msvc" ]
2 changes: 1 addition & 1 deletion src/clash_font.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub static clash: [u8; 45660] = [
pub static CLASH: [u8; 45660] = [
0x00, 0x01, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x80, 0x00, 0x03, 0x00, 0x70, 0x46, 0x46, 0x54, 0x4D,
0x85, 0x07, 0x9D, 0xA1, 0x00, 0x00, 0xB2, 0x40, 0x00, 0x00, 0x00, 0x1C, 0x47, 0x44, 0x45, 0x46,
0x15, 0xF4, 0x14, 0x1B, 0x00, 0x00, 0xA3, 0x64, 0x00, 0x00, 0x00, 0x90, 0x47, 0x50, 0x4F, 0x53,
Expand Down
13 changes: 6 additions & 7 deletions src/draw_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ pub unsafe fn draw_scaling_bar(
y1: f32,
x2: f32,
y2: f32,
width: f32, // Width for the border
value: f32,
max: f32,
color: COLORREF,
Expand All @@ -33,7 +32,7 @@ pub unsafe fn draw_scaling_bar(
let old_brush = SelectObject(hdc, border_brush);

// Draw the border rectangle
Rectangle(
let _ = Rectangle(
hdc,
x1 as i32,
y1 as i32,
Expand All @@ -43,7 +42,7 @@ pub unsafe fn draw_scaling_bar(

// Restore the old brush
SelectObject(hdc, old_brush);
DeleteObject(border_brush);
let _ = DeleteObject(border_brush);

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

// Clean up: restore the old brush and delete the created brush
SelectObject(hdc, old_fill_brush);
DeleteObject(fill_brush);
let _ = DeleteObject(fill_brush);
}

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

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

// Draw the circle (ellipse with equal width and height)
Ellipse(hdc, left, top, right, bottom);
let _ = Ellipse(hdc, left, top, right, bottom);

// Restore the old brush and delete the created brush
SelectObject(hdc, old_brush);
DeleteObject(brush);
let _ = DeleteObject(brush);
}
10 changes: 4 additions & 6 deletions src/esp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::distance;
use crate::draw_utils::{draw_border_box, draw_circle, draw_scaling_bar, draw_text};
use crate::entity::Entity;
use crate::get_window_dimensions::get_window_dimensions;
use crate::misc::{init_mem_patches, player_fields_monitor};
use crate::misc::init_mem_patches;
use crate::offsets::offsets::{ENTITY_LIST_OFFSET, LOCAL_PLAYER_OFFSET, NUMBER_OF_PLAYERS_IN_MATCH_OFFSET, VIEW_MATRIX_ADDR};
use crate::vars::game_vars::{ENTITY_LIST_PTR, FOV, VIEW_MATRIX};
use crate::vars::game_vars::LOCAL_PLAYER;
Expand All @@ -26,7 +26,7 @@ use crate::vars::handles::GAME_WINDOW_HANDLE;
use crate::vars::ui_vars::{IS_DRAW_FOV, IS_ESP};
use crate::vec_structures::Vec2;
use crate::world_to_screen::world_to_screen;

#[allow(unused)]
unsafe fn esp_cleanup(
window_handle_hwnd: HWND,
hdc: HDC,
Expand Down Expand Up @@ -157,8 +157,8 @@ pub unsafe fn esp_entrypoint() -> Result<(), Box<String>> {
println!("[esp] Window resized to: {}x{}", new_width, new_height);

// Cleanup old resources
DeleteObject(mem_bitmap);
DeleteDC(mem_dc);
let _ = DeleteObject(mem_bitmap);
let _ = DeleteDC(mem_dc);

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

if !IS_ESP {
println!("[esp] Turning off ESP");
Expand Down Expand Up @@ -264,7 +263,6 @@ pub unsafe fn esp_entrypoint() -> Result<(), Box<String>> {
head_screen_pos.y,
feet_screen_pos.x - 15.0,
feet_screen_pos.y,
box_width as f32 * 2.5,
entity.health() as f32,
100.0,
COLORREF(0x0000FF00),
Expand Down
9 changes: 6 additions & 3 deletions src/game.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::ffi::c_void;

use windows::Win32::System::Memory::{PAGE_EXECUTE_READWRITE, PAGE_PROTECTION_FLAGS, VirtualProtect};

use crate::offsets::offsets::{BRIGHTNESS, SET_BRIGHTNESS};
use crate::vars::handles::AC_CLIENT_EXE_HMODULE;
use windows::Win32::System::Memory::{PAGE_PROTECTION_FLAGS, PAGE_EXECUTE_READWRITE, VirtualProtect};

pub unsafe fn c_brightness() -> *mut usize {
(AC_CLIENT_EXE_HMODULE + BRIGHTNESS) as *mut usize
}
Expand All @@ -10,9 +13,9 @@ pub unsafe fn set_brightness() -> *mut usize {
(AC_CLIENT_EXE_HMODULE + SET_BRIGHTNESS) as *mut usize
}

pub unsafe fn set_brightness_toggle(isON: bool)
pub unsafe fn set_brightness_toggle(is_on: bool)
{
if isON
if is_on
{
*c_brightness() = 100;
}
Expand Down
118 changes: 118 additions & 0 deletions src/get_local_player_hook.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@

use std::ptr::null_mut;
use std::thread;
use ilhook::x86::{CallbackOption, Hooker, HookFlags, HookType, Registers};

use crate::entity::Entity;
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};
use crate::pattern_mask::PatternMask;
use crate::utils::find_pattern;
use crate::vars::hooks::{LOCAL_PLAYER_HOOK};
use crate::vars::ui_vars::{IS_GRENADES_INFINITE, IS_INFINITE_AMMO, IS_INVULNERABLE, IS_NO_RELOAD};

pub static mut LOCAL_PLAYER_FIELDS_ADDR: * mut usize = null_mut();

// The function to be hooked
#[inline(never)]
pub(crate) unsafe extern "cdecl" fn get_local_player_health(
reg: *mut Registers,
_: usize
) {
LOCAL_PLAYER_FIELDS_ADDR = (*reg).ebx as *mut usize;
if LOCAL_PLAYER_FIELDS_ADDR != null_mut()
{
let local_player_ent = Entity::from_addr(LOCAL_PLAYER_FIELDS_ADDR as usize);
if IS_GRENADES_INFINITE
{
if *((local_player_ent.entity_starts_at_addr + GRENADES_COUNT) as *mut i32) == 0
{
*((local_player_ent.entity_starts_at_addr + GRENADES_COUNT) as *mut i32) = 1;
}
}
if IS_NO_RELOAD
{
*((local_player_ent.entity_starts_at_addr + KNIFE_COOLDOWN) as *mut f32) = 0.0f32;
*((local_player_ent.entity_starts_at_addr + PISTOL_COOLDOWN) as *mut f32) = 0.0f32;
*((local_player_ent.entity_starts_at_addr + CARBINE_COOLDOWN) as *mut f32) = 0.0f32;
*((local_player_ent.entity_starts_at_addr + SHOTGUN_COOLDOWN) as *mut f32) = 0.0f32;
*((local_player_ent.entity_starts_at_addr + SUBMACHINEGUN_COOLDOWN) as *mut f32) = 0.0f32;
*((local_player_ent.entity_starts_at_addr + SNIPER_COOLDOWN) as *mut f32) = 0.0f32;
*((local_player_ent.entity_starts_at_addr + RIFLE_COOLDOWN) as *mut f32) = 0.0f32;
}
if IS_INVULNERABLE
{
*((local_player_ent.entity_starts_at_addr + HEALTH_OFFSET_FROM_LOCAL_PLAYER) as *mut i32) = 1337;
*((local_player_ent.entity_starts_at_addr + ARMOR_OFFSET_FROM_LOCAL_PLAYER) as *mut i32) = 1337;
}
if IS_INFINITE_AMMO
{
*((local_player_ent.entity_starts_at_addr + AMMO_RIFLE) as *mut i32) = 40;
*((local_player_ent.entity_starts_at_addr + AMMO_IN_MAGAZINE_RIFLE) as *mut i32) = 40;

*((local_player_ent.entity_starts_at_addr + AMMO_PISTOL) as *mut i32) = 40;
*((local_player_ent.entity_starts_at_addr + AMMO_IN_MAGAZINE_PISTOL) as *mut i32) = 40;

*((local_player_ent.entity_starts_at_addr + AMMO_CARBINE) as *mut i32) = 40;
*((local_player_ent.entity_starts_at_addr + AMMO_IN_MAGAZINE_CARBINE) as *mut i32) = 40;

*((local_player_ent.entity_starts_at_addr + AMMO_SHOTGUN) as *mut i32) = 40;
*((local_player_ent.entity_starts_at_addr + AMMO_IN_MAGAZINE_SHOTGUN) as *mut i32) = 40;

*((local_player_ent.entity_starts_at_addr + AMMO_SUBMACHINEGUN) as *mut i32) = 40;
*((local_player_ent.entity_starts_at_addr + AMMO_IN_MAGAZINE_SUBMACHINEGUN) as *mut i32) = 40;

*((local_player_ent.entity_starts_at_addr + AMMO_SNIPER) as *mut i32) = 40;
*((local_player_ent.entity_starts_at_addr + AMMO_IN_MAGAZINE_SNIPER) as *mut i32) = 40;
}
}
}




// Example of finding a pattern and setting up the hook
pub fn setup_invul() {
unsafe {
thread::spawn(||
{
/*8B 8B EC 00 00 00 83 F9 19*/
/*8B ? ? ? ? ? 83 F9 19*/
/*x?????xxx*/
let pattern_mask = PatternMask::aob_to_pattern_mask(
"8B ? ? ? ? ? 83 F9 19"
);

println!("[GetLocalPlayerHealthHook] {:#x}", &pattern_mask);

let get_local_player_health_aob = find_pattern("ac_client.exe",
&*pattern_mask.aob_pattern,
&pattern_mask.mask_to_string());
/* &[0x8B, 0x8B, 0xEC, 0x00, 0x00, 0x00, 0x83, 0xF9, 0x19],
"x?????xxx");*/

if let Some(addr) = get_local_player_health_aob {
println!("[get_local_player_hook.rs->setup_invul] local player get current hp pattern found at: {:#x}", addr);
let hooker = Hooker::new(
addr,
HookType::JmpBack(get_local_player_health),
CallbackOption::None,
0,
HookFlags::empty(),
);
let hook_res = hooker.hook();

match hook_res {
Ok(trampoline_hook) => {
*LOCAL_PLAYER_HOOK.lock().unwrap() = Some(trampoline_hook);
println!("[get_local_player_hook.rs->setup_invul] local player get current hp pattern hook succeeded!");
}
Err(e) => {
println!("[get_local_player_hook.rs->setup_invul] local player get current hp pattern hook failed: {:?}", e);
}
}
} else {
println!("[get_local_player_hook.rs->setup_invul] local player get current hp pattern not found");
}
});
}
}
20 changes: 14 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

use std::ffi::c_void;

use windows::Win32::Foundation::{BOOL, HMODULE, TRUE};
use windows::Win32::Foundation::{BOOL, CloseHandle, HMODULE, TRUE};
use windows::Win32::System::LibraryLoader::DisableThreadLibraryCalls;
use windows::Win32::System::SystemServices::{DLL_PROCESS_ATTACH, DLL_PROCESS_DETACH, DLL_THREAD_ATTACH, DLL_THREAD_DETACH};
use windows::Win32::System::Threading::{CreateThread, THREAD_CREATION_FLAGS};

use vars::handles::CHEAT_DLL_HMODULE;

mod main_thread;
mod trampoline;

mod ui;
mod esp;
mod utils;
Expand All @@ -30,9 +30,11 @@ mod angle;
mod getclosestentity;
mod aimbot;
mod misc;
mod triggerbot;
mod triggerbot_hook;
mod game;
mod clash_font;
mod get_local_player_hook;
mod pattern_mask;

#[no_mangle]
#[allow(non_snake_case, unused_variables)]
Expand All @@ -45,14 +47,20 @@ extern "system" fn DllMain(
match call_reason {
DLL_PROCESS_ATTACH =>
unsafe {
DisableThreadLibraryCalls(dll_module).expect("[lib] Failed to disable thread library calls");
DisableThreadLibraryCalls(dll_module).
expect("[lib.rs] Failed to disable thread library calls");
CHEAT_DLL_HMODULE = dll_module.0 as isize;
CreateThread(None,
let handle = CreateThread(None,
0,
Some(main_thread::MainThread),
Some(dll_module.0),
THREAD_CREATION_FLAGS(0),
None).expect("[lib] Failed to create thread");
None).expect("[lib.rs] Failed to create thread");
if !handle.0.is_null()
{
CloseHandle(handle).
expect("[lib.rs] Failed to close null handle.");
}
}
DLL_THREAD_ATTACH => (),
DLL_THREAD_DETACH => (),
Expand Down
2 changes: 2 additions & 0 deletions src/main_thread.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::ffi::{c_void, CString};

use hudhook::{eject, Hudhook};
use hudhook::hooks::opengl3::ImguiOpenGl3Hooks;
use hudhook::windows::Win32::Foundation::HINSTANCE;
use windows::core::PCSTR;
use windows::Win32::System::LibraryLoader::GetModuleHandleA;
use windows::Win32::System::Threading::Sleep;

use crate::esp::esp_entrypoint;
use crate::ui::RenderLoop;
use crate::utils::setup_tracing;
Expand Down
2 changes: 2 additions & 0 deletions src/memorypatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ impl MemoryPatch {
}
}
// Constructor for patching with a buffer and size
#[allow(unused)]
pub fn new(buffer_to_patch: &[u8], size_buffer: usize, location: *mut c_void, size_location: usize) -> Result<Self, Box<dyn Error>> {
if size_buffer > size_location {
return Err("Error on MemoryPatch trying to write buffer bigger than expected".into());
Expand Down Expand Up @@ -54,6 +55,7 @@ impl MemoryPatch {
}

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

0 comments on commit 5fe5d86

Please sign in to comment.