예제 #1
0
        public ME3FaceFXAnimSet(IMEPackage Pcc, IExportEntry Entry)
        {
            pcc    = Pcc;
            export = Entry;
            int start = export.propsEnd() + 4;
            SerializingContainer Container = new SerializingContainer(new MemoryStream(export.Data.Skip(start).ToArray()));

            Container.isLoading = true;
            Serialize(Container);
        }
예제 #2
0
 private static void UpdateOffsets(IExportEntry export)
 {
     //update offsets for pcc-stored audio in wwisestreams
     if (export.ClassName == "WwiseStream" && export.GetProperty <NameProperty>("Filename") == null)
     {
         byte[] binData = export.getBinaryData();
         binData.OverwriteRange(12, BitConverter.GetBytes(export.DataOffset + export.propsEnd() + 16));
         export.setBinaryData(binData);
     }
     //update offsets for pcc-stored movies in texturemovies
     if (export.ClassName == "TextureMovie" && export.GetProperty <NameProperty>("TextureFileCacheName") == null)
     {
         byte[] binData = export.getBinaryData();
         binData.OverwriteRange(12, BitConverter.GetBytes(export.DataOffset + export.propsEnd() + 16));
         export.setBinaryData(binData);
     }
     //update offsets for pcc-stored mips in Textures
     else if (export.ClassName == "Texture2D" || export.ClassName == "LightMapTexture2D" || export.ClassName == "TextureFlipBook")
     {
         int          baseOffset = export.DataOffset + export.propsEnd();
         MemoryStream binData    = new MemoryStream(export.getBinaryData());
         for (int i = binData.ReadValueS32(); i > 0 && binData.Position < binData.Length; i--)
         {
             if (binData.ReadValueS32() == 0) //pcc-stored
             {
                 int uncompressedSize = binData.ReadValueS32();
                 binData.Seek(4, SeekOrigin.Current);                           //skip compressed size
                 binData.WriteValueS32(baseOffset + (int)binData.Position + 4); //update offset
                 binData.Seek(uncompressedSize + 8, SeekOrigin.Current);        //skip texture and width + height values
             }
             else
             {
                 binData.Seek(20, SeekOrigin.Current);//skip whole rest of mip definition
             }
         }
         export.setBinaryData(binData.ToArray());
     }
 }
예제 #3
0
        public void Save()
        {
            MemoryStream         m         = new MemoryStream();
            SerializingContainer Container = new SerializingContainer(m);

            Container.isLoading = false;
            Serialize(Container);
            m = Container.Memory;
            MemoryStream res   = new MemoryStream();
            int          start = export.propsEnd();

            res.Write(export.Data, 0, start);
            res.WriteValueS32((int)m.Length);
            res.WriteStream(m);
            res.WriteValueS32(0);
            export.Data = res.ToArray();
        }
        public static bool TryFindCodexMap(IMEPackage pcc, out IExportEntry export, out int dataOffset)
        {
            export     = null;
            dataOffset = -1;

            try
            {
                export = pcc.Exports.First(exp => exp.ClassName == "BioCodexMap");
            }
            catch
            {
                return(false);
            }

            dataOffset = export.propsEnd();

            return(true);
        }
예제 #5
0
 public void Deserialize()
 {
     BinaryOffset = export.propsEnd() + (export.FileRef.Game == MEGame.ME2 ? 0x18 : 0x10);
     ReadChunks();
 }
