|
appeal
新手上路

积分 12
发帖 4
注册 2007-9-19
状态 离线
|
『楼 主』:
如何将txt转成bin文件?
利用Python 2.5加下面的程序,把bin转成了txt文件,但是修改后不知道应该怎么转回bin文件.请高手帮忙.
# 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(unicode(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 += unicode(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 += unicode(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(''):
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)



[ Last edited by appeal on 2007-9-19 at 05:29 PM ]
|
|
2007-9-19 15:41 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第
2 楼』:
python也能到这里提问,不错不错很有前途。
请问楼主这里的Python是否DGJPP在DOS下的编译版本?
|

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>" |
|
2007-9-19 16:43 |
|
|
appeal
新手上路

积分 12
发帖 4
注册 2007-9-19
状态 离线
|
『第
3 楼』:
又上传了3个贴图,高手这回能理解了吗?我把txt.strings.bin用python和那个小程序转成了txt文件,给游戏做了汉化,现在想转回去txt.strings.bin,不知道该怎么办.
|
|
2007-9-19 17:33 |
|
|
lp1129
初级用户
 
积分 186
发帖 92
注册 2007-3-27
状态 离线
|
『第
4 楼』:
贴图可以直接以附件上传的,不用外链
|
|
2007-9-19 23:06 |
|
|
lp1129
初级用户
 
积分 186
发帖 92
注册 2007-3-27
状态 离线
|
『第
5 楼』:
可以肯定,转回BIN格式基本上就不能用了,这样做汉化,不太好用
|
|
2007-9-19 23:09 |
|
|
appeal
新手上路

积分 12
发帖 4
注册 2007-9-19
状态 离线
|
『第
6 楼』:
就算这样,翻译内容是固定的,也算没白翻译.请问这里面的txt.strings.bin和txt要怎么相互转换?为什么转回去就不能用了呢?
|
|
2007-9-19 23:45 |
|
|
jackwu
初级用户
 
积分 45
发帖 22
注册 2007-9-13
状态 离线
|
|
2007-9-28 10:35 |
|
|