public BTP(NitroFile file, BMD model) { this.m_File = file; this.m_FileName = file.m_Name; this.m_Model = model; m_NumFrames = m_File.Read16(0x00); m_NumTextures = m_File.Read16(0x02); m_TextureHeadersOffset = m_File.Read32(0x04); m_TextureNames = new List<string>(); m_NumPalettes = m_File.Read16(0x08); m_PaletteHeadersOffset = m_File.Read32(0x0C); m_PaletteNames = new List<string>(); m_FrameChangesOffset = m_File.Read32(0x10); m_FrameTextureIDsOffset = m_File.Read32(0x14); m_FramePaletteIDsOffset = m_File.Read32(0x18); m_NumMaterials = m_File.Read16(0x1C); m_MaterialHeadersOffset = m_File.Read32(0x20); m_MaterialNames = new List<string>(); for (int i = 0; i < m_NumTextures; i++) { m_TextureNames.Add(m_File.ReadString(m_File.Read32(m_TextureHeadersOffset + 0x04 + (uint)(i * 8)), 0)); } for (int i = 0; i < m_NumPalettes; i++) { m_PaletteNames.Add(m_File.ReadString(m_File.Read32(m_PaletteHeadersOffset + 0x04 + (uint)(i * 8)), 0)); } // Read in the frames for each material m_MaterialData = new Dictionary<string, BTPMaterialData>(); m_Frames = new List<BTPFrameData>(); for (int i = 0; i < m_NumMaterials; i++) { m_MaterialNames.Add(m_File.ReadString(m_File.Read32(m_MaterialHeadersOffset + 0x04 + (uint)(i * 12)), 0)); ushort matFrameChanges = m_File.Read16(m_MaterialHeadersOffset + 0x08 + (uint)(i * 12)); ushort startOffsetFrameChanges = m_File.Read16(m_MaterialHeadersOffset + 0x0A + (uint)(i * 12)); int matNumFrames = 0; for (int j = 0; j < matFrameChanges; j++) { ushort frameNum = m_File.Read16((uint)(m_FrameChangesOffset + (startOffsetFrameChanges * 2) + (j * 2))); // If not the last frame in the sequence, length = (next frame number - current frame number) else, // length = (number of frames in sequence - current frame number) int nextFrameNum = (j != (matFrameChanges - 1)) ? (int)m_File.Read16((uint)(m_FrameChangesOffset + (startOffsetFrameChanges * 2) + ((j + 1) * 2))) : -1; int length = (nextFrameNum != -1) ? (nextFrameNum - frameNum) : (m_NumFrames - frameNum); ushort texID = m_File.Read16((uint)(m_FrameTextureIDsOffset + (startOffsetFrameChanges * 2) + (j * 2))); ushort palID = m_File.Read16((uint)(m_FramePaletteIDsOffset + (startOffsetFrameChanges * 2) + (j * 2))); AddFrame(matNumFrames, m_Frames.Count, texID, palID, length); matNumFrames += length; } BTPMaterialData matData = new BTPMaterialData(m_MaterialNames[i], matFrameChanges, startOffsetFrameChanges, matNumFrames); m_MaterialData.Add(m_MaterialNames[i], matData); } }
public BTP(NitroFile file, BMD model) { this.m_File = file; this.m_FileName = file.m_Name; this.m_Model = model; m_NumFrames = m_File.Read16(0x00); m_NumTextures = m_File.Read16(0x02); m_TextureHeadersOffset = m_File.Read32(0x04); m_TextureNames = new List <string>(); m_NumPalettes = m_File.Read16(0x08); m_PaletteHeadersOffset = m_File.Read32(0x0C); m_PaletteNames = new List <string>(); m_FrameChangesOffset = m_File.Read32(0x10); m_FrameTextureIDsOffset = m_File.Read32(0x14); m_FramePaletteIDsOffset = m_File.Read32(0x18); m_NumMaterials = m_File.Read16(0x1C); m_MaterialHeadersOffset = m_File.Read32(0x20); m_MaterialNames = new List <string>(); for (int i = 0; i < m_NumTextures; i++) { m_TextureNames.Add(m_File.ReadString(m_File.Read32(m_TextureHeadersOffset + 0x04 + (uint)(i * 8)), 0)); } for (int i = 0; i < m_NumPalettes; i++) { m_PaletteNames.Add(m_File.ReadString(m_File.Read32(m_PaletteHeadersOffset + 0x04 + (uint)(i * 8)), 0)); } // Read in the frames for each material m_MaterialData = new Dictionary <string, BTPMaterialData>(); m_Frames = new List <BTPFrameData>(); for (int i = 0; i < m_NumMaterials; i++) { m_MaterialNames.Add(m_File.ReadString(m_File.Read32(m_MaterialHeadersOffset + 0x04 + (uint)(i * 12)), 0)); ushort matFrameChanges = m_File.Read16(m_MaterialHeadersOffset + 0x08 + (uint)(i * 12)); ushort startOffsetFrameChanges = m_File.Read16(m_MaterialHeadersOffset + 0x0A + (uint)(i * 12)); int matNumFrames = 0; for (int j = 0; j < matFrameChanges; j++) { ushort frameNum = m_File.Read16((uint)(m_FrameChangesOffset + (startOffsetFrameChanges * 2) + (j * 2))); // If not the last frame in the sequence, length = (next frame number - current frame number) else, // length = (number of frames in sequence - current frame number) int nextFrameNum = (j != (matFrameChanges - 1)) ? (int)m_File.Read16((uint)(m_FrameChangesOffset + (startOffsetFrameChanges * 2) + ((j + 1) * 2))) : -1; int length = (nextFrameNum != -1) ? (nextFrameNum - frameNum) : (m_NumFrames - frameNum); ushort texID = m_File.Read16((uint)(m_FrameTextureIDsOffset + (startOffsetFrameChanges * 2) + (j * 2))); ushort palID = m_File.Read16((uint)(m_FramePaletteIDsOffset + (startOffsetFrameChanges * 2) + (j * 2))); AddFrame(matNumFrames, m_Frames.Count, texID, palID, length); matNumFrames += length; } BTPMaterialData matData = new BTPMaterialData(m_MaterialNames[i], matFrameChanges, startOffsetFrameChanges, matNumFrames); m_MaterialData.Add(m_MaterialNames[i], matData); } }