public MaterialMaterialEntry FIllMatMatEntryPropertiesPart1(MaterialMaterialEntry MME, MaterialEntry ParentMat, BinaryReader bnr, int OffsetToStart, int ID)
        {
            MME.Index    = ID;
            MME.TypeHash = ByteUtilitarian.BytesToStringL2R(bnr.ReadBytes(4).ToList(), MME.TypeHash);

            //Gets the Material type.
            MME.MatType = CFGHandler.ArchiveHashToName(MME.MatType, MME.TypeHash);

            MME.UnknownField04 = bnr.ReadInt32();
            byte[] NameHashBytes = bnr.ReadBytes(4);
            MME.NameHash = ByteUtilitarian.BytesToStringL2R(NameHashBytes.ToList(), MME.TypeHash);
            NameTemp     = BitConverter.ToUInt32(NameHashBytes, 0);

            //ShaderObjects.
            MME.BlendState        = new MatShaderObject();
            MME.DepthStencilState = new MatShaderObject();
            MME.RasterizerState   = new MatShaderObject();
            MME.CmdBufferSize     = bnr.ReadInt32();

            byte[] ShadeTemp = new byte[4];
            ShadeTemp = bnr.ReadBytes(4);
            uint ShadeUInt = BitConverter.ToUInt32(ShadeTemp, 0);

            MME.BlendState.Index = ShadeUInt & 0x00000FFF;
            MME.BlendState.Hash  = "";
            MME.BlendState.Hash  = CFGHandler.ShaderHashToName(MME.BlendState.Hash, Convert.ToInt32(MME.BlendState.Index));

            ShadeTemp = bnr.ReadBytes(4);
            ShadeUInt = BitConverter.ToUInt32(ShadeTemp, 0);
            MME.DepthStencilState.Index = ShadeUInt & 0x00000FFF;
            MME.DepthStencilState.Hash  = "";
            MME.DepthStencilState.Hash  = CFGHandler.ShaderHashToName(MME.DepthStencilState.Hash, Convert.ToInt32(MME.DepthStencilState.Index));


            ShadeTemp = bnr.ReadBytes(4);
            ShadeUInt = BitConverter.ToUInt32(ShadeTemp, 0);
            MME.RasterizerState.Index   = (ShadeUInt & 0x00000FFF);
            MME.RasterizerState.Hash    = "";
            MME.RasterizerState.Hash    = CFGHandler.ShaderHashToName(MME.RasterizerState.Hash, Convert.ToInt32(MME.RasterizerState.Index));
            MME.MaterialCommandListInfo = new MaterialCmdListInfo();

            //The Material Command List Info.
            ShadeTemp = bnr.ReadBytes(4);
            ShadeUInt = BitConverter.ToUInt32(ShadeTemp, 0);
            MME.MaterialCommandListInfo.Count   = Convert.ToInt32(ShadeUInt & 0xFFF);
            MME.MaterialCommandListInfo.Unknown = Convert.ToInt32(ShadeUInt & 0xFFFF000);
            MME.MaterialinfoFlags = ByteUtilitarian.BytesToStringL2R(bnr.ReadBytes(4).ToList(), MME.MaterialinfoFlags);
            MME.UnknownField24    = bnr.ReadInt32();
            MME.UnknownField28    = bnr.ReadInt32();
            MME.UnknownField2C    = bnr.ReadInt32();
            MME.UnknownField30    = bnr.ReadInt32();
            MME.AnimDataSize      = bnr.ReadInt32();
            MME.CmdListOffset     = Convert.ToInt32(bnr.ReadInt64());
            MME.AnimDataOffset    = Convert.ToInt32(bnr.ReadInt64());
            OffsetToStart         = Convert.ToInt32(bnr.BaseStream.Position);

            return(MME);
        }
        public static MaterialEntry BuildMatEntry(BinaryReader MBR, MaterialEntry MATEntry)
        {
            //Header variables.
            MATEntry.Magic          = ByteUtilitarian.BytesToStringL2R(MBR.ReadBytes(4).ToList(), MATEntry.Magic);
            MATEntry.SomethingCount = MBR.ReadInt32();
            MATEntry.MaterialCount  = MBR.ReadInt32();
            MATEntry.TextureCount   = MBR.ReadInt32();
            MATEntry.WeirdHash      = ByteUtilitarian.BytesToStringL2R(MBR.ReadBytes(4).ToList(), MATEntry.Magic);
            MATEntry.Field14        = MBR.ReadInt32();
            MATEntry.TextureOffset  = MBR.ReadInt32();
            MBR.BaseStream.Position = MBR.BaseStream.Position + 4;
            MATEntry.MaterialOffset = MBR.ReadInt32();
            MBR.BaseStream.Position = MBR.BaseStream.Position + 4;

            //For the Texture References.
            MATEntry.Textures       = new List <MaterialTextureReference>();
            MBR.BaseStream.Position = MATEntry.TextureOffset;
            for (int i = 0; i < MATEntry.TextureCount; i++)
            {
                MaterialTextureReference TexTemp = new MaterialTextureReference();
                TexTemp = TexTemp.FillMaterialTexReference(MATEntry, i, MBR, TexTemp);
                MATEntry.Textures.Add(TexTemp);
            }

            //Now for the Materials themselves.

            MATEntry.Materials = new List <MaterialMaterialEntry>();
            byte[] ShadeTemp  = new byte[4];
            int    PrevOffset = Convert.ToInt32(MBR.BaseStream.Position);

            //uint ShadeUInt;
            //byte[] NameHashBytes;
            //uint NameTemp;


            //Part 1 of Materials.
            for (int i = 0; i < MATEntry.MaterialCount; i++)
            {
                MaterialMaterialEntry MMEntry = new MaterialMaterialEntry();
                MMEntry = MMEntry.FIllMatMatEntryPropertiesPart1(MMEntry, MATEntry, MBR, PrevOffset, i);
                MMEntry = MMEntry.FIllMatMatEntryPropertiesPart2(MMEntry, MATEntry, MBR, PrevOffset, i);

                MATEntry.Materials.Add(MMEntry);
                PrevOffset = PrevOffset + 72;
                MBR.BaseStream.Position = PrevOffset;
            }

            return(MATEntry);
        }
        public MaterialTextureReference FillMaterialTexReference(MaterialEntry Mat, int ID, BinaryReader bnr, MaterialTextureReference texref)
        {
            //Typehash.
            texref.TypeHash       = ByteUtilitarian.BytesToStringL2R(bnr.ReadBytes(4).ToList(), texref.TypeHash);
            texref.UnknownParam04 = bnr.ReadInt32();
            texref.UnknownParam08 = bnr.ReadInt32();
            texref.UnknownParam0C = bnr.ReadInt32();
            texref.UnknownParam10 = bnr.ReadInt32();
            texref.UnknownParam14 = bnr.ReadInt32();
            //Name.
            texref.FullTexName = Encoding.ASCII.GetString(bnr.ReadBytes(64)).Trim('\0');
            texref.Index       = ID + 1;

            return(texref);
        }
        public static EffectListEntry BuildEffectListEntry(BinaryReader bnr, EffectListEntry eflentry)
        {
            //Specific file type work goes here!
            int ID = 0;

            //Header Stuff.
            eflentry.Magic       = ByteUtilitarian.BytesToString(bnr.ReadBytes(4), eflentry.Magic);
            eflentry.Version     = bnr.ReadInt32();
            eflentry.FileSize    = bnr.ReadInt32();
            eflentry.FPS         = Convert.ToInt32(bnr.ReadSingle());
            eflentry.EntryCountA = bnr.ReadInt16();
            eflentry.EntryCountB = bnr.ReadInt16();
            eflentry.CountXor    = bnr.ReadInt32();
            eflentry.Unknown18   = bnr.ReadInt32();
            eflentry.Unknown1C   = bnr.ReadInt32();
            eflentry.Buffer10    = bnr.ReadInt32();
            eflentry.Buffer11    = bnr.ReadInt32();
            eflentry.Buffer12    = bnr.ReadInt32();
            eflentry.Buffer13    = bnr.ReadInt32();

            eflentry.Effects = new List <EffectNode>();
            int PrevOffset = Convert.ToInt32(bnr.BaseStream.Position);
            int Iterator   = 0;

            try
            {
                for (int i = 0; i < eflentry.EntryCountA; i++)
                {
                    EffectNode fx = new EffectNode();
                    fx = EffectNode.BuildEffect(fx, i, bnr, eflentry, PrevOffset);
                    eflentry.Effects.Add(fx);
                    ID++;
                    PrevOffset = PrevOffset + 4;
                    bnr.BaseStream.Position = PrevOffset;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("The efl at index: " + ID + " inside the file\n" + eflentry.TrueName + " threw out an error.\nAs long as you do not modify the named file you should be able to save changes made to other files inside this arc and the file will not be modified.", "Uh-Oh");
            }


            return(eflentry);
        }
Beispiel #5
0
        public static ChainListEntry InsertChainListEntry(TreeView tree, ArcEntryWrapper node, string filename, Type filetype = null)
        {
            ChainListEntry clstentry = new ChainListEntry();

            InsertEntry(tree, node, filename, clstentry);

            clstentry.DecompressedFileLength = clstentry.UncompressedData.Length;
            clstentry._DecompressedFileLength = clstentry.UncompressedData.Length;
            clstentry.CompressedFileLength = clstentry.CompressedData.Length;
            clstentry._CompressedFileLength = clstentry.CompressedData.Length;
            clstentry._FileName = clstentry.TrueName;
            clstentry.EntryName = clstentry.FileName;

            clstentry.TypeHash = "326F732E";

            //Type specific work here.
            using (MemoryStream CslStream = new MemoryStream(clstentry.UncompressedData))
            {
                using (BinaryReader bnr = new BinaryReader(CslStream))
                {

                    bnr.BaseStream.Position = 4;
                    clstentry.Unknown04 = bnr.ReadInt32();
                    clstentry.TotalEntrySize = bnr.ReadInt32();
                    clstentry.CHNEntryCount = bnr.ReadInt32();
                    clstentry.CCLEntryCount = bnr.ReadInt32();

                    clstentry.ChainEntries = new List<CHNEntry>();
                    clstentry.ChainCollEntries = new List<CCLEntry>();

                    for (int g = 0; g < clstentry.CHNEntryCount; g++)
                    {
                        CHNEntry cHN = new CHNEntry();
                        cHN.FullPath = Encoding.ASCII.GetString(bnr.ReadBytes(64)).Trim('\0');
                        cHN.TypeHash = ByteUtilitarian.BytesToStringL2R(bnr.ReadBytes(4).ToList(), cHN.TypeHash);

                        try
                        {
                            using (var sr = new StreamReader("archive_filetypes.cfg"))
                            {
                                while (!sr.EndOfStream)
                                {
                                    var keyword = Console.ReadLine() ?? cHN.TypeHash;
                                    var line = sr.ReadLine();
                                    if (String.IsNullOrEmpty(line)) continue;
                                    if (line.IndexOf(keyword, StringComparison.CurrentCultureIgnoreCase) >= 0)
                                    {
                                        cHN.FileExt = line;
                                        cHN.FileExt = cHN.FileExt.Split(' ')[1];
                                        cHN.TotalName = cHN.FullPath + cHN.FileExt;
                                        break;
                                    }
                                }
                            }

                        }
                        catch (FileNotFoundException)
                        {
                            MessageBox.Show("I cannot find archive_filetypes.cfg so I cannot finish parsing the arc.", "Oh Boy");
                            using (StreamWriter sw = File.AppendText("Log.txt"))
                            {
                                sw.WriteLine("Cannot find archive_filetypes.cfg and thus cannot continue parsing.");
                            }
                            return null;
                        }

                        clstentry.ChainEntries.Add(cHN);
                        bnr.BaseStream.Position = bnr.BaseStream.Position + 16;
                    }

                    for (int h = 0; h < clstentry.CCLEntryCount; h++)
                    {
                        CCLEntry cCL = new CCLEntry();
                        cCL.FullPath = Encoding.ASCII.GetString(bnr.ReadBytes(64)).Trim('\0');
                        cCL.TypeHash = ByteUtilitarian.BytesToStringL2R(bnr.ReadBytes(4).ToList(), cCL.TypeHash);

                        try
                        {
                            using (var sr = new StreamReader("archive_filetypes.cfg"))
                            {
                                while (!sr.EndOfStream)
                                {
                                    var keyword = Console.ReadLine() ?? cCL.TypeHash;
                                    var line = sr.ReadLine();
                                    if (String.IsNullOrEmpty(line)) continue;
                                    if (line.IndexOf(keyword, StringComparison.CurrentCultureIgnoreCase) >= 0)
                                    {
                                        cCL.FileExt = line;
                                        cCL.FileExt = cCL.FileExt.Split(' ')[1];
                                        cCL.TotalName = cCL.FullPath + cCL.FileExt;
                                        break;
                                    }
                                }
                            }

                        }
                        catch (FileNotFoundException)
                        {
                            MessageBox.Show("I cannot find archive_filetypes.cfg so I cannot finish parsing the arc.", "Oh Boy");
                            using (StreamWriter sw = File.AppendText("Log.txt"))
                            {
                                sw.WriteLine("Cannot find archive_filetypes.cfg and thus cannot continue parsing.");
                            }
                            return null;
                        }

                        clstentry.ChainCollEntries.Add(cCL);
                    }

                }
            }

            clstentry.TextBackup = new List<string>();

            return clstentry;
        }
Beispiel #6
0
        public static ChainListEntry ReplaceCST(TreeView tree, ArcEntryWrapper node, string filename, Type filetype = null)
        {
            ChainListEntry cstnentry = new ChainListEntry();
            ChainListEntry cstoldentry = new ChainListEntry();

            tree.BeginUpdate();

            //Gotta Fix this up then test insert and replacing.
            try
            {
                using (BinaryReader br = new BinaryReader(File.OpenRead(filename)))
                {

                    ReplaceKnownEntry(tree, node, filename, cstnentry, cstoldentry);

                    cstnentry._FileName = cstnentry.TrueName;
                    cstnentry._DecompressedFileLength = cstnentry.UncompressedData.Length;
                    cstnentry._CompressedFileLength = cstnentry.CompressedData.Length;

                    cstnentry.TypeHash = "326F732E";

                    //Type specific work here.
                    using (MemoryStream CslStream = new MemoryStream(cstnentry.UncompressedData))
                    {
                        using (BinaryReader bnr = new BinaryReader(CslStream))
                        {

                            bnr.BaseStream.Position = 4;
                            cstnentry.Unknown04 = bnr.ReadInt32();
                            cstnentry.TotalEntrySize = bnr.ReadInt32();
                            cstnentry.CHNEntryCount = bnr.ReadInt32();
                            cstnentry.CCLEntryCount = bnr.ReadInt32();

                            cstnentry.ChainEntries = new List<CHNEntry>();
                            cstnentry.ChainCollEntries = new List<CCLEntry>();

                            for (int g = 0; g < cstnentry.CHNEntryCount; g++)
                            {
                                CHNEntry cHN = new CHNEntry();
                                cHN.FullPath = Encoding.ASCII.GetString(bnr.ReadBytes(64)).Trim('\0');
                                cHN.TypeHash = ByteUtilitarian.BytesToStringL2R(bnr.ReadBytes(4).ToList(), cHN.TypeHash);

                                try
                                {
                                    using (var sr = new StreamReader("archive_filetypes.cfg"))
                                    {
                                        while (!sr.EndOfStream)
                                        {
                                            var keyword = Console.ReadLine() ?? cHN.TypeHash;
                                            var line = sr.ReadLine();
                                            if (String.IsNullOrEmpty(line)) continue;
                                            if (line.IndexOf(keyword, StringComparison.CurrentCultureIgnoreCase) >= 0)
                                            {
                                                cHN.FileExt = line;
                                                cHN.FileExt = cHN.FileExt.Split(' ')[1];
                                                cHN.TotalName = cHN.FullPath + cHN.FileExt;
                                                break;
                                            }
                                        }
                                    }

                                }
                                catch (FileNotFoundException)
                                {
                                    MessageBox.Show("I cannot find archive_filetypes.cfg so I cannot finish parsing the arc.", "Oh Boy");
                                    using (StreamWriter sw = File.AppendText("Log.txt"))
                                    {
                                        sw.WriteLine("Cannot find archive_filetypes.cfg and thus cannot continue parsing.");
                                    }
                                    return null;
                                }

                                cstnentry.ChainEntries.Add(cHN);
                                bnr.BaseStream.Position = bnr.BaseStream.Position + 16;
                            }

                            for (int h = 0; h < cstnentry.CCLEntryCount; h++)
                            {
                                CCLEntry cCL = new CCLEntry();
                                cCL.FullPath = Encoding.ASCII.GetString(bnr.ReadBytes(64)).Trim('\0');
                                cCL.TypeHash = ByteUtilitarian.BytesToStringL2R(bnr.ReadBytes(4).ToList(), cCL.TypeHash);

                                try
                                {
                                    using (var sr = new StreamReader("archive_filetypes.cfg"))
                                    {
                                        while (!sr.EndOfStream)
                                        {
                                            var keyword = Console.ReadLine() ?? cCL.TypeHash;
                                            var line = sr.ReadLine();
                                            if (String.IsNullOrEmpty(line)) continue;
                                            if (line.IndexOf(keyword, StringComparison.CurrentCultureIgnoreCase) >= 0)
                                            {
                                                cCL.FileExt = line;
                                                cCL.FileExt = cCL.FileExt.Split(' ')[1];
                                                cCL.TotalName = cCL.FullPath + cCL.FileExt;
                                                break;
                                            }
                                        }
                                    }

                                }
                                catch (FileNotFoundException)
                                {
                                    MessageBox.Show("I cannot find archive_filetypes.cfg so I cannot finish parsing the arc.", "Oh Boy");
                                    using (StreamWriter sw = File.AppendText("Log.txt"))
                                    {
                                        sw.WriteLine("Cannot find archive_filetypes.cfg and thus cannot continue parsing.");
                                    }
                                    return null;
                                }

                                cstnentry.ChainCollEntries.Add(cCL);
                            }

                        }
                    }

                    cstnentry.TextBackup = new List<string>();


                    //Hmmm.

                    var tag = node.Tag;
                    if (tag is ChainListEntry)
                    {
                        cstoldentry = tag as ChainListEntry;
                    }
                    string path = "";
                    int index = cstoldentry.EntryName.LastIndexOf("\\");
                    if (index > 0)
                    {
                        path = cstoldentry.EntryName.Substring(0, index);
                    }

                    cstnentry.EntryName = path + "\\" + cstnentry.TrueName;

                    tag = cstnentry;

                    if (node.Tag is ChainListEntry)
                    {
                        node.Tag = cstnentry;
                        node.Name = Path.GetFileNameWithoutExtension(cstnentry.EntryName);
                        node.Text = Path.GetFileNameWithoutExtension(cstnentry.EntryName);

                    }

                    var aew = node as ArcEntryWrapper;

                    string type = node.GetType().ToString();
                    if (type == "ThreeWorkTool.Resources.Wrappers.ArcEntryWrapper")
                    {
                        aew.entryfile = cstnentry;
                    }

                    node = aew;
                    node.entryfile = cstnentry;
                    tree.EndUpdate();

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Read error. Is the file readable?");
                using (StreamWriter sw = File.AppendText("Log.txt"))
                {
                    sw.WriteLine("Read error. Cannot access the file:" + filename + "\n" + ex);
                }
            }



            return node.entryfile as ChainListEntry;
        }
        public static LMTM3AEntry ReplaceLMTM3AEntry(TreeView tree, ArcEntryWrapper node, string filename, Type filetype = null)
        {
            LMTM3AEntry m3aentry = new LMTM3AEntry();
            LMTM3AEntry oldentry = new LMTM3AEntry();

            tree.BeginUpdate();

            var tag = node.Tag;

            if (tag is LMTM3AEntry)
            {
                oldentry = tag as LMTM3AEntry;
            }

            //Builds the ma3entry.
            m3aentry._FileType   = ".m3a";
            m3aentry.FileExt     = m3aentry._FileType;
            m3aentry.FullData    = System.IO.File.ReadAllBytes(filename);
            m3aentry.AnimationID = oldentry.AnimationID;
            m3aentry.FileName    = oldentry.FileName;
            m3aentry.ShortName   = oldentry.ShortName;
            m3aentry._IsBlank    = false;

            using (MemoryStream MAThreeStream = new MemoryStream(m3aentry.FullData))
            {
                using (BinaryReader bnr = new BinaryReader(MAThreeStream))
                {
                    if (bnr.BaseStream.Length < 5)
                    {
                        MessageBox.Show("The entry you are trying to import is a blank one,\nso the replace command has been aborted.", "We have a problem here.");
                        return(null);
                    }


                    int projdatlength = m3aentry.FullData.Length - 96;
                    m3aentry.RawData = new byte[(projdatlength)];
                    Array.Copy(m3aentry.FullData, 0, m3aentry.RawData, 0, projdatlength);
                    m3aentry.MotionData = new byte[96];
                    projdatlength       = m3aentry.FullData.Length - 96;
                    Array.Copy(m3aentry.FullData, projdatlength, m3aentry.MotionData, 0, 96);
                    bnr.BaseStream.Position = (bnr.BaseStream.Length - 96);

                    m3aentry.TrackPointer   = bnr.ReadInt32();
                    bnr.BaseStream.Position = bnr.BaseStream.Position + 4;
                    m3aentry.TrackCount     = bnr.ReadInt32();
                    m3aentry.FrameCount     = bnr.ReadInt32();
                    m3aentry._FrameTotal    = m3aentry.FrameCount;
                    m3aentry.IsBlank        = false;
                    m3aentry.LoopFrame      = bnr.ReadInt32();

                    m3aentry.UnknownValue14 = ByteUtilitarian.BytesToString(bnr.ReadBytes(4), m3aentry.UnknownValue14);
                    m3aentry.UnknownValue18 = ByteUtilitarian.BytesToString(bnr.ReadBytes(4), m3aentry.UnknownValue18);
                    m3aentry.UnknownValue1C = ByteUtilitarian.BytesToString(bnr.ReadBytes(4), m3aentry.UnknownValue1C);

                    m3aentry.EndFramesAdditiveScenePosition.W = bnr.ReadSingle();
                    m3aentry.EndFramesAdditiveScenePosition.X = bnr.ReadSingle();
                    m3aentry.EndFramesAdditiveScenePosition.Y = bnr.ReadSingle();
                    m3aentry.EndFramesAdditiveScenePosition.Z = bnr.ReadSingle();

                    m3aentry.EndFramesAdditiveSceneRotation.W = bnr.ReadSingle();
                    m3aentry.EndFramesAdditiveSceneRotation.X = bnr.ReadSingle();
                    m3aentry.EndFramesAdditiveSceneRotation.Y = bnr.ReadSingle();
                    m3aentry.EndFramesAdditiveSceneRotation.Z = bnr.ReadSingle();

                    m3aentry.AnimationFlags = bnr.ReadInt64();

                    m3aentry.EventClassesPointer = bnr.ReadInt32();

                    //m3aentry.EventClassesPointer = bnr.ReadInt32();
                    //bnr.BaseStream.Position = bnr.BaseStream.Position + 4;

                    m3aentry.AnimDataSize = (m3aentry.EventClassesPointer - m3aentry.TrackPointer) + 352;


                    m3aentry.AnimDataSize       = m3aentry.FullData.Length - 448;
                    m3aentry.FloatTracksPointer = bnr.ReadInt32();
                    bnr.BaseStream.Position     = bnr.BaseStream.Position + 4;

                    m3aentry.Unknown58 = bnr.ReadInt32();
                    m3aentry.Unknown5C = bnr.ReadSingle();

                    m3aentry.PrevOffsetThree = Convert.ToInt32(bnr.BaseStream.Position);
                    bnr.BaseStream.Position  = m3aentry.TrackPointer;
                    m3aentry.RawData         = new byte[m3aentry.AnimDataSize];
                    Array.Copy(m3aentry.FullData, m3aentry.RawData, m3aentry.AnimDataSize);
                    m3aentry.MotionData     = new byte[96];
                    bnr.BaseStream.Position = (m3aentry.FullData.Length - 96);
                    m3aentry.MotionData     = bnr.ReadBytes(96);
                    bnr.BaseStream.Position = m3aentry.PrevOffsetThree;

                    //Gets the Tracks.
                    m3aentry.Tracks         = new List <Track>();
                    bnr.BaseStream.Position = 0;

                    for (int j = 0; j < m3aentry.TrackCount; j++)
                    {
                        Track track = new Track();
                        track.TrackNumber = j;
                        track.BufferType  = bnr.ReadByte();
                        BufferType type = (BufferType)track.BufferType;
                        track.BufferKind        = type.ToString();
                        track.TrackType         = bnr.ReadByte();
                        track.BoneType          = bnr.ReadByte();
                        track.BoneID            = bnr.ReadByte();
                        track.Weight            = bnr.ReadSingle();
                        track.BufferSize        = bnr.ReadInt32();
                        bnr.BaseStream.Position = bnr.BaseStream.Position + 4;
                        track.BufferPointer     = bnr.ReadInt32();
                        bnr.BaseStream.Position = bnr.BaseStream.Position + 4;
                        track.ReferenceData.W   = bnr.ReadSingle();
                        track.ReferenceData.X   = bnr.ReadSingle();
                        track.ReferenceData.Y   = bnr.ReadSingle();
                        track.ReferenceData.Z   = bnr.ReadSingle();
                        track.ExtremesPointer   = bnr.ReadInt32();
                        bnr.BaseStream.Position = bnr.BaseStream.Position + 4;
                        m3aentry.PrevOffset     = Convert.ToInt32(bnr.BaseStream.Position);


                        if (track.BufferSize != 0)
                        {
                            //MessageBox.Show("Track #" + j + " inside " + lmtentry.EntryName + "\nhas a buffer size that is NOT ZERO.", "Debug Note");
                            bnr.BaseStream.Position = track.BufferPointer;
                            track.Buffer            = bnr.ReadBytes(track.BufferSize);
                        }

                        if (track.ExtremesPointer != 0)
                        {
                            //MessageBox.Show("Track # " + j + " inside " + lmtentry.EntryName + "\nhas an actual extremes pointer.", "Debug Note");
                            bnr.BaseStream.Position = Convert.ToInt32(track.ExtremesPointer);

                            track.Extremes = new Extremes();

                            track.Extremes.min.W = bnr.ReadSingle();
                            track.Extremes.min.X = bnr.ReadSingle();
                            track.Extremes.min.Y = bnr.ReadSingle();
                            track.Extremes.min.Z = bnr.ReadSingle();

                            track.Extremes.max.W = bnr.ReadSingle();
                            track.Extremes.max.X = bnr.ReadSingle();
                            track.Extremes.max.Y = bnr.ReadSingle();
                            track.Extremes.max.Z = bnr.ReadSingle();
                        }
                        bnr.BaseStream.Position = m3aentry.PrevOffset;
                        m3aentry.Tracks.Add(track);
                    }


                    bnr.BaseStream.Position = m3aentry.FullData.Length - 448;
                    //Animation Events.
                    m3aentry.Events = new List <AnimEvent>();

                    for (int k = 0; k < 4; k++)
                    {
                        AnimEvent animEvent = new AnimEvent();

                        for (int l = 0; l < 32; l++)
                        {
                            animEvent.EventRemap = new List <int>();
                            animEvent.EventRemap.Add(bnr.ReadInt16());
                        }

                        animEvent.EventCount    = bnr.ReadInt32();
                        bnr.BaseStream.Position = bnr.BaseStream.Position + 4;

                        animEvent.EventsPointer = bnr.ReadInt32();
                        bnr.BaseStream.Position = bnr.BaseStream.Position + 4;

                        m3aentry.PrevOffsetTwo  = Convert.ToInt32(bnr.BaseStream.Position);
                        bnr.BaseStream.Position = animEvent.EventsPointer;
                        animEvent.EventBit      = bnr.ReadInt32();
                        animEvent.FrameNumber   = bnr.ReadInt32();

                        m3aentry.Events.Add(animEvent);
                        bnr.BaseStream.Position = m3aentry.PrevOffsetTwo;
                    }

                    //Subtracts pointers in there by the data offset to get their base value.
                    int OffTemp = 0;
                    using (MemoryStream msm3a = new MemoryStream(m3aentry.RawData))
                    {
                        using (BinaryReader brm3a = new BinaryReader(msm3a))
                        {
                            using (BinaryWriter bwm3a = new BinaryWriter(msm3a))
                            {
                                //Adjusts the offsets in the Rawdata of the m3a.
                                bwm3a.BaseStream.Position = 0;

                                for (int y = 0; y < m3aentry.TrackCount; y++)
                                {
                                    bwm3a.BaseStream.Position = 0;
                                    bwm3a.BaseStream.Position = 16 + (48 * y);
                                    OffTemp = brm3a.ReadInt32();
                                    bwm3a.BaseStream.Position = (bwm3a.BaseStream.Position - 4);
                                    if (OffTemp > 0)
                                    {
                                        OffTemp = OffTemp - m3aentry.TrackPointer;
                                        bwm3a.Write(OffTemp);
                                    }
                                    bwm3a.BaseStream.Position = 40 + (48 * y);
                                    OffTemp = brm3a.ReadInt32();
                                    bwm3a.BaseStream.Position = (bwm3a.BaseStream.Position - 4);
                                    if (OffTemp > 0)
                                    {
                                        OffTemp = OffTemp - m3aentry.TrackPointer;
                                        bwm3a.Write(OffTemp);
                                    }
                                }

                                //Adjusts the offsets in the Events.
                                bwm3a.BaseStream.Position = (bwm3a.BaseStream.Length - 280);

                                OffTemp = m3aentry.RawData.Length - 32;

                                bwm3a.Write(OffTemp);
                                bwm3a.BaseStream.Position = bwm3a.BaseStream.Position + 76;

                                OffTemp = m3aentry.RawData.Length - 24;

                                bwm3a.Write(OffTemp);
                                bwm3a.BaseStream.Position = bwm3a.BaseStream.Position + 76;

                                OffTemp = m3aentry.RawData.Length - 16;

                                bwm3a.Write(OffTemp);
                                bwm3a.BaseStream.Position = bwm3a.BaseStream.Position + 76;

                                OffTemp = m3aentry.RawData.Length - 8;

                                bwm3a.Write(OffTemp);
                            }
                        }
                    }

                    //Appends the Animation Block Data to the FullData.
                    m3aentry.FullData    = new byte[(m3aentry.AnimDataSize + 96)];
                    m3aentry._FileLength = m3aentry.FullData.LongLength;
                    Array.Copy(m3aentry.RawData, 0, m3aentry.FullData, 0, m3aentry.RawData.Length);
                    Array.Copy(m3aentry.MotionData, 0, m3aentry.FullData, m3aentry.RawData.Length, m3aentry.MotionData.Length);
                }
            }

            try
            {
                using (BinaryReader bnr = new BinaryReader(File.OpenRead(filename)))
                {
                    m3aentry.RawData = System.IO.File.ReadAllBytes(filename);


                    /*
                     * var tag = node.Tag;
                     * if (tag is LMTM3AEntry)
                     * {
                     *  oldentry = tag as LMTM3AEntry;
                     * }
                     */

                    tag = m3aentry;

                    if (node.Tag is LMTM3AEntry)
                    {
                        node.Tag = m3aentry;
                    }

                    var aew = node as ArcEntryWrapper;

                    string type = node.GetType().ToString();
                    if (type == "ThreeWorkTool.Resources.Wrappers.ArcEntryWrapper")
                    {
                        aew.entryfile = m3aentry;
                    }

                    node           = aew;
                    node.entryfile = m3aentry;

                    /*
                     * //ArcEntryWrapper aew = new ArcEntryWrapper();
                     * if (node is ArcEntryWrapper)
                     * {
                     *  node.entryfile as ArcEntryWrapper = node.Tag;
                     * }
                     */
                    tree.EndUpdate();
                    node.ImageIndex         = 18;
                    node.SelectedImageIndex = 18;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Read error. Is the file readable?");
                using (StreamWriter sw = File.AppendText("Log.txt"))
                {
                    sw.WriteLine("Read Error! Here's the exception info:\n" + ex);
                }
            }



            return(node.entryfile as LMTM3AEntry);
        }
        public LMTM3AEntry FillM3AProprties(LMTM3AEntry Anim, int datalength, int ID, int RowTotal, int SecondOffset, BinaryReader bnr, int SecondaryCount, LMTEntry lmtentry)
        {
            //Reads the AnnimBlock Header.
            LMTM3AEntry M3a = new LMTM3AEntry();

            M3a.KeyFrames           = new List <KeyFrame>();
            M3a._FileType           = ".m3a";
            M3a.FileExt             = M3a._FileType;
            bnr.BaseStream.Position = lmtentry.OffsetList[ID];
            M3a.TrackPointer        = bnr.ReadInt32();
            bnr.BaseStream.Position = bnr.BaseStream.Position + 4;
            M3a.TrackCount          = bnr.ReadInt32();
            M3a.FrameCount          = bnr.ReadInt32();
            M3a._FrameTotal         = M3a.FrameCount;
            M3a.LoopFrame           = bnr.ReadInt32();

            M3a.UnknownValue14 = ByteUtilitarian.BytesToString(bnr.ReadBytes(4), M3a.UnknownValue14);
            M3a.UnknownValue18 = ByteUtilitarian.BytesToString(bnr.ReadBytes(4), M3a.UnknownValue18);
            M3a.UnknownValue1C = ByteUtilitarian.BytesToString(bnr.ReadBytes(4), M3a.UnknownValue1C);

            M3a.EndFramesAdditiveScenePosition.W = bnr.ReadSingle();
            M3a.EndFramesAdditiveScenePosition.X = bnr.ReadSingle();
            M3a.EndFramesAdditiveScenePosition.Y = bnr.ReadSingle();
            M3a.EndFramesAdditiveScenePosition.Z = bnr.ReadSingle();

            M3a.EndFramesAdditiveSceneRotation.W = bnr.ReadSingle();
            M3a.EndFramesAdditiveSceneRotation.X = bnr.ReadSingle();
            M3a.EndFramesAdditiveSceneRotation.Y = bnr.ReadSingle();
            M3a.EndFramesAdditiveSceneRotation.Z = bnr.ReadSingle();

            M3a.AnimationFlags = bnr.ReadInt64();

            M3a.EventClassesPointer = bnr.ReadInt32();
            bnr.BaseStream.Position = bnr.BaseStream.Position + 4;
            M3a.AnimDataSize        = (M3a.EventClassesPointer - M3a.TrackPointer) + 352;
            M3a.FloatTracksPointer  = bnr.ReadInt32();
            bnr.BaseStream.Position = bnr.BaseStream.Position + 4;

            M3a.Unknown58 = bnr.ReadInt32();
            M3a.Unknown5C = bnr.ReadSingle();

            PrevOffsetThree         = Convert.ToInt32(bnr.BaseStream.Position);
            bnr.BaseStream.Position = M3a.TrackPointer;
            M3a.RawData             = new byte[M3a.AnimDataSize];
            M3a.RawData             = bnr.ReadBytes(M3a.AnimDataSize);
            M3a.MotionData          = new byte[96];
            bnr.BaseStream.Position = lmtentry.OffsetList[ID];
            M3a.MotionData          = bnr.ReadBytes(96);
            bnr.BaseStream.Position = PrevOffsetThree;

            //Gets the Tracks.
            M3a.Tracks = new List <Track>();
            bnr.BaseStream.Position = M3a.TrackPointer;

            for (int j = 0; j < M3a.TrackCount; j++)
            {
                Track track = new Track();
                track.TrackNumber   = j;
                track.ExtremesArray = new float[8];
                track.BufferType    = bnr.ReadByte();
                BufferType type = (BufferType)track.BufferType;
                track.BufferKind        = type.ToString();
                track.TrackType         = bnr.ReadByte();
                track.BoneType          = bnr.ReadByte();
                track.BoneID            = bnr.ReadByte();
                track.Weight            = bnr.ReadSingle();
                track.BufferSize        = bnr.ReadInt32();
                bnr.BaseStream.Position = bnr.BaseStream.Position + 4;
                track.BufferPointer     = bnr.ReadInt32();
                bnr.BaseStream.Position = bnr.BaseStream.Position + 4;
                track.ReferenceData.W   = bnr.ReadSingle();
                track.ReferenceData.X   = bnr.ReadSingle();
                track.ReferenceData.Y   = bnr.ReadSingle();
                track.ReferenceData.Z   = bnr.ReadSingle();
                track.ExtremesPointer   = bnr.ReadInt32();
                bnr.BaseStream.Position = bnr.BaseStream.Position + 4;
                PrevOffset = Convert.ToInt32(bnr.BaseStream.Position);


                if (track.BufferSize != 0)
                {
                    //MessageBox.Show("Track #" + j + " inside " + lmtentry.EntryName + "\nhas a buffer size that is NOT ZERO.", "Debug Note");
                    bnr.BaseStream.Position = track.BufferPointer;
                    track.Buffer            = bnr.ReadBytes(track.BufferSize);
                }

                else
                {
                    track.Buffer = new byte[0];
                }


                if (track.ExtremesPointer != 0)
                {
                    //MessageBox.Show("Track # " + j + " inside " + lmtentry.EntryName + "\nhas an actual extremes pointer.", "Debug Note");
                    bnr.BaseStream.Position = Convert.ToInt32(track.ExtremesPointer);

                    track.Extremes = new Extremes();

                    track.Extremes.min.W = bnr.ReadSingle();
                    track.Extremes.min.X = bnr.ReadSingle();
                    track.Extremes.min.Y = bnr.ReadSingle();
                    track.Extremes.min.Z = bnr.ReadSingle();

                    track.Extremes.max.W = bnr.ReadSingle();
                    track.Extremes.max.X = bnr.ReadSingle();
                    track.Extremes.max.Y = bnr.ReadSingle();
                    track.Extremes.max.Z = bnr.ReadSingle();

                    track.ExtremesArray[0] = track.Extremes.min.W;
                    track.ExtremesArray[1] = track.Extremes.min.X;
                    track.ExtremesArray[2] = track.Extremes.min.Y;
                    track.ExtremesArray[3] = track.Extremes.min.Z;
                    track.ExtremesArray[4] = track.Extremes.max.W;
                    track.ExtremesArray[5] = track.Extremes.max.X;
                    track.ExtremesArray[6] = track.Extremes.max.Y;
                    track.ExtremesArray[7] = track.Extremes.max.Z;

                    //Keyframes Take 1.

                    IEnumerable <KeyFrame> Key = LMTM3ATrackBuffer.Convert(track.BufferType, track.Buffer, track.ExtremesArray, track.BoneID, track.BufferKind);
                    M3a.KeyFrames.AddRange(Key.ToList());
                }

                else
                {
                    IEnumerable <KeyFrame> Key = LMTM3ATrackBuffer.Convert(track.BufferType, track.Buffer, track.ExtremesArray, track.BoneID, track.BufferKind);
                    M3a.KeyFrames.AddRange(Key.ToList());
                }

                bnr.BaseStream.Position = PrevOffset;
                M3a.Tracks.Add(track);
            }

            bnr.BaseStream.Position = M3a.EventClassesPointer;
            //Animation Events.
            M3a.Events = new List <AnimEvent>();

            for (int k = 0; k < 4; k++)
            {
                AnimEvent animEvent = new AnimEvent();

                for (int l = 0; l < 32; l++)
                {
                    animEvent.EventRemap = new List <int>();
                    animEvent.EventRemap.Add(bnr.ReadInt16());
                }

                animEvent.EventCount    = bnr.ReadInt32();
                bnr.BaseStream.Position = bnr.BaseStream.Position + 4;

                animEvent.EventsPointer = bnr.ReadInt32();
                bnr.BaseStream.Position = bnr.BaseStream.Position + 4;

                PrevOffsetTwo           = Convert.ToInt32(bnr.BaseStream.Position);
                bnr.BaseStream.Position = animEvent.EventsPointer;
                animEvent.EventBit      = bnr.ReadInt32();
                animEvent.FrameNumber   = bnr.ReadInt32();

                M3a.Events.Add(animEvent);
                bnr.BaseStream.Position = PrevOffsetTwo;
            }

            M3a.AnimationID = ID;
            M3a.FileName    = "AnimationID" + M3a.AnimationID + ".m3a";
            M3a.ShortName   = "AnimationID" + M3a.AnimationID;
            M3a._IsBlank    = false;
            Anim            = M3a;

            //Subtracts pointers in there by the data offset to get their base value.
            int OffTemp = 0;

            using (MemoryStream msm3a = new MemoryStream(M3a.RawData))
            {
                using (BinaryReader brm3a = new BinaryReader(msm3a))
                {
                    using (BinaryWriter bwm3a = new BinaryWriter(msm3a))
                    {
                        //Adjusts the offsets in the Rawdata of the m3a.
                        bwm3a.BaseStream.Position = 0;

                        for (int y = 0; y < M3a.TrackCount; y++)
                        {
                            bwm3a.BaseStream.Position = 0;
                            bwm3a.BaseStream.Position = 16 + (48 * y);
                            OffTemp = brm3a.ReadInt32();
                            bwm3a.BaseStream.Position = (bwm3a.BaseStream.Position - 4);
                            if (OffTemp > 0)
                            {
                                OffTemp = OffTemp - M3a.TrackPointer;
                                bwm3a.Write(OffTemp);
                            }
                            bwm3a.BaseStream.Position = 40 + (48 * y);
                            OffTemp = brm3a.ReadInt32();
                            bwm3a.BaseStream.Position = (bwm3a.BaseStream.Position - 4);
                            if (OffTemp > 0)
                            {
                                OffTemp = OffTemp - M3a.TrackPointer;
                                bwm3a.Write(OffTemp);
                            }
                        }

                        //Adjusts the offsets in the Events.
                        bwm3a.BaseStream.Position = (bwm3a.BaseStream.Length - 280);

                        OffTemp = M3a.RawData.Length - 32;

                        bwm3a.Write(OffTemp);
                        bwm3a.BaseStream.Position = bwm3a.BaseStream.Position + 76;

                        OffTemp = M3a.RawData.Length - 24;

                        bwm3a.Write(OffTemp);
                        bwm3a.BaseStream.Position = bwm3a.BaseStream.Position + 76;

                        OffTemp = M3a.RawData.Length - 16;

                        bwm3a.Write(OffTemp);
                        bwm3a.BaseStream.Position = bwm3a.BaseStream.Position + 76;

                        OffTemp = M3a.RawData.Length - 8;

                        bwm3a.Write(OffTemp);
                    }
                }
            }

            //Appends the Animation Block Data to the FullData.
            M3a.FullData    = new byte[(M3a.AnimDataSize + 96)];
            M3a._FileLength = M3a.FullData.LongLength;
            Array.Copy(M3a.RawData, 0, M3a.FullData, 0, M3a.RawData.Length);
            Array.Copy(M3a.MotionData, 0, M3a.FullData, M3a.RawData.Length, M3a.MotionData.Length);

            return(Anim);
        }
Beispiel #9
0
        public static ResourcePathListEntry ReplaceRPL(TreeView tree, ArcEntryWrapper node, string filename, Type filetype = null)
        {
            ResourcePathListEntry rpathentry = new ResourcePathListEntry();
            ResourcePathListEntry rpoldentry = new ResourcePathListEntry();

            tree.BeginUpdate();

            //Gotta Fix this up then test insert and replacing.
            try
            {
                using (BinaryReader br = new BinaryReader(File.OpenRead(filename)))
                {
                    ReplaceKnownEntry(tree, node, filename, rpathentry, rpoldentry);

                    ASCIIEncoding ascii = new ASCIIEncoding();

                    //Gets the Magic.
                    byte[] MTemp = new byte[4];
                    string STemp = " ";
                    Array.Copy(rpathentry.UncompressedData, 0, MTemp, 0, 4);
                    rpathentry.Magic = ByteUtilitarian.BytesToString(MTemp, rpathentry.Magic);

                    Array.Copy(rpathentry.UncompressedData, 12, MTemp, 0, 4);
                    Array.Reverse(MTemp);
                    STemp = ByteUtilitarian.BytesToString(MTemp, STemp);

                    int ECTemp = Convert.ToInt32(STemp, 16);
                    rpathentry._EntryTotal = ECTemp;
                    rpathentry.EntryCount  = ECTemp;

                    //Starts occupying the entry list via structs.
                    rpathentry.EntryList = new List <PathEntries>();
                    byte[] PLName  = new byte[] { };
                    byte[] PTHName = new byte[] { };

                    int    p = 16;
                    string Teme;
                    string Hame;

                    for (int g = 0; g < rpathentry.EntryCount; g++)
                    {
                        PathEntries pe = new PathEntries();
                        PLName = rpathentry.UncompressedData.Skip(p).Take(64).Where(x => x != 0x00).ToArray();
                        Teme   = ascii.GetString(PLName);

                        pe.FullPath = Teme;
                        p           = p + 64;
                        PTHName     = rpathentry.UncompressedData.Skip(p).Take(4).Where(x => x != 0x00).ToArray();
                        Array.Reverse(PTHName);

                        Teme        = ByteUtilitarian.BytesToString(PTHName, Teme);
                        pe.TypeHash = Teme;

                        try
                        {
                            using (var sr = new StreamReader("archive_filetypes.cfg"))
                            {
                                while (!sr.EndOfStream)
                                {
                                    var keyword = Console.ReadLine() ?? Teme;
                                    var line    = sr.ReadLine();
                                    if (String.IsNullOrEmpty(line))
                                    {
                                        continue;
                                    }
                                    if (line.IndexOf(keyword, StringComparison.CurrentCultureIgnoreCase) >= 0)
                                    {
                                        Hame         = line;
                                        Hame         = Hame.Split(' ')[1];
                                        pe.TotalName = pe.FullPath + Hame;
                                        pe.FileExt   = Hame;
                                        break;
                                    }
                                }
                            }
                        }
                        catch (FileNotFoundException)
                        {
                            MessageBox.Show("I cannot find archive_filetypes.cfg so I cannot finish parsing the arc.", "Oh Boy");
                            br.Close();
                        }

                        rpathentry.EntryList.Add(pe);
                        p = p + 4;
                    }

                    rpathentry.TextBackup  = new List <string>();
                    rpathentry._FileLength = rpathentry.UncompressedData.Length;

                    //Hmmm.

                    var tag = node.Tag;
                    if (tag is ResourcePathListEntry)
                    {
                        rpoldentry = tag as ResourcePathListEntry;
                    }
                    string path  = "";
                    int    index = rpoldentry.EntryName.LastIndexOf("\\");
                    if (index > 0)
                    {
                        path = rpoldentry.EntryName.Substring(0, index);
                    }

                    rpathentry.EntryName = path + "\\" + rpathentry.TrueName;

                    tag = rpathentry;

                    if (node.Tag is ResourcePathListEntry)
                    {
                        node.Tag  = rpathentry;
                        node.Name = Path.GetFileNameWithoutExtension(rpathentry.EntryName);
                        node.Text = Path.GetFileNameWithoutExtension(rpathentry.EntryName);
                    }

                    var aew = node as ArcEntryWrapper;

                    string type = node.GetType().ToString();
                    if (type == "ThreeWorkTool.Resources.Wrappers.ArcEntryWrapper")
                    {
                        aew.entryfile = rpathentry;
                    }

                    node           = aew;
                    node.entryfile = rpathentry;
                    tree.EndUpdate();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Read error. Is the file readable?");
                using (StreamWriter sw = File.AppendText("Log.txt"))
                {
                    sw.WriteLine("Read error. Cannot access the file:" + filename + "\n" + ex);
                }
            }



            return(node.entryfile as ResourcePathListEntry);
        }
Beispiel #10
0
        public static ModelEntry BuildModelEntry(BinaryReader bnr, ModelEntry modentry)
        {
            //Header Stuff. So huge.
            modentry.Magic              = ByteUtilitarian.BytesToString(bnr.ReadBytes(4), modentry.Magic);
            modentry.Version            = bnr.ReadInt16();
            modentry.BoneCount          = bnr.ReadInt16();
            modentry.PrimitiveCount     = bnr.ReadInt16();
            modentry.MaterialCount      = bnr.ReadInt16();
            modentry.VertexCount        = bnr.ReadInt32();
            modentry.IndexCount         = bnr.ReadInt32();
            modentry.PolygonCount       = bnr.ReadInt32();
            modentry.VertexBufferSizeA  = bnr.ReadInt32();
            modentry.VertexBufferSizeB  = bnr.ReadInt32();
            modentry.GroupCount         = bnr.ReadInt64();
            modentry.BonesOffset        = Convert.ToInt32(bnr.ReadInt64());
            modentry.GroupOffset        = Convert.ToInt32(bnr.ReadInt64());
            modentry.MaterialsOffset    = Convert.ToInt32(bnr.ReadInt64());
            modentry.PrimitveOffset     = Convert.ToInt32(bnr.ReadInt64());
            modentry.VertexBufferOffset = Convert.ToInt32(bnr.ReadInt64());
            modentry.IndexBufferOffset  = Convert.ToInt32(bnr.ReadInt64());
            modentry.ExtraDataOffset    = Convert.ToInt32(bnr.ReadInt64());

            //Bounding Sphere.
            modentry.BoundingSphere       = new Vector3();
            modentry.BoundingSphere.X     = bnr.ReadSingle();
            modentry.BoundingSphere.Y     = bnr.ReadSingle();
            modentry.BoundingSphere.Z     = bnr.ReadSingle();
            modentry.BoundingSphereRadius = bnr.ReadSingle();

            //Bounding Boxes.
            modentry.BoundingBoxMin = new Vector4();
            modentry.BoundingBoxMax = new Vector4();

            modentry.BoundingBoxMin.X = bnr.ReadSingle();
            modentry.BoundingBoxMin.Y = bnr.ReadSingle();
            modentry.BoundingBoxMin.Z = bnr.ReadSingle();
            modentry.BoundingBoxMin.W = bnr.ReadSingle();

            modentry.BoundingBoxMax.X = bnr.ReadSingle();
            modentry.BoundingBoxMax.Y = bnr.ReadSingle();
            modentry.BoundingBoxMax.Z = bnr.ReadSingle();
            modentry.BoundingBoxMax.W = bnr.ReadSingle();

            modentry.Field90 = bnr.ReadInt32();
            modentry.Field94 = bnr.ReadInt32();
            modentry.Field98 = bnr.ReadInt32();
            modentry.Field9C = bnr.ReadInt32();
            modentry.PrimitiveJointLinkCount = bnr.ReadInt32();

            //Bones.
            modentry.BoneLocalMatrixOffset   = modentry.BonesOffset + (24 * modentry.BoneCount);
            modentry.BoneInvBindMatrixOffset = modentry.BoneLocalMatrixOffset + (modentry.BoneCount * 64);
            bnr.BaseStream.Position          = modentry.BonesOffset;
            modentry.Bones = new List <ModelBoneEntry>();
            int PrevOffset = modentry.BonesOffset;

            for (int n = 0; n < modentry.BoneCount; n++)
            {
                ModelBoneEntry Bone = new ModelBoneEntry();
                Bone = Bone.FillModelBoneEntry(Bone, modentry, bnr, PrevOffset, n);
                modentry.Bones.Add(Bone);
                PrevOffset = PrevOffset + 24;
            }

            //Material Names.
            bnr.BaseStream.Position = modentry.MaterialsOffset;
            modentry.MaterialNames  = new List <string>();
            string Stringtemp;

            for (int m = 0; m < modentry.MaterialCount; m++)
            {
                Stringtemp = Encoding.ASCII.GetString(bnr.ReadBytes(128)).Trim('\0');
                modentry.MaterialNames.Add(Stringtemp);
            }


            //Groups.
            bnr.BaseStream.Position = modentry.GroupOffset;
            modentry.Groups         = new List <ModelGroupEntry>();
            PrevOffset = Convert.ToInt32(bnr.BaseStream.Position);

            for (int o = 0; o < modentry.GroupCount; o++)
            {
                ModelGroupEntry Group = new ModelGroupEntry();
                Group = Group.FillModelGroupEntry(Group, modentry, bnr, PrevOffset, o);
                modentry.Groups.Add(Group);

                PrevOffset = PrevOffset + 32;
            }

            return(modentry);
        }
Beispiel #11
0
        public static ResourcePathListEntry FillRPLEntry(string filename, List <string> subnames, TreeView tree, BinaryReader br, int c, int ID, Type filetype = null)
        {
            ResourcePathListEntry RPLentry = new ResourcePathListEntry();

            FillEntry(filename, subnames, tree, br, c, ID, RPLentry, filetype);

            RPLentry._FileName   = RPLentry.TrueName;
            RPLentry._FileType   = RPLentry.FileExt;
            RPLentry._FileLength = RPLentry.DSize;

            ASCIIEncoding ascii = new ASCIIEncoding();

            //Specific file type work goes here!

            //Gets the Magic.
            RPLentry.Magic       = BitConverter.ToString(RPLentry.UncompressedData, 0, 4).Replace("-", string.Empty);
            RPLentry._EntryTotal = BitConverter.ToInt32(RPLentry.UncompressedData, 12);
            RPLentry.EntryCount  = RPLentry._EntryTotal;

            //If the entry count is too high then it means the lrp file is likely corrupted or malinformed, meaning we put out an error message and force a close lest we hang.
            if (RPLentry.EntryCount > 76310)
            {
                string errorpath = "";
                foreach (string s in subnames)
                {
                    errorpath = errorpath + s + "\\";
                }
                errorpath = errorpath + RPLentry._FileName + ".lrp";
                MessageBox.Show("The file located at \n" + errorpath + "\nis malinformed and has way too many entries.\nFor this reason, I cannot continue reading this arc file and must close. Sorry.", "ATTENTION", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Process.GetCurrentProcess().Kill();
            }


            //Starts occupying the entry list via structs.
            RPLentry.EntryList = new List <PathEntries>();
            byte[] PLName  = new byte[] { };
            byte[] PTHName = new byte[] { };

            int    p = 16;
            string Teme;
            string Hame;

            for (int g = 0; g < RPLentry.EntryCount; g++)
            {
                PathEntries pe = new PathEntries();
                PLName = RPLentry.UncompressedData.Skip(p).Take(64).Where(x => x != 0x00).ToArray();
                Teme   = ascii.GetString(PLName);

                pe.FullPath = Teme;
                p           = p + 64;
                PTHName     = RPLentry.UncompressedData.Skip(p).Take(4).Where(x => x != 0x00).ToArray();
                Array.Reverse(PTHName);

                Teme        = ByteUtilitarian.BytesToString(PTHName, Teme);
                pe.TypeHash = Teme;

                try
                {
                    using (var sr = new StreamReader("archive_filetypes.cfg"))
                    {
                        while (!sr.EndOfStream)
                        {
                            var keyword = Console.ReadLine() ?? Teme;
                            var line    = sr.ReadLine();
                            if (String.IsNullOrEmpty(line))
                            {
                                continue;
                            }
                            if (line.IndexOf(keyword, StringComparison.CurrentCultureIgnoreCase) >= 0)
                            {
                                Hame         = line;
                                Hame         = Hame.Split(' ')[1];
                                pe.TotalName = pe.FullPath + Hame;
                                pe.FileExt   = Hame;
                                break;
                            }
                        }
                    }
                }
                catch (FileNotFoundException)
                {
                    MessageBox.Show("I cannot find archive_filetypes.cfg so I cannot finish parsing the arc.", "Oh Boy");
                    using (StreamWriter sw = File.AppendText("Log.txt"))
                    {
                        sw.WriteLine("Cannot find archive_filetypes.cfg and thus cannot continue parsing.");
                    }
                    return(null);
                }

                RPLentry.EntryList.Add(pe);
                p = p + 4;
            }

            RPLentry.TextBackup = new List <string>();

            return(RPLentry);
        }
Beispiel #12
0
        public static ResourcePathListEntry RenewRPLList(TextBox texbox, ResourcePathListEntry rple)
        {
            //Reconstructs the Entry List.
            string txbtxt = texbox.Text;

            string[] SPLT = new string[] { };

            SPLT = txbtxt.Split('\n');

            rple.EntryCount = SPLT.Length;
            rple.EntryList  = new List <PathEntries>();

            for (int g = 0; g < rple.EntryCount; g++)
            {
                PathEntries pe = new PathEntries();
                pe.TotalName = SPLT[g];
                rple.EntryList.Add(pe);
            }

            //Rebuilds the Decompressed data Array.
            //byte[] NewLRP = new byte[] { };
            List <byte> NEWLRP = new List <byte>();

            byte[] HeaderLRP = { 0x4C, 0x52, 0x50, 0x00, 0x00, 0x01, 0xFE, 0xFF };
            NEWLRP.AddRange(HeaderLRP);
            int NewEntryCount = rple.EntryCount;

            //if (rple.EntryList[(rple.EntryCount - 1)].TotalName == "" || rple.EntryList[(rple.EntryCount - 1)].TotalName == " ")
            if (string.IsNullOrWhiteSpace(rple.EntryList[(rple.EntryCount - 1)].TotalName))
            {
                NewEntryCount--;
            }
            int ProjectedSize = NewEntryCount * 68;
            int EstimatedSize = ((int)Math.Round(ProjectedSize / 16.0, MidpointRounding.AwayFromZero) * 16);

            EstimatedSize = EstimatedSize + 48;

            //byte[] LRPEntryTotal = { Convert.ToByte(NewEntryCount), 0x00};
            byte[] LRPEntryTotal = new byte[4];
            LRPEntryTotal[3] = Convert.ToByte(NewEntryCount);
            Array.Reverse(LRPEntryTotal);

            //Converts an integer to 4 bytes in a roundabout way.
            string LRPSize = EstimatedSize.ToString("X8");

            byte[] LRPProjSize = new byte[4];
            LRPProjSize = ByteUtilitarian.StringToByteArray(LRPSize);
            Array.Reverse(LRPProjSize);

            //Finishes the header for the new LRP built from what you see on the textbox.
            NEWLRP.AddRange(LRPProjSize);
            NEWLRP.AddRange(LRPEntryTotal);

            string ENTemp  = "";
            string RPTemp  = "";
            string HashStr = "";

            byte[] HashTempDX = new byte[4];

            //Starts building the entries.
            for (int k = 0; k < NewEntryCount; k++)
            {
                ENTemp = rple.EntryList[k].TotalName;
                ENTemp = ENTemp.Replace("\r", "");
                int      inp     = (ENTemp.IndexOf("."));
                string[] SplTemp = ENTemp.Split('.');
                if (inp < 0)
                {
                    RPTemp = "";
                }
                else
                {
                    RPTemp = ENTemp.Substring(inp, ENTemp.Length - inp);
                }
                ENTemp = SplTemp[0];
                bool ExtFound = false;

                int    NumberChars = ENTemp.Length;
                byte[] namebuffer  = Encoding.ASCII.GetBytes(ENTemp);
                int    nblength    = namebuffer.Length;

                //Space for name is 64 bytes so we make a byte array with that size and then inject the name data in it.
                byte[] writenamedata = new byte[64];
                Array.Clear(writenamedata, 0, writenamedata.Length);

                for (int i = 0; i < namebuffer.Length; ++i)
                {
                    writenamedata[i] = namebuffer[i];
                }

                NEWLRP.AddRange(writenamedata);

                if (RPTemp == "")
                {
                    HashTempDX[0] = 0xFF;
                    HashTempDX[1] = 0xFF;
                    HashTempDX[2] = 0xFF;
                    HashTempDX[3] = 0xFF;
                }
                else
                {
                    //Typehash stuff.
                    try
                    {
                        using (var sr = new StreamReader("archive_filetypes.cfg"))
                        {
                            while (!sr.EndOfStream)
                            {
                                var keyword = Console.ReadLine() ?? RPTemp;
                                var line    = sr.ReadLine();
                                if (String.IsNullOrEmpty(line))
                                {
                                    continue;
                                }
                                if (line.IndexOf(keyword, StringComparison.CurrentCultureIgnoreCase) >= 0)
                                {
                                    ExtFound = true;
                                    HashStr  = line;
                                    HashStr  = HashStr.Split(' ')[0];
                                    break;
                                }
                            }
                        }
                    }
                    catch (FileNotFoundException)
                    {
                        MessageBox.Show("I cannot find archive_filetypes.cfg so I cannot finish parsing the arc.", "Oh Boy");
                        using (StreamWriter sw = File.AppendText("Log.txt"))
                        {
                            sw.WriteLine("Cannot find archive_filetypes.cfg and thus cannot continue parsing.");
                        }
                        return(null);
                    }
                }
                if (ExtFound == true)
                {
                    HashTempDX = ByteUtilitarian.StringToByteArray(HashStr);
                    Array.Reverse(HashTempDX);
                }
                else
                {
                    HashTempDX[0] = 0xFF;
                    HashTempDX[1] = 0xFF;
                    HashTempDX[2] = 0xFF;
                    HashTempDX[3] = 0xFF;
                }

                NEWLRP.AddRange(HashTempDX);
            }

            if (EstimatedSize > (NEWLRP.Count - 16))
            {
                for (int vv = 0; EstimatedSize > (NEWLRP.Count - 16); vv++)
                {
                    NEWLRP.Add(0x00);
                }
            }

            rple.UncompressedData = NEWLRP.ToArray();
            rple.DSize            = rple.UncompressedData.Length;

            rple.CompressedData = Zlibber.Compressor(rple.UncompressedData);
            rple.CSize          = rple.CompressedData.Length;

            rple._FileLength = rple.UncompressedData.Length;
            rple._EntryTotal = NewEntryCount;

            return(rple);
        }
Beispiel #13
0
        public static EffectListEntry FillEFLEntry(string filename, List <string> subnames, TreeView tree, BinaryReader br, int c, int ID, Type filetype = null)
        {
            EffectListEntry effectList = new EffectListEntry();

            //This block gets the name of the entry.
            effectList.OffsetTemp = c;
            effectList.EntryID    = ID;
            List <byte> BTemp = new List <byte>();

            br.BaseStream.Position = effectList.OffsetTemp;
            BTemp.AddRange(br.ReadBytes(64));
            BTemp.RemoveAll(ByteUtilitarian.IsZeroByte);

            if (SBname == null)
            {
                SBname = new StringBuilder();
            }
            else
            {
                SBname.Clear();
            }

            string        Tempname;
            ASCIIEncoding ascii = new ASCIIEncoding();

            Tempname = ascii.GetString(BTemp.ToArray());

            //Compressed Data size.
            BTemp = new List <byte>();
            c     = c + 68;
            br.BaseStream.Position = c;
            BTemp.AddRange(br.ReadBytes(4));
            effectList.CSize = BitConverter.ToInt32(BTemp.ToArray(), 0);

            //Uncompressed Data size.
            BTemp = new List <byte>();
            c     = c + 4;
            br.BaseStream.Position = c;
            BTemp.AddRange(br.ReadBytes(4));
            BTemp.Reverse();
            string TempStr = "";

            TempStr = ByteUtilitarian.BytesToStringL2(BTemp, TempStr);
            BigInteger BN1, BN2, DIFF;

            BN2              = BigInteger.Parse("40000000", NumberStyles.HexNumber);
            BN1              = BigInteger.Parse(TempStr, NumberStyles.HexNumber);
            DIFF             = BN1 - BN2;
            effectList.DSize = (int)DIFF;

            //Data Offset.
            BTemp = new List <byte>();
            c     = c + 4;
            br.BaseStream.Position = c;
            BTemp.AddRange(br.ReadBytes(4));
            effectList.AOffset = BitConverter.ToInt32(BTemp.ToArray(), 0);

            //Compressed Data.
            BTemp = new List <byte>();
            c     = effectList.AOffset;
            br.BaseStream.Position = c;
            BTemp.AddRange(br.ReadBytes(effectList.CSize));
            effectList.CompressedData = BTemp.ToArray();


            //Namestuff.
            effectList.EntryName = Tempname;

            //Ensures existing subdirectories are cleared so the directories for files are displayed correctly.
            if (subnames != null)
            {
                if (subnames.Count > 0)
                {
                    subnames.Clear();
                }
            }

            //Gets the filename without subdirectories.
            if (effectList.EntryName.Contains("\\"))
            {
                string[] splstr = effectList.EntryName.Split('\\');

                //foreach (string v in splstr)
                for (int v = 0; v < (splstr.Length - 1); v++)
                {
                    if (!subnames.Contains(splstr[v]))
                    {
                        subnames.Add(splstr[v]);
                    }
                }


                effectList.TrueName = effectList.EntryName.Substring(effectList.EntryName.IndexOf("\\") + 1);
                Array.Clear(splstr, 0, splstr.Length);

                while (effectList.TrueName.Contains("\\"))
                {
                    effectList.TrueName = effectList.TrueName.Substring(effectList.TrueName.IndexOf("\\") + 1);
                }
            }
            else
            {
                effectList.TrueName = effectList.EntryName;
            }

            effectList._FileName = effectList.TrueName;

            effectList.EntryDirs   = subnames.ToArray();
            effectList.FileExt     = ".efl";
            effectList.EntryName   = effectList.EntryName + effectList.FileExt;
            effectList._FileName   = effectList.TrueName;
            effectList._FileType   = effectList.FileExt;
            effectList._FileLength = effectList.DSize;

            //Decompression Time.
            effectList.UncompressedData = ZlibStream.UncompressBuffer(effectList.CompressedData);

            //Specific file type work goes here!

            //Header is 30 bytes. What info is in there?
            byte[] MTemp = new byte[4];
            string STemp = " ";

            Array.Copy(effectList.UncompressedData, 0, MTemp, 0, 4);
            effectList.Magic = ByteUtilitarian.BytesToString(MTemp, effectList.Magic);

            //These values at 0x04 seem identical based on what I've seen so far.
            //string SCTemp = " ";
            Array.Copy(effectList.UncompressedData, 4, MTemp, 0, 4);
            effectList.Magic = ByteUtilitarian.BytesToString(MTemp, effectList.WeirdConstant);

            //Gets the Data Size.
            Array.Copy(effectList.UncompressedData, 8, MTemp, 0, 4);
            Array.Reverse(MTemp);
            STemp = ByteUtilitarian.BytesToString(MTemp, STemp);
            int ECTemp = Convert.ToInt32(STemp, 16);

            effectList.DataSize = ECTemp;

            //These values at 0x0C also seem identical based on what I've seen so far.
            Array.Copy(effectList.UncompressedData, 4, MTemp, 0, 4);
            effectList.Magic = ByteUtilitarian.BytesToString(MTemp, effectList.OtherWeirdConstant);

            byte[] TwoTemp = new byte[2];
            Array.Copy(effectList.UncompressedData, 16, TwoTemp, 0, 2);
            Array.Reverse(TwoTemp);
            effectList.SomeEntryCount = BitConverter.ToInt32(TwoTemp, 0);

            Array.Copy(effectList.UncompressedData, 18, TwoTemp, 0, 2);
            Array.Reverse(TwoTemp);
            effectList.OtherEntryCount = BitConverter.ToInt32(TwoTemp, 0);

            return(effectList);
        }
Beispiel #14
0
        public static GemEntry RenewGemEntry(TextBox texbox, GemEntry gem)
        {
            //Reconstructs the Entry List.
            string txbtxt = texbox.Text;

            string[] SPLT = new string[] { };

            SPLT = txbtxt.Split('\n');

            gem.EntryCountTotal      = SPLT.Length;
            gem.InterpolatedFileSize = gem.EntryCountTotal * 64;
            gem.EntryList            = new List <GEMEntries>();

            for (int g = 0; g < gem.EntryCountTotal; g++)
            {
                GEMEntries pe = new GEMEntries();
                pe.TotalName = SPLT[g];
                gem.EntryList.Add(pe);
            }

            //Rebuilds the Decompressed data Array.
            List <byte> NEWGEM = new List <byte>();

            byte[] HeaderGEM = { 0x47, 0x45, 0x4D, 0x00, 0x01, 0x01, 0xFE, 0xFF };
            NEWGEM.AddRange(HeaderGEM);
            int NewEntryCount = gem.EntryCountTotal;

            //Converts an integer to 4 bytes in a roundabout way.
            string GEMSize = 192.ToString("X8");

            byte[] GEMProjSize = new byte[4];
            GEMProjSize = ByteUtilitarian.StringToByteArray(GEMSize);
            Array.Reverse(GEMProjSize);

            NEWGEM.AddRange(GEMProjSize);

            string ENTemp = "";

            //string RPTemp = "";
            //string HashStr = "";
            byte[] HashTempDX = new byte[4];
            int    counter    = gem.EntryCountTotal - 1;

            for (int k = 0; k < counter; k++)
            {
                ENTemp = gem.EntryList[k].TotalName;
                ENTemp = ENTemp.Replace("\r", "");
                int    NumberChars = ENTemp.Length;
                byte[] namebuffer  = Encoding.ASCII.GetBytes(ENTemp);
                int    nblength    = namebuffer.Length;

                //Space for name is 64 bytes so we make a byte array with that size and then inject the name data in it.
                byte[] writenamedata = new byte[64];
                Array.Clear(writenamedata, 0, writenamedata.Length);

                for (int i = 0; i < namebuffer.Length; ++i)
                {
                    writenamedata[i] = namebuffer[i];
                }

                NEWGEM.AddRange(writenamedata);
            }

            gem.UncompressedData = NEWGEM.ToArray();
            gem.DSize            = gem.UncompressedData.Length;
            gem.CompressedData   = Zlibber.Compressor(gem.UncompressedData);
            gem.CSize            = gem.CompressedData.Length;
            gem._FileLength      = gem.UncompressedData.Length;

            return(gem);
        }
Beispiel #15
0
        public static ArcFile LoadArc(TreeView tree, string filename, List<string> foldernames, bool IsBigEndian, bool Verifier = false,Type filetype = null, int arcsize = -1)
        {
            
            ArcFile arcfile = new ArcFile();
            byte[] Bytes = File.ReadAllBytes(filename);

            using (BinaryReader br = new BinaryReader(File.Open(filename, FileMode.Open)))
            {

                arcsize = Bytes.Length;
                int Totalsize = arcsize;
                arcfile.FileLength = arcsize;
                arcfile.Tempname = filename;

                br.BaseStream.Position = 0;
                byte[] HeaderMagic = br.ReadBytes(4);
                //Checks file signature/Endianess.
                if (HeaderMagic[0] == 0x00 && HeaderMagic[1] == 0x43 && HeaderMagic[2] == 0x52 && HeaderMagic[3] == 0x41)
                {
                    /*
                    MessageBox.Show("This .arc file is not in the kind of endian I can deal with right now, so these will be in read only.\nDon't expect save to work... or for the program to be stable", "Just so you know....");

                    IsBigEndian = true;
                    arcfile.HeaderMagic = HeaderMagic;
                    arcfile.MaterialCount = 0;
                    arcfile.arctable = new List<ArcEntry>();
                    arcfile.arcfiles = new List<object>();
                    arcfile.FileList = new List<string>();
                    arcfile.TypeHashes = new List<string>();

                    br.BaseStream.Position = 4;
                    var data = br.ReadBytes(2);
                    Array.Reverse(data);
                    arcfile.UnknownFlag = br.ReadByte();



                    return arcfile;

                    
                     
                    */

                    MessageBox.Show("This .arc file is not in the kind of endian I can deal with right now. Closing.", "Just so you know....");
                    br.Close();
                    return null;

                }

                if (HeaderMagic[0] != 0x41 && HeaderMagic[1] != 0x52 && HeaderMagic[2] != 0x43 && HeaderMagic[3] != 0x00)
                {
                    MessageBox.Show("This .arc file is either not the correct kind or is not properly extracted, so I'm closing it.", "Oh dear");
                    br.Close();
                    return null;
                }

                #region PC Arc
                IsBigEndian = false;
                arcfile.HeaderMagic = HeaderMagic;
                arcfile.MaterialCount = 0;
                arcfile.arctable = new List<ArcEntry>();
                arcfile.arcfiles = new List<object>();
                arcfile.FileList = new List<string>();
                arcfile.TypeHashes = new List<string>();

                br.BaseStream.Position = 4;
                arcfile.UnknownFlag = br.ReadByte();

                br.BaseStream.Position = 6;
                arcfile.FileCount = BitConverter.ToInt16((br.ReadBytes(2)), 0);
                arcfile.Version = arcfile.UnknownFlag;

                List<String> filenames = new List<String>();

                List<string> subdref = new List<string>();
                foldernames = subdref;


                //byte[] BytesTemp;
                //BytesTemp = new byte[] { };
                List<byte> BytesTemp = new List<byte>();
                byte[] HTTemp = new byte[] { };
                int j = 8;
                int l = 64;
                int m = 80;
                int n = 4;

                //Iterates through the header/first part of the arc to get all the filenames and occupy the filename list.
                for (int i = 0; i < arcfile.FileCount; i++)
                {
                    BytesTemp.Clear();
                    BytesTemp.TrimExcess();
                    j = 8 + (m * i);
                    //Copies the specified range to isolate the bytes containing a filename.
                    br.BaseStream.Position = j;
                    BytesTemp.AddRange(br.ReadBytes(l));
                    BytesTemp.RemoveAll(ByteUtilitarian.IsZeroByte);
                    filenames.Add(ByteUtilitarian.BytesToStringL(BytesTemp));
                    //For The Typehashes.
                    n = 72 + (m * i);

                    br.BaseStream.Position = n;
                    HTTemp = br.ReadBytes(4);
                    Array.Reverse(HTTemp);
                    arcfile.TypeHashes.Add(ByteUtilitarian.HashBytesToString(HTTemp));

                }

                //Fills in each file as an ArcEntry or TextureEntry as needed. 
                j = 8;
                int IDCounter = 0;
                for (int i = 0; i < arcfile.FileCount; i++)
                {
                    j = 8 + (80 * i);
                    switch (arcfile.TypeHashes[i])
                    {
                        //Texture Files.
                        case "241F5DEB":
                            TextureEntry newtexen = TextureEntry.FillTexEntry(filename, foldernames, tree, br, j, IDCounter);
                            arcfile.arcfiles.Add(newtexen);
                            arcfile.FileList.Add(newtexen.EntryName);
                            foldernames.Clear();
                            IDCounter++;
                            break;

                        //Resource Path Lists.
                        case "357EF6D4":
                            ResourcePathListEntry newplen = ResourcePathListEntry.FillRPLEntry(filename, foldernames, tree, br, j, IDCounter);
                            arcfile.arcfiles.Add(newplen);
                            arcfile.FileList.Add(newplen.EntryName);
                            foldernames.Clear();
                            IDCounter++;
                            break;


                        //Materials. Incomplete.                        
                        case "2749C8A8":
                            MaterialEntry Maten = MaterialEntry.FillMatEntry(filename, foldernames, tree, br, j, IDCounter);
                            arcfile.arcfiles.Add(Maten);
                            arcfile.FileList.Add(Maten.EntryName);
                            foldernames.Clear();
                            IDCounter++;
                            arcfile.MaterialCount++;
                            break;
                            

                        //LMT Files.
                        case "76820D81":
                            LMTEntry LMTen = LMTEntry.FillLMTEntry(filename, foldernames, tree, br, j, IDCounter);
                            arcfile.arcfiles.Add(LMTen);
                            arcfile.FileList.Add(LMTen.EntryName);
                            foldernames.Clear();
                            IDCounter++;
                            break;
                        
                        //MSD Files.
                        case "5B55F5B1":
                            MSDEntry newmsden = MSDEntry.FillMSDEntry(filename, foldernames, tree, br, Bytes, j, IDCounter);
                            arcfile.arcfiles.Add(newmsden);
                            arcfile.FileList.Add(newmsden.EntryName);
                            foldernames.Clear();
                            IDCounter++;
                            break;

                        //CST Files.
                        case "326F732E":
                            ChainListEntry CSTen = ChainListEntry.FillCSTEntry(filename, foldernames, tree, br, j, IDCounter);
                            arcfile.arcfiles.Add(CSTen);
                            arcfile.FileList.Add(CSTen.EntryName);
                            foldernames.Clear();
                            IDCounter++;
                            break;

                        //CHN Files.
                        case "3E363245":
                            ChainEntry CHNen = ChainEntry.FillChainEntry(filename, foldernames, tree, br, j, IDCounter);
                            arcfile.arcfiles.Add(CHNen);
                            arcfile.FileList.Add(CHNen.EntryName);
                            foldernames.Clear();
                            IDCounter++;
                            break;

                        //CCL Files.
                        case "0026E7FF":
                            ChainCollisionEntry CCLen = ChainCollisionEntry.FillChainCollEntry(filename, foldernames, tree, br, j, IDCounter);
                            arcfile.arcfiles.Add(CCLen);
                            arcfile.FileList.Add(CCLen.EntryName);
                            foldernames.Clear();
                            IDCounter++;
                            break;

                        //MOD Files.
                        case "58A15856":
                            ModelEntry MODen = ModelEntry.FillModelEntry(filename, foldernames, tree, br, j, IDCounter);
                            arcfile.arcfiles.Add(MODen);
                            arcfile.FileList.Add(MODen.EntryName);
                            foldernames.Clear();
                            IDCounter++;
                            break;

                        case "361EA2A5":
                            MissionEntry MISen = MissionEntry.FillMissionEntry(filename, foldernames, tree, br, j, IDCounter);
                            arcfile.arcfiles.Add(MISen);
                            arcfile.FileList.Add(MISen.EntryName);
                            foldernames.Clear();
                            IDCounter++;
                            break;

                        //Gem Files.
                        case "448BBDD4":
                           GemEntry GEMen = GemEntry.FillGEMEntry(filename, foldernames, tree, br, j, IDCounter);
                           arcfile.arcfiles.Add(GEMen);
                           arcfile.FileList.Add(GEMen.EntryName);
                           foldernames.Clear();
                           IDCounter++;
                           break;

                        //EFL Files.
                        case "6D5AE854":
                           EffectListEntry EFLen = EffectListEntry.FillEFLEntry(filename, foldernames, tree, br, j, IDCounter);
                           arcfile.arcfiles.Add(EFLen);
                           arcfile.FileList.Add(EFLen.EntryName);
                           foldernames.Clear();
                           IDCounter++;
                           break;
                        

                        //New Formats go like this!   
                        /*
                        case "********":
                           *****Entry ****en = *****Entry.Fill*****Entry(filename, foldernames, tree, br, j, IDCounter);
                           arcfile.arcfiles.Add(*****en);
                           arcfile.FileList.Add(*****.EntryName);
                           foldernames.Clear();
                           IDCounter++;
                           break;
                        */

                        default:
                            //Everything not listed above.
                            ArcEntry newentry = ArcEntry.FillArcEntry(filename, foldernames, tree, br, j, IDCounter);
                            arcfile.arcfiles.Add(newentry);
                            arcfile.FileList.Add(newentry.EntryName);
                            foldernames.Clear();
                            IDCounter++;
                            break;
                    }
                }

                arcfile._FileAmount = Convert.ToUInt16(IDCounter);                

                br.Close();
            }

            return arcfile;

            #endregion

        }
Beispiel #16
0
        public static ResourcePathListEntry InsertRPL(TreeView tree, ArcEntryWrapper node, string filename, Type filetype = null)
        {
            ResourcePathListEntry rplentry = new ResourcePathListEntry();

            try
            {
                using (BinaryReader bnr = new BinaryReader(File.OpenRead(filename)))
                {
                    InsertKnownEntry(tree, node, filename, rplentry, bnr);

                    //Specific file type work goes here!
                    ASCIIEncoding ascii = new ASCIIEncoding();

                    //Gets the Magic.
                    byte[] MTemp = new byte[4];
                    string STemp = " ";
                    Array.Copy(rplentry.UncompressedData, 0, MTemp, 0, 4);
                    rplentry.Magic = ByteUtilitarian.BytesToString(MTemp, rplentry.Magic);

                    Array.Copy(rplentry.UncompressedData, 12, MTemp, 0, 4);
                    Array.Reverse(MTemp);
                    STemp = ByteUtilitarian.BytesToString(MTemp, STemp);

                    int ECTemp = Convert.ToInt32(STemp, 16);
                    rplentry._EntryTotal = ECTemp;
                    rplentry.EntryCount  = ECTemp;

                    //Starts occupying the entry list via structs.
                    rplentry.EntryList = new List <PathEntries>();
                    byte[] PLName  = new byte[] { };
                    byte[] PTHName = new byte[] { };

                    int    p = 16;
                    string Teme;
                    string Hame;

                    for (int g = 0; g < rplentry.EntryCount; g++)
                    {
                        PathEntries pe = new PathEntries();
                        PLName = rplentry.UncompressedData.Skip(p).Take(64).Where(x => x != 0x00).ToArray();
                        Teme   = ascii.GetString(PLName);

                        pe.FullPath = Teme;
                        p           = p + 64;
                        PTHName     = rplentry.UncompressedData.Skip(p).Take(4).Where(x => x != 0x00).ToArray();
                        Array.Reverse(PTHName);

                        Teme        = ByteUtilitarian.BytesToString(PTHName, Teme);
                        pe.TypeHash = Teme;

                        try
                        {
                            using (var sr = new StreamReader("archive_filetypes.cfg"))
                            {
                                while (!sr.EndOfStream)
                                {
                                    var keyword = Console.ReadLine() ?? Teme;
                                    var line    = sr.ReadLine();
                                    if (String.IsNullOrEmpty(line))
                                    {
                                        continue;
                                    }
                                    if (line.IndexOf(keyword, StringComparison.CurrentCultureIgnoreCase) >= 0)
                                    {
                                        Hame         = line;
                                        Hame         = Hame.Split(' ')[1];
                                        pe.TotalName = pe.FullPath + Hame;
                                        pe.FileExt   = Hame;
                                        break;
                                    }
                                }
                            }
                        }
                        catch (FileNotFoundException)
                        {
                            MessageBox.Show("I cannot find archive_filetypes.cfg so I cannot finish parsing the arc.", "Oh Boy");
                            using (StreamWriter sw = File.AppendText("Log.txt"))
                            {
                                sw.WriteLine("Cannot find archive_filetypes.cfg and thus cannot continue parsing.");
                            }
                            return(null);
                        }

                        rplentry.EntryList.Add(pe);
                        p = p + 4;
                    }

                    rplentry.TextBackup = new List <string>();
                }
            }
            catch (Exception ex)
            {
                using (StreamWriter sw = File.AppendText("Log.txt"))
                {
                    sw.WriteLine("Caught the exception:" + ex);
                }
            }

            return(rplentry);
        }
        public static void FillEntry(string filename, List <string> subnames, TreeView tree, BinaryReader br, int c, int ID, DefaultWrapper entrytobuild, Type filetype = null)
        {
            List <byte> BTemp = new List <byte>();

            //This block gets the name of the entry.
            entrytobuild.OffsetTemp = c;
            entrytobuild.EntryID    = ID;
            br.BaseStream.Position  = entrytobuild.OffsetTemp;
            var TempName = Encoding.ASCII.GetString(br.ReadBytes(64)).Trim('\0');

            //This is for the bytes that have the typehash, the thing that dictates the type of file stored.
            BTemp = new List <byte>();
            c     = c + 64;
            br.BaseStream.Position = c;
            entrytobuild.TypeHash  = ByteUtilitarian.BytesToStringL2R(br.ReadBytes(4).ToList(), entrytobuild.TypeHash);

            //Compressed Data size.
            entrytobuild.CSize = br.ReadInt32();

            //Uncompressed Data size.
            entrytobuild.DSize = br.ReadInt32() - 1073741824;

            //Data Offset.
            entrytobuild.AOffset = br.ReadInt32();

            //Compressed Data.
            BTemp = new List <byte>();
            br.BaseStream.Position      = entrytobuild.AOffset;
            entrytobuild.CompressedData = br.ReadBytes(entrytobuild.CSize);

            //Namestuff.
            entrytobuild.EntryName = TempName;

            //Ensures existing subdirectories are cleared so the directories for files are displayed correctly.
            if (subnames != null)
            {
                if (subnames.Count > 0)
                {
                    subnames.Clear();
                }
            }

            //Gets the filename without subdirectories.
            if (entrytobuild.EntryName.Contains("\\"))
            {
                string[] splstr = entrytobuild.EntryName.Split('\\');

                //foreach (string v in splstr)
                for (int v = 0; v < (splstr.Length - 1); v++)
                {
                    if (!subnames.Contains(splstr[v]))
                    {
                        subnames.Add(splstr[v]);
                    }
                }


                entrytobuild.TrueName = entrytobuild.EntryName.Substring(entrytobuild.EntryName.IndexOf("\\") + 1);
                Array.Clear(splstr, 0, splstr.Length);

                while (entrytobuild.TrueName.Contains("\\"))
                {
                    entrytobuild.TrueName = entrytobuild.TrueName.Substring(entrytobuild.TrueName.IndexOf("\\") + 1);
                }
            }
            else
            {
                entrytobuild.TrueName = entrytobuild.EntryName;
            }


            entrytobuild.EntryDirs = subnames.ToArray();


            //Looks through the archive_filetypes.cfg file to find the extension associated with the typehash.
            try
            {
                using (var sr = new StreamReader("archive_filetypes.cfg"))
                {
                    while (!sr.EndOfStream)
                    {
                        var keyword = Console.ReadLine() ?? entrytobuild.TypeHash;
                        var line    = sr.ReadLine();
                        if (String.IsNullOrEmpty(line))
                        {
                            continue;
                        }
                        if (line.IndexOf(keyword, StringComparison.CurrentCultureIgnoreCase) >= 0)
                        {
                            entrytobuild.FileExt   = line;
                            entrytobuild.FileExt   = entrytobuild.FileExt.Split(' ')[1];
                            entrytobuild.EntryName = entrytobuild.EntryName + entrytobuild.FileExt;
                            break;
                        }
                    }
                }
            }
            catch (FileNotFoundException)
            {
                MessageBox.Show("Cannot find archive_filetypes.cfg so I cannot continue parsing this file.\n Find archive_filetypes.cfg and then restart this program.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                using (StreamWriter sw = File.AppendText("Log.txt"))
                {
                    sw.WriteLine("Cannot find archive_filetypes.cfg so I cannot continue parsing the file.");
                }
                Process.GetCurrentProcess().Kill();
            }

            //Decompression Time.
            entrytobuild.UncompressedData = ZlibStream.UncompressBuffer(entrytobuild.CompressedData);
        }