Skip to content

Commit

Permalink
Add stage0_commands config option, bump version to 0.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Prof9 committed Nov 7, 2023
1 parent 7339e08 commit 2bdf2ce
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 2 deletions.
58 changes: 57 additions & 1 deletion Cargo.lock

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

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ chaudloader has some development options which can be enabled to aid with mod de

- `developer_mode` (type: boolean, default: `false`): Enables developer mode. Required to be `true` in order to use any of the other development options.
- `enable_hook_guards` (type: boolean, default: `false`): Enables hook guards.
- `stage0_commands` (type: string array, default: `[]`): List of shell commands to run during stage0 before the game's entry point. If any of the commands returns a nonzero exit code, loading is aborted. The following variables can be used in commands:
- `%PID%`: Replaced by the game's process ID.

## For developers

Expand Down
3 changes: 2 additions & 1 deletion chaudloader/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chaudloader"
version = "0.9.2"
version = "0.10.0"
edition = "2021"

[lib]
Expand Down Expand Up @@ -33,3 +33,4 @@ maud = "0.25"
url = "2"
opener = "0.6"
proc-macro2 = "^1.0.60"
run_script = "0.10.1"
1 change: 1 addition & 0 deletions chaudloader/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct Config {
// Secret options
pub developer_mode: Option<bool>,
pub enable_hook_guards: Option<bool>, // requires developer_mode
pub stage0_commands: Option<std::collections::BTreeSet<String>>, // requires developer_mode
}

const CONFIG_FILE_NAME: &str = "chaudloader.toml";
Expand Down
12 changes: 12 additions & 0 deletions chaudloader/src/hooks/stage0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,18 @@ pub unsafe fn install() -> Result<(), anyhow::Error> {

let config = config::load()?;

if config.developer_mode == Some(true) {
for cmd in config.stage0_commands.iter().flatten() {
let (code, _, _) = run_script::run_script!(
cmd
.replace("%PID%", &std::process::id().to_string())
)?;
if code != 0 {
log::error!("Command {cmd} exited with code {code}");
}
}
}

unsafe {
// Hook GetProcAddress to avoid ntdll.dll hooks being installed
GetProcAddressForCaller
Expand Down

0 comments on commit 2bdf2ce

Please sign in to comment.