public void CopyImgList(ME2Texture2D inTex, ME2PCCObject pcc)
{
numMipMaps = inTex.numMipMaps;
if (properties.ContainsKey("NeverStream") && properties["NeverStream"].Value.IntValue == 1)
{
imageData = null;
GC.Collect();
// store images as pccSto format
privateimgList = new List<ImageInfo>();
MemoryStream tempData = new MemoryStream();
for (int i = 0; i < inTex.privateimgList.Count; i++)
{
ImageInfo newImg = new ImageInfo();
ImageInfo replaceImg = inTex.privateimgList[i];
newImg.storageType = storage.pccSto;
newImg.uncSize = replaceImg.uncSize;
newImg.cprSize = replaceImg.uncSize;
newImg.imgSize = replaceImg.imgSize;
newImg.offset = (int)(tempData.Position);
if (replaceImg.storageType == storage.arcCpr)
{
string archivePath = inTex.FullArcPath;
if (!File.Exists(archivePath))
throw new FileNotFoundException("Texture archive not found in " + archivePath);
using (FileStream archiveStream = File.OpenRead(archivePath))
{
archiveStream.Seek(replaceImg.offset, SeekOrigin.Begin);
SaltLZOHelper lzohelp = new SaltLZOHelper();
tempData.WriteBytes(lzohelp.DecompressTex(archiveStream, replaceImg.offset, replaceImg.uncSize, replaceImg.cprSize));
}
}
else if (replaceImg.storageType == storage.pccSto)
{
byte[] buffer = new byte[newImg.cprSize];
Buffer.BlockCopy(inTex.imageData, replaceImg.offset, buffer, 0, buffer.Length);
tempData.WriteBytes(buffer);
}
else
throw new NotImplementedException("Copying from non package stored texture no available");
privateimgList.Add(newImg);
}
for (int i = 0; i < privateimgList.Count; i++)
{
ImageInfo tempinfo = privateimgList[i];
if (inTex.privateimgList[i].storageType == storage.empty)
tempinfo.storageType = storage.empty;
privateimgList[i] = tempinfo;
}
imageData = tempData.ToArray();
tempData.Close();
tempData = null;
GC.Collect();
}
else
{
imageData = inTex.imageData;
privateimgList = inTex.privateimgList;
}
// add properties "TextureFileCacheName" and "TFCFileGuid" if they are missing,
if (!properties.ContainsKey("TextureFileCacheName") && inTex.properties.ContainsKey("TextureFileCacheName"))
{
SaltPropertyReader.Property none = properties["None"];
properties.Remove("None");
SaltPropertyReader.Property property = new SaltPropertyReader.Property();
property.TypeVal = SaltPropertyReader.Type.NameProperty;
property.Name = "TextureFileCacheName";
property.Size = 8;
SaltPropertyReader.PropertyValue value = new SaltPropertyReader.PropertyValue();
value.StringValue = "Textures";
property.Value = value;
properties.Add("TextureFileCacheName", property);
arcName = value.StringValue;
if (!properties.ContainsKey("TFCFileGuid"))
{
SaltPropertyReader.Property guidprop = new SaltPropertyReader.Property();
guidprop.TypeVal = SaltPropertyReader.Type.StructProperty;
guidprop.Name = "TFCFileGuid";
guidprop.Size = 16;
SaltPropertyReader.PropertyValue guid = new SaltPropertyReader.PropertyValue();
guid.len = guidprop.Size;
guid.StringValue = "Guid";
guid.IntValue = pcc.AddName(guid.StringValue);
guid.Array = new List<SaltPropertyReader.PropertyValue>();
for (int i = 0; i < 4; i++)
guid.Array.Add(new SaltPropertyReader.PropertyValue());
guidprop.Value = guid;
properties.Add("TFCFileGuid", guidprop);
}
properties.Add("None", none);
}
// copy specific properties from inTex
for (int i = 0; i < inTex.properties.Count; i++)
{
SaltPropertyReader.Property prop = inTex.properties.ElementAt(i).Value;
switch (prop.Name)
{
case "TextureFileCacheName":
arcName = prop.Value.StringValue;
properties["TextureFileCacheName"].Value.StringValue = arcName;
break;
case "TFCFileGuid":
SaltPropertyReader.Property GUIDProp = properties["TFCFileGuid"];
for (int l = 0; l < 4; l++)
{
SaltPropertyReader.PropertyValue tempVal = GUIDProp.Value.Array[l];
tempVal.IntValue = prop.Value.Array[l].IntValue;
GUIDProp.Value.Array[l] = tempVal;
}
break;
case "MipTailBaseIdx":
properties["MipTailBaseIdx"].Value.IntValue = prop.Value.IntValue;
break;
case "SizeX":
properties["SizeX"].Value.IntValue = prop.Value.IntValue;
break;
case "SizeY":
properties["SizeY"].Value.IntValue = prop.Value.IntValue;
break;
}
}
}