mirror of
https://github.com/pmret/papermario.git
synced 2024-11-09 12:32:38 +01:00
Minor enhanement ;) (#488)
This commit is contained in:
parent
149b764045
commit
f6fa89bbc4
@ -4,6 +4,7 @@ import os
|
|||||||
from sys import argv
|
from sys import argv
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from itertools import tee
|
from itertools import tee
|
||||||
|
import struct
|
||||||
|
|
||||||
def next_multiple(pos, multiple):
|
def next_multiple(pos, multiple):
|
||||||
return pos + pos % multiple
|
return pos + pos % multiple
|
||||||
@ -20,7 +21,6 @@ def build_mapfs(out_bin, assets, version):
|
|||||||
# every TOC entry's name field has data after the null terminator made up from all the previous name fields.
|
# every TOC entry's name field has data after the null terminator made up from all the previous name fields.
|
||||||
# we probably don't have to do this for the game to read the data properly (it doesn't read past the null terminator
|
# we probably don't have to do this for the game to read the data properly (it doesn't read past the null terminator
|
||||||
# of `string`), but the original devs' equivalent of this script had this bug so we need to replicate it to match.
|
# of `string`), but the original devs' equivalent of this script had this bug so we need to replicate it to match.
|
||||||
written_names = []
|
|
||||||
|
|
||||||
with open(out_bin, "wb") as f:
|
with open(out_bin, "wb") as f:
|
||||||
f.write(get_version_date(version).encode("ascii"))
|
f.write(get_version_date(version).encode("ascii"))
|
||||||
@ -28,6 +28,7 @@ def build_mapfs(out_bin, assets, version):
|
|||||||
next_data_pos = (len(assets) + 1) * 0x1C
|
next_data_pos = (len(assets) + 1) * 0x1C
|
||||||
|
|
||||||
asset_idx = 0
|
asset_idx = 0
|
||||||
|
lastname = ""
|
||||||
for decompressed, compressed in assets:
|
for decompressed, compressed in assets:
|
||||||
toc_entry_pos = 0x20 + asset_idx * 0x1C
|
toc_entry_pos = 0x20 + asset_idx * 0x1C
|
||||||
|
|
||||||
@ -39,17 +40,14 @@ def build_mapfs(out_bin, assets, version):
|
|||||||
|
|
||||||
#print(f"{name} {offset:08X} {size:08X} {decompressed_size:08X}")
|
#print(f"{name} {offset:08X} {size:08X} {decompressed_size:08X}")
|
||||||
|
|
||||||
written_names.append(name)
|
|
||||||
# write all previously-written names; required to match
|
# write all previously-written names; required to match
|
||||||
for prev_name in written_names:
|
lastname = name + lastname[len(name):]
|
||||||
f.seek(toc_entry_pos)
|
f.seek(toc_entry_pos)
|
||||||
f.write(prev_name.encode('ascii'))
|
f.write(lastname.encode('ascii'))
|
||||||
|
|
||||||
# write TOC entry.
|
# write TOC entry.
|
||||||
f.seek(toc_entry_pos + 0x10)
|
f.seek(toc_entry_pos + 0x10)
|
||||||
f.write(offset.to_bytes(4, byteorder="big"))
|
f.write(struct.pack(">III", offset, size, decompressed_size))
|
||||||
f.write(size.to_bytes(4, byteorder="big"))
|
|
||||||
f.write(decompressed_size.to_bytes(4, byteorder="big"))
|
|
||||||
|
|
||||||
# write data.
|
# write data.
|
||||||
f.seek(0x20 + next_data_pos)
|
f.seek(0x20 + next_data_pos)
|
||||||
@ -61,10 +59,10 @@ def build_mapfs(out_bin, assets, version):
|
|||||||
# end_data
|
# end_data
|
||||||
toc_entry_pos = 0x20 + asset_idx * 0x1C
|
toc_entry_pos = 0x20 + asset_idx * 0x1C
|
||||||
|
|
||||||
written_names.append("end_data\0")
|
last_name_entry = "end_data\0"
|
||||||
for prev_name in written_names:
|
f.seek(toc_entry_pos)
|
||||||
f.seek(toc_entry_pos)
|
lastname = last_name_entry + lastname[len(last_name_entry):]
|
||||||
f.write(prev_name.encode('ascii'))
|
f.write(lastname.encode('ascii'))
|
||||||
|
|
||||||
f.seek(toc_entry_pos + 0x18)
|
f.seek(toc_entry_pos + 0x18)
|
||||||
f.write((0x903F0000).to_bytes(4, byteorder="big")) # TODO: figure out purpose
|
f.write((0x903F0000).to_bytes(4, byteorder="big")) # TODO: figure out purpose
|
||||||
|
Loading…
Reference in New Issue
Block a user