Archipelago/worlds/soe/patch.py

45 lines
1.1 KiB
Python
Raw Normal View History

import os
from typing import BinaryIO, Optional
2021-11-07 14:38:02 +00:00
import Utils
from worlds.Files import APDeltaPatch
2021-11-07 14:38:02 +00:00
2021-11-10 08:17:27 +00:00
USHASH = '6e9c94511d04fac6e0a1e582c170be3a'
2022-03-18 03:53:09 +00:00
class SoEDeltaPatch(APDeltaPatch):
hash = USHASH
game = "Secret of Evermore"
patch_file_ending = ".apsoe"
@classmethod
def get_source_data(cls) -> bytes:
with open(get_base_rom_path(), "rb") as stream:
return read_rom(stream)
2022-03-31 03:08:15 +00:00
def get_base_rom_path(file_name: Optional[str] = None) -> str:
options = Utils.get_options()
if not file_name:
file_name = options["soe_options"]["rom_file"]
if not file_name:
raise ValueError("Missing soe_options -> rom_file from host.yaml")
2022-03-31 03:08:15 +00:00
if not os.path.exists(file_name):
file_name = Utils.user_path(file_name)
return file_name
2021-11-10 08:17:27 +00:00
def read_rom(stream: BinaryIO, strip_header: bool = True) -> bytes:
2021-11-07 14:38:02 +00:00
"""Reads rom into bytearray and optionally strips off any smc header"""
data = stream.read()
if strip_header and len(data) % 0x400 == 0x200:
return data[0x200:]
return data
if __name__ == '__main__':
2022-03-18 03:53:09 +00:00
import sys
print('Please use ../../patch.py', file=sys.stderr)
2022-03-18 03:53:09 +00:00
sys.exit(1)