예제 #6
0
        public Bio2DA(IExportEntry export)
        {
            Console.WriteLine("Loading " + export.ObjectName);
            this.export = export;
            IMEPackage pcc = export.FileRef;

            byte[] data = export.Data;

            RowNames = new List <string>();
            if (export.ClassName == "Bio2DA")
            {
                string rowLabelsVar = "m_sRowLabel";
                var    properties   = export.GetProperties();
                var    props        = export.GetProperty <ArrayProperty <NameProperty> >(rowLabelsVar);
                if (props != null)
                {
                    foreach (NameProperty n in props)
                    {
                        RowNames.Add(n.ToString());
                    }
                }
                else
                {
                    Console.WriteLine("Unable to find row names property!");
                    Debugger.Break();
                    return;
                }
            }
            else
            {
                string rowLabelsVar = "m_lstRowNumbers"; //Bio2DANumberedRows
                var    props        = export.GetProperty <ArrayProperty <IntProperty> >(rowLabelsVar);
                if (props != null)
                {
                    foreach (IntProperty n in props)
                    {
                        RowNames.Add(n.Value.ToString());
                    }
                }
                else
                {
                    Console.WriteLine("Unable to find row names property!");
                    Debugger.Break();
                    return;
                }
            }

            //Get Columns
            ColumnNames = new List <string>();
            int colcount         = BitConverter.ToInt32(data, data.Length - 4);
            int currentcoloffset = 0;

            while (colcount >= 0)
            {
                currentcoloffset += 4;
                int colindex = BitConverter.ToInt32(data, data.Length - currentcoloffset);
                currentcoloffset += 8; //names in this case don't use nameindex values.
                int    nameindex = BitConverter.ToInt32(data, data.Length - currentcoloffset);
                string name      = pcc.getNameEntry(nameindex);
                ColumnNames.Insert(0, name);
                colcount--;
            }
            Cells = new Bio2DACell[RowNames.Count(), ColumnNames.Count()];

            currentcoloffset += 4;  //column count.
            int infilecolcount = BitConverter.ToInt32(data, data.Length - currentcoloffset);

            //start of binary data
            int binstartoffset = export.propsEnd(); //arrayheader + nonenamesize + number of items in this list
            int curroffset     = binstartoffset;

            int cellcount = BitConverter.ToInt32(data, curroffset);

            if (cellcount > 0)
            {
                curroffset += 4;
                for (int rowindex = 0; rowindex < RowNames.Count(); rowindex++)
                {
                    for (int colindex = 0; colindex < ColumnNames.Count() && curroffset < data.Length - currentcoloffset; colindex++)
                    {
                        byte dataType = 255;
                        dataType = data[curroffset];
                        curroffset++;
                        int    dataSize = dataType == Bio2DACell.TYPE_NAME ? 8 : 4;
                        byte[] celldata = new byte[dataSize];
                        Buffer.BlockCopy(data, curroffset, celldata, 0, dataSize);
                        Bio2DACell cell = new Bio2DACell(pcc, curroffset, dataType, celldata);
                        Cells[rowindex, colindex] = cell;
                        curroffset += dataSize;
                    }
                }
                CellCount = RowNames.Count() * ColumnNames.Count();
            }
            else
            {
                IsIndexed   = true;
                curroffset += 4; //theres a 0 here for some reason
                cellcount   = BitConverter.ToInt32(data, curroffset);
                curroffset += 4;

                //curroffset += 4;
                while (CellCount < cellcount)
                {
                    int index = BitConverter.ToInt32(data, curroffset);
                    int row   = index / ColumnNames.Count();
                    int col   = index % ColumnNames.Count();
                    curroffset += 4;
                    byte dataType = data[curroffset];
                    int  dataSize = dataType == Bio2DACell.TYPE_NAME ? 8 : 4;
                    curroffset++;
                    byte[] celldata = new byte[dataSize];
                    Buffer.BlockCopy(data, curroffset, celldata, 0, dataSize);
                    Bio2DACell cell = new Bio2DACell(pcc, curroffset, dataType, celldata);
                    Cells[row, col] = cell;
                    CellCount++;
                    curroffset += dataSize;
                }
            }
            Console.WriteLine("Finished loading " + export.ObjectName);
        }
예제 #7
0
        public void Write2DAToExport()
        {
            using (var stream = new MemoryStream())
            {
                //Cell count
                if (IsIndexed)
                {
                    //Indexed ones seem to have 0 at start
                    stream.WriteBytes(BitConverter.GetBytes(0));
                }
                stream.WriteBytes(BitConverter.GetBytes(CellCount));

                //Write cell data
                for (int rowindex = 0; rowindex < RowNames.Count(); rowindex++)
                {
                    for (int colindex = 0; colindex < ColumnNames.Count(); colindex++)
                    {
                        Bio2DACell cell = Cells[rowindex, colindex];
                        if (cell != null)
                        {
                            if (IsIndexed)
                            {
                                //write index
                                int index = (rowindex * ColumnNames.Count()) + colindex; //+1 because they are not zero based indexes since they are numerals
                                stream.WriteBytes(BitConverter.GetBytes(index));
                            }
                            stream.WriteByte(cell.Type);
                            stream.WriteBytes(cell.Data);
                        }
                        else
                        {
                            if (IsIndexed)
                            {
                                //this is a blank cell. It is not present in the table.
                                continue;
                            }
                            else
                            {
                                Console.WriteLine("THIS SHOULDN'T OCCUR!");
                            }
                        }
                    }
                }

                //Write Columns
                if (!IsIndexed)
                {
                    stream.WriteBytes(BitConverter.GetBytes(0)); //seems to be a 0 before column definitions
                }
                //Console.WriteLine("Columns defs start at " + stream.Position.ToString("X6"));
                stream.WriteBytes(BitConverter.GetBytes(ColumnNames.Count()));
                for (int colindex = 0; colindex < ColumnNames.Count(); colindex++)
                {
                    //Console.WriteLine("Writing column definition " + columnNames[colindex]);
                    int nameIndexForCol = export.FileRef.findName(ColumnNames[colindex]);
                    stream.WriteBytes(BitConverter.GetBytes(nameIndexForCol));
                    stream.WriteBytes(BitConverter.GetBytes(0)); //second half of name reference in 2da is always zero since they're always indexed at 0
                    stream.WriteBytes(BitConverter.GetBytes(colindex));
                }

                int    propsEnd      = export.propsEnd();
                byte[] binarydata    = stream.ToArray();
                byte[] propertydata  = export.Data.Take(propsEnd).ToArray();
                var    newExportData = new byte[propertydata.Length + binarydata.Length];
                propertydata.CopyTo(newExportData, 0);
                binarydata.CopyTo(newExportData, propertydata.Length);
                //Console.WriteLine("Old data size: " + export.Data.Length);
                //Console.WriteLine("NEw data size: " + newExportData.Length);
                if (export.Data.Length != newExportData.Length)
                {
                    Console.WriteLine("FILES ARE WRONG SIZE");
                    Debugger.Break();
                }
                export.Data = newExportData;
            }
        }
