Crates.io | wot_replay_parser |
lib.rs | wot_replay_parser |
version | 0.2.2 |
source | src |
created_at | 2022-11-08 08:50:07.100616 |
updated_at | 2022-12-04 10:12:02.629989 |
description | A parser for `.wotreplay` files generated by the game World of Tanks |
homepage | |
repository | https://github.com/dacite/wot-battle-results-parser |
max_upload_size | |
id | 707889 |
size | 9,760,525 |
This project aims to parse World of Tanks battle results from two sources:
.dat
files from World of Tanks cache folder (Currently outdated).wotreplay
files from the game directoryCurrently I am making major changes to this repo and is therefore a work in progress
A .wotreplay
file contains two sections:
This project can parse both sections. However, most of the code if focused on trying to extract useful information from the Binary section.
1.15.0
- 1.17.0
Backwards compatibility is not guaranteed for the Datfile parser. This is not very important anyway since these files don't persist indefintely like .wotreplay
files do.
0.9.13
- 1.18.1
One of the big goals of this project is to parse as many replay versions as possible. However, as this project is still a work in progress, the kind of information that you can get from each replay differs based on the replay version.
For example, the Position
information of each tank have barely changed over
the years and therefore will probably work with all replays from 0.9.13
to today whereas something like OnStaticCollision
(a tank colliding with a fence for ex.) has changed quite frequently and require more inspection. While this is not easy to do,
the great thing is that there is a mechanism in place (see here) that let's us quickly make the necessary changes to support more versions.
Currently this project is only available as Rust library. Perhaps in the future, we can provide Python bindings. To use it, add the following to the [dependencies]
section of Cargo.toml
wot_replay_parser = "0.2.1"
use wot_replay_parser::ReplayParser;
pub fn main() {
let path = "/home/dacite/Projects/wot-battle-results-parser/examples/example.wotreplay";
// ReplayParser can take a path or Vec<u8>
let replay_parser = ReplayParser::parse_file(path).unwrap();
// replay_json_start return serde_json::Value type
let replay_json_start = replay_parser.replay_json_start().unwrap();
let json_string_start = serde_json::to_string_pretty(&replay_json_start).unwrap();
// This portion is only available for complete replays (i.e the player watched the battle to the end)
let replay_json_end = replay_parser.replay_json_end().unwrap();
let json_string_end = serde_json::to_string_pretty(&replay_json_end).unwrap();
println!("{}", json_string_start);
println!("{}", json_string_end);
// There are some other methods readily available as well. See docs.rs page for information
println!(
"Replay Version: {:?}",
replay_parser.parse_replay_version().unwrap()
);
}
The binary section of the replay can be separated into "packets". Each packet has some metadata information and then the payload. This is useful if you are developing another projects that needs the packet abstraction.
I used this to create https://dacite.github.io/wot-packet-analyzer. This is a GUI for analyzing packets and finding out what they mean. Useful as a development tool.
use wot_replay_parser::ReplayParser;
pub fn main() {
let path = "/home/dacite/Projects/wot-battle-results-parser/examples/example.wotreplay";
// ReplayParser can take a path or Vec<u8>
let replay_parser = ReplayParser::parse_file(path).unwrap();
for packet in replay_parser.packet_stream() {
let packet = packet.unwrap();
// This will print out the metadata information of the packet
println!("{:?}", packet);
// Adding the plus sign will print out the payload information
println!("{:+?}", packet);
}
}
This is where most of the work is left to do. Events is an abstraction over packets. i.e it shows the actual
data that is present in a packet. Some events such as Position
,AvatarCreate
works really well as of today.
See BattleEvent
to see what kind
of events are supported. Not that this doesn't mean it will work in all replays
use wot_replay_parser::{ReplayParser, BattleEvent};
pub fn main() {
let path = "/home/dacite/Projects/wot-battle-results-parser/examples/example.wotreplay";
// ReplayParser can take a path or Vec<u8>
let replay_parser = ReplayParser::parse_file(path).unwrap();
for event in replay_parser.event_stream().unwrap() {
let event = event.unwrap();
// This will print out the event if is a chat event (Ofcourse, you can print out all event types if needed)
if let BattleEvent::Chat(chat_event) = event {
// Print out the event
println!("{:?}", chat_event);
// You can also convert these events to any format supported by serde . Here is an example
// where it is converted to JSON
println!("{}", serde_json::to_string_pretty(&chat_event).unwrap());
}
}
}
See the docs.rs link for more thorough documentation: https://docs.rs/wot_replay_parser/latest/wot_replay_parser
.wotreplay
files. Useful for developmentwot_replay_parser
libraryBackwards compatibility is not guaranteed for the Datfile parser. This is not very important anyway since these files don't persist indefintely like .wotreplay
files do.
.def
files comes from here