예제 #1
0
        /// <summary>
        /// Creates a new StringTable instance.
        /// </summary>
        /// <param name="Chunk">The chunk data for this StringTable.</param>
        public StringTable(IffChunk Chunk) : base(Chunk)
        {
            MemoryStream MemStream = new MemoryStream(Chunk.Data);
            BinaryReader Reader    = new BinaryReader(MemStream);

            //Another example of the grossness of this format; random use of big-endian numbers...
            byte[] FormatCodeBuf = Reader.ReadBytes(2);
            Array.Reverse(FormatCodeBuf);

            m_FormatCode = BitConverter.ToUInt16(FormatCodeBuf, 0);

            switch (m_FormatCode)
            {
            case 0:
                //Some tables are empty... LITERALLY!
                if (Reader.BaseStream.Position < Reader.BaseStream.Length)
                {
                    m_NumEntries = Reader.ReadUInt16();

                    for (int i = 0; i < m_NumEntries; i++)
                    {
                        StringTableString Str = new StringTableString();

                        Str.Str = ReadPascalString(Reader);

                        m_Strings.Add(Str);
                    }
                }

                break;

            case 0xFFFF:
                m_NumEntries = Reader.ReadUInt16();

                for (int i = 0; i < m_NumEntries; i++)
                {
                    StringTableString Str = new StringTableString();

                    char          C;
                    StringBuilder SB = new StringBuilder();

                    while (true)
                    {
                        C = Reader.ReadChar();
                        SB.Append(C);

                        if (C == '\0')
                        {
                            break;
                        }
                    }

                    Str.Str = SB.ToString();
                    m_Strings.Add(Str);
                }

                break;

            case 0xFEFF:
                m_NumEntries = Reader.ReadUInt16();

                for (int i = 0; i < m_NumEntries; i++)
                {
                    StringTableString Str = new StringTableString();

                    char          C;
                    StringBuilder SB = new StringBuilder();

                    //String
                    while (true)
                    {
                        C = Reader.ReadChar();
                        SB.Append(C);

                        if (C == '\0')
                        {
                            break;
                        }
                    }

                    Str.Str = SB.ToString();
                    m_Strings.Add(Str);
                    SB = new StringBuilder();

                    //Comment
                    while (true)
                    {
                        C = Reader.ReadChar();
                        SB.Append(C);

                        if (C == '\0')
                        {
                            break;
                        }
                    }
                }

                break;

            case 0xFDFF:
                m_NumEntries = Reader.ReadUInt16();

                for (int i = 0; i < m_NumEntries; i++)
                {
                    StringTableString Str = new StringTableString();
                    Str.LanguageCode = Reader.ReadByte();

                    char          C;
                    StringBuilder SB = new StringBuilder();

                    while (true)
                    {
                        C = (char)Reader.ReadByte();

                        if (C == '\0')
                        {
                            break;
                        }

                        SB.Append(C);
                    }

                    Str.Str = SB.ToString();

                    C  = new char();
                    SB = new StringBuilder();

                    while (true)
                    {
                        C = (char)Reader.ReadByte();

                        if (C == '\0')
                        {
                            break;
                        }

                        SB.Append(C);
                    }

                    Str.Str2 = SB.ToString();


                    m_Strings.Add(Str);
                }

                break;

            case 0xFCFF:     //Only found in TSO-files!
                m_NumSets = Reader.ReadByte();

                if (m_NumSets >= 1)
                {
                    for (int i = 0; i < m_NumSets; i++)
                    {
                        StringSet Set = new StringSet();

                        Set.NumEntries = Reader.ReadInt16();

                        for (int j = 0; j < Set.NumEntries; j++)
                        {
                            // string code, then two specially-counted strings
                            // for some reason, the language code is one below the
                            // documented values.  we adjust this here, which
                            // unfortunately makes non-translated strings strange.
                            StringTableString Str = new StringTableString();
                            Str.LanguageCode = (byte)(Reader.ReadByte() + 1);

                            Str.Str  = ReadPascalString1(Reader);
                            Str.Str2 = ReadPascalString1(Reader);

                            Set.Strings.Add(Str);
                        }

                        m_StringSets.Add(Set);
                    }
                }

                break;
            }

            Reader.Close();
        }
