-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optim: Add remote simulation support
- Loading branch information
Showing
8 changed files
with
740 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//! Bunnymod XT. | ||
use std::os::raw::c_char; | ||
use std::ptr::NonNull; | ||
|
||
use hltas::HLTAS; | ||
|
||
use crate::utils::{MainThreadMarker, Pointer, PointerTrait}; | ||
|
||
pub static BXT_TAS_LOAD_SCRIPT_FROM_STRING: Pointer<unsafe extern "C" fn(*const c_char)> = | ||
Pointer::empty(b"bxt_tas_load_script_from_string\0"); | ||
|
||
static POINTERS: &[&dyn PointerTrait] = &[&BXT_TAS_LOAD_SCRIPT_FROM_STRING]; | ||
|
||
#[cfg(unix)] | ||
fn open_library() -> Option<libloading::Library> { | ||
use libc::{RTLD_NOLOAD, RTLD_NOW}; | ||
|
||
let library = unsafe { | ||
libloading::os::unix::Library::open(Some("libBunnymodXT.so"), RTLD_NOW | RTLD_NOLOAD) | ||
}; | ||
library.ok().map(libloading::Library::from) | ||
} | ||
|
||
#[cfg(windows)] | ||
fn open_library() -> Option<libloading::Library> { | ||
libloading::os::windows::Library::open_already_loaded("BunnymodXT.dll") | ||
.ok() | ||
.map(libloading::Library::from) | ||
} | ||
|
||
#[instrument(name = "bxt::find_pointers", skip_all)] | ||
pub unsafe fn find_pointers(marker: MainThreadMarker) { | ||
let library = match open_library() { | ||
Some(library) => library, | ||
None => { | ||
debug!("could not find Bunnymod XT"); | ||
return; | ||
} | ||
}; | ||
|
||
for pointer in POINTERS { | ||
let ptr = library | ||
.get(pointer.symbol()) | ||
.ok() | ||
.and_then(|sym| NonNull::new(*sym)); | ||
pointer.set(marker, ptr); | ||
pointer.log(marker); | ||
} | ||
} | ||
|
||
pub unsafe fn tas_load_script(marker: MainThreadMarker, script: &HLTAS) { | ||
let mut buf = Vec::new(); | ||
script.to_writer(&mut buf).unwrap(); | ||
|
||
// Write the terminating NULL byte. | ||
buf.push(0); | ||
|
||
BXT_TAS_LOAD_SCRIPT_FROM_STRING.get(marker)(buf.as_ptr().cast()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
//! Hooked functions. | ||
pub mod bxt; | ||
pub mod engine; | ||
pub mod sdl; | ||
pub mod server; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.