public void Serialize(SerializingContainer Container, MEVersion version)
 {
     MaterialIndex = Container + MaterialIndex;
     ChunkIndex    = Container + ChunkIndex;
     BaseIndex     = Container + BaseIndex;
     NumTriangles  = Container + NumTriangles;
     if (version == MEVersion.ME3)
     {
         short s = 0;
         s = Container + s;
     }
 }
            public void Serialize(SerializingContainer Container, MEVersion version)
            {
                if (version == MEVersion.ME2)
                {
                    Position.X = Container + Position.X;
                    Position.Y = Container + Position.Y;
                    Position.Z = Container + Position.Z;
                }
                TangentX = Container + TangentX;
                TangentZ = Container + TangentZ;
                if (Container.isLoading)
                {
                    InfluenceBones   = new byte[4];
                    InfluenceWeights = new byte[4];
                }
                for (int i = 0; i < 4; i++)
                {
                    InfluenceBones[i] = Container + InfluenceBones[i];
                }
                for (int i = 0; i < 4; i++)
                {
                    InfluenceWeights[i] = Container + InfluenceWeights[i];
                }
                if (version == MEVersion.ME3)
                {
                    Position.X = Container + Position.X;
                    Position.Y = Container + Position.Y;
                    Position.Z = Container + Position.Z;
                }

                ushort sU = 0;
                ushort sV = 0;

                sU = Container + sU;
                sV = Container + sV;
                U  = HalfToFloat(sU);
                V  = HalfToFloat(sV);

                Normals  = UnpackNormal(TangentZ);
                Tangents = UnpackNormal(TangentX);
            }
        private void SerializeLODs(SerializingContainer Container)
        {
            int count = 0;

            if (!Container.isLoading)
            {
                count = LODModels.Count();
            }
            count = Container + count;
            // this is the actual number of lods but we only care about lod0 (and it prevents us from looking for other lods in ME1/ME2)
            // so we force count to 1.
            count = 1;
            if (Container.isLoading)
            {
                LODModels = new List <LODModelStruct>();
                for (int i = 0; i < count; i++)
                {
                    LODModels.Add(new LODModelStruct());
                }
            }
            for (int i = 0; i < count; i++)
            {
                LODModelStruct lod     = LODModels[i];
                MEVersion      version = MEVersion.ME1;
                if (Owner is ME2Package)
                {
                    version = MEVersion.ME2;
                }
                else if (Owner is ME3Package)
                {
                    version = MEVersion.ME3;
                }
                lod.Serialize(Container, version);
                LODModels[i] = lod;
            }
        }
            public void Serialize(SerializingContainer Container, MEVersion version)
            {
                //Sections
                int count = 0;

                if (!Container.isLoading)
                {
                    count = Sections.Count();
                }
                count = Container + count;
                if (Container.isLoading)
                {
                    Sections = new List <SectionStruct>();
                    for (int i = 0; i < count; i++)
                    {
                        Sections.Add(new SectionStruct());
                    }
                }
                for (int i = 0; i < count; i++)
                {
                    SectionStruct sec = Sections[i];
                    sec.Serialize(Container, version);
                    Sections[i] = sec;
                }
                //IndexBuffer
                if (Container.isLoading)
                {
                    IndexBuffer = new MultiSizeIndexContainerStruct();
                }
                IndexBuffer.Serialize(Container);
                //unk1
                Unk1 = Container + Unk1;
                if (Unk1 > 0)
                {
                    ushort[] indices = new ushort[Unk1];
                    for (int i = 0; i < Unk1; i++)
                    {
                        indices[i] = Container + indices[i];
                    }
                }
                //Active Bones
                int activeBonesCount = 0;

                if (!Container.isLoading)
                {
                    activeBonesCount = (short)ActiveBones.Count();
                }
                activeBonesCount = Container + activeBonesCount;
                if (Container.isLoading)
                {
                    ActiveBones = new List <ushort>();
                    for (int i = 0; i < activeBonesCount; i++)
                    {
                        ActiveBones.Add(0);
                    }
                }
                for (int i = 0; i < activeBonesCount; i++)
                {
                    ActiveBones[i] = Container + ActiveBones[i];
                }
                //unk2
                Unk2 = Container + Unk2;
                if (Unk2 > 0)
                {
                    byte[] f74 = new byte[Unk2];
                    for (int i = 0; i < Unk2; i++)
                    {
                        f74[i] = Container + f74[i];
                    }
                }
                //Chunks
                if (!Container.isLoading)
                {
                    count = Chunks.Count();
                }
                count = Container + count;
                if (Container.isLoading)
                {
                    Chunks = new List <SkelMeshChunkStruct>();
                    for (int i = 0; i < count; i++)
                    {
                        Chunks.Add(new SkelMeshChunkStruct());
                    }
                }
                for (int i = 0; i < count; i++)
                {
                    SkelMeshChunkStruct c = Chunks[i];
                    c.Serialize(Container);
                    Chunks[i] = c;
                }
                //Size
                Size = Container + Size;
                //NumVertices
                NumVertices = Container + NumVertices;
                //unk3
                Unk3 = Container + Unk3;
                if (Unk3 > 0)
                {
                    for (int i = 0; i < Unk3; i++)
                    {
                        int[] fedge3 = new int[4];
                        fedge3[0] = Container + fedge3[0];
                        fedge3[1] = Container + fedge3[1];
                        fedge3[2] = Container + fedge3[2];
                        fedge3[3] = Container + fedge3[3];
                    }
                }
                //RequiredBones (f24)
                if (!Container.isLoading)
                {
                    count = RequiredBones.Count();
                }
                count = Container + count;
                if (Container.isLoading)
                {
                    RequiredBones = new List <byte>();
                    for (int i = 0; i < count; i++)
                    {
                        RequiredBones.Add(0);
                    }
                }
                for (int i = 0; i < count; i++)
                {
                    RequiredBones[i] = Container + RequiredBones[i];
                }
                //RawPointIndicesFlag
                RawPointIndicesFlag = Container + RawPointIndicesFlag;
                //RawPointIndicesCount
                RawPointIndicesCount = Container + RawPointIndicesCount;
                RawPointIndices      = new List <ushort>();
                if (RawPointIndicesCount > 0)
                {
                    //RawPointIndices
                    if (Container.isLoading)
                    {
                        for (int i = 0; i < RawPointIndicesCount; i++)
                        {
                            RawPointIndices.Add(0);
                        }
                    }
                    for (int i = 0; i < RawPointIndicesCount; i++)
                    {
                        RawPointIndices[i] = Container + RawPointIndices[i];
                    }
                }
                //RawPointIndicesSize
                RawPointIndicesSize = Container + RawPointIndicesSize;
                //RawPointIndicesOffset
                RawPointIndicesOffset = Container + RawPointIndicesOffset;

                //VertexBufferGPUSkin
                if (Container.isLoading)
                {
                    VertexBufferGPUSkin = new VertexBufferGPUSkinStruct();
                }

                VertexBufferGPUSkin.Serialize(Container, version);

                //unk4
                Unk4 = Container + Unk4;
            }
            public void Serialize(SerializingContainer Container, MEVersion version)
            {
                //NumTexCoords
                NumTexCoords = 1;

                if (version == MEVersion.ME1)
                {
                    //VertexSize
                    VertexSize = Container + VertexSize;

                    Vertices = new List <GPUSkinVertexStruct>();
                    int VertsCount = 0;
                    VertsCount = Container + VertsCount;
                    for (int i = 0; i < VertsCount; i++)
                    {
                        var aSoftVert = new SoftSkinVertexStruct();
                        aSoftVert.Serialize(Container);
                        GPUSkinVertexStruct gpuv = new GPUSkinVertexStruct(aSoftVert);
                        Vertices.Add(gpuv);
                    }
                    UseFullPrecisionUVs = 1;
                    return;
                }

                ////UseFullPrecisionUVs
                UseFullPrecisionUVs = Container + UseFullPrecisionUVs;
                if (version == MEVersion.ME3)
                {
                    ////UsePackedPosition
                    UsePackedPosition = Container + UsePackedPosition;
                    //Extension
                    Extension.X = Container + Extension.X;
                    Extension.Y = Container + Extension.Y;
                    Extension.Z = Container + Extension.Z;
                    //origin
                    Origin.X = Container + Origin.X;
                    Origin.Y = Container + Origin.Y;
                    Origin.Z = Container + Origin.Z;
                }

                //vertexsize
                VertexSize = Container + VertexSize;
                int count = 0;

                if (!Container.isLoading)
                {
                    count = Vertices.Count();
                }
                count = Container + count;
                if (Container.isLoading)
                {
                    Vertices = new List <GPUSkinVertexStruct>();
                    for (int i = 0; i < count; i++)
                    {
                        Vertices.Add(new GPUSkinVertexStruct());
                    }
                }
                int VertexDiff = VertexSize - 32;

                for (int i = 0; i < count; i++)
                {
                    GPUSkinVertexStruct v = Vertices[i];
                    v.Serialize(Container, version);

                    if (VertexDiff > 0)
                    {
                        byte b = 0;
                        for (int j = 0; j < VertexDiff; j++)
                        {
                            b = Container + b;
                        }
                    }
                    Vertices[i] = v;
                }
            }