Guest User

ACLR Test Patcher

a guest
Sep 16th, 2016
43
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os
  2. import shutil
  3. import subprocess
  4. import tempfile
  5. import zlib
  6.  
  7. #Make a copy of AC.BIN
  8. if os.path.isfile('AC.orig'):
  9.     pass
  10. elif os.path.isfile('AC.BIN'):
  11.     shutil.copy('AC.BIN', 'AC.orig')
  12. else:
  13.     print('File AC.BIN not found.')
  14.     quit()
  15.  
  16. #Extract file and decompress
  17. with open('AC.orig', 'rb') as f:
  18.     with tempfile.NamedTemporaryFile(delete = False) as g:
  19.         tempfilename = g.name
  20.         f.seek(0x6CC000)
  21.         g.write(zlib.decompress(f.read(25553321)))
  22. #Apply patch using xdelta
  23. patched = '006cc000.BIN'
  24. subprocess.run(['xdelta', '-d', '-s', tempfilename, '006cc000.xdelta', patched])
  25. #Delete temporary file
  26. os.remove(tempfilename)
  27. #Compress and insert patched file
  28. with open('AC.orig', 'rb') as f:
  29.     with open('AC.BIN', 'wb') as g:
  30.         g.write(f.read(0x6CC000))                   #Copy up to our patched file
  31.         with open(patched, 'rb') as h:              #Compress and write our patched file
  32.             g.write(zlib.compress(h.read()))
  33.         g.write(b'\x00' * (0x01faa800 - g.tell()))  #Write zeros up to start of next file
  34.         f.seek(0x01faa800)                          #Align file pointer
  35.         g.write(f.read())                           #Copy the rest of the file
  36. #os.remove(patched)
RAW Paste Data