forked from StrafesNET/asset-tool
quicksave
This commit is contained in:
parent
2efbc3b437
commit
581a0d6699
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1358,6 +1358,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy-regex",
|
"lazy-regex",
|
||||||
"rbx_dom_weak",
|
"rbx_dom_weak",
|
||||||
|
"rbx_xml",
|
||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -6,4 +6,5 @@ edition = "2021"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
lazy-regex = "3.1.0"
|
lazy-regex = "3.1.0"
|
||||||
rbx_dom_weak = "2.7.0"
|
rbx_dom_weak = "2.7.0"
|
||||||
|
rbx_xml = "0.13.3"
|
||||||
tokio = { version = "1.35.1", features = ["fs"] }
|
tokio = { version = "1.35.1", features = ["fs"] }
|
||||||
|
3
rox_compiler/src/common.rs
Normal file
3
rox_compiler/src/common.rs
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
pub(crate) fn sanitize<'a>(s:&'a str)->std::borrow::Cow<'a,str>{
|
||||||
|
lazy_regex::regex!(r"[^A-z0-9.-]").replace_all(s,"_")
|
||||||
|
}
|
@ -1,4 +1,8 @@
|
|||||||
use rbx_dom_weak::types::Ref;
|
use std::path::PathBuf;
|
||||||
|
use tokio::io::AsyncReadExt;
|
||||||
|
|
||||||
|
use crate::types::{DecompileStyle,PropertiesOverride};
|
||||||
|
use crate::common::sanitize;
|
||||||
|
|
||||||
//holy smokes what am I doing lmao
|
//holy smokes what am I doing lmao
|
||||||
//This giant machine is supposed to search for files according to style rules
|
//This giant machine is supposed to search for files according to style rules
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use std::path::PathBuf;
|
use std::{io::Read, path::PathBuf};
|
||||||
|
|
||||||
use rbx_dom_weak::types::Ref;
|
use rbx_dom_weak::types::Ref;
|
||||||
|
use crate::{common::sanitize, types::{DecompileStyle, PropertiesOverride}};
|
||||||
|
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq)]
|
||||||
enum Class{
|
enum Class{
|
||||||
@ -43,33 +43,6 @@ enum WriteStackInstruction<'a>{
|
|||||||
Destroy(Ref),
|
Destroy(Ref),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
struct PropertiesOverride{
|
|
||||||
name:Option<String>,
|
|
||||||
class:Option<String>,
|
|
||||||
}
|
|
||||||
impl PropertiesOverride{
|
|
||||||
fn is_some(&self)->bool{
|
|
||||||
self.name.is_some()
|
|
||||||
||self.class.is_some()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl std::fmt::Display for PropertiesOverride{
|
|
||||||
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
|
||||||
if let Some(name)=self.name.as_deref(){
|
|
||||||
writeln!(f,"--!Properties.Name = \"{}\"",name)?;
|
|
||||||
}
|
|
||||||
if let Some(class)=self.class.as_deref(){
|
|
||||||
writeln!(f,"--!Properties.ClassName = \"{}\"",class)?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn sanitize<'a>(s:&'a str)->std::borrow::Cow<'a,str>{
|
|
||||||
lazy_regex::regex!(r"[^A-z0-9.-]").replace_all(s,"_")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn write_item(dom:&rbx_dom_weak::WeakDom,mut file:PathBuf,node:&TreeNode,node_name_override:String,mut properties:PropertiesOverride,style:DecompileStyle,write_models:bool,write_scripts:bool)->AResult<()>{
|
fn write_item(dom:&rbx_dom_weak::WeakDom,mut file:PathBuf,node:&TreeNode,node_name_override:String,mut properties:PropertiesOverride,style:DecompileStyle,write_models:bool,write_scripts:bool)->AResult<()>{
|
||||||
file.push(sanitize(node_name_override.as_str()).as_ref());
|
file.push(sanitize(node_name_override.as_str()).as_ref());
|
||||||
match node.class{
|
match node.class{
|
||||||
@ -132,9 +105,7 @@ struct DecompiledContext{
|
|||||||
tree_refs:std::collections::HashMap<rbx_dom_weak::types::Ref,TreeNode>,
|
tree_refs:std::collections::HashMap<rbx_dom_weak::types::Ref,TreeNode>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_decompiled_context<R:Read>(input:R)->AResult<DecompiledContext>{
|
fn generate_decompiled_context(dom:rbx_dom_weak::WeakDom)->Result<DecompiledContext,DecompileError>{
|
||||||
let dom=load_dom(input)?;
|
|
||||||
|
|
||||||
let mut tree_refs=std::collections::HashMap::new();
|
let mut tree_refs=std::collections::HashMap::new();
|
||||||
tree_refs.insert(dom.root_ref(),TreeNode::new(
|
tree_refs.insert(dom.root_ref(),TreeNode::new(
|
||||||
"src".to_owned(),
|
"src".to_owned(),
|
||||||
@ -237,7 +208,7 @@ struct WriteConfig{
|
|||||||
write_scripts:bool,
|
write_scripts:bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn write_files(config:WriteConfig,mut context:DecompiledContext)->AResult<()>{
|
async fn write_files(config:WriteConfig,mut context:DecompiledContext)->Result<(),WriteError>{
|
||||||
let mut write_queue=Vec::new();
|
let mut write_queue=Vec::new();
|
||||||
let mut destroy_queue=Vec::new();
|
let mut destroy_queue=Vec::new();
|
||||||
|
|
||||||
|
@ -1,2 +1,4 @@
|
|||||||
|
mod common;
|
||||||
|
pub mod types;
|
||||||
pub mod compile;
|
pub mod compile;
|
||||||
pub mod decompile;
|
pub mod decompile;
|
||||||
|
29
rox_compiler/src/types.rs
Normal file
29
rox_compiler/src/types.rs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#[derive(Clone,Copy,Debug)]
|
||||||
|
pub enum DecompileStyle{
|
||||||
|
Rox,
|
||||||
|
Rojo,
|
||||||
|
RoxRojo,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub(crate) struct PropertiesOverride{
|
||||||
|
pub name:Option<String>,
|
||||||
|
pub class:Option<String>,
|
||||||
|
}
|
||||||
|
impl PropertiesOverride{
|
||||||
|
pub fn is_some(&self)->bool{
|
||||||
|
self.name.is_some()
|
||||||
|
||self.class.is_some()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl std::fmt::Display for PropertiesOverride{
|
||||||
|
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||||
|
if let Some(name)=self.name.as_deref(){
|
||||||
|
writeln!(f,"--!Properties.Name = \"{}\"",name)?;
|
||||||
|
}
|
||||||
|
if let Some(class)=self.class.as_deref(){
|
||||||
|
writeln!(f,"--!Properties.ClassName = \"{}\"",class)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
11
src/main.rs
11
src/main.rs
@ -180,11 +180,20 @@ enum CookieType{
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone,Copy,Debug,clap::ValueEnum)]
|
#[derive(Clone,Copy,Debug,clap::ValueEnum)]
|
||||||
enum DecompileStyle{
|
pub enum DecompileStyle{
|
||||||
Rox,
|
Rox,
|
||||||
Rojo,
|
Rojo,
|
||||||
RoxRojo,
|
RoxRojo,
|
||||||
}
|
}
|
||||||
|
impl DecompileStyle{
|
||||||
|
fn rox(&self)->rox_compiler::types::DecompileStyle{
|
||||||
|
match self{
|
||||||
|
DecompileStyle::Rox=>rox_compiler::types::DecompileStyle::Rox,
|
||||||
|
DecompileStyle::Rojo=>rox_compiler::types::DecompileStyle::Rojo,
|
||||||
|
DecompileStyle::RoxRojo=>rox_compiler::types::DecompileStyle::RoxRojo,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main()->AResult<()>{
|
async fn main()->AResult<()>{
|
||||||
|
Loading…
Reference in New Issue
Block a user