fix CRC computation

master
Lucent 2023-10-11 11:51:12 +02:00
parent 8e97e2b000
commit 355c2cff9e
2 changed files with 22 additions and 19 deletions

17
GUI.py
View File

@ -20,11 +20,15 @@ tt_SectorShuffle = ' Randomly shuffle the arrangement of the Sectors. '
tt_HideItems = ' Make all items appear as ? tanks. ' tt_HideItems = ' Make all items appear as ? tanks. '
generating = False generating = False
def fileHash(file): def fileHash(fileName):
checksum = 0 with open(fileName, 'rb') as fh:
return checksum hash = 0
# WARNING: Decompyle incomplete while True:
s = fh.read(65536)
if not s:
break
hash = zlib.crc32(s, hash)
return hash & 0xFFFFFFFF
def rando_thread(window = None, values = None): def rando_thread(window = None, values = None):
global failedgen, randoerror, generating, fileName, basegame, failedgen, randoerror, generating, finishGenerating global failedgen, randoerror, generating, fileName, basegame, failedgen, randoerror, generating, finishGenerating
@ -236,8 +240,7 @@ def main_window(debug):
ui.popup('Please select a Metroid Fusion (U) rom.', title='No source rom selected') ui.popup('Please select a Metroid Fusion (U) rom.', title='No source rom selected')
if basegame != None and basegame != '': if basegame != None and basegame != '':
checksum = fileHash(basegame) checksum = fileHash(basegame)
# if checksum != 1819625372: if checksum != 1819625372:
if checksum != 0:
ui.popup('Only Metroid Fusion (U) is supported.\nCheck the CRC32 value: it should be 6C75479C', title='Bad Checksum') ui.popup('Only Metroid Fusion (U) is supported.\nCheck the CRC32 value: it should be 6C75479C', title='Bad Checksum')
else: else:
values.update({ values.update({

View File

@ -18,12 +18,15 @@ version = '0.11.6'
def ceiling(num, denom): def ceiling(num, denom):
return -(num // -denom) return -(num // -denom)
def fileHash(fileName):
def fileHash(file): with open(fileName, 'rb') as fh:
checksum = 0 hash = 0
return checksum while True:
# WARNING: Decompyle incomplete s = fh.read(65536)
if not s:
break
hash = zlib.crc32(s, hash)
return (hash & 0xFFFFFFFF)
def enable_item(graph, item): def enable_item(graph, item):
globals()[item] = True globals()[item] = True
@ -4665,8 +4668,7 @@ def patch_game():
# FIXME: windows? # FIXME: windows?
os.system(os.path.join('.', 'flips', 'flips') + ' --apply ' + os.path.join('.', 'data', 'MFOR.bps') + ' "' + BaseName + '" "'+ os.path.join('.', 'seeds', '{}.gba'.format(FileName)) + '"') os.system(os.path.join('.', 'flips', 'flips') + ' --apply ' + os.path.join('.', 'data', 'MFOR.bps') + ' "' + BaseName + '" "'+ os.path.join('.', 'seeds', '{}.gba'.format(FileName)) + '"')
checksum = fileHash(os.path.join('.', 'seeds', '{}.gba'.format(FileName))) checksum = fileHash(os.path.join('.', 'seeds', '{}.gba'.format(FileName)))
# if checksum != 0x92561217L: if checksum != 2455114263:
if checksum != 0:
os.remove(os.path.join('.', 'seeds', '{}.gba'.format(FileName))) os.remove(os.path.join('.', 'seeds', '{}.gba'.format(FileName)))
print('Error: Base patch file has been modified. Please go to https://metroidconstruction.com/ and re-download MFOR.') print('Error: Base patch file has been modified. Please go to https://metroidconstruction.com/ and re-download MFOR.')
sys.exit(1) sys.exit(1)
@ -4688,16 +4690,14 @@ def start_randomizer(rom, settings):
print('Error: no base game provided.') print('Error: no base game provided.')
sys.exit(1) sys.exit(1)
checksum = fileHash(BaseGame) checksum = fileHash(BaseGame)
# if checksum != 1819625372: if checksum != 1819625372:
if checksum != 0:
print('Only Metroid Fusion (U) is supported. Check the CRC32 value: it should be 6C75479C') print('Only Metroid Fusion (U) is supported. Check the CRC32 value: it should be 6C75479C')
sys.exit(1) sys.exit(1)
Debug = settings['Debug'] Debug = settings['Debug']
settings.pop('Debug') settings.pop('Debug')
if Debug == False: if Debug == False:
checksum = fileHash(os.path.join('.', 'data', 'MFOR.bps')) checksum = fileHash(os.path.join('.', 'data', 'MFOR.bps'))
# if checksum != 558161692: if checksum != 558161692:
if checksum != 0:
print('Error: Base patch file has been modified. Please go to https://metroidconstruction.com/ and re-download MFOR.') print('Error: Base patch file has been modified. Please go to https://metroidconstruction.com/ and re-download MFOR.')
sys.exit(1) sys.exit(1)
totalRandoTime = time.time() totalRandoTime = time.time()