I finally debugged this for myself. I have python 3.x installed, and since python is a piece of :poop:, they aren't backwards compatible with older scripts. And it doesn't work in THREE different ways.
1) Some syntax is screwed up with on of the comments.
So you have to right-click the strings_bin_converter.py file and open as a txt file with notepad or something, comment out the "[B]print 'Converting file '+filepath+'('+str(i)+' of '+str(len(arr))+')'[/B]" line with a "[B]#[/B]" so that it looks like this:
[B]#print 'Converting file '+filepath+'('+str(i)+' of '+str(len(arr))+')'[/B]
They are just comments so I didn't feel like learning how to fix it, you'll know it worked when you see a bunch of new files pop up in the text directory. :thumbsup2 but if you want to figure it out, its probably something to do with the changes to the 'str' function between python 2 and python 3.
2) [B]os.listdir(''):[/B] Doesn't work the way it did in python 2.x apparently, but thats ok you can copy-paste in the complete directory of your data/text folder, mines in steam:
[B]os.listdir('C:/Program Files (x86)/Steam/steamapps/common/Medieval II Total War/data/text'):[/B]
Next you'll get an error about 'unicode' not being defined.
To fix this replace the instances where you find '[B]unicode[/B]' with '[B]str[/B]'.
[B]fw.write(str(struct.pack('HH',0xFFFE,0xAC00),'UTF-16')+'\r\n')
tagstr += str(f.read(2), 'UTF-16')
screenstr += str(tempstr, 'UTF-16')[/B]
My entire file that seems to work for me:
[SPOILER][CODE]# strings_bin_converter.py (c) 2006 Stefan Reutter (alias alpaca)
# Version 0.72
# A script to convert a number of MTW2 .strings.bin files to their .txt counterparts
import sys
import codecs
import struct
import os
def convertFile(filepath):
"""
Takes a type 2 .strings.bin file and converts it to a text file
"""
f = open(filepath+'.strings.bin', 'rb')
(style1,) = struct.unpack('h',f.read(2))
(style2,) = struct.unpack('h', f.read(2))
if style1 == 2 and style2 == 2048:
fw = codecs.open(filepath, encoding='UTF-16', mode='w')
fw.write(str(struct.pack('HH',0xFFFE,0xAC00),'UTF-16')+'\r\n')
(length,) = struct.unpack('i',f.read(4))
for string in range(length):
(strlen,) = struct.unpack('h', f.read(2))
tagstr = ''
for i in range(strlen):
tagstr += str(f.read(2), 'UTF-16')
(strlen,) = struct.unpack('h', f.read(2))
screenstr = ''
for i in range(strlen):
tempstr = f.read(2)
(e,) = struct.unpack('H',tempstr)
if e == 10:
screenstr += '\\n'
else:
screenstr += str(tempstr, 'UTF-16')
fw.write('{'+tagstr+'}'+screenstr+'\r\n')
fw.close()
f.close()
if sys.argv[1] == 'all':
arr = []
i = 1
#for filepath in os.listdir(''):
for filepath in os.listdir('C:/Program Files (x86)/Steam/steamapps/common/Medieval II Total War/data/text'):
if filepath.find('.strings.bin') > -1:
arr.append(filepath.split('.strings.bin')[0])
for filepath in arr:
#print 'Converting file '+filepath+'('+str(i)+' of '+str(len(arr))+')'
convertFile(filepath)
i+=1
else:
for i in range(len(sys.argv)-1):
path = sys.argv[i+1]
convertFile(path)[/CODE][/SPOILER]