private void ReadExports(MemoryStream fs)
        {
            DebugOutput.PrintLn("Reading Exports...");
            fs.Seek(ExportOffset, SeekOrigin.Begin);
            exports = new List <ME1ExportEntry>();
            byte[] buffer;

            for (int i = 0; i < ExportCount; i++)
            {
                long start = fs.Position;

                fs.Seek(40, SeekOrigin.Current);
                int count = fs.ReadValueS32();
                fs.Seek(4 + count * 12, SeekOrigin.Current);
                count = fs.ReadValueS32();
                fs.Seek(4 + count * 4, SeekOrigin.Current);
                fs.Seek(16, SeekOrigin.Current);
                long end = fs.Position;
                fs.Seek(start, SeekOrigin.Begin);

                ME1ExportEntry exp = new ME1ExportEntry(this, fs.ReadBytes((int)(end - start)), (uint)start);
                buffer = new byte[exp.DataSize];
                fs.Seek(exp.DataOffset, SeekOrigin.Begin);
                fs.Read(buffer, 0, buffer.Length);
                exp.Data             = buffer;
                exp.DataChanged      = false;
                exp.Index            = i;
                exp.PropertyChanged += exportChanged;
                exports.Add(exp);
                fs.Seek(end, SeekOrigin.Begin);
            }
        }
Beispiel #2
0
 private void ReadExports(MemoryStream fs)
 {
     exports = new List <IExportEntry>();
     fs.Seek(ExportOffset, SeekOrigin.Begin);
     for (int i = 0; i < ExportCount; i++)
     {
         ME1ExportEntry exp = new ME1ExportEntry(this, fs);
         exp.Index            = i;
         exp.PropertyChanged += exportChanged;
         exports.Add(exp);
     }
 }
        public void addExport(ME1ExportEntry exportEntry)
        {
            if (exportEntry.FileRef != this)
            {
                throw new Exception("you cannot add a new export entry from another file, it has invalid references!");
            }

            exportEntry.DataChanged      = true;
            exportEntry.Index            = exports.Count;
            exportEntry.PropertyChanged += exportChanged;
            exports.Add(exportEntry);
            ExportCount = exports.Count;

            updateTools(PackageChange.ExportAdd, ExportCount);
        }
        public IExportEntry Clone()
        {
            ME1ExportEntry newExport = new ME1ExportEntry(FileRef as ME1Package);

            newExport.header       = this.header.TypedClone();
            newExport.headerOffset = 0;
            newExport.Data         = this.Data;
            int    index = 0;
            string name  = ObjectName;

            foreach (IExportEntry ent in FileRef.Exports)
            {
                if (name == ent.ObjectName && ent.indexValue > index)
                {
                    index = ent.indexValue;
                }
            }
            index++;
            newExport.indexValue = index;
            return(newExport);
        }
        /// <summary>
        ///     save PCCObject to file by reconstruction from data
        /// </summary>
        /// <param name="path">full path + file name.</param>
        public void saveByReconstructing(string path)
        {
            try
            {
                this.IsCompressed = false;
                MemoryStream m = new MemoryStream();
                m.WriteBytes(header);

                // Set numblocks to zero
                m.WriteValueS32(0);
                //Write the magic number (What is this?)
                m.WriteBytes(new byte[] { 0xF2, 0x56, 0x1B, 0x4E });
                // Write 4 bytes of 0
                m.WriteValueS32(0);

                //name table
                NameOffset = (int)m.Position;
                NameCount  = names.Count;
                foreach (string name in names)
                {
                    m.WriteValueS32(name.Length + 1);
                    m.WriteString(name);
                    m.WriteByte(0);
                    m.WriteValueS32(0);
                    m.WriteValueS32(458768);
                }
                //import table
                ImportOffset = (int)m.Position;
                ImportCount  = imports.Count;
                foreach (ImportEntry e in imports)
                {
                    m.WriteBytes(e.header);
                }
                //export table
                ExportOffset = (int)m.Position;
                ExportCount  = exports.Count;
                for (int i = 0; i < exports.Count; i++)
                {
                    ME1ExportEntry e = exports[i];
                    e.headerOffset = (uint)m.Position;
                    m.WriteBytes(e.header);
                }
                //freezone
                int FreeZoneSize = expDataBegOffset - FreeZoneStart;
                FreeZoneStart = (int)m.Position;
                m.Write(new byte[FreeZoneSize], 0, FreeZoneSize);
                expDataBegOffset = (int)m.Position;
                //export data
                for (int i = 0; i < exports.Count; i++)
                {
                    ME1ExportEntry e = exports[i];
                    e.DataOffset = (int)m.Position;
                    e.DataSize   = e.Data.Length;
                    m.WriteBytes(e.Data);
                    long pos = m.Position;
                    m.Seek(e.headerOffset + 32, SeekOrigin.Begin);
                    m.WriteValueS32(e.DataSize);
                    m.WriteValueS32(e.DataOffset);
                    m.Seek(pos, SeekOrigin.Begin);
                }
                //update header
                m.Seek(0, SeekOrigin.Begin);
                m.WriteBytes(header);

                File.WriteAllBytes(path, m.ToArray());
                AfterSave();
            }
            catch (Exception ex)
            {
                MessageBox.Show("PCC Save error:\n" + ex.Message);
            }
        }