forked from Yggdrasill-Moe/Niflheim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrld_text_output.py
112 lines (102 loc) · 2.82 KB
/
rld_text_output.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# -*- coding:utf-8 -*-
#用于导出rld文件的文本
#by Darkness-TX
#2017.11.17
import struct
import os
import sys
import io
def byte2int(byte):
long_tuple = struct.unpack('L',byte)
long = long_tuple[0]
return long
def int2byte(num):
return struct.pack('L',num)
def dumpstr(src):
bstr = b''
c = src.read(1)
while c != b'\x00':
bstr += c
c = src.read(1)
return bstr.decode('932')
def FormatString(string, count):
res = "○%08d○\n%s\n●%08d●\n%s\n\n"%(count, string, count, string)
return res
def ReadHeader(src):
tag = ''
magic = src.read(4)
ver = byte2int(src.read(4))
offset = byte2int(src.read(4))
count = byte2int(src.read(4))
flag = byte2int(src.read(4))
if flag == 1:
tag = dumpstr(src)
return magic, ver, offset, count, flag, tag
def Opcode_Analysis(src):
buff = byte2int(src.read(4))
op = buff & 0xFFFF
init_count = (buff & 0xFF0000) >> 16
str_count = (buff >> 24) & 0xF
unk = buff >> 28
return op, init_count, str_count, unk
def Get_Name_Table(dump_str):
names = {}
for l in dump_str:
group = l.split(',')
names[int(group[0])] = group[3]
return names
def rld_output(fname, name_table=[]):
print(fname)
src = open(os.path.join('rld', fname), 'rb')
magic, ver, offset, count, flag, tag = ReadHeader(src)
if magic != b'\00DLR':
print(fname + "不是支持的类型")
else:
src.seek(offset + 4, os.SEEK_SET)
dst = open(os.path.join('rld', fname[:-4] + '.txt'), 'w', encoding='utf16')
l = 0
dump_str = []
for i in range(0, count):
opcode, init_count, str_count, unk = Opcode_Analysis(src)
all_init = []
all_str =[]
for j in range(0, init_count):
val = src.read(4)
all_init.append(byte2int(val))
for k in range(0, str_count):
row = dumpstr(src)
all_str.append(row)
if opcode == 28:
if all_init[0] in name_table:
dst.write(FormatString(name_table[all_init[0]], l))
dump_str.append(name_table[all_init[0]])
l += 1
for string in all_str:
if string != '*' and string != '$noname$' and len(string) != 0 and string.count(',') < 2:
dst.write(FormatString(string, l))
dump_str.append(string)
l += 1
elif opcode == 21:
for string in all_str:
if string != '*' and string != '$noname$' and len(string) != 0 and string.count(',') < 2:
dst.write(FormatString(string, l))
dump_str.append(string)
l += 1
elif opcode == 48:
dst.write(FormatString(all_str[0], l))
dump_str.append(all_str[0])
l += 1
elif opcode == 191:
if len(all_str[0]) != len(all_str[0].encode('932')):
dst.write(FormatString(all_str[0], l))
dump_str.append(all_str[0])
l += 1
return dump_str
def main():
dump_str = rld_output('defChara.bin')
name_table = Get_Name_Table(dump_str)
for f in os.listdir('rld'):
if not f.endswith('.bin') or f == 'defChara.bin':
continue
rld_output(f, name_table)
main()