-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBOTW-AutoMips.py
149 lines (140 loc) · 5.92 KB
/
BOTW-AutoMips.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
146
147
148
149
import os, sys, struct, time
model_offset = 120
def writeTo(filename, position, content):
fh = open(filename, "r+b")
fh.seek(position)
fh.write(content)
fh.close()
def mipTime(filename, position, number_mips):
with open(filename, 'r+b') as f:
for k in range(1, number_mips + 1):
print(position)
pPos = 0
print("Mip : " + str(k))
pPos = position + 4 + (k * 16) + 12
f.seek(pPos)
offset = struct.unpack(">l",f.read(4))[0]
pPos += offset
f.seek(pPos)
try:
mips = struct.unpack(">l",f.read(4))[0]
except:
mips = 0
print("Mip Value Before: " + str(mips))
miplist = list(map(hex,struct.unpack('>4B',struct.pack('>l',mips))))
if miplist[1] == "0x0":
print("Pass")
pass
else:
print("Edit")
mips -= 131072
content = struct.pack('>l', mips)
print("Mip Value After: " + str(mips))
print("Struct Version: " + str(content))
writeTo(filename, pPos, content)
print("Edited")
def matCheck(filename, tempPos, number_of_mats):
with open(filename, 'rb') as f:
for j in range(1, number_of_mats + 1):
mPos = 0
print("Material Number : " + str(j))
mPos = tempPos + 4 + (j * 16) + 12
print("Mat Pos : " + str(mPos))
f.seek(mPos)
offset = struct.unpack(">l",f.read(4))[0]
mPos += offset + 36 + 12
f.seek(mPos)
print(mPos)
offset = struct.unpack(">l",f.read(4))[0]
mPos += offset
print(mPos)
f.seek(mPos)
mPos += 4
f.seek(mPos)
numberOfMips = struct.unpack(">l",f.read(4))[0]
print("Number of Mips : " + str(numberOfMips))
mipTime(filename, mPos, numberOfMips)
def main(filename):
with open(filename, 'rb') as f:
f.seek(32)
ofsModelDict = struct.unpack(">l",f.read(4))[0]
pointer = 32 + ofsModelDict
f.seek(pointer)
modelSize = struct.unpack(">l",f.read(4))[0]
print("Size of Model (uint) : " + str(modelSize))
pointer += 4
f.seek(pointer)
number_Models = struct.unpack(">l",f.read(4))[0]
print("Number of Models : " + str(number_Models))
pointer += 4
for i in range(1, number_Models + 1):
Mpointer = 0
print("Model Number : " + str(i))
Mpointer = pointer + (i * 16) + 12
print(Mpointer)
f.seek(Mpointer)
ofsData = struct.unpack(">l",f.read(4))[0]
Mpointer += ofsData + 24
print(Mpointer)
f.seek(Mpointer)
ofsMaterialDict = struct.unpack(">l",f.read(4))[0]
Mpointer += ofsMaterialDict + 4
f.seek(Mpointer)
number_Materials = struct.unpack(">l",f.read(4))[0]
print("Number of Mats : " + str(number_Materials))
print(Mpointer)
matCheck(filename, Mpointer, number_Materials)
if __name__ == "__main__":
print(sys.version)
if len(sys.argv) < 2:
print('Insufficient arguments. Please supply a bfres file when using this tool.')
exit()
if len(sys.argv) > 2:
tin = len(sys.argv)
i = 1
while i < tin:
filename = sys.argv[i]
with open(filename, 'rb') as f:
p1 = struct.unpack(">s",f.read(1))[0]
p2 = struct.unpack(">s",f.read(1))[0]
p3 = struct.unpack(">s",f.read(1))[0]
p4 = struct.unpack(">s",f.read(1))[0]
word = str(p1+p2+p3+p4)
word = word.replace("b", "").replace("'", "")
if word == "Yaz0":
print("Error 1: Encoded File Detected")
print("File Name: {}".format(sys.argv[i].rsplit("\\", 2)[-1]))
print("This file has not been decoded yet." + " Please use BOTW-Yaz0 or Yaz0dec before using this tool.")
print("Continuing in 5 seconds...")
time.sleep(5)
elif word != "FRES":
print("Error 2: Unusual Filetype detected")
print("File Name: {}".format(sys.argv[i].rsplit("\\", 2)[-1]))
print('File is the wrong format. Format Given : ' + str(word))
print("Continuing in 5 seconds...")
time.sleep(5)
else:
print("File Accepted...please wait while Mip-Maps are disabled.")
print("File Name: {}".format(sys.argv[i].rsplit("\\", 2)[-1]))
main(filename)
i+=1
else:
filename = sys.argv[1]
with open(filename, 'rb') as f:
p1 = struct.unpack(">s",f.read(1))[0]
p2 = struct.unpack(">s",f.read(1))[0]
p3 = struct.unpack(">s",f.read(1))[0]
p4 = struct.unpack(">s",f.read(1))[0]
word = str(p1+p2+p3+p4)
word = word.replace("b", "").replace("'", "")
if word == "Yaz0":
print("Error 1: Encoded File Detected")
print("This file has not been decoded yet." + " Please use BOTW-Yaz0 or Yaz0dec before using this tool.")
exit()
elif word != "FRES":
print("Error 2: Unusual Filetype detected")
print('File is the wrong format. Format Given : ' + str(word))
exit()
print("File Accepted...please wait while Mip-Maps are disabled.")
main(filename)
print("Finished, have a nice day!")