From e309f15cb8ed006cb853d34c6aec2571f9333431 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Tue, 12 Sep 2023 17:52:45 -0700 Subject: [PATCH] implement extract --- src/main.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/main.rs b/src/main.rs index b100163..20da11f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,10 +15,16 @@ enum Commands { Download(MapList), Upload, Scan, + Extract(Map), Replace, Interactive, } +#[derive(Args)] +struct Map { + id:u64, +} + #[derive(Args)] struct MapList { maps: Vec, @@ -203,6 +209,42 @@ fn scan() -> Result<(), Box>{ std::fs::write("id",id.to_string())?; Ok(()) } +fn extract(file_id:u64) -> Result<(), Box>{ + let mut id = 0; + //Construct allowed scripts + let mut script_set = std::collections::HashSet::::new(); + + let file_id_string=file_id.to_string(); + + for entry in std::fs::read_dir("maps/unprocessed")? { + let file_thing=entry?; + if file_thing.file_name().to_str().unwrap().find(&file_id_string).is_none(){ + continue; + } + let input = std::io::BufReader::new(std::fs::File::open(file_thing.path())?); + + let dom = rbx_binary::from_reader(input)?; + + let scripts = get_scripts(dom); + + //extract scribb + for script in scripts.iter() { + if let Some(rbx_dom_weak::types::Variant::String(s)) = script.properties.get("Source") { + if script_set.contains(s) { + continue; + }else{ + script_set.insert(s.clone()); + std::fs::write(format!("scripts/extracted/{:?}_{}_{}.lua",file_thing.file_name(),id,script.name),s)?; + id+=1; + } + }else{ + panic!("FATAL: failed to get source for {:?}",file_thing.file_name()); + } + } + } + println!("extracted {} {}",id,if id==1 {"script"}else{"scripts"}); + Ok(()) +} fn replace() -> Result<(), Box>{ let allowed_map=get_allowed_map()?; let replace_map=get_replace_map()?; @@ -457,5 +499,6 @@ fn main() -> Result<(), Box> { Commands::Scan=>scan(), Commands::Replace=>replace(), Commands::Interactive=>interactive(), + Commands::Extract(map)=>extract(map.id), } }