Add Race rom encryption.
This commit is contained in:
parent
e72b74d476
commit
ad765659dd
2
Main.py
2
Main.py
|
@ -188,7 +188,7 @@ def main(args, seed=None):
|
||||||
patch_enemizer(world, player, rom, args.enemizercli)
|
patch_enemizer(world, player, rom, args.enemizercli)
|
||||||
|
|
||||||
if args.race:
|
if args.race:
|
||||||
patch_race_rom(rom)
|
patch_race_rom(rom, world, player)
|
||||||
|
|
||||||
world.spoiler.hashes[(player, team)] = get_hash_string(rom.hash)
|
world.spoiler.hashes[(player, team)] = get_hash_string(rom.hash)
|
||||||
|
|
||||||
|
|
36
Rom.py
36
Rom.py
|
@ -11,6 +11,7 @@ import struct
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
import threading
|
import threading
|
||||||
|
import xxtea
|
||||||
import concurrent.futures
|
import concurrent.futures
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
@ -58,6 +59,31 @@ class LocalRom(object):
|
||||||
def write_bytes(self, startaddress: int, values):
|
def write_bytes(self, startaddress: int, values):
|
||||||
self.buffer[startaddress:startaddress + len(values)] = values
|
self.buffer[startaddress:startaddress + len(values)] = values
|
||||||
|
|
||||||
|
def encrypt_range(self, startaddress: int, length: int, key: bytes):
|
||||||
|
for i in range(0, length, 8):
|
||||||
|
data = bytes(self.read_bytes(startaddress + i, 8))
|
||||||
|
data = xxtea.encrypt(data, key, padding=False)
|
||||||
|
self.write_bytes(startaddress + i, bytearray(data))
|
||||||
|
|
||||||
|
def encrypt(self, world, player):
|
||||||
|
local_random = world.rom_seeds[player]
|
||||||
|
key = bytes(local_random.getrandbits(8 * 16).to_bytes(16, 'big'))
|
||||||
|
self.write_bytes(0x1800B0, bytearray(key))
|
||||||
|
self.write_int16(0x180087, 1)
|
||||||
|
|
||||||
|
itemtable = []
|
||||||
|
locationtable = []
|
||||||
|
for i in range(168):
|
||||||
|
itemtable.append(self.read_byte(0xE96E + (i * 3)))
|
||||||
|
locationtable.append(self.read_byte(0xe96C + (i * 3)))
|
||||||
|
locationtable.append(self.read_byte(0xe96D + (i * 3)))
|
||||||
|
self.write_bytes(0xE96C, locationtable)
|
||||||
|
self.write_bytes(0xE96C + 0x150, itemtable)
|
||||||
|
self.encrypt_range(0xE96C + 0x150, 168, key)
|
||||||
|
self.encrypt_range(0x180000, 32, key)
|
||||||
|
self.encrypt_range(0x180140, 32, key)
|
||||||
|
|
||||||
|
|
||||||
def write_to_file(self, file, hide_enemizer=False):
|
def write_to_file(self, file, hide_enemizer=False):
|
||||||
with open(file, 'wb') as outfile:
|
with open(file, 'wb') as outfile:
|
||||||
outfile.write(self.buffer)
|
outfile.write(self.buffer)
|
||||||
|
@ -1422,16 +1448,10 @@ def patch_rom(world, rom, player, team, enemized):
|
||||||
|
|
||||||
return rom
|
return rom
|
||||||
|
|
||||||
try:
|
|
||||||
import RaceRom
|
|
||||||
except ImportError:
|
|
||||||
RaceRom = None
|
|
||||||
|
|
||||||
def patch_race_rom(rom):
|
def patch_race_rom(rom, world, player):
|
||||||
rom.write_bytes(0x180213, [0x01, 0x00]) # Tournament Seed
|
rom.write_bytes(0x180213, [0x01, 0x00]) # Tournament Seed
|
||||||
|
rom.encrypt(world, player)
|
||||||
if 'RaceRom' in sys.modules:
|
|
||||||
RaceRom.encrypt(rom)
|
|
||||||
|
|
||||||
def write_custom_shops(rom, world, player):
|
def write_custom_shops(rom, world, player):
|
||||||
shops = [shop for shop in world.shops if shop.custom and shop.region.player == player]
|
shops = [shop for shop in world.shops if shop.custom and shop.region.player == player]
|
||||||
|
|
|
@ -5,4 +5,5 @@ fuzzywuzzy>=0.18.0
|
||||||
bsdiff4>=1.2.0
|
bsdiff4>=1.2.0
|
||||||
prompt_toolkit>=3.0.6
|
prompt_toolkit>=3.0.6
|
||||||
appdirs>=1.4.4
|
appdirs>=1.4.4
|
||||||
maseya-z3pr>=1.0.0rc1
|
maseya-z3pr>=1.0.0rc1
|
||||||
|
xxtea>=2.0.0
|
Loading…
Reference in New Issue