Created
June 28, 2021 18:16
-
-
Save benhall-7/dfc77d045e1305568efab40af889f0fb to your computer and use it in GitHub Desktop.
An example function that edits and saves a param in ui_chara_db.prc
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
use prc::*; | |
use prc::hash40::{Hash40, to_hash40}; | |
fn edit_ui_chara_db() { | |
// with the param data ready, | |
let mut root = open("ui_chara_db.prc").unwrap(); | |
// enter the first and only node of the file ("db_root") | |
let (db_root_hash, db_root) = &mut root.0[0]; | |
assert_eq!(*db_root_hash, to_hash40("db_root")); | |
let db_root_list = db_root.try_into_mut::<ParamList>().unwrap(); | |
// iterate the list to find the param with Lucina's data | |
// we could go to the exact index, but this is subject to change across game updates. | |
let lucina = db_root_list.0.iter_mut().find(|param| { | |
let ui_chara_struct = param.try_into_ref::<ParamStruct>().unwrap(); | |
// we assume ui_chara_id will always be the first param. | |
// given the file, this is a safe assumption, but there are | |
// more fool-proof ways of searching for the right node. | |
let (_, ui_chara_id) = &ui_chara_struct.0[0]; | |
let ui_chara_hash = ui_chara_id.try_into_ref::<Hash40>().unwrap(); | |
// check to make sure it's lucina | |
*ui_chara_hash == to_hash40("ui_chara_lucina") | |
}).unwrap().try_into_mut::<ParamStruct>().unwrap(); | |
// now we have lucina's data, we can convert to a dictionary to gain faster access | |
// to arbitrary keys, but since we only want to change 1 param, we'll just iterate | |
lucina.0.iter_mut().for_each(|(hash, param)| { | |
if *hash == to_hash40("ui_series_id") { | |
*param.try_into_mut::<Hash40>().unwrap() = to_hash40("ui_series_persona"); | |
} | |
}); | |
save("new_ui_chara_db", &root).unwrap(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment