Advertisement
Guest User

ED3 DAT Pack v1

a guest
May 12th, 2015
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.53 KB | None | 0 0
  1. import os
  2. import struct
  3. import glob
  4. import sys
  5.  
  6. hdr_index = []                          #Read the index file data
  7. with open('hdrspec.csv','rb') as f:
  8.     for line in f:
  9.         line = line.translate(None,'\r\n')
  10.         line = line.split(',')
  11.         line[1] = int(line[1])
  12.         hdr_index.append(line)
  13.  
  14. def dat_pack(filename):
  15.     for filename1, hdrlen in hdr_index:     #Find header length
  16.         if filename1 == filename + '.DAT':
  17.             break
  18.     else:
  19.         print 'File not in index.'
  20.         quit()
  21.  
  22.     with open(filename + '.DAT','wb') as f:     #Write new .DAT file
  23.         f.write('LB DAT\x1A\x00')               #Secret code
  24.         f.write(struct.pack('<I',hdrlen))       #Header length
  25.         f.write('\x00'*4)                       #Format spec
  26.         start_of_data = hdrlen*4 + 0x14         #Data start position
  27.         pos = start_of_data                     #Position counter
  28.         f.write(struct.pack('<I',start_of_data))    #Write 1st file location
  29.         for f1 in glob.glob(filename + '\\' + '*.dat'): #Loop thru .dat files
  30.             pos += os.path.getsize(f1)          #Increment position counter
  31.             f.write(struct.pack('<I',pos))      #Write position of next file
  32.         while f.tell() < start_of_data:         #Write 00 until start of data
  33.             f.write('\x00'*4)
  34.         for f1 in glob.glob(filename + '\\' + '*.dat'):     #Loop again
  35.             with open(f1,'rb') as g:            #Write each file in succession
  36.                 f.write(g.read())
  37.  
  38. dat_pack(sys.argv[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement