Skip to content

Commit

Permalink
Logging and version check
Browse files Browse the repository at this point in the history
  • Loading branch information
jac3km4 committed Mar 15, 2022
1 parent 38b6518 commit 36da461
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 64 deletions.
102 changes: 100 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 23 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,28 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
egui = "0.17"
egui-hook = { git = "https://github.com/jac3km4/egui-hook", rev = "v0.0.3" }
rhai = "1.5"
phf = { version = "0.10", features = ["macros"] }
heck = "0.4"
log = "0.4"

[dependencies.pelite]
version = "0.9"
default-features = false

[dependencies.flexi_logger]
version = "0.22"
default-features = false

[dependencies.phf]
version = "0.10"
default-features = false
features = ["macros"]

[dependencies.egui]
version = "0.17"
default-features = false
features = ["single_threaded"]

[dependencies.egui-hook]
git = "https://github.com/jac3km4/egui-hook"
rev = "v0.0.4"
24 changes: 18 additions & 6 deletions src/elex.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
use std::borrow::Cow;
use std::mem::transmute;
use std::{mem, ptr};

use egui_hook::import_foreign;
use pelite::pe64::{Pe, PeView};

pub fn get_all_functions<'a>() -> impl Iterator<Item = (Cow<'a, str>, FunctionPtr)> {
unsafe { &*get_function_registry() }
.functions()
.map(|fun| (fun.name(), fun.ptr()))
}

#[inline]
pub fn get_player() -> Entity {
Entity(get_player_ptr())
}

#[inline]
pub fn get_player_look_at() -> Entity {
let player = get_player();
let mut entity = Entity(std::ptr::null());
let mut entity = Entity(ptr::null());
get_player_look_at_ptr(&player, &mut entity);
entity
}
Expand Down Expand Up @@ -92,14 +95,14 @@ pub struct FunctionPtr(usize);
impl FunctionPtr {
#[inline]
pub fn invoke_default<A>(&self, val: A) -> i64 {
let ptr = get_player();
let func: extern "C" fn(Entity, Entity, A) -> i64 = unsafe { transmute(self.0) };
func(ptr, ptr, val)
let player = get_player();
let func: extern "C" fn(Entity, Entity, A) -> i64 = unsafe { mem::transmute(self.0) };
func(player, player, val)
}

#[inline]
pub fn invoke_with<A>(&self, a: Entity, b: Entity, val: A) -> i64 {
let func: extern "C" fn(Entity, Entity, A) -> i64 = unsafe { transmute(self.0) };
let func: extern "C" fn(Entity, Entity, A) -> i64 = unsafe { mem::transmute(self.0) };
func(a, b, val)
}
}
Expand Down Expand Up @@ -145,3 +148,12 @@ pub struct Type;
// TODO: reverse
#[repr(C)]
pub struct GameObject;

const SUPPORTED_VERSION_TS: u32 = 1646857151;

pub fn version_check() -> bool {
let handle = unsafe { egui_hook::GetModuleHandleA(egui_hook::PSTR(ptr::null())) };
let pe = unsafe { PeView::module(handle.0 as *const _) };
let pe_ts = pe.file_header().TimeDateStamp;
SUPPORTED_VERSION_TS == pe_ts
}
Loading

0 comments on commit 36da461

Please sign in to comment.