1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//! Rust bindings for the [Geode SDK](https://geode-sdk.org)
// //! 
// //! ## Usage
// //! 

#![feature(abi_thiscall, stmt_expr_attributes)]

//doing #[link(name = "Geode", kind = "raw-dylib")] didn't work :(
#[doc(hidden)]
macro_rules! geo_fn {
    ($target_ty:ty, $sym_name:expr) => {
        #[allow(unused_unsafe)]
        unsafe {
            let base = windows::Win32::System::LibraryLoader::GetModuleHandleA(windows::core::s!(
                "Geode.dll"
            ))
            .unwrap();

            let c_name = std::ffi::CString::new($sym_name).unwrap();

            let address = windows::Win32::System::LibraryLoader::GetProcAddress(
                base,
                windows::core::PCSTR(c_name.as_ptr() as _),
            )
            .unwrap() as usize;
            std::mem::transmute::<_, $target_ty>(address)
        }
    };
}

///Defines the entry point for the mod.
///Requires the `windows` crate with the following features: ["Win32_Foundation", "Win32_System_Threading", "Win32_Security"].
#[macro_export]
macro_rules! entry {
    ($($exprs:tt)*) => {
        #[no_mangle]
        #[allow(non_snake_case)]
        unsafe extern "system" fn DllMain(
            _module: *const (),
            call_reason: u32,
            _reserved: *const (),
        ) -> u32 {
            if call_reason == 1 {
                windows::Win32::System::LibraryLoader::DisableThreadLibraryCalls(
                    windows::Win32::Foundation::HINSTANCE(_module as isize),
                );

                windows::Win32::System::Threading::CreateThread(
                    None,
                    0,
                    Some(main_thread),
                    Some(_module as _),
                    windows::Win32::System::Threading::THREAD_CREATION_FLAGS(0),
                    None,
                )
                .unwrap();
            }

            1
        }

        unsafe extern "system" fn main_thread(_: *mut core::ffi::c_void) -> u32 {
            $($exprs)*
            0
        }
    }
}

pub mod hook;
pub mod loader;
pub mod log;
pub mod mod_;
pub mod prelude;
mod stl;
pub mod tulip;
pub mod utils;