Guest User

Nayuta Item Insert v1

a guest
Oct 25th, 2014
321
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Insert Nayuta no Kiseki item.tbl
  2. # To run, need itemdata.csv from the dump tool (with English text this time)
  3. # Max name length is 23 (extra truncated)
  4. # Max description length is 78 (extra truncated)
  5. # For item descriptions only 60 characters will display
  6. # 1. Put this script, item.orig (renamed item.tbl) and itemdata.csv
  7. #    in same folder
  8. # 2. Run script
  9. # Output is itemdata.tbl (game format)
  10.  
  11. import os
  12.  
  13. def get_data(filename):
  14.     totalbytes = os.path.getsize(filename)
  15.     infile = open(filename, 'rb')
  16.     totalfiledata = infile.read(totalbytes)
  17.     infile.close()
  18.     return totalfiledata
  19.  
  20. def replacestr(origstr,replacestr,startpos,replacelen):
  21. #Returns a string with a replaced sub-string
  22. #origstr - the original string, replacestr = the string to replace
  23. #startpos - where the replacement string should go
  24. #replacelen - how many characters of the original string to replace
  25.     return origstr[:startpos] + replacestr + origstr[startpos+replacelen:]
  26.  
  27. filedata = get_data('item.orig')
  28.  
  29. # Read input data
  30. inputdata = []
  31. with open('itemdata.csv','rb') as f:
  32.     for line in f:
  33.         line = line.translate(None,"\r\n") #Trims newline characters
  34.         line = line.split('\t')
  35.         if line[0] != "":
  36.             addr = int(line[0],16)
  37.             name = line[1]
  38.         else:
  39.             desc = line[1]
  40.             inputdata.append((addr,name,desc))
  41.  
  42. for addr, name, desc in inputdata:
  43.     if len(name) > 23:
  44.         print "Name %s at address %s len = %d, max len = 23, truncating" % \
  45.               (name, hex(addr), len(name))
  46.         name = name[:23]
  47.     if len(desc) > 78:
  48.         print ("Description %s at address %s len = %d, "
  49.               "max len = 78, truncating" % (desc, hex(addr), len(desc)))
  50.         desc = desc[:78]
  51.     name = name + (23-len(name))*"\x00"
  52.     desc = desc + (78-len(desc))*"\x00"
  53.     filedata = replacestr(filedata,name,addr,23)
  54.     filedata = replacestr(filedata,desc,addr + 0x18,78)
  55.  
  56. outfile = open('item.tbl','wb')
  57. outfile.write(filedata)
  58. outfile.close()
RAW Paste Data