Skip to content

Commit 3d477ee

Browse files
committed
code and files refactor
1 parent b275783 commit 3d477ee

11 files changed

+69
-61
lines changed

.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
cross_compile.sh
2+
13
files/*.bin
24
files/*.json
35

@@ -7,6 +9,4 @@ Cargo.lock
79

810
**/*.rs.bk
911

10-
*.pdb
11-
1212
.vscode/

BinReader-Rust_image.png

94.3 KB
Loading

Cargo.toml

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
[package]
22
name = "binreader-rust"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
authors = ["autergame"]
55

66
[dependencies]
77
byteorder = "1.4.3"
88
json = "0.12.4"
9-
dtoa = "1.0.2"
10-
clap = "3.2.15"
11-
glob = "0.3.0"
9+
dtoa = "1.0.5"
10+
clap = "4.1.4"
11+
glob = "0.3.1"
12+
13+
[profile]
14+
release = { strip = true }

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ League Of Legends Bin Reader And Writter Using Rust
66

77
## Help From:
88
* https://github.com/autergame/BinReader
9+
* https://github.com/CommunityDragon/CDTB
910
* https://github.com/moonshadow565/ritobin
1011
* https://github.com/LoL-Fantome/LeagueToolkit
11-
* https://github.com/CommunityDragon/CDTB
12-
* https://github.com/DaveGamble/cJSON
1312

1413
## How to use:
1514

File renamed without changes.

src/lol_bin_json_read.rs src/json_reader.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
use lol_bin_hashes;
2-
use lol_bin_struct::*;
1+
use hashes;
2+
use structs::*;
33

44
use json::JsonValue;
55

66
fn string_to_hash_u32(value: &str) -> u32 {
77
if let Some(hex) = hex_or_decimal_from_string_u32(value) {
88
hex
99
} else {
10-
lol_bin_hashes::fnv1a(value)
10+
hashes::fnv1a(value)
1111
}
1212
}
1313

1414
fn string_to_hash_u64(value: &str) -> u64 {
1515
if let Some(hex) = hex_or_decimal_from_string_u64(value) {
1616
hex
1717
} else {
18-
lol_bin_hashes::xxhash(value)
18+
hashes::xxhash(value)
1919
}
2020
}
2121

src/lol_bin_json_write.rs src/json_writer.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
use lol_bin_struct::*;
2-
3-
use std::collections::HashMap;
1+
use structs::*;
42

53
use json::{codegen::Generator, JsonValue};
4+
use std::collections::HashMap;
65

76
fn hash_u32_to_string(value: u32, hash_map: &mut HashMap<u64, String>) -> String {
87
let str_value = hash_map.get(&(value as u64));

src/main.rs

+51-44
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,20 @@ use std::io::{BufRead, BufReader, Read, Write};
1010
use std::collections::HashMap;
1111
use std::path::Path;
1212

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;
1919

2020
fn main() {
2121
let matches = clap::Command::new("BinReader-Rust")
22-
.version("0.1.0")
22+
.version("0.3.0")
2323
.author("https://github.com/autergame/")
2424
.about("League Of Legends Bin Reader And Writter")
2525
.arg_required_else_help(true)
2626
.subcommand_required(true)
27-
.mut_subcommand("help", |subcmd| subcmd.hide(true))
2827
.subcommand(
2928
clap::Command::new("decode")
3029
.about("Decodes the given file")
@@ -79,8 +78,8 @@ fn main() {
7978

8079
if let Some(output) = output {
8180
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);
8483
write_u8(Path::new(output), jsonstr.as_bytes());
8584
} else {
8685
let input_paths = glob::glob(input)
@@ -89,11 +88,11 @@ fn main() {
8988

9089
for mut input_path in input_paths {
9190
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);
9493
input_path.set_extension("json");
9594
write_u8(&input_path, jsonstr.as_bytes());
96-
println!("");
95+
println!();
9796
}
9897
}
9998
} else if let Some(matches) = matches.subcommand_matches("encode") {
@@ -102,8 +101,8 @@ fn main() {
102101

103102
if let Some(output) = output {
104103
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);
107106
write_u8(Path::new(output), &bin);
108107
} else {
109108
let input_paths = glob::glob(input)
@@ -112,53 +111,64 @@ fn main() {
112111

113112
for mut input_path in input_paths {
114113
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);
117116
input_path.set_extension("bin");
118117
write_u8(&input_path, &bin);
119-
println!("");
118+
println!();
120119
}
121120
}
122121
}
123122
}
124123

125124
fn load_hashes_from_file(path: &Path, hash_map: &mut HashMap<u64, String>) -> u32 {
125+
let path_str = path.to_str().unwrap();
126+
126127
let file = match File::open(path) {
127128
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);
134131
return 0;
135132
}
136133
};
137134

138-
let mut lines: u32 = 0;
135+
let mut lines = 0;
139136
let mut reader = BufReader::new(file);
140137
let mut line = String::with_capacity(1024);
141138

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 {
147148
let mut line_split = line.split(' ');
148149

149150
if line_split.clone().count() == 2 {
150151
let key_str = line_split.next().unwrap();
151152

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 {
159169
line.clear();
160170
continue;
161-
};
171+
}
162172

163173
lines += hash_map
164174
.insert(
@@ -175,18 +185,15 @@ fn load_hashes_from_file(path: &Path, hash_map: &mut HashMap<u64, String>) -> u3
175185
line.clear();
176186
}
177187

178-
println!("File: {} loaded: {} lines", path.to_str().unwrap(), lines);
188+
println!("File: {} loaded: {} lines", path_str, lines);
179189

180190
lines
181191
}
182192

183193
fn add_to_hash_map(hashes_to_insert: &[&str], hash_map: &mut HashMap<u64, String>) {
184194
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());
190197
}
191198
}
192199

src/lol_bin_read.rs src/reader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use lol_bin_struct::*;
1+
use structs::*;
22

33
use byteorder::{LittleEndian, ReadBytesExt};
44
use std::io::{Cursor, Read};
File renamed without changes.

src/lol_bin_write.rs src/writer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use lol_bin_struct::*;
1+
use structs::*;
22

33
use byteorder::{LittleEndian, WriteBytesExt};
44
use std::io::Write;

0 commit comments

Comments
 (0)