from struct import * 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 = [0, 0, 0, 1] vf01 = [0, 0, 0, 0] vf02 = vf01[:] vf03 = vf01[:] vf04 = vf01[:] vf05 = vf01[:] vf06 = vf01[:] vf07 = vf01[:] vf08 = vf01[:] vf09 = vf01[:] vf10 = vf01[:] vf11 = vf01[:] vf12 = vf01[:] vf13 = vf01[:] vf14 = vf01[:] vf15 = vf01[:] vf16 = vf01[:] vf17 = vf01[:] vf18 = vf01[:] vf19 = vf01[:] vf20 = vf01[:] vf21 = vf01[:] vf22 = vf01[:] vf23 = vf01[:] vf24 = vf01[:] vf25 = vf01[:] vf26 = vf01[:] vf27 = vf01[:] vf28 = vf01[:] vf29 = vf01[:] vf30 = vf01[:] vf31 = vf01[:] acc = vf01[:] i = 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 list(unpack('ffff', get(n))) def ints(n): return list(unpack('iiii', get(n))) def vint(n): return [i & 0xFFFF for i in unpack('IIII', get(n))] def bc(v): return [v, v, v, v] def sub(a, b): return [a[0]-b[0], a[1]-b[1], a[2]-b[2], a[3]-b[3]] def add(a, b): return [a[0]+b[0], a[1]+b[1], a[2]+b[2], a[3]+b[3]] def mul(a, b): return [a[0]*b[0], a[1]*b[1], a[2]*b[2], a[3]*b[3]] def vmax(a, b): return [max(a[0],b[0]), max(a[1],b[1]), max(a[2],b[2]), max(a[3],b[3])] def vmin(a, b): return [min(a[0],b[0]), min(a[1],b[1]), min(a[2],b[2]), min(a[3],b[3])] 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 [v[0] * s, v[1] * s, v[2] * s, v[3]] 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 = [2048.0, 2048.0, -9512.0, 0] vf28 = [-163.45947265625, 156.86185789108276, 0, -0.8583860397338867] vf29 = [ 426.774377822876, 59.49576425552368, 0, -0.3293575346469879] vf30 = [-0.63568115234375, -392.16218662261963, 0, -0.3933153450489044] vf31 = [ 504.58984375, 158.0400390625, 5035515.0, 7.75994873046875] copy(vf07, floats(0x3f6), 'zw') copy(vf03, max(vf31, vf31), 'xyz') copy(vf04, max(vf28, vf28), 'xy') copy(vf06, max(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, max(vf13, vf10), 'w') vf08[Z] = vf00[W] copy(vf08, convvert(ints(base+1), uvscale), 'xy') copy(vf13, min(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')