-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move functionality to modules and add prim read and extract examples
- Loading branch information
Showing
23 changed files
with
586 additions
and
3,068 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/target | ||
/objects | ||
/objects | ||
/output |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,13 @@ | ||
use std::{env, fs}; | ||
use std::fs::OpenOptions; | ||
use std::io::prelude::*; | ||
use std::env; | ||
|
||
use glacier2obj::connect::game_connection::GameConnection; | ||
|
||
use tungstenite::{connect, Message}; | ||
use url::Url; | ||
|
||
pub fn main() { | ||
let args: Vec<String> = env::args().collect(); | ||
if args.len() < 2 { | ||
eprintln!("Usage: cargo run -- example connect_to_game <in_file> <out_file>"); | ||
eprintln!("Usage: cargo run -- example connect_to_game <path to a to_find.json file> <path to an output prims.json file>"); | ||
return; | ||
} | ||
println!("Connecting to game on port 46735"); | ||
|
||
let (mut socket, _response) = connect( | ||
Url::parse("ws://localhost:46735/socket").unwrap() | ||
).expect("Can't connect"); | ||
|
||
let _ = socket.write_message(Message::Text(r#"{"type":"hello","identifier":"glacier2obj"}"#.into())); | ||
let message = fs::read_to_string(args[1].as_str()).expect(format!("Error opening {}. Run a scan to generate this file", args[1].as_str()).as_str()); | ||
|
||
let _ = socket.write_message(Message::Text(message.into())); | ||
|
||
fs::write(args[2].as_str(), "").expect(format!("Error writing to {}", args[2].as_str()).as_str()); | ||
|
||
let mut out_file = OpenOptions::new() | ||
.write(true) | ||
.append(true) | ||
.open(args[2].as_str()) | ||
.unwrap(); | ||
|
||
let mut welcome_received: bool = false; | ||
let mut is_first: bool = true; | ||
|
||
loop { | ||
let msg = socket.read_message().expect("Error reading message"); | ||
if msg.to_string().as_str() == "Done sending entities." { | ||
println!("Received Done message. Finalizing json output and exiting."); | ||
if let Err(e) = writeln!(out_file, "]}}") { | ||
eprintln!("Couldn't write to file: {}", e); | ||
} | ||
break | ||
} | ||
if welcome_received { | ||
if !is_first { | ||
if let Err(e) = writeln!(out_file, ",") { | ||
eprintln!("Couldn't write to file: {}", e); | ||
} | ||
} else { | ||
is_first = false; | ||
} | ||
if let Err(e) = write!(out_file, "{}", msg) { | ||
eprintln!("Couldn't write to file: {}", e); | ||
} | ||
} else { | ||
if let Err(e) = write!(out_file, r#"{{"entities":["#) { | ||
eprintln!("Couldn't write to file: {}", e); | ||
} | ||
welcome_received = true; | ||
} | ||
} | ||
} | ||
GameConnection::get_prim_list_from_game(args[1].as_str(), args[2].as_str()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use glacier2obj::extract::prim_extraction::PrimExtraction; | ||
use glacier2obj::json_serde::prims_json::PrimsJson; | ||
use glacier2obj::package::package_scan::PackageScan; | ||
use std::env; | ||
|
||
fn main() { | ||
let args: Vec<String> = env::args().collect(); | ||
|
||
if args.len() < 6 { | ||
eprintln!("Usage: cargo run --example extract_prims -- <path to a Retail directory> <path to a Runtime directory> <game version (H2016 | HM2 | HM3)> <path to a prims.json file> <path to output directory>"); | ||
return; | ||
} | ||
let prims_json = PrimsJson::build_from_prims_file(args[4].clone()); | ||
let needed_prim_hashes = PrimExtraction::get_needed_prim_hashes(&prims_json, args[5].clone()); | ||
if needed_prim_hashes.is_empty() { | ||
println!("All prim files already exist. Skipping extraction."); | ||
return; | ||
} | ||
println!("Extracting {} prims.", needed_prim_hashes.len()); | ||
let partition_manager = PackageScan::scan_packages(args[1].clone(), args[3].clone()).unwrap(); | ||
PrimExtraction::extract_prims(args[2].clone(), needed_prim_hashes, &partition_manager, args[5].clone()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use glacier2obj::json_serde::prims_json::PrimsJson; | ||
use std::env; | ||
|
||
fn main() { | ||
let args: Vec<String> = env::args().collect(); | ||
|
||
if args.len() < 2 { | ||
eprintln!("Usage: cargo run --example read_prims -- <path to a prims.json file>"); | ||
return; | ||
} | ||
let mut prims_json: PrimsJson = PrimsJson::build_from_prims_file(args[1].clone()); | ||
prims_json.output_prims(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.