Пример #1
0
        public HexEditForm(byte[] bytes, string name, bool readOnly, PointeredFile pointeredFile)
        {
            internalBytes = bytes;
            pointerSet    = pointeredFile;
            InitializeComponent();
            this.Text  = ("Hex Editor - " + name);
            this.Load += attachStream;
            isReadOnly = readOnly;
            toggleReadOnlyButton.Visible = false;
            toggleReadOnlyButton.Enabled = false;

            if (readOnly == true)
            {
                saveButton.Visible = false;
                saveButton.Enabled = false;
            }
        }
Пример #2
0
        public ThinkDragonFile(string inFilename, byte[] rawData, byte[] subHeader, int[] ptrs, int baseAddr)
        {
            backupRaw = new PointeredFile(inFilename, rawData, subHeader, ptrs, baseAddr, false);

            filename = inFilename;
            MemoryStream inStream = new MemoryStream(rawData);
            BinaryReader inReader = new BinaryReader(inStream);

            inStream.Seek(8, SeekOrigin.Begin);
            int headerLoc = inReader.ReadInt32();

            inStream.Seek(headerLoc, SeekOrigin.Begin);
            int  groupOneLoc   = inReader.ReadInt32() - baseAddr;
            int  groupTwoLoc   = inReader.ReadInt32() - baseAddr;
            byte groupOneCount = inReader.ReadByte();
            byte groupTwoCount = inReader.ReadByte();

            //In De Ragan, groups 1 and 2 are each only 1 entry long.

            //Group 1 is much easier than group 2.
            inStream.Seek(groupOneLoc, SeekOrigin.Begin);
            groupOne.floatOne   = inReader.ReadSingle();
            groupOne.floatTwo   = inReader.ReadSingle();
            groupOne.floatThree = inReader.ReadSingle();
            groupOne.floatFour  = inReader.ReadSingle();
            int  groupOneChildOneLoc   = inReader.ReadInt32() - baseAddr;
            int  groupOneChildTwoLoc   = inReader.ReadInt32() - baseAddr;
            byte groupOneChildOneCount = inReader.ReadByte();
            byte groupOneChildTwoCount = inReader.ReadByte();

            groupOne.byteOne          = inReader.ReadByte();
            groupOne.byteTwo          = inReader.ReadByte();
            groupOne.groupOneChildOne = new List <Tuple <float, float> >();
            groupOne.groupOneChildTwo = new List <Tuple <float, float, float> >();
            inStream.Seek(groupOneChildOneLoc, SeekOrigin.Begin);
            for (int i = 0; i < groupOneChildOneCount; i++)
            {
                float a = inReader.ReadSingle();
                float b = inReader.ReadSingle();
                groupOne.groupOneChildOne.Add(new Tuple <float, float>(a, b));
            }
            inStream.Seek(groupOneChildTwoLoc, SeekOrigin.Begin);
            for (int i = 0; i < groupOneChildTwoCount; i++)
            {
                float a = inReader.ReadSingle();
                float b = inReader.ReadSingle();
                float c = inReader.ReadSingle();
                groupOne.groupOneChildTwo.Add(new Tuple <float, float, float>(a, b, c));
            }

            //Group 2...
            //Five pointers, five counts, and then mystery values!
            //First four appear to be to lists of float/int pairs.
            inStream.Seek(groupTwoLoc, SeekOrigin.Begin);
            int  groupTwoBranchOneLoc     = inReader.ReadInt32() - baseAddr;
            int  groupTwoBranchTwoLoc     = inReader.ReadInt32() - baseAddr;
            int  groupTwoBranchThreeLoc   = inReader.ReadInt32() - baseAddr;
            int  groupTwoBranchFourLoc    = inReader.ReadInt32() - baseAddr;
            int  groupTwoBranchFiveLoc    = inReader.ReadInt32() - baseAddr;
            byte groupTwoBranchOneCount   = inReader.ReadByte();
            byte groupTwoBranchTwoCount   = inReader.ReadByte();
            byte groupTwoBranchThreeCount = inReader.ReadByte();
            byte groupTwoBranchFourCount  = inReader.ReadByte();
            byte groupTwoBranchFiveCount  = inReader.ReadByte();

            groupTwo.byte1      = inReader.ReadByte();
            groupTwo.byte2      = inReader.ReadByte();
            groupTwo.byte3      = inReader.ReadByte();
            groupTwo.int1       = inReader.ReadInt32();
            groupTwo.branchFive = new List <List <GroupTwoLeaf> >();

            groupTwo.branchOne   = readFloatIntList(groupTwoBranchOneLoc, groupTwoBranchOneCount, baseAddr, inStream, inReader);
            groupTwo.branchTwo   = readFloatIntList(groupTwoBranchTwoLoc, groupTwoBranchTwoCount, baseAddr, inStream, inReader);
            groupTwo.branchThree = readFloatIntList(groupTwoBranchThreeLoc, groupTwoBranchThreeCount, baseAddr, inStream, inReader);
            groupTwo.branchFour  = readFloatIntList(groupTwoBranchFourLoc, groupTwoBranchFourCount, baseAddr, inStream, inReader);

            for (int i = 0; i < groupTwoBranchFiveCount; i++)
            {
                inStream.Seek(groupTwoBranchFiveLoc + i * 8, SeekOrigin.Begin);
                int currentPointer = inReader.ReadInt32() - baseAddr;
                int currentCount   = inReader.ReadInt32();

                List <GroupTwoLeaf> leaves = new List <GroupTwoLeaf>();
                for (int j = 0; j < currentCount; j++)
                {
                    inStream.Seek(currentPointer + j * 20, SeekOrigin.Begin);
                    GroupTwoLeaf leaf         = new GroupTwoLeaf();
                    int          tupleListPtr = inReader.ReadInt32() - baseAddr;
                    leaf.unkFloat1 = inReader.ReadSingle();
                    leaf.unkFloat2 = inReader.ReadSingle();
                    byte tupleCount = inReader.ReadByte();
                    leaf.unkByte1 = inReader.ReadByte();
                    leaf.unkByte2 = inReader.ReadByte();
                    leaf.unkByte3 = inReader.ReadByte();
                    leaf.unkByte4 = inReader.ReadByte();
                    leaf.unkByte5 = inReader.ReadByte();
                    leaf.unkByte6 = inReader.ReadByte();
                    leaf.unkByte7 = inReader.ReadByte();

                    inStream.Seek(tupleListPtr, SeekOrigin.Begin);
                    for (int k = 0; k < tupleCount; k++)
                    {
                        float a = inReader.ReadSingle();
                        int   b = inReader.ReadInt32();
                        leaf.tupleList.Add(new Tuple <float, int>(a, b));
                    }
                    leaves.Add(leaf);
                }
                groupTwo.branchFive.Add(leaves);
            }
        }
