forked from KatDevsGames/z3randomizer
-
Notifications
You must be signed in to change notification settings - Fork 6
/
keydropshuffle.asm
225 lines (197 loc) · 6.02 KB
/
keydropshuffle.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
org $06926e ; <- 3126e - sprite_prep.asm : 2664 (LDA $0B9B : STA $0CBA, X)
jsl SpriteKeyPrep : nop #2
org $06d049 ; <- 35049 sprite_absorbable : 31-32 (JSL Sprite_DrawRippleIfInWater : JSR Sprite_DrawAbsorbable)
jsl SpriteKeyDrawGFX : bra + : nop : +
org $06d180
jsl BigKeyGet : bcs $07 : nop #5
org $06d18d ; <- 3518D - sprite_absorbable.asm : 274 (LDA $7EF36F : INC A : STA $7EF36F)
jsl KeyGet
org $06f9f3 ; bank06.asm : 6732 (JSL Sprite_LoadProperties)
jsl LoadProperties_PreserveItemMaybe
org $06d23a
Sprite_DrawAbsorbable:
org $1eff81
Sprite_DrawRippleIfInWater:
org $0db818
Sprite_LoadProperties:
org $288000 ;140000
ShuffleKeyDrops:
db 0
ShuffleKeyDropsReserved:
db 0
LootTable: ;PC: 140002
db $0e, $00, $24 ;; ice jelly key
db $13, $00, $24 ;; pokey 2
db $16, $00, $24 ;; swamp waterway pot
db $21, $00, $24 ;; key rat
db $35, $00, $24 ;; swamp trench 2 pot
db $36, $00, $24 ;; hookshot pot
db $37, $00, $24 ;; trench 1 pot
db $38, $00, $24 ;; pot row pot
db $39, $00, $24 ;; skull gibdo
db $3d, $00, $24 ;; gt minihelma
db $3e, $00, $24 ;; ice conveyor
db $3f, $00, $24 ;; ice hammer block ??? is this a dungeon secret?
db $43, $00, $24 ;; tiles 2 pot
db $53, $00, $24 ;; beamos hall pot
db $56, $00, $24 ;; skull west lobby pot
db $63, $00, $24 ;; desert tiles 1 pot
db $71, $00, $24 ;; boomerang guard
db $72, $00, $24 ;; hc map guard
db $7b, $00, $24 ;; gt star pits pot
db $80, $00, $32 ;; a big key (for the current dungeon)
db $8b, $00, $24 ;; gt conv cross block
db $9b, $00, $24 ;; gt dlb switch pot
db $9f, $00, $24 ;; ice many pots
db $99, $00, $24 ;; eastern eyegore
db $a1, $00, $24 ;; mire fishbone pot
db $ab, $00, $24 ;; tt spike switch pot
db $b0, $00, $24 ;; tower circle of pots usain
db $b3, $00, $24 ;; mire spikes pot
db $b6, $00, $24 ;; pokey 1
db $ba, $00, $24 ;; eastern dark pot
db $bc, $00, $24 ;; tt hallway pot
db $c0, $00, $24 ;; tower dark archer
db $c1, $00, $24 ;; mire glitchy jelly
db $ff, $00, $ff
;140068
KeyTable:
db $a0, $a0, $a2, $a3, $a4, $a5, $a6, $a7, $a8, $a9, $aa, $ab, $ac, $ad
KeyDropItemEncrypted:
db $00, $00, $00, $00, $00, $00, $00, $00
db $00, $00, $00, $00, $00, $00, $00, $00
db $00, $00, $00, $00, $00, $00, $00, $00
db $00, $00, $00, $00, $00, $00, $00, $00
db $00, $00, $00, $00, $00, $00, $00, $00
KeyDropPlayerEncrypted:
db $00, $00, $00, $00, $00, $00, $00, $00
db $00, $00, $00, $00, $00, $00, $00, $00
db $00, $00, $00, $00, $00, $00, $00, $00
db $00, $00, $00, $00, $00, $00, $00, $00
db $00, $00, $00, $00, $00, $00, $00, $00
SpriteKeyPrep:
{
lda $0b9b : sta $0cba, x ; what we wrote over
pha
lda.l ShuffleKeyDrops : bne + : pla : rtl : + phx
lda.l IsEncrypted : beq .decrypted
ldx #$ff
- inx #1 : lda.l LootTable, x : cmp #$ff : beq ++ : cmp $a0 : bne -
php : rep #$30 : lda $00 : pha : lda $02 : pha
lda.w #KeyDropPlayerEncrypted : sta $00
lda.w #KeyDropPlayerEncrypted>>16 : sta $02
txa : jsl RetrieveValueFromEncryptedTable : and.w #$00FF : sta !MULTIWORLD_SPRITEITEM_PLAYER_ID
lda.w #KeyDropItemEncrypted : sta $00
lda.w #KeyDropItemEncrypted>>16 : sta $02
txa : jsl RetrieveValueFromEncryptedTable : and.w #$00FF
plx : stx $02 : plx : stx $00 : plp
bra ++++
.decrypted
ldx #$fd
- inx #3 : lda.l LootTable, x : cmp #$ff : beq ++ : cmp $a0 : bne -
inx : lda.l LootTable, x : sta !MULTIWORLD_SPRITEITEM_PLAYER_ID
inx : lda.l LootTable, x
++++ plx : sta $0e80, x
cmp #$24 : bne +++
lda $a0 : cmp #$80 : bne + : lda #$24
+++ jsl PrepDynamicTile : bra +
++ plx : lda #$24 : sta $0e80, x
pla
rtl
}
SpriteKeyDrawGFX:
{
jsl Sprite_DrawRippleIfInWater
pha
lda.l ShuffleKeyDrops : bne +
- pla
phk : pea.w .jslrtsreturn-1
pea.w $068014 ; an rtl address - 1 in Bank06
jml Sprite_DrawAbsorbable
.jslrtsreturn
rtl
+ lda $0e80, x
cmp #$24 : bne +
lda $a0 : cmp #$80 : bne - : lda #$24
+ jsl DrawDynamicTile ; see DrawHeartPieceGFX if problems
cmp #$03 : bne +
pha : lda $0e60, x : ora.b #$20 : sta $0E60, x : pla
+
jsl.l Sprite_DrawShadowLong
pla : rtl
}
KeyGet:
{
lda $7ef36f ; what we wrote over
pha
lda.l ShuffleKeyDrops : bne +
- pla : rtl
+ ldy $0e80, x
lda $a0 : cmp #$87 : bne +
jsr ShouldKeyBeCountedForDungeon : bcc -
jsl CountChestKeyLong : bra -
+ sty $00
jsr KeyGetPlayer : sta !MULTIWORLD_ITEM_PLAYER_ID
lda !MULTIWORLD_ITEM_PLAYER_ID : bne .receive
phx
lda $040c : lsr : tax
lda $00 : CMP.l KeyTable, x : bne +
- JSL.l FullInventoryExternal : jsl CountChestKeyLong : plx : pla : rtl
+ cmp #$af : beq - ; universal key
cmp #$24 : beq - ; small key for this dungeon
plx
.receive
jsl.l $0791b3 ; Player_HaltDashAttackLong
jsl.l Link_ReceiveItem
pla : dec : rtl
}
; Input Y - the item type
ShouldKeyBeCountedForDungeon:
{
phx
lda $040c : lsr : tax
tya : cmp KeyTable, x : bne +
- plx : sec : rts
+ cmp #$24 : beq -
plx : clc : rts
}
BigKeyGet:
{
lda.l ShuffleKeyDrops : bne +
- stz $02e9 : ldy.b #$32 ; what we wrote over
phx : jsl Link_ReceiveItem : plx ; what we wrote over
clc : rtl
+
ldy $0e80, x
cpy #$32 : beq -
+ sec : rtl
}
KeyGetPlayer:
{
phx
lda.l IsEncrypted : beq .decrypted
ldx #$ff
- inx #1 : lda.l LootTable, x : cmp #$ff : beq ++ : cmp $a0 : bne -
++ php : rep #$30 : lda $00 : pha : lda $02 : pha
lda.w #KeyDropPlayerEncrypted : sta $00
lda.w #KeyDropPlayerEncrypted>>16 : sta $02
txa : jsl RetrieveValueFromEncryptedTable : and.w #$00FF
plx : stx $02 : plx : stx $00 : plp
plx
rts
.decrypted
ldx #$fd
- inx #3 : lda.l LootTable, x : cmp #$ff : beq ++ : cmp $a0 : bne -
++ inx : lda.l LootTable, x
plx
rts
}
LoadProperties_PreserveItemMaybe:
{
lda.l ShuffleKeyDrops : bne +
jsl Sprite_LoadProperties : rtl
+ lda $0e80, x : pha
jsl Sprite_LoadProperties
pla : sta $0e80, x
rtl
}