blixt / py-starbound

Python package for working with Starbound files.
MIT License
104 stars 22 forks source link

Possible explanation of "magic byte" in SBVJ01 files #32

Closed katanacrimson closed 7 years ago

katanacrimson commented 7 years ago

Per Kawa in the Starbound Discord, 0x01 is used if the SBVJ01 file is versioned. If it isn't versioned, it'll be 0x00 and will skip the Int32 field for the entity version, immediately going straight to the entity data itself (the SBON dynamic type structure).

Needs to be verified, but if this is the case, that's more for the formats file.

blixt commented 7 years ago

Cool! Thank you for the update. I haven't encountered any files that don't have the flag set, but if they exist, they'd probably read as corrupted files so fixing this is important (assuming we can verify it).

katanacrimson commented 7 years ago

I believe Kawa was trying to load SBVJ01 files in SB directly a bit ago - some logs:

katana - Today at 1:15 PM @ Kawa-oneechan about the sbvj01 magic byte - anything sb ships with or makes that it can be verified with? Kawa-oneechan - Today at 1:16 PM That's six magic bytes, silly. katana - Today at 1:16 PM trying to justify changes in a couple other language libraries for it I'm talking about the 0x00/0x01 Kawa-oneechan - Today at 1:16 PM Which one? katana - Today at 1:16 PM the versioning toggle Kawa-oneechan - Today at 1:16 PM Ah. I'll check. I have a piece of code from Kyren around here... No wait that's paks. Other source Actually, let's just try it. katana - Today at 1:21 PM ooh, yes, the Leeroy verification method. Kawa-oneechan - Today at 1:22 PM Test 1: use 0x02, with version u32 katana - Today at 1:22 PM :D Kawa-oneechan - Today at 1:22 PM 0x02 with version stamp: WORKS 0x04 also works. PParrot - Today at 1:23 PM does 0xff work? Kawa-oneechan - Today at 1:23 PM Nonzero, no stamp: root object is mistaken for stamp, content is null. @PParrot: with or without a version u32? PParrot - Today at 1:24 PM with Kawa-oneechan - Today at 1:24 PM Yes.

Might be able to use the same method to verify, though; I've got my hands full on trying to get SBAsset6 write support implemented in js-starbound, so if you'd like to take a shot, @blixt - be my guest.

Kawa-oneechan commented 7 years ago

Hi~

I'd like to elaborate that when I wrote my webpage on the format of SBVJ files, I had assistance from Kyren herself on matters like the versioning flag. And to restate the Discord log in clearer terms, 0x00 means unversioned, any other value means versioned, and if it's unversioned there is no version # u32.

blixt commented 7 years ago

@Kawa-oneechan @damianb Thank you for the additional information! I'll assume this is the case and update the document and code (obviously no one knows better than Kyren. :)

I was just a bit confused since I would have expected the notion of "no version" to either just be version 0, or a magic constant (e.g., -1 or MAX_INT) as opposed to an additional byte.

If you guys ever talk to the Starbound team I would appreciate if you asked them to help us fill out some more blanks in the FORMATS doc, as it's starting to get pretty complete now. :)