public ME2Texture2D(ME2PCCObject pcc, int pccExpID, String pathBioGame)
{
ME2ExportEntry exp = pcc.Exports[pccExpID];
if (String.Compare(exp.ClassName, className) != 0 && String.Compare(exp.ClassName, class2) != 0 && String.Compare(exp.ClassName, class3) != 0)
{
throw new FormatException("Export is not a texture");
}
Class = exp.ClassName;
exportOffset = exp.DataOffset;
FullPackage = exp.PackageFullName;
texName = exp.ObjectName;
pccFileName = pcc.pccFileName;
allPccs = new List<string>();
allPccs.Add(pcc.pccFileName);
properties = new Dictionary<string, SaltPropertyReader.Property>();
byte[] rawData = (byte[])exp.Data.Clone();
Compression = "No Compression";
int propertiesOffset = SaltPropertyReader.detectStart(pcc, rawData);
headerData = new byte[propertiesOffset];
Buffer.BlockCopy(rawData, 0, headerData, 0, propertiesOffset);
pccOffset = (uint)exp.DataOffset;
UnpackNum = 0;
List<SaltPropertyReader.Property> tempProperties = SaltPropertyReader.getPropList(pcc, rawData);
for (int i = 0; i < tempProperties.Count; i++)
{
SaltPropertyReader.Property property = tempProperties[i];
if (property.Name == "UnpackMin")
UnpackNum++;
if (!properties.ContainsKey(property.Name))
properties.Add(property.Name, property);
switch (property.Name)
{
case "Format": texFormat = Textures.Methods.ParseFormat(property.Value.StringValue); break;
case "TextureFileCacheName": arcName = property.Value.StringValue; break;
case "LODGroup": LODGroup = property.Value.StringValue; break;
case "CompressionSettings": Compression = property.Value.StringValue; 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");
if (!String.IsNullOrEmpty(arcName))
FullArcPath = GetTexArchive(pathBioGame);
imageData = new byte[rawData.Length - dataOffset];
Buffer.BlockCopy(rawData, (int)dataOffset, imageData, 0, (int)(rawData.Length - dataOffset));
//DebugOutput.PrintLn("ImageData size = " + imageData.Length);
pccExpIdx = pccExpID;
MemoryStream dataStream = new MemoryStream(imageData);
privateimgList = new List<ImageInfo>();
dataStream.ReadValueU32(); //Current position in pcc
numMipMaps = dataStream.ReadValueU32();
uint count = numMipMaps;
ArcDataSize = 0;
//DebugOutput.PrintLn(numMipMaps + " derp");
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)dataStream.Position;
dataStream.Seek(imgInfo.uncSize, SeekOrigin.Current);
}
else if (imgInfo.storageType == storage.arcCpr || imgInfo.storageType == storage.arcUnc)
{
ArcDataSize += imgInfo.uncSize;
}
imgInfo.imgSize = new ImageSize(dataStream.ReadValueU32(), dataStream.ReadValueU32());
if (privateimgList.Exists(img => img.imgSize == imgInfo.imgSize))
{
uint width = imgInfo.imgSize.width;
uint height = imgInfo.imgSize.height;
if (width == 4 && privateimgList.Exists(img => img.imgSize.width == width))
width = privateimgList.Last().imgSize.width / 2;
if (width == 0)
width = 1;
if (height == 4 && privateimgList.Exists(img => img.imgSize.height == height))
height = privateimgList.Last().imgSize.height / 2;
if (height == 0)
height = 1;
imgInfo.imgSize = new ImageSize(width, height);
if (privateimgList.Exists(img => img.imgSize == imgInfo.imgSize))
throw new Exception("Duplicate image size found");
}
privateimgList.Add(imgInfo);
count--;
//DebugOutput.PrintLn("ImgInfo no: " + count + ", Storage Type = " + imgInfo.storageType + ", offset = " + imgInfo.offset);
}
// Grab the rest for the footer
footerData = new byte[dataStream.Length - dataStream.Position];
footerData = dataStream.ReadBytes(footerData.Length);
}