Core remove legacy patch (#1047)

Co-authored-by: black-sliver <59490463+black-sliver@users.noreply.github.com>
This commit is contained in:
Fabian Dill
2022-09-30 00:36:30 +02:00
committed by GitHub
parent 8ab0b410c3
commit 61e39f355d
22 changed files with 259 additions and 491 deletions

View File

@@ -1,11 +1,12 @@
from __future__ import annotations
import Utils
from Patch import read_rom
import worlds.AutoWorld
import worlds.Files
LTTPJPN10HASH = '03a63945398191337e896e5771f77173'
RANDOMIZERBASEHASH = '9952c2a3ec1b421e408df0d20c8f0c7f'
ROM_PLAYER_LIMIT = 255
LTTPJPN10HASH: str = "03a63945398191337e896e5771f77173"
RANDOMIZERBASEHASH: str = "9952c2a3ec1b421e408df0d20c8f0c7f"
ROM_PLAYER_LIMIT: int = 255
import io
import json
@@ -34,7 +35,7 @@ from worlds.alttp.Text import KingsReturn_texts, Sanctuary_texts, Kakariko_texts
DeathMountain_texts, \
LostWoods_texts, WishingWell_texts, DesertPalace_texts, MountainTower_texts, LinksHouse_texts, Lumberjacks_texts, \
SickKid_texts, FluteBoy_texts, Zora_texts, MagicShop_texts, Sahasrahla_names
from Utils import local_path, user_path, int16_as_bytes, int32_as_bytes, snes_to_pc, is_frozen, parse_yaml
from Utils import local_path, user_path, int16_as_bytes, int32_as_bytes, snes_to_pc, is_frozen, parse_yaml, read_snes_rom
from worlds.alttp.Items import ItemFactory, item_table, item_name_groups, progression_items
from worlds.alttp.EntranceShuffle import door_addresses
from worlds.alttp.Options import smallkey_shuffle
@@ -57,13 +58,13 @@ class LocalRom(object):
self.orig_buffer = None
with open(file, 'rb') as stream:
self.buffer = read_rom(stream)
self.buffer = read_snes_rom(stream)
if patch:
self.patch_base_rom()
self.orig_buffer = self.buffer.copy()
if vanillaRom:
with open(vanillaRom, 'rb') as vanillaStream:
self.orig_buffer = read_rom(vanillaStream)
self.orig_buffer = read_snes_rom(vanillaStream)
def read_byte(self, address: int) -> int:
return self.buffer[address]
@@ -123,29 +124,24 @@ class LocalRom(object):
return expected == buffermd5.hexdigest()
def patch_base_rom(self):
if os.path.isfile(local_path('basepatch.sfc')):
with open(local_path('basepatch.sfc'), 'rb') as stream:
if os.path.isfile(user_path('basepatch.sfc')):
with open(user_path('basepatch.sfc'), 'rb') as stream:
buffer = bytearray(stream.read())
if self.verify(buffer):
self.buffer = buffer
if not os.path.exists(local_path('data', 'basepatch.apbp')):
Patch.create_patch_file(local_path('basepatch.sfc'))
return
if not os.path.isfile(local_path('data', 'basepatch.apbp')):
raise RuntimeError('Base patch unverified. Unable to continue.')
with open(local_path("data", "basepatch.bsdiff4"), "rb") as f:
delta = f.read()
if os.path.isfile(local_path('data', 'basepatch.apbp')):
_, target, buffer = Patch.create_rom_bytes(local_path('data', 'basepatch.apbp'), ignore_version=True)
if self.verify(buffer):
self.buffer = bytearray(buffer)
with open(user_path('basepatch.sfc'), 'wb') as stream:
stream.write(buffer)
return
raise RuntimeError('Base patch unverified. Unable to continue.')
raise RuntimeError('Could not find Base Patch. Unable to continue.')
buffer = bsdiff4.patch(get_base_rom_bytes(), delta)
if self.verify(buffer):
self.buffer = bytearray(buffer)
with open(user_path('basepatch.sfc'), 'wb') as stream:
stream.write(buffer)
return
raise RuntimeError('Base patch unverified. Unable to continue.')
def write_crc(self):
crc = (sum(self.buffer[:0x7FDC] + self.buffer[0x7FE0:]) + 0x01FE) & 0xFFFF
@@ -544,7 +540,7 @@ class Sprite():
def get_vanilla_sprite_data(self):
file_name = get_base_rom_path()
base_rom_bytes = bytes(read_rom(open(file_name, "rb")))
base_rom_bytes = bytes(read_snes_rom(open(file_name, "rb")))
Sprite.sprite = base_rom_bytes[0x80000:0x87000]
Sprite.palette = base_rom_bytes[0xDD308:0xDD380]
Sprite.glove_palette = base_rom_bytes[0xDEDF5:0xDEDF9]
@@ -2906,7 +2902,7 @@ hash_alphabet = [
]
class LttPDeltaPatch(Patch.APDeltaPatch):
class LttPDeltaPatch(worlds.Files.APDeltaPatch):
hash = LTTPJPN10HASH
game = "A Link to the Past"
patch_file_ending = ".aplttp"
@@ -2920,7 +2916,7 @@ def get_base_rom_bytes(file_name: str = "") -> bytes:
base_rom_bytes = getattr(get_base_rom_bytes, "base_rom_bytes", None)
if not base_rom_bytes:
file_name = get_base_rom_path(file_name)
base_rom_bytes = bytes(read_rom(open(file_name, "rb")))
base_rom_bytes = bytes(read_snes_rom(open(file_name, "rb")))
basemd5 = hashlib.md5()
basemd5.update(base_rom_bytes)