|
| 1 | +"""File responsible for modifying the animation code file.""" |
| 2 | + |
| 3 | +import zlib |
| 4 | +from typing import BinaryIO |
| 5 | +from BuildClasses import ROMPointerFile |
| 6 | +from BuildEnums import TableNames |
| 7 | +from BuildLib import ROMName |
| 8 | + |
| 9 | +anim_file = "animation_code.bin" |
| 10 | + |
| 11 | + |
| 12 | +class AnimChange: |
| 13 | + """Class to store information pertaining to an animation coding change.""" |
| 14 | + |
| 15 | + def __init__(self, animation: int, offset: int, value: int, value_size: int): |
| 16 | + """Initialize with given parameters.""" |
| 17 | + self.animation = animation |
| 18 | + self.offset = offset |
| 19 | + self.value = value |
| 20 | + self.value_size = value_size |
| 21 | + |
| 22 | + def enact(self, fh: BinaryIO): |
| 23 | + """Apply the animation change.""" |
| 24 | + fh.seek(self.animation * 4) |
| 25 | + header = int.from_bytes(fh.read(4), "big") |
| 26 | + fh.seek(header + self.offset) |
| 27 | + fh.write((self.value).to_bytes(self.value_size, "big")) |
| 28 | + |
| 29 | + |
| 30 | +anim_changes = [ |
| 31 | + AnimChange(0x2C1, 0x26 + 3, 0xFF, 1), # Increase kop volume to 255 |
| 32 | + AnimChange(0x2C1, 0x1C + 2, 15, 1), # Double the chance of a kop making a noise |
| 33 | +] |
| 34 | + |
| 35 | + |
| 36 | +def modifyAnimationCode(): |
| 37 | + """Pull geo file from ROM and modify.""" |
| 38 | + with open(ROMName, "rb") as fh: |
| 39 | + anim_code_file = ROMPointerFile(fh, TableNames.Unknown13, 0) |
| 40 | + fh.seek(anim_code_file.start) |
| 41 | + dec = zlib.decompress(fh.read(anim_code_file.size), 15 + 32) |
| 42 | + with open(anim_file, "wb") as fg: |
| 43 | + fg.write(dec) |
| 44 | + with open(anim_file, "r+b") as fh: |
| 45 | + for change in anim_changes: |
| 46 | + change.enact(fh) |
0 commit comments