Allow applying patches to rom from CLI
This commit is contained in:
2
CLI.py
2
CLI.py
@@ -179,7 +179,7 @@ def parse_cli(argv, no_defaults=False):
|
|||||||
'decoupledoors', 'door_type_mode', 'bonk_drops',
|
'decoupledoors', 'door_type_mode', 'bonk_drops',
|
||||||
'trap_door_mode', 'key_logic_algorithm',
|
'trap_door_mode', 'key_logic_algorithm',
|
||||||
'door_self_loops', 'any_enemy_logic', 'aga_randomness',
|
'door_self_loops', 'any_enemy_logic', 'aga_randomness',
|
||||||
'money_balance']:
|
'money_balance', 'patches']:
|
||||||
value = getattr(defaults, name) if getattr(playerargs, name) is None else getattr(playerargs, name)
|
value = getattr(defaults, name) if getattr(playerargs, name) is None else getattr(playerargs, name)
|
||||||
if player == 1:
|
if player == 1:
|
||||||
setattr(ret, name, {1: value})
|
setattr(ret, name, {1: value})
|
||||||
|
|||||||
2
Main.py
2
Main.py
@@ -67,6 +67,7 @@ from Rom import (
|
|||||||
JsonRom,
|
JsonRom,
|
||||||
LocalRom,
|
LocalRom,
|
||||||
apply_rom_settings,
|
apply_rom_settings,
|
||||||
|
apply_rom_patches,
|
||||||
get_hash_string,
|
get_hash_string,
|
||||||
patch_race_rom,
|
patch_race_rom,
|
||||||
patch_rom,
|
patch_rom,
|
||||||
@@ -364,6 +365,7 @@ def main(args, seed=None, fish=None):
|
|||||||
rom_names.append((player, team, list(rom.name)))
|
rom_names.append((player, team, list(rom.name)))
|
||||||
world.spoiler.hashes[(player, team)] = get_hash_string(rom.hash)
|
world.spoiler.hashes[(player, team)] = get_hash_string(rom.hash)
|
||||||
|
|
||||||
|
apply_rom_patches(rom, map(lambda arg: arg.strip(), args.patches[player].split(",")))
|
||||||
apply_rom_settings(rom, args.heartbeep[player], args.heartcolor[player], args.quickswap[player],
|
apply_rom_settings(rom, args.heartbeep[player], args.heartcolor[player], args.quickswap[player],
|
||||||
args.fastmenu[player], args.disablemusic[player], args.sprite[player], args.triforce_gfx[player],
|
args.fastmenu[player], args.disablemusic[player], args.sprite[player], args.triforce_gfx[player],
|
||||||
args.ow_palettes[player], args.uw_palettes[player], args.reduce_flashing[player],
|
args.ow_palettes[player], args.uw_palettes[player], args.reduce_flashing[player],
|
||||||
|
|||||||
43
Rom.py
43
Rom.py
@@ -2088,6 +2088,49 @@ def hud_format_text(text):
|
|||||||
output += b'\x7f\x00'
|
output += b'\x7f\x00'
|
||||||
return output[:32]
|
return output[:32]
|
||||||
|
|
||||||
|
def read_bytes(f, count):
|
||||||
|
values = f.read(count)
|
||||||
|
if len(values) < count:
|
||||||
|
raise EOFError
|
||||||
|
return values
|
||||||
|
|
||||||
|
def apply_rom_patches(rom, patches):
|
||||||
|
for patch in patches:
|
||||||
|
if not os.path.exists(f"patches/{patch}.ips"):
|
||||||
|
logging.getLogger('').warning("Patch %s not found -- skipping", patch)
|
||||||
|
continue
|
||||||
|
|
||||||
|
with open(f"patches/{patch}.ips", "rb") as f:
|
||||||
|
byte_changes = []
|
||||||
|
try:
|
||||||
|
header = read_bytes(f, 5)
|
||||||
|
if header != b"PATCH":
|
||||||
|
logging.getLogger('').warning("Patch %s invalid -- skipping", patch)
|
||||||
|
continue
|
||||||
|
|
||||||
|
while True:
|
||||||
|
address = read_bytes(f, 3)
|
||||||
|
if address == b"EOF":
|
||||||
|
break
|
||||||
|
|
||||||
|
address = int.from_bytes(address, byteorder="big")
|
||||||
|
length = int.from_bytes(read_bytes(f, 2), byteorder="big")
|
||||||
|
|
||||||
|
if length > 0:
|
||||||
|
byte_changes.append((address, list(f.read(length))))
|
||||||
|
else:
|
||||||
|
length = int.from_bytes(read_bytes(f, 2), byteorder="big")
|
||||||
|
value = read_bytes(f, 1)
|
||||||
|
byte_changes.append((address, length * list(value)))
|
||||||
|
|
||||||
|
for address, values in byte_changes:
|
||||||
|
rom.write_bytes(address, values)
|
||||||
|
|
||||||
|
logging.getLogger("").info("Patch %s applied successfully", patch)
|
||||||
|
|
||||||
|
except EOFError:
|
||||||
|
logging.getLogger('').warning("Patch %s invalid -- skipping", patch)
|
||||||
|
continue
|
||||||
|
|
||||||
def apply_rom_settings(rom, beep, color, quickswap, fastmenu, disable_music, sprite, triforce_gfx,
|
def apply_rom_settings(rom, beep, color, quickswap, fastmenu, disable_music, sprite, triforce_gfx,
|
||||||
ow_palettes, uw_palettes, reduce_flashing, shuffle_sfx,
|
ow_palettes, uw_palettes, reduce_flashing, shuffle_sfx,
|
||||||
|
|||||||
BIN
patches/no_dungeon_item_popups.ips
Normal file
BIN
patches/no_dungeon_item_popups.ips
Normal file
Binary file not shown.
BIN
patches/pod_key_swap.ips
Normal file
BIN
patches/pod_key_swap.ips
Normal file
Binary file not shown.
BIN
patches/pod_key_swap.ips.bak
Normal file
BIN
patches/pod_key_swap.ips.bak
Normal file
Binary file not shown.
@@ -754,6 +754,10 @@
|
|||||||
"type": "bool"
|
"type": "bool"
|
||||||
},
|
},
|
||||||
"money_balance": {},
|
"money_balance": {},
|
||||||
|
"patches": {
|
||||||
|
"type": "str",
|
||||||
|
"help": "suppress"
|
||||||
|
},
|
||||||
"settingsonload": {
|
"settingsonload": {
|
||||||
"choices": [
|
"choices": [
|
||||||
"default",
|
"default",
|
||||||
|
|||||||
Reference in New Issue
Block a user