public static GTA5NGLUT[] BuildLUTs2(uint[][] tables) { byte[][] temp = new byte[16][]; for (int i = 0; i < 16; i++) { temp[i] = new byte[65536]; } GTA5NGLUT[] array = new GTA5NGLUT[16]; for (int j = 0; j < 16; j++) { array[j] = new GTA5NGLUT(); } byte[][] tempLUTS = new byte[16][]; for (int k = 0; k < 16; k++) { tempLUTS[k] = new byte[6553600]; } uint[] t0 = tables[0]; uint[] t1 = tables[1]; uint[] t2 = tables[2]; uint[] t3 = tables[3]; uint[] t4 = tables[4]; uint[] t5 = tables[5]; uint[] t6 = tables[6]; uint[] t7 = tables[7]; uint[] t8 = tables[8]; uint[] t9 = tables[9]; uint[] t10 = tables[10]; uint[] t11 = tables[11]; uint[] t12 = tables[12]; uint[] t13 = tables[13]; uint[] t14 = tables[14]; uint[] t15 = tables[15]; Parallel.For(0L, 256L, delegate(long k1) { for (long num5 = 0L; num5 < 6553600; num5 += 1L) { long num6 = k1 * 6553600 + num5; byte b = (byte)(num6 & 0xFF); byte b2 = (byte)(num6 >> 8 & 0xFF); byte b3 = (byte)(num6 >> 16 & 0xFF); byte b4 = (byte)(num6 >> 24 & 0xFF); uint num7 = t0[(int)b] ^ t7[(int)b2] ^ t10[(int)b3] ^ t13[(int)b4]; uint num8 = t1[(int)b] ^ t4[(int)b2] ^ t11[(int)b3] ^ t14[(int)b4]; uint num9 = t2[(int)b] ^ t5[(int)b2] ^ t8[(int)b3] ^ t15[(int)b4]; uint num10 = t3[(int)b] ^ t6[(int)b2] ^ t9[(int)b3] ^ t12[(int)b4]; if (num7 < 65536) { temp[0][(int)num7] = b; temp[7][(int)num7] = b2; temp[10][(int)num7] = b3; temp[13][(int)num7] = b4; } if (num8 < 65536) { temp[1][(int)num8] = b; temp[4][(int)num8] = b2; temp[11][(int)num8] = b3; temp[14][(int)num8] = b4; } if (num9 < 65536) { temp[2][(int)num9] = b; temp[5][(int)num9] = b2; temp[8][(int)num9] = b3; temp[15][(int)num9] = b4; } if (num10 < 65536) { temp[3][(int)num10] = b; temp[6][(int)num10] = b2; temp[9][(int)num10] = b3; temp[12][(int)num10] = b4; } if ((num7 & 0xFF) == 0) { tempLUTS[0][(int)(num7 >> 8)] = b; tempLUTS[7][(int)(num7 >> 8)] = b2; tempLUTS[10][(int)(num7 >> 8)] = b3; tempLUTS[13][(int)(num7 >> 8)] = b4; } if ((num8 & 0xFF) == 0u) { tempLUTS[1][(int)(num8 >> 8)] = b; tempLUTS[4][(int)(num8 >> 8)] = b2; tempLUTS[11][(int)(num8 >> 8)] = b3; tempLUTS[14][(int)(num8 >> 8)] = b4; } if ((num9 & 0xFF) == 0u) { tempLUTS[2][(int)(num9 >> 8)] = b; tempLUTS[5][(int)(num9 >> 8)] = b2; tempLUTS[8][(int)(num9 >> 8)] = b3; tempLUTS[15][(int)(num9 >> 8)] = b4; } if ((num10 & 0xFF) == 0u) { tempLUTS[3][(int)(num10 >> 8)] = b; tempLUTS[6][(int)(num10 >> 8)] = b2; tempLUTS[9][(int)(num10 >> 8)] = b3; tempLUTS[12][(int)(num10 >> 8)] = b4; } } }); for (int l = 0; l < 16; l++) { array[l].LUT0 = new byte[256][]; for (int m = 0; m < 256; m++) { byte[] array2 = new byte[256]; for (int n = 0; n < 256; n++) { array2[n] = temp[l][256 * m + n]; } array[l].LUT0[(int)array2[0]] = array2; } } for (int num = 0; num < 16; num++) { GTA5NGLUT gta5NGLUT = array[num]; gta5NGLUT.LUT1 = new byte[256][]; gta5NGLUT.Indices = new byte[65536]; for (int num2 = 0; num2 < 256; num2++) { byte[] array3 = new byte[256]; for (int num3 = 0; num3 < 256; num3++) { array3[num3] = tempLUTS[num][256 * num2 + num3]; } gta5NGLUT.LUT1[(int)array3[0]] = array3; } for (int num4 = 0; num4 < 65536; num4++) { gta5NGLUT.Indices[num4] = tempLUTS[num][256 * num4]; } } return(array); }
public static GTA5NGLUT[] BuildLUTs2(uint[][] tables) { var temp = new byte[16][]; for (int i = 0; i < 16; i++) { temp[i] = new byte[65536]; } var result = new GTA5NGLUT[16]; for (int i = 0; i < 16; i++) { result[i] = new GTA5NGLUT(); //result[i].Tables = new byte[256][]; //result[i].LUT = new byte[16777216]; } var tempLUTS = new byte[16][]; for (int i = 0; i < 16; i++) { tempLUTS[i] = new byte[16777216]; } var t0 = tables[0]; var t1 = tables[1]; var t2 = tables[2]; var t3 = tables[3]; var t4 = tables[4]; var t5 = tables[5]; var t6 = tables[6]; var t7 = tables[7]; var t8 = tables[8]; var t9 = tables[9]; var t10 = tables[10]; var t11 = tables[11]; var t12 = tables[12]; var t13 = tables[13]; var t14 = tables[14]; var t15 = tables[15]; /*Parallel.For(0, 0x100, (long k1) => * { * for (long k2 = 0; k2 < 0x1000000; k2++) * { * long i = k1 * 0x1000000 + k2; * * byte b0 = (byte)((i >> 0) & 0xFF); * byte b1 = (byte)((i >> 8) & 0xFF); * byte b2 = (byte)((i >> 16) & 0xFF); * byte b3 = (byte)((i >> 24) & 0xFF); * * var x1 = * t0[b0] ^ * t7[b1] ^ * t10[b2] ^ * t13[b3]; * var x2 = * t1[b0] ^ * t4[b1] ^ * t11[b2] ^ * t14[b3]; * var x3 = * t2[b0] ^ * t5[b1] ^ * t8[b2] ^ * t15[b3]; * var x4 = * t3[b0] ^ * t6[b1] ^ * t9[b2] ^ * t12[b3]; * * // the first LUT-compression step is built-it * // because it would take 4GB ram per data byte (and there are 16) * * if (x1 < 65536) * { * temp[0][x1] = b0; * temp[7][x1] = b1; * temp[10][x1] = b2; * temp[13][x1] = b3; * } * * if (x2 < 65536) * { * temp[1][x2] = b0; * temp[4][x2] = b1; * temp[11][x2] = b2; * temp[14][x2] = b3; * } * * if (x3 < 65536) * { * temp[2][x3] = b0; * temp[5][x3] = b1; * temp[8][x3] = b2; * temp[15][x3] = b3; * } * * if (x4 < 65536) * { * temp[3][x4] = b0; * temp[6][x4] = b1; * temp[9][x4] = b2; * temp[12][x4] = b3; * } * * if ((x1 & 0x000000FF) == 0) * { * tempLUTS[0][x1 >> 8] = b0; * tempLUTS[7][x1 >> 8] = b1; * tempLUTS[10][x1 >> 8] = b2; * tempLUTS[13][x1 >> 8] = b3; * } * * if ((x2 & 0x000000FF) == 0) * { * tempLUTS[1][x2 >> 8] = b0; * tempLUTS[4][x2 >> 8] = b1; * tempLUTS[11][x2 >> 8] = b2; * tempLUTS[14][x2 >> 8] = b3; * } * * if ((x3 & 0x000000FF) == 0) * { * tempLUTS[2][x3 >> 8] = b0; * tempLUTS[5][x3 >> 8] = b1; * tempLUTS[8][x3 >> 8] = b2; * tempLUTS[15][x3 >> 8] = b3; * } * * if ((x4 & 0x000000FF) == 0) * { * tempLUTS[3][x4 >> 8] = b0; * tempLUTS[6][x4 >> 8] = b1; * tempLUTS[9][x4 >> 8] = b2; * tempLUTS[12][x4 >> 8] = b3; * } * } * });*/ for (int i = 0; i < 16; i++) { result[i].LUT0 = new byte[256][]; for (int blockIdx = 0; blockIdx < 256; blockIdx++) { var xl = new byte[256]; for (int k = 0; k < 256; k++) { xl[k] = temp[i][256 * blockIdx + k]; } result[i].LUT0[xl[0]] = xl; } } // compress tables... // length from 2^24 -> 2^16 for (int i = 0; i < 16; i++) { GTA5NGLUT lut = result[i]; lut.LUT1 = new byte[256][]; lut.Indices = new byte[65536]; for (int blockIdx = 0; blockIdx < 256; blockIdx++) { var xl = new byte[256]; for (int k = 0; k < 256; k++) { xl[k] = tempLUTS[i][256 * blockIdx + k]; } lut.LUT1[xl[0]] = xl; } for (int blockIdx = 0; blockIdx < 65536; blockIdx++) { lut.Indices[blockIdx] = tempLUTS[i][256 * blockIdx]; } } return(result); }