mirror of
https://github.com/MarioSpore/Grinch-AP.git
synced 2025-10-21 12:11:33 -06:00
Zillion: remove rom requirement for generation (#2875)
* in the middle of work towards no rom for generation (not working) * no rom needed for Zillion generation * revert core changes
This commit is contained in:
@@ -1,22 +1,53 @@
|
||||
from typing import BinaryIO, Optional, cast
|
||||
import Utils
|
||||
from worlds.Files import APDeltaPatch
|
||||
import os
|
||||
from typing import Any, BinaryIO, Optional, cast
|
||||
import zipfile
|
||||
|
||||
from typing_extensions import override
|
||||
|
||||
import Utils
|
||||
from worlds.Files import APPatch
|
||||
|
||||
from zilliandomizer.patch import Patcher
|
||||
|
||||
from .gen_data import GenData
|
||||
|
||||
USHASH = 'd4bf9e7bcf9a48da53785d2ae7bc4270'
|
||||
|
||||
|
||||
class ZillionDeltaPatch(APDeltaPatch):
|
||||
class ZillionPatch(APPatch):
|
||||
hash = USHASH
|
||||
game = "Zillion"
|
||||
patch_file_ending = ".apzl"
|
||||
result_file_ending = ".sms"
|
||||
|
||||
gen_data_str: str
|
||||
""" JSON encoded """
|
||||
|
||||
def __init__(self, *args: Any, gen_data_str: str = "", **kwargs: Any) -> None:
|
||||
super().__init__(*args, **kwargs)
|
||||
self.gen_data_str = gen_data_str
|
||||
|
||||
@classmethod
|
||||
def get_source_data(cls) -> bytes:
|
||||
with open(get_base_rom_path(), "rb") as stream:
|
||||
return read_rom(stream)
|
||||
|
||||
@override
|
||||
def write_contents(self, opened_zipfile: zipfile.ZipFile) -> None:
|
||||
super().write_contents(opened_zipfile)
|
||||
opened_zipfile.writestr("gen_data.json",
|
||||
self.gen_data_str,
|
||||
compress_type=zipfile.ZIP_DEFLATED)
|
||||
|
||||
@override
|
||||
def read_contents(self, opened_zipfile: zipfile.ZipFile) -> None:
|
||||
super().read_contents(opened_zipfile)
|
||||
self.gen_data_str = opened_zipfile.read("gen_data.json").decode()
|
||||
|
||||
def patch(self, target: str) -> None:
|
||||
self.read()
|
||||
write_rom_from_gen_data(self.gen_data_str, target)
|
||||
|
||||
|
||||
def get_base_rom_path(file_name: Optional[str] = None) -> str:
|
||||
options = Utils.get_options()
|
||||
@@ -32,3 +63,21 @@ def read_rom(stream: BinaryIO) -> bytes:
|
||||
data = stream.read()
|
||||
# I'm not aware of any sms header.
|
||||
return data
|
||||
|
||||
|
||||
def write_rom_from_gen_data(gen_data_str: str, output_rom_file_name: str) -> None:
|
||||
""" take the output of `GenData.to_json`, and create rom from it """
|
||||
gen_data = GenData.from_json(gen_data_str)
|
||||
|
||||
base_rom_path = get_base_rom_path()
|
||||
zz_patcher = Patcher(base_rom_path)
|
||||
|
||||
zz_patcher.write_locations(gen_data.zz_game.regions, gen_data.zz_game.char_order[0])
|
||||
zz_patcher.all_fixes_and_options(gen_data.zz_game)
|
||||
zz_patcher.set_external_item_interface(gen_data.zz_game.char_order[0], gen_data.zz_game.options.max_level)
|
||||
zz_patcher.set_multiworld_items(gen_data.multi_items)
|
||||
zz_patcher.set_rom_to_ram_data(gen_data.game_id)
|
||||
|
||||
patched_rom_bytes = zz_patcher.get_patched_bytes()
|
||||
with open(output_rom_file_name, "wb") as binary_file:
|
||||
binary_file.write(patched_rom_bytes)
|
||||
|
Reference in New Issue
Block a user