-
-
Notifications
You must be signed in to change notification settings - Fork 491
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fb34aec
commit dcfdbc9
Showing
9 changed files
with
179 additions
and
21 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,40 @@ | ||
use std::{error::Error, sync::{LazyLock, Mutex}, path::PathBuf}; | ||
|
||
use libloading::Library; | ||
|
||
use crate::utils::files; | ||
|
||
pub static BOOTSTRAP: LazyLock<Mutex<Option<Library>>> = LazyLock::new(|| Mutex::new(None)); | ||
|
||
pub fn init() -> Result<(), Box<dyn Error>> { | ||
let args: Vec<String> = std::env::args().collect(); | ||
|
||
//TODO: Support UTF-16 (it will suck) | ||
let mut base_dir = std::env::current_dir()?; | ||
let mut no_mods = false; | ||
|
||
for arg in args.iter() { | ||
if arg.starts_with("--melonloader.basedir") { | ||
let a: Vec<&str> = arg.split("=").collect(); | ||
base_dir = PathBuf::from(a[1]); | ||
} | ||
|
||
if arg.contains("--no-mods") { | ||
no_mods = true; | ||
} | ||
} | ||
|
||
//return Ok, and silently stop loading MelonLoader, if the user has specified to not load mods, | ||
//or if the game is not a Unity game | ||
if no_mods { | ||
return Ok(()); | ||
} | ||
|
||
let bootstrap_path = files::get_bootstrap_path(&base_dir)?; | ||
|
||
unsafe { | ||
*BOOTSTRAP.try_lock()? = Some(Library::new(&bootstrap_path)?); | ||
} | ||
|
||
Ok(()) | ||
} |
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,23 @@ | ||
//! lets us throw an internal failure | ||
/// Throws an internal failure with the given message | ||
/// | ||
/// This creates a message box, and then panics. | ||
/// It uses the same syntax as _format!_ | ||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
/// # use utils::assert; | ||
/// assert::internal_failure!("This is an internal failure"); | ||
/// ``` | ||
#[macro_export] | ||
macro_rules! internal_failure { | ||
($($arg:tt)*) => {{ | ||
let msg = &format_args!($($arg)*).to_string(); | ||
|
||
std::println!("{}", msg); | ||
let _ = msgbox::create("Internal Failure", msg, msgbox::IconType::Error); | ||
std::process::exit(1); | ||
}}; | ||
} |
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,9 @@ | ||
use std::path::PathBuf; | ||
|
||
use thiserror::Error; | ||
|
||
#[derive(Debug, Error)] | ||
pub enum ProxyError { | ||
#[error("failed to find Bootstrap at \"{0}\" please make sure you have installed MelonLoader correctly")] | ||
BootstrapNotFound(PathBuf), | ||
} |
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,20 @@ | ||
use std::{env::consts::DLL_EXTENSION, path::PathBuf}; | ||
|
||
use super::errors::ProxyError; | ||
|
||
/// search for Bootstrap in the given path | ||
pub fn get_bootstrap_path(base_path: &PathBuf) -> Result<PathBuf, ProxyError> { | ||
let bootstrap_names = ["melon_bootstrap", "libmelon_bootstrap"]; //by convention, on unix, the library is prefixed with "lib" | ||
|
||
let path = base_path.join("MelonLoader").join("Dependencies"); | ||
|
||
for name in bootstrap_names.iter() { | ||
let bootstrap_path = path.join(name).with_extension(DLL_EXTENSION); | ||
|
||
if bootstrap_path.exists() { | ||
return Ok(bootstrap_path); | ||
} | ||
} | ||
|
||
Err(ProxyError::BootstrapNotFound(base_path.to_owned())) | ||
} |
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,3 @@ | ||
pub mod assert; | ||
pub mod errors; | ||
pub mod files; |