Example #1
0
 public static void WriteName(this BinaryWriter writer, string name)
 {
     byte[] nameBuf = Utility.EncryptName(name);
     writer.Write(nameBuf.Length);
     writer.Write(nameBuf);
 }
Example #2
0
 public static void WriteNameWithoutLength(this BinaryWriter writer, string name, int length)
 {
     byte[] nameBuf = Utility.EncryptName(name, length);
     writer.Write(nameBuf);
 }
Example #3
0
        protected xxFrame ParseFrame()
        {
            xxFrame frame = new xxFrame();

            frame.Name = reader.ReadName();

            int numChildFrames = reader.ReadInt32();

            frame.InitChildren(numChildFrames);

            frame.Matrix   = reader.ReadMatrix();
            frame.Unknown1 = (Format >= 7) ? reader.ReadBytes(32) : reader.ReadBytes(16);

            int numSubmeshes = reader.ReadInt32();

            frame.Bounds   = new BoundingBox(reader.ReadVector3(), reader.ReadVector3());
            frame.Unknown2 = (Format >= 7) ? reader.ReadBytes(64) : reader.ReadBytes(16);

            if (Format >= 6)
            {
                frame.Name2 = reader.ReadName();
            }

            if (numSubmeshes > 0)
            {
                xxMesh mesh = new xxMesh();
                frame.Mesh = mesh;
                mesh.NumVector2PerVertex = reader.ReadByte();

                mesh.SubmeshList = new List <xxSubmesh>(numSubmeshes);
                for (int i = 0; i < numSubmeshes; i++)
                {
                    xxSubmesh submesh = new xxSubmesh();
                    mesh.SubmeshList.Add(submesh);

                    submesh.Unknown1      = (Format >= 7) ? reader.ReadBytes(64) : reader.ReadBytes(16);
                    submesh.MaterialIndex = reader.ReadInt32();

                    submesh.FaceList   = ParseFaceList();
                    submesh.VertexList = ParseVertexList();

                    if (Format >= 7)
                    {
                        submesh.Unknown2 = reader.ReadBytes(20);
                    }

                    if (mesh.NumVector2PerVertex > 0)
                    {
                        submesh.Vector2Lists = new List <List <Vector2> >(submesh.VertexList.Count);
                        for (int j = 0; j < submesh.VertexList.Count; j++)
                        {
                            List <Vector2> vectorList = new List <Vector2>(mesh.NumVector2PerVertex);
                            submesh.Vector2Lists.Add(vectorList);
                            for (byte k = 0; k < mesh.NumVector2PerVertex; k++)
                            {
                                vectorList.Add(reader.ReadVector2());
                            }
                        }
                    }

                    if (Format >= 2)
                    {
                        submesh.Unknown3 = reader.ReadBytes(100);                         // 96 + 4
                    }

                    if (Format >= 7)
                    {
                        submesh.Unknown4 = reader.ReadBytes(284);                         // 256 + 28

                        if (Format >= 8)
                        {
                            byte   format    = reader.ReadByte();
                            string nullFrame = reader.ReadName();
                            byte[] u5end     = reader.ReadBytes(12 + 4);

                            byte[] encryptedName = Utility.EncryptName(nullFrame);
                            submesh.Unknown5    = new byte[1 + 4 + encryptedName.Length + 12 + 4];
                            submesh.Unknown5[0] = format;
                            BitConverter.GetBytes(encryptedName.Length).CopyTo(submesh.Unknown5, 1);
                            encryptedName.CopyTo(submesh.Unknown5, 1 + 4);
                            u5end.CopyTo(submesh.Unknown5, 1 + 4 + encryptedName.Length);
                        }
                    }
                    else
                    {
                        if (Format >= 3)
                        {
                            submesh.Unknown4 = reader.ReadBytes(64);
                        }
                        if (Format >= 5)
                        {
                            submesh.Unknown5 = reader.ReadBytes(20);
                        }
                        if (Format >= 6)
                        {
                            submesh.Unknown6 = reader.ReadBytes(28);
                        }
                    }
                }

                ushort numVerticesDup = reader.ReadUInt16();
                mesh.VertexListDuplicate        = new List <xxVertex>(numVerticesDup);
                mesh.VertexListDuplicateUnknown = reader.ReadBytes(8);                  // 4 + 4
                for (int i = 0; i < numVerticesDup; i++)
                {
                    mesh.VertexListDuplicate.Add(ParseVertex());
                }

                mesh.BoneList = ParseBoneList();
            }

            for (int i = 0; i < numChildFrames; i++)
            {
                frame.AddChild(ParseFrame());
            }

            return(frame);
        }