-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssDumper.py
145 lines (134 loc) · 4.38 KB
/
ssDumper.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# -*- coding: utf-8 -*-
# For Windows OS Only....
import sys
import os
import glob
import struct
import unicodedata
from Decryption import Decrypt
class Header:
headerData=b''
headerList=[]
length=0
index=0
count=0
offset=0
dataCount=0
def __init__(H,f):
f.seek(0)
H.length=struct.unpack('I',f.read(4))[0]
H.headerData=f.read(128)
H.headerList=struct.unpack('32I',H.headerData)
H.index=H.headerList[2]
H.count=H.headerList[3]
H.offset=H.headerList[4]
H.dataCount=H.headerList[5]
def Check(scr):
for char in scr:
if unicodedata.east_asian_width(char)!='Na':
return True
return False
def main(argv):
if argv.count('-a')>0:
noDump=True
argv.remove('-a')
else:
noDump=False
if argv.count('-d')>0:
copyLine=True
argv.remove('-d')
else:
copyLine=False
if argv.count('-x')>0:
xlsxMode=True
import openpyxl
argv.remove('-x')
else:
xlsxMode=False
if argv.count('-s')>0:
singleXlsx=True
argv.remove('-s')
else:
singleXlsx=False
if len(argv)<2 or argv[1]=='':
print ("Usage: "+argv[0][argv[0].rfind("\\")+1:]+" <Scene\> [Text\] [-a] [-c] [-x] [-s]")
return False
inF=argv[1]+"\\"
if len(argv)<3 or argv[2]=='':
outF=argv[0][:argv[0].rfind("\\")+1]+argv[1][argv[1].rfind("\\")+1:]+"_out\\"
else:
outF=argv[0][:argv[0].rfind("\\")+1]+argv[2]+"\\"
if not singleXlsx and not os.path.exists(outF):
os.makedirs(outF)
if xlsxMode and singleXlsx:
workBook=openpyxl.Workbook()
outXLS=outF[:outF.rfind("\\")].replace(".xlsx","")+".xlsx"
for inFN in glob.glob(inF+"*.ss"):
print(inFN)
if xlsxMode:
name=inFN[inFN.rfind("\\")+1:]
sheet=name[:31]
if not singleXlsx:
outXLS=outF+inFN[inFN.rfind("\\")+1:]+".xlsx"
workBook=openpyxl.Workbook()
workSheet=workBook.active
workSheet.title=sheet
else:
workSheet=workBook.create_sheet(sheet)
workSheet.column_dimensions['A'].width=8
workSheet.column_dimensions['B'].width=64
workSheet.column_dimensions['C'].width=64
if name!=sheet:
tempName=name
else:
tempName=""
workSheet.append(["Index","Text","Translation",tempName])
else:
outFN=outF+inFN[inFN.rfind("\\")+1:]+".txt"
output=open(outFN,'w',1,"UTF-8")
size=os.path.getsize(inFN)
file=open(inFN,'rb')
header=Header(file)
file.seek(header.index)
offset=[]
length=[]
for n in range(0,header.count):
offset.append(struct.unpack('I',file.read(4))[0])
length.append(struct.unpack('I',file.read(4))[0])
for x in range(0,header.count):
if length[x]==0:
continue
file.seek(header.offset+offset[x]*2,0)
string=file.read(length[x]*2)
text=Decrypt(string,length[x],x).decode("UTF-16")
if not Check(text) and not noDump:
continue
if xlsxMode:
if copyLine:
workSheet.append([x,text,text])
else:
workSheet.append([x,text])
else:
if copyLine:
outLine="○"+'%.6d'%x+"○"+text+"\n●"+'%.6d'%x+"●"+text+"\n\n"
else:
outLine="○"+'%.6d'%x+"○"+text+"\n●"+'%.6d'%x+"●\n\n"
output.write(outLine)
file.close()
if xlsxMode:
textLine=workSheet.max_row
if textLine==1 and singleXlsx:
workBook.remove(workSheet)
elif textLine>1 and not singleXlsx:
workBook.save(outXLS)
else:
output.close()
if os.path.getsize(outFN)==0:
os.remove(outFN)
if singleXlsx:
print("Saving xlsx file...")
workBook.remove(workBook['Sheet'])
workBook.save(outXLS)
return True
if __name__=="__main__":
main(sys.argv)