From 10f4c7bf61a583a9869e3fb64f0141ff649c6e7f Mon Sep 17 00:00:00 2001 From: owent Date: Sat, 26 Aug 2023 12:40:23 +0800 Subject: [PATCH] Add `--head-only` and `--silence` --- README.md | 20 +++++++++++++-- src/exec/Cargo.toml | 2 +- src/exec/src/main.rs | 61 +++++++++++++++++++++++++++----------------- 3 files changed, 57 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index d52254a..1ef0dfd 100644 --- a/README.md +++ b/README.md @@ -26,13 +26,13 @@ You can use environment `RUST_LOG=` to control log level and `RUST_LOG_ST Example output: `./xresloader-dump-bin -p ./sample-conf/kind.pb -b ./sample-data/role_upgrade_cfg.bin` (Without `--pretty`) ```bash -======================== Header: .\sample-data\role_upgrade_cfg.bin ======================== +======================== Header: ./sample-data/role_upgrade_cfg.bin ======================== xresloader version: 2.8.0 data version: 2.8.0.20200609192757 data count: 11 hash code: sha256:718d22f78006e5d34d6b68eb56e204a00f4174737b6864e247b661d8963c7df3 description: -============ Body: .\sample-data\role_upgrade_cfg.bin -> role_upgrade_cfg ============ +============ Body: ./sample-data/role_upgrade_cfg.bin -> role_upgrade_cfg ============ [ {"Id": 10001, "Level": 1}, {"Id": 10001, "Level": 2, "CostType": 10001, "CostValue": 50}, @@ -48,6 +48,22 @@ description: ] ``` +### Dump string in binary files into a standalone json/text file + +This can be used to generate string table data source for UnrealEngine(UE). + +```bash +./xresloader-dump-bin.exe -p ../xresloader/sample/proto_v3/kind.pb \ + -b ../xresloader/sample/proto_v3/arr_in_arr_cfg.bin \ + -b ../xresloader/sample/proto_v3/event_cfg.bin \ + --output-string-table-json string-table.json --output-string-table-text string-table.txt \ + --silence --string-table-pretty + +# strings will be saved in string-table.json and string-table.txt +# We can also use --string-table-value-regex-rule and --string-table-value-regex-file to filter contents +# and use --string-table-field-path-file to filter contents by which protocol paths +``` + https://doc.rust-lang.org/cargo/reference/config.html [1]: https://github.com/xresloader/xresloader diff --git a/src/exec/Cargo.toml b/src/exec/Cargo.toml index a14bdec..d7a4ffe 100644 --- a/src/exec/Cargo.toml +++ b/src/exec/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "xresloader-dump-bin" -version = "2.2.0" +version = "2.2.1" authors = ["owent "] license = "MIT" description = "A tool to dump human readable text from binary output of xresloader" diff --git a/src/exec/src/main.rs b/src/exec/src/main.rs index b044e04..19de22d 100644 --- a/src/exec/src/main.rs +++ b/src/exec/src/main.rs @@ -35,11 +35,11 @@ use file_descriptor_index::FileDescriptorIndex; #[derive(Parser, Debug)] #[clap(version, about, long_about = None)] struct DumpOptions { - /// pb file + /// pb files(can be used mulpitle times) #[clap(short, long, value_parser, action = ArgAction::Append)] pb_file: Vec, - /// binary file generated by xresloader + /// binary files generated by xresloader(can be used mulpitle times) #[clap(short, long, value_parser, action = ArgAction::Append)] bin_file: Vec, @@ -55,6 +55,14 @@ struct DumpOptions { #[clap(long, value_parser, default_value = "false")] plain: bool, + /// head_only mode + #[clap(long, value_parser, default_value = "false")] + head_only: bool, + + /// silence mode + #[clap(long, value_parser, default_value = "false")] + silence: bool, + /// Output string table as json #[clap(long, value_parser, default_value = "")] output_string_table_json: String, @@ -63,15 +71,15 @@ struct DumpOptions { #[clap(long, value_parser, default_value = "")] output_string_table_text: String, - /// Field value matching for string table + /// Field value matching for string table(can be used mulpitle times) #[clap(long, value_parser, action = ArgAction::Append)] string_table_value_regex_rule: Vec, - /// Load field value matching rule from file for string table + /// Load field value matching rule(regex) from file for string table(can be used mulpitle times) #[clap(long, value_parser, action = ArgAction::Append)] string_table_value_regex_file: Vec, - /// Load field path from file for string table + /// Load field path from file for string table(can be used mulpitle times) #[clap(long, value_parser, action = ArgAction::Append)] string_table_field_path_file: Vec, @@ -580,21 +588,22 @@ fn main() { } }; - - info!("======================== Header: {} ========================", &bin_file); - info!("xresloader version: {}", data_blocks.header.xres_ver); - info!("data version: {}", data_blocks.header.data_ver); - info!("data count: {}", data_blocks.header.count); - info!("hash code: {}", data_blocks.header.hash_code); - info!("description: {}", data_blocks.header.description); - if !data_blocks.header.data_source.is_empty() { - info!("data source:"); - } - for data_source in &data_blocks.header.data_source { - if data_source.count > 0 { - info!(" - file: {}, sheet: {}, count: {}", data_source.file, data_source.sheet, data_source.count); - } else { - info!(" - file: {}, sheet: {}", data_source.file, data_source.sheet); + if !args.silence { + info!("======================== Header: {} ========================", &bin_file); + info!("xresloader version: {}", data_blocks.header.xres_ver); + info!("data version: {}", data_blocks.header.data_ver); + info!("data count: {}", data_blocks.header.count); + info!("hash code: {}", data_blocks.header.hash_code); + info!("description: {}", data_blocks.header.description); + if !data_blocks.header.data_source.is_empty() { + info!("data source:"); + } + for data_source in &data_blocks.header.data_source { + if data_source.count > 0 { + info!(" - file: {}, sheet: {}, count: {}", data_source.file, data_source.sheet, data_source.count); + } else { + info!(" - file: {}, sheet: {}", data_source.file, data_source.sheet); + } } } @@ -621,9 +630,11 @@ fn main() { }, }); } - info!("============ Body: {} -> {} ============", &bin_file, &data_blocks.data_message_type); + if !args.silence { + info!("============ Body: {} -> {} ============", &bin_file, &data_blocks.data_message_type); + } let mut row_index = 0; - if !args.plain { + if !args.plain && !args.head_only && !args.silence { info!("["); } let mut current_string_table :Option = None; @@ -663,6 +674,10 @@ fn main() { string_table.load_message(message.as_ref(), &string_table_value_regex_rules, &string_table_field_paths, &fallback_data_source); } + if args.head_only || args.silence { + continue; + } + if args.pretty { if args.plain { info!(" ------------ Row {} ------------\n{}", row_index, protobuf::text_format::print_to_string_pretty(message.as_ref())); @@ -691,7 +706,7 @@ fn main() { } } } - if !args.plain { + if !args.plain && !args.head_only && !args.silence { info!("]"); }