Exemple #1
0
            public CommonData(Reader <T> owner, Type fieldType)
            {
                var fieldTypeCode = Type.GetTypeCode(fieldType);

                if (fieldType.IsArray)
                {
                    fieldTypeCode = Type.GetTypeCode(fieldType.GetElementType());
                }

                var count = owner.ReadInt32();

                Values = new Dictionary <int, object>(count);
                var expectedType = owner.ReadByte();

                for (var i = 0; i < count; ++i)
                {
                    switch (expectedType)
                    {
                    case 1:
                        Values[owner.ReadInt32()] = fieldTypeCode == TypeCode.Int16 ? (object)owner.ReadInt16() : (object)owner.ReadUInt16();
                        break;

                    case 2:
                        Values[owner.ReadInt32()] = fieldTypeCode == TypeCode.Byte ? (object)owner.ReadByte() : (object)owner.ReadSByte();
                        break;

                    case 3:
                        Values[owner.ReadInt32()] = owner.ReadSingle();
                        break;

                    case 4:
                        Values[owner.ReadInt32()] = fieldTypeCode == TypeCode.Int32 ? (object)owner.ReadInt32() : (object)owner.ReadUInt32();
                        break;

                    default:
                        throw new InvalidOperationException();
                    }
                }
            }
Exemple #2
0
            public CommonData(Reader <T> owner, Type fieldType)
            {
                var fieldTypeCode = Type.GetTypeCode(fieldType);

                if (fieldType.IsArray)
                {
                    fieldTypeCode = Type.GetTypeCode(fieldType.GetElementType());
                }

                var count = owner.ReadInt32();

                Values = new Dictionary <int, object>(count);
                var expectedType = owner.ReadByte();

                /// Starting with patch 7.3.0.24473 (PTR), this structure is now padded.
                /// This is the only change as it was not enough to trigger a version update.
                /// For now, we will peek for 0 bytes, since this block is not supposed contain
                /// non-default values anyway, and skip accordingly.
                ///
                /// Note: The entire handling of the so-called "common block" is completely
                /// shit but even to this day I have no idea how to better handle it.
                /// Warpten, 8/20/17 2:06AM

                for (var i = 0; i < count; ++i)
                {
                    switch (expectedType)
                    {
                    case 0:
                        Values[owner.ReadInt32()] = owner.ReadString();
                        break;

                    case 1:
                        Values[owner.ReadInt32()] = fieldTypeCode == TypeCode.Int16 ? (object)owner.ReadInt16() : (object)owner.ReadUInt16();
                        if (owner.PeekChar() == '\0')
                        {
                            owner.BaseStream.Position += 2;
                        }
                        break;

                    case 2:
                        Values[owner.ReadInt32()] = fieldTypeCode == TypeCode.Byte ? (object)owner.ReadByte() : (object)owner.ReadSByte();
                        if (owner.PeekChar() == '\0')
                        {
                            owner.BaseStream.Position += 3;
                        }
                        break;

                    case 3:
                        Values[owner.ReadInt32()] = owner.ReadSingle();
                        break;

                    case 4:
                        Values[owner.ReadInt32()] = fieldTypeCode == TypeCode.Int32 ? (object)owner.ReadInt32() : (object)owner.ReadUInt32();
                        break;

                    default:
                        throw new NotSupportedException($"Type {expectedType} in the common block is not supported!");
                    }
                }
            }