Beispiel #1
0
            private byte[] DecompressBytes(ARZFile arzFile)
            {
                // Read in the compressed data and decompress it, storing the results in a memorystream
                FileStream arzStream = new FileStream(arzFile.m_filename, FileMode.Open, FileAccess.Read, FileShare.Read);

                try
                {
                    arzStream.Seek(m_offset, SeekOrigin.Begin);

                    // Create a decompression stream
                    ZInputStream zinput = new ZInputStream(arzStream);
                    // Create a memorystream to hold the decompressed data
                    MemoryStream outStream = new MemoryStream();
                    try
                    {
                        // Now decompress
                        byte[] buffer = new byte[1024];
                        int    len;
                        while ((len = zinput.read(buffer, 0, 1024)) > 0)
                        {
                            outStream.Write(buffer, 0, len);
                        }

                        // Now create a final Byte array to hold the answer
                        byte[] ans = new byte[(int)zinput.TotalOut];

                        // Copy the data into it
                        Array.Copy(outStream.GetBuffer(), ans, (int)zinput.TotalOut);

                        // Return the decompressed data
                        return(ans);
                    }
                    finally
                    {
                        outStream.Close();
                    }
                }
                finally
                {
                    arzStream.Close();
                }
            }
Beispiel #2
0
            public void Decode(BinaryReader inReader, int baseOffset, ARZFile arzFile)
            {
                // Record Entry Format
                // 0x0000 int32 stringEntryID (dbr filename)
                // 0x0004 int32 string length
                // 0x0008 string (record type)
                // 0x00?? int32 offset
                // 0x00?? int32 length in bytes
                // 0x00?? int32 timestamp?
                // 0x00?? int32 timestamp?
                m_idstringIndex = inReader.ReadInt32();
                m_recordType    = ReadCString(inReader);

                m_offset         = inReader.ReadInt32() + baseOffset;
                m_compressedSize = inReader.ReadInt32();
                m_crap1          = inReader.ReadInt32();
                m_crap2          = inReader.ReadInt32();

                // Get the ID string
                m_id = arzFile.Getstring(m_idstringIndex);
            }
Beispiel #3
0
            public DBRecord Decompress(ARZFile arzFile)
            {
                // record variables have this format:
                // 0x00 int16 specifies data type:
                //		0x0000 = int - data will be an int32
                //      0x0001 = float - data will be a Single
                //		0x0002 = string - data will be an int32 that is index into string table
                //      0x0003 = bool - data will be an int32
                // 0x02 int16 specifies number of values (usually 1, but sometimes more (for arrays)
                // 0x04 int32 key string ID (the id into the string table for this variable name
                // 0x08 data value
                byte[] data = DecompressBytes(arzFile);
                // Lets dump the file to disk
                //System.IO.FileStream dump = new System.IO.FileStream("recdump.dat", System.IO.FileMode.Create, System.IO.FileAccess.Write);
                //try
                //{
                //	dump.Write(data, 0, data.Length);
                //}
                //finally
                //{
                //	dump.Close();
                //}

                int numDWords    = data.Length / 4;
                int numVariables = numDWords / 3;

                if (data.Length % 4 != 0)
                {
                    throw new ApplicationException(string.Format("Error while parsing arz record {0}, data Length = {1} which is not a multiple of 4", ID, (int)data.Length));
                }

                DBRecord record = new DBRecord(ID, RecordType);

                // Create a memory stream to read the binary data
                MemoryStream inStream = new MemoryStream(data, false);
                BinaryReader inReader = new BinaryReader(inStream);

                try
                {
                    int i = 0;
                    while (i < numDWords)
                    {
                        int    pos          = (int)inReader.BaseStream.Position;
                        short  dataType     = inReader.ReadInt16();
                        short  valCount     = inReader.ReadInt16();
                        int    variableID   = inReader.ReadInt32();
                        string variableName = arzFile.Getstring(variableID);

                        if (variableName == null)
                        {
                            throw new ApplicationException(string.Format("Error while parsing arz record {0}, variable is NULL", ID));
                        }

                        if (dataType < 0 || dataType > 3)
                        {
                            throw new ApplicationException(string.Format("Error while parsing arz record {0}, variable {2}, bad dataType {3}", ID, variableName, dataType));
                        }
                        Variable v = new Variable(variableName, (VariableDataType)dataType, valCount);

                        if (valCount < 1)
                        {
                            throw new ApplicationException(string.Format("Error while parsing arz record {0}, variable {1}, bad valCount {2}", ID, variableName, valCount));
                        }

                        i += 2 + valCount;                 // increment our dword count

                        for (int j = 0; j < valCount; ++j)
                        {
                            switch (v.DataType)
                            {
                            case VariableDataType.Integer:
                            case VariableDataType.Boolean:
                            {
                                int val = inReader.ReadInt32();
                                v[j] = val;
                                break;
                            }

                            case VariableDataType.Float:
                            {
                                float val = inReader.ReadSingle();
                                v[j] = val;
                                break;
                            }

                            case VariableDataType.StringVar:
                            {
                                int    id  = inReader.ReadInt32();
                                string val = arzFile.Getstring(id);
                                if (val == null)
                                {
                                    val = "";
                                }
                                else
                                {
                                    val = val.Trim();
                                }
                                v[j] = val;
                                break;
                            }

                            default:
                            {
                                int val = inReader.ReadInt32();
                                v[j] = val;
                                break;
                            }
                            }
                        }
                        record.Set(v);
                    }
                }
                finally {
                    inReader.Close();
                }
                return(record);
            }