11use std:: borrow:: Cow ;
2+ use std:: ffi:: CString ;
23use std:: { mem, ptr} ;
34
4- use egui_hook :: import_foreign ;
5+ use memhack_derive :: foreign_fn ;
56use pelite:: pe64:: { Pe , PeView } ;
67
78pub fn get_all_functions < ' a > ( ) -> impl Iterator < Item = ( Cow < ' a , str > , FunctionPtr ) > {
8- unsafe { & * get_function_registry ( ) }
9+ get_function_registry ( )
910 . functions ( )
1011 . map ( |fun| ( fun. name ( ) , fun. ptr ( ) ) )
1112}
1213
13- #[ inline]
14- pub fn get_player ( ) -> Entity {
15- Entity ( get_player_ptr ( ) )
16- }
17-
18- #[ inline]
1914pub fn get_player_look_at ( ) -> Entity {
2015 let player = get_player ( ) ;
21- let mut entity = Entity ( ptr :: null ( ) ) ;
22- get_player_look_at_ptr ( & player, & mut entity) ;
16+ let mut entity = Entity :: null ( ) ;
17+ get_player_look_at_ref ( & player, & mut entity) ;
2318 entity
2419}
2520
26- import_foreign ! ( 0x0867080 , get_function_registry( ) -> * const FunctionRegistry ) ;
27- import_foreign ! ( 0x040B710 , get_player_ptr( ) -> * const GameObject ) ;
28- import_foreign ! ( 0x0B17FF0 , get_player_look_at_ptr( player: * const Entity , entity: * mut Entity ) -> ( ) ) ;
21+ pub fn resolve_item ( name : & str ) -> Entity {
22+ let mut item = Entity :: null ( ) ;
23+ if let Ok ( str) = CString :: new ( name) {
24+ resolve_item_by_cstr ( & mut item, str. as_ptr ( ) ) ;
25+ }
26+ item
27+ }
28+
29+ #[ inline]
30+ #[ foreign_fn( 0x040B710 ) ]
31+ pub fn get_player ( ) -> Entity { }
32+ #[ inline]
33+ #[ foreign_fn( 0x0867080 ) ]
34+ fn get_function_registry < ' a > ( ) -> & ' a FunctionRegistry { }
35+ #[ inline]
36+ #[ foreign_fn( 0x0B17FF0 ) ]
37+ fn get_player_look_at_ref ( player : & Entity , entity : & mut Entity ) -> ( ) { }
38+ #[ inline]
39+ #[ foreign_fn( 0x0B30C00 ) ]
40+ fn resolve_item_by_cstr ( item : & mut Entity , name : * const i8 ) -> ( ) { }
41+ #[ inline]
42+ #[ foreign_fn( 0x0B13020 ) ]
43+ pub fn give_item ( target : & Entity , item : & Entity , quantity : u32 , x : u32 , notify : Notify ) -> ( ) { }
2944
3045#[ derive( Debug , Clone , Copy ) ]
3146#[ repr( C ) ]
@@ -36,6 +51,28 @@ impl Entity {
3651 pub fn null ( ) -> Entity {
3752 Entity ( std:: ptr:: null ( ) )
3853 }
54+
55+ #[ inline]
56+ pub fn is_null ( & self ) -> bool {
57+ self . 0 . is_null ( )
58+ }
59+ }
60+
61+ #[ repr( u32 ) ]
62+ pub enum Notify {
63+ Never = 0 ,
64+ Always = 2 ,
65+ }
66+
67+ impl From < bool > for Notify {
68+ #[ inline]
69+ fn from ( notify : bool ) -> Self {
70+ if notify {
71+ Notify :: Always
72+ } else {
73+ Notify :: Never
74+ }
75+ }
3976}
4077
4178#[ derive( Debug ) ]
0 commit comments