@@ -10,21 +10,20 @@ use std::io::{BufRead, BufReader, Read, Write};
10
10
use std:: collections:: HashMap ;
11
11
use std:: path:: Path ;
12
12
13
- mod lol_bin_hashes ;
14
- mod lol_bin_json_read ;
15
- mod lol_bin_json_write ;
16
- mod lol_bin_read ;
17
- mod lol_bin_struct ;
18
- mod lol_bin_write ;
13
+ mod hashes ;
14
+ mod json_reader ;
15
+ mod json_writer ;
16
+ mod reader ;
17
+ mod structs ;
18
+ mod writer ;
19
19
20
20
fn main ( ) {
21
21
let matches = clap:: Command :: new ( "BinReader-Rust" )
22
- . version ( "0.1 .0" )
22
+ . version ( "0.3 .0" )
23
23
. author ( "https://github.com/autergame/" )
24
24
. about ( "League Of Legends Bin Reader And Writter" )
25
25
. arg_required_else_help ( true )
26
26
. subcommand_required ( true )
27
- . mut_subcommand ( "help" , |subcmd| subcmd. hide ( true ) )
28
27
. subcommand (
29
28
clap:: Command :: new ( "decode" )
30
29
. about ( "Decodes the given file" )
@@ -79,8 +78,8 @@ fn main() {
79
78
80
79
if let Some ( output) = output {
81
80
let contents = read_to_u8 ( Path :: new ( input) ) ;
82
- let bin_file = lol_bin_read :: read_bin ( & contents) ;
83
- let jsonstr = lol_bin_json_write :: convert_bin_to_json ( & bin_file, & mut hash_map) ;
81
+ let bin_file = reader :: read_bin ( & contents) ;
82
+ let jsonstr = json_writer :: convert_bin_to_json ( & bin_file, & mut hash_map) ;
84
83
write_u8 ( Path :: new ( output) , jsonstr. as_bytes ( ) ) ;
85
84
} else {
86
85
let input_paths = glob:: glob ( input)
@@ -89,11 +88,11 @@ fn main() {
89
88
90
89
for mut input_path in input_paths {
91
90
let contents = read_to_u8 ( & input_path) ;
92
- let bin_file = lol_bin_read :: read_bin ( & contents) ;
93
- let jsonstr = lol_bin_json_write :: convert_bin_to_json ( & bin_file, & mut hash_map) ;
91
+ let bin_file = reader :: read_bin ( & contents) ;
92
+ let jsonstr = json_writer :: convert_bin_to_json ( & bin_file, & mut hash_map) ;
94
93
input_path. set_extension ( "json" ) ;
95
94
write_u8 ( & input_path, jsonstr. as_bytes ( ) ) ;
96
- println ! ( "" ) ;
95
+ println ! ( ) ;
97
96
}
98
97
}
99
98
} else if let Some ( matches) = matches. subcommand_matches ( "encode" ) {
@@ -102,8 +101,8 @@ fn main() {
102
101
103
102
if let Some ( output) = output {
104
103
let contents = read_string ( Path :: new ( input) ) ;
105
- let bin_file = lol_bin_json_read :: convert_json_to_bin ( & contents) ;
106
- let bin = lol_bin_write :: write_bin ( & bin_file) ;
104
+ let bin_file = json_reader :: convert_json_to_bin ( & contents) ;
105
+ let bin = writer :: write_bin ( & bin_file) ;
107
106
write_u8 ( Path :: new ( output) , & bin) ;
108
107
} else {
109
108
let input_paths = glob:: glob ( input)
@@ -112,53 +111,64 @@ fn main() {
112
111
113
112
for mut input_path in input_paths {
114
113
let contents = read_string ( & input_path) ;
115
- let bin_file = lol_bin_json_read :: convert_json_to_bin ( & contents) ;
116
- let bin = lol_bin_write :: write_bin ( & bin_file) ;
114
+ let bin_file = json_reader :: convert_json_to_bin ( & contents) ;
115
+ let bin = writer :: write_bin ( & bin_file) ;
117
116
input_path. set_extension ( "bin" ) ;
118
117
write_u8 ( & input_path, & bin) ;
119
- println ! ( "" ) ;
118
+ println ! ( ) ;
120
119
}
121
120
}
122
121
}
123
122
}
124
123
125
124
fn load_hashes_from_file ( path : & Path , hash_map : & mut HashMap < u64 , String > ) -> u32 {
125
+ let path_str = path. to_str ( ) . unwrap ( ) ;
126
+
126
127
let file = match File :: open ( path) {
127
128
Ok ( file) => file,
128
- Err ( err) => {
129
- println ! (
130
- "Could not open hash file: {} error: {}" ,
131
- path. to_str( ) . unwrap( ) ,
132
- err
133
- ) ;
129
+ Err ( error) => {
130
+ println ! ( "Could not open hash file: {} error: {}" , path_str, error) ;
134
131
return 0 ;
135
132
}
136
133
} ;
137
134
138
- let mut lines: u32 = 0 ;
135
+ let mut lines = 0 ;
139
136
let mut reader = BufReader :: new ( file) ;
140
137
let mut line = String :: with_capacity ( 1024 ) ;
141
138
142
- while reader
143
- . read_line ( & mut line)
144
- . unwrap_or_else ( |_| panic ! ( "Could not read line: {}" , path. to_str( ) . unwrap( ) ) )
145
- != 0
146
- {
139
+ let msg = |error| {
140
+ println ! (
141
+ "Could not read line hash file: {} error: {}" ,
142
+ path_str, error
143
+ ) ;
144
+ 0
145
+ } ;
146
+
147
+ while reader. read_line ( & mut line) . unwrap_or_else ( msg) != 0 {
147
148
let mut line_split = line. split ( ' ' ) ;
148
149
149
150
if line_split. clone ( ) . count ( ) == 2 {
150
151
let key_str = line_split. next ( ) . unwrap ( ) ;
151
152
152
- let key: u64 = if key_str. len ( ) == 8 {
153
- u32:: from_str_radix ( key_str, 16 )
154
- . unwrap_or_else ( |_| panic ! ( "Invalid hex: {}" , key_str) ) as u64
155
- } else if key_str. len ( ) == 16 {
156
- u64:: from_str_radix ( key_str, 16 )
157
- . unwrap_or_else ( |_| panic ! ( "Invalid hex: {}" , key_str) )
158
- } else {
153
+ let key = match key_str. len ( ) {
154
+ 8 => u32:: from_str_radix ( key_str, 16 ) . unwrap_or_else ( |_| {
155
+ println ! ( "Invalid hex: {}" , key_str) ;
156
+ 0
157
+ } ) as u64 ,
158
+ 16 => u64:: from_str_radix ( key_str, 16 ) . unwrap_or_else ( |_| {
159
+ println ! ( "Invalid hex: {}" , key_str) ;
160
+ 0
161
+ } ) ,
162
+ _ => {
163
+ line. clear ( ) ;
164
+ continue ;
165
+ }
166
+ } ;
167
+
168
+ if key == 0 {
159
169
line. clear ( ) ;
160
170
continue ;
161
- } ;
171
+ }
162
172
163
173
lines += hash_map
164
174
. insert (
@@ -175,18 +185,15 @@ fn load_hashes_from_file(path: &Path, hash_map: &mut HashMap<u64, String>) -> u3
175
185
line. clear ( ) ;
176
186
}
177
187
178
- println ! ( "File: {} loaded: {} lines" , path . to_str ( ) . unwrap ( ) , lines) ;
188
+ println ! ( "File: {} loaded: {} lines" , path_str , lines) ;
179
189
180
190
lines
181
191
}
182
192
183
193
fn add_to_hash_map ( hashes_to_insert : & [ & str ] , hash_map : & mut HashMap < u64 , String > ) {
184
194
for hash_name in hashes_to_insert {
185
- hash_map. insert (
186
- lol_bin_hashes:: fnv1a ( hash_name) as u64 ,
187
- hash_name. to_string ( ) ,
188
- ) ;
189
- hash_map. insert ( lol_bin_hashes:: xxhash ( hash_name) , hash_name. to_string ( ) ) ;
195
+ hash_map. insert ( hashes:: fnv1a ( hash_name) as u64 , hash_name. to_string ( ) ) ;
196
+ hash_map. insert ( hashes:: xxhash ( hash_name) , hash_name. to_string ( ) ) ;
190
197
}
191
198
}
192
199
0 commit comments