@@ -4,11 +4,12 @@ extern crate dtoa;
4
4
extern crate glob;
5
5
extern crate json;
6
6
7
- use std:: fs:: File ;
8
- use std:: io:: { BufRead , BufReader , Read , Write } ;
9
-
10
- use std:: collections:: HashMap ;
11
- use std:: path:: Path ;
7
+ use std:: {
8
+ collections:: HashMap ,
9
+ fs:: File ,
10
+ io:: { BufRead , BufReader , Read , Write } ,
11
+ path:: Path ,
12
+ } ;
12
13
13
14
mod hashes;
14
15
mod json_reader;
@@ -19,7 +20,7 @@ mod writer;
19
20
20
21
fn main ( ) {
21
22
let matches = clap:: Command :: new ( "BinReader-Rust" )
22
- . version ( "0.3.0" )
23
+ . version ( env ! ( "CARGO_PKG_VERSION" ) )
23
24
. author ( "https://github.com/autergame/" )
24
25
. about ( "League Of Legends Bin Reader And Writter" )
25
26
. arg_required_else_help ( true )
@@ -58,66 +59,76 @@ fn main() {
58
59
)
59
60
. get_matches ( ) ;
60
61
61
- if let Some ( matches) = matches. subcommand_matches ( "decode" ) {
62
- let input = matches. get_one :: < String > ( "INPUT" ) . unwrap ( ) ;
63
- let output = matches. get_one :: < String > ( "OUTPUT" ) ;
64
-
65
- let mut hash_map: HashMap < u64 , String > = HashMap :: new ( ) ;
66
- add_to_hash_map ( & [ "path" , "patch" , "value" ] , & mut hash_map) ;
67
-
68
- println ! ( "Loading hashes" ) ;
69
- let mut lines =
70
- load_hashes_from_file ( Path :: new ( "files/hashes.bintypes.txt" ) , & mut hash_map) ;
71
- lines += load_hashes_from_file ( Path :: new ( "files/hashes.binfields.txt" ) , & mut hash_map) ;
72
- lines += load_hashes_from_file ( Path :: new ( "files/hashes.binhashes.txt" ) , & mut hash_map) ;
73
- lines += load_hashes_from_file ( Path :: new ( "files/hashes.binentries.txt" ) , & mut hash_map) ;
74
- lines += load_hashes_from_file ( Path :: new ( "files/hashes.lcu.txt" ) , & mut hash_map) ;
75
- lines += load_hashes_from_file ( Path :: new ( "files/hashes.game.txt" ) , & mut hash_map) ;
76
- println ! ( "Loaded total of hashes: {lines}" ) ;
77
- println ! ( "Finished loading hashes.\n " ) ;
78
-
79
- if let Some ( output) = output {
80
- let contents = read_to_u8 ( Path :: new ( input) ) ;
81
- let bin_file = reader:: read_bin ( & contents) ;
82
- let jsonstr = json_writer:: convert_bin_to_json ( & bin_file, & mut hash_map) ;
83
- write_u8 ( Path :: new ( output) , jsonstr. as_bytes ( ) ) ;
84
- } else {
85
- let input_paths = glob:: glob ( input)
86
- . expect ( "Failed to read glob pattern" )
87
- . filter_map ( Result :: ok) ;
88
-
89
- for mut input_path in input_paths {
90
- let contents = read_to_u8 ( & input_path) ;
91
- let bin_file = reader:: read_bin ( & contents) ;
92
- let jsonstr = json_writer:: convert_bin_to_json ( & bin_file, & mut hash_map) ;
93
- input_path. set_extension ( "json" ) ;
94
- write_u8 ( & input_path, jsonstr. as_bytes ( ) ) ;
95
- println ! ( ) ;
62
+ match matches. subcommand ( ) {
63
+ Some ( ( "decode" , args) ) => {
64
+ let input = args. get_one :: < String > ( "INPUT" ) . unwrap ( ) ;
65
+ let output = args. get_one :: < String > ( "OUTPUT" ) ;
66
+
67
+ let mut hash_map: HashMap < u64 , String > = HashMap :: new ( ) ;
68
+ add_to_hash_map ( & [ "path" , "patch" , "value" ] , & mut hash_map) ;
69
+
70
+ println ! ( "Loading hashes" ) ;
71
+ let mut lines =
72
+ load_hashes_from_file ( Path :: new ( "files/hashes.bintypes.txt" ) , & mut hash_map) ;
73
+ lines += load_hashes_from_file ( Path :: new ( "files/hashes.binfields.txt" ) , & mut hash_map) ;
74
+ lines += load_hashes_from_file ( Path :: new ( "files/hashes.binhashes.txt" ) , & mut hash_map) ;
75
+ lines += load_hashes_from_file ( Path :: new ( "files/hashes.binentries.txt" ) , & mut hash_map) ;
76
+ lines += load_hashes_from_file ( Path :: new ( "files/hashes.lcu.txt" ) , & mut hash_map) ;
77
+ lines += load_hashes_from_file ( Path :: new ( "files/hashes.game.txt" ) , & mut hash_map) ;
78
+ println ! ( "Loaded total of hashes: {lines}" ) ;
79
+ println ! ( "Finished loading hashes.\n " ) ;
80
+
81
+ match output {
82
+ Some ( output) => {
83
+ let contents = read_to_u8 ( Path :: new ( input) ) ;
84
+ let bin_file = reader:: read_bin ( & contents) ;
85
+ let jsonstr = json_writer:: convert_bin_to_json ( & bin_file, & mut hash_map) ;
86
+ write_u8 ( Path :: new ( output) , jsonstr. as_bytes ( ) ) ;
87
+ }
88
+ None => {
89
+ let input_paths = glob:: glob ( input)
90
+ . expect ( "Failed to read glob pattern" )
91
+ . filter_map ( Result :: ok) ;
92
+
93
+ for mut input_path in input_paths {
94
+ let contents = read_to_u8 ( & input_path) ;
95
+ let bin_file = reader:: read_bin ( & contents) ;
96
+ let jsonstr = json_writer:: convert_bin_to_json ( & bin_file, & mut hash_map) ;
97
+ input_path. set_extension ( "json" ) ;
98
+ write_u8 ( & input_path, jsonstr. as_bytes ( ) ) ;
99
+ println ! ( ) ;
100
+ }
101
+ }
96
102
}
97
103
}
98
- } else if let Some ( matches) = matches. subcommand_matches ( "encode" ) {
99
- let input = matches. get_one :: < String > ( "INPUT" ) . unwrap ( ) ;
100
- let output = matches. get_one :: < String > ( "OUTPUT" ) ;
101
-
102
- if let Some ( output) = output {
103
- let contents = read_string ( Path :: new ( input) ) ;
104
- let bin_file = json_reader:: convert_json_to_bin ( & contents) ;
105
- let bin = writer:: write_bin ( & bin_file) ;
106
- write_u8 ( Path :: new ( output) , & bin) ;
107
- } else {
108
- let input_paths = glob:: glob ( input)
109
- . expect ( "Failed to read glob pattern" )
110
- . filter_map ( Result :: ok) ;
111
-
112
- for mut input_path in input_paths {
113
- let contents = read_string ( & input_path) ;
114
- let bin_file = json_reader:: convert_json_to_bin ( & contents) ;
115
- let bin = writer:: write_bin ( & bin_file) ;
116
- input_path. set_extension ( "bin" ) ;
117
- write_u8 ( & input_path, & bin) ;
118
- println ! ( ) ;
104
+ Some ( ( "encode" , args) ) => {
105
+ let input = args. get_one :: < String > ( "INPUT" ) . unwrap ( ) ;
106
+ let output = args. get_one :: < String > ( "OUTPUT" ) ;
107
+
108
+ match output {
109
+ Some ( output) => {
110
+ let contents = read_string ( Path :: new ( input) ) ;
111
+ let bin_file = json_reader:: convert_json_to_bin ( & contents) ;
112
+ let bin = writer:: write_bin ( & bin_file) ;
113
+ write_u8 ( Path :: new ( output) , & bin) ;
114
+ }
115
+ None => {
116
+ let input_paths = glob:: glob ( input)
117
+ . expect ( "Failed to read glob pattern" )
118
+ . filter_map ( Result :: ok) ;
119
+
120
+ for mut input_path in input_paths {
121
+ let contents = read_string ( & input_path) ;
122
+ let bin_file = json_reader:: convert_json_to_bin ( & contents) ;
123
+ let bin = writer:: write_bin ( & bin_file) ;
124
+ input_path. set_extension ( "bin" ) ;
125
+ write_u8 ( & input_path, & bin) ;
126
+ println ! ( ) ;
127
+ }
128
+ }
119
129
}
120
130
}
131
+ _ => { }
121
132
}
122
133
}
123
134
0 commit comments