Beispiel #1
0
        private void ImportFontMap(String sourceFile, String xmlMap)
        {
            IDFStruct idfData;

            IDFCharStruct[] charsData;

            using (FileStream idfFS = new FileStream(sourceFile, FileMode.Open, FileAccess.Read))
                using (BinaryReader idfReader = new BinaryReader(idfFS))
                {
                    idfData = new IDFStruct(idfReader);

                    String xmlLine;
                    using (StreamReader xmlReader = new StreamReader(xmlMap))
                    {
                        xmlLine            = xmlReader.ReadLine();
                        idfData.CharsCount = Convert.ToInt16(this.GetParam("chars", xmlLine));

                        idfData.Unknown1 = Convert.ToInt16(this.GetParam("param1", xmlLine));
                        idfData.Unknown2 = Convert.ToInt16(this.GetParam("param2", xmlLine));
                        idfData.Unknown3 = Convert.ToInt16(this.GetParam("param3", xmlLine));

                        charsData = new IDFCharStruct[idfData.CharsCount];
                        for (int i = 0; i < idfData.CharsCount; ++i)
                        {
                            xmlLine = xmlReader.ReadLine();

                            charsData[i] = new IDFCharStruct();

                            charsData[i].CharID = Convert.ToInt32(this.GetParam("id", xmlLine));

                            charsData[i].LeftTopX = Convert.ToInt16(this.GetParam("x", xmlLine));
                            charsData[i].LeftTopY = Convert.ToInt16(this.GetParam("y", xmlLine));

                            charsData[i].Width  = Convert.ToByte(this.GetParam("width", xmlLine));
                            charsData[i].Height = Convert.ToByte(this.GetParam("height", xmlLine));

                            charsData[i].BearingX = Convert.ToByte(this.GetParam("bearingX", xmlLine));
                            charsData[i].BearingY = Convert.ToByte(this.GetParam("bearingY", xmlLine));

                            charsData[i].AdvanceX = Convert.ToByte(this.GetParam("advanceX", xmlLine));
                            charsData[i].AdvanceY = Convert.ToByte(this.GetParam("advanceY", xmlLine));
                        }
                    }
                }

            // Create new 48.dat
            using (FileStream xmlFS = new FileStream(sourceFile, FileMode.Create, FileAccess.Write))
                using (BinaryWriter xmlmapWriter = new BinaryWriter(xmlFS))
                {
                    xmlmapWriter.Write(idfData.Magic);
                    xmlmapWriter.Write(idfData.Unknown1);
                    xmlmapWriter.Write(idfData.Unknown2);
                    xmlmapWriter.Write(idfData.Unknown3);

                    byte[] tempChars = BitConverter.GetBytes(idfData.CharsCount);
                    Array.Reverse(tempChars);

                    xmlmapWriter.Write(tempChars);

                    for (int i = 0; i < idfData.CharsCount; ++i)
                    {
                        xmlmapWriter.Write(charsData[i].Width);
                        xmlmapWriter.Write(charsData[i].Height);

                        xmlmapWriter.Write(charsData[i].BearingY);
                        xmlmapWriter.Write(charsData[i].AdvanceY);

                        xmlmapWriter.Write(charsData[i].BearingX);
                        xmlmapWriter.Write(charsData[i].AdvanceX);

                        xmlmapWriter.Write(charsData[i].LeftTopX);
                        xmlmapWriter.Write(charsData[i].LeftTopY);
                    }

                    for (int i = 0; i < idfData.CharsCount; ++i)
                    {
                        xmlmapWriter.Write(charsData[i].CharID);
                    }
                }
        }
Beispiel #2
0
        public void Run()
        {
            output += "\\";
            String header = output + "HEADER.data";

            FileInfo file = new FileInfo(output);

            Directory.CreateDirectory(file.DirectoryName);

            using (FileStream fs = new FileStream(input, FileMode.Open, FileAccess.Read))
                using (BinaryReader data = new BinaryReader(fs))
                {
                    this.StatusText = "Getting PTR structure...";
                    OnProgressUpdate?.Invoke(this.CurrentProgress, this.TotalFiles, this.StatusText);

                    CPTRStruct cptr = new CPTRStruct(data);

                    byte[] compessedData       = data.ReadBytes((int)(data.BaseStream.Length - 0x10));
                    byte[] decompressedPTRData = this.DecompressData(ref compessedData);

                    using (BufferedStream stream = new BufferedStream(new FileStream(header, FileMode.Create, FileAccess.Write)))
                    {
                        stream.Write(decompressedPTRData, 0, decompressedPTRData.Length);
                    }

                    using (BinaryReader ptrData = new BinaryReader(new FileStream(header, FileMode.Open, FileAccess.Read)))
                    {
                        DPTRStruct  ptr   = new DPTRStruct(ptrData);
                        PKRStruct[] table = ptr.Files;

                        this.TotalFiles      = (int)ptr.FilesCount;
                        this.CurrentProgress = 0;
                        OnProgressUpdate?.Invoke(this.CurrentProgress, this.TotalFiles, this.StatusText);

                        using (FileStream pkrFS = new FileStream(pkrFile, FileMode.Open, FileAccess.Read))
                            using (BinaryReader pkr = new BinaryReader(pkrFS))
                            {
                                byte[]   pkrData;
                                string   outputFile;
                                FileInfo extractedFile;

                                for (int i = 0; i < ptr.FilesCount; ++i)
                                {
                                    this.CurrentProgress = i;
                                    OnProgressUpdate?.Invoke(this.CurrentProgress, this.TotalFiles, this.StatusText);

                                    pkr.BaseStream.Seek(table[i].Offset, SeekOrigin.Begin);

                                    if (ptr.Filenames.ElementAtOrDefault(table[i].NameID) != null)
                                    {
                                        this.StatusText = "Extracting: " + ptr.Filenames[table[i].NameID];
                                        OnProgressUpdate?.Invoke(this.CurrentProgress, this.TotalFiles, this.StatusText);

                                        outputFile = output + ptr.Filenames[table[i].NameID];
                                        pkrData    = pkr.ReadBytes(table[i].CompressedSize);

                                        if (table[i].CompressedSize != table[i].DecompressedSize)
                                        {
                                            pkrData = this.DecompressData(ref pkrData);
                                        }

                                        extractedFile = new FileInfo(outputFile);

                                        this.SaveData(ref pkrData, outputFile);

                                        pkrData = null;

                                        // File extension is lanb -> convert it.
                                        if (extractedFile.Extension.Equals(".lanb"))
                                        {
                                            this.StatusText = "Converting text file: " + ptr.Filenames[table[i].NameID];

                                            using (FileStream lanbFS = new FileStream(outputFile, FileMode.Open, FileAccess.Read))
                                                using (BinaryReader lanbReader = new BinaryReader(lanbFS))
                                                {
                                                    LABNStruct lanbData = new LABNStruct(lanbReader);

                                                    using (StreamWriter lanbWriter = new StreamWriter(outputFile + ".txt"))
                                                    {
                                                        for (int j = 0; j < lanbData.StringCount; ++j)
                                                        {
                                                            lanbWriter.WriteLine(lanbData.RowsName[j]);
                                                            lanbWriter.WriteLine(lanbData.RowsText[j]);
                                                        }
                                                    }
                                                }
                                        }
                                        // File name is 48.dat -> convert to xml map. (some games 64_df.dat)
                                        else if (extractedFile.Name.Equals("48.dat"))
                                        {
                                            this.StatusText = "Converting font map: " + ptr.Filenames[table[i].NameID];

                                            using (FileStream idfFS = new FileStream(outputFile, FileMode.Open, FileAccess.Read))
                                                using (BinaryReader idfReader = new BinaryReader(idfFS))
                                                {
                                                    IDFStruct       idfData   = new IDFStruct(idfReader);
                                                    IDFCharStruct[] charsData = idfData.CharsData;

                                                    using (StreamWriter lanbWriter = new StreamWriter(outputFile + ".xml"))
                                                    {
                                                        lanbWriter.WriteLine("<GeneralData " +
                                                                             "chars=\"" + idfData.CharsCount +
                                                                             "\" param1=\"" + idfData.Unknown1 +
                                                                             "\" param2=\"" + idfData.Unknown2 +
                                                                             "\" param3=\"" + idfData.Unknown3 + "\" />"
                                                                             );

                                                        for (int j = 0; j < charsData.Length; ++j)
                                                        {
                                                            lanbWriter.WriteLine("<Char " +
                                                                                 "id=\"" + charsData[j].CharID +
                                                                                 "\" x=\"" + charsData[j].LeftTopX +
                                                                                 "\" y=\"" + charsData[j].LeftTopY +
                                                                                 "\" width=\"" + charsData[j].Width +
                                                                                 "\" height=\"" + charsData[j].Height +
                                                                                 "\" bearingX=\"" + charsData[j].BearingX +
                                                                                 "\" bearingY=\"" + charsData[j].BearingY +
                                                                                 "\" advanceX=\"" + charsData[j].AdvanceX +
                                                                                 "\" advanceY=\"" + charsData[j].AdvanceY + "\" />"
                                                                                 );
                                                        }
                                                    }
                                                }
                                        }
                                    }
                                }
                            }
                    }
                }

            GC.Collect();
            GC.WaitForPendingFinalizers();

            this.StatusText      = "Done";
            this.CurrentProgress = this.TotalFiles;
            OnProgressUpdate?.Invoke(this.CurrentProgress, this.TotalFiles, this.StatusText);
        }