def main(argv): if len(argv) < 2 or argv[1] == '': print("Usage: " + argv[0][argv[0].rfind("\\") + 1:] + " <Scene\> [Text\]") 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 os.path.exists(outF): os.makedirs(outF) for inFN in glob.glob(inF + "*.ss"): print(inFN) outFN = outF + inFN[inFN.rfind("\\") + 1:] + ".txt" 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]) output = open(outFN, 'w', 1, "UTF-8") 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): continue outLine = "○" + '%.6d' % x + "○" + text + "\n●" + '%.6d' % x + "●" + text + "\n\n" output.write(outLine) file.close() output.close() if os.path.getsize(outFN) == 0: os.remove(outFN) return True
def main(argv): if argv.count('-db') > 0: dbLine = True argv.remove('-db') else: dbLine = False if argv.count('-q') > 0: quotChange = True argv.remove('-q') else: quotChange = False if argv.count('-x') > 0: xlsxMode = True import openpyxl argv.remove('-x') else: xlsxMode = False if len(argv) < 3 or argv[1] == '' or argv[2] == '': print("Usage: " + argv[0][argv[0].rfind("\\") + 1:] + " <Scene\> <Text\> [Scene_packed\] [-x [-db]] [-q]") return False inF = argv[1] + "\\" txtF = argv[2] + "\\" if len(argv) < 4 or argv[3] == '': outF = argv[0][:argv[0].rfind("\\") + 1] + argv[1][argv[1].rfind("\\") + 1:] + "_packed\\" else: outF = argv[0][:argv[0].rfind("\\") + 1] + argv[3] + "\\" if not os.path.exists(outF): os.makedirs(outF) for txtFN in glob.glob(txtF + "*.txt"): print(txtFN) inFN = inF + txtFN[txtFN.rfind("\\") + 1:].replace( ".txt", ".ss").replace(".ss.ss", ".ss") outFN = outF + txtFN[txtFN.rfind("\\") + 1:].replace( ".txt", ".ss").replace(".ss.ss", ".ss") SS = ss(inFN) txt = open(txtFN, 'r', 1, "UTF-8") for line in txt.readlines(): if not line[0] == u"●": continue index = int(line[1:line.find("●", 1)]) text = line[line.find("●", 1) + 1:].replace("\n", "") if quotChange: text = change(text) SS.length[index] = len(text) SS.string[index] = Decrypt( text.encode("UTF-16")[2:], SS.length[index], index) txt.close() SS.write(outFN) if xlsxMode: for txtFN in glob.glob(txtF + "*.xlsx"): print(txtFN) workBook = openpyxl.load_workbook(txtFN) for sheet in workBook: name = sheet['D1'].value if name == None or name == "" or len(sheet.title) < 31: name = sheet.title print(name) inFN = inF + name outFN = outF + name SS = ss(inFN) for a, b, c in zip(sheet['A'], sheet['B'], sheet['C']): try: index = int(a.value) except: continue text = c.value if text == None: text = "" else: text = str(text) jp = str(b.value) if dbLine and jp != text and (len(text) > 2 or len(jp) > 2): if quotChange: text = change(text) + '#NEWLINE' + jp else: text = text + '#NEWLINE' + jp elif quotChange: text = change(text) SS.length[index] = len(text) SS.string[index] = Decrypt( text.encode("UTF-16")[2:], SS.length[index], index) SS.write(outFN) return True
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 fillColor=openpyxl.styles.PatternFill(fill_type="solid", fgColor="F2F2F2") border=openpyxl.styles.Border(top=openpyxl.styles.Side(style='thin',color='D0D7E5'),left=openpyxl.styles.Side(style='thin',color='D0D7E5'),right=openpyxl.styles.Side(style='thin',color='D0D7E5')) 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]) workSheet.cell(workSheet.max_row,3).fill=fillColor workSheet.cell(workSheet.max_row,3).border=border 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
def main(argv): if len(argv)<3 or argv[1]=='' or argv[2]=='': print ("Usage: "+argv[0][argv[0].rfind("\\")+1:]+" <Scene\> <Text\> [Scene_packed\]") return False inF=argv[1]+"\\" txtF=argv[2]+"\\" if len(argv)<4 or argv[3]=='': outF=argv[0][:argv[0].rfind("\\")+1]+argv[1][argv[1].rfind("\\")+1:]+"_packed\\" else: outF=argv[0][:argv[0].rfind("\\")+1]+argv[3]+"\\" if not os.path.exists(outF): os.makedirs(outF) for txtFN in glob.glob(txtF+"*.txt"): print(txtFN) inFN=inF+txtFN[txtFN.rfind("\\")+1:].replace(".txt",".ss").replace(".ss.ss",".ss") outFN=outF+txtFN[txtFN.rfind("\\")+1:].replace(".txt",".ss").replace(".ss.ss",".ss") 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]) string=[] for x in range(0,header.count): if length[x]==0: string.append(b'') continue file.seek(header.offset+offset[x]*2,0) string.append(file.read(length[x]*2)) file.seek(header.offset) ssData=file.read() file.close() txt=open(txtFN,'r',1,"UTF-8") for line in txt.readlines(): if not line[0]==u"●": continue index=int(line[1:line.find("●",1)]) text=line[line.find("●",1)+1:-1] length[index]=len(text) string[index]=Decrypt(text.encode("UTF-16")[2:],length[index],index) txt.close() output=open(outFN,'wb') output.write(struct.pack("I",header.length)) output.write(header.headerData[:16]) output.write(struct.pack("I",size)) output.write(header.headerData[20:]) newOffset=0 for n in range(0,header.count): output.write(struct.pack("I",newOffset)) output.write(struct.pack("I",length[n])) newOffset+=length[n] output.write(ssData) for x in range(0,header.count): output.write(string[x]) output.close() return True