Esempio n. 1
0
        public bool loadSubfile(odfFileSection section)
        {
            using (BinaryReader reader = ODFFormat.ReadFile(section, ODFPath))
            {
                switch (section.Type)
                {
                case odfSectionType.MAT: return(loadMAT(reader, section));

                case odfSectionType.MATA: return(loadMATA(reader, section));

                case odfSectionType.TEX: return(loadTEX(reader, section));

                case odfSectionType.MESH: return(loadMESH(reader, section));

                case odfSectionType.FRAM: return(loadFRAM(reader, section));

                case odfSectionType.ENVL: return(loadENVL(reader, section));

                case odfSectionType.MORP: return(loadMORP(reader, section));

                case odfSectionType.TXPT: return(loadTXPT(reader, section));

                case odfSectionType.ANIM: return(loadANIM(reader, section));

                case odfSectionType.BANM: return(loadBANM(reader, section));
                }
            }
            return(false);
        }
Esempio n. 2
0
        private bool loadMATA(BinaryReader reader, odfFileSection fileSec)
        {
            ObjectName     name        = new ObjectName(reader.ReadBytes(64));
            ObjectID       id          = new ObjectID(reader.ReadBytes(4));
            int            numMatLists = reader.ReadInt32();
            odfMATASection mataSec     = new odfMATASection(id, numMatLists);

            mataSec.Name = name;
            for (int i = 0; i < numMatLists; i++)
            {
                id = new ObjectID(reader.ReadBytes(4));
                float           unk1    = reader.ReadSingle();
                int             numSets = reader.ReadInt32();
                odfMaterialList matList = new odfMaterialList(numSets);
                matList.MaterialId = id;
                matList.Unknown1   = unk1;
                matList.Unknown2   = reader.ReadInt32();
                if (!loadMaterialPropertySets(reader, numSets, matList))
                {
                    return(false);
                }

                mataSec.AddChild(matList);
            }

            fileSec.Section = mataSec;
            MataSection     = mataSec;
            return(true);
        }
Esempio n. 3
0
        public static odfFrameSection ParseFrame(BinaryReader reader)
        {
            odfParser      parser  = new odfParser(String.Empty);
            odfFileSection fileSec = new odfFileSection(odfSectionType.FRAM, String.Empty);

            reader.BaseStream.Seek(4, SeekOrigin.Begin);
            fileSec.Size = reader.ReadInt32();
            return(parser.loadFRAM(reader, fileSec) ? parser.FrameSection : null);
        }
Esempio n. 4
0
        public static odfTextureSection ParseTextureList(BinaryReader reader)
        {
            odfParser      parser  = new odfParser(String.Empty);
            odfFileSection fileSec = new odfFileSection(odfSectionType.TEX, String.Empty);

            reader.BaseStream.Seek(4, SeekOrigin.Begin);
            fileSec.Size = reader.ReadInt32();
            return(parser.loadTEX(reader, fileSec) ? parser.TextureSection : null);
        }
Esempio n. 5
0
        public static odfMaterialSection ParseMaterialList(BinaryReader reader)
        {
            odfParser      parser  = new odfParser(String.Empty);
            odfFileSection fileSec = new odfFileSection(odfSectionType.MAT, String.Empty);

            reader.BaseStream.Seek(4, SeekOrigin.Begin);
            fileSec.Size = reader.ReadInt32();
            return(parser.loadMAT(reader, fileSec) ? parser.MaterialSection : null);
        }
Esempio n. 6
0
        private bool loadMAT(BinaryReader reader, odfFileSection fileSec)
        {
            int numMats = fileSec.Size / (64 + 4 + 18 * 4);
            odfMaterialSection matSec = new odfMaterialSection(numMats);

            if (!loadMaterials(reader, numMats, matSec))
            {
                return(false);
            }
            fileSec.Section = matSec;
            MaterialSection = matSec;
            return(true);
        }
Esempio n. 7
0
        private bool loadANIM(BinaryReader reader, odfFileSection fileSec)
        {
            ObjectName     name        = new ObjectName(reader.ReadBytes(64));
            ObjectID       id          = new ObjectID(reader.ReadBytes(4));
            int            numTracks   = reader.ReadInt32();
            odfANIMSection animSection = new odfANIMSection(id, numTracks);

            animSection.Name = name;
            ParseTracks(reader, numTracks, animSection);

            fileSec.Section = animSection;
            AnimSection     = animSection;
            return(true);
        }
Esempio n. 8
0
        private bool loadFRAM(BinaryReader reader, odfFileSection fileSec)
        {
            odfFrameSection objSection = new odfFrameSection();

            for (int secOffset = 0; secOffset < fileSec.Size; secOffset += 64 + 4 + 16 * 4 + 44 + 4 + 4 + 216 + 4 + 8 * 4 + 12 + 4 + 0x1FC + 4 + 8 + 4)
            {
                ObjectName name  = new ObjectName(reader.ReadBytes(64));
                ObjectID   id    = new ObjectID(reader.ReadBytes(4));
                odfFrame   frame = new odfFrame(name, id, 4);

                frame.Matrix       = reader.ReadMatrix();
                frame.AlwaysZero1  = reader.ReadBytes(44);
                frame.ParentId     = new ObjectID(reader.ReadBytes(4));
                frame.MeshId       = new ObjectID(reader.ReadBytes(4));
                frame.AlwaysZero2  = reader.ReadBytes(216);
                frame.Unknown3     = reader.ReadInt32();
                frame.Unknown4     = reader.ReadSingleArray(8);
                frame.Unknown5     = reader.ReadUInt32();
                frame.Unknown6     = reader.ReadInt32();
                frame.AlwaysZero7  = reader.ReadBytes(4);
                frame.Unknown8     = reader.ReadSingle();
                frame.AlwaysZero9  = reader.ReadBytes(0x1FC);
                frame.Unknown10    = reader.ReadSingle();
                frame.AlwaysZero11 = reader.ReadBytes(8);
                frame.Unknown12    = reader.ReadSingle();

                if (objSection.Count > 0)
                {
                    odfFrame parentFrame = odf.FindFrame(frame.ParentId, objSection.RootFrame);
                    if (parentFrame == null)
                    {
                        Console.WriteLine("Error in FRAM : ParentId " + frame.ParentId + " not found for frame " + frame.Name);
                        return(false);
                    }
                    else
                    {
                        parentFrame.AddChild(frame);
                    }
                }
                else
                {
                    objSection.AddChild(frame);
                }
            }

            fileSec.Section   = objSection;
            this.FrameSection = objSection;
            return(true);
        }
Esempio n. 9
0
        private bool loadTEX(BinaryReader reader, odfFileSection fileSec)
        {
            int TEXsize = 64 + 4 + 64;
            odfTextureSection texSec = new odfTextureSection(fileSec.Size / TEXsize);

            texSec._FormatType = 10;
            byte[] buffer = reader.ReadBytes(fileSec.Size);
            for (int secOffset = 0; secOffset < fileSec.Size; secOffset += TEXsize)
            {
                byte[] sub = new byte[64];
                Array.Copy(buffer, secOffset, sub, 0, 64);
                ObjectName name = new ObjectName(sub);
                sub = new byte[4];
                Array.Copy(buffer, secOffset + 64, sub, 0, 4);
                ObjectID   id  = new ObjectID(sub);
                odfTexture tex = new odfTexture(name, id, texSec._FormatType);
                sub = new byte[64];
                Array.Copy(buffer, secOffset + 64 + 4, sub, 0, 64);
                tex.TextureFile = new ObjectName(sub);
                if (secOffset == 0 && TEXsize < fileSec.Size)
                {
                    int notZero = 0;
                    for (int i = 64 + 4 + 64; i < 64 + 4 + 64 + 72; i++)
                    {
                        if (buffer[i] != 0 && ++notZero > 5)
                        {
                            break;
                        }
                    }
                    if (notZero <= 5)
                    {
                        texSec._FormatType = 9;
                        tex.Unknown1       = new byte[72];
                        TEXsize           += 72;
                    }
                }
                if (texSec._FormatType < 10)
                {
                    Array.Copy(buffer, secOffset + 64 + 4 + 64, tex.Unknown1, 0, 72);
                }

                texSec.AddChild(tex);
            }

            fileSec.Section     = texSec;
            this.TextureSection = texSec;
            return(true);
        }
Esempio n. 10
0
        public List <odfFileSection> ScanFile(string odfPath, int fileSize)
        {
            using (FileStream fs = testEncryption(odfPath))
            {
                List <odfFileSection> sectionList = new List <odfFileSection>();
                ICryptoTransform      trans       = null;
                Stream stream = fs;
                if (this.isEncrypted)
                {
                    trans  = CryptoTransform();
                    stream = (Stream) new CryptoStream(fs, trans, CryptoStreamMode.Read);
                }

                List <BinaryReader> usedReaders = new List <BinaryReader>(20);
                for (int addr = 12, length = (int)fs.Length; addr < length;)
                {
                    if (trans is CryptoTransformThreeChoices)
                    {
                        ((CryptoTransformThreeChoices)trans).keyOffset = addr;
                    }
                    fs.Seek(addr, SeekOrigin.Begin);

                    BinaryReader   reader  = new BinaryReader(stream);
                    odfFileSection section = new odfFileSection(odfFileSection.DecryptSectionType(reader.ReadBytes(4)), odfPath);
                    section.Size = reader.ReadInt32();
                    usedReaders.Add(reader);
                    section.Offset = addr + 4 + 4;

                    addr += 4 + 4 + section.Size;
                    if (section.Type == odfSectionType.BANM)
                    {
                        addr += 264;
                    }
                    sectionList.Add(section);
                }
                while (usedReaders.Count > 0)
                {
                    BinaryReader reader = usedReaders[0];
                    usedReaders.RemoveAt(0);
                    reader.Dispose();
                }

                return(sectionList);
            }
        }
Esempio n. 11
0
        public BinaryReader ReadFile(odfFileSection section, string odfPath)
        {
            int bufferSize = section.Size;

            if (bufferSize == 0)
            {
                return(null);
            }
            FileStream fs = null;

            try
            {
                fs = File.OpenRead(odfPath);
                fs.Seek(section.Offset, SeekOrigin.Begin);
                Stream stream = null;
                if (section.Type == odfSectionType.BANM)
                {
                    bufferSize += 264;
                }
                if (this.isEncrypted)
                {
                    ICryptoTransform trans = CryptoTransform();
                    if (trans is CryptoTransformThreeChoices)
                    {
                        ((CryptoTransformThreeChoices)trans).keyOffset = section.Offset;
                    }
                    stream = new CryptoStream(new BufferedStream(fs, bufferSize), trans, CryptoStreamMode.Read);
                }
                else
                {
                    stream = new BufferedStream(fs, bufferSize);
                }
                return(new BinaryReader(stream));
            }
            catch (Exception e)
            {
                if (fs != null)
                {
                    fs.Close();
                }
                throw e;
            }
        }
Esempio n. 12
0
        private bool loadBANM(BinaryReader reader, odfFileSection fileSec)
        {
            ObjectName     name        = new ObjectName(reader.ReadBytes(64));
            ObjectID       id          = new ObjectID(reader.ReadBytes(4));
            int            numTracks   = reader.ReadInt32();
            odfBANMSection banmSection = new odfBANMSection(id, numTracks);

            banmSection.Name = name;
            ParseTracks(reader, numTracks, banmSection);
            banmSection.AlwaysZeroName = new ObjectName(reader.ReadBytes(64));

            banmSection.Range.AlwaysZero252      = reader.ReadBytes(252);
            banmSection.Range.StartKeyframeIndex = reader.ReadSingle();
            banmSection.Range.EndKeyframeIndex   = reader.ReadSingle();
            banmSection.Range.AlwaysZero4        = reader.ReadBytes(4);

            fileSec.Section = banmSection;
            BANMList.Add(banmSection);
            return(true);
        }
Esempio n. 13
0
        private bool loadENVL(BinaryReader reader, odfFileSection fileSec)
        {
            ObjectID id = new ObjectID(reader.ReadBytes(4));

            byte[]             alwaysZero   = reader.ReadBytes(64);
            int                numEnvelopes = reader.ReadInt32();
            odfEnvelopeSection envSection   = new odfEnvelopeSection(numEnvelopes);

            envSection.Id           = id;
            envSection.AlwaysZero64 = alwaysZero;
            envSection._FormatType  = MeshSection != null ? MeshSection._FormatType : -1;
            for (int envIdx = 0; envIdx < numEnvelopes; envIdx++)
            {
                odfBoneList boneList = ParseBoneList(reader, envSection._FormatType);
                envSection.AddChild(boneList);
            }

            fileSec.Section = envSection;
            EnvelopeSection = envSection;
            return(true);
        }
Esempio n. 14
0
        private bool loadTXPT(BinaryReader reader, odfFileSection fileSec)
        {
            ObjectName     name         = new ObjectName(reader.ReadBytes(64));
            ObjectID       id           = new ObjectID(reader.ReadBytes(4));
            int            numTxPtLists = reader.ReadInt32();
            odfTXPTSection txptSection  = new odfTXPTSection(id, numTxPtLists);

            txptSection.Name = name;
            for (int txptListIdx = 0; txptListIdx < numTxPtLists; txptListIdx++)
            {
                id = new ObjectID(reader.ReadBytes(4));
                int[]       unk1         = reader.ReadInt32Array(4);
                int         numTxptInfos = reader.ReadInt32();
                int         unk2         = reader.ReadInt32();
                odfTxPtList txptList     = new odfTxPtList(numTxptInfos);
                txptList.MeshFrameId = id;
                txptList.Unknown1    = unk1;
                txptList.Unknown2    = unk2;
                for (int i = 0; i < numTxptInfos; i++)
                {
                    odfTxPt txptInfo = new odfTxPt();
                    txptInfo.Index        = reader.ReadSingle();
                    txptInfo.Value        = reader.ReadInt32();
                    txptInfo.AlwaysZero16 = reader.ReadBytes(16);
                    txptInfo.Prev         = reader.ReadInt32();
                    txptInfo.Next         = reader.ReadInt32();

                    txptList.TxPtList.Add(txptInfo);
                }

                txptSection.AddChild(txptList);
            }

            fileSec.Section = txptSection;
            TXPTSection     = txptSection;
            return(true);
        }
Esempio n. 15
0
        private bool loadMORP(BinaryReader reader, odfFileSection fileSec)
        {
            ObjectName      name            = new ObjectName(reader.ReadBytes(64));
            ObjectID        id              = new ObjectID(reader.ReadBytes(4));
            int             numMorphObjects = reader.ReadInt32();
            odfMorphSection morpSection     = new odfMorphSection(id, numMorphObjects);

            morpSection.Name = name;
            for (int morphObjIdx = 0; morphObjIdx < numMorphObjects; morphObjIdx++)
            {
                id = new ObjectID(reader.ReadBytes(4));
                byte[]         alwaysZero       = reader.ReadBytes(16);
                int            numSelectorInfos = reader.ReadInt32();
                int            numProfiles      = reader.ReadInt32();
                odfMorphObject morphObj         = new odfMorphObject(id, numSelectorInfos, numProfiles);
                morphObj.AlwaysZero16 = alwaysZero;
                morphObj.Name         = new ObjectName(reader.ReadBytes(64));

                morphObj.NumIndices     = reader.ReadInt32();
                morphObj.MeshIndices    = reader.ReadUInt16Array(morphObj.NumIndices);
                morphObj.UnknownIndices = reader.ReadInt32Array(morphObj.NumIndices);

                for (int idx = 0; idx < numProfiles; idx++)
                {
                    odfMorphProfile profile = new odfMorphProfile();
                    profile.VertexList = ParseVertexList(reader, morphObj.NumIndices);
                    profile.Name       = new ObjectName(reader.ReadBytes(64));

                    morphObj.AddChild(profile);
                }

                List <odfMorphSelector> selectorList = new List <odfMorphSelector>(numSelectorInfos);
                for (int idx = 0; idx < numSelectorInfos; idx++)
                {
                    odfMorphSelector selectorInfo = new odfMorphSelector();
                    selectorInfo.Threshold    = reader.ReadInt32();
                    selectorInfo.ProfileIndex = reader.ReadInt32();

                    selectorList.Add(selectorInfo);
                }
                morphObj.SelectorList = selectorList;

                morphObj.ClipType = reader.ReadInt32();
                if (morphObj.ClipType > 0)
                {
                    int numClipInfos             = reader.ReadInt32();
                    List <odfMorphClip> clipList = new List <odfMorphClip>(numClipInfos);
                    for (int idx = 0; idx < numClipInfos; idx++)
                    {
                        odfMorphClip clipInfo = new odfMorphClip();
                        clipInfo.StartIndex = reader.ReadInt32();
                        clipInfo.EndIndex   = reader.ReadInt32();
                        clipInfo.Unknown    = reader.ReadInt32();

                        clipList.Add(clipInfo);
                    }
                    morphObj.MorphClipList = clipList;
                }

                morphObj.MinusOne = reader.ReadInt32();
                morphObj.FrameId  = new ObjectID(reader.ReadBytes(4));

                morpSection.AddChild(morphObj);
            }

            fileSec.Section = morpSection;
            MorphSection    = morpSection;
            return(true);
        }
Esempio n. 16
0
        public List<odfFileSection> ScanFile(string odfPath, int fileSize)
        {
            using (FileStream fs = testEncryption(odfPath))
            {
                List<odfFileSection> sectionList = new List<odfFileSection>();
                ICryptoTransform trans = null;
                Stream stream = fs;
                if (this.isEncrypted)
                {
                    trans = CryptoTransform();
                    stream = (Stream)new CryptoStream(fs, trans, CryptoStreamMode.Read);
                }

                List<BinaryReader> usedReaders = new List<BinaryReader>(20);
                for (int addr = 12, length = (int)fs.Length; addr < length; )
                {
                    if (trans is CryptoTransformThreeChoices)
                    {
                        ((CryptoTransformThreeChoices)trans).keyOffset = addr;
                    }
                    fs.Seek(addr, SeekOrigin.Begin);

                    BinaryReader reader = new BinaryReader(stream);
                    odfFileSection section = new odfFileSection(odfFileSection.DecryptSectionType(reader.ReadBytes(4)), odfPath);
                    section.Size = reader.ReadInt32();
                    usedReaders.Add(reader);
                    section.Offset = addr + 4 + 4;

                    addr += 4 + 4 + section.Size;
                    if (section.Type == odfSectionType.BANM)
                    {
                        addr += 264;
                    }
                    sectionList.Add(section);
                }
                while (usedReaders.Count > 0)
                {
                    BinaryReader reader = usedReaders[0];
                    usedReaders.RemoveAt(0);
                    reader.Dispose();
                }

                return sectionList;
            }
        }
Esempio n. 17
0
        private bool loadMESH(BinaryReader reader, odfFileSection fileSec)
        {
            odfMeshSection meshSection = new odfMeshSection(0);

            meshSection._FormatType = 10;
            if (!reader.BaseStream.CanSeek)
            {
                byte[] buffer = reader.ReadBytes(fileSec.Size);
                reader = new BinaryReader(new MemoryStream(buffer));
            }
            for (int endPosition = (int)reader.BaseStream.Position + fileSec.Size; reader.BaseStream.Position < endPosition;)
            {
                ObjectName name         = new ObjectName(reader.ReadBytes(64));
                ObjectID   id           = new ObjectID(reader.ReadBytes(4));
                int        numSubmeshes = reader.ReadInt32();
                odfMesh    mesh         = new odfMesh(name, id, numSubmeshes);

                for (int submeshIdx = 0; submeshIdx < numSubmeshes; submeshIdx++)
                {
                    name = new ObjectName(reader.ReadBytes(64));
                    id   = new ObjectID(reader.ReadBytes(4));

                    int    unknown1    = reader.ReadInt32();
                    byte[] alwaysZero1 = reader.ReadBytes(4);

                    ObjectID   materialId = new ObjectID(reader.ReadBytes(4));
                    ObjectID[] texID      = new ObjectID[4];
                    for (int texIdx = 0; texIdx < 4; texIdx++)
                    {
                        texID[texIdx] = new ObjectID(reader.ReadBytes(4));
                    }

                    UInt32 unknown31 = reader.ReadUInt32();

                    byte[] alwaysZero2 = reader.ReadBytes(16);

                    int unknown3 = reader.ReadInt32();

                    byte[] numVertsOrUnknown       = reader.ReadBytes(4);
                    byte[] numVertIndicesOrUnknown = reader.ReadBytes(4);
                    int    unknown4                = reader.ReadInt32();
                    int    unknown5                = reader.ReadInt32();
                    byte[] unknownOrNumVerts       = reader.ReadBytes(4);
                    byte[] unknownOrNumVertIndices = reader.ReadBytes(4);

                    if (meshSection.Count == 0)
                    {
                        int numVerts      = BitConverter.ToInt32(numVertsOrUnknown, 0);
                        int numVertexIdxs = BitConverter.ToInt32(numVertIndicesOrUnknown, 0);
                        if (numVerts * numVertexIdxs == 0)
                        {
                            meshSection._FormatType = 9;
                        }
                    }
                    odfSubmesh submesh = new odfSubmesh(name, id, meshSection._FormatType);
                    submesh.Unknown1    = unknown1;
                    submesh.AlwaysZero1 = alwaysZero1;
                    submesh.MaterialId  = materialId;
                    submesh.TextureIds  = texID;
                    submesh.Unknown31   = unknown31;
                    submesh.AlwaysZero2 = alwaysZero2;
                    submesh.Unknown4    = unknown3;
                    submesh.Unknown5    = unknown4;
                    submesh.Unknown6    = unknown5;
                    int numVertices, numVertexIndices;
                    if (meshSection._FormatType < 10)
                    {
                        submesh.Unknown7    = BitConverter.ToInt32(numVertsOrUnknown, 0);
                        submesh.Unknown8    = numVertIndicesOrUnknown;
                        numVertices         = BitConverter.ToInt32(unknownOrNumVerts, 0);
                        numVertexIndices    = BitConverter.ToInt32(unknownOrNumVertIndices, 0);
                        submesh.AlwaysZero3 = reader.ReadBytes(448);
                    }
                    else
                    {
                        numVertices      = BitConverter.ToInt32(numVertsOrUnknown, 0);
                        numVertexIndices = BitConverter.ToInt32(numVertIndicesOrUnknown, 0);
                        submesh.Unknown7 = BitConverter.ToInt32(unknownOrNumVerts, 0);
                        submesh.Unknown8 = unknownOrNumVertIndices;
                    }

                    submesh.VertexList = ParseVertexList(reader, numVertices);
                    submesh.FaceList   = ParseFaceList(reader, numVertexIndices / 3);

                    submesh.AlwaysZero4 = reader.ReadBytes(24);

                    mesh.AddChild(submesh);
                }
                meshSection.AddChild(mesh);
            }

            fileSec.Section = meshSection;
            MeshSection     = meshSection;
            return(true);
        }
Esempio n. 18
0
 public BinaryReader ReadFile(odfFileSection section, string odfPath)
 {
     int bufferSize = section.Size;
     if (bufferSize == 0)
         return null;
     FileStream fs = null;
     try
     {
         fs = File.OpenRead(odfPath);
         fs.Seek(section.Offset, SeekOrigin.Begin);
         Stream stream = null;
         if (section.Type == odfSectionType.BANM)
             bufferSize += 264;
         if (this.isEncrypted)
         {
             ICryptoTransform trans = CryptoTransform();
             if (trans is CryptoTransformThreeChoices)
                 ((CryptoTransformThreeChoices)trans).keyOffset = section.Offset;
             stream = new CryptoStream(new BufferedStream(fs, bufferSize), trans, CryptoStreamMode.Read);
         }
         else
             stream = new BufferedStream(fs, bufferSize);
         return new BinaryReader(stream);
     }
     catch (Exception e)
     {
         if (fs != null)
         {
             fs.Close();
         }
         throw e;
     }
 }