Esempio n. 1
0
        private static void Extract(string fileName)
        {
            sceModule sceModule = new sceModule(fileName);

            if (!sceModule.isHaveText())
            {
                return;
            }
            string path = !(Path.GetDirectoryName(fileName) != "") ? Environment.CurrentDirectory + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".txt" : Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".txt";

            Console.WriteLine(string.Format("Extracting {0}...", Path.GetFileName(fileName)));

            if (jpcodes == null || dumpRaw)
            {
                ExtractRaw(fileName, sceModule);
                return;
            }

            if (dumpCount)
            {
                ExtractCount(fileName, sceModule);
                return;
            }

            if (codes == null)
            {
                MiscUtils.Warn("No CODES.txt file! Special sequences will be ignored, output can get messy!");
            }

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

            for (int idx = 0; idx < sceModule.Count; ++idx)
            {
                string str = sceModule.GetStringBlock(idx);
                if (codes != null)
                {
                    str = codes.ConvertNativeToTags(str);
                }

                if (jpcodes != null)
                {
                    str = jpcodes.ConvertAtoB(str);
                }
                stringList.Add(HexToAnsi(str));
                stringList.Add("[ENDBLOCK]");
            }

            if (useSJIS)
            {
                File.WriteAllLines(path, stringList.ToArray(), SJIS);
            }
            else
            {
                File.WriteAllLines(path, stringList.ToArray());
            }
        }
Esempio n. 2
0
        private static void RepackRaw(string path, sceModule sceModule)
        {
            byte[] dump          = File.ReadAllBytes(path);
            string hexStringDump = BitConverter.ToString(dump).Replace("-", string.Empty);

            string[] hexDump = hexStringDump.Split(new[] { AnsiToHex("\r\n[ENDBLOCK]\r\n") }, StringSplitOptions.None);

            if (hexDump[hexDump.Length - 1].Equals(string.Empty))
            {
                Array.Resize(ref hexDump, hexDump.Length - 1);
            }

            for (int index = 0; index < hexDump.Length; ++index)
            {
                sceModule.SetBlock(index, HexToArrayByte(hexDump[index]));
            }
            sceModule.Save();
            sceModule.Dispose();
            return;
        }
Esempio n. 3
0
        private static void ExtractRaw(string fileName, sceModule sceModule)
        {
            string path;

            if (Path.GetDirectoryName(fileName) == "")
            {
                path = Environment.CurrentDirectory + "\\" + Path.GetFileNameWithoutExtension(fileName) + "_raw.txt";
            }
            else
            {
                path = Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName) + "_raw.txt";
            }

            List <byte> dump = new List <byte>();

            for (int idx = 0; idx < sceModule.Count; ++idx)
            {
                dump.AddRange(sceModule.GetBlock(idx));
                dump.AddRange(Encoding.ASCII.GetBytes("\r\n[ENDBLOCK]\r\n"));
            }
            File.WriteAllBytes(path, dump.ToArray());
            return;
        }
Esempio n. 4
0
        private static void ExtractCount(string fileName, sceModule sceModule)
        {
            string path;

            if (Path.GetDirectoryName(fileName) == "")
            {
                path = Environment.CurrentDirectory + "\\" + Path.GetFileNameWithoutExtension(fileName) + "_count.txt";
            }
            else
            {
                path = Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName) + "_count.txt";
            }

            List <string> byteInfo = new List <string>();
            int           total    = 0;
            bool          switch1  = true;

            for (int idx = 0; idx < sceModule.Count; ++idx)
            {
                total += sceModule.GetBlock(idx).Length;
                if (total > 0xFFF && switch1)
                {
                    byteInfo.Add("-----------CUT POINT-----------------------");
                    byteInfo.Add("|       length average: " + (total / idx + 1));
                    byteInfo.Add("-----------CUT POINT-----------------------");
                    switch1 = false;
                }
                byteInfo.Add(string.Format("Block: {0:D3},", idx)
                             + string.Format(" Ptr: 0x{0:X6}", sceModule.Header.fileStrings[idx].myOffset)
                             + string.Format(" ({0:D}),", (int)sceModule.Header.fileStrings[idx].typeOffset)
                             + string.Format(" Text: 0x{0:X6}", sceModule.Header.fileStrings[idx].offset)
                             + string.Format(" | Line length: {0:D3}, ", sceModule.GetBlock(idx).Length)
                             + string.Format("total length: {0:D4}", total));
            }
            File.WriteAllLines(path, byteInfo.ToArray());
            return;
        }
Esempio n. 5
0
        private static void Repack(string fileName)
        {
            sceModule sceModule = new sceModule(fileName);

            //check if rsce has text beforehand
            if (!sceModule.isHaveText())
            {
                return;
            }

            string path;

            if (useAltPath)
            {
                path = altPath;
            }
            else
            {
                if (Path.GetDirectoryName(fileName) == "")
                {
                    path = Environment.CurrentDirectory + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".txt";
                }
                else
                {
                    path = Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".txt";
                }
            }

            if (!File.Exists(path))
            {
                MiscUtils.Die("The file \"" + Path.GetFileName(path) + "\" does not exist!");
            }

            //Echo!
            Console.WriteLine(string.Format("Repacking {0}...", Path.GetFileName(fileName)));

            if (jpcodes == null || dumpRaw)
            {
                RepackRaw(path, sceModule);
                return;
            }

            //Convert UTF-8 to SJIS, as it's easier to detect kanjis in SJIS
            byte[] temp;
            if (!useSJIS)
            {
                temp = Encoding.Convert(Encoding.UTF8, SJIS, File.ReadAllBytes(path));
            }
            else
            {
                temp = File.ReadAllBytes(path);
            }
            string[] stringSeparators = new string[] { "\r\n" };
            string[] strArray         = SJIS.GetString(temp).Split(stringSeparators, StringSplitOptions.None);

            //Can't ignore empty lines with the split (some lines might be blank in the source file)
            //but the last line can't be blank, so handle that here
            if (strArray[strArray.Length - 1].Equals(string.Empty))
            {
                Array.Resize(ref strArray, strArray.Length - 1);
            }

            List <string> stringList      = new List <string>();
            List <string> plainStringList = new List <string>();
            List <int>    lineNumberList  = new List <int>();
            int           lineNumber      = 0;
            int           blockLine       = 0;
            string        str             = "";

            for (int index = 0; index < strArray.Length; ++index)
            {
                if (strArray[index].StartsWith("//"))
                {
                    continue;
                }

                if (strArray[index].StartsWith("[ENDBLOCK]"))
                {
                    lineNumberList.Add(lineNumber - blockLine);
                    blockLine = 0;
                    stringList.Add(str);
                    plainStringList.Add(str.Replace("\r\n", "\\r\\n"));
                    str = "";
                }
                else
                {
                    if (strArray[index + 1].StartsWith("[ENDBLOCK]"))
                    {
                        str = str + strArray[index];
                    }
                    else
                    {
                        str = str + strArray[index] + "\r\n";
                        blockLine++;
                    }
                }
                lineNumber++;
            }

            //check if same ammount of lines are present
            if (sceModule.Header.fileStrings.Count != stringList.Count)
            {
                MiscUtils.Warn("Different amount of strings in the file!");
                MiscUtils.Warn("expected "
                               + sceModule.Header.fileStrings.Count + " but got "
                               + stringList.Count);
                MiscUtils.Warn("Packing anyway, but expect errors!");
                Console.WriteLine();
            }

            for (int index = 0; index < stringList.Count; ++index)
            {
                stringList[index] = AnsiToHex(stringList[index]);
            }
            if (jpcodes != null)
            {
                for (int index = 0; index < stringList.Count; ++index)
                {
                    stringList[index] = jpcodes.ConvertBtoA(stringList[index]);
                }
            }
            if (codes != null)
            {
                for (int index = 0; index < stringList.Count; ++index)
                {
                    stringList[index] = codes.ConvertTagsToNative(stringList[index]);
                }
            }
            else
            {
                MiscUtils.Warn("No CODES.txt file! If the file has replaced tags they will be inserted verbatim!");
            }

            int realLine    = 0;
            int skippedLine = 0;

            for (int index = 0; index < stringList.Count; ++index)
            {
                realLine++;
                while (stringList[index].StartsWith(AnsiToHex("<IGNORE>")))
                {
                    if (verbose)
                    {
                        MiscUtils.Info("Ignoring block " + realLine + " (around line " + lineNumberList[index] + ")...");
                    }

                    lineNumberList.RemoveAt(index);
                    plainStringList.RemoveAt(index);
                    sceModule.Header.fileStrings.RemoveAt(index);
                    stringList.RemoveAt(index);
                    realLine++;
                    skippedLine++;
                }
                sceModule.SetBlock(index, HexToArrayByte(stringList[index]), plainStringList, lineNumberList);
            }

            MiscUtils.Info("Ignored " + skippedLine + " blocks");
            Console.WriteLine();
            sceModule.Save(doDeduplication);
            sceModule.Dispose();
        }
Esempio n. 6
0
        private static void Repack(string fileName)
        {
            sceModule sceModule = new sceModule(fileName);

            //check if rsce has text beforehand
            if (!sceModule.isHaveText())
            {
                return;
            }

            string path = !(Path.GetDirectoryName(fileName) != "") ? Environment.CurrentDirectory + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".txt" : Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".txt";

            if (!File.Exists(path))
            {
                return;
            }

            //Echo!
            Console.WriteLine(string.Format("Repacking {0}...", Path.GetFileName(fileName)));

            if (jpcodes == null)
            {
                Console.WriteLine("No JPCODES.txt file! Assuming dump is raw...");
            }
            if (jpcodes == null || dumpRaw)
            {
                byte[] dump          = File.ReadAllBytes(path);
                string hexStringDump = System.BitConverter.ToString(dump).Replace("-", string.Empty);

                string[] hexDump = hexStringDump.Split(new[] { "0D0A5B454E44424C4F434B5D0D0A" /*"\r\n[ENDBLOCK]\r\n"*/ }, StringSplitOptions.None);

                if (hexDump[hexDump.Length - 1].Equals(String.Empty))
                {
                    Array.Resize(ref hexDump, hexDump.Length - 1);
                }

                for (int index = 0; index < hexDump.Length; ++index)
                {
                    sceModule.SetBlock(index, HexToArrayByte(hexDump[index]));
                }
                sceModule.Save();
                sceModule.Dispose();
                return;
            }

            //Convert UTF-8 to SJIS, as it's easier to detect kanjis in SJIS
            byte[] temp;
            if (!useSJIS)
            {
                temp = Encoding.Convert(Encoding.UTF8, SJIS, File.ReadAllBytes(path));
            }
            else
            {
                temp = File.ReadAllBytes(path);
            }
            string[] stringSeparators = new string[] { "\r\n" };
            string[] strArray         = SJIS.GetString(temp).Split(stringSeparators, StringSplitOptions.None);

            //Can't ignore empty lines with the split (some lines might be blank in the source file)
            //but the last line can't be blank, so handle that here
            if (strArray[strArray.Length - 1].Equals(String.Empty))
            {
                Array.Resize(ref strArray, strArray.Length - 1);
            }
            List <string> stringList = new List <string>();
            string        str        = "";

            for (int index = 0; index < strArray.Length; ++index)
            {
                if (strArray[index] == "[ENDBLOCK]")
                {
                    stringList.Add(str);
                    str = "";
                }
                else
                {
                    str = !(strArray[index + 1] != "[ENDBLOCK]") ? str + strArray[index] : str + strArray[index] + "\r\n";
                }
            }
            for (int index = 0; index < stringList.Count; ++index)
            {
                stringList[index] = AnsiToHex(stringList[index]);
            }
            if (jpcodes != null)
            {
                for (int index = 0; index < stringList.Count; ++index)
                {
                    stringList[index] = jpcodes.ConvertBtoA(stringList[index]);
                }
            }
            if (codes != null)
            {
                for (int index = 0; index < stringList.Count; ++index)
                {
                    stringList[index] = codes.ConvertTagsToNative(stringList[index]);
                }
            }
            else
            {
                Console.WriteLine("No CODES.txt file! If the file has replaced tags they will be inserted verbatim!");
            }

            for (int index = 0; index < stringList.Count; ++index)
            {
                sceModule.SetBlock(index, HexToArrayByte(stringList[index]));
            }
            sceModule.Save();
            sceModule.Dispose();
        }
