Skip to content

BMG - #39

Open
Fl-ppie wants to merge 12 commits into
Demorck:masterfrom
Fl-ppie:BMG
Open

BMG#39
Fl-ppie wants to merge 12 commits into
Demorck:masterfrom
Fl-ppie:BMG

Conversation

@Fl-ppie

@Fl-ppie Fl-ppie commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

This is the correct BMG PR. For some reason the original one doesn't behave. I probably messed something up

@Fl-ppie Fl-ppie mentioned this pull request Jul 30, 2026
Closed
@Demorck
Demorck self-requested a review July 31, 2026 00:37
@Demorck Demorck added file format Changes, adding something about files format core Affect the core of wiithon tests Adding, changing or removing tests (unit or not) labels Jul 31, 2026
@Demorck Demorck added this to Wiithon Jul 31, 2026
@Demorck Demorck added this to the 0.2.0 milestone Jul 31, 2026
@github-project-automation github-project-automation Bot moved this to Public in Wiithon Jul 31, 2026
@Demorck

Demorck commented Aug 3, 2026

Copy link
Copy Markdown
Owner

You also need to add tests for everyfile and BMG.
Every tests will minimum have roundtrip and need to covers a lot of stuff

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 you do not know what is it:
read(write(read(x))) = x
read -> write -> read produces the same result

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)

@Demorck Demorck Jul 31, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove assert, throw exception instead

assert data_magic == DATA_MAGIC

file_magic = reader.string(0x4)
assert file_magic == FILE_MAGIC

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assert -> exceptions

if entries == None:
entries = []

self.entry_count = len(entries)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


entry_count = reader.u16()
entry_size = reader.u8()
reader.skip(0x1)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You missed 4 bytes of padding here

entry_size = reader.u8()
reader.skip(0x1)

assert entry_size == cls.entry_size

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert

self.entry_count = len(self.entries)
writer.u16(self.entry_count)
writer.u8(self.entry_size)
writer.seek(0x8)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.pad


for entry in self.entries:
entry_data = entry.export_entry()
writer.raw(entry_data.read)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.getvalue()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Affect the core of wiithon file format Changes, adding something about files format tests Adding, changing or removing tests (unit or not)

Projects

Status: Public

Development

Successfully merging this pull request may close these issues.

2 participants