forked from StrafesNET/map-tool
ref cannot refer to object in another dom
This commit is contained in:
parent
e309f15cb8
commit
37f0dad7a1
86
src/main.rs
86
src/main.rs
@ -42,7 +42,16 @@ fn class_is_a(class: &str, superclass: &str) -> bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fn recursive_collect_scripts(scripts: &mut std::vec::Vec<rbx_dom_weak::types::Ref>,dom: &rbx_dom_weak::WeakDom, instance: &rbx_dom_weak::Instance){
|
||||
for &referent in instance.children() {
|
||||
if let Some(c) = dom.get_by_ref(referent) {
|
||||
if class_is_a(c.class.as_str(), "LuaSourceContainer") {
|
||||
scripts.push(c.referent());//copy ref
|
||||
}
|
||||
recursive_collect_scripts(scripts,dom,c);
|
||||
}
|
||||
}
|
||||
}
|
||||
fn get_full_name(dom:&rbx_dom_weak::WeakDom,instance:&rbx_dom_weak::Instance) -> String{
|
||||
let mut full_name=instance.name.clone();
|
||||
let mut pref=instance.parent();
|
||||
@ -72,15 +81,9 @@ fn get_full_name(dom:&rbx_dom_weak::WeakDom,instance:&rbx_dom_weak::Instance) ->
|
||||
//I can edit the file and it will edit it in place
|
||||
//I pass/fail(with comment)/allow each script
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
fn get_script_refs(dom:&rbx_dom_weak::WeakDom) -> Vec<rbx_dom_weak::types::Ref>{
|
||||
let mut scripts = std::vec::Vec::new();
|
||||
recursive_collect_scripts(&mut scripts, dom, dom.root());
|
||||
scripts
|
||||
}
|
||||
|
||||
@ -167,12 +170,13 @@ fn scan() -> Result<(), Box<dyn std::error::Error>>{
|
||||
|
||||
let dom = rbx_binary::from_reader(input)?;
|
||||
|
||||
let scripts = get_scripts(dom);
|
||||
let script_refs = get_script_refs(&dom);
|
||||
|
||||
//check scribb
|
||||
let mut fail_count=0;
|
||||
let mut fail_type=Scan::Passed;
|
||||
for script in scripts.iter() {
|
||||
for &script_ref in script_refs.iter() {
|
||||
if let Some(script)=dom.get_by_ref(script_ref){
|
||||
if let Some(rbx_dom_weak::types::Variant::String(s)) = script.properties.get("Source") {
|
||||
//flag keywords and instantly fail
|
||||
if check_source_illegal_keywords(s){
|
||||
@ -194,6 +198,9 @@ fn scan() -> Result<(), Box<dyn std::error::Error>>{
|
||||
}else{
|
||||
panic!("FATAL: failed to get source for {:?}",file_thing.file_name());
|
||||
}
|
||||
}else{
|
||||
panic!("FATAL: failed to get_by_ref {:?}",script_ref);
|
||||
}
|
||||
}
|
||||
let mut dest=match fail_type {
|
||||
Scan::Passed => std::path::PathBuf::from("maps/processed"),
|
||||
@ -225,10 +232,11 @@ fn extract(file_id:u64) -> Result<(), Box<dyn std::error::Error>>{
|
||||
|
||||
let dom = rbx_binary::from_reader(input)?;
|
||||
|
||||
let scripts = get_scripts(dom);
|
||||
let script_refs = get_script_refs(&dom);
|
||||
|
||||
//extract scribb
|
||||
for script in scripts.iter() {
|
||||
for &script_ref in script_refs.iter() {
|
||||
if let Some(script)=dom.get_by_ref(script_ref){
|
||||
if let Some(rbx_dom_weak::types::Variant::String(s)) = script.properties.get("Source") {
|
||||
if script_set.contains(s) {
|
||||
continue;
|
||||
@ -240,6 +248,9 @@ fn extract(file_id:u64) -> Result<(), Box<dyn std::error::Error>>{
|
||||
}else{
|
||||
panic!("FATAL: failed to get source for {:?}",file_thing.file_name());
|
||||
}
|
||||
}else{
|
||||
panic!("FATAL: failed to get_by_ref {:?}",script_ref);
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("extracted {} {}",id,if id==1 {"script"}else{"scripts"});
|
||||
@ -253,18 +264,16 @@ fn replace() -> Result<(), Box<dyn std::error::Error>>{
|
||||
let file_thing=entry?;
|
||||
|
||||
let input = std::io::BufReader::new(std::fs::File::open(file_thing.path())?);
|
||||
let dom = rbx_binary::from_reader(input)?;
|
||||
let mut dom = rbx_binary::from_reader(input)?;
|
||||
|
||||
let input = std::io::BufReader::new(std::fs::File::open(file_thing.path())?);
|
||||
let mut write_dom = rbx_binary::from_reader(input)?;
|
||||
|
||||
let scripts = get_scripts(dom);
|
||||
let script_refs = get_script_refs(&dom);
|
||||
|
||||
//check scribb
|
||||
let mut any_failed=false;
|
||||
for script in scripts.iter() {
|
||||
for &script_ref in script_refs.iter() {
|
||||
if let Some(script)=dom.get_by_ref(script_ref){
|
||||
if let Some(rbx_dom_weak::types::Variant::String(source)) = script.properties.get("Source") {
|
||||
if let (Some(replace_id),Some(replace_script))=(replace_map.get(source),write_dom.get_by_ref_mut(script.referent())) {
|
||||
if let (Some(replace_id),Some(replace_script))=(replace_map.get(source),dom.get_by_ref_mut(script.referent())) {
|
||||
println!("replace {}",replace_id);
|
||||
//replace the source
|
||||
if let Some(replace_source)=allowed_map.get(replace_id){
|
||||
@ -278,8 +287,10 @@ fn replace() -> Result<(), Box<dyn std::error::Error>>{
|
||||
any_failed=true;
|
||||
}
|
||||
}else{
|
||||
println!("failed to failed to get source");
|
||||
any_failed=true;
|
||||
panic!("FATAL: failed to get source for {:?}",file_thing.file_name());
|
||||
}
|
||||
}else{
|
||||
panic!("FATAL: failed to get_by_ref {:?}",script_ref);
|
||||
}
|
||||
}
|
||||
if any_failed {
|
||||
@ -288,7 +299,7 @@ fn replace() -> Result<(), Box<dyn std::error::Error>>{
|
||||
let mut dest=std::path::PathBuf::from("maps/unprocessed");
|
||||
dest.set_file_name(file_thing.file_name());
|
||||
let output = std::io::BufWriter::new(std::fs::File::open(dest)?);
|
||||
rbx_binary::to_writer(output, &write_dom, &[write_dom.root_ref()])?;
|
||||
rbx_binary::to_writer(output, &dom, &[dom.root_ref()])?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
@ -348,19 +359,17 @@ fn interactive() -> Result<(), Box<dyn std::error::Error>>{
|
||||
let file_thing=entry?;
|
||||
println!("processing map={:?}",file_thing.file_name());
|
||||
let input = std::io::BufReader::new(std::fs::File::open(file_thing.path())?);
|
||||
let dom = rbx_binary::from_reader(input)?;
|
||||
let mut dom = rbx_binary::from_reader(input)?;
|
||||
|
||||
let input = std::io::BufReader::new(std::fs::File::open(file_thing.path())?);
|
||||
let mut write_dom = rbx_binary::from_reader(input)?;
|
||||
|
||||
let scripts = get_scripts(dom);
|
||||
let script_refs = get_script_refs(&dom);
|
||||
|
||||
//check scribb
|
||||
let mut script_count=0;
|
||||
let mut replace_count=0;
|
||||
let mut block_count=0;
|
||||
let mut fail_type=Interactive::Passed;
|
||||
for script in scripts.iter() {
|
||||
for &script_ref in script_refs.iter() {
|
||||
if let Some(script)=dom.get_by_ref(script_ref){
|
||||
if let Some(rbx_dom_weak::types::Variant::String(source)) = script.properties.get("Source") {
|
||||
script_count+=1;
|
||||
let source_action=if check_source_illegal_keywords(source) {
|
||||
@ -376,7 +385,7 @@ fn interactive() -> Result<(), Box<dyn std::error::Error>>{
|
||||
//load source into current.lua
|
||||
std::fs::write("current.lua",source)?;
|
||||
//prompt action in terminal
|
||||
println!("unresolved source location={}",get_full_name(&write_dom, script));
|
||||
println!("unresolved source location={}",get_full_name(&dom, script));
|
||||
//wait for input
|
||||
let script_action;
|
||||
loop{
|
||||
@ -430,11 +439,11 @@ fn interactive() -> Result<(), Box<dyn std::error::Error>>{
|
||||
};
|
||||
|
||||
match source_action{
|
||||
ScriptAction::Pass => println!("passed source location={}",get_full_name(&write_dom, script)),
|
||||
ScriptAction::Pass => println!("passed source location={}",get_full_name(&dom, script)),
|
||||
ScriptAction::Replace(replace_id)=>{
|
||||
//replace the source
|
||||
let location=get_full_name(&write_dom, script);
|
||||
if let (Some(replace_source),Some(replace_script))=(allowed_map.get(&replace_id),write_dom.get_by_ref_mut(script.referent())){
|
||||
let location=get_full_name(&dom, script);
|
||||
if let (Some(replace_source),Some(replace_script))=(allowed_map.get(&replace_id),dom.get_by_ref_mut(script.referent())){
|
||||
replace_count+=1;
|
||||
println!("replaced source id={} location={}",replace_id,location);
|
||||
replace_script.properties.insert("Source".to_string(), rbx_dom_weak::types::Variant::String(replace_source.clone()));
|
||||
@ -443,12 +452,12 @@ fn interactive() -> Result<(), Box<dyn std::error::Error>>{
|
||||
}
|
||||
}
|
||||
ScriptAction::Flag => {
|
||||
println!("flagged source location={}",get_full_name(&write_dom, script));
|
||||
println!("flagged source location={}",get_full_name(&dom, script));
|
||||
fail_type=Interactive::Flagged;
|
||||
},
|
||||
ScriptAction::Block => {
|
||||
block_count+=1;
|
||||
println!("blocked source location={}",get_full_name(&write_dom, script));
|
||||
println!("blocked source location={}",get_full_name(&dom, script));
|
||||
match fail_type{
|
||||
Interactive::Passed => fail_type=Interactive::Blocked,
|
||||
_=>(),
|
||||
@ -456,7 +465,10 @@ fn interactive() -> Result<(), Box<dyn std::error::Error>>{
|
||||
},
|
||||
}
|
||||
}else{
|
||||
panic!("script source property is none!");
|
||||
panic!("FATAL: failed to get source for {:?}",file_thing.file_name());
|
||||
}
|
||||
}else{
|
||||
panic!("FATAL: failed to get_by_ref {:?}",script_ref);
|
||||
}
|
||||
}
|
||||
let mut dest=match fail_type{
|
||||
|
Loading…
Reference in New Issue
Block a user