public Texture2D(ME3Package pccObj, int texIdx)
{
pccRef = pccObj;
// check if texIdx is an Export index and a Texture2D class
if (pccObj.isExport(texIdx) && (pccObj.Exports[texIdx].ClassName == className))
{
IExportEntry expEntry = pccObj.Exports[texIdx];
properties = new Dictionary<string, PropertyReader.Property>();
byte[] rawData = expEntry.Data;
int propertiesOffset = PropertyReader.detectStart(pccObj, rawData, expEntry.ObjectFlags);
headerData = new byte[propertiesOffset];
Buffer.BlockCopy(rawData, 0, headerData, 0, propertiesOffset);
pccOffset = (uint)expEntry.DataOffset;
List<PropertyReader.Property> tempProperties = PropertyReader.getPropList(expEntry);
texName = expEntry.ObjectName;
for (int i = 0; i < tempProperties.Count; i++)
{
PropertyReader.Property property = tempProperties[i];
if (!properties.ContainsKey(pccObj.Names[property.Name]))
properties.Add(pccObj.Names[property.Name], property);
switch (pccObj.Names[property.Name])
{
case "Format": texFormat = pccObj.Names[property.Value.IntValue].Substring(3); break;
case "TextureFileCacheName": arcName = pccObj.Names[property.Value.IntValue]; break;
case "LODGroup": LODGroup = pccObj.Names[property.Value.IntValue]; break;
case "None": dataOffset = (uint)(property.offsetval + property.Size); break;
}
}
// if "None" property isn't found throws an exception
if (dataOffset == 0)
throw new Exception("\"None\" property not found");
else
{
imageData = new byte[rawData.Length - dataOffset];
Buffer.BlockCopy(rawData, (int)dataOffset, imageData, 0, (int)(rawData.Length - dataOffset));
}
}
else
throw new Exception("Texture2D " + texIdx + " not found");
pccExpIdx = texIdx;
MemoryStream dataStream = new MemoryStream(imageData);
numMipMaps = dataStream.ReadValueU32();
uint count = numMipMaps;
imgList = new List<ImageInfo>();
while (dataStream.Position < dataStream.Length && count > 0)
{
ImageInfo imgInfo = new ImageInfo();
imgInfo.storageType = (storage)dataStream.ReadValueS32();
imgInfo.uncSize = dataStream.ReadValueS32();
imgInfo.cprSize = dataStream.ReadValueS32();
imgInfo.offset = dataStream.ReadValueS32();
if (imgInfo.storageType == storage.pccSto)
{
//imgInfo.offset = (int)(pccOffset + dataOffset); // saving pcc offset as relative to exportdata offset, not absolute
imgInfo.offset = (int)dataStream.Position; // saving pcc offset as relative to exportdata offset, not absolute
//MessageBox.Show("Pcc class offset: " + pccOffset + "\nimages data offset: " + imgInfo.offset.ToString());
dataStream.Seek(imgInfo.uncSize, SeekOrigin.Current);
}
imgInfo.imgSize = new ImageSize(dataStream.ReadValueU32(), dataStream.ReadValueU32());
imgList.Add(imgInfo);
count--;
}
// save what remains
/*int remainingBytes = (int)(dataStream.Length - dataStream.Position);
footerData = new byte[remainingBytes];
dataStream.Read(footerData, 0, footerData.Length);*/
}