map-tool/src/main.rs

75 lines
2.3 KiB
Rust
Raw Normal View History

2023-09-05 00:16:02 +00:00
fn class_is_a(class: &str, superclass: &str) -> bool {
if class==superclass {
return true
}
let class_descriptor=rbx_reflection_database::get().classes.get(class);
if let Some(descriptor) = &class_descriptor {
if let Some(class_super) = &descriptor.superclass {
return class_is_a(&class_super, superclass)
}
}
return false
}
2023-09-13 01:16:45 +00:00
fn get_scripts(dom:rbx_dom_weak::WeakDom) -> Vec<rbx_dom_weak::Instance>{
let mut scripts = std::vec::Vec::<rbx_dom_weak::Instance>::new();
let (_,mut instances) = dom.into_raw();
for (_,instance) in instances.drain() {
if class_is_a(instance.class.as_str(), "LuaSourceContainer") {
scripts.push(instance);
2023-09-05 00:16:02 +00:00
}
}
2023-09-13 01:16:45 +00:00
scripts
2023-09-05 00:16:02 +00:00
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Using buffered I/O is recommended with rbx_binary
let input = std::io::BufReader::new(std::fs::File::open("map.rbxm")?);
let dom = rbx_binary::from_reader(input)?;
//Construct allowed scripts
let mut allowed = std::collections::HashSet::<String>::new();
for entry in std::fs::read_dir("allowed")? {
allowed.insert(std::fs::read_to_string(entry?.path())?);
}
2023-09-13 01:16:45 +00:00
let scripts = get_scripts(dom);
//check scribb
let mut any_failed=false;
for script in scripts.iter() {
2023-09-05 00:34:31 +00:00
if let Some(rbx_dom_weak::types::Variant::String(s)) = script.properties.get("Source") {
if allowed.contains(s) {
println!("pass");
}else{
println!("fail");
any_failed=true;
std::fs::write(format!("blocked/{}.lua",i),s)?;
}
}else{
println!("failed to get source");
any_failed=true;
}
2023-09-05 00:16:02 +00:00
}else{
2023-09-05 00:34:31 +00:00
println!("failed to deref script");
2023-09-05 00:16:02 +00:00
any_failed=true;
}
}
if any_failed {
println!("One or more scripts are not allowed.");
return Ok(())//everything is not ok but idk how to return an error LMAO
}
println!("All scripts passed!");
// std::process::Command::new("rbxcompiler")
// .arg("--compile=false")
// .arg("--group=6980477")
// .arg("--asset=5692139100")
// .arg("--input=map.rbxm")
// .spawn()?;
Ok(())
2023-09-04 19:24:00 +00:00
}