Exemple #1
0
 static void ExportPTP(GameFile objectFile, string value, string openedFileDir, Parameters parameters)
 {
     if (objectFile.GameData is BMD bmd)
     {
         string path = Path.Combine(openedFileDir, Path.GetFileNameWithoutExtension(objectFile.Name.Replace('/', '+')) + ".PTP");
         PTP    PTP  = new PTP(bmd);
         if (parameters.CopyOld2New)
         {
             PTP.CopyOld2New(Static.OldEncoding());
         }
         File.WriteAllBytes(path, PTP.GetData());
     }
 }
Exemple #2
0
        static void ExportText(GameFile objectFile, string value, string openedFileDir, Parameters parameters)
        {
            if (objectFile.GameData is PTP ptp)
            {
                string path = value == "" ? Path.Combine(openedFileDir, Path.GetFileNameWithoutExtension(objectFile.Name) + ".TXT") : value;
                var    exp  = ptp.ExportTXT(parameters.RemoveSplit, Static.OldEncoding()).Select(x => $"{objectFile.Name}\t{x}");

                File.AppendAllLines(path, exp);
            }
            else if (objectFile.GameData is StringList strlst)
            {
                string   path = value == "" ? Path.Combine(openedFileDir, Path.GetFileNameWithoutExtension(objectFile.Name) + ".TXT") : value;
                string[] exp  = strlst.ExportText();

                File.AppendAllLines(path, exp);
            }
        }
Exemple #3
0
        static void Test(string[] args)
        {
            string testPath = @"d:\Persona 5\DATA_PS3_JAP\";
            var    par      = new Parameters(new string[][] { new string[] { "/sub" } });
            var    files    = Directory.EnumerateFiles(testPath, "*.*", SearchOption.AllDirectories).ToArray();
            int    index    = 0;

            foreach (var filePath in files)
            {
                Console.Write($"{index++}/{files.Length}\r");

                var OpenedFileDir = Path.GetDirectoryName(filePath);
                if (new FileInfo(filePath).Length > 10000000)
                {
                    continue;
                }
                GameFile file = GameFormatHelper.OpenFile(Path.GetFileName(filePath), File.ReadAllBytes(filePath));
                if (file != null)
                {
                    SubFileAction((a, b, c, d) =>
                    {
                        try
                        {
                            if (a.GameData is BMD bmd)
                            {
                                PTP ptp     = new PTP(bmd);
                                var newName = a.Name.Replace('/', '+');
                                string path = Path.Combine(c, Path.GetFileNameWithoutExtension(newName) + ".TXT");

                                var exp = ptp.ExportTXT(true, Static.OldEncoding());
                                File.WriteAllLines(path, exp);
                            }
                        }
                        catch { }
                    }, file, "", OpenedFileDir, par);
                }
            }
        }
Exemple #4
0
        static void ImportText(GameFile objectFile, string value, string openedFileDir, Parameters parameters)
        {
            if (objectFile.GameData is PTP ptp)
            {
                string path = value == "" ? Path.Combine(openedFileDir, Path.GetFileNameWithoutExtension(objectFile.Name) + ".TXT") : value;

                if (File.Exists(path))
                {
                    List <string[]> import = File.ReadAllLines(path, parameters.FileEncoding).Select(x => x.Split('\t')).ToList();

                    LineMap MAP = new LineMap(parameters.Map);

                    if (parameters.LineByLine)
                    {
                        if (MAP[LineMap.Type.NewText] >= 0)
                        {
                            string[] importedText = import
                                                    .Select(x => x[MAP[LineMap.Type.NewText]])
                                                    .ToArray();
                            ptp.ImportTextLBL(importedText);
                        }
                    }
                    else
                    {
                        if (MAP[LineMap.Type.FileName] >= 0
                            & MAP[LineMap.Type.MSGindex] >= 0
                            & MAP[LineMap.Type.StringIndex] >= 0
                            & MAP[LineMap.Type.NewText] >= 0)
                        {
                            string[][] importedText = import
                                                      .Where(x => x.Length >= MAP.MinLength)
                                                      .Where(x => x[MAP[LineMap.Type.FileName]].Equals(objectFile.Name, StringComparison.CurrentCultureIgnoreCase))
                                                      .Where(x => x[MAP[LineMap.Type.NewText]] != "")
                                                      .Select(x => new string[]
                            {
                                x[MAP[LineMap.Type.MSGindex]],
                                x[MAP[LineMap.Type.StringIndex]],
                                x[MAP[LineMap.Type.NewText]]
                            })
                                                      .ToArray();

                            if (parameters.Width > 0)
                            {
                                var charWidth = Static.NewFont().GetCharWidth(Static.NewEncoding());
                                ptp.ImportText(importedText, charWidth, parameters.Width);
                            }
                            else
                            {
                                ptp.ImportText(importedText);
                            }
                        }
                    }

                    if (MAP[LineMap.Type.OldName] >= 0 & MAP[LineMap.Type.NewName] >= 0)
                    {
                        Dictionary <string, string> importedText = import
                                                                   .Where(x => x.Length >= MAP.MinLength)
                                                                   .GroupBy(x => x[MAP[LineMap.Type.OldName]])
                                                                   .ToDictionary(x => x.Key, x => x.First()[MAP[LineMap.Type.NewName]]);
                        ptp.ImportNames(importedText, Static.OldEncoding());
                    }
                }
            }
            else if (objectFile.GameData is StringList strlst)
            {
                string path = value == "" ? Path.Combine(openedFileDir, Path.GetFileNameWithoutExtension(objectFile.Name) + ".TXT") : value;
                if (File.Exists(path))
                {
                    string[][] importedtext = File.ReadAllLines(path, parameters.FileEncoding).Select(x => x.Split('\t')).
                                              Where(x => x.Length > 1 && x[1] != "").ToArray();
                    strlst.ImportText(importedtext);
                }
            }
        }
Exemple #5
0
        public static void FindIncorrectString(string PTPdir, string txtFile)
        {
            string temp = PTPdir;

            byte[] searchArray = new byte[] { 0xF1, 0x25 };

            string[] Files = Directory.GetFiles(temp, "*.ptp", SearchOption.AllDirectories);

            List <string> returned = new List <string>();

            string DIRtemp = "";

            foreach (var file in Files)
            {
                PTP PTP = null;

                try { PTP = new PTP(File.ReadAllBytes(file)); }
                catch { continue; }

                foreach (var msg in PTP.Msg)
                {
                    foreach (var str in msg.Strings)
                    {
                        var tempPrefix = str.Prefix.FirstOrDefault(x => x.Data.SequenceEqual(searchArray));
                        if (tempPrefix.Data != null)
                        {
                            string DIR = IOTools.RelativePath(Path.GetDirectoryName(file), temp);
                            if (DIRtemp != DIR)
                            {
                                DIRtemp = DIR;
                                returned.Add("");
                            }
                            string FILE        = Path.GetFileName(file);
                            string MSGINDEX    = msg.Index.ToString();
                            string STRINGINDEX = str.Index.ToString();

                            returned.Add($"{DIR}\t{FILE}\t{MSGINDEX}\t{STRINGINDEX}\t{str.OldString.GetString(Static.OldEncoding(), false).Replace('\n', ' ')}");
                        }
                    }
                }
            }

            File.WriteAllLines(txtFile, returned);
        }