SHARE
TWEET

CC Level Splicer

quiznos00 May 22nd, 2016 (edited) 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. in_name = raw_input('Input file name?: ')
  2. with open(in_name) as f:
  3.     for i, l in enumerate(f):
  4.         pass
  5. input_f = open(in_name,'r')    
  6. out_name = raw_input('Output file name?: ')
  7.  
  8. levels = input_f.read().split('\n')
  9. output_buffer = b'\xac\xaa\x02\x00' + chr(i + 1)+ b'\x00'
  10.  
  11. failed = False
  12.  
  13. for x in levels:
  14.     pair = x.split('\t')
  15.     level_f = open(pair[0],'rb')
  16.     level_f.seek(4, 0)
  17.     num_levels = ord(level_f.read(1)) + 256*ord(level_f.read(1))
  18.     while (True):
  19.         lb = level_f.read(1) + level_f.read(1)
  20.         ln = level_f.read(1) + level_f.read(1)
  21.         num_bytes = ord(lb[0]) + ord(lb[1])*256
  22.         level_num = ord(ln[0]) + ord(ln[1])*256
  23.         if (level_num == int(pair[1])):
  24.             level_bytes = level_f.read(num_bytes-2)
  25.             output_buffer += (lb + ln + level_bytes)
  26.             break
  27.         level_f.seek(num_bytes-2,1)
  28.         if (level_num == num_levels):
  29.             failed = True
  30.             break
  31.     level_f.close()
  32.    
  33. input_f.close()
  34.  
  35. if (not failed):
  36.     output_f = open(out_name,'wb')
  37.     output_f.write(output_buffer)
  38.     output_f.close()
  39.     print "Success"
  40. else:
  41.     print "Failure"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top