Exemple #1
0
        public virtual void Read(OsiReader reader)
        {
            var wtf = reader.ReadByte();

            if (wtf == 49)
            {
                TypeId   = reader.ReadUInt32();
                IntValue = reader.ReadInt32();
            }
            else if (wtf == 48)
            {
                TypeId = reader.ReadUInt32();
                switch ((Type)TypeId)
                {
                case Type.Unknown:
                    break;

                case Type.Integer:
                    IntValue = reader.ReadInt32();
                    break;

                case Type.Float:
                    FloatValue = reader.ReadSingle();
                    break;

                case Type.String:
                    if (reader.ReadByte() > 0)
                    {
                        StringValue = reader.ReadString();
                    }
                    break;

                default:
                    StringValue = reader.ReadString();
                    break;
                }
            }
            else
            {
                throw new InvalidDataException("Unrecognized value type");
            }
        }
Exemple #2
0
        public virtual void Read(OsiReader reader)
        {
            // possibly isReference?
            var wtf = reader.ReadByte();

            if (wtf == '1')
            {
                TypeId   = reader.ReadUInt32();
                IntValue = reader.ReadInt32();
            }
            else if (wtf == '0')
            {
                TypeId = reader.ReadUInt32();
                uint writtenTypeId = TypeId;

                uint alias;
                bool dos1alias = false;
                if (reader.TypeAliases.TryGetValue(writtenTypeId, out alias))
                {
                    writtenTypeId = alias;
                    if (reader.Ver < OsiVersion.VerEnhancedTypes)
                    {
                        dos1alias = true;
                    }
                }

                if (reader.Ver < OsiVersion.VerEnhancedTypes)
                {
                    // Convert D:OS 1 type ID to D:OS 2 type ID
                    writtenTypeId = ConvertOS1ToOS2Type(writtenTypeId);
                }

                switch ((Type)writtenTypeId)
                {
                case Type.Unknown:
                    break;

                case Type.Integer:
                    IntValue = reader.ReadInt32();
                    break;

                case Type.Integer64:
                    Int64Value = reader.ReadInt64();
                    break;

                case Type.Float:
                    FloatValue = reader.ReadSingle();
                    break;

                case Type.GuidString:
                case Type.String:
                    // D:OS 1 aliased strings didn't have a flag byte
                    if (dos1alias)
                    {
                        StringValue = reader.ReadString();
                    }
                    else if (reader.ReadByte() > 0)
                    {
                        StringValue = reader.ReadString();
                    }
                    break;

                default:
                    StringValue = reader.ReadString();
                    break;
                }
            }
            else
            {
                throw new InvalidDataException("Unrecognized value type");
            }
        }