Remove duplicated help entry
[dormin.git] / reeng / skb.py
bloba7ef5be73db3571bc293e2e0adcf9f0b32ab1d0b
1 #!/usr/bin/python
2 from struct import unpack
3 import xff2, sys, math
5 def cstr (s, p):
6 return s[p:p+s[p:].find ("\x00")]
8 def subs (s, p, c):
9 return s[p:p+c]
11 minmax = [["none", "none", -1e9, 1e9],
12 ["none", "none", -1e9, 1e9],
13 ["none", "none", -1e9, 1e9],
14 ["none", "none", -1e9, 1e9],
15 ["none", "none", -1e9, 1e9],
16 ["none", "none", -1e9, 1e9],
17 ["none", "none", -1e9, 1e9],
18 ["none", "none", -1e9, 1e9],
19 ["none", "none", -1e9, 1e9]]
21 def prminmax ():
22 j = 0
23 for (nmax, nmin, vmax, vmin) in minmax:
24 print "[%d] min % f %-15s" % (j, vmin, nmin),
25 print "max % f %s" % (vmax, nmax)
26 j += 1
28 def magn (F):
29 return math.sqrt (reduce (lambda a,b:b*b+a, F,0))
30 ## x = F[0]
31 ## y = F[1]
32 ## z = F[2]
33 ## return math.sqrt (x*x+y*y+z*z)
35 class SKB:
36 def rt (self, pos, t):
37 buf = self.data[pos:pos+64]
38 D1 = unpack ("<3I", buf[0:12])
39 F1 = unpack ("<9f", buf[12:48])
40 if t:
41 H1 = unpack ("<6H", buf[48:60])
42 else:
43 H1 = unpack ("<3i", buf[48:60])
44 F2 = unpack ("<f", buf[60:64])
45 return (D1, F1, H1, F2)
47 def rt1 (self, data, tup):
48 t1 = self.rt (tup[0], False)
49 (D, F, _, _) = t1
50 name = cstr (self.data[self.strtab1:], D[0])
51 for j in range (9):
52 if F[j] > minmax[j][2]:
53 minmax[j][2] = F[j]
54 minmax[j][0] = name
55 if F[j] < minmax[j][3]:
56 minmax[j][3] = F[j]
57 minmax[j][1] = name
59 self.t1.append (t1)
61 def rt2 (self, n):
62 pos = self.off2 + n*64
63 self.t2.append (self.rt (pos, True))
65 def __init__ (self, file, xff):
66 rodata = xff.sections[1]
67 self.rodata = rodata
68 self.roff = rodata[1][7]
69 file.seek (self.roff)
70 data = file.read ()#rodata[1][2])
71 self.data = data
73 print "hdr at %08x" % (xff.off_sign + self.roff)
74 hdr = data[xff.off_sign:]
76 D1 = unpack ("<4I", hdr[:16])
77 D2 = unpack ("<3I", hdr[32:44])
79 self.one = D1[0]
80 self.count1 = D1[1]
81 self.off1 = D1[2]
82 self.strtab1 = D1[3]
84 self.count2 = D2[0]
85 self.off2 = D2[1]
86 self.strtab2 = D2[2]
88 self.data1 = []
89 pos = 44
90 print "%d" % len (data)
91 for i in range (self.count1 + 3):
92 tup = unpack ("<2I", hdr[pos:pos+8])
93 self.data1.append (tup)
94 pos += 8
96 self.Unk1 = unpack ("<2I4fI", subs (data, self.data1[self.count1][0], 7*4))
97 self.Unk2 = unpack ("<I", subs (data, self.data1[self.count1 + 1][0], 4))[0]
98 self.Unk3 = unpack ("<I", subs (data, self.data1[self.count1 + 2][0], 4))[0]
100 self.t1 = []
101 for i in range (self.count1):
102 self.rt1 (data, self.data1[i])
104 self.t2 = []
105 for i in range (self.count2):
106 self.rt2 (i)
108 self.names = []
109 for i in range (self.count1):
110 tup = unpack ("<II", hdr[pos:pos+8])
111 if tup[1] <> 0:
112 raise "Whoopsie daisy", hex (pos + self.roff)
113 name = cstr (data, tup[0] + self.strtab1)
114 self.names.append (name)
115 pos += 8
117 def prt (self, t, taboff, defval):
118 i = 0
119 print
120 for e in t:
121 D1, F1, H1, F2 = e
122 print "[%2d] %s at %08x" % (i,
123 cstr (self.data[taboff:], D1[0]),
124 self.data1[i][0] + self.roff)
126 if D1[1] <> defval:
127 print "!D1[1] %08x (%d)" % (D1[1], D1[1])
128 if D1[2] <> defval:
129 print "!D1[2] %08x (%d)" % (D1[2], D1[2])
131 print " V0 (% f, % f, % f)" % (F1[0], F1[1], F1[2])
132 print " V1 (% f, % f, % f)" % (F1[3], F1[4], F1[5])
133 print " V2 (% f, % f, % f)" % (F1[6], F1[7], F1[8])
135 l13 = magn (F1[1:4])
136 # l57 = magn (F1[5:8])
137 # l68 = magn (F1[6:])
138 l58 = magn (F1[5:])
139 print " %f %f" % (l13, l58)
141 if defval == 0:
142 for j in range (6):
143 print " H1[%d] %04x (%d)" % (j, H1[j], H1[j])
144 else:
145 for j in range (3):
146 print " H1[%d] % d" % (j, H1[j])
148 if F2[0] <> 0.0:
149 print "!F2 % f" % F2[0]
150 print
151 i += 1
153 def pr (self):
154 print "one %d" % self.one
156 print "count1 %d" % self.count1
157 print "off1 %08x" % (self.off1 + self.roff)
158 print "strtab1 %08x" % (self.strtab1 + self.roff)
160 print "count2 %d" % self.count2
161 print "off2 %08x" % (self.off2 + self.roff)
162 print "strtab2 %08x" % (self.strtab2 + self.roff)
164 print "Unk1[0] %08x(%08x) %d" % (self.Unk1[0],
165 self.Unk1[0] + self.roff,
166 self.Unk1[0])
167 print " [1] %08x %d" % (self.Unk1[1], self.Unk1[1])
168 for j in range (4):
169 print " [%d] % f" % (j+2, self.Unk1[j+2])
170 print " [6] %08x(%08x) %d" % (self.Unk1[6],
171 self.Unk1[6] + self.roff,
172 self.Unk1[6])
174 # for f in self.F4:
175 # print f
177 i = 0
178 for elem1 in self.data1:
179 off = elem1[0] + self.roff
180 if i < len (self.names):
181 name = self.names[i]
182 else:
183 name = ""
184 print "[%2d] %-15s %08x(%08x), %08x(%d)" % (i, name,
185 elem1[0], off, elem1[1], elem1[1])
186 i += 1
188 self.prt (self.t1, self.strtab1, 0xffffffff)
189 self.prt (self.t2, self.strtab2, 0x00000000)
191 print sys.argv[1]
192 f = open (sys.argv[1], "rb")
193 x = xff2.XFF (f, 0)
194 s = SKB (f, x)
195 s.pr ()
196 prminmax ()