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. '
generating = False
def fileHash(file):
checksum = 0
return checksum
# WARNING: Decompyle incomplete
def fileHash(fileName):
with open(fileName, 'rb') as fh:
hash = 0
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):
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')
if basegame != None and basegame != '':
checksum = fileHash(basegame)
# if checksum != 1819625372:
if checksum != 0:
if checksum != 1819625372:
ui.popup('Only Metroid Fusion (U) is supported.\nCheck the CRC32 value: it should be 6C75479C', title='Bad Checksum')
else:
values.update({

View File

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