Example #1
0
        public CTSS(IFFChunk BaseChunk) : base(BaseChunk)
        {
            FileReader Reader = new FileReader(new MemoryStream(m_Data), false);

            Version = Reader.ReadInt16();
            ushort NumStrings = 0;

            if ((Reader.StreamLength - Reader.Position) > 2)
            {
                switch (Version)
                {
                case 0:
                    NumStrings = Reader.ReadUShort();

                    for (int i = 0; i < NumStrings; i++)
                    {
                        TranslatedString Str = new TranslatedString();
                        Str.LangCode      = LanguageCodes.unused;
                        Str.TranslatedStr = Reader.ReadPascalString();

                        if (Strings.ContainsKey(Str.LangCode))
                        {
                            Strings[Str.LangCode].Add(Str);
                        }
                        else
                        {
                            List <TranslatedString> LanguageSet = new List <TranslatedString>();
                            LanguageSet.Add(Str);
                            Strings.Add(Str.LangCode, LanguageSet);
                        }
                    }

                    break;

                case -1:
                    NumStrings = Reader.ReadUShort();

                    for (int i = 0; i < NumStrings; i++)
                    {
                        TranslatedString Str = new TranslatedString();
                        Str.LangCode      = LanguageCodes.unused;
                        Str.TranslatedStr = Reader.ReadCString();

                        if (Strings.ContainsKey(Str.LangCode))
                        {
                            Strings[Str.LangCode].Add(Str);
                        }
                        else
                        {
                            List <TranslatedString> LanguageSet = new List <TranslatedString>();
                            LanguageSet.Add(Str);
                            Strings.Add(Str.LangCode, LanguageSet);
                        }
                    }

                    break;

                case -2:
                    NumStrings = Reader.ReadUShort();

                    for (int i = 0; i < NumStrings; i++)
                    {
                        TranslatedString Str = new TranslatedString();
                        Str.LangCode      = LanguageCodes.unused;
                        Str.TranslatedStr = Reader.ReadCString();
                        Reader.ReadCString();     //Comment

                        if (Strings.ContainsKey(Str.LangCode))
                        {
                            Strings[Str.LangCode].Add(Str);
                        }
                        else
                        {
                            List <TranslatedString> LanguageSet = new List <TranslatedString>();
                            LanguageSet.Add(Str);
                            Strings.Add(Str.LangCode, LanguageSet);
                        }
                    }

                    break;

                case -3:
                    NumStrings = Reader.ReadUShort();

                    for (int i = 0; i < NumStrings; i++)
                    {
                        TranslatedString Str = new TranslatedString();
                        Str.LangCode      = (LanguageCodes)Reader.ReadByte();
                        Str.TranslatedStr = Reader.ReadCString();
                        Reader.ReadCString();     //Comment

                        if (Strings.ContainsKey(Str.LangCode))
                        {
                            Strings[Str.LangCode].Add(Str);
                        }
                        else
                        {
                            List <TranslatedString> LanguageSet = new List <TranslatedString>();
                            LanguageSet.Add(Str);
                            Strings.Add(Str.LangCode, LanguageSet);
                        }
                    }

                    break;

                case -4:
                    byte LanguageSets = Reader.ReadByte();
                    for (int i = 0; i < LanguageSets; i++)
                    {
                        NumStrings = Reader.ReadUShort();

                        for (int j = 0; j < NumStrings; j++)
                        {
                            TranslatedString Str = new TranslatedString();
                            Str.LangCode      = (LanguageCodes)(Reader.ReadByte() + 1);
                            Str.TranslatedStr = Reader.ReadString();
                            Reader.ReadString();     //Comment

                            if (Strings.ContainsKey(Str.LangCode))
                            {
                                Strings[Str.LangCode].Add(Str);
                            }
                            else
                            {
                                List <TranslatedString> LanguageSet = new List <TranslatedString>();
                                LanguageSet.Add(Str);
                                Strings.Add(Str.LangCode, LanguageSet);
                            }
                        }
                    }

                    break;
                }
            }

            Reader.Close();
            m_Data = null;
        }
Example #2
0
        public CST(IFFChunk BaseChunk)
            : base(BaseChunk)
        {
            FileReader Reader = new FileReader(new MemoryStream(m_Data), false);

            Version = Reader.ReadInt16();
            ushort NumStrings = 0;

            if ((Reader.StreamLength - Reader.Position) > 2)
            {
                switch (Version)
                {
                    case 0:
                        NumStrings = Reader.ReadUShort();

                        for (int i = 0; i < NumStrings; i++)
                        {
                            TranslatedString Str = new TranslatedString();
                            Str.LangCode = LanguageCodes.unused;
                            Str.TranslatedStr = Reader.ReadPascalString();

                            if (Strings.ContainsKey(Str.LangCode))
                                Strings[Str.LangCode].Add(Str);
                            else
                            {
                                List<TranslatedString> LanguageSet = new List<TranslatedString>();
                                LanguageSet.Add(Str);
                                Strings.Add(Str.LangCode, LanguageSet);
                            }
                        }

                        break;
                    case -1:
                        NumStrings = Reader.ReadUShort();

                        for (int i = 0; i < NumStrings; i++)
                        {
                            TranslatedString Str = new TranslatedString();
                            Str.LangCode = LanguageCodes.unused;
                            Str.TranslatedStr = Reader.ReadCString();

                            if (Strings.ContainsKey(Str.LangCode))
                                Strings[Str.LangCode].Add(Str);
                            else
                            {
                                List<TranslatedString> LanguageSet = new List<TranslatedString>();
                                LanguageSet.Add(Str);
                                Strings.Add(Str.LangCode, LanguageSet);
                            }
                        }

                        break;
                    case -2:
                        NumStrings = Reader.ReadUShort();

                        for (int i = 0; i < NumStrings; i++)
                        {
                            TranslatedString Str = new TranslatedString();
                            Str.LangCode = LanguageCodes.unused;
                            Str.TranslatedStr = Reader.ReadCString();
                            Reader.ReadCString(); //Comment

                            if (Strings.ContainsKey(Str.LangCode))
                                Strings[Str.LangCode].Add(Str);
                            else
                            {
                                List<TranslatedString> LanguageSet = new List<TranslatedString>();
                                LanguageSet.Add(Str);
                                Strings.Add(Str.LangCode, LanguageSet);
                            }
                        }

                        break;
                    case -3:
                        NumStrings = Reader.ReadUShort();

                        for (int i = 0; i < NumStrings; i++)
                        {
                            TranslatedString Str = new TranslatedString();
                            Str.LangCode = (LanguageCodes)Reader.ReadByte();
                            Str.TranslatedStr = Reader.ReadCString();
                            Reader.ReadCString(); //Comment

                            if (Strings.ContainsKey(Str.LangCode))
                                Strings[Str.LangCode].Add(Str);
                            else
                            {
                                List<TranslatedString> LanguageSet = new List<TranslatedString>();
                                LanguageSet.Add(Str);
                                Strings.Add(Str.LangCode, LanguageSet);
                            }
                        }

                        break;
                    case -4:
                        byte LanguageSets = Reader.ReadByte();
                        for (int i = 0; i < LanguageSets; i++)
                        {
                            NumStrings = Reader.ReadUShort();

                            for (int j = 0; j < NumStrings; j++)
                            {
                                TranslatedString Str = new TranslatedString();
                                Str.LangCode = (LanguageCodes)(Reader.ReadByte() + 1);
                                Str.TranslatedStr = Reader.ReadString();
                                Reader.ReadString(); //Comment

                                if (Strings.ContainsKey(Str.LangCode))
                                    Strings[Str.LangCode].Add(Str);
                                else
                                {
                                    List<TranslatedString> LanguageSet = new List<TranslatedString>();
                                    LanguageSet.Add(Str);
                                    Strings.Add(Str.LangCode, LanguageSet);
                                }
                            }
                        }

                        break;
                }
            }

            Reader.Close();
            m_Data = null;
        }
Example #3
0
 /// <summary>
 /// Adds a string to this STR chunk.
 /// If it exists, it will be replaced
 /// </summary>
 /// <param name="Str">The TranslatedString instance to add.</param>
 /// <param name="Index">The index of the string to add. Typically 0 through 2 for objects
 /// where 0 is the name, 1 is the price and 2 is the description.</param>
 public void AddString(TranslatedString Str, ObjectStringIndices Index)
 {
     Strings[Str.LangCode][(int)Index] = Str;
 }