예제 #8
0
        public void Write2DAToExport()
        {
            using (var stream = new MemoryStream())
            {
                //Cell count
                if (IsIndexed)
                {
                    //Indexed ones seem to have 0 at start
                    stream.WriteBytes(BitConverter.GetBytes(0));
                }
                stream.WriteBytes(BitConverter.GetBytes(PopulatedCellCount));

                //Write cell data
                for (int rowindex = 0; rowindex < RowCount; rowindex++)
                {
                    for (int colindex = 0; colindex < ColumnCount; colindex++)
                    {
                        Bio2DACell cell = Cells[rowindex, colindex];
                        if (cell != null)
                        {
                            if (IsIndexed)
                            {
                                //write index
                                int index = (rowindex * ColumnCount) + colindex; //+1 because they are not zero based indexes since they are numerals
                                stream.WriteBytes(BitConverter.GetBytes(index));
                            }
                            stream.WriteByte((byte)cell.Type);
                            stream.WriteBytes(cell.Data);
                        }
                        else
                        {
                            if (IsIndexed)
                            {
                                //this is a blank cell. It is not present in the table.
                                continue;
                            }
                            else
                            {
                                Debug.WriteLine("THIS SHOULDN'T OCCUR!");
                                Debugger.Break();
                                throw new Exception("A non-indexed Bio2DA cannot have null cells.");
                            }
                        }
                    }
                }

                //Write Columns
                if (!IsIndexed)
                {
                    stream.WriteBytes(BitConverter.GetBytes(0)); //seems to be a 0 before column definitions
                }
                //Console.WriteLine("Columns defs start at " + stream.Position.ToString("X6"));
                stream.WriteBytes(BitConverter.GetBytes(ColumnCount));
                for (int colindex = 0; colindex < ColumnCount; colindex++)
                {
                    //Console.WriteLine("Writing column definition " + columnNames[colindex]);
                    int nameIndexForCol = export.FileRef.FindNameOrAdd(ColumnNames[colindex]);
                    stream.WriteBytes(BitConverter.GetBytes(nameIndexForCol));
                    stream.WriteBytes(BitConverter.GetBytes(0)); //second half of name reference in 2da is always zero since they're always indexed at 0
                    stream.WriteBytes(BitConverter.GetBytes(colindex));
                }

                int    propsEnd   = export.propsEnd();
                byte[] binarydata = stream.ToArray();

                //Todo: Rewrite properties here
                PropertyCollection props = new PropertyCollection();
                if (export.ClassName == "Bio2DA")
                {
                    var indicies = new ArrayProperty <NameProperty>(ArrayType.Name, "m_sRowLabel");
                    foreach (var rowname in RowNames)
                    {
                        indicies.Add(new NameProperty {
                            Value = rowname
                        });
                    }
                    props.Add(indicies);
                }
                else
                {
                    var indices = new ArrayProperty <IntProperty>(ArrayType.Int, "m_lstRowNumbers");
                    foreach (var rowname in RowNames)
                    {
                        indices.Add(new IntProperty(int.Parse(rowname)));
                    }
                    props.Add(indices);
                }

                MemoryStream propsStream = new MemoryStream();
                props.WriteTo(propsStream, export.FileRef);
                MemoryStream currentDataStream   = new MemoryStream(export.Data);
                byte[]       propertydata        = propsStream.ToArray();
                int          propertyStartOffset = export.GetPropertyStart();
                var          newExportData       = new byte[propertyStartOffset + propertydata.Length + binarydata.Length];
                Buffer.BlockCopy(export.Data, 0, newExportData, 0, propertyStartOffset);
                propertydata.CopyTo(newExportData, propertyStartOffset);
                binarydata.CopyTo(newExportData, propertyStartOffset + propertydata.Length);
                //Console.WriteLine("Old data size: " + export.Data.Length);
                //Console.WriteLine("NEw data size: " + newExportData.Length);

                //This assumes the input and output data sizes are the same. We should not assume this with new functionality
                //if (export.Data.Length != newExportData.Length)
                //{
                //    Debug.WriteLine("FILES ARE WRONG SIZE");
                //    Debugger.Break();
                //}
                export.Data = newExportData;
            }
        }