untangle patch_game

master
magical 2024-02-03 01:25:28 -08:00
parent afde644b38
commit 707a7b70a1
1 changed files with 219 additions and 237 deletions

View File

@ -2646,8 +2646,7 @@ def patch_game():
for line in symFile: for line in symFile:
x = line.split() x = line.split()
if len(x) > 1 and re.search('^[a-zA-Z]', x[1]): if len(x) > 1 and re.search('^[a-zA-Z]', x[1]):
sym.update({ sym.update({ x[1]: x[0][2:] })
x[1]: x[0][2:] })
os.remove(os.path.join('.', 'data', 'asm', 'temp.sym')) os.remove(os.path.join('.', 'data', 'asm', 'temp.sym'))
roomEventOffset = int(sym.get('t_bossanddownloadevents'), 16) roomEventOffset = int(sym.get('t_bossanddownloadevents'), 16)
itemEventOffset = int(sym.get('t_obtainitemevents'), 16) itemEventOffset = int(sym.get('t_obtainitemevents'), 16)
@ -2655,6 +2654,7 @@ def patch_game():
print('roomEventOffset: 0x{:06X}'.format(roomEventOffset)) print('roomEventOffset: 0x{:06X}'.format(roomEventOffset))
print('itemEventOffset: 0x{:06X}'.format(itemEventOffset)) print('itemEventOffset: 0x{:06X}'.format(itemEventOffset))
print('securityOffset: 0x{:06X}'.format(securityOffset)) print('securityOffset: 0x{:06X}'.format(securityOffset))
else:
roomEventOffset = 8326320 roomEventOffset = 8326320
itemEventOffset = 5726112 itemEventOffset = 5726112
securityOffset = 479192 securityOffset = 479192
@ -2729,6 +2729,7 @@ def patch_game():
blockValue += 1 blockValue += 1
clipValue = ItemList.index(itemName) clipValue = ItemList.index(itemName)
if clipValue < 2: if clipValue < 2:
# Energy Tank or Missile Tank
clipValue = clipValue ^ 99 clipValue = clipValue ^ 99
if 'Hidden' in nodeType: if 'Hidden' in nodeType:
clipValue += 2 clipValue += 2
@ -2741,7 +2742,7 @@ def patch_game():
elif 'Underwater' in nodeType: elif 'Underwater' in nodeType:
clipValue += 2 clipValue += 2
elif clipValue >= 3: elif clipValue >= 3:
clipValue = (clipValue - 3) * 3 + 120 clipValue = (clipValue - 3)*3 + 120
if 'Hidden' in nodeType: if 'Hidden' in nodeType:
clipValue += 1 clipValue += 1
elif 'Underwater' in nodeType: elif 'Underwater' in nodeType:
@ -2757,7 +2758,7 @@ def patch_game():
slot = BossDataList.index(name) slot = BossDataList.index(name)
roomEvent = roomEventOffset roomEvent = roomEventOffset
if roomEvent != None: if roomEvent != None:
roomEvent = roomEvent + 3 + slot * 4 roomEvent = roomEvent + 3 + slot*4
if itemValue < 3: if itemValue < 3:
itemValue += 1 itemValue += 1
else: else:
@ -2771,14 +2772,16 @@ def patch_game():
patchedGame.write(itemValue.to_bytes(1, 'little')) patchedGame.write(itemValue.to_bytes(1, 'little'))
if name == 'Data S5': if name == 'Data S5':
roomEvent = roomEventOffset roomEvent = roomEventOffset
roomEvent = roomEvent + 3 + (slot + 1) * 4 roomEvent = roomEvent + 3 + (slot + 1)*4
patchedGame.seek(roomEvent) patchedGame.seek(roomEvent)
patchedGame.write(itemValue.to_bytes(1, 'little')) patchedGame.write(itemValue.to_bytes(1, 'little'))
if itemName in MajorItems: if itemName in MajorItems:
offset = CreditsOffsets.get(itemName) offset = CreditsOffsets.get(itemName)
if 'Boss' in nodeType: if 'Boss' in nodeType:
location = name location = name
elif 'S0' in name: else:
if 'S0' in name:
location = 'Main Deck : ' location = 'Main Deck : '
else: else:
location = 'Sector {} : '.format(name[6:7]) location = 'Sector {} : '.format(name[6:7])
@ -2787,7 +2790,7 @@ def patch_game():
else: else:
location = location + nodeType + ' Room' location = location + nodeType + ' Room'
spaces = ceiling(30 - len(location), 2) spaces = ceiling(30 - len(location), 2)
location = ' ' * spaces + location location = ' '*spaces + location
patchedGame.seek(offset) patchedGame.seek(offset)
patchedGame.write(location.encode('ascii')) patchedGame.write(location.encode('ascii'))
for x in range(len(location), 35): for x in range(len(location), 35):
@ -2830,6 +2833,7 @@ def patch_game():
doorData = unpacked[0] - 134217728 doorData = unpacked[0] - 134217728
patchedGame.seek(doorData, 0) patchedGame.seek(doorData, 0)
doorNumber = 0 doorNumber = 0
while True:
connectionType = int.from_bytes(patchedGame.read(1), 'little') connectionType = int.from_bytes(patchedGame.read(1), 'little')
patchedGame.seek(5, 1) patchedGame.seek(5, 1)
offset = patchedGame.tell() offset = patchedGame.tell()
@ -2837,7 +2841,7 @@ def patch_game():
patchedGame.seek(5, 1) patchedGame.seek(5, 1)
resume = patchedGame.tell() resume = patchedGame.tell()
if connectionType == 0 and connectedDoor == 0: if connectionType == 0 and connectedDoor == 0:
continue break
sourceDoor = 'S{}-{:02X}'.format(currentArea, doorNumber) sourceDoor = 'S{}-{:02X}'.format(currentArea, doorNumber)
targetDoorStr = World.doorConnections.get(sourceDoor) targetDoorStr = World.doorConnections.get(sourceDoor)
connectedArea = World.areaConnections.get(sourceDoor, currentArea) connectedArea = World.areaConnections.get(sourceDoor, currentArea)
@ -2855,7 +2859,6 @@ def patch_game():
if areaByte != targetArea: if areaByte != targetArea:
patchedGame.seek(offset) patchedGame.seek(offset)
patchedGame.write(targetArea.to_bytes(1, 'little')) patchedGame.write(targetArea.to_bytes(1, 'little'))
continue
for target in World.patcher: for target in World.patcher:
value = World.patcher.get(target) value = World.patcher.get(target)
patchedGame.seek(target) patchedGame.seek(target)
@ -2875,6 +2878,7 @@ def patch_game():
iterable = diff_bytearrays(blocksize, sourcedata, targetdata) iterable = diff_bytearrays(blocksize, sourcedata, targetdata)
write_bps(bps_progress(iterable), patch) write_bps(bps_progress(iterable), patch)
print('') print('')
ItemNames = [ ItemNames = [
'Missile Data', 'Missile Data',
'Morph Ball', 'Morph Ball',
@ -2896,65 +2900,43 @@ def patch_game():
'Ice Beam'] 'Ice Beam']
if SeedSettings['RaceSeed'] == False: if SeedSettings['RaceSeed'] == False:
spoilerLog = dict() spoilerLog = dict()
spoilerLog.update({ spoilerLog.update({ 'MFOR Version': version })
'MFOR Version': version }) spoilerLog.update({ 'Seed': SeedValue })
spoilerLog.update({
'Seed': SeedValue })
settingsDict = dict() settingsDict = dict()
settingsDict.update({ settingsDict.update({ 'Difficulty': SeedSettings['Difficulty'] })
'Difficulty': SeedSettings['Difficulty'] })
if SeedSettings['MajorMinor'] == False: if SeedSettings['MajorMinor'] == False:
settingsDict.update({ settingsDict.update({ 'Item pool': 'Major items anywhere' })
'Item pool': 'Major items anywhere' })
else: else:
settingsDict.update({ settingsDict.update({ 'Item pool': 'Limited major item locations' })
'Item pool': 'Limited major item locations' }) settingsDict.update({ 'Missile upgrades enable Missiles': SeedSettings['MissilesWithoutMainData'] })
settingsDict.update({ settingsDict.update({ 'Power Bombs without normal Bombs': SeedSettings['PowerBombsWithoutBombs'] })
'Missile upgrades enable Missiles': SeedSettings['MissilesWithoutMainData'] }) settingsDict.update({ 'Allow logical damage runs': SeedSettings['DamageRuns'] })
settingsDict.update({ settingsDict.update({ 'Separated security levels': SeedSettings['SplitSecurity'] })
'Power Bombs without normal Bombs': SeedSettings['PowerBombsWithoutBombs'] }) settingsDict.update({ 'Sector shuffle': SeedSettings['SectorShuffle'] })
settingsDict.update({
'Allow logical damage runs': SeedSettings['DamageRuns'] })
settingsDict.update({
'Separated security levels': SeedSettings['SplitSecurity'] })
settingsDict.update({
'Sector shuffle': SeedSettings['SectorShuffle'] })
if SeedSettings['SectorShuffle'] == True: if SeedSettings['SectorShuffle'] == True:
sectorLayout = str() sectorLayout = str()
for x in areaLayout: for x in areaLayout:
sectorLayout = sectorLayout.strip() + ' {}'.format(x) sectorLayout = sectorLayout.strip() + ' {}'.format(x)
settingsDict.update({ settingsDict.update({ 'Sector layout:': sectorLayout })
'Sector layout:': sectorLayout }) settingsDict.update({ 'Hide item graphics': SeedSettings['HideItems'] })
settingsDict.update({ settingsDict.update({ 'E-Tanks': PlacedETanks })
'Hide item graphics': SeedSettings['HideItems'] }) settingsDict.update({ 'Missile Tanks': PlacedMissiles })
settingsDict.update({ settingsDict.update({ 'Power Bomb Tanks': PlacedPowerBombs })
'E-Tanks': PlacedETanks }) spoilerLog.update({ 'Settings': settingsDict })
settingsDict.update({
'Missile Tanks': PlacedMissiles })
settingsDict.update({
'Power Bomb Tanks': PlacedPowerBombs })
spoilerLog.update({
'Settings': settingsDict })
itemProgression = dict() itemProgression = dict()
for x in range(len(PlacedItems)): for x in range(len(PlacedItems)):
if PlacedItems[x] in MajorItems: if PlacedItems[x] in MajorItems:
namedItem = ItemNames[MajorItems.index(PlacedItems[x])] namedItem = ItemNames[MajorItems.index(PlacedItems[x])]
PlacedItems[x] = namedItem PlacedItems[x] = namedItem
itemProgression.update({ itemProgression.update({ UsedLocations[x]: PlacedItems[x] })
UsedLocations[x]: PlacedItems[x] }) spoilerLog.update({ 'Item order': itemProgression })
continue
spoilerLog.update({
'Item order': itemProgression })
itemDict = dict() itemDict = dict()
World.itemLocations.sort() World.itemLocations.sort()
for x in range(0, len(World.itemLocations)): for x in range(0, len(World.itemLocations)):
itemDict.update({ itemDict.update({ World.itemLocations[x]: 0 })
World.itemLocations[x]: 0 })
for x in range(0, len(PlacedItems)): for x in range(0, len(PlacedItems)):
itemDict.update({ itemDict.update({ UsedLocations[x]: PlacedItems[x] })
UsedLocations[x]: PlacedItems[x] }) spoilerLog.update({ 'Items': itemDict })
spoilerLog.update({
'Items': itemDict })
with open(os.path.join('.', 'spoilers', '{}.json'.format(FileName)), 'w') as spoiler: with open(os.path.join('.', 'spoilers', '{}.json'.format(FileName)), 'w') as spoiler:
json.dump(spoilerLog, spoiler, indent=4) json.dump(spoilerLog, spoiler, indent=4)