Inheritance: IPCCObject
Ejemplo n.º 1
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="file"></param>
 /// <param name="stream"></param>
 /// <param name="WhichGame"></param>
 /// <returns></returns>
 public static IPCCObject CreatePCCObject(string file, MemoryTributary stream, int WhichGame)
 {
     IPCCObject pcc;
     if (WhichGame == 1)
         pcc = new ME1PCCObject(file, stream);
     else if (WhichGame == 2)
         pcc = new ME2PCCObject(file, stream);
     else if (WhichGame == 3)
         pcc = new ME3PCCObject(file, stream);
     else
     {
         DebugOutput.PrintLn("WHAT HAVE YOU DONE!!   PCCObject creation failed!");
         return null;
     }
     return pcc;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a PCCObject from a file.
        /// </summary>
        /// <param name="file">PCC file to create object from.</param>
        /// <param name="WhichGame">Game version.</param>
        /// <returns>IPCCObject from file.</returns>
        public static IPCCObject CreatePCCObject(string file, int WhichGame)
        {
            IPCCObject pcc;

            // KFreon: Use different methods for each game.
            if (WhichGame == 1)
                pcc = new ME1PCCObject(file);
            else if (WhichGame == 2)
                pcc = new ME2PCCObject(file);
            else if (WhichGame == 3)
                pcc = new ME3PCCObject(file);
            else
            {
                DebugOutput.PrintLn("WHAT HAVE YOU DONE!!   PCCObject creation failed!");
                return null;
            }
            return pcc;
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="file"></param>
        /// <param name="stream"></param>
        /// <param name="WhichGame"></param>
        /// <returns></returns>
        public static IPCCObject CreatePCCObject(string file, MemoryStream stream, int WhichGame)
        {
            IPCCObject pcc;

            if (WhichGame == 1)
            {
                pcc = new ME1PCCObject(file, stream);
            }
            else if (WhichGame == 2)
            {
                pcc = new ME2PCCObject(file, stream);
            }
            else if (WhichGame == 3)
            {
                pcc = new ME3PCCObject(file, stream);
            }
            else
            {
                DebugOutput.PrintLn("WHAT HAVE YOU DONE!!   PCCObject creation failed!");
                return(null);
            }
            return(pcc);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a PCCObject from a file.
        /// </summary>
        /// <param name="file">PCC file to create object from.</param>
        /// <param name="WhichGame">Game version.</param>
        /// <returns>IPCCObject from file.</returns>
        public static IPCCObject CreatePCCObject(string file, int WhichGame)
        {
            IPCCObject pcc;

            // KFreon: Use different methods for each game.
            if (WhichGame == 1)
            {
                pcc = new ME1PCCObject(file);
            }
            else if (WhichGame == 2)
            {
                pcc = new ME2PCCObject(file);
            }
            else if (WhichGame == 3)
            {
                pcc = new ME3PCCObject(file);
            }
            else
            {
                DebugOutput.PrintLn("WHAT HAVE YOU DONE!!   PCCObject creation failed!");
                return(null);
            }
            return(pcc);
        }
Ejemplo n.º 5
0
        public byte[] extractImage(ImageInfo imgInfo, bool NoOutput, string archiveDir = null, string fileName = null)
        {
            ImageFile imgFile;
            if (fileName == null)
                fileName = texName + "_" + imgInfo.imgSize + getFileFormat();

            byte[] imgBuffer = null;

            switch (imgInfo.storageType)
            {
                case storage.pccSto:
                    imgBuffer = new byte[imgInfo.uncSize];
                    Buffer.BlockCopy(imageData, imgInfo.offset, imgBuffer, 0, imgInfo.uncSize);
                    break;
                case storage.arcCpr:
                case storage.arcUnc:
                    string archivePath = FindFile();
                    if (String.IsNullOrEmpty(archivePath))
                        throw new FileNotFoundException();
                    ME1PCCObject temp = new ME1PCCObject(archivePath);
                    for (int i = 0; i < temp.ExportCount; i++)
                    {
                        if (String.Compare(texName, temp.Exports[i].ObjectName, true) == 0 && temp.Exports[i].ValidTextureClass())
                        {
                            ME1Texture2D temptex = new ME1Texture2D(temp, i);
                            imgBuffer = temptex.extractImage(imgInfo.imgSize.ToString(), NoOutput, null, fileName);
                            //                            temptex.extractImage(imgInfo.imgSize.ToString(), temp, null, fileName);
                        }
                    }
                    break;
                case storage.pccCpr:
                    using (MemoryStream ms = new MemoryStream(imageData))
                    {
                        SaltLZOHelper lzohelp = new SaltLZOHelper();
                        imgBuffer = lzohelp.DecompressTex(ms, imgInfo.offset, imgInfo.uncSize, imgInfo.cprSize);
                    }
                    break;
                default:
                    throw new FormatException("Unsupported texture storage type");
            }

            if (imgInfo.storageType == storage.pccSto || imgInfo.storageType == storage.pccCpr)
            {
                if (getFileFormat() == ".dds")
                    imgFile = new DDS(fileName, imgInfo.imgSize, texFormat, imgBuffer);
                else
                    imgFile = new TGA(fileName, imgInfo.imgSize, texFormat, imgBuffer);

                byte[] saveImg = imgFile.ToArray();

                if (!NoOutput)
                    using (FileStream outputImg = new FileStream(imgFile.fileName, FileMode.Create, FileAccess.Write))
                        outputImg.Write(saveImg, 0, saveImg.Length);
                return saveImg;
            }
            return imgBuffer;
        }
Ejemplo n.º 6
0
 public void LoadPcc(IPCCObject pcc, string path)
 {
     switch (pcc.GameVersion)
     {
         case 1:
             pcc = new ME1PCCObject(path);
             break;
         case 2:
             pcc = new ME2PCCObject(path);
             break;
         case 3:
             pcc = new ME3PCCObject(path);
             break;
     }
 }
Ejemplo n.º 7
0
        public ME1Texture2D(ME1PCCObject pcc, int pccExpID)
        {
            ME1ExportEntry exp = pcc.Exports[pccExpID]; ;
            Class = exp.ClassName;
            exportOffset = exp.DataOffset;
            FullPackage = exp.PackageFullName;
            texName = exp.ObjectName;
            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 = 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");
            else
            {
                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;
            //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.pccCpr)
                {
                    imgInfo.offset = (int)dataStream.Position;
                    dataStream.Seek(imgInfo.cprSize, SeekOrigin.Current);
                }

                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);
            }
            dataStream.Seek(-4, SeekOrigin.End);
            footerData = dataStream.ReadBytes(4);
            dataStream.Dispose();
        }
Ejemplo n.º 8
0
        public byte[] DumpImage(ImageSize imgSize)
        {
            byte[] imgBuffer = null;

            ImageInfo imgInfo;
            if (privateimgList.Exists(img => (img.imgSize == imgSize && img.cprSize != -1)))
                imgInfo = privateimgList.Find(img => img.imgSize == imgSize);
            else
                //throw new FileNotFoundException("Image with resolution " + imgSize + " not found");
                return null;
            switch (imgInfo.storageType)
            {
                case storage.pccSto:
                    imgBuffer = new byte[imgInfo.uncSize];
                    Buffer.BlockCopy(imageData, imgInfo.offset, imgBuffer, 0, imgInfo.uncSize);
                    break;
                case storage.arcCpr:
                case storage.arcUnc:
                    string archivePath = FindFile();
                    if (String.IsNullOrEmpty(archivePath))
                        throw new FileNotFoundException();
                    ME1PCCObject temp = new ME1PCCObject(archivePath);
                    for (int i = 0; i < temp.ExportCount; i++)
                    {
                        if (String.Compare(texName, temp.Exports[i].ObjectName, true) == 0 && (temp.Exports[i].ClassName == "Texture2D"))// || temp.Exports[i].ClassName == "TextureFlipBook"))
                        {
                            ME1Texture2D temptex = new ME1Texture2D(temp, i);
                            /*if (imgSize.width > dims)
                            {
                                dims = (int) imgSize.width;*/
                            byte[] temp1 = temptex.DumpImage(imgSize);
                            if (temp1 != null)
                                imgBuffer = temp1;
                            //}

                        }
                    }
                    break;
                case storage.pccCpr:
                    using (MemoryStream ms = new MemoryStream(imageData))
                    {
                        SaltLZOHelper lzohelp = new SaltLZOHelper();
                        imgBuffer = lzohelp.DecompressTex(ms, imgInfo.offset, imgInfo.uncSize, imgInfo.cprSize);
                    }
                    break;
                default:
                    throw new FormatException("Unsupported texture storage type");
                    imgBuffer = null;
                    break;
            }

            return imgBuffer;
        }
Ejemplo n.º 9
0
        public void CopyImgList(ME1Texture2D inTex, ME1PCCObject pcc, bool norender = false)
        {
            List<ImageInfo> tempList = new List<ImageInfo>();
            MemoryStream tempData = new MemoryStream();
            SaltLZOHelper lzo = new SaltLZOHelper();
            numMipMaps = inTex.numMipMaps;

            // forced norenderfix
            // norender = true;

            int type = -1;
            if (!norender)
            {
                if (privateimgList.Exists(img => img.storageType == storage.arcCpr) && privateimgList.Count > 1)
                    type = 1;
                else if (privateimgList.Exists(img => img.storageType == storage.pccCpr))
                    type = 2;
                else if (privateimgList.Exists(img => img.storageType == storage.pccSto) || privateimgList.Count == 1)
                    type = 3;
            }
            else
                type = 3;

            switch (type)
            {
                case 1:
                    for (int i = 0; i < inTex.privateimgList.Count; i++)
                    {
                        try
                        {
                            ImageInfo newImg = new ImageInfo();
                            ImageInfo replaceImg = inTex.privateimgList[i];
                            ME1Texture2D.storage replaceType = privateimgList.Find(img => img.imgSize == replaceImg.imgSize).storageType;

                            int j = 0;
                            while (replaceType == storage.empty)
                            {
                                j++;
                                replaceType = privateimgList[privateimgList.FindIndex(img => img.imgSize == replaceImg.imgSize) + j].storageType;
                            }

                            if (replaceType == storage.arcCpr || !privateimgList.Exists(img => img.imgSize == replaceImg.imgSize))
                            {
                                newImg.storageType = storage.arcCpr;
                                newImg.uncSize = replaceImg.uncSize;
                                newImg.cprSize = replaceImg.cprSize;
                                newImg.imgSize = replaceImg.imgSize;
                                newImg.offset = (int)(replaceImg.offset + inTex.pccOffset + inTex.dataOffset);
                            }
                            else
                            {
                                newImg.storageType = storage.pccSto;
                                newImg.uncSize = replaceImg.uncSize;
                                newImg.cprSize = replaceImg.uncSize;
                                newImg.imgSize = replaceImg.imgSize;
                                newImg.offset = (int)(tempData.Position);
                                using (MemoryStream tempStream = new MemoryStream(inTex.imageData))
                                {
                                    tempData.WriteBytes(lzo.DecompressTex(tempStream, replaceImg.offset, replaceImg.uncSize, replaceImg.cprSize));
                                }
                            }
                            tempList.Add(newImg);
                        }
                        catch
                        {
                            ImageInfo replaceImg = inTex.privateimgList[i];
                            if (!privateimgList.Exists(img => img.imgSize == replaceImg.imgSize))
                                throw new Exception("An error occurred during imglist copying and no suitable replacement was found");
                            ImageInfo newImg = privateimgList.Find(img => img.imgSize == replaceImg.imgSize);
                            if (newImg.storageType != storage.pccCpr && newImg.storageType != storage.pccSto)
                                throw new Exception("An error occurred during imglist copying and no suitable replacement was found");
                            int temppos = newImg.offset;
                            newImg.offset = (int)tempData.Position;
                            tempData.Write(imageData, temppos, newImg.cprSize);
                            tempList.Add(newImg);
                        }
                    }
                    break;
                case 2:
                    for (int i = 0; i < inTex.privateimgList.Count; i++)
                    {
                        ImageInfo newImg = new ImageInfo();
                        ImageInfo replaceImg = inTex.privateimgList[i];
                        newImg.storageType = storage.pccCpr;
                        newImg.uncSize = replaceImg.uncSize;
                        newImg.cprSize = replaceImg.cprSize;
                        newImg.imgSize = replaceImg.imgSize;
                        newImg.offset = (int)(tempData.Position);
                        byte[] buffer = new byte[newImg.cprSize];
                        Buffer.BlockCopy(inTex.imageData, replaceImg.offset, buffer, 0, buffer.Length);
                        tempData.WriteBytes(buffer);
                        tempList.Add(newImg);
                    }
                    break;
                case 3:
                    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.pccCpr)
                        {
                            using (MemoryStream tempStream = new MemoryStream(inTex.imageData))
                            {
                                tempData.WriteBytes(lzo.DecompressTex(tempStream, 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");
                        tempList.Add(newImg);
                    }
                    break;
                default:
                    throw new NotImplementedException();
            }

            for (int i = 0; i < tempList.Count; i++)
            {
                ImageInfo tempinfo = tempList[i];
                if (inTex.privateimgList[i].storageType == storage.empty)
                    tempinfo.storageType = storage.empty;
                tempList[i] = tempinfo;
            }

            privateimgList = tempList;
            imageData = tempData.ToArray();
            tempData.Close();

            byte[] buff;
            //Copy properties
            using (MemoryStream tempMem = new MemoryStream())
            {
                tempMem.WriteBytes(headerData);
                for (int i = 0; i < inTex.properties.Count; i++)
                {
                    SaltPropertyReader.Property prop = inTex.properties.ElementAt(i).Value;

                    if (prop.Name == "UnpackMin")
                    {
                        for (int j = 0; j < inTex.UnpackNum; j++)
                        {
                            tempMem.WriteValueS64(pcc.AddName(prop.Name));
                            tempMem.WriteValueS64(pcc.AddName(prop.TypeVal.ToString()));
                            tempMem.WriteValueS32(prop.Size);
                            tempMem.WriteValueS32(j);
                            tempMem.WriteValueF32(prop.Value.FloatValue, Endian.Little);
                        }
                        continue;
                    }

                    tempMem.WriteValueS64(pcc.AddName(prop.Name));
                    if (prop.Name == "None")
                    {
                        for (int j = 0; j < 12; j++)
                            tempMem.WriteByte(0);
                    }
                    else
                    {
                        tempMem.WriteValueS64(pcc.AddName(prop.TypeVal.ToString()));
                        tempMem.WriteValueS64(prop.Size);

                        switch (prop.TypeVal)
                        {
                            case SaltPropertyReader.Type.IntProperty:
                                tempMem.WriteValueS32(prop.Value.IntValue);
                                break;
                            case SaltPropertyReader.Type.BoolProperty:
                                tempMem.Seek(-4, SeekOrigin.Current);
                                tempMem.WriteValueS32(prop.Value.IntValue);
                                tempMem.Seek(4, SeekOrigin.Current);
                                break;
                            case SaltPropertyReader.Type.NameProperty:
                                tempMem.WriteValueS64(pcc.AddName(prop.Value.StringValue));
                                // Heff: Modified to handle name references.
                                //var index = pcc.AddName(prop.Value.StringValue);
                                //tempMem.WriteValueS32(index);
                                //tempMem.WriteValueS32(prop.Value.NameValue.count);
                                break;
                            case SaltPropertyReader.Type.StrProperty:
                                tempMem.WriteValueS32(prop.Value.StringValue.Length + 1);
                                foreach (char c in prop.Value.StringValue)
                                    tempMem.WriteByte((byte)c);
                                tempMem.WriteByte(0);
                                break;
                            case SaltPropertyReader.Type.StructProperty:
                                tempMem.WriteValueS64(pcc.AddName(prop.Value.StringValue));
                                foreach (SaltPropertyReader.PropertyValue value in prop.Value.Array)
                                    tempMem.WriteValueS32(value.IntValue);
                                break;
                            case SaltPropertyReader.Type.ByteProperty:
                                tempMem.WriteValueS32(pcc.AddName(prop.Value.StringValue));
                                tempMem.WriteValueS32(prop.Value.IntValue);
                                break;
                            case SaltPropertyReader.Type.FloatProperty:
                                tempMem.WriteValueF32(prop.Value.FloatValue, Endian.Little);
                                break;
                            default:
                                throw new FormatException("unknown property");
                        }
                    }
                }
                buff = tempMem.ToArray();
            }

            int propertiesOffset = SaltPropertyReader.detectStart(pcc, buff);
            headerData = new byte[propertiesOffset];
            Buffer.BlockCopy(buff, 0, headerData, 0, propertiesOffset);
            properties = new Dictionary<string, SaltPropertyReader.Property>();
            List<SaltPropertyReader.Property> tempProperties = SaltPropertyReader.getPropList(pcc, buff);
            UnpackNum = 0;
            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 = 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");
        }
Ejemplo n.º 10
0
 public void ChangeTexFormat(string newFormat, ME1PCCObject pcc)
 {
     SaltPropertyReader.Property prop = properties["Format"];
     Int64 formatID = (Int64)pcc.AddName(newFormat);
     byte[] buff = BitConverter.GetBytes(formatID);
     Buffer.BlockCopy(buff, 0, prop.raw, 24, sizeof(Int64));
     prop.Value.StringValue = pcc.Names[(int)formatID];
     properties["Format"] = prop;
     texFormat = properties["Format"].Value.StringValue;
 }
Ejemplo n.º 11
0
 public void ChangeCompression(string newComp, ME1PCCObject pcc)
 {
     if (!properties.ContainsKey("CompressionSettings"))
         throw new KeyNotFoundException("Texture doesn't have a compression property");
     SaltPropertyReader.Property prop = properties["CompressionSettings"];
     Int64 comp = (Int64)pcc.AddName(newComp);
     byte[] buff = BitConverter.GetBytes(comp);
     Buffer.BlockCopy(buff, 0, prop.raw, 24, sizeof(Int64));
     prop.Value.StringValue = pcc.Names[(int)comp];
     properties["CompressionSettings"] = prop;
     Compression = properties["CompressionSettings"].Value.StringValue;
 }
Ejemplo n.º 12
0
        /// <summary>
        /// This function will first guess and then do a thorough search to find the original location of the texture
        /// </summary>
        private string FindFile()
        {
            if (!String.IsNullOrEmpty(oriPackage))
                return oriPackage;

            // KFreon:  All files should have been added elsewhere rather than searched for here
            if (allFiles == null)
            {
                allFiles = new List<string>(ME1Directory.Files);

            }
            string package = FullPackage.Split('.')[0];
            for (int i = 0; i < allFiles.Count; i++)
            {
                string[] parts = allFiles[i].Split('\\');
                string tempFile = parts.Last().Split('.')[0];
                if (String.Compare(package, tempFile, true) == 0)
                    return allFiles[i];
            }
            /*if (!KFreonLib.Misc.Methods.DisplayYesNoDialogBox("Package guessing failed. Would you like to do the thorough check? (LONG)", "Continue?"))
                return null;*/
            for (int i = 0; i < allFiles.Count; i++)
            {
                ME1PCCObject temp = new ME1PCCObject(allFiles[i]);
                for (int j = 0; j < temp.ExportCount; j++)
                {
                    ME1ExportEntry exp = temp.Exports[j];
                    if (String.Compare(texName, exp.ObjectName, true) == 0 && exp.ClassName == "ME1Texture2D")
                    {
                        ME1Texture2D temptex = new ME1Texture2D(temp, j);
                        if (temptex.privateimgList[0].storageType == storage.pccCpr || temptex.privateimgList[0].storageType == storage.pccSto)
                        {
                            return allFiles[i];
                        }
                    }
                }
            }
            return null;
        }
Ejemplo n.º 13
0
        public byte[] ToArray(int pccExportDataOffset, ME1PCCObject pcc)
        {
            MemoryStream buffer = new MemoryStream();
            buffer.Write(headerData, 0, headerData.Length);

            if (properties.ContainsKey("LODGroup"))
            {
                properties["LODGroup"].Value.StringValue = "TEXTUREGROUP_LightAndShadowMap";
                //properties["LODGroup"].Value.IntValue = 1025;
            }
            else
            {
                buffer.WriteValueS64(pcc.AddName("LODGroup"));
                buffer.WriteValueS64(pcc.AddName("ByteProperty"));
                buffer.WriteValueS64(8);
                buffer.WriteValueS32(pcc.AddName("TEXTUREGROUP_LightAndShadowMap"));
                buffer.WriteValueS32(1025);
            }

            foreach (KeyValuePair<string, SaltPropertyReader.Property> kvp in properties)
            {
                SaltPropertyReader.Property prop = kvp.Value;

                if (prop.Name == "UnpackMin")
                {
                    for (int j = 0; j < UnpackNum; j++)
                    {
                        buffer.WriteValueS64(pcc.AddName(prop.Name));
                        buffer.WriteValueS64(pcc.AddName(prop.TypeVal.ToString()));
                        buffer.WriteValueS32(prop.Size);
                        buffer.WriteValueS32(j);
                        buffer.WriteValueF32(prop.Value.FloatValue, Endian.Little);
                    }
                    continue;
                }

                buffer.WriteValueS64(pcc.AddName(prop.Name));
                if (prop.Name == "None")
                {
                    for (int j = 0; j < 12; j++)
                        buffer.WriteByte(0);
                }
                else
                {
                    buffer.WriteValueS64(pcc.AddName(prop.TypeVal.ToString()));
                    buffer.WriteValueS64(prop.Size);

                    switch (prop.TypeVal)
                    {
                        case SaltPropertyReader.Type.IntProperty:
                            buffer.WriteValueS32(prop.Value.IntValue);
                            break;
                        case SaltPropertyReader.Type.BoolProperty:
                            buffer.Seek(-4, SeekOrigin.Current);
                            buffer.WriteValueS32(prop.Value.IntValue);
                            buffer.Seek(4, SeekOrigin.Current);
                            break;
                        case SaltPropertyReader.Type.NameProperty:
                            buffer.WriteValueS64(pcc.AddName(prop.Value.StringValue));
                            // Heff: Modified to handle name references.
                            //var index = pcc.AddName(prop.Value.StringValue);
                            //buffer.WriteValueS32(index);
                            //buffer.WriteValueS32(prop.Value.NameValue.count);
                            break;
                        case SaltPropertyReader.Type.StrProperty:
                            buffer.WriteValueS32(prop.Value.StringValue.Length + 1);
                            foreach (char c in prop.Value.StringValue)
                                buffer.WriteByte((byte)c);
                            buffer.WriteByte(0);
                            break;
                        case SaltPropertyReader.Type.StructProperty:
                            buffer.WriteValueS64(pcc.AddName(prop.Value.StringValue));
                            foreach (SaltPropertyReader.PropertyValue value in prop.Value.Array)
                                buffer.WriteValueS32(value.IntValue);
                            break;
                        case SaltPropertyReader.Type.ByteProperty:
                            buffer.WriteValueS32(pcc.AddName(prop.Value.StringValue));
                            buffer.WriteValueS32(prop.Value.IntValue);
                            break;
                        case SaltPropertyReader.Type.FloatProperty:
                            buffer.WriteValueF32(prop.Value.FloatValue, Endian.Little);
                            break;
                        default:
                            throw new FormatException("unknown property");
                    }
                }
            }

            buffer.WriteValueS32((int)(pccOffset + buffer.Position + 4));

            //Remove empty textures
            List<ImageInfo> tempList = new List<ImageInfo>();
            foreach (ImageInfo imgInfo in privateimgList)
            {
                if (imgInfo.storageType != storage.empty)
                    tempList.Add(imgInfo);
            }
            privateimgList = tempList;
            numMipMaps = (uint)privateimgList.Count;

            buffer.WriteValueU32(numMipMaps);

            foreach (ImageInfo imgInfo in privateimgList)
            {
                buffer.WriteValueS32((int)imgInfo.storageType);
                buffer.WriteValueS32(imgInfo.uncSize);
                buffer.WriteValueS32(imgInfo.cprSize);
                if (imgInfo.storageType == storage.pccSto)
                {
                    buffer.WriteValueS32((int)(imgInfo.offset + pccExportDataOffset + dataOffset));
                    buffer.Write(imageData, imgInfo.offset, imgInfo.uncSize);
                }
                else if (imgInfo.storageType == storage.pccCpr)
                {
                    buffer.WriteValueS32((int)(imgInfo.offset + pccExportDataOffset + dataOffset));
                    buffer.Write(imageData, imgInfo.offset, imgInfo.cprSize);
                }
                else
                    buffer.WriteValueS32(imgInfo.offset);
                if (imgInfo.imgSize.width < 4)
                    buffer.WriteValueU32(4);
                else
                    buffer.WriteValueU32(imgInfo.imgSize.width);
                if (imgInfo.imgSize.height < 4)
                    buffer.WriteValueU32(4);
                else
                    buffer.WriteValueU32(imgInfo.imgSize.height);
            }
            buffer.WriteBytes(footerData);
            return buffer.ToArray();
        }