BMG - #39
Conversation
BMG is a binary message data file used for the text
|
You also need to add tests for everyfile and BMG. It's impossible to write perfect and exhaustive tests (see the reader one, i forgot 2 bytes encoded characters) but at least roundtrip. It's the most important. If it's impossible because of some garbage padding data, you also can do roundtrip by object (like every fields need to have the same value) |
| def seek(self, offset: int) -> None: | ||
| self.stream.seek(offset) | ||
| def seek(self, offset: int) -> int: | ||
| return self.stream.seek(offset) |
There was a problem hiding this comment.
You never use the seek return value, remove it from the PR
| def skip(self, count: int) -> None: | ||
| self.stream.read(count) | ||
|
|
||
| def back(self, count: int) -> int: |
There was a problem hiding this comment.
You are using it one time and it's for backing and reread node size. You could read node_size and getting the type from the node_byte.
And it clamp when at 0 without any errors
Remove it from the PR
| section_count: int | ||
| sections: list[BMGSection] | ||
|
|
||
| def __init__(self, raw_bytes: BinaryIO): |
There was a problem hiding this comment.
The init need to have a "empty" body just to initalize fields. All the reading stuff goes to a read method with @classmethod decorator
| def __init__(self, raw_bytes: BinaryIO): | ||
| reader = BinaryReader(raw_bytes) | ||
| data_magic = reader.string(0x4) | ||
| assert data_magic == DATA_MAGIC |
There was a problem hiding this comment.
Remove assert, throw exception instead
| assert data_magic == DATA_MAGIC | ||
|
|
||
| file_magic = reader.string(0x4) | ||
| assert file_magic == FILE_MAGIC |
| if entries == None: | ||
| entries = [] | ||
|
|
||
| self.entry_count = len(entries) |
|
|
||
| entry_count = reader.u16() | ||
| entry_size = reader.u8() | ||
| reader.skip(0x1) |
There was a problem hiding this comment.
You missed 4 bytes of padding here
| entry_size = reader.u8() | ||
| reader.skip(0x1) | ||
|
|
||
| assert entry_size == cls.entry_size |
| self.entry_count = len(self.entries) | ||
| writer.u16(self.entry_count) | ||
| writer.u8(self.entry_size) | ||
| writer.seek(0x8) |
|
|
||
| for entry in self.entries: | ||
| entry_data = entry.export_entry() | ||
| writer.raw(entry_data.read) |
This is the correct
BMGPR. For some reason the original one doesn't behave. I probably messed something up