Beispiel #1
0
        public void ReadFile()         //actually reads the file into filebytes
        {
            if (parentarcfile != null) //if it's an arc subfile
            {
                if (offset != 0)
                {
                    filebytes = new byte[size];
                    Array.Copy(parentarcfile.filebytes, offset, filebytes, 0, size);
                }

                DecompressFile();   //check for compression

                switch (Path.GetExtension(filename).ToLower())
                {
                case ".st":
                    ReadTextFileEPF();
                    break;

                case ".st2":
                    ReadTextFileHR();
                    break;
                }
            }
            else if (parentrdtfile != null)                         //if it's an rdt subfile
            {
                rdtSubfileData subfileTable = new rdtSubfileData(); //read this subfile's table
                int            overallIndex = 0;
                subfileTable.IndexInList = overallIndex;

                subfileTable.parentfile = this;
                subfileTable.ReadRawData(parentrdtfile.filebytes, offset);

                rdtSubfileDataList.Add(subfileTable);
                overallIndex++;

                if (subfileTable.filebytes == null || subfileTable.filebytes.Length == 0)
                {
                    return;
                }

                //now read the subfile table
                int numlists = BitConverter.ToInt32(subfileTable.filebytes, 0);  //number of lists e.g. 2: the list of centre bounds, the list of compressed files
                //Console.WriteLine(numlists);

                int curOffset = 4;  //offset in subfile table filebytes

                //From what I can tell, the file offsets in an RDT initially lead to a table (beginning with ID 0x03),
                //which contains lists of file types. The first one tends to be a centre bounds etc file, describing the
                //sprite. The next list tends to contain LZ10 compressed stuff, where the first file is the offset of
                //animation metadata. Then, frame durations. Then after that, it's the offsets of alternating
                //palettes and sprites. All these offsets are relative to the start of the RDT, which is a pain...

                for (int i = 0; i < numlists; i++)
                {
                    int countInList = BitConverter.ToUInt16(subfileTable.filebytes, curOffset);
                    curOffset += 2;
                    for (int f = 0; f < countInList; f++)
                    {
                        rdtSubfileData newSubfile = new rdtSubfileData();
                        newSubfile.IndexInList = overallIndex;
                        newSubfile.parentfile  = this;
                        newSubfile.ReadRawData(parentrdtfile.filebytes, BitConverter.ToInt32(subfileTable.filebytes, curOffset));
                        overallIndex++;

                        if (f == 0)
                        {
                            newSubfile.graphicsType = "GraphicsMetadata";
                        }
                        else if (f == 1)
                        {
                            newSubfile.graphicsType = "GraphicsFrameDurations";
                        }

                        if (f > 1)
                        {
                            if (f % 2 == 0)
                            {
                                newSubfile.graphicsType = "palette";
                            }
                            else
                            {
                                newSubfile.graphicsType = "image";
                            }
                        }

                        newSubfile.Parse();
                        rdtSubfileDataList.Add(newSubfile);
                        curOffset += 4;
                    }
                }

                filebytes = new Byte[1];    //set dummy filebytes so that this file registers as read by EPFExplorer
            }
        }