From 29a01812ecfab9c03a6132e46062de2a5f686faa Mon Sep 17 00:00:00 2001 From: Jack Fox <0xdeadbeef1@gmail.com> Date: Tue, 17 May 2022 17:09:24 -0400 Subject: [PATCH 1/3] Updated place runner to accept additional arguments --- src/place_runner.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/place_runner.rs b/src/place_runner.rs index 2dd57d8..6ce8469 100644 --- a/src/place_runner.rs +++ b/src/place_runner.rs @@ -26,8 +26,8 @@ impl Drop for KillOnDrop { pub struct PlaceRunner { pub port: u16, - pub place_path: PathBuf, pub server_id: String, + pub args: Vec, pub lua_script: String, } @@ -56,7 +56,7 @@ impl PlaceRunner { let _studio_process = KillOnDrop( Command::new(studio_install.application_path()) - .arg(format!("{}", self.place_path.display())) + .args(&self.args) .stdout(Stdio::null()) .stderr(Stdio::null()) .spawn()?, From 38eebb596f419c41e947124bd83d891bd8e158bf Mon Sep 17 00:00:00 2001 From: Jack Fox <0xdeadbeef1@gmail.com> Date: Tue, 17 May 2022 17:15:02 -0400 Subject: [PATCH 2/3] Implemented arguments to open a specific place --- src/main.rs | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index fb76cd3..765a3db 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,6 +22,16 @@ struct Options { #[structopt(long("place"))] place_path: Option, + /// The universe of the place id to open in Roblox Studio. If not specified, + /// the place-id will not be used + #[structopt(long("universe"))] + universe_id: Option, + + /// The place id to open in Roblox Studio. If not specified, the place-id + /// will not be used + #[structopt(long("place-id"))] + place_id: Option, + /// A path to the script to run in Roblox Studio. /// /// The script will be run at plugin-level security. @@ -30,11 +40,13 @@ struct Options { } fn run(options: Options) -> Result { + // Additional parameters that we may want to pass to roblox Studio + let mut params = vec![]; + // Create a temp directory to house our place, even if a path is given from // the command line. This helps ensure Studio won't hang trying to tell the // user that the place is read-only because of a .lock file. let temp_place_folder = tempdir()?; - let temp_place_path; match &options.place_path { Some(place_path) => { @@ -44,17 +56,40 @@ fn run(options: Options) -> Result { .to_str() .ok_or_else(|| anyhow!("Place file extension had invalid Unicode"))?; - temp_place_path = temp_place_folder + let temp_place_path = temp_place_folder .path() .join(format!("run-in-roblox-place.{}", extension)); fs::copy(place_path, &temp_place_path)?; + + params.push(format!("{}", temp_place_path.display())); } None => { - unimplemented!("run-in-roblox with no place argument"); + // Fall back to testing universe and place-id + // If we have both a universe and place id, we need to pass them to Studio + match (&options.universe_id, &options.place_id) { + (Some(universe_id), Some(place_id)) => { + params.extend_from_slice(&vec![ + // This tells studio to open the place + "-task".to_string(), + "EditPlace".to_string(), + // The universe to open + "-universeId".to_string(), + universe_id.to_string(), + // The place to open + "-placeId".to_string(), + place_id.to_string(), + ]); + } + _ => { + unimplemented!("run-in-roblox must have a place path or universe and place id"); + } + }; } } + + let script_contents = fs::read_to_string(&options.script_path)?; // Generate a random, unique ID for this session. The plugin we inject will @@ -64,9 +99,9 @@ fn run(options: Options) -> Result { let place_runner = PlaceRunner { port: 50312, - place_path: temp_place_path.clone(), server_id: server_id.clone(), lua_script: script_contents.clone(), + args: params, }; let (sender, receiver) = mpsc::channel(); From 33119c6a7dd9f32a5a1e131f7858920e8779596e Mon Sep 17 00:00:00 2001 From: Jack Fox <0xdeadbeef1@gmail.com> Date: Tue, 17 May 2022 17:52:59 -0400 Subject: [PATCH 3/3] Updated universe-id and place-id optional and default to the default baseplate --- src/main.rs | 49 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/src/main.rs b/src/main.rs index 765a3db..1bf899c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,7 +24,7 @@ struct Options { /// The universe of the place id to open in Roblox Studio. If not specified, /// the place-id will not be used - #[structopt(long("universe"))] + #[structopt(long("universe-id"))] universe_id: Option, /// The place id to open in Roblox Studio. If not specified, the place-id @@ -65,26 +65,41 @@ fn run(options: Options) -> Result { params.push(format!("{}", temp_place_path.display())); } None => { + // Default baseplate place: https://www.roblox.com/games/95206881/Baseplate + let mut place_id = "95206881".to_string(); + let mut universe_id = Some("28220420".to_string()); + // Fall back to testing universe and place-id // If we have both a universe and place id, we need to pass them to Studio match (&options.universe_id, &options.place_id) { - (Some(universe_id), Some(place_id)) => { - params.extend_from_slice(&vec![ - // This tells studio to open the place - "-task".to_string(), - "EditPlace".to_string(), - // The universe to open - "-universeId".to_string(), - universe_id.to_string(), - // The place to open - "-placeId".to_string(), - place_id.to_string(), - ]); - } - _ => { - unimplemented!("run-in-roblox must have a place path or universe and place id"); - } + (Some(input_universe_id), Some(input_place_id)) => { + place_id = format!("{}", input_place_id); + universe_id = Some(format!("{}", input_universe_id)); + }, + (None, Some(input_place_id)) => { + place_id = format!("{}", input_place_id); + universe_id = None; + }, + (Some(_), None) => { + unimplemented!("You must specify a place-id if you specify a universe-id"); + }, + _ => {} }; + + params.extend_from_slice(&vec![ + // This tells studio to open the place + "-task".to_string(), + "EditPlace".to_string(), + "-placeId".to_string(), + place_id, + ]); + + if let Some(universe_id) = universe_id { + params.extend_from_slice(&vec![ + "-universeId".to_string(), + universe_id, + ]); + } } }