Esempio n. 1
0
        private NTROSerialization.NTROValue ReadField(ResourceIntrospectionManifest.ResourceDiskStruct.Field field, bool pointer)
        {
            switch (field.Type)
            {
            case DataType.Struct:
                var newStruct = Resource.IntrospectionManifest.ReferencedStructs.First(x => x.Id == field.TypeData);
                return(new NTROSerialization.NTROValue <NTROSerialization.NTROStruct>(field.Type, ReadStructure(newStruct, Reader.BaseStream.Position), pointer));

            case DataType.Enum:
                // TODO: Lookup in ReferencedEnums
                return(new NTROSerialization.NTROValue <uint>(field.Type, Reader.ReadUInt32(), pointer));

            case DataType.SByte:
                return(new NTROSerialization.NTROValue <sbyte>(field.Type, Reader.ReadSByte(), pointer));

            case DataType.Byte:
                return(new NTROSerialization.NTROValue <byte>(field.Type, Reader.ReadByte(), pointer));

            case DataType.Boolean:
                return(new NTROSerialization.NTROValue <bool>(field.Type, Reader.ReadByte() == 1 ? true : false, pointer));

            case DataType.Int16:
                return(new NTROSerialization.NTROValue <short>(field.Type, Reader.ReadInt16(), pointer));

            case DataType.UInt16:
                return(new NTROSerialization.NTROValue <ushort>(field.Type, Reader.ReadUInt16(), pointer));

            case DataType.Int32:
                return(new NTROSerialization.NTROValue <int>(field.Type, Reader.ReadInt32(), pointer));

            case DataType.UInt32:
                return(new NTROSerialization.NTROValue <uint>(field.Type, Reader.ReadUInt32(), pointer));

            case DataType.Float:
                return(new NTROSerialization.NTROValue <float>(field.Type, Reader.ReadSingle(), pointer));

            case DataType.Int64:
                return(new NTROSerialization.NTROValue <long>(field.Type, Reader.ReadInt64(), pointer));

            case DataType.ExternalReference:
                var id = Reader.ReadUInt64();
                return(new NTROSerialization.NTROValue <ResourceExtRefList.ResourceReferenceInfo>(field.Type, Resource.ExternalReferences.ResourceRefInfoList.FirstOrDefault(c => c.Id == id), pointer));

            case DataType.UInt64:
                return(new NTROSerialization.NTROValue <ulong>(field.Type, Reader.ReadUInt64(), pointer));

            case DataType.Vector:
                var vector3 = new NTROSerialization.Vector3(
                    Reader.ReadSingle(),
                    Reader.ReadSingle(),
                    Reader.ReadSingle()
                    );

                return(new NTROSerialization.NTROValue <NTROSerialization.Vector3>(field.Type, vector3, pointer));

            case DataType.Quaternion:
            case DataType.Color:
            case DataType.Fltx4:
            case DataType.Vector4D:
                var vector4 = new NTROSerialization.Vector4(
                    Reader.ReadSingle(),
                    Reader.ReadSingle(),
                    Reader.ReadSingle(),
                    Reader.ReadSingle()
                    );

                return(new NTROSerialization.NTROValue <NTROSerialization.Vector4>(field.Type, vector4, pointer));

            case DataType.String4:
            case DataType.String:
                return(new NTROSerialization.NTROValue <string>(field.Type, Reader.ReadOffsetString(Encoding.UTF8), pointer));

            case DataType.Matrix3x4:
            case DataType.Matrix3x4a:
                var matrix3x4a = new NTROSerialization.Matrix3x4(
                    Reader.ReadSingle(), Reader.ReadSingle(), Reader.ReadSingle(), Reader.ReadSingle(),
                    Reader.ReadSingle(), Reader.ReadSingle(), Reader.ReadSingle(), Reader.ReadSingle(),
                    Reader.ReadSingle(), Reader.ReadSingle(), Reader.ReadSingle(), Reader.ReadSingle()
                    );

                return(new NTROSerialization.NTROValue <NTROSerialization.Matrix3x4>(field.Type, matrix3x4a, pointer));

            case DataType.CTransform:
                var transform = new NTROSerialization.CTransform(
                    Reader.ReadSingle(), Reader.ReadSingle(), Reader.ReadSingle(), Reader.ReadSingle(),
                    Reader.ReadSingle(), Reader.ReadSingle(), Reader.ReadSingle(), Reader.ReadSingle()
                    );

                return(new NTROSerialization.NTROValue <NTROSerialization.CTransform>(field.Type, transform, pointer));

            default:
                throw new NotImplementedException(string.Format("Unknown data type: {0}", field.Type));
            }
        }
Esempio n. 2
0
        private NTROSerialization.NTROValue ReadField(ResourceIntrospectionManifest.ResourceDiskStruct.Field field, bool pointer)
        {
            switch (field.Type)
            {
                case DataType.Struct:
                    var newStruct = Resource.IntrospectionManifest.ReferencedStructs.First(x => x.Id == field.TypeData);
                    return new NTROSerialization.NTROValue<NTROSerialization.NTROStruct>(field.Type, ReadStructure(newStruct, Reader.BaseStream.Position), pointer);

                case DataType.Enum:
                    // TODO: Lookup in ReferencedEnums
                    return new NTROSerialization.NTROValue<uint>(field.Type, Reader.ReadUInt32(), pointer);

                case DataType.SByte:
                    return new NTROSerialization.NTROValue<sbyte>(field.Type, Reader.ReadSByte(), pointer);

                case DataType.Byte:
                    return new NTROSerialization.NTROValue<byte>(field.Type, Reader.ReadByte(), pointer);

                case DataType.Boolean:
                    return new NTROSerialization.NTROValue<bool>(field.Type, Reader.ReadByte() == 1 ? true : false, pointer);

                case DataType.Int16:
                    return new NTROSerialization.NTROValue<short>(field.Type, Reader.ReadInt16(), pointer);

                case DataType.UInt16:
                    return new NTROSerialization.NTROValue<ushort>(field.Type, Reader.ReadUInt16(), pointer);

                case DataType.Int32:
                    return new NTROSerialization.NTROValue<int>(field.Type, Reader.ReadInt32(), pointer);

                case DataType.UInt32:
                    return new NTROSerialization.NTROValue<uint>(field.Type, Reader.ReadUInt32(), pointer);

                case DataType.Float:
                    return new NTROSerialization.NTROValue<float>(field.Type, Reader.ReadSingle(), pointer);

                case DataType.Int64:
                    return new NTROSerialization.NTROValue<long>(field.Type, Reader.ReadInt64(), pointer);

                case DataType.ExternalReference: // Handled elsewhere
                case DataType.UInt64:
                    return new NTROSerialization.NTROValue<ulong>(field.Type, Reader.ReadUInt64(), pointer);

                case DataType.Vector:
                    var vector3 = new NTROSerialization.Vector3(
                        Reader.ReadSingle(),
                        Reader.ReadSingle(),
                        Reader.ReadSingle()
                    );

                    return new NTROSerialization.NTROValue<NTROSerialization.Vector3>(field.Type, vector3, pointer);

                case DataType.Quaternion:
                case DataType.Color:
                case DataType.Fltx4:
                case DataType.Vector4D:
                    var vector4 = new NTROSerialization.Vector4(
                        Reader.ReadSingle(),
                        Reader.ReadSingle(),
                        Reader.ReadSingle(),
                        Reader.ReadSingle()
                    );

                    return new NTROSerialization.NTROValue<NTROSerialization.Vector4>(field.Type, vector4, pointer);

                case DataType.String4:
                case DataType.String:
                    return new NTROSerialization.NTROValue<string>(field.Type, Reader.ReadOffsetString(Encoding.UTF8), pointer);

                case DataType.Matrix3x4:
                case DataType.Matrix3x4a:
                    var matrix3x4a = new NTROSerialization.Matrix3x4(
                        Reader.ReadSingle(), Reader.ReadSingle(), Reader.ReadSingle(), Reader.ReadSingle(),
                        Reader.ReadSingle(), Reader.ReadSingle(), Reader.ReadSingle(), Reader.ReadSingle(),
                        Reader.ReadSingle(), Reader.ReadSingle(), Reader.ReadSingle(), Reader.ReadSingle()
                     );

                    return new NTROSerialization.NTROValue<NTROSerialization.Matrix3x4>(field.Type, matrix3x4a, pointer);

                case DataType.CTransform:
                    var transform = new NTROSerialization.CTransform(
                        Reader.ReadSingle(), Reader.ReadSingle(), Reader.ReadSingle(), Reader.ReadSingle(),
                        Reader.ReadSingle(), Reader.ReadSingle(), Reader.ReadSingle(), Reader.ReadSingle()
                     );

                    return new NTROSerialization.NTROValue<NTROSerialization.CTransform>(field.Type, transform, pointer);

                default:
                    throw new NotImplementedException(string.Format("Unknown data type: {0}", field.Type));
            }
        }
Esempio n. 3
0
        private NTROValue ReadField(ResourceIntrospectionManifest.ResourceDiskStruct.Field field, bool pointer)
        {
            switch (field.Type)
            {
                case DataType.Struct:
                    var newStruct = Resource.IntrospectionManifest.ReferencedStructs.First(x => x.Id == field.TypeData);
                    return new NTROValue<NTROStruct>(field.Type, ReadStructure(newStruct, Reader.BaseStream.Position), pointer);

                case DataType.Enum:
                    // TODO: Lookup in ReferencedEnums
                    return new NTROValue<uint>(field.Type, Reader.ReadUInt32(), pointer);

                case DataType.SByte:
                    return new NTROValue<sbyte>(field.Type, Reader.ReadSByte(), pointer);

                case DataType.Byte:
                    return new NTROValue<byte>(field.Type, Reader.ReadByte(), pointer);

                case DataType.Boolean:
                    return new NTROValue<bool>(field.Type, Reader.ReadByte() == 1 ? true : false, pointer);

                case DataType.Int16:
                    return new NTROValue<short>(field.Type, Reader.ReadInt16(), pointer);

                case DataType.UInt16:
                    return new NTROValue<ushort>(field.Type, Reader.ReadUInt16(), pointer);

                case DataType.Int32:
                    return new NTROValue<int>(field.Type, Reader.ReadInt32(), pointer);

                case DataType.UInt32:
                    return new NTROValue<uint>(field.Type, Reader.ReadUInt32(), pointer);

                case DataType.Float:
                    return new NTROValue<float>(field.Type, Reader.ReadSingle(), pointer);

                case DataType.Int64:
                    return new NTROValue<long>(field.Type, Reader.ReadInt64(), pointer);

                case DataType.ExternalReference:
                    var id = Reader.ReadUInt64();
                    var value = id > 0
                        ? Resource.ExternalReferences?.ResourceRefInfoList.FirstOrDefault(c => c.Id == id)
                        : null;

                    return new NTROValue<ResourceExtRefList.ResourceReferenceInfo>(field.Type, value, pointer);

                case DataType.UInt64:
                    return new NTROValue<ulong>(field.Type, Reader.ReadUInt64(), pointer);

                case DataType.Vector:
                    var vector3 = new Vector3(
                        Reader.ReadSingle(),
                        Reader.ReadSingle(),
                        Reader.ReadSingle());

                    return new NTROValue<Vector3>(field.Type, vector3, pointer);

                case DataType.Quaternion:
                case DataType.Color:
                case DataType.Fltx4:
                case DataType.Vector4D:
                case DataType.Vector4D_44:
                    var vector4 = new Vector4(
                        Reader.ReadSingle(),
                        Reader.ReadSingle(),
                        Reader.ReadSingle(),
                        Reader.ReadSingle());

                    return new NTROValue<Vector4>(field.Type, vector4, pointer);

                case DataType.String4:
                case DataType.String:
                    return new NTROValue<string>(field.Type, Reader.ReadOffsetString(Encoding.UTF8), pointer);

                case DataType.Matrix3x4:
                case DataType.Matrix3x4a:
                    var matrix3x4a = new Matrix3x4(
                        Reader.ReadSingle(),
                        Reader.ReadSingle(),
                        Reader.ReadSingle(),
                        Reader.ReadSingle(),
                        Reader.ReadSingle(),
                        Reader.ReadSingle(),
                        Reader.ReadSingle(),
                        Reader.ReadSingle(),
                        Reader.ReadSingle(),
                        Reader.ReadSingle(),
                        Reader.ReadSingle(),
                        Reader.ReadSingle());

                    return new NTROValue<Matrix3x4>(field.Type, matrix3x4a, pointer);

                case DataType.CTransform:
                    var transform = new CTransform(
                        Reader.ReadSingle(),
                        Reader.ReadSingle(),
                        Reader.ReadSingle(),
                        Reader.ReadSingle(),
                        Reader.ReadSingle(),
                        Reader.ReadSingle(),
                        Reader.ReadSingle(),
                        Reader.ReadSingle());

                    return new NTROValue<CTransform>(field.Type, transform, pointer);

                default:
                    throw new NotImplementedException($"Unknown data type: {field.Type} (name: {field.FieldName})");
            }
        }