public void ReadMaterial(byte[] file, uint address, uint materialStructCount) { NJS_MATERIAL newMat = new NJS_MATERIAL(); int curAddress = (int)address; for (int i = 0; i < materialStructCount; i++) { uint type = ByteConverter.ToUInt32(file, curAddress); curAddress += 4; switch (type) { case 2: newMat.SourceAlpha = (AlphaInstruction)ByteConverter.ToUInt32(file, curAddress); curAddress += 4; newMat.DestinationAlpha = (AlphaInstruction)ByteConverter.ToUInt32(file, curAddress); curAddress += 4; mat2_08 = ByteConverter.ToInt32(file, curAddress); curAddress += 4; break; case 3: newMat.TextureID = ByteConverter.ToInt32(file, curAddress); curAddress += 4; mat3_04 = ByteConverter.ToInt32(file, curAddress); curAddress += 4; mat3_08 = ByteConverter.ToInt32(file, curAddress); curAddress += 4; break; case 4: mat4_00 = ByteConverter.ToInt32(file, curAddress); curAddress += 4; mat4_04 = ByteConverter.ToInt32(file, curAddress); curAddress += 4; mat4_08 = ByteConverter.ToInt32(file, curAddress); curAddress += 4; break; case 5: newMat.DiffuseColor = VColor.FromBytes(file, (int)address, ColorType.RGBA8888_32); mat5_04 = ByteConverter.ToInt32(file, curAddress); curAddress += 4; mat5_08 = ByteConverter.ToInt32(file, curAddress); curAddress += 4; break; case 6: mat6_00 = ByteConverter.ToInt32(file, curAddress); curAddress += 4; mat6_04 = ByteConverter.ToInt32(file, curAddress); curAddress += 4; mat6_08 = ByteConverter.ToInt32(file, curAddress); curAddress += 4; break; default: ByteConverter.ToInt32(file, curAddress); curAddress += 4; ByteConverter.ToInt32(file, curAddress); curAddress += 4; ByteConverter.ToInt32(file, curAddress); curAddress += 4; //Debug.WriteLine($"Unexpected xj material type {type} at {(curAddress - 4).ToString("X")}"); break; } } mat = newMat; }
public XJVertexSet(byte[] file, int address, uint imageBase, Dictionary <int, string> labels) { VertexType = ByteConverter.ToUInt16(file, address); Ushort_02 = ByteConverter.ToUInt16(file, address + 0x2); var vertListOffset = ByteConverter.ToUInt32(file, address + 0x4); VertexSize = ByteConverter.ToUInt32(file, address + 0x8); var vertCount = ByteConverter.ToUInt32(file, address + 0xC); bool hasUV = (VertexType & 0x1) > 0; bool hasNormal = (VertexType & 0x2) > 0; bool hasColor = (VertexType & 0x4) > 0; bool hasUnk0 = (VertexType & 0x8) > 0; bool hasUnk1 = (VertexType & 0x10) > 0; bool hasUnk2 = (VertexType & 0x20) > 0; bool hasUnk3 = (VertexType & 0x40) > 0; bool hasUnk4 = (VertexType & 0x80) > 0; ushort calcedVertSize = 0xC; if (hasNormal) { calcedVertSize += 0xC; } if (hasColor) { calcedVertSize += 0x4; } if (hasUV) { calcedVertSize += 0x8; } if (VertexSize != calcedVertSize) { throw new Exception($"Vertsize {VertexSize} is not equal to Calculated Vertsize {calcedVertSize}"); } address = (int)(vertListOffset - imageBase); for (int i = 0; i < vertCount; i++) { Positions.Add(new Vertex(file, address)); address += 0xC; if (hasNormal) { Normals.Add(new Vertex(file, address)); address += 0xC; } if (hasColor) { Colors.Add(VColor.FromBytes(file, address, ColorType.RGBA8888_32)); address += 0x4; } if (hasUV) { UVs.Add(new UV(file, address, false, false, true)); address += 0x8; } } }