Skip to content

Commit

Permalink
Add --head-only and --silence
Browse files Browse the repository at this point in the history
  • Loading branch information
owent committed Aug 26, 2023
1 parent 0787811 commit 10f4c7b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 26 deletions.
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ You can use environment `RUST_LOG=<level>` 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},
Expand All @@ -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
2 changes: 1 addition & 1 deletion src/exec/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xresloader-dump-bin"
version = "2.2.0"
version = "2.2.1"
authors = ["owent <admin@owent.net>"]
license = "MIT"
description = "A tool to dump human readable text from binary output of xresloader"
Expand Down
61 changes: 38 additions & 23 deletions src/exec/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,

/// 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<String>,

Expand All @@ -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,
Expand All @@ -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<String>,

/// 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<String>,

/// 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<String>,

Expand Down Expand Up @@ -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);
}
}
}

Expand All @@ -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<StringTableContent> = None;
Expand Down Expand Up @@ -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()));
Expand Down Expand Up @@ -691,7 +706,7 @@ fn main() {
}
}
}
if !args.plain {
if !args.plain && !args.head_only && !args.silence {
info!("]");
}

Expand Down

0 comments on commit 10f4c7b

Please sign in to comment.