53
« on: 2014-04-29 01:36:29 »
Not sure if this might help others(not even sure how these files are supposed to be written)
I also note that its been awhile that someone posted in this thread.
Basically just convert folder of files instead of singular entered file.
Python 3.
This code is based on what Vehek posted.
import struct
import os
import sys
path = './Unconv/'
pathd = './Conv/'
imageCount = 2
for file in os.listdir(path):
current = os.path.join(path, file)
if os.path.isfile(current):
try:
model = open(current, 'rb')
model.seek(4)
offsets = struct.unpack("IIII", model.read(16))
model.seek(offsets[0])
modelData = model.read(offsets[3] - offsets[0])
outt = open(pathd+os.path.basename(current)+ '_mdl.dat', 'wb')
outt.write(struct.pack("IIII", 11, offsets[0] + 0x1C, offsets[1] + 0x1C, offsets[2] + 0x1C))
for i in range(8):
outt.write(struct.pack("I", offsets[3] + 0x1C))
outt.write(struct.pack("I", offsets[3] + 0x1C + 4 * (imageCount + 2) + imageCount * 0x4220))
outt.write(modelData)
outt.write(struct.pack("I", imageCount))
for i in range(imageCount + 1):
outt.write(struct.pack("I", i * 0x4220 + 4 * (imageCount + 2)))
#Create placeholder textures
for j in range(2):
outt.write(struct.pack("IIIHHHH", 0x10, 9, 0x20C, 2, 2, 256, 1))
for x in range(256):
outt.write(bytes("\x22\x22", 'UTF-8'))
outt.write(struct.pack("IHHHH", 0x400C, 1, 1, 0x40, 0x80))
for x in range(0x4000):
outt.write(bytes("\x00", 'UTF-8'))
outt.close()
except Exception:
pass
This is the altered code.
import struct
import os
import sys
path = './Unconv/'
pathd = './Conv/'
imageCount = 2
for file in os.listdir(path):
current = os.path.join(path, file)
if os.path.isfile(current):
try:
model = open(current, 'rb')
model.seek(4)
offsets = struct.unpack("IIII", model.read(16))
model.seek(offsets[0])
modelData = model.read(offsets[3] - offsets[0])
outt = open(pathd+os.path.basename(current)+ '_mdl.dat', 'wb')
outt.write(struct.pack("IIII", 11, offsets[0] + 0x1C, offsets[1] + 0x1C, offsets[2] + 0x1C))
for i in range(8):
outt.write(struct.pack("I", offsets[3] + 0x1C))
outt.write(struct.pack("I", offsets[3] + 0x1C + 4 * (imageCount + 2) + imageCount * 0x4220))
outt.write(modelData)
outt.write(struct.pack("I", imageCount))
for i in range(imageCount + 1):
outt.write(struct.pack("I", i * 0x4220 + 4 * (imageCount + 2)))
#Create placeholder textures
for j in range(2):
outt.write(struct.pack("IIIHHHH", 0x10, 9, 0x20C, 2, 2, 256, 1))
for x in range(256):
outt.write(bytes("\x22\x22", 'UTF-8'))
outt.write(struct.pack("IHHHH", 0x400C, 1, 1, 0x40, 0x80))
for x in range(0x4000):
outt.write(bytes("\x00", 'UTF-8'))
outt.close()
except Exception:
pass