|
|
|
|
@@ -1,13 +1,12 @@
|
|
|
|
|
use std::{io::Read,path::PathBuf};
|
|
|
|
|
use std::io::Read;
|
|
|
|
|
use clap::{Args,Parser,Subcommand};
|
|
|
|
|
use anyhow::Result as AResult;
|
|
|
|
|
use futures::StreamExt;
|
|
|
|
|
use rbx_dom_weak::types::Ref;
|
|
|
|
|
use tokio::io::AsyncReadExt;
|
|
|
|
|
use rbx_asset::context::{RobloxContext,InventoryItem,AssetVersion};
|
|
|
|
|
|
|
|
|
|
type AssetID=u64;
|
|
|
|
|
type AssetIDFileMap=Vec<(AssetID,PathBuf)>;
|
|
|
|
|
type AssetIDFileMap=Vec<(AssetID,std::path::PathBuf)>;
|
|
|
|
|
const CONCURRENT_DECODE:usize=8;
|
|
|
|
|
const CONCURRENT_REQUESTS:usize=32;
|
|
|
|
|
|
|
|
|
|
@@ -15,313 +14,260 @@ const CONCURRENT_REQUESTS:usize=32;
|
|
|
|
|
#[command(author,version,about,long_about=None)]
|
|
|
|
|
#[command(propagate_version = true)]
|
|
|
|
|
struct Cli{
|
|
|
|
|
//asset options
|
|
|
|
|
#[arg(short,long)]
|
|
|
|
|
group:Option<u64>,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
asset_id:Option<AssetID>,
|
|
|
|
|
//idk how to do this better
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
cookie_literal:Option<String>,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
cookie_env:Option<String>,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
cookie_file:Option<std::path::PathBuf>,
|
|
|
|
|
//TODO: read the versions.json file instead of doing this
|
|
|
|
|
//TODO: write file dates instead of versions.json
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
start_version:Option<u64>,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
end_version:Option<u64>,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
r#continue:bool,
|
|
|
|
|
|
|
|
|
|
//decompile options
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
no_models:Option<bool>,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
no_scripts:Option<bool>,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
no_template:Option<bool>,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
style:Option<String>,
|
|
|
|
|
|
|
|
|
|
//git options
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
git_committer_name:Option<String>,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
git_committer_email:Option<String>,
|
|
|
|
|
|
|
|
|
|
#[arg(short,long)]
|
|
|
|
|
input:Option<std::path::PathBuf>,
|
|
|
|
|
|
|
|
|
|
#[arg(short,long)]
|
|
|
|
|
output:Option<std::path::PathBuf>,
|
|
|
|
|
|
|
|
|
|
#[command(subcommand)]
|
|
|
|
|
command:Commands,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Subcommand)]
|
|
|
|
|
enum Commands{
|
|
|
|
|
DownloadHistory(DownloadHistorySubcommand),
|
|
|
|
|
Download(DownloadSubcommand),
|
|
|
|
|
DownloadGroupInventoryJson(DownloadGroupInventoryJsonSubcommand),
|
|
|
|
|
Create(CreateSubcommand),
|
|
|
|
|
Upload(UploadSubcommand),
|
|
|
|
|
Compile(CompileSubcommand),
|
|
|
|
|
Decompile(DecompileSubcommand),
|
|
|
|
|
DecompileHistoryIntoGit(DecompileHistoryIntoGitSubcommand),
|
|
|
|
|
DownloadAndDecompileHistoryIntoGit(DownloadAndDecompileHistoryIntoGitSubcommand),
|
|
|
|
|
DownloadHistory,
|
|
|
|
|
Download(AssetIDList),
|
|
|
|
|
Upload,
|
|
|
|
|
Compile,
|
|
|
|
|
Decompile,
|
|
|
|
|
DecompileHistoryIntoGit,
|
|
|
|
|
DownloadAndDecompileHistoryIntoGit,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Args)]
|
|
|
|
|
struct DownloadHistorySubcommand{
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
asset_id:AssetID,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
cookie_type:CookieType,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
cookie:String,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
output_folder:Option<PathBuf>,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
continue_from_versions:Option<bool>,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
start_version:Option<u64>,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
end_version:Option<u64>,
|
|
|
|
|
}
|
|
|
|
|
#[derive(Args)]
|
|
|
|
|
struct DownloadSubcommand{
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
cookie_type:CookieType,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
cookie:String,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
output_folder:Option<PathBuf>,
|
|
|
|
|
#[arg(required=true)]
|
|
|
|
|
asset_ids:Vec<AssetID>,
|
|
|
|
|
}
|
|
|
|
|
#[derive(Args)]
|
|
|
|
|
struct DownloadGroupInventoryJsonSubcommand{
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
cookie_type:CookieType,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
cookie:String,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
output_folder:Option<PathBuf>,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
group:u64,
|
|
|
|
|
}
|
|
|
|
|
#[derive(Args)]
|
|
|
|
|
struct CreateSubcommand{
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
cookie_type:CookieType,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
cookie:String,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
model_name:String,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
description:Option<String>,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
input_file:PathBuf,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
group:Option<u64>,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
free_model:Option<bool>,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
allow_comments:Option<bool>,
|
|
|
|
|
}
|
|
|
|
|
#[derive(Args)]
|
|
|
|
|
struct UploadSubcommand{
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
asset_id:AssetID,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
cookie_type:CookieType,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
cookie:String,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
input_file:PathBuf,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
group:Option<u64>,
|
|
|
|
|
}
|
|
|
|
|
#[derive(Args)]
|
|
|
|
|
struct CompileSubcommand{
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
input_folder:Option<PathBuf>,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
output_file:PathBuf,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
style:Option<DecompileStyle>,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
template:Option<PathBuf>,
|
|
|
|
|
}
|
|
|
|
|
#[derive(Args)]
|
|
|
|
|
struct DecompileSubcommand{
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
input_file:PathBuf,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
output_folder:Option<PathBuf>,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
style:DecompileStyle,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
write_template:Option<bool>,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
write_models:Option<bool>,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
write_scripts:Option<bool>,
|
|
|
|
|
}
|
|
|
|
|
#[derive(Args)]
|
|
|
|
|
struct DecompileHistoryIntoGitSubcommand{
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
input_folder:PathBuf,
|
|
|
|
|
//currently output folder must be the current folder due to git2 limitations
|
|
|
|
|
//output_folder:cli.output.unwrap(),
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
style:DecompileStyle,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
git_committer_name:String,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
git_committer_email:String,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
write_template:Option<bool>,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
write_models:Option<bool>,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
write_scripts:Option<bool>,
|
|
|
|
|
}
|
|
|
|
|
#[derive(Args)]
|
|
|
|
|
struct DownloadAndDecompileHistoryIntoGitSubcommand{
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
asset_id:AssetID,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
cookie_type:CookieType,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
cookie:String,
|
|
|
|
|
//currently output folder must be the current folder due to git2 limitations
|
|
|
|
|
//output_folder:cli.output.unwrap(),
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
style:DecompileStyle,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
git_committer_name:String,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
git_committer_email:String,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
write_template:Option<bool>,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
write_models:Option<bool>,
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
write_scripts:Option<bool>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Clone,clap::ValueEnum)]
|
|
|
|
|
enum CookieType{
|
|
|
|
|
Literal,
|
|
|
|
|
Environment,
|
|
|
|
|
File,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Clone,Copy,Debug,clap::ValueEnum)]
|
|
|
|
|
#[derive(Clone,Copy,Debug)]
|
|
|
|
|
enum DecompileStyle{
|
|
|
|
|
Rox,
|
|
|
|
|
Rojo,
|
|
|
|
|
RoxRojo,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Args)]
|
|
|
|
|
struct AssetIDList{
|
|
|
|
|
asset_ids:Vec<AssetID>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Args)]
|
|
|
|
|
struct PathBufList{
|
|
|
|
|
paths:Vec<std::path::PathBuf>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(serde::Deserialize)]
|
|
|
|
|
#[allow(nonstandard_style,dead_code)]
|
|
|
|
|
struct VersionPage{
|
|
|
|
|
previousPageCursor:Option<String>,
|
|
|
|
|
nextPageCursor:Option<String>,
|
|
|
|
|
data:Vec<AssetVersion>,
|
|
|
|
|
}
|
|
|
|
|
#[derive(serde::Deserialize,serde::Serialize)]
|
|
|
|
|
#[allow(nonstandard_style,dead_code)]
|
|
|
|
|
struct AssetVersion{
|
|
|
|
|
Id:u64,
|
|
|
|
|
assetId:AssetID,
|
|
|
|
|
assetVersionNumber:u64,
|
|
|
|
|
creatorType:String,
|
|
|
|
|
creatorTargetId:u64,
|
|
|
|
|
creatingUniverseId:Option<u64>,
|
|
|
|
|
created:chrono::DateTime<chrono::Utc>,
|
|
|
|
|
isPublished:bool,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
|
async fn main()->AResult<()>{
|
|
|
|
|
let cli=Cli::parse();
|
|
|
|
|
|
|
|
|
|
let cookie_enum={
|
|
|
|
|
match (cli.cookie_literal,cli.cookie_env,cli.cookie_file){
|
|
|
|
|
(Some(literal),None,None)=>Some(Cookie::Literal(literal)),
|
|
|
|
|
(None,Some(env_var),None)=>Some(Cookie::Environment(env_var)),
|
|
|
|
|
(None,None,Some(path))=>Some(Cookie::File(path)),
|
|
|
|
|
(None,None,None)=>None,
|
|
|
|
|
_=>Err(anyhow::Error::msg("Cookie was specified multiple times."))?,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
let cookie=match cookie_enum{
|
|
|
|
|
Some(c)=>Some(format!(".ROBLOSECURITY={}",match c{
|
|
|
|
|
Cookie::Literal(s)=>s,
|
|
|
|
|
Cookie::Environment(var)=>std::env::var(var)?,
|
|
|
|
|
Cookie::File(path)=>tokio::fs::read_to_string(path).await?,
|
|
|
|
|
})),
|
|
|
|
|
None=>None,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let decompile_style=match cli.style.as_deref(){
|
|
|
|
|
Some("rox")
|
|
|
|
|
|Some("Rox")=>Some(DecompileStyle::Rox),
|
|
|
|
|
Some("rojo")
|
|
|
|
|
|Some("Rojo")=>Some(DecompileStyle::Rojo),
|
|
|
|
|
Some("rox-rojo")
|
|
|
|
|
|Some("rojo-rox")
|
|
|
|
|
|Some("roxrojo")
|
|
|
|
|
|Some("rojorox")
|
|
|
|
|
|Some("RoxRojo")
|
|
|
|
|
|Some("RojoRox")=>Some(DecompileStyle::RoxRojo),
|
|
|
|
|
None=>None,
|
|
|
|
|
_=>Err(anyhow::Error::msg("Invalid style"))?,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
match cli.command{
|
|
|
|
|
Commands::DownloadHistory(subcommand)=>download_history(DownloadHistoryConfig{
|
|
|
|
|
continue_from_versions:subcommand.continue_from_versions.unwrap_or(false),
|
|
|
|
|
end_version:subcommand.end_version,
|
|
|
|
|
start_version:subcommand.start_version.unwrap_or(0),
|
|
|
|
|
output_folder:subcommand.output_folder.unwrap_or_else(||std::env::current_dir().unwrap()),
|
|
|
|
|
cookie:Cookie::from_type(subcommand.cookie_type,subcommand.cookie).await?.0,
|
|
|
|
|
asset_id:subcommand.asset_id,
|
|
|
|
|
Commands::DownloadHistory=>download_history(DownloadHistoryConfig{
|
|
|
|
|
continue_from_versions:cli.r#continue,
|
|
|
|
|
end_version:cli.end_version,
|
|
|
|
|
start_version:cli.start_version.unwrap_or(0),
|
|
|
|
|
output_folder:cli.output.unwrap(),
|
|
|
|
|
cookie:cookie.unwrap(),
|
|
|
|
|
asset_id:cli.asset_id.unwrap(),
|
|
|
|
|
}).await,
|
|
|
|
|
Commands::Download(subcommand)=>{
|
|
|
|
|
let output_folder=subcommand.output_folder.unwrap_or_else(||std::env::current_dir().unwrap());
|
|
|
|
|
download_list(
|
|
|
|
|
Cookie::from_type(subcommand.cookie_type,subcommand.cookie).await?.0,
|
|
|
|
|
subcommand.asset_ids.into_iter().map(|asset_id|{
|
|
|
|
|
let mut path=output_folder.clone();
|
|
|
|
|
path.push(asset_id.to_string());
|
|
|
|
|
(asset_id,path)
|
|
|
|
|
}).collect()
|
|
|
|
|
).await
|
|
|
|
|
},
|
|
|
|
|
Commands::DownloadGroupInventoryJson(subcommand)=>download_group_inventory_json(
|
|
|
|
|
Cookie::from_type(subcommand.cookie_type,subcommand.cookie).await?.0,
|
|
|
|
|
subcommand.group,
|
|
|
|
|
subcommand.output_folder.unwrap_or_else(||std::env::current_dir().unwrap()),
|
|
|
|
|
Commands::Download(asset_id_list)=>download_list(
|
|
|
|
|
cookie.unwrap(),
|
|
|
|
|
asset_id_list.asset_ids.into_iter().map(|asset_id|{
|
|
|
|
|
let mut path=cli.output.clone().unwrap();
|
|
|
|
|
path.push(asset_id.to_string());
|
|
|
|
|
(asset_id,path)
|
|
|
|
|
}).collect()
|
|
|
|
|
).await,
|
|
|
|
|
Commands::Create(subcommand)=>create(CreateConfig{
|
|
|
|
|
cookie:Cookie::from_type(subcommand.cookie_type,subcommand.cookie).await?.0,
|
|
|
|
|
group:subcommand.group,
|
|
|
|
|
input_file:subcommand.input_file,
|
|
|
|
|
model_name:subcommand.model_name,
|
|
|
|
|
description:subcommand.description.unwrap_or_else(||String::with_capacity(0)),
|
|
|
|
|
free_model:subcommand.free_model.unwrap_or(false),
|
|
|
|
|
allow_comments:subcommand.allow_comments.unwrap_or(false),
|
|
|
|
|
Commands::Upload=>upload_list(cookie.unwrap(),cli.group,vec![(cli.asset_id.unwrap(),cli.output.unwrap())]).await,
|
|
|
|
|
Commands::Compile=>compile(CompileConfig{
|
|
|
|
|
input_folder:cli.input.unwrap(),
|
|
|
|
|
output_file:cli.output.unwrap(),
|
|
|
|
|
template:None,
|
|
|
|
|
style:None,
|
|
|
|
|
}).await,
|
|
|
|
|
Commands::Upload(subcommand)=>upload_list(
|
|
|
|
|
Cookie::from_type(subcommand.cookie_type,subcommand.cookie).await?.0,
|
|
|
|
|
subcommand.group,
|
|
|
|
|
vec![(subcommand.asset_id,subcommand.input_file)]
|
|
|
|
|
).await,
|
|
|
|
|
Commands::Compile(subcommand)=>compile(CompileConfig{
|
|
|
|
|
input_folder:subcommand.input_folder.unwrap_or_else(||std::env::current_dir().unwrap()),
|
|
|
|
|
output_file:subcommand.output_file,
|
|
|
|
|
template:subcommand.template,
|
|
|
|
|
style:subcommand.style,
|
|
|
|
|
Commands::Decompile=>decompile(DecompileConfig{
|
|
|
|
|
style:decompile_style.unwrap(),
|
|
|
|
|
input_file:cli.input.unwrap(),
|
|
|
|
|
output_folder:cli.output.unwrap(),
|
|
|
|
|
write_template:!cli.no_template.unwrap_or(false),
|
|
|
|
|
write_models:!cli.no_models.unwrap_or(false),
|
|
|
|
|
write_scripts:!cli.no_scripts.unwrap_or(false),
|
|
|
|
|
}).await,
|
|
|
|
|
Commands::Decompile(subcommand)=>decompile(DecompileConfig{
|
|
|
|
|
style:subcommand.style,
|
|
|
|
|
input_file:subcommand.input_file,
|
|
|
|
|
output_folder:subcommand.output_folder.unwrap_or_else(||std::env::current_dir().unwrap()),
|
|
|
|
|
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::DecompileHistoryIntoGit(subcommand)=>decompile_history_into_git(DecompileHistoryConfig{
|
|
|
|
|
git_committer_name:subcommand.git_committer_name,
|
|
|
|
|
git_committer_email:subcommand.git_committer_email,
|
|
|
|
|
input_folder:subcommand.input_folder,
|
|
|
|
|
output_folder:std::env::current_dir()?,
|
|
|
|
|
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),
|
|
|
|
|
Commands::DecompileHistoryIntoGit=>decompile_history_into_git(DecompileHistoryConfig{
|
|
|
|
|
git_committer_name:cli.git_committer_name.unwrap(),
|
|
|
|
|
git_committer_email:cli.git_committer_email.unwrap(),
|
|
|
|
|
input_folder:cli.input.unwrap(),
|
|
|
|
|
output_folder:cli.output.unwrap(),
|
|
|
|
|
style:decompile_style.unwrap(),
|
|
|
|
|
write_template:!cli.no_template.unwrap_or(false),
|
|
|
|
|
write_models:!cli.no_models.unwrap_or(false),
|
|
|
|
|
write_scripts:!cli.no_scripts.unwrap_or(false),
|
|
|
|
|
}).await,
|
|
|
|
|
Commands::DownloadAndDecompileHistoryIntoGit(subcommand)=>download_and_decompile_history_into_git(DownloadAndDecompileHistoryConfig{
|
|
|
|
|
git_committer_name:subcommand.git_committer_name,
|
|
|
|
|
git_committer_email:subcommand.git_committer_email,
|
|
|
|
|
cookie:Cookie::from_type(subcommand.cookie_type,subcommand.cookie).await?.0,
|
|
|
|
|
asset_id:subcommand.asset_id,
|
|
|
|
|
output_folder:std::env::current_dir()?,
|
|
|
|
|
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),
|
|
|
|
|
Commands::DownloadAndDecompileHistoryIntoGit=>download_and_decompile_history_into_git(DownloadAndDecompileHistoryConfig{
|
|
|
|
|
git_committer_name:cli.git_committer_name.unwrap(),
|
|
|
|
|
git_committer_email:cli.git_committer_email.unwrap(),
|
|
|
|
|
cookie:cookie.unwrap(),
|
|
|
|
|
asset_id:cli.asset_id.unwrap(),
|
|
|
|
|
output_folder:cli.output.unwrap(),
|
|
|
|
|
style:decompile_style.unwrap(),
|
|
|
|
|
write_template:!cli.no_template.unwrap_or(false),
|
|
|
|
|
write_models:!cli.no_models.unwrap_or(false),
|
|
|
|
|
write_scripts:!cli.no_scripts.unwrap_or(false),
|
|
|
|
|
}).await,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct Cookie(String);
|
|
|
|
|
impl Cookie{
|
|
|
|
|
async fn from_type(cookie_type:CookieType,cookie_string:String)->AResult<Self>{
|
|
|
|
|
Ok(Self(format!(".ROBLOSECURITY={}",match cookie_type{
|
|
|
|
|
CookieType::Literal=>cookie_string,
|
|
|
|
|
CookieType::Environment=>std::env::var(cookie_string)?,
|
|
|
|
|
CookieType::File=>tokio::fs::read_to_string(cookie_string).await?,
|
|
|
|
|
})))
|
|
|
|
|
enum Cookie{
|
|
|
|
|
Literal(String),
|
|
|
|
|
Environment(String),
|
|
|
|
|
File(std::path::PathBuf),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum ReaderType<R:Read>{
|
|
|
|
|
GZip(flate2::read::GzDecoder<std::io::BufReader<R>>),
|
|
|
|
|
Raw(std::io::BufReader<R>),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn maybe_gzip_decode<R:Read>(input:R)->AResult<ReaderType<R>>{
|
|
|
|
|
let mut buf=std::io::BufReader::new(input);
|
|
|
|
|
let peek=std::io::BufRead::fill_buf(&mut buf)?;
|
|
|
|
|
match &peek[0..2]{
|
|
|
|
|
b"\x1f\x8b"=>Ok(ReaderType::GZip(flate2::read::GzDecoder::new(buf))),
|
|
|
|
|
_=>Ok(ReaderType::Raw(buf)),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct CreateConfig{
|
|
|
|
|
cookie:String,
|
|
|
|
|
model_name:String,
|
|
|
|
|
description:String,
|
|
|
|
|
input_file:PathBuf,
|
|
|
|
|
group:Option<u64>,
|
|
|
|
|
free_model:bool,
|
|
|
|
|
allow_comments:bool,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn create(config:CreateConfig)->AResult<()>{
|
|
|
|
|
let resp=RobloxContext::new(config.cookie)
|
|
|
|
|
.create(rbx_asset::context::CreateRequest{
|
|
|
|
|
name:config.model_name,
|
|
|
|
|
description:config.description,
|
|
|
|
|
ispublic:config.free_model,
|
|
|
|
|
allowComments:config.allow_comments,
|
|
|
|
|
groupId:config.group,
|
|
|
|
|
},tokio::fs::read(config.input_file).await?).await?;
|
|
|
|
|
println!("UploadResponse={:?}",resp);
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn upload_list(cookie:String,group:Option<u64>,asset_id_file_map:AssetIDFileMap)->AResult<()>{
|
|
|
|
|
let context=RobloxContext::new(cookie);
|
|
|
|
|
//this is calling map on the vec because the closure produces an iterator of futures
|
|
|
|
|
let client=reqwest::Client::new();
|
|
|
|
|
futures::stream::iter(asset_id_file_map.into_iter()
|
|
|
|
|
.map(|(asset_id,file)|{
|
|
|
|
|
let context=&context;
|
|
|
|
|
let client=&client;
|
|
|
|
|
let cookie=cookie.as_str();
|
|
|
|
|
let group=&group;
|
|
|
|
|
async move{
|
|
|
|
|
Ok((asset_id,context.upload(rbx_asset::context::UploadRequest{
|
|
|
|
|
assetid:asset_id,
|
|
|
|
|
name:None,
|
|
|
|
|
description:None,
|
|
|
|
|
ispublic:None,
|
|
|
|
|
allowComments:None,
|
|
|
|
|
groupId:group,
|
|
|
|
|
},tokio::fs::read(file).await?).await?))
|
|
|
|
|
let mut url=reqwest::Url::parse("https://data.roblox.com/Data/Upload.ashx?json=1&type=Model&genreTypeId=1")?;
|
|
|
|
|
//url borrow scope
|
|
|
|
|
{
|
|
|
|
|
let mut query=url.query_pairs_mut();//borrow here
|
|
|
|
|
query.append_pair("assetid",asset_id.to_string().as_str());
|
|
|
|
|
match group{
|
|
|
|
|
Some(group_id)=>{query.append_pair("groupId",group_id.to_string().as_str());},
|
|
|
|
|
None=>(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let body=tokio::fs::read_to_string(file).await?;
|
|
|
|
|
let mut resp=client.post(url.clone())
|
|
|
|
|
.header("Cookie",cookie)
|
|
|
|
|
.body(body.clone())
|
|
|
|
|
.send().await?;
|
|
|
|
|
|
|
|
|
|
//This is called a CSRF challenge apparently
|
|
|
|
|
if resp.status()==reqwest::StatusCode::FORBIDDEN{
|
|
|
|
|
if let Some(csrf_token)=resp.headers().get("X-CSRF-Token"){
|
|
|
|
|
resp=client.post(url)
|
|
|
|
|
.header("X-CSRF-Token",csrf_token)
|
|
|
|
|
.header("Cookie",cookie)
|
|
|
|
|
.body(body)
|
|
|
|
|
.send().await?;
|
|
|
|
|
}else{
|
|
|
|
|
Err(anyhow::Error::msg("Roblox returned 403 with no CSRF"))?;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok((asset_id,resp.bytes().await?))
|
|
|
|
|
}
|
|
|
|
|
}))
|
|
|
|
|
.buffer_unordered(CONCURRENT_REQUESTS)
|
|
|
|
|
.for_each(|b:AResult<_>|async{
|
|
|
|
|
match b{
|
|
|
|
|
Ok((asset_id,body))=>{
|
|
|
|
|
println!("asset_id={} UploadResponse={:?}",asset_id,body);
|
|
|
|
|
println!("asset_id={} response.body={:?}",asset_id,body);
|
|
|
|
|
},
|
|
|
|
|
Err(e)=>eprintln!("ul error: {}",e),
|
|
|
|
|
}
|
|
|
|
|
@@ -329,29 +275,41 @@ async fn upload_list(cookie:String,group:Option<u64>,asset_id_file_map:AssetIDFi
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn read_readable(mut readable:impl Read)->AResult<Vec<u8>>{
|
|
|
|
|
let mut contents=Vec::new();
|
|
|
|
|
readable.read_to_end(&mut contents)?;
|
|
|
|
|
Ok(contents)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn download_list(cookie:String,asset_id_file_map:AssetIDFileMap)->AResult<()>{
|
|
|
|
|
let context=RobloxContext::new(cookie);
|
|
|
|
|
let client=reqwest::Client::new();
|
|
|
|
|
futures::stream::iter(asset_id_file_map.into_iter()
|
|
|
|
|
.map(|(asset_id,file)|{
|
|
|
|
|
let context=&context;
|
|
|
|
|
let client=&client;
|
|
|
|
|
let cookie=cookie.as_str();
|
|
|
|
|
async move{
|
|
|
|
|
Ok((file,context.download(rbx_asset::context::DownloadRequest{asset_id,version:None}).await?))
|
|
|
|
|
let resp=client.get(format!("https://assetdelivery.roblox.com/v1/asset/?ID={}",asset_id))
|
|
|
|
|
.header("Cookie",cookie)
|
|
|
|
|
.send().await?;
|
|
|
|
|
Ok((file,resp.bytes().await?))
|
|
|
|
|
}
|
|
|
|
|
}))
|
|
|
|
|
.buffer_unordered(CONCURRENT_REQUESTS)
|
|
|
|
|
.for_each(|b:AResult<_>|async{
|
|
|
|
|
match b{
|
|
|
|
|
Ok((mut dest,data))=>{
|
|
|
|
|
//known file types
|
|
|
|
|
match &data[0..4]{
|
|
|
|
|
b"<rob"=>dest.set_extension("rbxm"),
|
|
|
|
|
b"\x89PNG"=>dest.set_extension("png"),
|
|
|
|
|
_=>false,
|
|
|
|
|
Ok((dest,body))=>{
|
|
|
|
|
let contents=match maybe_gzip_decode(&mut std::io::Cursor::new(body)){
|
|
|
|
|
Ok(ReaderType::GZip(readable))=>read_readable(readable),
|
|
|
|
|
Ok(ReaderType::Raw(readable))=>read_readable(readable),
|
|
|
|
|
Err(e)=>Err(e),
|
|
|
|
|
};
|
|
|
|
|
match contents{
|
|
|
|
|
Ok(data)=>match tokio::fs::write(dest,data).await{
|
|
|
|
|
Err(e)=>eprintln!("fs error: {}",e),
|
|
|
|
|
_=>(),
|
|
|
|
|
},
|
|
|
|
|
Err(e)=>eprintln!("gzip error: {}",e),
|
|
|
|
|
};
|
|
|
|
|
match tokio::fs::write(dest,data).await{
|
|
|
|
|
Err(e)=>eprintln!("fs error: {}",e),
|
|
|
|
|
_=>(),
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
Err(e)=>eprintln!("dl error: {}",e),
|
|
|
|
|
}
|
|
|
|
|
@@ -359,36 +317,31 @@ async fn download_list(cookie:String,asset_id_file_map:AssetIDFileMap)->AResult<
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn get_inventory_pages(context:&RobloxContext,group:u64)->AResult<Vec<InventoryItem>>{
|
|
|
|
|
let mut cursor:Option<String>=None;
|
|
|
|
|
let mut asset_list=Vec::new();
|
|
|
|
|
loop{
|
|
|
|
|
let mut page=context.inventory_page(rbx_asset::context::InventoryPageRequest{group,cursor}).await?;
|
|
|
|
|
asset_list.append(&mut page.data);
|
|
|
|
|
if page.nextPageCursor.is_none(){
|
|
|
|
|
break;
|
|
|
|
|
async fn download_page(client:&reqwest::Client,cookie:&str,asset_id:AssetID,cursor:Option<String>)->AResult<VersionPage>{
|
|
|
|
|
let mut url=reqwest::Url::parse(format!("https://develop.roblox.com/v1/assets/{}/saved-versions",asset_id).as_str())?;
|
|
|
|
|
//url borrow scope
|
|
|
|
|
{
|
|
|
|
|
let mut query=url.query_pairs_mut();//borrow here
|
|
|
|
|
//query.append_pair("sortOrder","Asc");
|
|
|
|
|
//query.append_pair("limit","100");
|
|
|
|
|
//query.append_pair("count","100");
|
|
|
|
|
match cursor.as_deref(){
|
|
|
|
|
Some(next_page)=>{query.append_pair("cursor",next_page);}
|
|
|
|
|
None=>(),
|
|
|
|
|
}
|
|
|
|
|
cursor=page.nextPageCursor;
|
|
|
|
|
}
|
|
|
|
|
Ok(asset_list)
|
|
|
|
|
println!("page url={}",url);
|
|
|
|
|
let resp=client.get(url)
|
|
|
|
|
.header("Cookie",cookie)
|
|
|
|
|
.send().await?;
|
|
|
|
|
Ok(resp.json::<VersionPage>().await?)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn download_group_inventory_json(cookie:String,group:u64,output_folder:PathBuf)->AResult<()>{
|
|
|
|
|
let context=RobloxContext::new(cookie);
|
|
|
|
|
let item_list=get_inventory_pages(&context,group).await?;
|
|
|
|
|
|
|
|
|
|
let mut path=output_folder.clone();
|
|
|
|
|
path.set_file_name("versions.json");
|
|
|
|
|
tokio::fs::write(path,serde_json::to_string(&item_list)?).await?;
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn get_version_history(context:&RobloxContext,asset_id:AssetID)->AResult<Vec<AssetVersion>>{
|
|
|
|
|
async fn get_version_history(client:&reqwest::Client,cookie:&str,asset_id:AssetID)->AResult<Vec<AssetVersion>>{
|
|
|
|
|
let mut cursor:Option<String>=None;
|
|
|
|
|
let mut asset_list=Vec::new();
|
|
|
|
|
loop{
|
|
|
|
|
let mut page=context.history_page(rbx_asset::context::HistoryPageRequest{asset_id,cursor}).await?;
|
|
|
|
|
let mut page=download_page(client,cookie,asset_id,cursor).await?;
|
|
|
|
|
asset_list.append(&mut page.data);
|
|
|
|
|
if page.nextPageCursor.is_none(){
|
|
|
|
|
break;
|
|
|
|
|
@@ -399,11 +352,35 @@ async fn get_version_history(context:&RobloxContext,asset_id:AssetID)->AResult<V
|
|
|
|
|
Ok(asset_list)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn download_asset_version(client:&reqwest::Client,cookie:&str,asset_id_str:&str,asset_version_str:&str)->AResult<reqwest::Response>{
|
|
|
|
|
let mut url=reqwest::Url::parse("https://assetdelivery.roblox.com/v1/asset/")?;
|
|
|
|
|
//url borrow scope
|
|
|
|
|
{
|
|
|
|
|
let mut query=url.query_pairs_mut();//borrow here
|
|
|
|
|
query.append_pair("ID",asset_id_str);
|
|
|
|
|
query.append_pair("version",asset_version_str);
|
|
|
|
|
}
|
|
|
|
|
println!("download url={}",url);
|
|
|
|
|
for i in 0..8{
|
|
|
|
|
let resp=client.get(url.clone())
|
|
|
|
|
.header("Cookie",cookie)
|
|
|
|
|
.send().await?;
|
|
|
|
|
|
|
|
|
|
if !resp.status().is_success(){
|
|
|
|
|
println!("request {} failed",i);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Ok(resp);
|
|
|
|
|
}
|
|
|
|
|
Err(anyhow::Error::msg("all requests failed"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct DownloadHistoryConfig{
|
|
|
|
|
continue_from_versions:bool,
|
|
|
|
|
end_version:Option<u64>,
|
|
|
|
|
start_version:u64,
|
|
|
|
|
output_folder:PathBuf,
|
|
|
|
|
output_folder:std::path::PathBuf,
|
|
|
|
|
cookie:String,
|
|
|
|
|
asset_id:AssetID,
|
|
|
|
|
}
|
|
|
|
|
@@ -445,7 +422,9 @@ async fn download_history(mut config:DownloadHistoryConfig)->AResult<()>{
|
|
|
|
|
None=>Err(anyhow::Error::msg("Cannot continue from versions.json - there are no previous versions"))?,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let context=RobloxContext::new(config.cookie);
|
|
|
|
|
let client=reqwest::Client::new();
|
|
|
|
|
|
|
|
|
|
let asset_id_string=config.asset_id.to_string();
|
|
|
|
|
|
|
|
|
|
//limit concurrent downloads
|
|
|
|
|
let mut join_set=tokio::task::JoinSet::new();
|
|
|
|
|
@@ -453,8 +432,10 @@ async fn download_history(mut config:DownloadHistoryConfig)->AResult<()>{
|
|
|
|
|
//poll paged list of all asset versions
|
|
|
|
|
let mut cursor:Option<String>=None;
|
|
|
|
|
loop{
|
|
|
|
|
let mut page=context.history_page(rbx_asset::context::HistoryPageRequest{asset_id:config.asset_id,cursor}).await?;
|
|
|
|
|
let context=&context;
|
|
|
|
|
let mut page=download_page(&client,config.cookie.as_str(),config.asset_id,cursor).await?;
|
|
|
|
|
let client=&client;
|
|
|
|
|
let cookie=config.cookie.clone();
|
|
|
|
|
let asset_id_str=asset_id_string.clone();
|
|
|
|
|
let output_folder=config.output_folder.clone();
|
|
|
|
|
let data=&page.data;
|
|
|
|
|
let asset_list_contents=&asset_list_contents;
|
|
|
|
|
@@ -479,13 +460,19 @@ async fn download_history(mut config:DownloadHistoryConfig)->AResult<()>{
|
|
|
|
|
while CONCURRENT_REQUESTS<=join_set.len(){
|
|
|
|
|
join_set.join_next().await.unwrap()??;
|
|
|
|
|
}
|
|
|
|
|
let context=context.clone();
|
|
|
|
|
let client=client.clone();
|
|
|
|
|
let cookie=cookie.clone();
|
|
|
|
|
let asset_id_str=asset_id_str.clone();
|
|
|
|
|
let mut path=output_folder.clone();
|
|
|
|
|
path.push(format!("{}_v{}.rbxl",config.asset_id,version_number));
|
|
|
|
|
join_set.spawn(async move{
|
|
|
|
|
let file=context.download(rbx_asset::context::DownloadRequest{asset_id:config.asset_id,version:Some(version_number)}).await?;
|
|
|
|
|
let resp=download_asset_version(&client,cookie.as_str(),asset_id_str.as_str(),version_number.to_string().as_str()).await?;
|
|
|
|
|
let contents=match maybe_gzip_decode(std::io::Cursor::new(resp.bytes().await?))?{
|
|
|
|
|
ReaderType::GZip(readable)=>read_readable(readable)?,
|
|
|
|
|
ReaderType::Raw(readable)=>read_readable(readable)?,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
tokio::fs::write(path,file).await?;
|
|
|
|
|
tokio::fs::write(path,contents).await?;
|
|
|
|
|
|
|
|
|
|
Ok::<_,anyhow::Error>(())
|
|
|
|
|
});
|
|
|
|
|
@@ -534,8 +521,8 @@ fn load_dom<R:Read>(input:R)->AResult<rbx_dom_weak::WeakDom>{
|
|
|
|
|
match &peek[0..4]{
|
|
|
|
|
b"<rob"=>{
|
|
|
|
|
match &peek[4..8]{
|
|
|
|
|
b"lox!"=>rbx_binary::from_reader(buf).map_err(anyhow::Error::msg),
|
|
|
|
|
b"lox "=>rbx_xml::from_reader_default(buf).map_err(anyhow::Error::msg),
|
|
|
|
|
b"lox!"=>return rbx_binary::from_reader(buf).map_err(anyhow::Error::msg),
|
|
|
|
|
b"lox "=>return rbx_xml::from_reader_default(buf).map_err(anyhow::Error::msg),
|
|
|
|
|
other=>Err(anyhow::Error::msg(format!("Unknown Roblox file type {:?}",other))),
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
@@ -611,7 +598,7 @@ 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:std::path::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());
|
|
|
|
|
match node.class{
|
|
|
|
|
Class::Folder=>(),
|
|
|
|
|
@@ -772,7 +759,7 @@ fn generate_decompiled_context<R:Read>(input:R)->AResult<DecompiledContext>{
|
|
|
|
|
|
|
|
|
|
struct WriteConfig{
|
|
|
|
|
style:DecompileStyle,
|
|
|
|
|
output_folder:PathBuf,
|
|
|
|
|
output_folder:std::path::PathBuf,
|
|
|
|
|
write_template:bool,
|
|
|
|
|
write_models:bool,
|
|
|
|
|
write_scripts:bool,
|
|
|
|
|
@@ -879,8 +866,8 @@ async fn write_files(config:WriteConfig,mut context:DecompiledContext)->AResult<
|
|
|
|
|
|
|
|
|
|
struct DecompileConfig{
|
|
|
|
|
style:DecompileStyle,
|
|
|
|
|
input_file:PathBuf,
|
|
|
|
|
output_folder:PathBuf,
|
|
|
|
|
input_file:std::path::PathBuf,
|
|
|
|
|
output_folder:std::path::PathBuf,
|
|
|
|
|
write_template:bool,
|
|
|
|
|
write_models:bool,
|
|
|
|
|
write_scripts:bool,
|
|
|
|
|
@@ -912,7 +899,7 @@ async fn decompile(config:DecompileConfig)->AResult<()>{
|
|
|
|
|
struct WriteCommitConfig{
|
|
|
|
|
git_committer_name:String,
|
|
|
|
|
git_committer_email:String,
|
|
|
|
|
output_folder:PathBuf,
|
|
|
|
|
output_folder:std::path::PathBuf,
|
|
|
|
|
style:DecompileStyle,
|
|
|
|
|
write_template:bool,
|
|
|
|
|
write_models:bool,
|
|
|
|
|
@@ -1003,9 +990,9 @@ async fn write_commit(config:WriteCommitConfig,b:Result<AResult<(AssetVersion,De
|
|
|
|
|
struct DecompileHistoryConfig{
|
|
|
|
|
git_committer_name:String,
|
|
|
|
|
git_committer_email:String,
|
|
|
|
|
input_folder:PathBuf,
|
|
|
|
|
input_folder:std::path::PathBuf,
|
|
|
|
|
style:DecompileStyle,
|
|
|
|
|
output_folder:PathBuf,
|
|
|
|
|
output_folder:std::path::PathBuf,
|
|
|
|
|
write_template:bool,
|
|
|
|
|
write_models:bool,
|
|
|
|
|
write_scripts:bool,
|
|
|
|
|
@@ -1054,28 +1041,34 @@ struct DownloadAndDecompileHistoryConfig{
|
|
|
|
|
git_committer_name:String,
|
|
|
|
|
git_committer_email:String,
|
|
|
|
|
style:DecompileStyle,
|
|
|
|
|
output_folder:PathBuf,
|
|
|
|
|
output_folder:std::path::PathBuf,
|
|
|
|
|
write_template:bool,
|
|
|
|
|
write_models:bool,
|
|
|
|
|
write_scripts:bool,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn download_and_decompile_history_into_git(config:DownloadAndDecompileHistoryConfig)->AResult<()>{
|
|
|
|
|
let context=RobloxContext::new(config.cookie);
|
|
|
|
|
let client=reqwest::Client::new();
|
|
|
|
|
|
|
|
|
|
//poll paged list of all asset versions
|
|
|
|
|
let asset_list=get_version_history(&context,config.asset_id).await?;
|
|
|
|
|
let asset_list=get_version_history(&client,&config.cookie.as_str(),config.asset_id).await?;
|
|
|
|
|
|
|
|
|
|
let repo=git2::Repository::init(config.output_folder.clone())?;
|
|
|
|
|
|
|
|
|
|
//download all versions
|
|
|
|
|
let asset_id=config.asset_id;
|
|
|
|
|
let asset_id_string=config.asset_id.to_string();
|
|
|
|
|
futures::stream::iter(asset_list.into_iter()
|
|
|
|
|
.map(|asset_version|{
|
|
|
|
|
let context=context.clone();
|
|
|
|
|
let client=client.clone();
|
|
|
|
|
let cookie=config.cookie.clone();
|
|
|
|
|
let asset_id_str=asset_id_string.clone();
|
|
|
|
|
tokio::task::spawn(async move{
|
|
|
|
|
let file=context.download(rbx_asset::context::DownloadRequest{asset_id,version:Some(asset_version.assetVersionNumber)}).await?;
|
|
|
|
|
Ok::<_,anyhow::Error>((asset_version,generate_decompiled_context(std::io::Cursor::new(file))?))
|
|
|
|
|
let resp=download_asset_version(&client,cookie.as_str(),asset_id_str.as_str(),asset_version.assetVersionNumber.to_string().as_str()).await?;
|
|
|
|
|
let contents=match maybe_gzip_decode(std::io::Cursor::new(resp.bytes().await?))?{
|
|
|
|
|
ReaderType::GZip(readable)=>generate_decompiled_context(readable)?,
|
|
|
|
|
ReaderType::Raw(readable)=>generate_decompiled_context(readable)?,
|
|
|
|
|
};
|
|
|
|
|
Ok::<_,anyhow::Error>((asset_version,contents))
|
|
|
|
|
})
|
|
|
|
|
}))
|
|
|
|
|
.buffered(CONCURRENT_DECODE)
|
|
|
|
|
@@ -1108,7 +1101,6 @@ async fn download_and_decompile_history_into_git(config:DownloadAndDecompileHist
|
|
|
|
|
//I could use a function!
|
|
|
|
|
//eventually:
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
#[allow(dead_code)]//idk why this thinks it's dead code, the errors are printed out in various places
|
|
|
|
|
enum QueryResolveError{
|
|
|
|
|
NotFound,//0 results
|
|
|
|
|
Ambiguous,//>1 results
|
|
|
|
|
@@ -1127,7 +1119,7 @@ struct FileWithName{
|
|
|
|
|
name:String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn get_file_async(mut path:PathBuf,file_name:impl AsRef<std::path::Path>)->Result<FileWithName,QueryResolveError>{
|
|
|
|
|
async fn get_file_async(mut path:std::path::PathBuf,file_name:impl AsRef<std::path::Path>)->Result<FileWithName,QueryResolveError>{
|
|
|
|
|
let name=file_name.as_ref().to_str().unwrap().to_owned();
|
|
|
|
|
path.push(file_name);
|
|
|
|
|
match tokio::fs::File::open(path).await{
|
|
|
|
|
@@ -1147,7 +1139,7 @@ struct QuerySingle{
|
|
|
|
|
script:QueryHandle,
|
|
|
|
|
}
|
|
|
|
|
impl QuerySingle{
|
|
|
|
|
fn rox(search_path:&PathBuf,search_name:&str)->Self{
|
|
|
|
|
fn rox(search_path:&std::path::PathBuf,search_name:&str)->Self{
|
|
|
|
|
Self{
|
|
|
|
|
script:tokio::spawn(get_file_async(search_path.clone(),format!("{}.lua",search_name)))
|
|
|
|
|
}
|
|
|
|
|
@@ -1168,7 +1160,7 @@ struct QueryTriple{
|
|
|
|
|
client:QueryHandle,
|
|
|
|
|
}
|
|
|
|
|
impl QueryTriple{
|
|
|
|
|
fn rox_rojo(search_path:&PathBuf,search_name:&str,search_module:bool)->Self{
|
|
|
|
|
fn rox_rojo(search_path:&std::path::PathBuf,search_name:&str,search_module:bool)->Self{
|
|
|
|
|
//this should be implemented as constructors of Triplet and Quadruplet to fully support Trey's suggestion
|
|
|
|
|
let module_name=if search_module{
|
|
|
|
|
format!("{}.module.lua",search_name)
|
|
|
|
|
@@ -1181,7 +1173,7 @@ impl QueryTriple{
|
|
|
|
|
client:tokio::spawn(get_file_async(search_path.clone(),format!("{}.client.lua",search_name))),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fn rojo(search_path:&PathBuf)->Self{
|
|
|
|
|
fn rojo(search_path:&std::path::PathBuf)->Self{
|
|
|
|
|
QueryTriple::rox_rojo(search_path,"init",false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -1251,7 +1243,7 @@ struct QueryQuad{
|
|
|
|
|
client:QueryHandle,
|
|
|
|
|
}
|
|
|
|
|
impl QueryQuad{
|
|
|
|
|
fn rox_rojo(search_path:&PathBuf,search_name:&str)->Self{
|
|
|
|
|
fn rox_rojo(search_path:&std::path::PathBuf,search_name:&str)->Self{
|
|
|
|
|
let fill=QueryTriple::rox_rojo(search_path,search_name,true);
|
|
|
|
|
Self{
|
|
|
|
|
module_implicit:QuerySingle::rox(search_path,search_name).script,//Script.lua
|
|
|
|
|
@@ -1312,9 +1304,9 @@ async fn script_node(search_name:&str,mut file:FileWithName,hint:ScriptHint)->AR
|
|
|
|
|
(Some("ModuleScript"),_)
|
|
|
|
|
|(None,ScriptHint::ModuleScript)=>CompileClass::ModuleScript(script_with_overrides.source),
|
|
|
|
|
(Some("LocalScript"),_)
|
|
|
|
|
|(None,ScriptHint::LocalScript)=>CompileClass::LocalScript(script_with_overrides.source),
|
|
|
|
|
|(None,ScriptHint::Script)=>CompileClass::LocalScript(script_with_overrides.source),
|
|
|
|
|
(Some("Script"),_)
|
|
|
|
|
|(None,ScriptHint::Script)=>CompileClass::Script(script_with_overrides.source),
|
|
|
|
|
|(None,ScriptHint::LocalScript)=>CompileClass::Script(script_with_overrides.source),
|
|
|
|
|
other=>Err(anyhow::Error::msg(format!("Invalid hint or class {other:?}")))?,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
@@ -1460,9 +1452,9 @@ enum CompileStackInstruction{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct CompileConfig{
|
|
|
|
|
input_folder:PathBuf,
|
|
|
|
|
output_file:PathBuf,
|
|
|
|
|
template:Option<PathBuf>,
|
|
|
|
|
input_folder:std::path::PathBuf,
|
|
|
|
|
output_file:std::path::PathBuf,
|
|
|
|
|
template:Option<std::path::PathBuf>,
|
|
|
|
|
style:Option<DecompileStyle>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1482,17 +1474,21 @@ enum TooComplicated<T>{
|
|
|
|
|
async fn compile(config:CompileConfig)->AResult<()>{
|
|
|
|
|
//basically decompile in reverse order
|
|
|
|
|
//load template dom
|
|
|
|
|
let mut dom=match config.template{
|
|
|
|
|
let input={
|
|
|
|
|
let template_path=config.template.unwrap_or_else(||{
|
|
|
|
|
let mut template_path=config.input_folder.clone();
|
|
|
|
|
template_path.push("template.rbxlx");
|
|
|
|
|
template_path
|
|
|
|
|
});
|
|
|
|
|
//mr dom doesn't like tokio files
|
|
|
|
|
Some(template_path)=>load_dom(std::io::BufReader::new(std::fs::File::open(template_path)?))?,
|
|
|
|
|
None=>rbx_dom_weak::WeakDom::default(),
|
|
|
|
|
std::io::BufReader::new(std::fs::File::open(template_path)?)
|
|
|
|
|
};
|
|
|
|
|
//hack to traverse root folder as the root object
|
|
|
|
|
dom.root_mut().name="src".to_owned();
|
|
|
|
|
let mut dom=load_dom(input)?;
|
|
|
|
|
|
|
|
|
|
//add in scripts and models
|
|
|
|
|
let mut folder=config.input_folder.clone();
|
|
|
|
|
let mut stack:Vec<CompileStackInstruction>=vec![CompileStackInstruction::TraverseReferent(dom.root_ref(),None)];
|
|
|
|
|
folder.push("src");
|
|
|
|
|
let mut stack:Vec<CompileStackInstruction>=dom.root().children().into_iter().map(|&referent|CompileStackInstruction::TraverseReferent(referent,None)).collect();
|
|
|
|
|
while let Some(instruction)=stack.pop(){
|
|
|
|
|
match instruction{
|
|
|
|
|
CompileStackInstruction::TraverseReferent(item_ref,blacklist)=>{
|
|
|
|
|
|