def parse_object(d): p, mainSz = 0, len(d) while p < mainSz: (id, sz), p = u('II', d, p) if id == 0x0900: (fmtVer, ), p = u('H', d, p) if fmtVer != 16: xray_utils.un_ver('OBJECT', fmtVer) break elif id == 0x0903: (flags, ), p = u('I', d, p) elif id == 0x0907: materials = parse_materials(d[p:p + sz]) p += sz elif id == 0x0910: verts, faces, materialIndices = parse_meshes(d[p:p + sz]) p += sz elif id == 0x0911: libVer, p = xray_utils.parse_date(d, p) (unk, ), p = u('I', d, p) elif id == 0x0912: userData, p = xray_utils.parse_string(d, p) elif id == 0x0922: author, p = xray_utils.parse_string(d, p) createDate, p = xray_utils.parse_date(d, p) modifer, p = xray_utils.parse_string(d, p) editDate, p = xray_utils.parse_date(d, p) elif id == 0x0925: lodReference, p = xray_utils.parse_string(d, p) else: xray_utils.un_blk(id) p += sz return verts, faces, materials, materialIndices
def parse_0x7777(data): p = 0 dataSize = len(data) while p < dataSize: (chunkId, chunkCompress, chunkSize), p = u('HHI', data, p) if chunkId == 0x0900: (version, ), p = u('H', data, p) dumpFile.write('version = {}\n'.format(version)) elif chunkId == 0x0902: ( fileVersion, unknow, ), p = u('II', data, p) reference, p = xray_utils.parse_string(data, p) dumpFile.write('file_version = {}\n'.format(fileVersion)) dumpFile.write('reference = {}\n'.format(reference)) elif chunkId == 0x0905: (flags, ), p = u('I', data, p) dumpFile.write('flags = {}\n'.format(flags)) elif chunkId == 0xf903: (posX, pozY, posZ, rotX, rotY, rotZ, scaleX, scaleY, scaleZ), p = u('9f', data, p) dumpFile.write('position = {0}, {1}, {2}\n'.format( posX, pozY, posZ)) dumpFile.write('rotation = {0}, {1}, {2}\n'.format( rotX, rotY, rotZ)) dumpFile.write('scale = {0}, {1}, {2}\n'.format( scaleX, scaleY, scaleZ)) elif chunkId == 0xf906: (objectFlags, ), p = u('I', data, p) objectSelected = bool(objectFlags & 0b1) objectVisible = bool(objectFlags & 0b10) objectLocked = bool(objectFlags & 0b100) objectMotionable = bool(objectFlags & 0b1000) dumpFile.write('selected = {}\n' 'visible = {}\n' 'locked = {}\n' 'motionable = {}\n'.format( objectSelected, objectVisible, objectLocked, objectMotionable)) elif chunkId == 0xf907: objectName, p = xray_utils.parse_string(data, p) dumpFile.write('name = {}\n'.format(objectName)) else: xray_utils.un_blk(chunkId) p += chunkSize
def parse_material_indices(d): ((matCnt, ), p), faceIndices = u('H', d, 0), [] for matIndex in range(matCnt): matName, p = xray_utils.parse_string(d, p) (tCnt, ), p = u('I', d, p) for i in range(tCnt): (faceIndex, ), p = u('I', d, p) faceIndices.append((faceIndex, matIndex)) faceIndices.sort() matIndices = [] for i in faceIndices: matIndices.append(i[1]) return matIndices
def parse_main(d): scale = 2.0 newMesh = b'' shader, _p = xray_utils.parse_string(d, 0) image, _p = xray_utils.parse_string(d, _p) newMesh += d[0:_p + 4] (flgs, minS, maxS, vCnt, iCnt), _p = u('IffII', d, _p) newMinSize = struct.pack('f', minS * scale) newMaxSize = struct.pack('f', maxS * scale) newMesh += newMinSize + newMaxSize + d[_p - 8:] verts, uvs, faces = [], [], [] for _ in range(vCnt): (X, Y, Z, U, V), _p = u('5f', d, _p) verts.append((X, Z, Y)) uvs.append((U, 1 - V)) for _ in range(iCnt // 3): (v1, v2, v3), _p = u('3H', d, _p) faces.append((v1, v3, v2)) meshData = {'verts': verts} meshData['faces'] = faces meshData['uvs'] = uvs meshData['images'] = image return newMesh
def parse_main(d): (motionCnt, ), p = u('I', d, 0) motionName, p = xray_utils.parse_string(d, p) (startFrame, endFrame), p = u('II', d, p) (fps, ), p = u('f', d, p) (ver, ), p = u('H', d, p) (flags, ), p = u('B', d, p) typeFx = flags & 0x1 stopAtEnd = flags & 0x2 noMix = flags & 0x4 syncPart = flags & 0x8 (bonePart, ), p = u('B', d, p) (boneStart, ), p = u('B', d, p) (speed, accrue, falloff, power, boneCnt), p = u('ffffH', d, p) for i in range(boneCnt): boneName, p = xray_utils.parse_string(d, p) (flags, ), p = u('B', d, p) for i in range(6): behaviours, p = u('BB', d, p) (keys, ), p = u('H', d, p) for j in range(keys): (value, time, shape), p = u('ffB', d, p) print(value, time * fps)
def parse_materials(d): ((matCnt, ), p), materials = u('I', d, 0), [] for i in range(matCnt): matName, p = xray_utils.parse_string(d, p) engine, p = xray_utils.parse_string(d, p) compiler, p = xray_utils.parse_string(d, p) material, p = xray_utils.parse_string(d, p) image, p = xray_utils.parse_string(d, p) uvMapName, p = xray_utils.parse_string(d, p) (flags, fvf, tc), p = u('III', d, p) materials.append(matName) materials = list(range(len(materials))) return materials
def parse_color(d): global dump dump += '; colors\n\n' (colorCount, ), p = u('B', d, 0) for colorID in range(colorCount): dump += '[color_{0:0>2}]\n'.format(colorID) (B, G, R, unknow, referenceCount), p = u('5B', d, p) dump += ' rgb = {0}, {1}, {2}\n'.format(R, G, B) refList = [] for i in range(referenceCount): reference, p = xray_utils.parse_string(d, p) refList.append(reference) dump += ' references = ' refListSize = len(refList) for n, ref in enumerate(refList): if n != refListSize - 1: dump += '"{0}", '.format(ref) else: dump += '"{0}"\n\n'.format(ref) return colorCount
def parse_mesh(d): p, blkSz = 0, len(d) while p < blkSz: (id, sz), p = u('II', d, p) if id == 0x1000: (meshVer, ), p = u('H', d, p) elif id == 0x1001: meshName, p = xray_utils.parse_string(d, p) elif id == 0x1002: (flags, ), p = u('B', d, p) elif id == 0x1004: bBox, p = u('6f', d, p) elif id == 0x1005: ((vCnt, ), p), verts = u('I', d, p), [] for i in range(vCnt): (X, Y, Z), p = u('3f', d, p) verts.append((X, Z, Y)) if sz > vCnt * 12 + 4: # unknow data (balon_01.object) p += sz - vCnt * 12 - 4 elif id == 0x1006: ((tCnt, ), p), faces = u('I', d, p), [] for i in range(tCnt): (v1, uv1, v2, uv2, v3, uv3), p = u('6I', d, p) faces.append((v1, v3, v2)) elif id == 0x1008: parse_uv_indices(d[p:p + sz]) p += sz elif id == 0x1009: materialIndices = parse_material_indices(d[p:p + sz]) p += sz elif id == 0x1010: (option0, option1), p = u('II', d, p) elif id == 0x1012: parse_uvs(d[p:p + sz]) p += sz elif id == 0x1013: smthGrps, p = u('%dI' % (len(d[p:p + sz]) // 4), d, p) else: xray_utils.un_blk(id) p += sz return verts, faces, materialIndices
def parse_uvs(data): (count, ), p = u('I', data, 0) for _ in range(count): n, p = xray_utils.parse_string(data, p) (dim, ), p = u('B', data, p) (discon, ), p = u('B', data, p) (typ, ), p = u('B', data, p) typ = typ & 0x3 (sz, ), p = u('I', data, p) if typ == 0: uvs = [] vtx = [] for i in range(sz): uvs_cur, p = u('ff', data, p) uvs.append(uvs_cur) (vtx_cur, ), p = u('I', data, p) vtx.append(vtx_cur) if discon: fcs = [] for i in range(sz): (fcs_cur, ), p = u('I', data, p) fcs.append(fcs_cur)
def parse_scene(data): p = 0 dataSize = len(data) while p < dataSize: (chunkId, chunkCompress, chunkSize), p = u('HHI', data, p) if chunkId == sceneObjectFmt['TAG']: authorName, p = xray_utils.parse_string(data, p) createDate, p = xray_utils.parse_date(data, p) dumpFile.write('author = \"{}\"\n'.format(authorName)) dumpFile.write('create_date = \"{}\"\n'.format(createDate)) elif chunkId == sceneObjectFmt['COUNT']: (objectCount, ), p = u('I', data, p) dumpFile.write('object_count = {}\n'.format(objectCount)) elif chunkId == sceneObjectFmt['OBJECTS']: parse_objects(data[p:p + chunkSize]) p += chunkSize elif chunkId == sceneObjectFmt['VERSION']: (version, ), p = u('H', data, p) dumpFile.write('\nversion = {}\n'.format(version)) elif chunkId == sceneObjectFmt['FLAGS']: (flags, ), p = u('I', data, p) dumpFile.write('flags = {}\n'.format(flags)) elif chunkId == sceneObjectFmt['PARAMS']: (minScaleX, minScaleY, minScaleZ, maxScaleX, maxScaleY, maxScaleZ, minRotX, minRotY, minRotZ, maxRotX, maxRotY, maxRotZ, snapObj), p = u('13f', data, p) dumpFile.write('min_scale = {0}, {1}, {2}\n'.format( minScaleX, minScaleY, minScaleZ)) dumpFile.write('max_scale = {0}, {1}, {2}\n'.format( maxScaleX, maxScaleY, maxScaleZ)) dumpFile.write('min_rotate = {0}, {1}, {2}\n'.format( minRotX, minRotY, minRotZ)) dumpFile.write('max_rotate = {0}, {1}, {2}\n'.format( maxRotX, maxRotY, maxRotZ)) dumpFile.write('snap_object = {0}\n'.format(snapObj)) else: xray_utils.un_blk(chunkId) p += chunkSize
d = xray_utils.read_bin_file('Bush6_hang.object') (id, cmpr, sz), p = u('HHI', d, 0) fileSize = len(d) while p < fileSize: (id, cmpr, sz), p = u('HHI', d, p) if id == 0x0900: # format version (fmtVer,), p = u('H', d, p) elif id == 0x0903: objectType, p = u('B', d, p) elif id == 0x0904: # transformations (pX, pY, pZ, rX, rY, rZ, sX, sY, sZ), p = u('9f', d, p) elif id == 0x0905: (materialId,), p = u('I', d, p) materialName, p = xray_utils.parse_string(d, p) shader, p = xray_utils.parse_string(d, p) unknow, p = u('BBHHHB', d, p) texture, p = xray_utils.parse_string(d, p) uvSlotName, p = xray_utils.parse_string(d, p) elif id == 0x0910: while p < sz: (meshId, meshSize), p = u('II', d, p) parse_mesh(d[p : p + meshSize]) p += meshSize elif id == 0x0911: (unknow1, unknow2), p = u('fI', d, p) elif id == 0x0912: unknow, p = u('B', d, p) elif id == 0x0913: unknow, p = u('I', d, p)
def parse_detail_reference(d): global dump referenceName, p = xray_utils.parse_string(d, 0) dump += ' reference = "{}"\n'.format(referenceName)