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 codecs
- 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:]
- TEXT_COL = 2
- filedata = get_data('item.orig')
- # Read input data
- inputdata = []
- with codecs.open('itemdata.tsv','rb', encoding = 'utf-8') as f:
- linecount = 1
- for line in f:
- ## print linecount
- line = line.rstrip('\r\n').split('\t')
- if line[0] != "":
- addr = int(line[0],16)
- name = line[TEXT_COL].encode('cp932')
- else:
- desc = line[TEXT_COL].encode('cp932')
- inputdata.append((addr,name,desc))
- linecount += 1
- 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) > 63:
- print ("Description %s at address %s len = %d, "
- "max len = 78, truncating" % (desc, hex(addr), len(desc)))
- desc = desc[:63]
- name = name + '\x00' + '\xfd' * (24 - len(name) - 1)
- desc = desc + '\x00' + '\xfd' * (64 - len(desc) - 1)
- filedata = replacestr(filedata,name,addr,24)
- filedata = replacestr(filedata,desc,addr + 0x18,64)
- outfile = open('item.tbl','wb')
- outfile.write(filedata)
- outfile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement