Example #1
0
        public CR2WFile()
        {
            Names      = new List <CR2WNameWrapper>();      //block 2
            Imports    = new List <CR2WImportWrapper>();    //block 3
            Properties = new List <CR2WPropertyWrapper>();  //block 4
            Chunks     = new List <CR2WExportWrapper>();    //block 5
            Buffers    = new List <CR2WBufferWrapper>();    //block 6
            Embedded   = new List <CR2WEmbeddedWrapper>();  //block 7

            m_fileheader = new CR2WFileHeader()
            {
                version = 162,
            };


            Logger = ServiceLocator.Default.ResolveType <ILoggerService>();

            StringDictionary = new Dictionary <uint, string>();
            m_tableheaders   = new CR2WTable[10];
        }
Example #2
0
        private void ProcessFile()
        {
            var id = ReadStruct <uint>();

            if (id != MAGIC)
            {
                throw new FormatException($"Not a CR2W file, Magic read as 0x{id:X8}");
            }

            m_fileheader = ReadStruct <CR2WFileHeader>();
            if (m_fileheader.version > 163 || m_fileheader.version < 159)
            {
                throw new FormatException($"Unknown Version {m_fileheader.version}. Supported versions: 159 - 163.");
            }

            var dt = new CDateTime(m_fileheader.timeStamp, null, "");

            m_hasInternalBuffer = m_fileheader.bufferSize > m_fileheader.fileSize;
            m_tableheaders      = ReadStructs <CR2WTable>(10);

            m_strings  = ReadStringsBuffer();
            m_names    = ReadTable <CR2WName>(1);
            m_imports  = ReadTable <CR2WImport>(2);
            m_table4   = ReadTable <CR2WProperty>(3);
            m_exports  = ReadTable <CR2WExport>(4);
            m_buffers  = ReadTable <CR2WBuffer>(5);
            m_embedded = ReadTable <CR2WEmbedded>(6);

            // Fixing
            for (int i = 0; i < m_names.Length; i++)
            {
                FixNameFNV1A(ref m_names[i]);
            }

            for (int i = 0; i < m_exports.Length; i++)
            {
                FixExportCRC32(ref m_exports[i]);
            }

            for (int i = 0; i < m_buffers.Length; i++)
            {
                FixBufferCRC32(ref m_buffers[i]);
            }

            // Write File
            m_stream.Seek(160, SeekOrigin.Begin);

            WriteStringBuffer();
            WriteTable <CR2WName>(m_names, 1);
            WriteTable <CR2WImport>(m_imports, 2);
            WriteTable <CR2WProperty>(m_table4, 3);
            WriteTable <CR2WExport>(m_exports, 4);
            WriteTable <CR2WBuffer>(m_buffers, 5);
            WriteTable <CR2WEmbedded>(m_embedded, 6);

            // Write Header again
            m_stream.Seek(0, SeekOrigin.Begin);

            m_fileheader.timeStamp = CDateTime.Now.ToUInt64();
            m_fileheader.crc32     = CalculateHeaderCRC32();

            WriteStruct <uint>(MAGIC);
            WriteStruct <CR2WFileHeader>(m_fileheader);
            WriteStructs <CR2WTable>(m_tableheaders);
        }