Esempio n. 7
0
        private static void Extract(string fileName)
        {
            sceModule sceModule = new sceModule(fileName);

            if (!sceModule.isHaveText())
            {
                return;
            }
            string path      = !(Path.GetDirectoryName(fileName) != "") ? Environment.CurrentDirectory + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".txt" : Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".txt";
            string pathCount = !(Path.GetDirectoryName(fileName) != "") ? Environment.CurrentDirectory + "\\" + Path.GetFileNameWithoutExtension(fileName) + "_count.txt" : Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName) + "_count.txt";

            Console.WriteLine(string.Format("Extracting {0}...", Path.GetFileName(fileName)));

            if (jpcodes == null)
            {
                Console.WriteLine("No JPCODES.txt file! Dumping raw bytes...");
            }
            if (jpcodes == null || dumpRaw || dumpCount)
            {
                List <byte>   dump     = new List <byte>();
                List <string> byteInfo = new List <string>();
                int           total    = 0;
                bool          switch1  = true;
                for (int idx = 0; idx < sceModule.Count - 1; ++idx)
                {
                    if (dumpCount)
                    {
                        total += sceModule.GetBlock(idx).Length;
                        if (total > 0xFFF && switch1)
                        {
                            byteInfo.Add("-----------CUT POINT-----------------------");
                            byteInfo.Add("|       length average: " + (total / idx + 1));
                            byteInfo.Add("-----------CUT POINT-----------------------");
                            switch1 = false;
                        }
                        byteInfo.Add("Block: " + String.Format("{0:D3}", idx) + " | Line length: " + String.Format("{0:D3}", sceModule.GetBlock(idx).Length) + " total length: " + String.Format("{0:D4}", total));
                    }
                    else
                    {
                        dump.AddRange(sceModule.GetBlock(idx));
                        dump.Add(0x0D); dump.Add(0x0A);
                        dump.AddRange(Encoding.ASCII.GetBytes("[ENDBLOCK]"));
                        dump.Add(0x0D); dump.Add(0x0A);
                    }
                }
                if (dumpCount)
                {
                    File.WriteAllLines(pathCount, byteInfo.ToArray());
                }
                else
                {
                    File.WriteAllBytes(path, dump.ToArray());
                }
                return;
            }

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

            for (int idx = 0; idx < sceModule.Count; ++idx)
            {
                string str = sceModule.GetStringBlock(idx);
                if (codes != null)
                {
                    str = codes.ConvertNativeToTags(str);
                }
                else
                {
                    Console.WriteLine("No CODES.txt file! Special sequences will be ignored, output can get messy!");
                }
                if (jpcodes != null)
                {
                    str = jpcodes.ConvertAtoB(str);
                }
                stringList.Add(HexToAnsi(str));
                stringList.Add("[ENDBLOCK]");
            }
            if (useSJIS)
            {
                File.WriteAllLines(path, stringList.ToArray(), SJIS);
            }
            else
            {
                File.WriteAllLines(path, stringList.ToArray());
            }
        }