3 个不稳定版本
0.2.2 | 2022年12月4日 |
---|---|
0.2.1 | 2022年11月10日 |
0.2.0 |
|
0.1.0 | 2022年11月8日 |
#1754 在 解析器实现
3MB
2K SLoC
坦克世界战斗结果解析器
文档正在建设中
本项目旨在从两个来源解析《坦克世界》战斗结果
.dat
文件,来自《坦克世界》缓存文件夹(目前已过时).wotreplay
文件,来自游戏目录
目前我正在对这个仓库进行重大更改,因此这是一个正在进行中的项目
Wot Replay Parser
.wotreplay
文件包含两个部分
- JSON部分:包含显示战斗结果时使用的信息
- 二进制部分:包含使用Wot客户端播放回放时使用的信息
本项目可以解析这两个部分。然而,大部分代码都集中在尝试从二进制部分提取有用信息。
支持的《坦克世界》版本
Datfile 解析器
1.15.0
-1.17.0
Datfile解析器的向后兼容性无法保证。这并不重要,因为这些文件不像.wotreplay
文件那样永久存在。
回放解析器
0.9.13
-1.18.1
本项目的一个主要目标是解析尽可能多的回放版本。然而,由于本项目仍在进行中,您可以从每个回放中获得的信息类型取决于回放版本。
例如,每辆坦克的Position
信息在过去的几年中几乎没有变化,因此可能会与从0.9.13
到今天的所有回放一起工作,而像OnStaticCollision
(例如坦克撞上栅栏)这样的信息则经常变化,需要更多的检查。虽然这并不容易做到,但好处是有一个机制可以快速进行必要的更改以支持更多版本(请参阅此处)。
示例用法
回放解析器
目前,此项目仅作为Rust库提供。也许将来,我们可以提供Python绑定。要使用它,请将以下内容添加到 [dependencies]
部分 Cargo.toml
wot_replay_parser = "0.2.1"
示例1:打印回放中的JSON部分
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()
);
}
示例2:以数据包的形式打印回放的二进制部分
回放的二进制部分可以分解为“数据包”。每个数据包包含一些元数据信息和负载。如果您正在开发需要数据包抽象的其他项目,这将很有用。
我使用它创建了 https://dacite.github.io/wot-packet-analyzer。这是一个分析数据包并了解它们含义的图形用户界面。作为一个开发工具很有用。
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);
}
}
示例3:打印回放的事件
这里还剩下大部分工作要做。事件是数据包的抽象。即它显示了数据包中实际存在的数据。一些事件如 Position
、AvatarCreate
到目前为止工作得很好。
查看 BattleEvent
了解支持的事件类型。请注意,这并不意味着它将在所有回放中都工作
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());
}
}
}
查看docs.rs链接获取更详细的文档:https://docs.rs/wot_replay_parser/latest/wot_replay_parser
使用此库的项目
- Wot Packet Analyzer: https://dacite.github.io/wot-packet-analyzer
- 一个用于分析
.wotreplay
文件中数据包的分析器。对开发很有用 - 使用
wot_replay_parser
库
- 一个用于分析
向后兼容性
Dat文件解析器
Datfile解析器的向后兼容性无法保证。这并不重要,因为这些文件不像.wotreplay
文件那样永久存在。
致谢
- https://github.com/Monstrofil/replays_unpack
.def
文件中的所有内容均来自这里
- https://github.com/lkolbly/wows-replays
- https://github.com/StranikS-Scan/WorldOfTanks-Decompiled
- 使跟踪更新中的更改变得非常容易!
- https://github.com/Phalynx/WoT-Replay-To-JSON
- https://github.com/evido/wotreplay-parser
- 为 vbAddict Wiki 做出贡献的人
- http://forum.worldoftanks.eu/index.php?/topic/185348-11011-wot-replay-analyzer-wip-1-08112020/
依赖项
~7MB
~137K SLoC