2022-10-21 21:26:40 +00:00
|
|
|
import os
|
2021-11-07 14:38:02 +00:00
|
|
|
from typing import Optional
|
2022-10-21 21:26:40 +00:00
|
|
|
|
2021-11-07 14:38:02 +00:00
|
|
|
import Utils
|
2022-09-29 22:36:30 +00:00
|
|
|
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"]
|
2022-10-21 21:26:40 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
2021-11-07 14:38:02 +00:00
|
|
|
def read_rom(stream, strip_header=True) -> bytes:
|
|
|
|
"""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)
|
|
|
|
sys.exit(1)
|