LogicAndTrick / sledge-formats

C# parsers and formats for Half-Life 1 and related engines.
MIT License
71 stars 10 forks source link

Entities lump does not write null terminator #7

Closed SamVanheer closed 2 years ago

SamVanheer commented 2 years ago

When the Entities lump writes the entity data string to the stream it writes the string but it doesn't append a null terminator: https://github.com/LogicAndTrick/sledge-formats/blob/0e8ea2ad1a695993053dcac163dc6af0fae7ae5c/Sledge.Formats.Bsp/Lumps/Entities.cs#L155

In most cases there will be a null byte right after the entities lump, but in some cases such as c1a2c this will not be the case. The engine will continue to parse data past the entity data string and will fail to read a { character, causing a Host_Error: ED_LoadFromFile: found � when expecting { error.

Although the engine does copy the string before parsing it, the lack of null terminator in the file itself seems to consistently affect parsing as well.

Comparing the bsp file before and after modification shows the entities lump is shorter by one byte.

Adding this after the string is written should fix this problem:

bw.Write((byte)0);