Skip to content

Rust ESP#48

Draft
hmate9 wants to merge 1 commit intomainfrom
rust-esp
Draft

Rust ESP#48
hmate9 wants to merge 1 commit intomainfrom
rust-esp

Conversation

@hmate9
Copy link
Owner

@hmate9 hmate9 commented Jun 5, 2025

Initi rust esp that should be more performant.

@hmate9 hmate9 requested a review from Copilot June 5, 2025 10:57
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a Python helper to compute game offsets and implements a high-performance Rust ESP overlay that reads those offsets, opens the game process, and draws player skeletons in a layered window.

  • Introduces esp_rs_init.py to extract and print dynamic offsets.
  • Implements esp-rs/src/main.rs for the Rust overlay using Win32 APIs and continuous rendering.
  • Updates Cargo.toml with the windows crate and adds usage instructions in README.md.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
esp_rs_init.py New script to find and print game module offsets
esp-rs/src/main.rs Rust overlay logic: process memory reads and drawing
esp-rs/Cargo.toml Adds Windows crate dependency and feature flags
README.md Documents setup and usage for the Rust ESP overlay
Comments suppressed due to low confidence (4)

esp-rs/src/main.rs:124

  • [nitpick] The loop variable i is ambiguous; consider renaming it to entity_index or actor_id to make its purpose clearer.
for i in 1..16u32 {

esp-rs/src/main.rs:31

  • Add unit tests for parse_offsets to verify it handles valid lines, missing prefixes, and malformed input to improve coverage and reliability.
fn parse_offsets(output: &str) -> HashMap<String, usize> {

README.md:141

  • Document any Python prerequisites (e.g., pymem installation) and specify minimum Python version or pip install steps to ensure first-time users can run the script smoothly.
python esp_rs_init.py

esp-rs/src/main.rs:106

  • ShowWindow isn't imported or fully qualified, so it will not resolve. Import it from windows::Win32::UI::WindowsAndMessaging or call it with a full path.
unsafe { ShowWindow(hwnd, SW_SHOW); windows::Win32::UI::WindowsAndMessaging::SetLayeredWindowAttributes(hwnd, 0, 255, LWA_ALPHA) };

let screen_width = unsafe { GetSystemMetrics(SM_CXSCREEN) };
let screen_height = unsafe { GetSystemMetrics(SM_CYSCREEN) };
let hinstance: HINSTANCE = unsafe { GetModuleHandleW(None)? };
let class_name = PCWSTR::from_raw("RustESP\0".encode_utf16().collect::<Vec<_>>().as_ptr());
Copy link

Copilot AI Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The temporary Vec for the UTF-16 class name is dropped immediately, leaving class_name with a dangling pointer. Store the Vec in a variable that lives until after window creation or use a static UTF-16 literal.

Suggested change
let class_name = PCWSTR::from_raw("RustESP\0".encode_utf16().collect::<Vec<_>>().as_ptr());
let class_name_vec = "RustESP\0".encode_utf16().collect::<Vec<_>>();
let class_name = PCWSTR::from_raw(class_name_vec.as_ptr());

Copilot uses AI. Check for mistakes.
Comment on lines +146 to +151
let pen = CreatePen(PS_SOLID, 2, RGB(255, 0, 0));
let old = SelectObject(hdc, pen);
MoveToEx(hdc, sx, sy, None);
LineTo(hdc, sx, sy);
SelectObject(hdc, old);
DeleteObject(pen);
Copy link

Copilot AI Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating and deleting a GDI pen for every bone each frame is expensive. Move pen creation outside the loops and reuse it to reduce GDI overhead.

Suggested change
let pen = CreatePen(PS_SOLID, 2, RGB(255, 0, 0));
let old = SelectObject(hdc, pen);
MoveToEx(hdc, sx, sy, None);
LineTo(hdc, sx, sy);
SelectObject(hdc, old);
DeleteObject(pen);
MoveToEx(hdc, sx, sy, None);
LineTo(hdc, sx, sy);

Copilot uses AI. Check for mistakes.
Comment on lines +127 to +132
let addr = list as usize + 8 * (((i & 0x7FFF) >> 9) as usize) + 0x10;
let base = read_u64(handle, addr)?;
let mut ctrl = read_u64(handle, base as usize + 120 * ((i & 0x1FF) as usize))?;
if i == 0 { ctrl = read_u64(handle, client_base + local_ctrl_offset)?; }
let ph = read_u64(handle, ctrl as usize + 0x878)?;
let entry = read_u64(handle, list as usize + 8 * (((ph as u32 & 0x7FFF) >> 9) as usize) + 0x10)?;
Copy link

Copilot AI Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This index calculation uses several magic numbers (0x7FFF, shift 9, 8, 0x10). Extract them into named constants or add a comment explaining their origin.

Suggested change
let addr = list as usize + 8 * (((i & 0x7FFF) >> 9) as usize) + 0x10;
let base = read_u64(handle, addr)?;
let mut ctrl = read_u64(handle, base as usize + 120 * ((i & 0x1FF) as usize))?;
if i == 0 { ctrl = read_u64(handle, client_base + local_ctrl_offset)?; }
let ph = read_u64(handle, ctrl as usize + 0x878)?;
let entry = read_u64(handle, list as usize + 8 * (((ph as u32 & 0x7FFF) >> 9) as usize) + 0x10)?;
const ENTITY_MASK: u32 = 0x7FFF; // Mask for entity ID extraction
const ENTITY_SHIFT: usize = 9; // Bit shift for entity index calculation
const ENTITY_STRIDE: usize = 8; // Stride between entities in the list
const ENTITY_OFFSET: usize = 0x10; // Offset for entity address calculation
let addr = list as usize + ENTITY_STRIDE * (((i & ENTITY_MASK) >> ENTITY_SHIFT) as usize) + ENTITY_OFFSET;
let base = read_u64(handle, addr)?;
let mut ctrl = read_u64(handle, base as usize + 120 * ((i & 0x1FF) as usize))?;
if i == 0 { ctrl = read_u64(handle, client_base + local_ctrl_offset)?; }
let ph = read_u64(handle, ctrl as usize + 0x878)?;
let entry = read_u64(handle, list as usize + ENTITY_STRIDE * (((ph as u32 & ENTITY_MASK) >> ENTITY_SHIFT) as usize) + ENTITY_OFFSET)?;

Copilot uses AI. Check for mistakes.
from offset_finder import find_offsets


def main(process: str = "deadlock.exe") -> None:
Copy link

Copilot AI Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider renaming the parameter to process_name for clarity and adding an argparse interface to handle custom process names and flags more robustly.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants