Пример #1
0
            public bool ReadFile(BinaryReader r)
            {
                String Identifier = CSF.ReadCString(r, 4);

                if (!Identifier.Equals(" FSC"))
                {
                    return(false);
                }

                Version = r.ReadInt32();

                if (Version != 3)
                {
                    return(false);
                }

                NumValues = r.ReadInt32();

                NumExtraValues = r.ReadInt32();

                Unused = r.ReadInt32();

                Language = r.ReadInt32();

                return(true);
            }
Пример #2
0
            public bool ReadFile(ArraySegment <byte> data, ref int size)
            {
                var offs = data.Offset;

                String Identifier = CSF.ReadCString(data, 4, offs);

                offs += 4;

                if (!Identifier.Equals(" LBL"))
                {
                    return(false);
                }

                StringCount = BitConverter.ToInt32(data.Array, offs);
                offs       += 4;

                uint LabelLength = BitConverter.ToUInt32(data.Array, offs);

                offs += 4;

                if (offs + LabelLength > data.Array.Length)
                {
                    return(false);
                }

                ID    = CSF.ReadCString(data, LabelLength, offs);
                offs += (int)LabelLength;

                for (var ixStr = 0; ixStr < StringCount; ++ixStr)
                {
                    if (offs + 8 > data.Array.Length)
                    {
                        return(false);
                    }

                    String strIdent = CSF.ReadCString(data, 4, offs);
                    offs += 4;

                    var isPlain    = strIdent.Equals(" RTS");
                    var isExtended = strIdent.Equals("WRTS");

                    if (isPlain || isExtended)
                    {
                        var Val = new CSFValue();

                        var VLen = BitConverter.ToInt32(data.Array, offs);
                        offs += 4;

                        if (offs + VLen * 2 > data.Array.Length)
                        {
                            return(false);
                        }

                        for (var i = 0; i < VLen; ++i)
                        {
                            var raw = BitConverter.ToUInt16(data.Array, offs);
                            offs += 2;
                            raw  ^= 0xFFFF;

                            Val.Plain += (char)raw;
                        }

                        if (isExtended)
                        {
                            if (offs + 4 > data.Array.Length)
                            {
                                return(false);
                            }

                            var XLen = BitConverter.ToUInt32(data.Array, offs);
                            offs += 4;

                            if (offs + XLen > data.Array.Length)
                            {
                                return(false);
                            }

                            Val.Extra = CSF.ReadCString(data, XLen, offs);
                            offs     += (int)XLen;
                        }

                        Values.Add(Val);
                    }
                    else
                    {
                        return(false);
                    }
                }

                size = offs - data.Offset;

                return(true);
            }