saul / demofile-net

Blazing fast cross-platform demo parser library for Counter-Strike 2, written in C#.
MIT License
76 stars 7 forks source link

Fix ReadUBits(32) masking out all bits. Thanks to @in0finite #56

Closed saul closed 2 months ago

saul commented 2 months ago

Fixes #37

github-actions[bot] commented 2 months ago

BenchmarkDotNet v0.13.9+228a464e8be6c580ad9408e98f18813f6407fb5a, Ubuntu 22.04.4 LTS (Jammy Jellyfish)
AMD EPYC 7763, 1 CPU, 4 logical and 2 physical cores
.NET SDK 8.0.203
  [Host]     : .NET 8.0.3 (8.0.324.11423), X64 RyuJIT AVX2
  Job-IGJYAE : .NET 8.0.3 (8.0.324.11423), X64 RyuJIT AVX2
  Job-FVCKUP : .NET 8.0.3 (8.0.324.11423), X64 RyuJIT AVX2

InvocationCount=1  MaxIterationCount=16  UnrollFactor=1  
WarmupCount=1  
Method Job Arguments Mean Error StdDev Ratio Gen0 Gen1 Allocated Alloc Ratio
ParseDemo Job-IGJYAE /p:Baseline=true 2.263 s 0.0115 s 0.0096 s 1.00 5000.0000 2000.0000 489.9 MB 1.00
ParseDemo Job-FVCKUP Default 2.207 s 0.0241 s 0.0226 s 0.97 5000.0000 2000.0000 489.9 MB 1.00
in0finite commented 2 months ago

Could you also add a safeguard after reading all entities from BitBuffer here, to make sure everything is read from it:

if (entityBitBuffer.RemainingBytes >= 4)
    throw "not all data read";