Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
trumank committed Nov 26, 2023
1 parent abeba51 commit 45acd0f
Showing 1 changed file with 49 additions and 12 deletions.
61 changes: 49 additions & 12 deletions src/integrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use tracing::info;
use uasset_utils::splice::{
extract_tracked_statements, inject_tracked_statements, walk, AssetVersion, TrackedStatement,
};
use unreal_asset::kismet::ExTrue;

use crate::providers::ModInfo;
use crate::{get_pak_from_data, open_file, DRGInstallation};
Expand Down Expand Up @@ -274,11 +275,13 @@ pub fn integrate<P: AsRef<Path>>(
"FSD/Content/UI/Menu_ServerList/_MENU_ServerList",
"FSD/Content/UI/Menu_ServerList/WND_JoiningModded",
];
let modding_tab_path = "FSD/Content/UI/Menu_EscapeMenu/MENU_EscapeMenu";

let mut deferred_assets: HashMap<&str, RawAsset> = HashMap::from_iter(
[pcb_path]
.iter()
.chain(patch_paths.iter())
.chain([modding_tab_path].iter())
.map(|path| (*path, RawAsset::default())),
);

Expand Down Expand Up @@ -434,22 +437,31 @@ pub fn integrate<P: AsRef<Path>>(
kind: IntegrationErrKind::Generic(e),
})?;
}
for patch_path in patch_paths {
let mut asset = deferred_assets[&patch_path]
.parse()
.map_err(|e| IntegrationErr {

let mut patch_deferred =
|path_str: &str, f: fn(&mut _) -> Result<()>| -> Result<(), IntegrationErr> {
let mut asset = deferred_assets[path_str]
.parse()
.map_err(|e| IntegrationErr {
mod_ctxt: None,
kind: IntegrationErrKind::Generic(e),
})?;
f(&mut asset).map_err(|e| IntegrationErr {
mod_ctxt: None,
kind: IntegrationErrKind::Generic(e),
})?;
patch(&mut asset).map_err(|e| IntegrationErr {
mod_ctxt: None,
kind: IntegrationErrKind::Generic(e),
})?;
write_asset(&mut mod_pak, asset, patch_path).map_err(|e| IntegrationErr {
mod_ctxt: None,
kind: IntegrationErrKind::Generic(e),
})?;
write_asset(&mut mod_pak, asset, path_str).map_err(|e| IntegrationErr {
mod_ctxt: None,
kind: IntegrationErrKind::Generic(e),
})?;
Ok(())
};

// apply patches to base assets
for patch_path in patch_paths {
patch_deferred(patch_path, patch)?;
}
patch_deferred(modding_tab_path, patch_modding_tab)?;

let mut int_pak_reader = Cursor::new(include_bytes!("../assets/integration.pak"));
let int_pak = repak::PakReader::new_any(&mut int_pak_reader).map_err(|e| IntegrationErr {
Expand Down Expand Up @@ -1147,3 +1159,28 @@ fn patch<C: Seek + Read>(asset: &mut Asset<C>) -> Result<()> {
inject_tracked_statements(asset, ver, statements);
Ok(())
}

fn patch_modding_tab<C: Seek + Read>(asset: &mut Asset<C>) -> Result<()> {
let ver = AssetVersion::new_from(asset);
let mut statements = extract_tracked_statements(asset, ver, &None);

for (_pi, statements) in statements.iter_mut() {
for statement in statements {
walk(&mut statement.ex, &|ex| match ex {
KismetExpression::ExLetBool(ex) => {
if matches!(&*ex.assignment_expression, KismetExpression::ExLocalVariable(v) if v.variable.new.as_ref().unwrap().path.last().unwrap().get_content(|c| c == "CallFunc_Should_Modding_Menu_be_Enabled_result"))
{
dbg!("PATCHED");
*ex.assignment_expression = ExTrue {
token: EExprToken::ExTrue,
}
.into()
}
}
_ => {}
});

Check failure on line 1181 in src/integrate.rs

View workflow job for this annotation

GitHub Actions / clippy

you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`

error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> src/integrate.rs:1169:43 | 1169 | ... walk(&mut statement.ex, &|ex| match ex { | _____________________________________^ 1170 | | ... KismetExpression::ExLetBool(ex) => { 1171 | | ... if matches!(&*ex.assignment_expression, KismetExpression::ExLocalVariable(v) if v.variable.new.as_ref().unwrap().path.last(... 1172 | | ... { ... | 1180 | | ... _ => {} 1181 | | ... }); | |_______^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match = note: `-D clippy::single-match` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::single_match)]` help: try | 1169 ~ walk(&mut statement.ex, &|ex| if let KismetExpression::ExLetBool(ex) = ex { 1170 + if matches!(&*ex.assignment_expression, KismetExpression::ExLocalVariable(v) if v.variable.new.as_ref().unwrap().path.last().unwrap().get_content(|c| c == "CallFunc_Should_Modding_Menu_be_Enabled_result")) 1171 + { 1172 + dbg!("PATCHED"); 1173 + *ex.assignment_expression = ExTrue { 1174 + token: EExprToken::ExTrue, 1175 + } 1176 + .into() 1177 + } 1178 ~ }); |

Check failure on line 1181 in src/integrate.rs

View workflow job for this annotation

GitHub Actions / clippy

you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`

error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> src/integrate.rs:1169:43 | 1169 | ... walk(&mut statement.ex, &|ex| match ex { | _____________________________________^ 1170 | | ... KismetExpression::ExLetBool(ex) => { 1171 | | ... if matches!(&*ex.assignment_expression, KismetExpression::ExLocalVariable(v) if v.variable.new.as_ref().unwrap().path.last(... 1172 | | ... { ... | 1180 | | ... _ => {} 1181 | | ... }); | |_______^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match = note: `-D clippy::single-match` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::single_match)]` help: try | 1169 ~ walk(&mut statement.ex, &|ex| if let KismetExpression::ExLetBool(ex) = ex { 1170 + if matches!(&*ex.assignment_expression, KismetExpression::ExLocalVariable(v) if v.variable.new.as_ref().unwrap().path.last().unwrap().get_content(|c| c == "CallFunc_Should_Modding_Menu_be_Enabled_result")) 1171 + { 1172 + dbg!("PATCHED"); 1173 + *ex.assignment_expression = ExTrue { 1174 + token: EExprToken::ExTrue, 1175 + } 1176 + .into() 1177 + } 1178 ~ }); |
}
}
inject_tracked_statements(asset, ver, statements);
Ok(())
}

0 comments on commit 45acd0f

Please sign in to comment.