Skip to content

Instantly share code, notes, and snippets.

@uyjulian
Last active July 23, 2022 11:07
Show Gist options
  • Save uyjulian/9ae71d72a387b712426d4bccd7ea9eb0 to your computer and use it in GitHub Desktop.
Save uyjulian/9ae71d72a387b712426d4bccd7ea9eb0 to your computer and use it in GitHub Desktop.
import sys
def parse_uvb(filepath):
import struct
with open(filepath, "rb") as f:
shouldbeUVab = struct.unpack("I", f.read(4))
if shouldbeUVab[0] != 1650546261:
raise Exception("Should be UVab")
length, = struct.unpack("I", f.read(4))
if length == 0:
return []
data = f.read(length * 4)
pos = 0
data_decoded = []
while pos < (length - 3):
int1, = struct.unpack("I", data[pos * 4:(pos + 1) * 4])
float1, = struct.unpack("f", data[pos * 4:(pos + 1) * 4])
if int1 == 1:
data_decoded.append([int1, list(struct.unpack("I", data[(pos + 1) * 4:(pos + 2) * 4]))])
pos += 1
elif int1 == 2 or int1 == 14 or int1 == 17 or int1 == 19:
data_decoded.append([int1, list(struct.unpack("I", data[(pos + 1) * 4:(pos + 2) * 4]))])
pos += 1
elif int1 == 3:
data_decoded.append([int1, list(struct.unpack("ffff", data[(pos + 1) * 4:(pos + 5) * 4]))])
pos += 4
elif int1 == 4 or int1 == 5 or int1 == 6 or int1 == 7 or int1 == 8 or int1 == 9 or int1 == 10:
data_decoded.append([int1, list(struct.unpack("ff", data[(pos + 1) * 4:(pos + 3) * 4]))])
pos += 2
elif int1 == 11 or int1 == 12:
data_decoded.append([int1, list(struct.unpack("Iffff", data[(pos + 1) * 4:(pos + 6) * 4]))])
pos += 5
elif int1 == 13:
data_decoded.append([int1, list(struct.unpack("I", data[(pos + 1) * 4:(pos + 2) * 4]))])
pos += 1
elif int1 == 15:
data_decoded.append([int1, list(struct.unpack("III", data[(pos + 1) * 4:(pos + 4) * 4]))])
pos += 3
elif int1 == 16 or int1 == 20:
data_decoded.append([int1, []])
pos += 0
elif int1 == 18:
data_decoded.append([int1, list(struct.unpack("Iffff", data[(pos + 1) * 4:(pos + 6) * 4]))])
pos += 5
else:
data_decoded.append([int1])
pos += 1
return data_decoded
dat_type_dic = {
1 : "jmp",
2 : "wait",
3 : "uv_minmax",
5 : "uv_ofs_set",
6 : "uv_ofs_add",
7 : "uv_ofs_dt",
8 : "uv_scl_set",
11 : "col_dif",
12 : "col_emi",
13 : "cntr_clr",
14 : "cntr_inc",
15 : "jmp_neq",
17 : "uv_target",
18 : "col_muv",
19 : "uv_ofs_interp",
20 : "time_stop",
}
uv_target_dic = {
0 : "tex1",
1 : "tex",
2 : "proj",
4 : "muv",
8 : "muv2",
16 : "dudv",
}
for arg in sys.argv[1:]:
print("FILE " + arg)
data_decoded = parse_uvb(arg)
for dat in data_decoded:
int1 = dat[0]
if int1 == 17:
uv_target = "unknown"
if dat[1][0] in uv_target_dic:
uv_target = uv_target_dic[dat[1][0]]
dat.append(uv_target)
dat_type = "???"
if dat[0] in dat_type_dic:
dat_type = dat_type_dic[dat[0]]
print(dat_type, dat)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment