map-tool: add command to extract union data
This commit is contained in:
@@ -13,6 +13,7 @@ const DOWNLOAD_LIMIT:usize=16;
|
||||
pub enum Commands{
|
||||
RobloxToSNF(RobloxToSNFSubcommand),
|
||||
DownloadAssets(DownloadAssetsSubcommand),
|
||||
ExtractUnionData(ExtractUnionData),
|
||||
}
|
||||
|
||||
#[derive(clap::Args)]
|
||||
@@ -33,6 +34,13 @@ pub struct DownloadAssetsSubcommand{
|
||||
#[arg(long,group="cookie",required=true)]
|
||||
cookie_file:Option<PathBuf>,
|
||||
}
|
||||
#[derive(clap::Args)]
|
||||
pub struct ExtractUnionData{
|
||||
#[arg(long)]
|
||||
output_folder:PathBuf,
|
||||
#[arg(long)]
|
||||
input_file:PathBuf,
|
||||
}
|
||||
|
||||
impl Commands{
|
||||
pub async fn run(self)->AResult<()>{
|
||||
@@ -46,6 +54,7 @@ impl Commands{
|
||||
subcommand.cookie_file,
|
||||
).await?,
|
||||
).await,
|
||||
Commands::ExtractUnionData(subcommand)=>extract_union_data(subcommand.input_file,subcommand.output_folder).await,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -347,3 +356,28 @@ pub fn convert_to_snf(dom:rbx_dom_weak::WeakDom)->Result<ConvertOutput,ConvertEr
|
||||
convert_errors,
|
||||
})
|
||||
}
|
||||
|
||||
async fn extract_union_data(input_file:PathBuf,output_folder:PathBuf)->AResult<()>{
|
||||
let data=tokio::fs::read(&input_file).await?;
|
||||
|
||||
let dom=rbx_binary::from_reader(Cursor::new(data))?;
|
||||
let &[referent]=dom.root().children()else{
|
||||
panic!("Expected one child");
|
||||
};
|
||||
let Some(instance)=dom.get_by_ref(referent)else{
|
||||
panic!("Missing instance");
|
||||
};
|
||||
let output_file=output_folder.join(input_file.file_stem().unwrap());
|
||||
if let Some(rbx_dom_weak::types::Variant::BinaryString(data))=instance.properties.get(&rbx_dom_weak::ustr("PhysicsData")){
|
||||
let mut physics_data_path=output_file.clone();
|
||||
physics_data_path.set_extension("physicsdata");
|
||||
tokio::fs::write(physics_data_path,data).await?;
|
||||
}
|
||||
if let Some(rbx_dom_weak::types::Variant::BinaryString(data))=instance.properties.get(&rbx_dom_weak::ustr("MeshData")){
|
||||
let mut mesh_data_path=output_file.clone();
|
||||
mesh_data_path.set_extension("meshdata");
|
||||
tokio::fs::write(mesh_data_path,data).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user