|
1 | 1 | use std::borrow::Cow; |
2 | | -use std::mem::transmute; |
| 2 | +use std::{mem, ptr}; |
3 | 3 |
|
4 | 4 | use egui_hook::import_foreign; |
| 5 | +use pelite::pe64::{Pe, PeView}; |
5 | 6 |
|
6 | 7 | pub fn get_all_functions<'a>() -> impl Iterator<Item = (Cow<'a, str>, FunctionPtr)> { |
7 | 8 | unsafe { &*get_function_registry() } |
8 | 9 | .functions() |
9 | 10 | .map(|fun| (fun.name(), fun.ptr())) |
10 | 11 | } |
11 | 12 |
|
| 13 | +#[inline] |
12 | 14 | pub fn get_player() -> Entity { |
13 | 15 | Entity(get_player_ptr()) |
14 | 16 | } |
15 | 17 |
|
| 18 | +#[inline] |
16 | 19 | pub fn get_player_look_at() -> Entity { |
17 | 20 | let player = get_player(); |
18 | | - let mut entity = Entity(std::ptr::null()); |
| 21 | + let mut entity = Entity(ptr::null()); |
19 | 22 | get_player_look_at_ptr(&player, &mut entity); |
20 | 23 | entity |
21 | 24 | } |
@@ -92,14 +95,14 @@ pub struct FunctionPtr(usize); |
92 | 95 | impl FunctionPtr { |
93 | 96 | #[inline] |
94 | 97 | pub fn invoke_default<A>(&self, val: A) -> i64 { |
95 | | - let ptr = get_player(); |
96 | | - let func: extern "C" fn(Entity, Entity, A) -> i64 = unsafe { transmute(self.0) }; |
97 | | - func(ptr, ptr, val) |
| 98 | + let player = get_player(); |
| 99 | + let func: extern "C" fn(Entity, Entity, A) -> i64 = unsafe { mem::transmute(self.0) }; |
| 100 | + func(player, player, val) |
98 | 101 | } |
99 | 102 |
|
100 | 103 | #[inline] |
101 | 104 | pub fn invoke_with<A>(&self, a: Entity, b: Entity, val: A) -> i64 { |
102 | | - let func: extern "C" fn(Entity, Entity, A) -> i64 = unsafe { transmute(self.0) }; |
| 105 | + let func: extern "C" fn(Entity, Entity, A) -> i64 = unsafe { mem::transmute(self.0) }; |
103 | 106 | func(a, b, val) |
104 | 107 | } |
105 | 108 | } |
@@ -145,3 +148,12 @@ pub struct Type; |
145 | 148 | // TODO: reverse |
146 | 149 | #[repr(C)] |
147 | 150 | pub struct GameObject; |
| 151 | + |
| 152 | +const SUPPORTED_VERSION_TS: u32 = 1646857151; |
| 153 | + |
| 154 | +pub fn version_check() -> bool { |
| 155 | + let handle = unsafe { egui_hook::GetModuleHandleA(egui_hook::PSTR(ptr::null())) }; |
| 156 | + let pe = unsafe { PeView::module(handle.0 as *const _) }; |
| 157 | + let pe_ts = pe.file_header().TimeDateStamp; |
| 158 | + SUPPORTED_VERSION_TS == pe_ts |
| 159 | +} |
0 commit comments