forked from iFatRain/pokemon-crystal-map-randomizer
/
randomizeROM.py
631 lines (536 loc) · 29 KB
/
randomizeROM.py
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
import time
import links_and_nodes.johto_all_warp_points
import links_and_nodes.kanto_all_warp_points
import links_and_nodes.johto_node_containers as Johto
import links_and_nodes.kanto_node_containers as Kanto
from links_and_nodes.johto_all_warp_points_dict import buildJohtoWarpLinks
from links_and_nodes.johto_node_dictionary_containers import buildJohtoMajorNodes, buildJohtoHubs, buildJohtoImportantDeadEnds, buildJohtoReachableDeadEnds, buildJohtoUselessDeadEnds, buildJohtoCorridors
from links_and_nodes.kanto_all_warp_points_dict import buildKantoWarpLinks
from links_and_nodes.kanto_node_dictionary_containers import buildKantoMajorNodes, buildKantoHubNodes, buildKantoImportantDeadEnds, buildKantoUselessDeadEnds, buildKantoCorridors
from logic import AutomaticWarpLocator
from logic.MemoryAddressReader import buildMemoryLocationsFromSym
from logic.DictionaryRandomizerLogic import randomizationStep1, randomizationStep2, randomizationStep3, randomizationStep4, \
checkJohtoCompletability, randomizationStep5, checkKantoCompletability, checkFullCompletability
from class_definitions import WarpInstruction, getHex
# def randomizeWarps(combinedRegions, addNewBark):
# print("Randomizing..")
# if combinedRegions:
# combinedFullyCompletable = False
# while combinedFullyCompletable is False:
# if addNewBark:
# print("ADDING NEWBARK")
# randomizedNodes = randomizationStep1(list(Johto.MajorNodes_Johto) + list(Kanto.MajorNodes_Kanto))
# else:
# randomizedNodes = randomizationStep1(list(Johto.MajorNodes_Johto) + list(Kanto.MajorNodes_Kanto))
# randomizedNodes = randomizationStep2(randomizedNodes, list(Johto.HubNodes_Johto) + list(Kanto.HubNodes_Kanto))
# randomizedNodes = randomizationStep3(randomizedNodes,
# list(Johto.ImportantDeadEndNodes_Johto) + list(Kanto.ImportantDeadEndNodes_Kanto),
# list(Johto.ReachableUselessDeadEndNodes_Johto) + list(Kanto.ReachableUselessDeadEndNodes_Kanto),
# list(Johto.UnreachableUselessDeadEndNodes_Johto) + list(Kanto.UnreachableUselessDeadEndNodes_Kanto))
# randomizedNodes = randomizationStep4(randomizedNodes)
# randomizedNodes = randomizationStep5(randomizedNodes, list(Johto.TwoWayCorridorNodes_Johto) + list(Kanto.TwoWayCorridorNodes_Kanto))
# combinedFullyCompletable = checkFullCompletability(randomizedNodes)
#
#
#
#
#
# else:
# johtoFullyCompletable = False
# while johtoFullyCompletable is False:
# randomizedJohto = randomizationStep1(list(Johto.MajorNodes_Johto))
# randomizedJohto = randomizationStep2(randomizedJohto, list(Johto.HubNodes_Johto))
# randomizedJohto = randomizationStep3(randomizedJohto, list(Johto.ImportantDeadEndNodes_Johto),
# list(Johto.ReachableUselessDeadEndNodes_Johto),
# list(Johto.UnreachableUselessDeadEndNodes_Johto))
# randomizedJohto = randomizationStep4(randomizedJohto)
# randomizedJohto = randomizationStep5(randomizedJohto, list(Johto.TwoWayCorridorNodes_Johto))
# johtoFullyCompletable = checkJohtoCompletability(randomizedJohto)
#
# kantoFullyCompletable = False
# while kantoFullyCompletable is False:
# randomizedKanto = randomizationStep1(list(Kanto.MajorNodes_Kanto))
# randomizedKanto = randomizationStep2(randomizedKanto, list(Kanto.HubNodes_Kanto))
# randomizedKanto = randomizationStep3(randomizedKanto, list(Kanto.ImportantDeadEndNodes_Kanto),
# list(Kanto.ReachableUselessDeadEndNodes_Kanto),
# list(Kanto.UnreachableUselessDeadEndNodes_Kanto))
# randomizedKanto = randomizationStep4(randomizedKanto)
# randomizedKanto = randomizationStep5(randomizedKanto, list(Kanto.TwoWayCorridorNodes_Kanto))
#
#
# kantoFullyCompletable = checkKantoCompletability(randomizedKanto)
#
# randomizedNodes = randomizedJohto + randomizedKanto
#
#
#
# return randomizedNodes
def randomizeWarpsNew(combinedRegions,unrandomMart):
print("Randomizing..")
if combinedRegions:
combinedFullyCompletable = False
while combinedFullyCompletable is False:
randomizedNodes = randomizationStep1(dict(**buildJohtoMajorNodes(unrandomMart),**buildKantoMajorNodes()))
randomizedNodes = randomizationStep2(randomizedNodes, dict(**buildJohtoHubs(),**buildKantoHubNodes()))
randomizedNodes = randomizationStep3(randomizedNodes,
dict(**buildJohtoImportantDeadEnds(unrandomMart),**buildKantoImportantDeadEnds()),
dict(**buildJohtoReachableDeadEnds()),
dict(**buildJohtoUselessDeadEnds(),**buildKantoUselessDeadEnds()))
randomizedNodes = randomizationStep4(randomizedNodes)
randomizedNodes = randomizationStep5(randomizedNodes, dict(**buildJohtoCorridors(),**buildKantoCorridors()))
combinedFullyCompletable = checkFullCompletability(randomizedNodes)
else:
johtoFullyCompletable = False
while johtoFullyCompletable is False:
randomizedJohto = randomizationStep1(buildJohtoMajorNodes(unrandomMart))
randomizedJohto = randomizationStep2(randomizedJohto, buildJohtoHubs())
randomizedJohto = randomizationStep3(randomizedJohto, buildJohtoImportantDeadEnds(unrandomMart),
buildJohtoReachableDeadEnds(),
buildJohtoUselessDeadEnds())
randomizedJohto = randomizationStep4(randomizedJohto)
randomizedJohto = randomizationStep5(randomizedJohto, buildJohtoCorridors())
johtoFullyCompletable = checkJohtoCompletability(randomizedJohto)
kantoFullyCompletable = False
while kantoFullyCompletable is False:
randomizedKanto = randomizationStep1(buildKantoMajorNodes())
randomizedKanto = randomizationStep2(randomizedKanto, buildKantoHubNodes())
randomizedKanto = randomizationStep3(randomizedKanto, buildKantoImportantDeadEnds(),
dict(),
buildKantoUselessDeadEnds())
randomizedKanto = randomizationStep4(randomizedKanto)
randomizedKanto = randomizationStep5(randomizedKanto, buildKantoCorridors())
kantoFullyCompletable = checkKantoCompletability(randomizedKanto)
randomizedNodes = randomizedJohto + randomizedKanto
return randomizedNodes
def checkForDoubles(inputLink, inputROM, warpLocations, johtoWarps):
if inputLink.OWN == johtoWarps.get("Ruins_Of_Alph_Ho_Oh_Chamber_Links").get("RUINS_OF_ALPH_HO_OH_CHAMBER_TO_RUINS_OF_ALPH_INNER_CHAMBER_2_LINK").OWN:
print("Fixing Ho Oh Chamber Double!")
standardLink = johtoWarps.get("Ruins_Of_Alph_Ho_Oh_Item_Room_Links")
inputROM.seek(warpLocations[standardLink.get("RUINS_OF_ALPH_HO_OH_ITEM_ROOM_TO_RUINS_OF_ALPH_HO_OH_WORD_ROOM_1_LINK").MEMORY_ORIGIN]
+ standardLink.get("RUINS_OF_ALPH_HO_OH_ITEM_ROOM_TO_RUINS_OF_ALPH_HO_OH_WORD_ROOM_1_LINK").OFFSET)
inputROM.write(WarpInstruction.getInstruction(inputLink.LINK.value))
inputROM.read(2)
inputROM.write(WarpInstruction.getInstruction(inputLink.LINK.value))
print("Done Fixing Ho Oh Double")
if inputLink.OWN == johtoWarps.get("Ruins_Of_Alph_Kabuto_Chamber_Links").get("RUINS_OF_ALPH_KABUTO_CHAMBER_TO_RUINS_OF_ALPH_INNER_CHAMBER_4_LINK").OWN:
print("Fixing Kabuto Chamber Double!")
standardLink = johtoWarps.get("Ruins_Of_Alph_Kabuto_Item_Room_Links")
inputROM.seek(warpLocations[standardLink.get("RUINS_OF_ALPH_KABUTO_ITEM_ROOM_TO_RUINS_OF_ALPH_KABUTO_WORD_ROOM_1_LINK").MEMORY_ORIGIN]
+ standardLink.get("RUINS_OF_ALPH_KABUTO_ITEM_ROOM_TO_RUINS_OF_ALPH_KABUTO_WORD_ROOM_1_LINK").OFFSET)
inputROM.write(WarpInstruction.getInstruction(inputLink.LINK.value))
inputROM.read(2)
inputROM.write(WarpInstruction.getInstruction(inputLink.LINK.value))
print("Done Fixing Kabuto Double")
if inputLink.OWN == johtoWarps.get("Ruins_Of_Alph_Aerodactyl_Chamber_Links").get("RUINS_OF_ALPH_AERODACTYL_CHAMBER_TO_RUINS_OF_ALPH_INNER_CHAMBER_8_LINK").OWN:
print("Fixing Aero Chamber Double!")
standardLink = johtoWarps.get("Ruins_Of_Alph_Aerodactyl_Item_Room_Links")
inputROM.seek(warpLocations[standardLink.get("RUINS_OF_ALPH_AERODACTYL_ITEM_ROOM_TO_RUINS_OF_ALPH_AERODACTYL_WORD_ROOM_1_LINK").MEMORY_ORIGIN]
+ standardLink.get("RUINS_OF_ALPH_AERODACTYL_ITEM_ROOM_TO_RUINS_OF_ALPH_AERODACTYL_WORD_ROOM_1_LINK").OFFSET)
inputROM.write(WarpInstruction.getInstruction(inputLink.LINK.value))
inputROM.read(2)
inputROM.write(WarpInstruction.getInstruction(inputLink.LINK.value))
print("Done Fixing Aero Double")
if inputLink.OWN == johtoWarps.get("Ruins_Of_Alph_Omanyte_Chamber_Links").get("RUINS_OF_ALPH_OMANYTE_CHAMBER_TO_RUINS_OF_ALPH_INNER_CHAMBER_6_LINK").OWN:
print("Fixing Omanyte Chamber Double!")
standardLink = johtoWarps.get("Ruins_Of_Alph_Omanyte_Item_Room_Links")
inputROM.seek(warpLocations[standardLink.get("RUINS_OF_ALPH_OMANYTE_ITEM_ROOM_TO_RUINS_OF_ALPH_OMANYTE_WORD_ROOM_1_LINK").MEMORY_ORIGIN]
+ standardLink.get("RUINS_OF_ALPH_OMANYTE_ITEM_ROOM_TO_RUINS_OF_ALPH_OMANYTE_WORD_ROOM_1_LINK").OFFSET)
inputROM.write(WarpInstruction.getInstruction(inputLink.LINK.value))
inputROM.read(2)
inputROM.write(WarpInstruction.getInstruction(inputLink.LINK.value))
print("Done Fixing Omanyte Double")
if inputLink.OWN == johtoWarps.get("Tin_Tower_1F_Links").get("TIN_TOWER_1F_TO_ECRUTEAK_CITY_LINK").OWN:
print("Fixing Rear Stairs of Tin Tower 1F")
standardLink = johtoWarps.get("Tin_Tower_1F_Links")
inputROM.seek(warpLocations[standardLink.get("TIN_TOWER_1F_TO_ECRUTEAK_CITY_LINK").MEMORY_ORIGIN] + 10)
inputROM.write(WarpInstruction.getInstruction(inputLink.LINK.value))
print("Done fixing Rear Stairs for Tin Tower")
def reassignWarp(inputROM, link, memLocation, locationOfWarpScript, bytesToFind):
inputROM.seek(memLocation - 2)
y_coord = inputROM.read(1)
x_coord = inputROM.read(1)
dest_map = WarpInstruction.getInstruction(link.OWN.value)[1::]
inputROM.seek(locationOfWarpScript)
script = inputROM.read(150)
dynamicOffset = script.find(bytesToFind)
inputROM.seek(locationOfWarpScript + dynamicOffset)
inputROM.seek(locationOfWarpScript + dynamicOffset)
inputROM.write(dest_map)
inputROM.write(x_coord)
inputROM.write(y_coord)
inputROM.seek(locationOfWarpScript + dynamicOffset)
def directConnectRed(inputROM, warpLocations, johtoWarps, kantoWarps):
link = johtoWarps.get("Victory_Road_Gate_Links").get("VICTORY_ROAD_GATE_TO_ROUTE_28_2_LINK")
inputROM.seek(warpLocations[link.MEMORY_ORIGIN] + link.OFFSET)
inputROM.write(WarpInstruction.getInstruction(link.LINK.value))
if link.DUAL_WIDTH is True:
inputROM.read(2)
inputROM.write(WarpInstruction.getInstruction(link.LINK.value))
link = kantoWarps.get("Silver_Cave_Room_3_Links").get("SILVER_CAVE_ROOM_3_TO_SILVER_CAVE_ROOM_2_2_LINK")
inputROM.seek(warpLocations[link.MEMORY_ORIGIN] + link.OFFSET)
inputROM.write(WarpInstruction.getInstruction(link.LINK.value))
if link.DUAL_WIDTH is True:
inputROM.read(2)
inputROM.write(WarpInstruction.getInstruction(link.LINK.value))
def randomizeROM(inputROM, settings, customPath):
startTime = time.time()
print("Randomizing Warps..")
randomizedNodes = randomizeWarpsNew(settings[2],settings[9])
rom = inputROM.read()
lookupDict = AutomaticWarpLocator.getLookupDict()
warpLocations = dict()
for key in lookupDict.keys():
foundLocation = rom.find(lookupDict[key])
warpLocations[key] = foundLocation + 5
scriptLocations = buildMemoryLocationsFromSym(settings[0], customPath)
# for key in warpLocations.keys():
# print(key, " is at ",hex(warpLocations.get(key)))
johtoWarps = buildJohtoWarpLinks()
kantoWarps = buildKantoWarpLinks()
print("Writing New Warps to ROM...")
for node in randomizedNodes:
for link in node[1].LINKS:
memLocation = warpLocations[link.MEMORY_ORIGIN] + link.OFFSET
inputROM.seek(memLocation)
inputROM.write(WarpInstruction.getInstruction(link.LINK.value))
if link.DUAL_WIDTH is True:
inputROM.read(2)
inputROM.write(WarpInstruction.getInstruction(link.LINK.value))
checkForDoubles(link, inputROM, warpLocations, johtoWarps)
#TODO investigate these with the changed speedchoice
if link.LINK == johtoWarps.get("Ecruteak_Gym_Links").get("ECRUTEAK_GYM_TO_ECRUTEAK_CITY_LINK").OWN:
print("REASSIGNING ECRUTEAK KICKOUT WARP")
reassignWarp(inputROM, link, memLocation, scriptLocations["EcruteakGymClosed"], b'\x04\t\x06\x1b')
if link.LINK == johtoWarps.get("Slowpoke_Well_B1F_Links").get("SLOWPOKE_WELL_B1F_TO_AZALEA_TOWN_LINK").OWN:
print("REASSIGNING SLOWPOKE WELL WARP")
reassignWarp(inputROM, link, memLocation, scriptLocations["TrainerGruntM1.Script"], b'\x08\x04\x03\x03')
directConnectRed(inputROM, warpLocations, johtoWarps, kantoWarps)
randomizeTime = time.time() - startTime
print("Time to randomize warps and write to ROM:", randomizeTime,"seconds")
writeWarpRandoNonOptionalChanges(inputROM, warpLocations, scriptLocations, settings)
if settings[1]:
enableLegendaries(inputROM, warpLocations, scriptLocations,settings)
if settings[3]:
disableDarkMode(inputROM, warpLocations)
if settings[4]:
doMapChanges(inputROM, warpLocations, scriptLocations)
reduceVisibilityDragonsDen(inputROM, warpLocations, scriptLocations)
if settings[5]:
catchEmAllBoi(inputROM, warpLocations,scriptLocations)
if settings[6]:
presolveAlphRuins(inputROM, warpLocations, scriptLocations)
if settings[7]:
removeRivalInMoon(inputROM, warpLocations, scriptLocations)
if settings[8]:
changeGoldenrodRockets(inputROM, warpLocations, scriptLocations)
#Starter levels will always be final script
if settings[-1]:
print("\tMaking starters lv100 for testing")
inputROM.seek(scriptLocations["CyndaquilPokeBallScript"])
inputROM.write(bytes.fromhex(getHex(98)))
inputROM.seek(scriptLocations["TotodilePokeBallScript"])
inputROM.write(bytes.fromhex(getHex(98)))
inputROM.seek(scriptLocations["ChikoritaPokeBallScript"])
inputROM.write(bytes.fromhex(getHex(98)))
#For testing custom scripts/warps
# inputROM.seek(warpLocations["CherrygroveCity"])
# inputROM.write(bytes.fromhex(getHex(1)))
# inputROM.write(bytes.fromhex(getHex(3)))
# inputROM.write(bytes.fromhex(getHex(30)))
inputROM.close()
return randomizedNodes
def reduceVisibilityDragonsDen(inputROM, warpLocations, scriptLocations):
# 1 byte of filler (1)
# 1 count byte, 2 warp events 1 + (1 + 5 + 5) = 12
# 1 count event, 1 co-ord event 12 + (1 + 8) = 21
# 1 count byte, 4 bg_events 21 + (1 + (4 * 5)) = 42
# 1 count event, Skip 3 object events 42 + (1 + (3 * 13)) = 82
# Skip to 11th byte for sight range 82 + 9?? = 91
inputROM.seek(scriptLocations["DragonsDenB1F_MapEvents"] + 91)
#Finding 1626049, expecting 1626040 (+11?)
# Should default to 4
value = inputROM.read(1)
inputROM.seek(scriptLocations["DragonsDenB1F_MapEvents"] + 91)
inputROM.write(bytes.fromhex(getHex(3)))
def removeRivalInMoon(inputROM, warpLocations, scriptLocations):
print("Removing Mt.Moon Rival Fight")
inputROM.seek(scriptLocations["InitializeEventsScript"] + 213)
inputROM.write(bytes.fromhex(getHex(164)))
inputROM.write(bytes.fromhex(getHex(7)))
inputROM.seek(scriptLocations["MountMoon_MapScripts"] + 1)
inputROM.write(bytes.fromhex(getHex(141)))
inputROM.seek(warpLocations["MountMoon"] + 52) # Rival mt moon
inputROM.write(bytes.fromhex(getHex(9)))
inputROM.write(bytes.fromhex(getHex(7)))
def writeWarpRandoNonOptionalChanges(inputROM, warpLocations, scriptLocations, settings):
inputROM.seek(scriptLocations["No_Biking"])
inputROM.write(bytes.fromhex(getHex(8)))
inputROM.seek(scriptLocations["BikeFunction"])
inputROM.write(bytes.fromhex(getHex(0)))
#Makes the Goldenrod B1F basement door always open so you aren't blocked
inputROM.seek(scriptLocations["GoldenrodB1FDoorUnlock"])
inputROM.write(bytes.fromhex(getHex(9)))
inputROM.write(bytes.fromhex(getHex(7)))
#Makes slowpoke guard walk left/right so you aren't blocked
inputROM.seek(warpLocations["AzaleaTown"] + 113)
inputROM.write(bytes.fromhex(getHex(2)))
inputROM.write(bytes.fromhex(getHex(1)))
# print("Mahogany: ", hex(warpLocations["MahoganyTown"]))
inputROM.seek(warpLocations["MahoganyTown"] + 25)
inputROM.write(bytes.fromhex(getHex(7)))
inputROM.read(7)
inputROM.write(bytes.fromhex(getHex(7)))
inputROM.read(30)
inputROM.write(bytes.fromhex(getHex(17)))
# print("Rt32: ", hex(warpLocations["Route32"]))
inputROM.seek(warpLocations["Route32"] + 21)
inputROM.write(bytes.fromhex(getHex(11)))
print("\tDisabling E4 Walking")
inputROM.seek(scriptLocations["KogasRoom_EnterMovement"])
inputROM.write(bytes.fromhex(getHex(71)))
inputROM.seek(scriptLocations["KarensRoom_EnterMovement"])
inputROM.write(bytes.fromhex(getHex(71)))
inputROM.seek(scriptLocations["WillsRoom_EnterMovement"])
inputROM.write(bytes.fromhex(getHex(71)))
inputROM.seek(scriptLocations["BrunosRoom_EnterMovement"])
inputROM.write(bytes.fromhex(getHex(71)))
inputROM.seek(scriptLocations["LancesRoom_EnterMovement"])
inputROM.write(bytes.fromhex(getHex(71)))
print("\tOpening All E4 Doors")
inputROM.seek(scriptLocations["KogasDoorLocksBehindYou"])
inputROM.write(bytes.fromhex(getHex(2)))
inputROM.write(bytes.fromhex(getHex(22)))
inputROM.seek((scriptLocations["KarensDoorLocksBehindYou"]))
inputROM.write(bytes.fromhex(getHex(2)))
inputROM.write(bytes.fromhex(getHex(22)))
inputROM.seek((scriptLocations["WillsDoorLocksBehindYou"]))
inputROM.write(bytes.fromhex(getHex(2)))
inputROM.write(bytes.fromhex(getHex(22)))
inputROM.seek((scriptLocations["BrunosDoorLocksBehindYou"]))
inputROM.write(bytes.fromhex(getHex(2)))
inputROM.write(bytes.fromhex(getHex(22)))
inputROM.seek(scriptLocations["LancesDoorLocksBehindYou"])
inputROM.read(1)
inputROM.write(bytes.fromhex(getHex(49)))
inputROM.seek(scriptLocations["KogasRoomDoors"])
inputROM.write(bytes.fromhex(getHex(2)))
inputROM.write(bytes.fromhex(getHex(22)))
inputROM.seek((scriptLocations["KarensRoomDoors"]))
inputROM.write(bytes.fromhex(getHex(2)))
inputROM.write(bytes.fromhex(getHex(22)))
inputROM.seek((scriptLocations["WillsRoomDoors"]))
inputROM.write(bytes.fromhex(getHex(2)))
inputROM.write(bytes.fromhex(getHex(22)))
inputROM.seek((scriptLocations["BrunosRoomDoors"]))
inputROM.write(bytes.fromhex(getHex(2)))
inputROM.write(bytes.fromhex(getHex(22)))
inputROM.seek(scriptLocations["LancesRoomDoors"])
inputROM.read(1)
inputROM.write(bytes.fromhex(getHex(49)))
print("\tFixing Champions Room Tile Collision")
inputROM.seek(scriptLocations["TilesetChampionsRoomColl"])
inputROM.write(bytes.fromhex(getHex(112)))
inputROM.write(bytes.fromhex(getHex(112)))
print("\tUnlocking Basement without Keycard")
inputROM.seek(scriptLocations['LockBasementDoor'])
inputROM.write(bytes.fromhex(getHex(46)))
print("\tMaking Director Always Appear in Underground Warehouse")
inputROM.seek(warpLocations['GoldenrodUndergroundWarehouse'] + 66)
inputROM.write(bytes.fromhex(getHex(255)))
inputROM.write(bytes.fromhex(getHex(255)))
print(hex(scriptLocations["DirectorKeycard"]))
inputROM.seek(scriptLocations["DirectorKeycard"])
inputROM.write(bytes.fromhex(getHex(0)))
# Remove Right Guard from Victory Road Gate
print("\tFixing Victory Road Gate")
if "Pokemon - Crystal Speedchoice" in settings[0]:
print("Detected Speedchoice offset of 91")
inputROM.seek(warpLocations["VictoryRoadGate"] + 86)
else:
inputROM.seek(warpLocations["VictoryRoadGate"] + 90)
print("Going to offset of 95")
inputROM.write(bytes.fromhex(getHex(26)))
inputROM.write(bytes.fromhex(getHex(0)))
print("\t Removing Rocks from Above")
inputROM.seek(scriptLocations["InitializeEventsScript"])
inputROM.write(bytes.fromhex(getHex(9)))
inputROM.read(2)
inputROM.write(bytes.fromhex(getHex(10)))
inputROM.read(2)
inputROM.write(bytes.fromhex(getHex(11)))
inputROM.read(2)
inputROM.write(bytes.fromhex(getHex(12)))
print("\t Making lower alph usable")
inputROM.seek(scriptLocations["RuinsOfAlphOutside_Blocks"])
inputROM.write(bytes.fromhex(getHex(90)))
inputROM.read(8)
inputROM.write(bytes.fromhex(getHex(90)))
print("\t Making Victory Road Usable")
inputROM.seek(scriptLocations["VictoryRoad_Blocks"])
inputROM.write(bytes.fromhex(getHex(2)))
inputROM.read(6)
inputROM.write(bytes.fromhex(getHex(2)))
def changeGoldenrodRockets(inputROM, warpLocations, scriptLocations):
print("Moving Goldenrod Rockets", hex(warpLocations["GoldenrodCity"]))
inputROM.seek(warpLocations["GoldenrodCity"] + 229)
inputROM.write(bytes.fromhex(getHex(7)))
inputROM.write(bytes.fromhex(getHex(2)))
inputROM.write(bytes.fromhex(getHex(17)))
inputROM.read(9)
inputROM.write(bytes.fromhex(getHex(21)))
inputROM.write(bytes.fromhex(getHex(33)))
inputROM.write(bytes.fromhex(getHex(2)))
inputROM.write(bytes.fromhex(getHex(70)))
inputROM.read(11)
inputROM.write(bytes.fromhex(getHex(2)))
inputROM.write(bytes.fromhex(getHex(16)))
inputROM.read(10)
inputROM.write(bytes.fromhex(getHex(24)))
inputROM.write(bytes.fromhex(getHex(2)))
inputROM.write(bytes.fromhex(getHex(66)))
inputROM.read(9)
inputROM.write(bytes.fromhex(getHex(31)))
inputROM.write(bytes.fromhex(getHex(37)))
inputROM.write(bytes.fromhex(getHex(2)))
inputROM.write(bytes.fromhex(getHex(67)))
inputROM.read(9)
inputROM.write(bytes.fromhex(getHex(14)))
inputROM.write(bytes.fromhex(getHex(32)))
inputROM.write(bytes.fromhex(getHex(2)))
inputROM.write(bytes.fromhex(getHex(34)))
inputROM.read(9)
inputROM.write(bytes.fromhex(getHex(16)))
inputROM.write(bytes.fromhex(getHex(24)))
inputROM.write(bytes.fromhex(getHex(2)))
inputROM.write(bytes.fromhex(getHex(51)))
def AddressToIntValues(address):
bank_size = 0x4000
value = (address % bank_size) + bank_size
bytes_return = value.to_bytes(2, byteorder='little')
return bytes_return
def enableLegendaries(inputROM, warpLocations, scriptLocations, settings):
print("\tEnabling Always Catchable Setting")
lugiaAppearAddress = scriptLocations["LugiaAddress"]
lugia_appear_bytes_result = AddressToIntValues(lugiaAppearAddress)
inputROM.seek(scriptLocations["LugiaToggle"])
inputROM.write(lugia_appear_bytes_result)
inputROM.seek(warpLocations["WhirlIslandLugiaChamber"] + 7)
inputROM.write(bytes.fromhex(getHex(15)))
#Change ho-oh, different in each version
if "1.1" in settings[0]:
print("Doing Vanilla Ho-OH")
inputROM.seek(scriptLocations["HoOhToggle"])
inputROM.write(bytes.fromhex(getHex(62)))
elif "Speedchoice" in settings[0]:
#inputROM.seek(scriptLocations["HoOhToggleE4"])
#noE4Address = scriptLocations["NoE4Address"]
#e4_bytes_result = AddressToIntValues(noE4Address)
appearAddress = scriptLocations["HoOhAddress"]
appear_bytes_result = AddressToIntValues(appearAddress)
# Convert appear address to bytes from the label it jumps to, and use this!
inputROM.seek(scriptLocations["HoOhToggle"])
#If user does not have Rainbow Wing check, replace NoAppear with Appear
inputROM.write(appear_bytes_result)
inputROM.seek(scriptLocations["HoOhToggleE4"])
#If user has not beaten E4, jump to NoE4 Check -- where checks if Ho-Oh already beaten
inputROM.write(appear_bytes_result)
print("Done Enabling Legendaries")
def presolveAlphRuins(inputROM, warpLocations, scriptLocations):
print("Fixing the Ruins of Alph FLoors")
print("Fixing Aero")
inputROM.seek(scriptLocations["RuinsOfAlphAerodactylChamber_MapScripts.FloorClosed"])
inputROM.write(bytes.fromhex(getHex(24)))
inputROM.read(3)
inputROM.write(bytes.fromhex(getHex(25)))
print("Fixing HoOh")
inputROM.seek(scriptLocations["RuinsOfAlphHoOhChamber_MapScripts.FloorClosed"])
inputROM.write(bytes.fromhex(getHex(24)))
inputROM.read(3)
inputROM.write(bytes.fromhex(getHex(25)))
print("Fixing Omanyte")
inputROM.seek(scriptLocations["RuinsOfAlphOmanyteChamber_MapScripts.FloorClosed"])
inputROM.write(bytes.fromhex(getHex(24)))
inputROM.read(3)
inputROM.write(bytes.fromhex(getHex(25)))
print("Fixing Kabuto")
inputROM.seek(scriptLocations["RuinsOfAlphKabutoChamber_MapScripts.FloorClosed"])
inputROM.write(bytes.fromhex(getHex(24)))
inputROM.read(3)
inputROM.write(bytes.fromhex(getHex(25)))
def doMapChanges(inputROM, warpLocations, scriptLocations):
print("\t Vermillion Map Block Changes")
inputROM.seek(scriptLocations["VermilionCity_Blocks"])
inputROM.write(bytes.fromhex(getHex(97)))
print("\t Mortar Map Block Changes")
inputROM.seek(scriptLocations["MountMortar2FInside_Blocks"])
inputROM.write(bytes.fromhex(getHex(2)))
print("\t Blackthorn Map Block Changes")
inputROM.seek(scriptLocations["BlackthornCity_Blocks"])
inputROM.write(bytes.fromhex(getHex(111))) # 6F
inputROM.write(bytes.fromhex(getHex(114))) # 72
inputROM.write(bytes.fromhex(getHex(109)))
inputROM.write(bytes.fromhex(getHex(113)))
inputROM.write(bytes.fromhex(getHex(111))) # 6F
inputROM.write(bytes.fromhex(getHex(114))) # 6C
inputROM.read(14)
inputROM.write(bytes.fromhex(getHex(105)))
inputROM.read(4)
inputROM.write(bytes.fromhex(getHex(2)))
inputROM.write(bytes.fromhex(getHex(2)))
inputROM.write(bytes.fromhex(getHex(2)))
inputROM.write(bytes.fromhex(getHex(71))) # 47
inputROM.read(11)
inputROM.write(bytes.fromhex(getHex(109))) # 6D
inputROM.write(bytes.fromhex(getHex(105)))
inputROM.write(bytes.fromhex(getHex(2)))
inputROM.write(bytes.fromhex(getHex(2)))
inputROM.write(bytes.fromhex(getHex(2)))
inputROM.write(bytes.fromhex(getHex(2)))
inputROM.read(14)
inputROM.write(bytes.fromhex(getHex(113)))
inputROM.write(bytes.fromhex(getHex(105)))
inputROM.write(bytes.fromhex(getHex(2))) # 69
inputROM.read(17)
inputROM.write(bytes.fromhex(getHex(113)))
inputROM.write(bytes.fromhex(getHex(105)))
inputROM.write(bytes.fromhex(getHex(2)))
inputROM.read(17)
inputROM.write(bytes.fromhex(getHex(113))) # 71
inputROM.write(bytes.fromhex(getHex(105)))
inputROM.write(bytes.fromhex(getHex(2))) # 71
inputROM.read(17)
inputROM.write(bytes.fromhex(getHex(113))) # 71
inputROM.write(bytes.fromhex(getHex(105)))
inputROM.write(bytes.fromhex(getHex(2))) # 71
inputROM.read(17)
inputROM.write(bytes.fromhex(getHex(113))) # 71
inputROM.read(28)
inputROM.write(bytes.fromhex(getHex(75))) # 71
inputROM.read(39)
inputROM.write(bytes.fromhex(getHex(90))) # 71
inputROM.read(16)
inputROM.write(bytes.fromhex(getHex(90))) # 71
inputROM.read(2)
inputROM.write(bytes.fromhex(getHex(90))) # 71
inputROM.seek(warpLocations["BlackthornCity"] + 56)
inputROM.write(bytes.fromhex(getHex(23)))
def catchEmAllBoi(inputROM, warpLocations, scriptLocations):
print("\tMaking Aides Give Pokeballs")
inputROM.seek(scriptLocations["AideScript_GivePotion"])
inputROM.write(bytes.fromhex(getHex(5)))
inputROM.write(bytes.fromhex(getHex(5)))
def disableDarkMode(inputROM, warpLocations):
print("Removing Flash Requirement in Dark Caves")
# print(hex(warpLocations["DungeonsMapGroup"] +587)) #write 12, read 8, 9 times then read 35, then write, read 8, write, then read 72, write, read 8 , write
inputROM.seek(warpLocations["DungeonsMapGroup"] + 586)
for i in range(9):
inputROM.write(bytes.fromhex(getHex(18)))
inputROM.read(8)
inputROM.read(27)
inputROM.write(bytes.fromhex(getHex(18)))
inputROM.read(8)
inputROM.write(bytes.fromhex(getHex(18)))
inputROM.read(71)
inputROM.write(bytes.fromhex(getHex(18)))
inputROM.read(8)
inputROM.write(bytes.fromhex(getHex(18)))