Skip to content

Commit

Permalink
feat/change windows injector to inject all mods instead of just libri…
Browse files Browse the repository at this point in the history
…vets
  • Loading branch information
notnotmelon committed Aug 15, 2024
1 parent 8687a75 commit b6e7e65
Show file tree
Hide file tree
Showing 7 changed files with 488 additions and 199 deletions.
97 changes: 97 additions & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "rivets-rs"
name = "rivets"
version = "0.1.0"
edition = "2021"
authors = ["Zachary Picco <[email protected]>"]
Expand All @@ -11,7 +11,7 @@ repository = "https://github.com/factorio-rivets/rivets-rs"
rivets-macros = { path = "rivets-macros" }
rivets-shared = { path = "rivets-shared" }
retour = { version = "0.3", features = ["static-detour"] }
abi_stable = "0.11"
dll-syringe = { version = "0.15", features = ["full"] }

[lints.clippy]
nursery = { level = "warn", priority = -1 }
Expand Down
36 changes: 21 additions & 15 deletions rivets-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,10 @@ pub fn detour(attr: TokenStream, item: TokenStream) -> TokenStream {
#[allow(unused_variables)]
#callback

pub unsafe extern "C" fn hook(address: u64) -> rivets::abi_stable::std_types::RResult<(), rivets::abi_stable::std_types::RBoxError> {
unsafe fn hook(address: u64) -> Result<(), rivets::retour::Error> {
let compiled_function: #cpp_function_header = std::mem::transmute(address);
Detour.initialize(compiled_function, #name)?.enable()?;
Ok(())
}
hook(address).map_err(|e| rivets::abi_stable::std_types::RBoxError::new(e)).into()
pub unsafe fn hook(address: u64) -> Result<(), rivets::retour::Error> {
let compiled_function: #cpp_function_header = std::mem::transmute(address);
Detour.initialize(compiled_function, #name)?.enable()?;
Ok(())
}
}
};
Expand Down Expand Up @@ -181,15 +178,24 @@ pub fn finalize(_: TokenStream) -> TokenStream {
}
});

let vec = quote! { abi_stable::std_types::RVec };

quote! {
#[rivets::abi_stable::sabi_extern_fn]
#[no_mangle]
pub extern "C" fn rivets_finalize() -> #vec<rivets::RivetsHook> {
let mut hooks: #vec<rivets::RivetsHook> = #vec::new();
#(#injects)*
hooks
rivets::dll_syringe::payload_procedure! {
fn rivets_finalize(symbol_cache: rivets::SymbolCache) -> Option<String> {
let base_address = match symbol_cache.get_module_base_address() {
Ok(base_address) => base_address,
Err(e) => return Some(format!("{e}")),
};

let mut hooks: Vec<rivets::RivetsHook> = Vec::new();
#(#injects)*
for hook in &hooks {
let inject_result = unsafe { symbol_cache.inject(base_address, hook) };
if inject_result.is_err() {
return Some(format!("{inject_result:?}"));
}
}
None
}
}
}
.into()
Expand Down
Loading

0 comments on commit b6e7e65

Please sign in to comment.