From 67128ece382209e0752db5b586aee14cf8c1265d Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Thu, 17 Nov 2022 23:44:59 +0100 Subject: [PATCH] LttP: make xxtea only required for race generation --- worlds/alttp/Rom.py | 13 ++++++++++--- worlds/alttp/__init__.py | 2 ++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/worlds/alttp/Rom.py b/worlds/alttp/Rom.py index 24a1588c..18e09ab1 100644 --- a/worlds/alttp/Rom.py +++ b/worlds/alttp/Rom.py @@ -1,7 +1,6 @@ from __future__ import annotations import Utils -import worlds.AutoWorld import worlds.Files LTTPJPN10HASH: str = "03a63945398191337e896e5771f77173" @@ -17,7 +16,6 @@ import random import struct import subprocess import threading -import xxtea import concurrent.futures import bsdiff4 from typing import Optional, List @@ -39,7 +37,6 @@ from Utils import local_path, user_path, int16_as_bytes, int32_as_bytes, snes_to 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 -import Patch try: from maseya import z3pr @@ -47,6 +44,11 @@ try: except: z3pr = None +try: + import xxtea +except: + xxtea = None + enemizer_logger = logging.getLogger("Enemizer") @@ -85,6 +87,11 @@ class LocalRom(object): self.write_bytes(startaddress + i, bytearray(data)) def encrypt(self, world, player): + global xxtea + if xxtea is None: + # cause crash to provide traceback + import xxtea + local_random = world.slot_seeds[player] key = bytes(local_random.getrandbits(8 * 16).to_bytes(16, 'big')) self.write_bytes(0x1800B0, bytearray(key)) diff --git a/worlds/alttp/__init__.py b/worlds/alttp/__init__.py index 93e0b02b..4517e269 100644 --- a/worlds/alttp/__init__.py +++ b/worlds/alttp/__init__.py @@ -157,6 +157,8 @@ class ALTTPWorld(World): rom_file = get_base_rom_path() if not os.path.exists(rom_file): raise FileNotFoundError(rom_file) + if world.is_race: + import xxtea def generate_early(self): if self.use_enemizer():