Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BMSSTOC (Sound TOC) #206

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

steven11sjf
Copy link
Contributor

  • contains helper data for the BFSAR about wave archives, sound streams, and groups
  • added some hashes from BFSAR

Copy link

codecov bot commented Aug 5, 2024

Codecov Report

Attention: Patch coverage is 96.29630% with 1 line in your changes missing coverage. Please review.

Project coverage is 76.47%. Comparing base (ef9f5ad) to head (731598a).

Files with missing lines Patch % Lines
.../mercury_engine_data_structures/formats/bmsstoc.py 96.15% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #206      +/-   ##
==========================================
+ Coverage   76.33%   76.47%   +0.14%     
==========================================
  Files          78       79       +1     
  Lines        3782     3809      +27     
==========================================
+ Hits         2887     2913      +26     
- Misses        895      896       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

"file_id" / FileId,
"warc_index" / Int32ul, # index of the WARC listed in BFSAR
"idx" / Int32ul, # 0 to max wave archives
Check(construct.this._index == construct.this.idx),
Copy link
Contributor

Choose a reason for hiding this comment

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

these Check calls suggest the index fields ought to be in a Rebuild

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should i keep the check and just add a rebuild? or solely rely on the rebuild?


FileId = Struct(
"file_idx" / Int24ul,
"file_type" / construct.Enum(Byte, sound=1, soundgroup=2, bank=3, player=4, wavearchive=5, group=6),
Copy link
Contributor

Choose a reason for hiding this comment

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

as a rule of thumb, always make an Enum class for use with construct.Enum

"wav_name" / PropertyEnum,
"file_id" / FileId,
"warc_index" / Int32ul, # index of the WARC listed in BFSAR
"idx" / Int32ul, # 0 to max wave archives
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand this comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not quite sure the best way to write it but in the BFSAR all sounds have a "global" index which is warc_index (like, sounds are numbered 0 - (N-1) and wave archives are N - N+len(WArc). and the idx field is the same but starts from 0.

"file_size" / Int32ul, # == length of romfs:/packs/sounds/<group>.bfgrp
Const(0, Int64ul),
"group" / PaddedString(0x80, "ascii"),
"_size" / Rebuild(Int32ul, lambda ctx: len(ctx.wavs)),
Copy link
Contributor

Choose a reason for hiding this comment

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

if this is a length/count, don't call it a size

"group" / PaddedString(0x80, "ascii"),
"_size" / Rebuild(Int32ul, lambda ctx: len(ctx.wavs)),
Const(0, Int32ul),
Const(b"\x0D\xF0\xAD\xBA" * 4), # 16B of BAADF00D magic from heap alloc
Copy link
Contributor

Choose a reason for hiding this comment

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

does Const(0xBAADF00D)[4] work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, closest i can get is twoConst(0xBAADF00DBAADF00D, Int64ul) calls. You need to specify the FormatField when you do it that way and it throws an error when making a Const an array
image

BMSSTOC = Struct(
"wave_archives" / PrefixedArray(Int32ul, WaveArchiveData),
"sound_streams" / PrefixedArray(Int32ul, SoundStreams),
"groups" / construct.Debugger(PrefixedArray(Int32ul, GroupData)),
Copy link
Contributor

Choose a reason for hiding this comment

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

why the debugger?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

to scare the bugs off obviously

"wave_archives" / PrefixedArray(Int32ul, WaveArchiveData),
"sound_streams" / PrefixedArray(Int32ul, SoundStreams),
"groups" / PrefixedArray(Int32ul, GroupData),
construct.Terminated,
Copy link
Contributor

Choose a reason for hiding this comment

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

these arrays can all use make_vector()

- contains helper data for the BFSAR about wave archives, sound streams,
  and groups
- uses rebuild for some more fields
- enum for FileId.file_type
- renamed a size to length
- removed a debugger
- added additional 2.1.0 data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants