def write_stream(self, stream): if not isinstance(stream, BinaryWriter): wtr = BinaryWriter(stream) else: wtr = stream wtr.write(self.original_header) wtr.seek(0) wtr.write(self.chunk_id) wtr.seek(0x31) wtr.write_uint8(self.loop_flag) wtr.write_uint8(self.channels) coding = self.coding if self.sample_rate == 32728: coding |= 4 elif self.sample_rate == 16364: coding |= 2 else: raise NotImplementedError() wtr.seek(0x100) buffer = self.buffer.copy() buffer = buffer.reshape((buffer.shape[0], buffer.shape[1] // 0x10, 0x10)) buffer = buffer.swapaxes(0, 1) wtr.write(buffer.tobytes()) size = wtr.tell() wtr.seek(0x40) wtr.write_uint32(size)
def export_data(self, wtr): if not isinstance(wtr, BinaryWriter): wtr = BinaryWriter(wtr) wtr: BinaryWriter puzzle_text_section = BinaryWriter() puzzle_text_section.write_string(self.text, encoding=self.encoding) puzzle_correct_offset = puzzle_text_section.tell() puzzle_text_section.write_string(self.correct_answer, encoding=self.encoding) puzzle_incorrect_offset = puzzle_text_section.tell() puzzle_text_section.write_string(self.incorrect_answer, encoding=self.encoding) puzzle_hint1_offset = puzzle_text_section.tell() puzzle_text_section.write_string(self.hint1, encoding=self.encoding) puzzle_hint2_offset = puzzle_text_section.tell() puzzle_text_section.write_string(self.hint2, encoding=self.encoding) puzzle_hint3_offset = puzzle_text_section.tell() puzzle_text_section.write_string(self.hint3, encoding=self.encoding) wtr.write_uint16(self.number) wtr.write_uint16(112) wtr.write_string(self.title, encoding=self.encoding, size=0x30) wtr.write_uint8(self.tutorial_id) for picarat in self.picarat_decay: wtr.write_uint8(picarat) wtr.write_uint8(self._flags) wtr.write_uint8(self.location_id) wtr.write_uint8(self.type) wtr.write_uint8(self.bg_btm_id) wtr.write(self.original[0x3c:0x3e]) # UnkSoundId wtr.write_uint8(self.bg_top_id) wtr.write_uint8(self.reward_id) wtr.write_uint32(0) wtr.write_uint32(puzzle_correct_offset) wtr.write_uint32(puzzle_incorrect_offset) wtr.write_uint32(puzzle_hint1_offset) wtr.write_uint32(puzzle_hint2_offset) wtr.write_uint32(puzzle_hint3_offset) wtr.write(b"\x00" * 4 * 6) wtr.write(puzzle_text_section.data) return wtr
def write_stream(self, stream): if isinstance(stream, BinaryWriter): wtr = stream else: wtr = BinaryWriter(stream) self.song_chunk.num_tracks = len(self.tracks) self.song_chunk.write(wtr) for track in self.tracks: track: Track track.write(wtr) self.eoc_chunk.write(wtr) self.smdl_header.file_length = wtr.tell() self.smdl_header.write(wtr) wtr.seek(0, io.SEEK_END)
def write(self, bw: BinaryWriter): bw.write_char_array([bytes([x]) for x in list(self.event_bytes)]) if offset := bw.tell() % 4: bw.write_char_array([b"\x98"] * (4 - offset))