mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 18:24:05 +02:00
more string table tests
This commit is contained in:
parent
a6ba0c20ec
commit
875dc7120c
43 changed files with 190 additions and 4 deletions
|
|
@ -22,7 +22,7 @@ pub struct StringCmdMessage {
|
|||
}
|
||||
|
||||
#[derive(BitRead, BitWrite, Debug, PartialEq)]
|
||||
pub struct SigOnStateMessage {
|
||||
pub struct SignOnStateMessage {
|
||||
pub state: u8,
|
||||
pub count: u32,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ pub enum Message<'a> {
|
|||
NetTick(NetTickMessage),
|
||||
StringCmd(StringCmdMessage),
|
||||
SetConVar(SetConVarMessage),
|
||||
SigOnState(SigOnStateMessage),
|
||||
SigOnState(SignOnStateMessage),
|
||||
Print(PrintMessage),
|
||||
ServerInfo(Box<ServerInfoMessage>),
|
||||
ClassInfo(ClassInfoMessage),
|
||||
|
|
@ -146,7 +146,7 @@ impl<'a> Message<'a> {
|
|||
MessageType::StringCmd => Message::StringCmd(StringCmdMessage::parse(stream, state)?),
|
||||
MessageType::SetConVar => Message::SetConVar(SetConVarMessage::parse(stream, state)?),
|
||||
MessageType::SigOnState => {
|
||||
Message::SigOnState(SigOnStateMessage::parse(stream, state)?)
|
||||
Message::SigOnState(SignOnStateMessage::parse(stream, state)?)
|
||||
}
|
||||
MessageType::Print => Message::Print(PrintMessage::parse(stream, state)?),
|
||||
MessageType::ServerInfo => {
|
||||
|
|
@ -200,7 +200,7 @@ impl<'a> Message<'a> {
|
|||
MessageType::NetTick => NetTickMessage::parse_skip(stream),
|
||||
MessageType::StringCmd => StringCmdMessage::parse_skip(stream),
|
||||
MessageType::SetConVar => SetConVarMessage::parse_skip(stream),
|
||||
MessageType::SigOnState => SigOnStateMessage::parse_skip(stream),
|
||||
MessageType::SigOnState => SignOnStateMessage::parse_skip(stream),
|
||||
MessageType::Print => PrintMessage::parse_skip(stream),
|
||||
MessageType::ServerInfo => ServerInfoMessage::parse_skip(stream),
|
||||
MessageType::ClassInfo => ClassInfoMessage::parse_skip(stream),
|
||||
|
|
|
|||
0
test_data/string_tables/DynamicModels.bin
Normal file
0
test_data/string_tables/DynamicModels.bin
Normal file
8
test_data/string_tables/DynamicModels_meta.json
Normal file
8
test_data/string_tables/DynamicModels_meta.json
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"max_entries": 2048,
|
||||
"fixed_userdata_size": {
|
||||
"size": 1,
|
||||
"bits": 1
|
||||
},
|
||||
"count": 0
|
||||
}
|
||||
0
test_data/string_tables/EffectDispatch.bin
Normal file
0
test_data/string_tables/EffectDispatch.bin
Normal file
5
test_data/string_tables/EffectDispatch_meta.json
Normal file
5
test_data/string_tables/EffectDispatch_meta.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"max_entries": 1024,
|
||||
"fixed_userdata_size": null,
|
||||
"count": 0
|
||||
}
|
||||
BIN
test_data/string_tables/GameRulesCreation.bin
Normal file
BIN
test_data/string_tables/GameRulesCreation.bin
Normal file
Binary file not shown.
5
test_data/string_tables/GameRulesCreation_meta.json
Normal file
5
test_data/string_tables/GameRulesCreation_meta.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"max_entries": 1,
|
||||
"fixed_userdata_size": null,
|
||||
"count": 1
|
||||
}
|
||||
BIN
test_data/string_tables/InfoPanel.bin
Normal file
BIN
test_data/string_tables/InfoPanel.bin
Normal file
Binary file not shown.
5
test_data/string_tables/InfoPanel_meta.json
Normal file
5
test_data/string_tables/InfoPanel_meta.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"max_entries": 128,
|
||||
"fixed_userdata_size": null,
|
||||
"count": 2
|
||||
}
|
||||
BIN
test_data/string_tables/Materials.bin
Normal file
BIN
test_data/string_tables/Materials.bin
Normal file
Binary file not shown.
5
test_data/string_tables/Materials_meta.json
Normal file
5
test_data/string_tables/Materials_meta.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"max_entries": 1024,
|
||||
"fixed_userdata_size": null,
|
||||
"count": 7
|
||||
}
|
||||
BIN
test_data/string_tables/ParticleEffectNames.bin
Normal file
BIN
test_data/string_tables/ParticleEffectNames.bin
Normal file
Binary file not shown.
5
test_data/string_tables/ParticleEffectNames_meta.json
Normal file
5
test_data/string_tables/ParticleEffectNames_meta.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"max_entries": 4096,
|
||||
"fixed_userdata_size": null,
|
||||
"count": 1866
|
||||
}
|
||||
BIN
test_data/string_tables/Scenes.bin
Normal file
BIN
test_data/string_tables/Scenes.bin
Normal file
Binary file not shown.
5
test_data/string_tables/Scenes_meta.json
Normal file
5
test_data/string_tables/Scenes_meta.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"max_entries": 8192,
|
||||
"fixed_userdata_size": null,
|
||||
"count": 3858
|
||||
}
|
||||
BIN
test_data/string_tables/ServerMapCycle.bin
Normal file
BIN
test_data/string_tables/ServerMapCycle.bin
Normal file
Binary file not shown.
BIN
test_data/string_tables/ServerMapCycleMvM.bin
Normal file
BIN
test_data/string_tables/ServerMapCycleMvM.bin
Normal file
Binary file not shown.
5
test_data/string_tables/ServerMapCycleMvM_meta.json
Normal file
5
test_data/string_tables/ServerMapCycleMvM_meta.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"max_entries": 128,
|
||||
"fixed_userdata_size": null,
|
||||
"count": 1
|
||||
}
|
||||
5
test_data/string_tables/ServerMapCycle_meta.json
Normal file
5
test_data/string_tables/ServerMapCycle_meta.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"max_entries": 128,
|
||||
"fixed_userdata_size": null,
|
||||
"count": 1
|
||||
}
|
||||
0
test_data/string_tables/ServerPopFiles.bin
Normal file
0
test_data/string_tables/ServerPopFiles.bin
Normal file
5
test_data/string_tables/ServerPopFiles_meta.json
Normal file
5
test_data/string_tables/ServerPopFiles_meta.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"max_entries": 128,
|
||||
"fixed_userdata_size": null,
|
||||
"count": 0
|
||||
}
|
||||
BIN
test_data/string_tables/VguiScreen.bin
Normal file
BIN
test_data/string_tables/VguiScreen.bin
Normal file
Binary file not shown.
5
test_data/string_tables/VguiScreen_meta.json
Normal file
5
test_data/string_tables/VguiScreen_meta.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"max_entries": 256,
|
||||
"fixed_userdata_size": null,
|
||||
"count": 3
|
||||
}
|
||||
1
test_data/string_tables/decalprecache.bin
Normal file
1
test_data/string_tables/decalprecache.bin
Normal file
|
|
@ -0,0 +1 @@
|
|||
#+c<>{{s<1B>+Ѓ+{<7B>C{Ѓ<>љ<EFBFBD>Ћ<13>+Ѓи<01>љ<EFBFBD>Ћ<13>+Ѓи<01>љ<EFBFBD>Ћ<13>+ЃиЅљ<D085>Ћ<13>+Ѓиљ<C2AD>Ћ<13>+ЃиСi+Ѓc{<7B>C{Ѓ<>љ<EFBFBD>Ћ<13>+ЃиK<D0B8>љ<EFBFBD>Ћ<13>+ЃиK<D0B8>љ<EFBFBD>Ћ<13>+ЃиKЄљ<D084>Ћ<13>+ЃиKЌљ<D08C>Ћ<13>+ЃиСЙ{{#{<7B>C{Ѓ<>љ<EFBFBD>Ћ<13>+Ѓи<15>љ<EFBFBD>Ћ<13>+Ѓи<15>љ<EFBFBD>Ћ<13>+ЃиЄљ<D084>Ћ<13>+ЃиЌљ<D08C>Ћ<13>+ЃиС9c<0B><>{<7B>C{Ѓ<>љ<EFBFBD>Ћ<13>+Ѓи_<D0B8>љ<EFBFBD>Ћ<13>+Ѓи_<D0B8>љ<EFBFBD>Ћ<13>+Ѓи_Єљ<D084>Ћ<13>+Ѓи_Ќљ<D08C>Ћ<13>+ЃиС1c+<2B>C{c{{#<23>љ<EFBFBD>Ћ<13>+ЃиЉ<D0B8>љ<EFBFBD>Ћ<13>+ЃиЉ<D0B8>љ<EFB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иj<>{<7B>C<>љ<EFBFBD>Ћ<13>+Ѓиџ<D0B8>љ<EFBFBD>Ћ<13>+Ѓи§<D0B8>љ<EFBFBD>Ћ<13>+ЃиU3#+ћ<>Ћ<13>+ЃиС{s<1B>+Ѓ+{<7B>C{Ѓ<>и?<3F>и=<3D>и;Ѕи9иСi+Ѓc{<7B>C{Ѓ<>и<D0B8>и}<7D>и{ЄиyЌиСЙ{{#{<7B>C{Ѓ<>и?<3F>и=<3D>и;Єи9ЌиС9c<0B><>{<7B>C{Ѓ<>и<D0B8>и}<7D>и{ЄиyЌиС1c+<2B>C{c{{#<23>иП<D0B8>иН<D0B8>иЛЄиЙЌиb{{#Ы3c+<2B>C{c{{#<23>и?<3F>и=<3D>и;Іи9ЎиC<D0B8>иA<D0B8>и3<D0B8>и1<D0B8>и/<2F>и-Ѓи+Ћи)Ги'Ли%Уи#<23>+[<5B>и?<3F>и=<3D>иJ;<3B>C{Ѓ<>иП<D0B8>иН<D0B8>иЛЃиЙЋи<13><>{{3<>иj<>{<7B>C<>иџ<D0B8>и§<D0B8>иU3#+иС!K<>Ѓ<EFBFBD>C{Ѓ<>иџ<D0B8>и§<D0B8>ићЃихk{#+cихk{#+cихk{#+cихk{#+cихk{#+cиЅk{#+cиSk{#+cиSk{#+cиSk{#+cиe<D0B8>i{#+cиc<D0B8>i{#+cиal{#+cиl{#+cиl{#+cиl{#+c
|
||||
8
test_data/string_tables/decalprecache_meta.json
Normal file
8
test_data/string_tables/decalprecache_meta.json
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"max_entries": 512,
|
||||
"fixed_userdata_size": {
|
||||
"size": 1,
|
||||
"bits": 2
|
||||
},
|
||||
"count": 133
|
||||
}
|
||||
BIN
test_data/string_tables/downloadables.bin
Normal file
BIN
test_data/string_tables/downloadables.bin
Normal file
Binary file not shown.
5
test_data/string_tables/downloadables_meta.json
Normal file
5
test_data/string_tables/downloadables_meta.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"max_entries": 8192,
|
||||
"fixed_userdata_size": null,
|
||||
"count": 1
|
||||
}
|
||||
1
test_data/string_tables/genericprecache.bin
Normal file
1
test_data/string_tables/genericprecache.bin
Normal file
|
|
@ -0,0 +1 @@
|
|||
|
||||
8
test_data/string_tables/genericprecache_meta.json
Normal file
8
test_data/string_tables/genericprecache_meta.json
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"max_entries": 512,
|
||||
"fixed_userdata_size": {
|
||||
"size": 1,
|
||||
"bits": 2
|
||||
},
|
||||
"count": 1
|
||||
}
|
||||
BIN
test_data/string_tables/instancebaseline.bin
Normal file
BIN
test_data/string_tables/instancebaseline.bin
Normal file
Binary file not shown.
5
test_data/string_tables/instancebaseline_meta.json
Normal file
5
test_data/string_tables/instancebaseline_meta.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"max_entries": 1024,
|
||||
"fixed_userdata_size": null,
|
||||
"count": 29
|
||||
}
|
||||
BIN
test_data/string_tables/lightstyles.bin
Normal file
BIN
test_data/string_tables/lightstyles.bin
Normal file
Binary file not shown.
5
test_data/string_tables/lightstyles_meta.json
Normal file
5
test_data/string_tables/lightstyles_meta.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"max_entries": 64,
|
||||
"fixed_userdata_size": null,
|
||||
"count": 64
|
||||
}
|
||||
BIN
test_data/string_tables/modelprecache.bin
Normal file
BIN
test_data/string_tables/modelprecache.bin
Normal file
Binary file not shown.
8
test_data/string_tables/modelprecache_meta.json
Normal file
8
test_data/string_tables/modelprecache_meta.json
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"max_entries": 4096,
|
||||
"fixed_userdata_size": {
|
||||
"size": 1,
|
||||
"bits": 2
|
||||
},
|
||||
"count": 780
|
||||
}
|
||||
BIN
test_data/string_tables/server_query_info.bin
Normal file
BIN
test_data/string_tables/server_query_info.bin
Normal file
Binary file not shown.
5
test_data/string_tables/server_query_info_meta.json
Normal file
5
test_data/string_tables/server_query_info_meta.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"max_entries": 4,
|
||||
"fixed_userdata_size": null,
|
||||
"count": 2
|
||||
}
|
||||
BIN
test_data/string_tables/soundprecache.bin
Normal file
BIN
test_data/string_tables/soundprecache.bin
Normal file
Binary file not shown.
8
test_data/string_tables/soundprecache_meta.json
Normal file
8
test_data/string_tables/soundprecache_meta.json
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"max_entries": 16384,
|
||||
"fixed_userdata_size": {
|
||||
"size": 1,
|
||||
"bits": 2
|
||||
},
|
||||
"count": 5362
|
||||
}
|
||||
BIN
test_data/string_tables/userinfo.bin
Normal file
BIN
test_data/string_tables/userinfo.bin
Normal file
Binary file not shown.
5
test_data/string_tables/userinfo_meta.json
Normal file
5
test_data/string_tables/userinfo_meta.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"max_entries": 256,
|
||||
"fixed_userdata_size": null,
|
||||
"count": 24
|
||||
}
|
||||
69
tests/stringtable.rs
Normal file
69
tests/stringtable.rs
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
use bitbuffer::{BitReadBuffer, BitReadStream, BitWriteStream, LittleEndian};
|
||||
use std::fs;
|
||||
use test_case::test_case;
|
||||
use tf_demo_parser::demo::message::stringtable::{
|
||||
parse_string_table_list, write_string_table_list, StringTableMeta,
|
||||
};
|
||||
use tf_demo_parser::demo::packet::stringtable::FixedUserDataSize;
|
||||
|
||||
#[test_case("test_data/string_tables/decalprecache.bin", "test_data/string_tables/decalprecache_meta.json"; "decalprecache")]
|
||||
#[test_case("test_data/string_tables/downloadables.bin", "test_data/string_tables/downloadables_meta.json"; "downloadables")]
|
||||
#[test_case("test_data/string_tables/DynamicModels.bin", "test_data/string_tables/DynamicModels_meta.json"; "DynamicModels")]
|
||||
#[test_case("test_data/string_tables/EffectDispatch.bin", "test_data/string_tables/EffectDispatch_meta.json"; "EffectDispatch")]
|
||||
#[test_case("test_data/string_tables/GameRulesCreation.bin", "test_data/string_tables/GameRulesCreation_meta.json"; "GameRulesCreation")]
|
||||
#[test_case("test_data/string_tables/genericprecache.bin", "test_data/string_tables/genericprecache_meta.json"; "genericprecache")]
|
||||
#[test_case("test_data/string_tables/InfoPanel.bin", "test_data/string_tables/InfoPanel_meta.json"; "InfoPanel")]
|
||||
// #[test_case("test_data/string_tables/instancebaseline.bin", "test_data/string_tables/instancebaseline_meta.json"; "instancebaseline")]
|
||||
#[test_case("test_data/string_tables/lightstyles.bin", "test_data/string_tables/lightstyles_meta.json"; "lightstyles")]
|
||||
#[test_case("test_data/string_tables/Materials.bin", "test_data/string_tables/Materials_meta.json"; "Materials")]
|
||||
#[test_case("test_data/string_tables/modelprecache.bin", "test_data/string_tables/modelprecache_meta.json"; "modelprecache")]
|
||||
#[test_case("test_data/string_tables/ParticleEffectNames.bin", "test_data/string_tables/ParticleEffectNames_meta.json"; "ParticleEffectNames")]
|
||||
// #[test_case("test_data/string_tables/Scenes.bin", "test_data/string_tables/Scenes_meta.json"; "Scenes")]
|
||||
#[test_case("test_data/string_tables/server_query_info.bin", "test_data/string_tables/server_query_info_meta.json"; "server_query_info")]
|
||||
#[test_case("test_data/string_tables/ServerMapCycle.bin", "test_data/string_tables/ServerMapCycle_meta.json"; "ServerMapCycle")]
|
||||
#[test_case("test_data/string_tables/ServerMapCycleMvM.bin", "test_data/string_tables/ServerMapCycleMvM_meta.json"; "ServerMapCycleMvM")]
|
||||
#[test_case("test_data/string_tables/ServerPopFiles.bin", "test_data/string_tables/ServerPopFiles_meta.json"; "ServerPopFiles")]
|
||||
#[test_case("test_data/string_tables/soundprecache.bin", "test_data/string_tables/soundprecache_meta.json"; "soundprecache")]
|
||||
#[test_case("test_data/string_tables/userinfo.bin", "test_data/string_tables/userinfo_meta.json"; "userinfo")]
|
||||
#[test_case("test_data/string_tables/VguiScreen.bin", "test_data/string_tables/VguiScreen_meta.json"; "VguiScreen")]
|
||||
fn string_table_reencode(input_file: &str, meta_file: &str) {
|
||||
let data = fs::read(input_file).unwrap();
|
||||
let meta: serde_json::Value =
|
||||
serde_json::from_str(&fs::read_to_string(meta_file).unwrap()).unwrap();
|
||||
let count = meta["count"].as_u64().unwrap() as u16;
|
||||
let max_entries = meta["max_entries"].as_u64().unwrap();
|
||||
let fixed_userdata_size =
|
||||
meta["fixed_userdata_size"]
|
||||
.as_object()
|
||||
.map(|size| FixedUserDataSize {
|
||||
size: size["size"].as_u64().unwrap() as u16,
|
||||
bits: size["bits"].as_u64().unwrap() as u8,
|
||||
});
|
||||
let table_meta = StringTableMeta {
|
||||
max_entries: max_entries as u16,
|
||||
fixed_userdata_size,
|
||||
};
|
||||
let mut stream = BitReadStream::new(BitReadBuffer::new(&data, LittleEndian));
|
||||
let parsed = parse_string_table_list(&mut stream, &table_meta, count).unwrap();
|
||||
|
||||
let mut out = Vec::with_capacity(data.len());
|
||||
let written_bits = {
|
||||
let mut write = BitWriteStream::new(&mut out, LittleEndian);
|
||||
write_string_table_list(&parsed, &mut write, &table_meta).unwrap();
|
||||
write.bit_len()
|
||||
};
|
||||
|
||||
let mut re_stream = BitReadStream::new(BitReadBuffer::new(&out, LittleEndian));
|
||||
let re_parsed = parse_string_table_list(&mut re_stream, &table_meta, count).unwrap();
|
||||
|
||||
assert_eq!(written_bits, stream.pos());
|
||||
assert_eq!(parsed, re_parsed);
|
||||
|
||||
assert_eq!(data.len(), out.len());
|
||||
if data.len() > 16 {
|
||||
pretty_assertions::assert_eq!(&data[0..data.len() - 8], &out[0..out.len() - 8]);
|
||||
pretty_assertions::assert_eq!(&data[data.len() - 8..], &out[out.len() - 8..]);
|
||||
} else {
|
||||
pretty_assertions::assert_eq!(data, out);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue