示例#1
0
文件: Common.cs 项目: takhlaq/Lumina
 public static Transformation Read(BinaryReader br)
 {
     return(new Transformation
     {
         Translation = Vector3.Read(br), Rotation = Vector3.Read(br), Scale = Vector3.Read(br)
     });
 }
示例#2
0
 public override void Read(BinaryReader reader)
 {
     base.Read(reader);
     frameId             = reader.ReadInt32();
     destinationEntityId = reader.ReadInt32();
     movementType        = (MovementType)reader.ReadInt32();
     destination.Read(reader);
 }
示例#3
0
文件: Common.cs 项目: pmgr/Lumina
 public static BoundingBox Read(BinaryReader reader)
 {
     return(new BoundingBox
     {
         Min = Vector3.Read(reader),
         Max = Vector3.Read(reader)
     });
 }
示例#4
0
    public void Read(TProtocol iprot)
    {
        TField field;

        iprot.ReadStructBegin();
        while (true)
        {
            field = iprot.ReadFieldBegin();
            if (field.Type == TType.Stop)
            {
                break;
            }
            switch (field.ID)
            {
            case 1:
                if (field.Type == TType.Struct)
                {
                    Header = new ProtocolAckBase();
                    Header.Read(iprot);
                }
                else
                {
                    TProtocolUtil.Skip(iprot, field.Type);
                }
                break;

            case 2:
                if (field.Type == TType.String)
                {
                    Name = iprot.ReadString();
                }
                else
                {
                    TProtocolUtil.Skip(iprot, field.Type);
                }
                break;

            case 3:
                if (field.Type == TType.Struct)
                {
                    Goal = new Vector3();
                    Goal.Read(iprot);
                }
                else
                {
                    TProtocolUtil.Skip(iprot, field.Type);
                }
                break;

            default:
                TProtocolUtil.Skip(iprot, field.Type);
                break;
            }
            iprot.ReadFieldEnd();
        }
        iprot.ReadStructEnd();
    }
示例#5
0
        //public Vector3 direction;


        public override void Read(BinaryReader reader)
        {
            base.Read(reader);
            frameId   = reader.ReadInt32();
            abilityId = reader.ReadInt32();
            targetId  = reader.ReadInt32();

            position.Read(reader);
        }
            }                                   // Found during discovery of unread bytes, no idea what this is for

            public static GfxBoundingBox Load(Utility utility)
            {
                var bb = new GfxBoundingBox();

                CGFXDebug.LoadStart(bb, utility);

                bb.Center      = Vector3.Read(utility);
                bb.Orientation = Matrix3x3.Read(utility);
                bb.Size        = Vector3.Read(utility);
                bb.Unknown     = utility.ReadFloat();

                return(bb);
            }
        public override void Load(Utility utility)
        {
            base.Load(utility);

            Unknown1      = utility.ReadU32();
            BranchVisible = utility.ReadU32();

            // FIXME according to SPICA this is an arbitrary list of child "GfxObjects"
            ChildCount  = utility.ReadU32();    // ???
            ChildOffset = utility.ReadOffset(); // Offset to pointer list (?) of children I assume
            if (ChildCount != 0 && ChildOffset != 0)
            {
                // PROTIP: GfxObject.cs in SPICA has all the TypeIds and I guess it's possible
                // that this would be a list pointing to any of them, but we can address it
                // one at a time if it comes up (because I certainly haven't implemented all
                // of these...)

                //[TypeChoice(0x01000000, typeof(GfxMesh))]
                //[TypeChoice(0x02000000, typeof(GfxSkeleton))]
                //[TypeChoice(0x04000000, typeof(GfxLUT))]
                //[TypeChoice(0x08000000, typeof(GfxMaterial))]
                //[TypeChoice(0x10000001, typeof(GfxShape))]
                //[TypeChoice(0x20000004, typeof(GfxTextureReference))]
                //[TypeChoice(0x20000009, typeof(GfxTextureCube))]
                //[TypeChoice(0x20000011, typeof(GfxTextureImage))]
                //[TypeChoice(0x4000000a, typeof(GfxCamera))]
                //[TypeChoice(0x40000012, typeof(GfxModel))]
                //[TypeChoice(0x40000092, typeof(GfxModelSkeletal))]
                //[TypeChoice(0x400000a2, typeof(GfxFragmentLight))]
                //[TypeChoice(0x40000122, typeof(GfxHemisphereLight))]
                //[TypeChoice(0x40000222, typeof(GfxVertexLight))]
                //[TypeChoice(0x40000422, typeof(GfxAmbientLight))]
                //[TypeChoice(0x80000001, typeof(GfxShaderReference))]

                throw new NotImplementedException("Child objects not implemented");
            }

            AnimGroup = utility.LoadDICTFromOffset <ChunkDICTAnimGroup>();

            TransformScale     = Vector3.Read(utility);
            TransformRotate    = Vector3.Read(utility);
            TransformTranslate = Vector3.Read(utility);
            LocalMatrix        = Matrix.Read(utility);
            WorldMatrix        = Matrix.Read(utility);
        }
        public override void Load(Utility utility)
        {
            base.Load(utility);

            Flags = utility.ReadU32();

            utility.LoadIndirect(() =>
            {
                BoundingBox = GfxBoundingBox.Load(utility);
            });

            PositionOffset = Vector3.Read(utility);

            SubMeshes = utility.LoadIndirectObjList(() => GfxSubMesh.Load(utility)).ToList();

            BaseAddress = utility.ReadU32();

            VertexBuffers = utility.LoadIndirectObjList(() => VertexBuffer.Load(utility)).ToList();

            utility.LoadIndirect(() =>
            {
                BlendShape = BlendShape.Load(utility);
            });
        }
        public override void Load(Utility utility)
        {
            // Used for later resolving ONLY
            OriginalOffset = utility.GetReadPosition();

            // Unlike most objects loaded from a DICT, bones DO NOT use the stndard
            // Type/Magic/Revision/Name/MetaData header and instead do their own thing...
            // (in short, not calling base.Load() here!!)
            Name = utility.ReadString();

            Flags = (BoneFlags)utility.ReadU32();

            Index       = utility.ReadI32();
            ParentIndex = utility.ReadI32();

            // NOTE !! Relational data... will have to treat this carefully...
            // We're UNUSUALLY going to store absolute offsets only here (so
            // we don't pointlessly and recursively reload bones several times),
            // and we'll resolve them LATER...
            ParentOffset      = utility.ReadOffset();
            ChildOffset       = utility.ReadOffset();
            PrevSiblingOffset = utility.ReadOffset();
            NextSiblingOffset = utility.ReadOffset();

            Scale       = Vector3.Read(utility);
            Rotation    = Vector3.Read(utility);
            Translation = Vector3.Read(utility);

            LocalTransform    = Matrix.Read(utility);
            WorldTransform    = Matrix.Read(utility);
            InvWorldTransform = Matrix.Read(utility);

            BillboardMode = (GfxBillboardMode)utility.ReadU32();

            MetaDatas = utility.LoadDICTFromOffset <ChunkDICTMetaData>();
        }
示例#10
0
 public void Read (TProtocol iprot)
 {
   TField field;
   iprot.ReadStructBegin();
   while (true)
   {
     field = iprot.ReadFieldBegin();
     if (field.Type == TType.Stop) { 
       break;
     }
     switch (field.ID)
     {
       case 1:
         if (field.Type == TType.Struct) {
           Header = new ProtocolBase();
           Header.Read(iprot);
         } else { 
           TProtocolUtil.Skip(iprot, field.Type);
         }
         break;
       case 2:
         if (field.Type == TType.Struct) {
           Dir = new Vector3();
           Dir.Read(iprot);
         } else { 
           TProtocolUtil.Skip(iprot, field.Type);
         }
         break;
       default: 
         TProtocolUtil.Skip(iprot, field.Type);
         break;
     }
     iprot.ReadFieldEnd();
   }
   iprot.ReadStructEnd();
 }
示例#11
0
 public override void Read(BinaryReader reader)
 {
     base.Read(reader);
     frameId = reader.ReadInt32();
     awayFrom.Read(reader);
 }
示例#12
0
    public void Read(TProtocol iprot)
    {
        TField field;

        iprot.ReadStructBegin();
        while (true)
        {
            field = iprot.ReadFieldBegin();
            if (field.Type == TType.Stop)
            {
                break;
            }
            switch (field.ID)
            {
            case 1:
                if (field.Type == TType.String)
                {
                    Uid = iprot.ReadString();
                }
                else
                {
                    TProtocolUtil.Skip(iprot, field.Type);
                }
                break;

            case 2:
                if (field.Type == TType.String)
                {
                    Type = iprot.ReadString();
                }
                else
                {
                    TProtocolUtil.Skip(iprot, field.Type);
                }
                break;

            case 3:
                if (field.Type == TType.I32)
                {
                    Camp = iprot.ReadI32();
                }
                else
                {
                    TProtocolUtil.Skip(iprot, field.Type);
                }
                break;

            case 4:
                if (field.Type == TType.I64)
                {
                    MovingStartTick = iprot.ReadI64();
                }
                else
                {
                    TProtocolUtil.Skip(iprot, field.Type);
                }
                break;

            case 5:
                if (field.Type == TType.Struct)
                {
                    Spos = new Vector3();
                    Spos.Read(iprot);
                }
                else
                {
                    TProtocolUtil.Skip(iprot, field.Type);
                }
                break;

            case 6:
                if (field.Type == TType.Struct)
                {
                    Cpos = new Vector3();
                    Cpos.Read(iprot);
                }
                else
                {
                    TProtocolUtil.Skip(iprot, field.Type);
                }
                break;

            case 7:
                if (field.Type == TType.Struct)
                {
                    Goal = new Vector3();
                    Goal.Read(iprot);
                }
                else
                {
                    TProtocolUtil.Skip(iprot, field.Type);
                }
                break;

            case 8:
                if (field.Type == TType.Double)
                {
                    Speed = iprot.ReadDouble();
                }
                else
                {
                    TProtocolUtil.Skip(iprot, field.Type);
                }
                break;

            case 9:
                if (field.Type == TType.Bool)
                {
                    Death = iprot.ReadBool();
                }
                else
                {
                    TProtocolUtil.Skip(iprot, field.Type);
                }
                break;

            default:
                TProtocolUtil.Skip(iprot, field.Type);
                break;
            }
            iprot.ReadFieldEnd();
        }
        iprot.ReadStructEnd();
    }
示例#13
0
 public void Read (TProtocol iprot)
 {
   TField field;
   iprot.ReadStructBegin();
   while (true)
   {
     field = iprot.ReadFieldBegin();
     if (field.Type == TType.Stop) { 
       break;
     }
     switch (field.ID)
     {
       case 1:
         if (field.Type == TType.String) {
           Uid = iprot.ReadString();
         } else { 
           TProtocolUtil.Skip(iprot, field.Type);
         }
         break;
       case 2:
         if (field.Type == TType.String) {
           Type = iprot.ReadString();
         } else { 
           TProtocolUtil.Skip(iprot, field.Type);
         }
         break;
       case 3:
         if (field.Type == TType.I32) {
           Camp = iprot.ReadI32();
         } else { 
           TProtocolUtil.Skip(iprot, field.Type);
         }
         break;
       case 4:
         if (field.Type == TType.I64) {
           MovingStartTick = iprot.ReadI64();
         } else { 
           TProtocolUtil.Skip(iprot, field.Type);
         }
         break;
       case 5:
         if (field.Type == TType.Struct) {
           Spos = new Vector3();
           Spos.Read(iprot);
         } else { 
           TProtocolUtil.Skip(iprot, field.Type);
         }
         break;
       case 6:
         if (field.Type == TType.Struct) {
           Cpos = new Vector3();
           Cpos.Read(iprot);
         } else { 
           TProtocolUtil.Skip(iprot, field.Type);
         }
         break;
       case 7:
         if (field.Type == TType.Struct) {
           Goal = new Vector3();
           Goal.Read(iprot);
         } else { 
           TProtocolUtil.Skip(iprot, field.Type);
         }
         break;
       case 8:
         if (field.Type == TType.Double) {
           Speed = iprot.ReadDouble();
         } else { 
           TProtocolUtil.Skip(iprot, field.Type);
         }
         break;
       case 9:
         if (field.Type == TType.Bool) {
           Death = iprot.ReadBool();
         } else { 
           TProtocolUtil.Skip(iprot, field.Type);
         }
         break;
       default: 
         TProtocolUtil.Skip(iprot, field.Type);
         break;
     }
     iprot.ReadFieldEnd();
   }
   iprot.ReadStructEnd();
 }
示例#14
0
        private static object ReadValue(BinaryReader reader, string type, StringType stringType)
        {
            switch (type)
            {
            case "int8":
                return(reader.ReadSByte());

            case "uint8":
                return(reader.ReadByte());

            case "int16":
                return(reader.ReadInt16());

            case "uint16":
                return(reader.ReadUInt16());

            case "int":
            case "int32":
                return(reader.ReadInt32());

            case "uint":
            case "uint32":
                return(reader.ReadUInt32());

            case "int64":
                return(reader.ReadInt64());

            case "uint64":
                return(reader.ReadUInt64());

            case "float":
                return(reader.ReadSingle());

            case "double":
                return(reader.ReadDouble());

            case "bool":
                return(reader.ReadBoolean());

            case "Vector3":
                return(Vector3.Read(reader));

            case "Vector4":
            case "Quaternion":
                return(Vector4.Read(reader));

            case "string":
                var size = reader.ReadUInt16();
                if (Program.IsVerbose)
                {
                    Console.WriteLine($"String length: {size}");
                }

                string str = string.Empty;
                if (stringType == StringType.Tpp)
                {
                    str = new string(reader.ReadChars(size));
                    reader.ReadChar();
                }
                else
                {
                    var currentChar = reader.ReadChar();
                    while (currentChar != '\0')
                    {
                        str        += currentChar;
                        currentChar = reader.ReadChar();
                    }
                }

                if (Program.IsVerbose)
                {
                    Console.WriteLine($"String: {str}");
                }

                return(str);

            default:
                throw new FormatException($"Unknown property type {type}");
            }
        }
示例#15
0
        public static MilkShape Load(BinaryReader br)
        {
            var ms      = new MilkShape();
            var utility = new Utility(br, null, Endianness.Little);     // Milkshape is tied to Win32, so definitely little endian

            // First comes the header (sizeof(ms3d_header_t) == 14)
            var magic = ReadString(utility, 10);

            if (magic != Magic)
            {
                throw new InvalidOperationException($"Milkshape Load: Bad magic, expected {Magic}, got {magic}");
            }

            var version = utility.ReadU32();

            if (version != 4)
            {
                throw new InvalidOperationException($"Milkshape Load: Unsupported version, expected 4, got {version}");
            }

            // Then comes the number of vertices
            var nNumVertices = utility.ReadU16();

            // Then come nNumVertices times ms3d_vertex_t structs (sizeof(ms3d_vertex_t) == 15)
            ms.Vertices = new List <ms3d_vertex_t>(nNumVertices);
            for (var v = 0; v < nNumVertices; v++)
            {
                var vertex = new ms3d_vertex_t();
                vertex.Flags    = (MilkshapeObjectFlags)utility.ReadByte(); // SELECTED | SELECTED2 | HIDDEN
                vertex.Position = Vector3.Read(utility);

                // NOTE: I'm merging the different specs / extended attributes here; will look confusing
                vertex.BoneIdsAndWeights[0].BoneId = utility.ReadSByte();

                vertex.ReferenceCount = utility.ReadByte();

                ms.Vertices.Add(vertex);
            }

            // Then comes the number of triangles
            var nNumTriangles = utility.ReadU16(); // 2 bytes

            // Then come nNumTriangles times ms3d_triangle_t structs (sizeof(ms3d_triangle_t) == 70)
            ms.Triangles = new List <ms3d_triangle_t>(nNumTriangles);
            for (var t = 0; t < nNumTriangles; t++)
            {
                ms.Triangles.Add(new ms3d_triangle_t
                {
                    Flags              = (MilkshapeObjectFlags)utility.ReadU16(), // SELECTED | SELECTED2 | HIDDEN
                    VertexIndices      = utility.ReadU16Ints(3),
                    VertexNormals      = new[] { Vector3.Read(utility), Vector3.Read(utility), Vector3.Read(utility) },
                    TextureCoordinates = ReadTextureCoordinates(utility),
                    SmoothingGroup     = utility.ReadByte(),                        // 1 - 32
                    GroupIndex         = utility.ReadByte()                         //
                });
            }

            // Then comes the number of groups
            var nNumGroups = utility.ReadU16(); // 2 bytes

            // Then come nNumGroups times groups (the sizeof a group is dynamic, because of triangleIndices is numtriangles long)
            ms.Groups = new List <ms3d_group_t>(nNumGroups);
            for (var g = 0; g < nNumGroups; g++)
            {
                var group = new ms3d_group_t();

                group.Flags = (MilkshapeObjectFlags)utility.ReadByte();     // SELECTED | HIDDEN
                group.Name  = ReadString(utility, 32);

                var numtriangles = utility.ReadU16();
                group.TriangleIndices = utility.ReadU16Ints(numtriangles);
                group.MaterialIndex   = utility.ReadSByte();

                ms.Groups.Add(group);
            }

            // number of materials
            var nNumMaterials = utility.ReadU16(); // 2 bytes

            // Then come nNumMaterials times ms3d_material_t structs (sizeof(ms3d_material_t) == 361)
            ms.Materials = new List <ms3d_material_t>(nNumMaterials);
            for (var m = 0; m < nNumMaterials; m++)
            {
                ms.Materials.Add(new ms3d_material_t
                {
                    Name         = ReadString(utility, 32),
                    Ambient      = utility.ReadFloats(4),
                    Diffuse      = utility.ReadFloats(4),
                    Specular     = utility.ReadFloats(4),
                    Emissive     = utility.ReadFloats(4),
                    Shininess    = utility.ReadFloat(),
                    Transparency = utility.ReadFloat(),
                    Mode         = utility.ReadSByte(),

                    // NOTE: Examining a file written by MilkShape, I saw garbage beyond
                    // the null terminator of these strings. Harmless, just FYI.
                    Texture  = ReadString(utility, 128),
                    Alphamap = ReadString(utility, 128)
                });
            }

            // save some keyframer data
            ms.fAnimationFPS = utility.ReadFloat();
            ms.fCurrentTime  = utility.ReadFloat();
            ms.iTotalFrames  = utility.ReadI32();

            // number of joints
            var nNumJoints = utility.ReadU16(); // 2 bytes

            // Then come nNumJoints joints (the size of joints are dynamic, because each joint has a differnt count of keys
            ms.Joints = new List <ms3d_joint_t>(nNumJoints);
            for (var j = 0; j < nNumJoints; j++)
            {
                var joint = new ms3d_joint_t();

                joint.Flags      = (MilkshapeObjectFlags)utility.ReadByte();
                joint.Name       = ReadString(utility, 32);
                joint.ParentName = ReadString(utility, 32);
                joint.Rotation   = Vector3.Read(utility);
                joint.Position   = Vector3.Read(utility);

                var numKeyFramesRot   = utility.ReadU16();
                var numKeyFramesTrans = utility.ReadU16();

                joint.KeyFramesRot = new ms3d_keyframe_rot_t[numKeyFramesRot];
                for (var r = 0; r < numKeyFramesRot; r++)
                {
                    joint.KeyFramesRot[r] = new ms3d_keyframe_rot_t
                    {
                        Time     = utility.ReadFloat(),
                        Rotation = Vector3.Read(utility)
                    };
                }

                joint.KeyFramesTrans = new ms3d_keyframe_pos_t[numKeyFramesTrans];
                for (var t = 0; t < numKeyFramesTrans; t++)
                {
                    joint.KeyFramesTrans[t] = new ms3d_keyframe_pos_t
                    {
                        Time     = utility.ReadFloat(),
                        Position = Vector3.Read(utility)
                    };
                }

                ms.Joints.Add(joint);
            }

            try
            {
                // subVersion specifying whether comment data exists
                var subVersion = utility.ReadU32();

                if (subVersion == 1)
                {
                    // Group comments
                    ReadComments(utility, ms.Groups);

                    // Material comments
                    ReadComments(utility, ms.Materials);

                    // Joint comments
                    ReadComments(utility, ms.Joints);

                    // Then comes the number of model comments, which is always 0 or 1
                    ReadComments(utility, new[] { ms }, true);
                }

                // subVersion specifying whether extended vertex data exists and to what extent
                subVersion = utility.ReadU32();

                if (subVersion > 0)
                {
                    // Then comes nNumVertices times ms3d_vertex_ex_t structs (sizeof(ms3d_vertex_ex_t) == 14)

                    // NOTE: I'm merging extended vertex data spec stuff from this mess:
                    //    sbyte[] boneIds = new sbyte[3];                                    // index of joint or -1, if -1, then that weight is ignored, since subVersion 1
                    //    byte[] weights = new byte[3];                                    // vertex weight ranging from 0 - 100, last weight is computed by 1.0 - sum(all weights), since subVersion 1
                    //                                                    // weight[0] is the weight for boneId in ms3d_vertex_t
                    //                                                    // weight[1] is the weight for boneIds[0]
                    //                                                    // weight[2] is the weight for boneIds[1]
                    //                                                    // 1.0f - weight[0] - weight[1] - weight[2] is the weight for boneIds[2]

                    // NOTE: "extra" depends in subVersion; 1 element if 2, 2 elements if 3
                    //    uint[] extra = new uint[2];									// vertex extra, which can be used as color or anything else, since subVersion 3

                    for (var v = 0; v < nNumVertices; v++)
                    {
                        var vertex = ms.Vertices[v];

                        // These are ADDITIONAL bone Ids
                        vertex.BoneIdsAndWeights[1].BoneId = utility.ReadSByte();
                        vertex.BoneIdsAndWeights[2].BoneId = utility.ReadSByte();
                        vertex.BoneIdsAndWeights[3].BoneId = utility.ReadSByte();

                        // These are WEIGHTS which were previously unavailable
                        vertex.BoneIdsAndWeights[0].Weight = utility.ReadByte();
                        vertex.BoneIdsAndWeights[1].Weight = utility.ReadByte();
                        vertex.BoneIdsAndWeights[2].Weight = utility.ReadByte();

                        // Final bone weight is computed -- NOTE, spec says 1.0 - [...], but I think it meant 100
                        vertex.BoneIdsAndWeights[3].Weight = (byte)(100 - vertex.BoneIdsAndWeights[0].Weight - vertex.BoneIdsAndWeights[1].Weight - vertex.BoneIdsAndWeights[2].Weight);

                        // How much "extra" data is here depends on subVersion...
                        var extraCount = subVersion - 1;
                        vertex.Extra = utility.ReadUInts(extraCount);
                    }
                }

                // subVersion specifying whether joints have color
                subVersion = utility.ReadU32();

                if (subVersion == 1)
                {
                    for (var j = 0; j < nNumJoints; j++)
                    {
                        var joint = ms.Joints[j];

                        joint.Color = new ColorFloat
                        {
                            R = utility.ReadFloat(),
                            G = utility.ReadFloat(),
                            B = utility.ReadFloat(),
                            A = 1.0f    // Not stored
                        };
                    }
                }

                // subVersion specifying whether model extended data exists
                subVersion = utility.ReadU32();

                if (subVersion == 1)
                {
                    ms.jointSize        = utility.ReadFloat(); // joint size, since subVersion == 1
                    ms.transparencyMode = utility.ReadI32();   // 0 = simple, 1 = depth buffered with alpha ref, 2 = depth sorted triangles, since subVersion == 1
                    ms.alphaRef         = utility.ReadFloat(); // alpha reference value for transparencyMode = 1, since subVersion == 1
                }
            }
            catch (IndexOutOfRangeException)
            {
                // This is a dirty hack because any file that doesn't have the extended data
                // will throw IndexOutOfRangeException but I really should be doing EOF checks
            }

            return(ms);
        }