Downloads: strings_bin_converter 0.72

strings_bin_converter 0.72

Uploaded by alpaca - December 28, 2006
Author Author alpaca
File Size File Size 2.1 KB
Downloads Downloads 31,804
+ Download
This allows you to convert the unpacked .strings.bin files to .txt files.
It's especially useful if you have a non-English version of the game.

Images

None

Comments

juanguer
February 13, 2008 at 12:03 PM
In Clouds across europe there is no such thing as historic_events and vanila folder there in no TEXT folder!
NathanielBlack
June 14, 2009 at 11:51 AM
very nice!
thanks!
Wraith.
September 24, 2011 at 01:54 PM
Unfortunately:

Any advice how to deal with this?
Ramesses II The Great
December 26, 2011 at 08:17 PM
This file converter does not work =(
Sir Luock
February 06, 2012 at 10:46 AM
It does not work!
JulianusApostate
February 24, 2012 at 06:00 PM
You need to get Python first for it to work. It says so in the readme
Willowran
April 09, 2012 at 01:44 PM
I've downloaded python, installed, run the converter... and the .bin files are still .bin files. cmd prompt flashes for a second, vanishes, and nothing changes. Does the change not take place right away, or is there a glitch?
Willowran
April 09, 2012 at 01:50 PM
Willowran
April 09, 2012 at 01:52 PM
Willowran
April 09, 2012 at 01:55 PM

C:\Program Files\SEGA\Medieval II Total War\data\text>strings_bin_converter.py a
ll
Traceback (most recent call last):
File "C:\Program Files\SEGA\Medieval II Total War\data\text\strings_bin_conver
ter.py", line 42, in <module>
for filepath in os.listdir(''):
WindowsError: [Error 3] The system cannot find the path specified: ''

C:\Program Files\SEGA\Medieval II Total War\data\text>pause
Press any key to continue . . .

any help with this? command prompt pops up with this


Spoiler Alert, click show to read: 
sorry for the triple post...i deleted the previous three, but for some reason they're still there...
MrCrapsley
April 26, 2012 at 12:47 PM
^I have the exact same problem, any help would be very handy
Hoki
July 04, 2012 at 08:24 PM
I finally debugged this for myself. I have python 3.x installed, and since python is a piece of :wub:, 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 "print 'Converting file '+filepath+'('+str(i)+' of '+str(len(arr))+')'" line with a "#" so that it looks like this:
#print 'Converting file '+filepath+'('+str(i)+' of '+str(len(arr))+')'
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. 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) os.listdir(''): 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:
os.listdir('C:/Program Files (x86)/Steam/steamapps/common/Medieval II Total War/data/text'):


Next you'll get an error about 'unicode' not being defined.
To fix this replace the instances where you find 'unicode' with 'str'.
fw.write(str(struct.pack('HH',0xFFFE,0xAC00),'UTF-16')+'\r\n')
tagstr += str(f.read(2), 'UTF-16')
screenstr += str(tempstr, 'UTF-16')



My entire file that seems to work for me:

Spoiler Alert, click show to read: 
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)
Comradical
August 31, 2012 at 10:00 AM
^ Above solution didn't work,
xXGreavesXx
June 16, 2013 at 07:41 AM
Thanks Worked fine, You need PYTHON 2.5 You cannot get Old or newer versions. ONLY 2.5
sdfsokpo
November 02, 2013 at 03:25 AM
Thanks