Skip to content

Replay reader doesn't handle header changes #3038

@sprunk

Description

@sprunk

Replay reader reads the hardcoded struct layout and assumes that the startscript is directly behind it:

var header = br.ReadStruct<DemoFileHeader>();
var script = Encoding.UTF8.GetString(br.ReadBytes(header.scriptSize));

If engine adds new members to the struct (planned in the near-ish future) then this will break. The header contains a headerSize member to solve this though (and a version member in the stronger case when members get added anywhere else than at the end):

public int headerSize; // Size of the DemoFileHeader, minor version number.

So there should be something like

 var header = br.ReadStruct<DemoFileHeader>();
 
+if (header.version != 5)
+  throw new NotSupportedException();
+
+const var expectedSize = Marshal.SizeOf(header);
+if (header.headerSize > expectedSize)
+  br.ReadBytes(header.headerSize - expectedSize);

 var script = Encoding.UTF8.GetString(br.ReadBytes(header.scriptSize));

Metadata

Metadata

Assignees

No one assigned

    Labels

    lowpriorityA task that can wait, possibly a large one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions