Advertisement
einstein95

DS No-Intro Header Patcher

May 10th, 2014
484
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.58 KB | None | 0 0
  1. import binascii,os,re,subprocess,sys,urllib,urllib2,zipfile
  2.  
  3. def CRC32_from_file(filename):
  4.     buf = open(filename,'rb').read()
  5.     buf = (binascii.crc32(buf) & 0xFFFFFFFF)
  6.     return "%08X" % buf
  7.  
  8. ds_file = sys.argv[1]
  9.  
  10. crc32 = CRC32_from_file(ds_file)
  11. print crc32
  12.  
  13. req = urllib2.Request('http://nds.hordeofninjas.com/Header%20Fix/')
  14. opener = urllib2.build_opener()
  15. opener.addheaders =[('User-Agent','Mozilla/5.0 (Windows NT 6.2; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0'),
  16.                     ('Connection','keep-alive')]
  17.  
  18. try:
  19.     res = opener.open(req)
  20. except urllib2.HTTPError:
  21.     httperror = 1
  22.     exit
  23. html = res.read()
  24.  
  25. link = re.findall("href=\"(.+?_Old-"+crc32+"_to.+)\">",html,re.IGNORECASE)
  26. try:
  27.     link = 'http://nds.hordeofninjas.com/Header%20Fix/'+link.pop()
  28. except IndexError:
  29.     print 'No patch found'
  30.     sys.exit()
  31.  
  32. file_name = link.split('/')[-1]
  33. file = open(file_name, 'wb')
  34. res = opener.open(link).read()
  35. file.write(res)
  36. file.close()
  37.  
  38. zipfile.ZipFile(file_name).extractall()
  39. subprocess.call('del '+file_name, shell=True)
  40.  
  41. patch = re.findall('(.+?)\.zip',file_name).pop()
  42. ds_file = re.findall('(.+?)\.nds',ds_file).pop()
  43.  
  44. if os.path.exists(patch+'.xdelta3'):
  45.     subprocess.call('xdelta30u.exe -d -s "'+ds_file+'.nds" "'+patch+'.xdelta3" "'+ds_file+'_patch.nds"', shell=True)
  46.     subprocess.call('del '+patch+'.xdelta3', shell=True)
  47. elif os.path.exists(patch+'.xdelta'):
  48.     subprocess.call('xdelta30u.exe -d -s "'+ds_file+'.nds" "'+patch+'.xdelta" "'+ds_file+'_patch.nds"', shell=True)
  49.     subprocess.call('del '+patch+'.xdelta', shell=True)
  50. else:
  51.     print crap
  52.  
  53. print 'Done '+ds_file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement