from struct import * from numpy import * numpy.set_printoptions(suppress=True) X = 0 Y = 1 Z = 2 W = 3 def init(name): f = open(name, 'rb') global mem mem = f.read() f.close() global vf00, vf01, vf02, vf03, vf04, vf05, vf06, vf07,\ vf08, vf09, vf10, vf11, vf12, vf13, vf14, vf15,\ vf16, vf17, vf18, vf19, vf20, vf21, vf22, vf23,\ vf24, vf25, vf26, vf27, vf28, vf29, vf30, vf31 global acc, i, q vf00 = array([0, 0, 0, 1], dtype=float32) vf01 = array([0, 0, 0, 0], dtype=float32) vf02 = array(vf01[:], dtype=float32) vf03 = array(vf01[:], dtype=float32) vf04 = array(vf01[:], dtype=float32) vf05 = array(vf01[:], dtype=float32) vf06 = array(vf01[:], dtype=float32) vf07 = array(vf01[:], dtype=float32) vf08 = array(vf01[:], dtype=float32) vf09 = array(vf01[:], dtype=float32) vf10 = array(vf01[:], dtype=float32) vf11 = array(vf01[:], dtype=float32) vf12 = array(vf01[:], dtype=float32) vf13 = array(vf01[:], dtype=float32) vf14 = array(vf01[:], dtype=float32) vf15 = array(vf01[:], dtype=float32) vf16 = array(vf01[:], dtype=float32) vf17 = array(vf01[:], dtype=float32) vf18 = array(vf01[:], dtype=float32) vf19 = array(vf01[:], dtype=float32) vf20 = array(vf01[:], dtype=float32) vf21 = array(vf01[:], dtype=float32) vf22 = array(vf01[:], dtype=float32) vf23 = array(vf01[:], dtype=float32) vf24 = array(vf01[:], dtype=float32) vf25 = array(vf01[:], dtype=float32) vf26 = array(vf01[:], dtype=float32) vf27 = array(vf01[:], dtype=float32) vf28 = array(vf01[:], dtype=float32) vf29 = array(vf01[:], dtype=float32) vf30 = array(vf01[:], dtype=float32) vf31 = array(vf01[:], dtype=float32) acc = array(vf01[:], dtype=float32) i = 0 q = 0 global vi00, vi01, vi02, vi03, vi04, vi05, vi06, vi07,\ vi08, vi09, vi10, vi11, vi12, vi13, vi14, vi15 vi00 = 0 vi01 = 0 vi02 = 0 vi03 = 0 vi04 = 0 vi05 = 0 vi06 = 0 vi07 = 0 vi08 = 0 vi09 = 0 vi10 = 0 vi11 = 0 vi12 = 0 vi13 = 0 vi14 = 0 vi15 = 0 def get(n): return mem[n*16:n*16+16] def floats(n): return array(list(unpack('ffff', get(n))), dtype=float32) def ints(n): return array(list(unpack('iiii', get(n))), dtype=float32) def vint(n): return array([i & 0xFFFF for i in unpack('IIII', get(n))], dtype=float32) def bc(v): return array([v, v, v, v], dtype=float32) def sub(a, b): return array([a[0]-b[0], a[1]-b[1], a[2]-b[2], a[3]-b[3]], dtype=float32) def add(a, b): return array([a[0]+b[0], a[1]+b[1], a[2]+b[2], a[3]+b[3]], dtype=float32) def mul(a, b): return array([a[0]*b[0], a[1]*b[1], a[2]*b[2], a[3]*b[3]], dtype=float32) def vmax(a, b): return array([max(a[0],b[0]), max(a[1],b[1]), max(a[2],b[2]), max(a[3],b[3])], dtype=float32) def vmin(a, b): return array([min(a[0],b[0]), min(a[1],b[1]), min(a[2],b[2]), min(a[3],b[3])], dtype=float32) def madd(a, b, c): return add(a, mul(b, c)) def msub(a, b, c): return sub(a, mul(b, c)) def copy(a, b, mask): if 'x' in mask: a[0] = b[0] if 'y' in mask: a[1] = b[1] if 'z' in mask: a[2] = b[2] if 'w' in mask: a[3] = b[3] normalscale = 1/128 vertscale1 = 1/128 vertscale2 = 1/1024 uvscale = 1/4096 def convvert(v, s=vertscale2): return array([v[0] * s, v[1] * s, v[2] * s, v[3]], dtype=float32) def project(base = 0): global vf00, vf01, vf02, vf03, vf04, vf05, vf06, vf07,\ vf08, vf09, vf10, vf11, vf12, vf13, vf14, vf15,\ vf16, vf17, vf18, vf19, vf20, vf21, vf22, vf23,\ vf24, vf25, vf26, vf27, vf28, vf29, vf30, vf31 global vi00, vi01, vi02, vi03, vi04, vi05, vi06, vi07,\ vi08, vi09, vi10, vi11, vi12, vi13, vi14, vi15 global acc, i, q vf02 = array([2048.0, 2048.0, -9512.0, 0], dtype=float32) vf28 = array([-163.45947265625, 156.86185789108276, 0, -0.8583860397338867], dtype=float32) vf29 = array([ 426.774377822876, 59.49576425552368, 0, -0.3293575346469879], dtype=float32) vf30 = array([-0.63568115234375, -392.16218662261963, 0, -0.3933153450489044], dtype=float32) vf31 = array([ 504.58984375, 158.0400390625, 5035515.0, 7.75994873046875], dtype=float32) copy(vf07, floats(0x3f6), 'zw') copy(vf03, vmax(vf31, vf31), 'xyz') copy(vf04, vmax(vf28, vf28), 'xy') copy(vf06, vmax(vf30, vf30), 'xyz') i = 255 copy(acc, mul(vf00, bc(i)), 'w') copy(vf03, mul(vf31, bc(vf07[Z])), 'w') copy(vf04, mul(vf28, bc(vf07[Z])), 'w') copy(vf05, mul(vf29, bc(vf07[Z])), 'w') copy(vf06, mul(vf30, bc(vf07[Z])), 'w') copy(vf10, mul(vf07, bc(vf07[Z])), 'w') copy(vf13, convvert(ints(base+0)), 'xyz') copy(vf10, sub(vf00, vf02), 'xyz') copy(vf05, vf29, 'xy') copy(vf12, madd(acc, vf07, bc(vf07[Z])), 'w') copy(acc, mul(vf03, bc(vf00[W])), 'xyzw') copy(acc, madd(acc, vf04, bc(vf13[X])), 'xyw') copy(acc, madd(acc, vf05, bc(vf13[Y])), 'xyw') copy(vf13, madd(acc, vf06, bc(vf13[Z])), 'xyzw') i = 2048.5 copy(acc, mul(vf10, bc(vf00[W])), 'xyzw') copy(vf11, msub(acc, vf00, bc(i)), 'xyzw') q = vf07[Z]/vf13[W] copy(vf13, vmax(vf13, vf10), 'w') vf08[Z] = vf00[W] copy(vf08, convvert(ints(base+1), uvscale), 'xy') copy(vf13, vmin(vf13, vf12), 'w') copy(vf13, mul(vf13, bc(q)), 'xyz') copy(vf14, mul(vf08, bc(q)), 'xyz') copy(vf13, sub(vf13, vf10), 'xyzw') copy(vf20, mul(vf13, bc(16)), 'xyzw') texcoords = [0.135798, 0.142299] def specmap(base=0): global vf00, vf01, vf02, vf03, vf04, vf05, vf06, vf07,\ vf08, vf09, vf10, vf11, vf12, vf13, vf14, vf15,\ vf16, vf17, vf18, vf19, vf20, vf21, vf22, vf23,\ vf24, vf25, vf26, vf27, vf28, vf29, vf30, vf31 global vi00, vi01, vi02, vi03, vi04, vi05, vi06, vi07,\ vi08, vi09, vi10, vi11, vi12, vi13, vi14, vi15 global acc, i, q copy(vf01, add(vf00, bc(vf00[W])), 'x') copy(vf03, floats(0x3cb), 'xyz') copy(vf04, vmax(vf03, vf03), 'z') copy(vf06, floats(0x3c9), 'xyz') copy(vf04, add(vf03, bc(vf00[W])), 'xy') copy(vf05, floats(0x3c8), 'xyz') i = 0.5 copy(vf09, convvert(ints(base+3), normalscale), 'xyz') copy(vf04, mul(vf04, bc(i)), 'xyz') i = 96 copy(vf08, vmax(vf00, bc(i)), 'xyz') copy(vf06, floats(0x3cd), 'w') copy(vf07, floats(0x3ca), 'xyz') copy(acc, mul(vf05, bc(vf09[X])), 'xyz') copy(acc, madd(acc, vf06, bc(vf09[Y])), 'xyz') copy(vf08, mul(vf08, bc(vf06[W])), 'xyz') copy(vf06, floats(0x3c8), 'w') copy(vf09, madd(acc, vf07, bc(vf09[Z])), 'xyz') copy(vf08, mul(vf08, bc(vf06[W])), 'xyz') # vf08 = [ 5.59434938, 5.59434938, 5.59434938, 0. ] # vf09 = [-0.02393183, 0.88809603, -0.42685986, 0. ] copy(vf11, mul(vf09, vf03), 'xyz') vf03[W] = 128 #copy(vf03, floats(base+2), 'w') i = 255 copy(vf08, vmin(vf08, bc(i)), 'xyz') vf16[Z] = texcoords[base//4] copy(acc, add(vf11, bc(vf11[Z])), 'x') copy(vf16, madd(acc, vf01, bc(vf11[Y])), 'x') vf09[W] = vf03[W] copy(vf10, mul(vf09, bc(vf16[X])), 'xyz') copy(acc, mul(vf04, bc(vf16[Z])), 'xyz') copy(vf09, vmax(vf08, vf08), 'xyz') copy(vf10, msub(acc, vf10, bc(vf16[Z])), 'xyz') copy(vf10, vf16, 'z') # vf10 = [ 0.11008248, 0.1011284 , 0.13579801, 0. ] colors1 = [ [103.70586, 103.70586, 103.70586, 255.0], [103.1474, 103.1474, 103.1474, 255.0], [106.09856, 106.09856, 106.09856, 255.0], [104.34376, 104.34376, 104.34376, 0.0] ] colors2 = [ [155.27876, 155.27876, 155.27876, 0], [154.72031, 154.72031, 154.72031, 0], [157.67146, 157.67146, 157.67146, 0], [155.91667, 155.91667, 155.91667, 0] ]