Code:
if (data[data.length - 1] == -3 && data[data.length - 2] == -1) { // L: 66
this.decodeOSRS1(data);
} else if (data[data.length - 1] == -2 && data[data.length - 2] == -1) { // L: 67
this.decodeOld1(data);
} else if (data[data.length - 1] == -1 && data[data.length - 2] == -1) { // usesNewHeader
this.decodeOSRS(data);
} else {
this.decodeOld(data); // L: 69
}
New decoder methods (The actual changes are commented with here 1 and here 2.
Code:
int[][] field2180;//todo new osrs anim stuff
int[][] field2181;//todo new osrs anim stuff
public void decodeOSRS1(byte data[]) {
Buffer header = new Buffer(data);
Buffer nc2 = new Buffer(data);
Buffer nc3 = new Buffer(data);
Buffer nc4 = new Buffer(data);
Buffer nc5 = new Buffer(data);
Buffer nc6 = new Buffer(data);
Buffer nc7 = new Buffer(data);
header.pos = data.length - 26;
vertexCount = header.getUShort();
triangleCount = header.getUShort();
texturedCount = header.getUByte();
int flags = header.getUByte();
int priority_opcode = header.getUByte();
int alpha_opcode = header.getUByte();
int tSkin_opcode = header.getUByte();
int texture_opcode = header.getUByte();
int vSkin_opcode = header.getUByte();
int newVar = header.getUByte();
int j3 = header.getUShort();
int k3 = header.getUShort();
int l3 = header.getUShort();
int i4 = header.getUShort();
int j4 = header.getUShort();
int texture_id = 0;
int texture_ = 0;
int texture__ = 0;
int face;
unmodifiedTriangleColor = new int[triangleCount];
if (texturedCount > 0) {
textureTypes = new byte[texturedCount];
header.pos = 0;
for (face = 0; face < texturedCount; face++) {
byte opcode = textureTypes[face] = header.getSByte();
if (opcode == 0) {
texture_id++;
}
if (opcode >= 1 && opcode <= 3) {
texture_++;
}
if (opcode == 2) {
texture__++;
}
}
}
int pos;
pos = texturedCount;
int vertexMod_offset = pos;
pos += vertexCount;
int drawTypeBasePos = pos;
if (flags == 1)
pos += triangleCount;
int faceMeshLink_offset = pos;
pos += triangleCount;
int facePriorityBasePos = pos;
if (priority_opcode == 255)
pos += triangleCount;
int tSkinBasePos = pos;
if (tSkin_opcode == 1)
pos += triangleCount;
int vSkinBasePos = pos;
if (vSkin_opcode == 1)
pos += vertexCount;
int alphaBasePos = pos;
if (alpha_opcode == 1)
pos += triangleCount;
int faceVPoint_offset = pos;
pos += i4;
int textureIdBasePos = pos;
if (texture_opcode == 1)
pos += triangleCount * 2;
int textureBasePos = pos;
pos += j4;
int color_offset = pos;
pos += triangleCount * 2;
int vertexX_offset = pos;
pos += j3;
int vertexY_offset = pos;
pos += k3;
int vertexZ_offset = pos;
pos += l3;
int mainBuffer_offset = pos;
pos += texture_id * 6;
int firstBuffer_offset = pos;
pos += texture_ * 6;
int secondBuffer_offset = pos;
pos += texture_ * 6;
int thirdBuffer_offset = pos;
pos += texture_ * 2;
int fourthBuffer_offset = pos;
pos += texture_;
int fifthBuffer_offset = pos;
pos += texture_ * 2 + texture__ * 2;
vertexX = new int[vertexCount];
vertexY = new int[vertexCount];
vertexZ = new int[vertexCount];
triangleVertexA = new int[triangleCount];
triangleVertexB = new int[triangleCount];
triangleVertexC = new int[triangleCount];
if (vSkin_opcode == 1)
vertexLabel = new int[vertexCount];
if (flags == 1)
faceDrawType = new int[triangleCount];
if (priority_opcode == 255)
trianglePriorities = new int[triangleCount];
else
priority = (byte) priority_opcode;
if (alpha_opcode == 1)
triangleAlpha = new int[triangleCount];
if (tSkin_opcode == 1)
triangleSkin = new int[triangleCount];
if (texture_opcode == 1)
triTex = new int[triangleCount];
if (texture_opcode == 1 && texturedCount > 0)
triTexCoord = new short[triangleCount];
if (newVar == 1) { // L: 169
this.field2180 = new int[vertexCount][]; // L: 170
this.field2181 = new int[vertexCount][]; // L: 171
}
if (texturedCount > 0) {
textureVertexA = new int[texturedCount];
textureVertexB = new int[texturedCount];
textureVertexC = new int[texturedCount];
}
header.pos = vertexMod_offset;
nc2.pos = vertexX_offset;
nc3.pos = vertexY_offset;
nc4.pos = vertexZ_offset;
nc5.pos = vSkinBasePos;
int start_x = 0;
int start_y = 0;
int start_z = 0;
for (int point = 0; point < vertexCount; point++) {
int flag = header.getUByte();
int x = 0;
if ((flag & 1) != 0) {
x = nc2.getSSmart();
}
int y = 0;
if ((flag & 2) != 0) {
y = nc3.getSSmart();
}
int z = 0;
if ((flag & 4) != 0) {
z = nc4.getSSmart();
}
vertexX[point] = start_x + x;
vertexY[point] = start_y + y;
vertexZ[point] = start_z + z;
start_x = vertexX[point];
start_y = vertexY[point];
start_z = vertexZ[point];
if (vertexLabel != null)
vertexLabel[point] = nc5.getUByte();
}
if (newVar == 1) { // HERE 1
for (int var53 = 0; var53 < vertexCount; ++var53) { // L: 204
int var54 = nc5.getUByte(); // L: 205
this.field2180[var53] = new int[var54]; // L: 206
this.field2181[var53] = new int[var54]; // L: 207
for (int var55 = 0; var55 < var54; ++var55) { // L: 208
this.field2180[var53][var55] = nc5.getUByte(); // L: 209
this.field2181[var53][var55] = nc5.getUByte(); // L: 210
}
}
}
header.pos = color_offset;
nc2.pos = drawTypeBasePos;
nc3.pos = facePriorityBasePos;
nc4.pos = alphaBasePos;
nc5.pos = tSkinBasePos;
nc6.pos = textureIdBasePos;
nc7.pos = textureBasePos;
for (face = 0; face < triangleCount; face++) {
unmodifiedTriangleColor[face] = (short) header.getUShort();
if (flags == 1) {
faceDrawType[face] = nc2.getSByte();
}
if (priority_opcode == 255) {
trianglePriorities[face] = nc3.getSByte();
}
if (alpha_opcode == 1) {
triangleAlpha[face] = nc4.getSByte();
if (triangleAlpha[face] < 0)
triangleAlpha[face] = (byte) (256 + triangleAlpha[face]);
}
if (tSkin_opcode == 1)
triangleSkin[face] = nc5.getUByte();
if (texture_opcode == 1) {
triTex[face] = (short) (nc6.getUShort() - 1);
if(triTex[face] >= 0) {
if(faceDrawType != null) {
if(faceDrawType[face] < 2 && unmodifiedTriangleColor[face] != 127 && unmodifiedTriangleColor[face] != -27075) {
triTex[face] = -1;
}
}
}
if(triTex[face] != -1) {
unmodifiedTriangleColor[face] = 127;
}
}
if (triTexCoord != null && triTex[face] != -1) {
triTexCoord[face] = (byte) (nc7.getUByte() - 1);
}
}
header.pos = faceVPoint_offset;
nc2.pos = faceMeshLink_offset;
int coordinate_a = 0;
int coordinate_b = 0;
int coordinate_c = 0;
int last_coordinate = 0;
for (face = 0; face < triangleCount; face++) {
int opcode = nc2.getUByte();
if (opcode == 1) {
coordinate_a = header.getSSmart() + last_coordinate;
last_coordinate = coordinate_a;
coordinate_b = header.getSSmart() + last_coordinate;
last_coordinate = coordinate_b;
coordinate_c = header.getSSmart() + last_coordinate;
last_coordinate = coordinate_c;
triangleVertexA[face] = (short) coordinate_a;
triangleVertexB[face] = (short) coordinate_b;
triangleVertexC[face] = (short) coordinate_c;
}
if (opcode == 2) {
coordinate_b = coordinate_c;
coordinate_c = header.getSSmart() + last_coordinate;
last_coordinate = coordinate_c;
triangleVertexA[face] = (short) coordinate_a;
triangleVertexB[face] = (short) coordinate_b;
triangleVertexC[face] = (short) coordinate_c;
}
if (opcode == 3) {
coordinate_a = coordinate_c;
coordinate_c = header.getSSmart() + last_coordinate;
last_coordinate = coordinate_c;
triangleVertexA[face] = (short) coordinate_a;
triangleVertexB[face] = (short) coordinate_b;
triangleVertexC[face] = (short) coordinate_c;
}
if (opcode == 4) {
int l14 = coordinate_a;
coordinate_a = coordinate_b;
coordinate_b = l14;
coordinate_c = header.getSSmart() + last_coordinate;
last_coordinate = coordinate_c;
triangleVertexA[face] = (short) coordinate_a;
triangleVertexB[face] = (short) coordinate_b;
triangleVertexC[face] = (short) coordinate_c;
}
}
header.pos = mainBuffer_offset;
nc2.pos = firstBuffer_offset;
nc3.pos = secondBuffer_offset;
nc4.pos = thirdBuffer_offset;
nc5.pos = fourthBuffer_offset;
nc6.pos = fifthBuffer_offset;
for (face = 0; face < texturedCount; face++) {
int opcode = textureTypes[face] & 0xff;
if (opcode == 0) {
textureVertexA[face] = (short) header.getUShort();
textureVertexB[face] = (short) header.getUShort();
textureVertexC[face] = (short) header.getUShort();
}
if (opcode == 1) {
textureVertexA[face] = (short) nc2.getUShort();
textureVertexB[face] = (short) nc2.getUShort();
textureVertexC[face] = (short) nc2.getUShort();
}
if (opcode == 2) {
textureVertexA[face] = (short) nc2.getUShort();
textureVertexB[face] = (short) nc2.getUShort();
textureVertexC[face] = (short) nc2.getUShort();
}
if (opcode == 3) {
textureVertexA[face] = (short) nc2.getUShort();
textureVertexB[face] = (short) nc2.getUShort();
textureVertexC[face] = (short) nc2.getUShort();
}
}
header.pos = pos;
face = header.getUByte();
if(face != 0) {
header.getUShort();
header.getUShort();
header.getUShort();
header.getInt();
}
}
private void decodeOld1(byte[] is) {
boolean has_face_type = false;
boolean has_texture_type = false;
Buffer[] buffers = new Buffer[5];
for(int i = 0; i < buffers.length; i++)
buffers[i] = new Buffer(is);
buffers[0].pos = is.length - 23;
vertexCount = buffers[0].getUShort();
triangleCount = buffers[0].getUShort();
texturedCount = buffers[0].getUByte();
int type_opcode = buffers[0].getUByte();
int priority_opcode = buffers[0].getUByte();
int alpha_opcode = buffers[0].getUByte();
int tSkin_opcode = buffers[0].getUByte();
int vSkin_opcode = buffers[0].getUByte();
int nwvar = buffers[0].getUByte();
int i_162_ = buffers[0].getUShort();
int i_163_ = buffers[0].getUShort();
int i_164_ = buffers[0].getUShort();
int i_165_ = buffers[0].getUShort();
int var22 = buffers[0].getUShort();
int pos = 0;
int i_167_ = pos;
pos += vertexCount;
int i_168_ = pos;
pos += triangleCount;
int priorityPos = pos;
if(priority_opcode == 255)
pos += triangleCount;
int i_170_ = pos;
if(tSkin_opcode == 1)
pos += triangleCount;
int i_171_ = pos;
if(type_opcode == 1)
pos += triangleCount;
int i_172_ = pos;
pos += var22;
//vskin opcode shud be here
int i_173_ = pos;
if(alpha_opcode == 1)
pos += triangleCount;
int i_174_ = pos;
pos += i_165_;
int i_175_ = pos;
pos += triangleCount * 2;
int i_176_ = pos;
pos += texturedCount * 6;
int i_177_ = pos;
pos += i_162_;
int i_178_ = pos;
pos += i_163_;
int i_179_ = pos;
vertexX = new int[vertexCount];
vertexY = new int[vertexCount];
vertexZ = new int[vertexCount];
triangleVertexA = new int[triangleCount];
triangleVertexB = new int[triangleCount];
triangleVertexC = new int[triangleCount];
unmodifiedTriangleColor = new int[triangleCount];
if(vSkin_opcode == 1)
vertexLabel = new int[vertexCount];
if(tSkin_opcode == 1)
triangleSkin = new int[triangleCount];
if (nwvar == 1) { // L: 376
this.field2180 = new int[vertexCount][]; // L: 377
this.field2181 = new int[vertexCount][]; // L: 378
}
if(alpha_opcode == 1)
triangleAlpha = new int[triangleCount];
if(priority_opcode != 255)
priority = (byte) priority_opcode;
else
trianglePriorities = new int[triangleCount];
if(texturedCount > 0) {
textureVertexA = new int[texturedCount];
textureVertexB = new int[texturedCount];
textureVertexC = new int[texturedCount];
textureTypes = new byte[texturedCount];
}
pos += i_164_;
if(type_opcode == 1) {
triTex = new int[triangleCount];
faceDrawType = new int[triangleCount];
triTexCoord = new short[triangleCount];
}
buffers[0].pos = i_167_;
buffers[1].pos = i_177_;
buffers[2].pos = i_178_;
buffers[3].pos = i_179_;
buffers[4].pos = i_172_;
int i_180_ = 0;
int i_181_ = 0;
int i_182_ = 0;
for(int point = 0; vertexCount > point; point++) {
int flag = buffers[0].getUByte();
int x = 0;
if((flag & 0x1) != 0)
x = buffers[1].getSSmart();
int i_186_ = 0;
if((0x2 & flag) != 0)
i_186_ = buffers[2].getSSmart();
int i_187_ = 0;
if((flag & 0x4) != 0)
i_187_ = buffers[3].getSSmart();
vertexX[point] = x + i_180_;
vertexY[point] = i_181_ + i_186_;
vertexZ[point] = i_182_ + i_187_;
i_180_ = vertexX[point];
i_181_ = vertexY[point];
i_182_ = vertexZ[point];
if(vSkin_opcode == 1) {
int weight = buffers[4].getUByte();
vertexLabel[point] = weight;
}
}
if (nwvar == 1) { // HERE 2
for (int var40 = 0; var40 < vertexCount; ++var40) { // L: 406
int var41 = buffers[4].getUByte(); // L: 407
this.field2180[var40] = new int[var41]; // L: 408
this.field2181[var40] = new int[var41]; // L: 409
for (int var42 = 0; var42 < var41; ++var42) { // L: 410
this.field2180[var40][var42] = buffers[4].getUByte(); // L: 411
this.field2181[var40][var42] = buffers[4].getUByte(); // L: 412
}
}
}
buffers[0].pos = i_175_;
buffers[1].pos = i_171_;
buffers[2].pos = priorityPos;
buffers[3].pos = i_173_;
buffers[4].pos = i_170_;
for(int face = 0; face < triangleCount; face++) {
unmodifiedTriangleColor[face] = buffers[0].getUShort();
if(type_opcode == 1) {
int i_189_ = buffers[1].getUByte();
if((i_189_ & 0x1) == 1) {
has_face_type = true;
faceDrawType[face] = (byte) 1;
} else
faceDrawType[face] = (byte) 0;
if((i_189_ & 0x2) == 2) {
triTexCoord[face] = (short) (i_189_ >> 2);
triTex[face] = unmodifiedTriangleColor[face];
unmodifiedTriangleColor[face] = 127;
if(triTex[face] != -1)
has_texture_type = true;
} else {
triTexCoord[face] = (short) -1;
triTex[face] = (short) -1;
}
}
if(priority_opcode == 255)
trianglePriorities[face] = buffers[2].getSByte();
if(alpha_opcode == 1) {
triangleAlpha[face] = buffers[3].getSByte();
if (triangleAlpha[face] < 0)
triangleAlpha[face] = (byte) (256 + triangleAlpha[face]);
}
if(tSkin_opcode == 1)
triangleSkin[face] = buffers[4].getUByte();
}
int used_vertexAmt = -1;
buffers[0].pos = i_174_;
buffers[1].pos = i_168_;
short i_190_ = 0;
short i_191_ = 0;
short i_192_ = 0;
int i_193_ = 0;
for(int i_194_ = 0; triangleCount > i_194_; i_194_++) {
int i_195_ = buffers[1].getUByte();
if(i_195_ == 1) {
i_190_ = (short) (i_193_ + buffers[0].getSSmart());
i_193_ = i_190_;
i_191_ = (short) (i_193_ + buffers[0].getSSmart());
i_193_ = i_191_;
i_192_ = (short) (buffers[0].getSSmart() + i_193_);
i_193_ = i_192_;
triangleVertexA[i_194_] = i_190_;
triangleVertexB[i_194_] = i_191_;
triangleVertexC[i_194_] = i_192_;
if(used_vertexAmt < i_190_)
used_vertexAmt = i_190_;
if((i_191_ ^ 0xffffffff) < (used_vertexAmt ^ 0xffffffff))
used_vertexAmt = i_191_;
if(i_192_ > used_vertexAmt)
used_vertexAmt = i_192_;
}
if(i_195_ == 2) {
i_191_ = i_192_;
i_192_ = (short) (i_193_ + buffers[0].getSSmart());
i_193_ = i_192_;
triangleVertexA[i_194_] = i_190_;
triangleVertexB[i_194_] = i_191_;
triangleVertexC[i_194_] = i_192_;
if(used_vertexAmt < i_192_)
used_vertexAmt = i_192_;
}
if(i_195_ == 3) {
i_190_ = i_192_;
i_192_ = (short) (buffers[0].getSSmart() + i_193_);
i_193_ = i_192_;
triangleVertexA[i_194_] = i_190_;
triangleVertexB[i_194_] = i_191_;
triangleVertexC[i_194_] = i_192_;
if((i_192_ ^ 0xffffffff) < (used_vertexAmt ^ 0xffffffff))
used_vertexAmt = i_192_;
}
if(i_195_ == 4) {
short i_196_ = i_190_;
i_190_ = i_191_;
i_191_ = i_196_;
i_192_ = (short) (buffers[0].getSSmart() + i_193_);
i_193_ = i_192_;
triangleVertexA[i_194_] = i_190_;
triangleVertexB[i_194_] = i_191_;
triangleVertexC[i_194_] = i_192_;
if((~i_192_) < (~used_vertexAmt))
used_vertexAmt = i_192_;
}
}
buffers[0].pos = i_176_;
used_vertexAmt++;
for(int i_197_ = 0; texturedCount > i_197_; i_197_++) {
textureTypes[i_197_] = (byte) 0;
textureVertexA[i_197_] = (short) buffers[0].getUShort();
textureVertexB[i_197_] = (short) buffers[0].getUShort();
textureVertexC[i_197_] = (short) buffers[0].getUShort();
}
if(triTexCoord != null) {
boolean textured = false;
for(int i_199_ = 0; i_199_ < triangleCount; i_199_++) {
int i_200_ = 0xffff & triTexCoord[i_199_];
if(i_200_ != 0xffff) {
if(((textureVertexA[i_200_] & 0xffff) == triangleVertexA[i_199_]) && ((0xffff & textureVertexB[i_200_]) == triangleVertexB[i_199_]) && triangleVertexC[i_199_] == (textureVertexC[i_200_] & 0xffff))
triTexCoord[i_199_] = (byte) -1;
else
textured = true;
}
}
if(!textured)
triTexCoord = null;
}
if(!has_texture_type) {
triTex = null;
}
if(!has_face_type)
faceDrawType = null;
int s = 4 << 7;
}