-
Notifications
You must be signed in to change notification settings - Fork 1
/
trib.py
214 lines (192 loc) · 8.6 KB
/
trib.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import os
import struct
import subprocess
from functools import partial
from tkinter import Tk, Label, Button, Entry
from tkinter.filedialog import askdirectory
if ':\\Windows' in os.getcwd():
os.chdir(os.environ['userprofile'] + '\\Desktop')
install_dir = os.path.dirname(os.path.abspath(__file__))
with open(os.path.join(install_dir, '#language.txt'), 'r', encoding="utf-8") as txt:
language = txt.read()
language = [''] + language.splitlines()
start = int(language[1].split(":")[25])
msm = int(language[1].split(":")[1])
a = Tk()
a.title(language[start])
a.minsize(840, 440)
a.config(bg='#bfaaff')
ico = os.path.join('msm_stuff', 'trib.ico')
a.iconbitmap(os.path.join(install_dir, ico))
def hex_float(number):
number = number.replace(',', '.') # replaces coma with dots
num = b''
w = hex(struct.unpack('<I', struct.pack('<f', float(number)))[0])[2:]
# add zeros to always make the value length to 8
# w = '0' * (8-len(w)) + w
w = w.zfill(8)
for octet in range(0, 8, 2): # transform for example "3f800000" to b'\x3f\x80\x00\x00'
num += bytes(chr(int(w[octet:(octet + 2)], 16)), 'latin-1')
return num
button_row = []
for m in range(7, 99):
for _ in range(7):
button_row.append(m)
button_col = [0, 1, 2, 3, 4, 5, 6] * 99
label_list = []
def scan_directory():
for tkstuff in a.winfo_children():
if tkstuff not in forstuff: # forstuff = everything except file buttons
tkstuff.destroy()
button_list = []
mdl_list = []
def change_scale(file, offset):
for y in range(12):
entries[y].config(bg='#ffffff')
if not entries[y].get().lstrip('-').replace('.', '', 1).isdigit() and not entries[y].get().lstrip('-').replace(',', '', 1).isdigit():
entries[y].config(bg='#ffaaaa')
return
j = mdl_list[offset]
done = False
default_scale = hex_float(entries[0].get()) + hex_float(entries[1].get()) + hex_float(entries[2].get())
with open(file, "r+b") as mdlo:
while j < os.path.getsize(file) - 20:
j += 1
mdlo.seek(j)
if mdlo.read(12) == default_scale:
mdlo.seek(j)
x = b''
for u in range(3, 12):
x += hex_float(entries[u].get())
mdlo.write(x)
j = os.path.getsize(file)
done = True
button_list[offset].destroy()
if done:
patched = Label(a, text=language[start + 1], bg='#bfaaff', width=30)
patched.grid(row=button_row[offset], column=button_col[offset])
else:
notpatched = Label(a, text=language[start + 2], fg='#0050ff', bg='#bfaaff', width=30)
notpatched.grid(row=button_row[offset], column=button_col[offset])
mdl = mdln = 0
for files in os.listdir('./'):
if mdl >= len(button_col):
break
try:
if not os.path.isfile(files):
continue
size = os.path.getsize(files)
if size < 10:
continue
with open(files, 'rb') as bfile:
cursor = 0
header = bfile.read(4)
if header == b'MDL0':
edit = partial(change_scale, files, mdl)
if mdl >= len(button_col):
break
filebu = Button(a, text='MDL0 ' + files, command=edit, activebackground='#a9ff99', width=30, fg='#0050ff')
filebu.grid(row=button_row[mdl], column=button_col[mdl])
button_list.append(filebu)
mdl_list.append(0)
mdln += 1
mdl += 1
elif header in [b'U\xaa8-', b'bres']:
new = 0
while cursor < size:
bfile.seek(cursor)
mdl0 = bfile.read(4)
if mdl0 == b'MDL0':
mdl_list.append(cursor)
new += 1
cursor += 16
if not new:
continue
out = subprocess.check_output(['wszst', 'list', files, '-R']) # returns all file names
first = True
if mdl >= len(button_col):
break
filabel = Label(a, text=files, bg='#bfaaff', font=2, fg='#ff2222', width=19)
filabel.grid(row=button_row[mdl], column=button_col[mdl])
mdl += 1
for k in range(len(out) - 17):
if out[k:k + 5] == b'brres':
if first:
first = False
else:
count = 1
while b'\n' not in out[k - count:k]:
count += 1
if mdl >= len(button_col):
break
flabel = Label(a, text=str(out[k - count + 1:k + 5])[2:-1] + " ->", bg='#bfaaff',
fg='#2222ff', width=30)
flabel.grid(row=button_row[mdl], column=button_col[mdl])
mdl += 1
elif out[k:k + 15] == b'3DModels(NW4R)/' and out[k + 15:k + 16] != b'\n':
z = 0
while b'\n' not in out[k + 15:k + z]:
z += 1
edit = partial(change_scale, files, mdln)
if mdl >= len(button_col):
break
filebu = Button(a, text=str(out[k + 15:k + z])[2:-3], command=edit, activebackground='#a9ff99', width=30)
filebu.grid(row=button_row[mdl], column=button_col[mdl])
button_list.append(filebu)
mdl += 1
mdln += 1
except PermissionError as error:
print(error)
continue
if mdln > 7: # if there are too many buttons for the small windows then put it on fullscreen
exitbu2 = Button(a, text=language[msm + 39], command=a.quit, activebackground='#d9ff8c', bg='#d9ff8c', fg='#ff2222', width=58, height=3, font=100)
exitbu2.grid(row=0, column=4, rowspan=2, columnspan=3)
a.attributes('-fullscreen', True)
def change_directory(): # enter button to change directory (take the entry content)
cwd = entry_dir.get()
if cwd == '':
cwd = os.getcwd()
else:
forstuff[1].configure(text=cwd)
entry_dir.delete(0, 'end')
os.chdir(cwd)
scan_directory()
def open_explorer(): # change directory with C:\Windows\explorer.exe GUI
new_cwd = askdirectory(initialdir=os.getcwd())
os.chdir(new_cwd)
forstuff[1].configure(text=new_cwd)
scan_directory()
ltxt = [language[msm + 18], os.getcwd(), language[start + 3], language[start + 4], language[start + 5], language[start + 6]]
forstuff = []
entries = []
entrow = [2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5]
for n in range(6): # create the 6 labels in ltxt
if n == 1:
text = Label(a, text=ltxt[n], bg='#bfaaff', width=60)
text.grid(row=0, column=1, columnspan=2)
else:
text = Label(a, text=ltxt[n], bg='#bfaaff', width=30)
text.grid(row=n, column=0)
forstuff.append(text)
for indice in range(12): # create 12 entries
entree = Entry(a, width=15)
entree.grid(row=entrow[indice], column=indice % 3 + 1)
if indice < 6:
entree.insert(0, '1.0')
else:
entree.insert(0, '0.0')
entries.append(entree)
forstuff += entries
entry_dir = Entry(a, width=30)
entry_dir.grid(row=1, column=1)
refreshbu = Button(a, text=language[msm + 40], command=change_directory, activebackground='#ff9999', width=30)
refreshbu.grid(row=1, column=2)
open_explorerbu = Button(a, text=language[msm + 19], command=open_explorer, activebackground='#96c7ff', width=15)
open_explorerbu.grid(row=1, column=0)
slash_n = Label(a, text='', bg='#bfaaff')
slash_n.grid(row=6)
dot = Label(a, text=f'{language[start + 7]}\n{language[start + 8]}', bg='#bfaaff', font=2, fg='#ff2222')
dot.grid(row=0, column=3, rowspan=2)
forstuff += [entry_dir, refreshbu, open_explorerbu, slash_n, dot]
scan_directory()
a.mainloop()