Skip to content

Commit db9e613

Browse files
committed
Basic support for Co-Op using World Ids.
1 parent 77a6ee7 commit db9e613

File tree

7 files changed

+63
-5
lines changed

7 files changed

+63
-5
lines changed

asm/custom_symbols.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ sys/main.dol:
8585
give_temporary_sword_during_ganondorf_fight_in_swordless: 0x803FED10
8686
give_temporary_sword_in_orcas_house_in_swordless: 0x803FED2C
8787
remove_temporary_sword_when_loading_stage_in_swordless: 0x803FED74
88+
custom_write_item_world_id: 0x803FF6B9
8889
test_room_stage_name: 0x8022D034
8990
test_room_starting_items_list: 0x8022D03C
9091
test_room_spawn_id: 0x800531E3
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
sys/main.dol:
2+
0x803F60E0:
3+
Data: [0x01]
4+
0x803FF6B8:
5+
Data: [0x94, 0x21, 0xFF, 0xF0, 0x7C, 0x08, 0x02, 0xA6, 0x90, 0x01, 0x00, 0x14,
6+
0x3C, 0xA0, 0x80, 0x40, 0x38, 0xA5, 0xF6, 0xFD, 0xA8, 0x1E, 0x01, 0xDC, 0x54,
7+
0x00, 0xC6, 0x3E, 0x90, 0x05, 0x00, 0x00, 0x3C, 0xA0, 0x80, 0x40, 0x38, 0xA5,
8+
0xF7, 0x01, 0xA8, 0x1E, 0x01, 0xE0, 0x54, 0x04, 0xC6, 0x3E, 0x90, 0x85, 0x00,
9+
0x00, 0x80, 0x01, 0x00, 0x14, 0x7C, 0x08, 0x03, 0xA6, 0x38, 0x21, 0x00, 0x10,
10+
0x4E, 0x80, 0x00, 0x20, 0x60, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00]
11+
files/rels/d_a_tbox.rel:
12+
0x2764:
13+
Data: [0x48, 0x00, 0x00, 0x01]
14+
Relocations: [{SymbolName: custom_write_item_world_id, Offset: 0x00, Type: R_PPC_REL24}]

asm/patcher.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def apply_patch(self, patch_name):
3333

3434
if file_path == "sys/main.dol":
3535
if org_address >= free_space_start:
36+
print("Bad Free Space for {} at Address {:02X}".format(patch_name, org_address))
3637
add_or_extend_main_dol_free_space_section(self, new_bytes, org_address)
3738
continue
3839
else:

asm/patches/multiworld_scripts.asm

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
.open "sys/main.dol"
2+
.org @NextFreeSpace
3+
.global custom_write_item_world_id
4+
custom_write_item_world_id:
5+
stwu sp, -0x10 (sp)
6+
mflr r0
7+
stw r0, 0x14 (sp)
8+
lis r5, world_id@ha
9+
addi r5, r5, world_id@l
10+
lha r0, 0x1DC(r30)
11+
rlwinm r0, r0, 0x18, 0x18, 0x1f
12+
stw r0, 0x0(r5)
13+
14+
lis r5, item_id@ha
15+
addi r5, r5, item_id@l
16+
lha r0, 0x1E0(r30)
17+
rlwinm r4, r0, 0x18, 0x18, 0x1f
18+
stw r4, 0x0(r5)
19+
20+
lwz r0, 0x14 (sp)
21+
mtlr r0
22+
addi sp, sp, 0x10
23+
blr
24+
25+
.global world_id
26+
world_id:
27+
nop
28+
.global item_id
29+
item_id:
30+
nop
31+
32+
.org 0x803F60E0 ; Enable Developer Mode
33+
.byte 1
34+
.close
35+
36+
37+
.open "files/rels/d_a_tbox.rel" ; Treasure chests
38+
.org 0x2761 ; In actionOpenWait__8daTbox_cFv
39+
b custom_write_item_world_id
40+
.close

data/actor_parameters.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3135,6 +3135,9 @@ d_a_tbox:
31353135
chest_type:
31363136
Bitfield name: params
31373137
Mask: 0x00F00000
3138+
world_id:
3139+
Bitfield name: x_rot
3140+
Mask: 0xFF00
31383141
room_num:
31393142
Bitfield name: x_rot
31403143
Mask: 0x003F

randomizer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ def apply_necessary_tweaks(self):
461461
patcher.apply_patch(self, "flexible_item_locations")
462462
patcher.apply_patch(self, "fix_vanilla_bugs")
463463
patcher.apply_patch(self, "misc_rando_features")
464+
patcher.apply_patch(self, "multiworld_scripts")
464465
tweaks.add_custom_actor_rels(self)
465466
tweaks.skip_wakeup_intro_and_start_at_dock(self)
466467
tweaks.start_ship_at_outset(self)

randomizers/items.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
import re
44
from collections import OrderedDict
5-
5+
import random
66
from fs_helpers import *
77
import tweaks
88

@@ -507,9 +507,6 @@ def randomize_progression_items(self):
507507
if not game_beatable:
508508
raise Exception("Game is not beatable on this seed! This error shouldn't happen.")
509509

510-
511-
512-
513510
def write_changed_items(self):
514511
for location_name, item_name in self.logic.done_item_locations.items():
515512
paths = self.logic.item_locations[location_name]["Paths"]
@@ -590,13 +587,14 @@ def change_hardcoded_item_in_rel(self, path, offset, item_id):
590587
rel = self.get_rel(path)
591588
rel.write_data(write_u8, offset, item_id)
592589

593-
def change_chest_item(self, arc_path, chest_index, layer, item_id):
590+
def change_chest_item(self, arc_path, chest_index, layer, item_id, world_id=0):
594591
if arc_path.endswith("Stage.arc"):
595592
dzx = self.get_arc(arc_path).get_file("stage.dzs")
596593
else:
597594
dzx = self.get_arc(arc_path).get_file("room.dzr")
598595
chest = dzx.entries_by_type_and_layer("TRES", layer)[chest_index]
599596
chest.item_id = item_id
597+
chest.world_id = 1
600598
chest.save_changes()
601599

602600
def change_event_item(self, arc_path, event_index, actor_index, action_index, item_id):

0 commit comments

Comments
 (0)