Skip to content

Commit

Permalink
class isn't always the first export
Browse files Browse the repository at this point in the history
  • Loading branch information
bananaturtlesandwich committed Apr 9, 2024
1 parent ec95380 commit 6f61b4f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ authors = ["spuds"]
repository = "https://github.com/bananaturtlesandwich/spaghetti"
description = "a function hooker for cooked unreal engine blueprints"
readme = "README.md"
version = "1.0.0"
version = "1.0.1"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Options:
- mind blown

# credits
- [truman](https://github.com/trumank) for creating [kismet-analyzer](https://github.com/trumank/kismet-analyzer) since, although implemented differently it helped me come up with this idea
- [truman](https://github.com/trumank) for creating [kismet-analyzer](https://github.com/trumank/kismet-analyzer) since, although implemented differently, it helped me come up with this idea
- [atenfyr](https://github.com/atenfyr) for creating the extensive [UAssetAPI](https://github.com/atenfyr/UAssetAPI) which made this project possible ❤️
- [localcc](https://github.com/localcc) for rewriting it as [unreal_asset](https://github.com/AstroTechies/unrealmodding/tree/main/unreal_asset), allowing me to program this in [rust <img src="https://raw.githubusercontent.com/Tarikul-Islam-Anik/Animated-Fluent-Emojis/master/Emojis/Food/Crab.png" width="20" />](https://www.rust-lang.org/)

44 changes: 24 additions & 20 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ fn main() {
}
let version = match version {
Some(version) => version.0,
// None if ignored => {
// print!("version [default: 5.1]: ");
// std::io::Write::flush(&mut std::io::stdout())
// .map_err(clap::Error::from)
// .unwrap_or_else(|e| e.exit());
// let mut buf = String::new();
// std::io::stdin()
// .read_line(&mut buf)
// .map_err(clap::Error::from)
// .unwrap_or_else(|e| e.exit());
// cli::VersionParser::parse(&buf).unwrap_or(
// unreal_asset::engine_version::EngineVersion::VER_UE5_1,
// )
// }
None if ignored => {
print!("version [default: 5.1]: ");
std::io::Write::flush(&mut std::io::stdout())
.map_err(clap::Error::from)
.unwrap_or_else(|e| e.exit());
let mut buf = String::new();
std::io::stdin()
.read_line(&mut buf)
.map_err(clap::Error::from)
.unwrap_or_else(|e| e.exit());
cli::VersionParser::parse(&buf)
.map(|v| v.0)
.unwrap_or(unreal_asset::engine_version::EngineVersion::VER_UE5_1)
}
None => unreal_asset::engine_version::EngineVersion::VER_UE5_1,
};
let hook = io::open(hook_path, version).unwrap_or_else(|e| {
Expand All @@ -76,8 +76,14 @@ fn main() {
});
let mut name_map = orig.get_name_map().clone_resource();
// why does it need the import for cast?
let (class, exports) = orig.asset_data.exports.split_at_mut(1);
let Export::ClassExport(class) = &mut class[0] else {
let split = orig
.asset_data
.exports
.iter()
.position(|ex| matches!(ex, Export::ClassExport(_)))
.unwrap_or_default();
let (class, exports) = orig.asset_data.exports.split_at_mut(split + 1);
let Export::ClassExport(class) = &mut class[split] else {
eprintln!("provided file is not a blueprint");
std::process::exit(0)
};
Expand Down Expand Up @@ -121,13 +127,11 @@ fn main() {
class.func_map.insert(
orig.get_base_export().object_name.clone(),
unreal_asset::types::PackageIndex {
// i + 2 since exports is one export short
index: (i + 2) as i32,
index: (i + split + 2) as i32,
},
)
}
// len + 1 since exports is one export short
let mut insert = exports.len() + 1;
let mut insert = exports.len() + split + 1;
for (i, (_, name)) in funcs.iter().enumerate() {
class.func_map.insert(
name_map.get_mut().add_fname(name),
Expand Down

0 comments on commit 6f61b4f

Please sign in to comment.