diff --git a/worlds/kdl3/Aesthetics.py b/worlds/kdl3/Aesthetics.py index 8c7363908f..55ad0f2722 100644 --- a/worlds/kdl3/Aesthetics.py +++ b/worlds/kdl3/Aesthetics.py @@ -420,7 +420,7 @@ def rgb888_to_bgr555(red, green, blue) -> bytes: return struct.pack("H", outcol) -def get_palette_bytes(palette, target, offset, factor): +def get_palette_bytes(palette, target, offset, factor) -> bytes: output_data = bytearray() for color in target: hexcol = palette[color] @@ -431,4 +431,4 @@ def get_palette_bytes(palette, target, offset, factor): col = tuple(int(int(factor*x) + offset) for x in col) byte_data = rgb888_to_bgr555(col[0], col[1], col[2]) output_data.extend(bytearray(byte_data)) - return output_data + return bytes(output_data) diff --git a/worlds/kdl3/Rom.py b/worlds/kdl3/Rom.py index b8a81dc0e3..0505b2a14a 100644 --- a/worlds/kdl3/Rom.py +++ b/worlds/kdl3/Rom.py @@ -387,9 +387,6 @@ def patch_rom(world: "KDL3World", patch: KDL3ProcedurePatch): patch.write_file("kdl3_basepatch.bsdiff4", get_data(__name__, os.path.join("data", "kdl3_basepatch.bsdiff4"))) - tiles = get_data(__name__, os.path.join("data", "APPauseIcons.dat")) - patch.write_token(APTokenTypes.WRITE, 0x3F000, tiles) - # Write open world patch if world.options.open_world: patch.write_token(APTokenTypes.WRITE, 0x143C7, bytes([0xAD, 0xC1, 0x5A, 0xCD, 0xC1, 0x5A, ])) @@ -449,7 +446,7 @@ def patch_rom(world: "KDL3World", patch: KDL3ProcedurePatch): patch.write_token(APTokenTypes.WRITE, 0x4A38D, world.random.choice(music_choices).to_bytes(1, "little")) for room in rooms: - room.patch(patch) + room.patch(patch, bool(world.options.consumables.value), True) if world.options.virtual_console in [1, 3]: # Flash Reduction diff --git a/worlds/kdl3/Room.py b/worlds/kdl3/Room.py index 6c2363928f..e0edc85ef5 100644 --- a/worlds/kdl3/Room.py +++ b/worlds/kdl3/Room.py @@ -2,6 +2,7 @@ import struct import typing from BaseClasses import Region, ItemClassification from worlds.Files import APTokenTypes +from .ClientAddrs import consumable_addrs, star_addrs if typing.TYPE_CHECKING: from .Rom import KDL3ProcedurePatch @@ -43,14 +44,39 @@ class KDL3Room(Region): self.consumables = consumables self.consumable_pointer = consumable_pointer - def patch(self, patch: "KDL3ProcedurePatch"): + def patch(self, patch: "KDL3ProcedurePatch", consumables: bool, local_items: bool): patch.write_token(APTokenTypes.WRITE, self.pointer + 2, self.music.to_bytes(1, "little")) animals = [x.item.name for x in self.locations if "Animal" in x.name] if len(animals) > 0: for current_animal, address in zip(animals, self.animal_pointers): patch.write_token(APTokenTypes.WRITE, self.pointer + address + 7, animal_map[current_animal].to_bytes(1, "little")) - if self.multiworld.worlds[self.player].options.consumables: + if local_items: + for location in self.locations: + if not location.address or location.item.player != self.player: + continue + item = location.item.code + item_idx = item & 0x00000F + location_idx = location.address & 0xFFFF + if location_idx & 0xF00 in (0x300, 0x400, 0x500, 0x600): + # consumable or star, need remapped + location_base = location_idx & 0xF00 + if location_base == 0x300: + # consumable + location_idx = consumable_addrs[location_idx & 0xFF] | 0x1000 + else: + # star + location_idx = star_addrs[location.address] | 0x2000 + if item & 0x000070 == 0: + patch.write_token(APTokenTypes.WRITE, 0x4B000 + location_idx, bytes([item_idx | 0x10])) + elif item & 0x000010 > 0: + patch.write_token(APTokenTypes.WRITE, 0x4B000 + location_idx, bytes([item_idx | 0x20])) + elif item & 0x000020 > 0: + patch.write_token(APTokenTypes.WRITE, 0x4B000 + location_idx, bytes([item_idx | 0x40])) + elif item & 0x000040 > 0: + patch.write_token(APTokenTypes.WRITE, 0x4B000 + location_idx, bytes([item_idx | 0x80])) + + if consumables: load_len = len(self.entity_load) for consumable in self.consumables: location = next(x for x in self.locations if x.name == consumable["name"]) diff --git a/worlds/kdl3/data/kdl3_basepatch.bsdiff4 b/worlds/kdl3/data/kdl3_basepatch.bsdiff4 index cd002121cd..662467bac0 100644 Binary files a/worlds/kdl3/data/kdl3_basepatch.bsdiff4 and b/worlds/kdl3/data/kdl3_basepatch.bsdiff4 differ diff --git a/worlds/kdl3/data/APPauseIcons.dat b/worlds/kdl3/src/APPauseIcons.dat similarity index 100% rename from worlds/kdl3/data/APPauseIcons.dat rename to worlds/kdl3/src/APPauseIcons.dat diff --git a/worlds/kdl3/src/kdl3_basepatch.asm b/worlds/kdl3/src/kdl3_basepatch.asm index e419d0632f..4ddbd2b105 100644 --- a/worlds/kdl3/src/kdl3_basepatch.asm +++ b/worlds/kdl3/src/kdl3_basepatch.asm @@ -519,8 +519,16 @@ ConsumableSet: BRA .LoopHead ; return to loop head .ApplyCheck: LDA $A000, X ; consumables index + PHA ORA #$0001 STA $A000, X + PLA + AND #$00FF + BNE .Return + TXA + ORA #$1000 + JSL ApplyLocalCheck + .Return: PLY PLX PLA @@ -1183,8 +1191,15 @@ StarsSet: BRA .2LoopHead .2LoopEnd: LDA $B000, X + PHA ORA #$0001 STA $B000, X + PLA + AND #$00FF + BNE .Return + TXA + ORA #$2000 + JSL ApplyLocalCheck .Return: PLY PLX @@ -1199,6 +1214,26 @@ StarsSet: STA $39D7 BRA .Return +org $07A680 +ApplyLocalCheck: +; args: A-address of check following $08B000 + TAX + LDA $08B000, X + AND #$00FF + TAY + LDX #$0000 + .Loop: + LDA $C000, X + BEQ .Apply + INX + INX + CPX #$0010 + BCC .Loop + BRA .Return ; this is dangerous, could lose a check here + .Apply: + STY $C000, X + .Return: + RTL org $07C000 db "KDL3_BASEPATCH_ARCHI" @@ -1234,4 +1269,7 @@ org $07E040 db $3A, $01 db $3B, $05 db $3C, $05 - db $3D, $05 \ No newline at end of file + db $3D, $05 + +org $07F000 +incbin "APPauseIcons.bin" \ No newline at end of file