wfowler1 / LibBSP

C# library for parsing and reading BSP (Binary Space Partition) structures in Quake-based game engines
Other
93 stars 26 forks source link

Writing BSP corrupts game lump #8

Closed Mooshua closed 1 year ago

Mooshua commented 1 year ago

Issue When saving a BSP that contains static props and launching it with CS:GO, static props present in the original BSP no longer render. Occurs even when LibBSP performs no mutation

Reproduction

Possible cause The valve developer wiki contains this note:

Note that fileofs is relative to the beginning of the BSP file, not to the game lump offset.

This value does not appear to be patched to the new location of the static prop lump.

wfowler1 commented 1 year ago

D'oh, it figures I'd miss something stupid like this. It's hard to test every single thing for so many different games. I made sure to account for the offset thing in GameLump.cs on line 307, it's possible it's not working correctly. But I think it's more likely that static props are being written in the wrong format. I'm a little surprised the game wouldn't outright crash if that were the case, though. I'll have to do some comparisons.

These static prop lumps are such a pain.

Mooshua commented 1 year ago

I think your fix would work if lumps were serialized in the same order as they were serialized in the BSP, but if the lumpinfo becomes inaccurate then that means this will too.

I am also surprised it isn't crashing the game

But I think it's more likely that static props are being written in the wrong format.

I disagree. I used VIDE to extract the lumps and the only difference between a working game lump and a bad one is the offset in each gamelump's header.

Mooshua commented 1 year ago

Hi--I got this working on a local fork. It's super messy and I'm not sure you will like it, but it should give starting point:

Approximate changes:

This probably could have been fixed better by simply modifying the LumpInfo field for each lump to match the new lump location during the write.

Hope this helps. Good luck!

wfowler1 commented 1 year ago

Interesting. I haven't had the chance to look at it yet, hopefully I can dig deeper soon.

wfowler1 commented 1 year ago

Ok I've got my solution in place, it's probably similar to what you've got. Let me know how this goes.