Пример #3
0
 public PointeredFileViewer(PointeredFile toImport)
 {
     InitializeComponent();
     internalFile      = toImport;
     richTextBox1.Text = "";
     if (internalFile.splitData != null)
     {
         List <int> condensedPointers = new List <int>();
         for (int i = 0; i < internalFile.sortedPtrs.Length; i++)
         {
             if (!condensedPointers.Contains(internalFile.sortedPtrs[i]))
             {
                 condensedPointers.Add(internalFile.sortedPtrs[i]);
             }
         }
         StringWriter beta = new StringWriter();
         beta.WriteLine("Header:");
         beta.WriteLine(ASCIIEncoding.ASCII.GetString(internalFile.splitData[0], 0, 4).Replace("\0", ""));
         for (int i = 4; i < internalFile.splitData[0].Length; i++)
         {
             if (internalFile.sortedPtrLocs.Contains(i))
             {
                 if (i != 4)
                 {
                     beta.WriteLine();
                 }
                 beta.Write(BitConverter.ToString(internalFile.splitData[0], i, 4).Replace("-", ""));
                 beta.WriteLine(" -- pointer to (" + (condensedPointers.IndexOf(BitConverter.ToInt32(internalFile.splitData[0], i)) + 1) + ")");
                 i += 3;
             }
             else
             {
                 beta.Write(BitConverter.ToString(internalFile.splitData[0], i, 1));
             }
         }
         beta.WriteLine();
         beta.WriteLine();
         //for (int i = 0; i < bigassfile.Length; i++)
         //    beta.WriteLine(bigassfile[i]);
         bool previousPtr = true;
         int  displayNum  = 1;
         for (int i = 1; i < internalFile.splitData.Length; i++)
         {
             if (internalFile.splitData[i].Length > 0)
             {
                 beta.WriteLine("(" + displayNum + ")");
                 displayNum++;
                 previousPtr = true;
                 int lineLength = 0;
                 for (int j = 0; j < internalFile.splitData[i].Length; j++)
                 {
                     if (internalFile.sortedPtrLocs.Contains(internalFile.sortedPtrs[i - 1] + j))
                     {
                         if (!previousPtr)
                         {
                             beta.WriteLine();
                         }
                         beta.Write(BitConverter.ToString(internalFile.splitData[i], j, 4).Replace("-", ""));
                         beta.WriteLine(" -- pointer to (" + (condensedPointers.IndexOf(BitConverter.ToInt32(internalFile.splitData[i], j)) + 1) + ")");
                         //beta.WriteLine(" -- pointer to (" + Array.IndexOf(internalFile.sortedPtrLocs, internalFile.sortedPtrLocs[i] + j) + ")");
                         j          += 3;
                         previousPtr = true;
                         lineLength  = 0;
                     }
                     else
                     {
                         previousPtr = false;
                         beta.Write(BitConverter.ToString(internalFile.splitData[i], j, 1));
                         lineLength++;
                         if (lineLength % 4 == 0)
                         {
                             beta.Write(" ");
                         }
                         if (lineLength == 16)
                         {
                             beta.WriteLine();
                             lineLength = 0;
                         }
                     }
                 }
                 beta.WriteLine();
                 beta.WriteLine();
             }
         }
         richTextBox1.Text = beta.ToString();
     }
 }
        private List <int> condensedPointers;          //Utility to avoid having to jump around in the file constantly.

        public PointeredFileViewer(PointeredFile toImport)
        {
            InitializeComponent();
            internalFile      = toImport;
            richTextBox1.Text = "";
            if (internalFile.splitData != null)
            {
                condensedPointers = new List <int>(internalFile.destinationToPointers.Keys);
                condensedPointers.Sort();
                beta            = new StringWriter();
                pointerLineRefs = new Dictionary <int, int>();
                pointedLineRefs = new Dictionary <int, int>(); pointedLineRefs.Add(0, 0);
                writerLine      = 0;

                writeTrackedLine("Header:");
                writeTrackedLine(ASCIIEncoding.ASCII.GetString(internalFile.splitData[0].contents, 0, 4).Replace("\0", ""));
                for (int i = 4; i < internalFile.splitData[0].contents.Length; i++)
                {
                    if (internalFile.pointerToDestination.ContainsKey(i))
                    {
                        if (i != 4)
                        {
                            writeTrackedLine();
                        }
                        uint ptr   = (uint)internalFile.pointerToDestination[i];
                        uint index = ptr;
                        pointerLineRefs.Add(i, writerLine);
                        if (!internalFile.isBigEndian)
                        {
                            ptr = PointeredFile.ReverseBytes(ptr);
                        }
                        beta.Write(ptr.ToString("X8").Replace("-", ""));
                        writeTrackedLine(" -- pointer to (" + (condensedPointers.IndexOf((int)index) + 1) + ")");
                        i += 3;
                    }
                    else
                    {
                        beta.Write(BitConverter.ToString(internalFile.splitData[0].contents, i, 1));
                    }
                }
                writeTrackedLine();
                writeTrackedLine();

                bool previousPtr    = true;
                int  displayNum     = 1;
                int  currentAddress = internalFile.splitData[1].chunkLocation;
                for (int i = 1; i < internalFile.splitData.Count; i++)
                {
                    pointedLineRefs.Add(i, writerLine);
                    if (internalFile.splitData[i].contents.Length > 0)
                    {
                        writeTrackedLine("(" + displayNum + ")");
                        displayNum++;
                        previousPtr = true;
                        int lineLength = 0;
                        for (int j = 0; j < internalFile.splitData[i].contents.Length; j++)
                        {
                            if (internalFile.pointerToDestination.ContainsKey(currentAddress))
                            {
                                if (!previousPtr)
                                {
                                    writeTrackedLine();
                                }
                                uint ptr   = (uint)internalFile.pointerToDestination[currentAddress];
                                uint index = ptr;
                                pointerLineRefs.Add(currentAddress, writerLine);
                                if (!internalFile.isBigEndian)
                                {
                                    ptr = PointeredFile.ReverseBytes(ptr);
                                }
                                beta.Write(ptr.ToString("X8").Replace("-", ""));
                                writeTrackedLine(" -- pointer to (" + (condensedPointers.IndexOf((int)index) + 1) + ")");
                                j += 3;
                                currentAddress += 4;
                                previousPtr     = true;
                                lineLength      = 0;
                            }
                            else
                            {
                                previousPtr = false;
                                beta.Write(BitConverter.ToString(internalFile.splitData[i].contents, j, 1));
                                lineLength++;
                                if (lineLength % 4 == 0)
                                {
                                    beta.Write(" ");
                                }
                                if (lineLength == 16)
                                {
                                    writeTrackedLine();
                                    lineLength = 0;
                                }
                                currentAddress++;
                            }
                        }
                        writeTrackedLine();
                        writeTrackedLine();
                    }
                }
                richTextBox1.Text = beta.ToString();

                if (!internalFile.isBrokenFile)
                {
                    //Set up the treeview
                    TreeNode rootNode = new TreeNode();
                    rootNode.Text = "File root @ 0";
                    rootNode.Tag  = 0;
                    treeView1.Nodes.Insert(1, rootNode);

                    for (int i = 1; i < internalFile.splitData.Count; i++)
                    {
                        TreeNode treeNode = new TreeNode();
                        treeNode.Text = $"({i}) @ {internalFile.splitData[i].chunkLocation.ToString("X").Replace("-", "")}";
                        treeNode.Tag  = internalFile.splitData[i].chunkLocation;

                        treeView1.Nodes.Insert(treeView1.Nodes.Count + 1, treeNode);
                        populateSubPointersShallow(treeNode);
                    }
                }
            }
            else
            {
                condensedPointers = new List <int>();
            }
        }