-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnames.py
More file actions
147 lines (136 loc) · 5.46 KB
/
names.py
File metadata and controls
147 lines (136 loc) · 5.46 KB
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
146
147
import os
import shutil
import subprocess
import re
def names(in_string, validType):
in_file_sb = open("tmp", "wb")
bankPath = "banks"
if validType == True:
in_file_sb.close()
in_file_sb = open("soundbank." + in_string, "rb")
bankPath = "banks_" + in_string
else:
in_file_sb.close()
in_file_sb = open("soundbank", "rb")
in_file_sb.seek(0,2)
sbSize = in_file_sb.tell()
in_file_sb.seek(0)
sbNames = []
sNames = []
sbStart = []
objIDs = []
sCounts = []
in_file_sb.seek(0)
RTableOffset = []
objID = 0
sCount = 0
objIDs = []
objNames = []
sbNamesinBank = []
while in_file_sb.tell() < sbSize - 1024:
readTest = in_file_sb.read(4)
sNamesinBank = []
in_file_sb.seek(-4,1)
if readTest == b'1TAD':
sbStart.append(in_file_sb.tell())
in_file_sb.seek(12,1)
sizeCheck = int.from_bytes(in_file_sb.read(4), "little")
in_file_sb.seek(sbStart[len(sbStart) - 1] + 32)
if sizeCheck == 3:
in_file_sb.seek(-12,1)
NTStart = int.from_bytes(in_file_sb.read(4), "little") + sbStart[len(sbStart) - 1]
NTEnd = int.from_bytes(in_file_sb.read(4), "little")
#sb_search = in_file_sb.read(4096)
#in_file_sb.seek(-4096, 1)
#if sb_search.find(b'WAVEfmt') < 0:
#continue
in_file_sb.seek(NTStart + 12)
sbName = ''
sbRead = in_file_sb.read(1)
NTCount = 1
while sbRead != b'\x00':
sbStr = str(sbRead, 'UTF-8')
sbName += sbStr
sbRead = in_file_sb.read(1)
NTCount += 1
sbNames.append(sbName.split(".")[0])
print(sbName)
sCount = 0
sCounts.append(0)
if not os.path.exists(bankPath + os.path.sep + "wwnames"):
os.makedirs(bankPath + os.path.sep + "wwnames")
out_file_txt = open(bankPath + os.path.sep + "wwnames" + os.path.sep + sbName.split(".sound")[0] + ".txt", "w")
while NTCount < NTEnd - 8:
sName = ''
sRead = in_file_sb.read(1)
NTCount += 1
if sRead == b'\x00':
continue
if not sRead.isalpha():
break
while sRead != b'\x00' and int.from_bytes(sRead, "little") < 123:
try:
sStr = str(sRead, 'UTF-8')
except:
break
sName += sStr
sRead = in_file_sb.read(1)
NTCount += 1
if NTCount > NTEnd - 8:
in_file_sb.seek(-1,1)
break
#if sName.find("VFX_SWITCH_LOADER") >= 0:
#break
#if sName.startswith("Play") == True:
#break
#if sName.startswith("Stop") == True or sName.startswith("STOP") == True:
#continue
sNames.append(sName)
sNamesinBank.append(sName)
out_file_txt.write(sName + "\n")
#print(sName)
sCount += 1
out_file_txt.close()
sCounts[len(sCounts) - 1] = sCount
in_file_sb.seek(sbStart[len(sbStart) - 1] + 20)
RTableOffset = (int.from_bytes(in_file_sb.read(4), "little") + sbStart[len(sbStart) - 1])
RTableSize = int(int.from_bytes(in_file_sb.read(4), "little") / 16)
in_file_sb.seek(RTableOffset)
for j in range(RTableSize):
in_file_sb.seek(12,1)
objID = int.from_bytes(in_file_sb.read(2), "little")
if len(sNamesinBank) > j:
objIDs.append(objID)
objNames.append(sNamesinBank[j])
in_file_sb.seek(sbStart[len(sbStart) - 1] + 8)
finalJump = int.from_bytes(in_file_sb.read(4), "little")
in_file_sb.seek(sbStart[len(sbStart) - 1] + finalJump - 4)
sbNamesinBank.append(sNamesinBank)
in_file_sb.seek(1,1)
in_file_sb.close()
os.remove("tmp")
#try:
if os.path.exists(bankPath + os.path.sep + "wwnames" + os.path.sep + "init.txt"):
in_file_txt = open(bankPath + os.path.sep + "wwnames" + os.path.sep + "init.txt", "r")
inread = in_file_txt.read()
in_file_txt.close()
for outfile in sorted(os.listdir(bankPath + os.path.sep + "wwnames")):
if not outfile.endswith(".txt") or outfile == "init.txt":
continue
out_file_txt = open(bankPath + os.path.sep + "wwnames" + os.path.sep + outfile, "a")
out_file_txt.write(inread)
out_file_txt.close()
elif os.path.exists("init.txt"):
in_file_txt = open("init.txt", "r")
inread = in_file_txt.read()
in_file_txt.close()
for outfile in sorted(os.listdir(bankPath + os.path.sep + "wwnames")):
if not outfile.endswith(".txt") or outfile == "init.txt":
continue
out_file_txt = open(bankPath + os.path.sep + "wwnames" + os.path.sep + outfile, "a")
out_file_txt.write(inread)
out_file_txt.close()
#except:
#print("No init.bnk file")
#in_string = input("Rift Apart WWise Bank Language Suffix: ")
#names(in_string)