forked from StrafesNET/map-tool
implement extract
This commit is contained in:
parent
29374e4ff5
commit
e309f15cb8
43
src/main.rs
43
src/main.rs
@ -15,10 +15,16 @@ enum Commands {
|
|||||||
Download(MapList),
|
Download(MapList),
|
||||||
Upload,
|
Upload,
|
||||||
Scan,
|
Scan,
|
||||||
|
Extract(Map),
|
||||||
Replace,
|
Replace,
|
||||||
Interactive,
|
Interactive,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Args)]
|
||||||
|
struct Map {
|
||||||
|
id:u64,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Args)]
|
#[derive(Args)]
|
||||||
struct MapList {
|
struct MapList {
|
||||||
maps: Vec<u64>,
|
maps: Vec<u64>,
|
||||||
@ -203,6 +209,42 @@ fn scan() -> Result<(), Box<dyn std::error::Error>>{
|
|||||||
std::fs::write("id",id.to_string())?;
|
std::fs::write("id",id.to_string())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
fn extract(file_id:u64) -> Result<(), Box<dyn std::error::Error>>{
|
||||||
|
let mut id = 0;
|
||||||
|
//Construct allowed scripts
|
||||||
|
let mut script_set = std::collections::HashSet::<String>::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<dyn std::error::Error>>{
|
fn replace() -> Result<(), Box<dyn std::error::Error>>{
|
||||||
let allowed_map=get_allowed_map()?;
|
let allowed_map=get_allowed_map()?;
|
||||||
let replace_map=get_replace_map()?;
|
let replace_map=get_replace_map()?;
|
||||||
@ -457,5 +499,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
Commands::Scan=>scan(),
|
Commands::Scan=>scan(),
|
||||||
Commands::Replace=>replace(),
|
Commands::Replace=>replace(),
|
||||||
Commands::Interactive=>interactive(),
|
Commands::Interactive=>interactive(),
|
||||||
|
Commands::Extract(map)=>extract(map.id),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user