예제 #2
0
        /// <summary>
        /// Creates a new StringTable instance.
        /// </summary>
        /// <param name="Chunk">The chunk data for this StringTable.</param>
        public StringTable(IffChunk Chunk)
            : base(Chunk)
        {
            MemoryStream MemStream = new MemoryStream(Chunk.Data);
            BinaryReader Reader = new BinaryReader(MemStream);

            //Another example of the grossness of this format; random use of big-endian numbers...
            byte[] FormatCodeBuf = Reader.ReadBytes(2);
            Array.Reverse(FormatCodeBuf);

            m_FormatCode = BitConverter.ToUInt16(FormatCodeBuf, 0);

            switch (m_FormatCode)
            {
                case 0:
                    //Some tables are empty... LITERALLY!
                    if (Reader.BaseStream.Position < Reader.BaseStream.Length)
                    {
                        m_NumEntries = Reader.ReadUInt16();

                        for (int i = 0; i < m_NumEntries; i++)
                        {
                            StringTableString Str = new StringTableString();

                            Str.Str = ReadPascalString(Reader);

                            m_Strings.Add(Str);
                        }
                    }

                    break;
                case 0xFFFF:
                    m_NumEntries = Reader.ReadUInt16();

                    for (int i = 0; i < m_NumEntries; i++)
                    {
                        StringTableString Str = new StringTableString();

                        char C;
                        StringBuilder SB = new StringBuilder();

                        while (true)
                        {
                            C = Reader.ReadChar();
                            SB.Append(C);

                            if (C == '\0')
                                break;
                        }

                        Str.Str = SB.ToString();
                        m_Strings.Add(Str);
                    }

                    break;
                case 0xFEFF:
                    m_NumEntries = Reader.ReadUInt16();

                    for (int i = 0; i < m_NumEntries; i++)
                    {
                        StringTableString Str = new StringTableString();

                        char C;
                        StringBuilder SB = new StringBuilder();

                        //String
                        while (true)
                        {
                            C = Reader.ReadChar();
                            SB.Append(C);

                            if (C == '\0')
                                break;
                        }

                        Str.Str = SB.ToString();
                        m_Strings.Add(Str);
                        SB = new StringBuilder();

                        //Comment
                        while (true)
                        {
                            C = Reader.ReadChar();
                            SB.Append(C);

                            if (C == '\0')
                                break;
                        }
                    }

                    break;
                case 0xFDFF:
                    m_NumEntries = Reader.ReadUInt16();

                    for (int i = 0; i < m_NumEntries; i++)
                    {
                        StringTableString Str = new StringTableString();
                        Str.LanguageCode = Reader.ReadByte();

                        char C;
                        StringBuilder SB = new StringBuilder();

                        while (true)
                        {
                            C = (char)Reader.ReadByte();

                            if (C == '\0')
                                break;

                            SB.Append(C);
                        }

                        Str.Str = SB.ToString();

                        C = new char();
                        SB = new StringBuilder();

                        while (true)
                        {
                            C = (char)Reader.ReadByte();

                            if (C == '\0')
                                break;

                            SB.Append(C);
                        }

                        Str.Str2 = SB.ToString();

                        m_Strings.Add(Str);
                    }

                    break;

                case 0xFCFF: //Only found in TSO-files!
                    m_NumSets = Reader.ReadByte();

                    if (m_NumSets >= 1)
                    {
                        for (int i = 0; i < m_NumSets; i++)
                        {
                            StringSet Set = new StringSet();

                            Set.NumEntries = Reader.ReadInt16();

                            for (int j = 0; j < Set.NumEntries; j++)
                            {
                                // string code, then two specially-counted strings
                                // for some reason, the language code is one below the
                                // documented values.  we adjust this here, which
                                // unfortunately makes non-translated strings strange.
                                StringTableString Str = new StringTableString();
                                Str.LanguageCode = (byte)(Reader.ReadByte() + 1);

                                Str.Str = ReadPascalString1(Reader);
                                Str.Str2 = ReadPascalString1(Reader);

                                Set.Strings.Add(Str);
                            }

                            m_StringSets.Add(Set);
                        }
                    }

                    break;
            }

            Reader.Close();
        }