Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Insert Nayuta no Kiseki item.tbl
- # To run, need itemdata.csv from the dump tool (with English text this time)
- # Max name length is 23 (extra truncated)
- # Max description length is 78 (extra truncated)
- # For item descriptions only 60 characters will display
- # 1. Put this script, item.orig (renamed item.tbl) and itemdata.csv
- # in same folder
- # 2. Run script
- # Output is itemdata.tbl (game format)
- import os
- def get_data(filename):
- totalbytes = os.path.getsize(filename)
- infile = open(filename, 'rb')
- totalfiledata = infile.read(totalbytes)
- infile.close()
- return totalfiledata
- def replacestr(origstr,replacestr,startpos,replacelen):
- #Returns a string with a replaced sub-string
- #origstr - the original string, replacestr = the string to replace
- #startpos - where the replacement string should go
- #replacelen - how many characters of the original string to replace
- return origstr[:startpos] + replacestr + origstr[startpos+replacelen:]
- filedata = get_data('item.orig')
- # Read input data
- inputdata = []
- with open('itemdata.csv','rb') as f:
- for line in f:
- line = line.translate(None,"\r\n") #Trims newline characters
- line = line.split('\t')
- if line[0] != "":
- addr = int(line[0],16)
- name = line[1]
- else:
- desc = line[1]
- inputdata.append((addr,name,desc))
- for addr, name, desc in inputdata:
- if len(name) > 23:
- print "Name %s at address %s len = %d, max len = 23, truncating" % \
- (name, hex(addr), len(name))
- name = name[:23]
- if len(desc) > 78:
- print ("Description %s at address %s len = %d, "
- "max len = 78, truncating" % (desc, hex(addr), len(desc)))
- desc = desc[:78]
- name = name + (23-len(name))*"\x00"
- desc = desc + (78-len(desc))*"\x00"
- filedata = replacestr(filedata,name,addr,23)
- filedata = replacestr(filedata,desc,addr + 0x18,78)
- outfile = open('item.tbl','wb')
- outfile.write(filedata)
- outfile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement