From d5f3467ddd880f775807adb7e4f24f1d5bf61af3 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Mon, 1 Jul 2024 20:41:52 -0700 Subject: [PATCH] download-decompile --- src/main.rs | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/main.rs b/src/main.rs index 44a77b2..9cb4159 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,6 +21,7 @@ struct Cli{ enum Commands{ DownloadHistory(DownloadHistorySubcommand), Download(DownloadSubcommand), + DownloadDecompile(DownloadDecompileSubcommand), DownloadGroupInventoryJson(DownloadGroupInventoryJsonSubcommand), Create(CreateSubcommand), Upload(UploadSubcommand), @@ -148,6 +149,25 @@ struct DecompileSubcommand{ write_scripts:Option, } #[derive(Args)] +struct DownloadDecompileSubcommand{ + #[arg(long)] + cookie_type:CookieType, + #[arg(long)] + cookie:String, + #[arg(long)] + output_folder:Option, + #[arg(long)] + asset_id:AssetID, + #[arg(long)] + style:Style, + #[arg(long)] + write_template:Option, + #[arg(long)] + write_models:Option, + #[arg(long)] + write_scripts:Option, +} +#[derive(Args)] struct DecompileHistoryIntoGitSubcommand{ #[arg(long)] input_folder:PathBuf, @@ -236,6 +256,17 @@ async fn main()->AResult<()>{ }).collect() ).await }, + Commands::DownloadDecompile(subcommand)=>{ + download_decompile(DownloadDecompileConfig{ + cookie:Cookie::from_type(subcommand.cookie_type,subcommand.cookie).await?.0, + asset_id:subcommand.asset_id, + output_folder:subcommand.output_folder.unwrap_or_else(||std::env::current_dir().unwrap()), + style:subcommand.style, + write_template:subcommand.write_template.unwrap_or(false), + write_models:subcommand.write_models.unwrap_or(false), + write_scripts:subcommand.write_scripts.unwrap_or(true), + }).await + }, Commands::DownloadGroupInventoryJson(subcommand)=>download_group_inventory_json( Cookie::from_type(subcommand.cookie_type,subcommand.cookie).await?.0, subcommand.group, @@ -606,6 +637,34 @@ async fn decompile(config:DecompileConfig)->AResult<()>{ Ok(()) } +struct DownloadDecompileConfig{ + cookie:String, + asset_id:AssetID, + style:Style, + output_folder:PathBuf, + write_template:bool, + write_models:bool, + write_scripts:bool, +} + +async fn download_decompile(config:DownloadDecompileConfig)->AResult<()>{ + let context=RobloxContext::new(config.cookie); + let file=context.download(rbx_asset::context::DownloadRequest{asset_id:config.asset_id,version:None}).await?; + + let dom=load_dom(std::io::Cursor::new(file))?; + let context=rox_compiler::DecompiledContext::from_dom(dom); + + context.write_files(rox_compiler::WriteConfig{ + style:config.style.rox(), + output_folder:config.output_folder, + write_template:config.write_template, + write_models:config.write_models, + write_scripts:config.write_scripts, + }).await?; + + Ok(()) +} + struct WriteCommitConfig{ git_committer_name:String, git_committer_email:String,