Exemple #1
0
        public static void Processor()
        {
            Console.Title = "PD_Tool: Converter Tools: DEX Converter";
            KKtMain.Choose(1, "dex", out string[] FileNames);

            DEXa Data = new DEXa();

            foreach (string file in FileNames)
            {
                Data = new DEXa {
                    filepath = file.Replace(Path.
                                            GetExtension(file), ""), ext = Path.GetExtension(file)
                };

                Console.Title = "PD_Tool: Converter Tools: DEX Reader: " + Path.GetFileNameWithoutExtension(file);
                switch (Data.ext.ToLower())
                {
                case ".dex":
                case ".bin":
                    Data.DEXReader();
                    Data.XMLWriter();
                    break;

                case ".xml":
                    Data.XMLReader();
                    Data.DEXWriter();
                    break;
                }
            }
        }
Exemple #2
0
        public static void Processor()
        {
            Console.Title = "PD_Tool: DB Converter";
            Console.Clear();
            KKtMain.ConsoleDesign(true);
            KKtMain.ConsoleDesign("         Choose type of DataBase file:");
            KKtMain.ConsoleDesign(false);
            KKtMain.ConsoleDesign("1. Auth DB Converter");
            KKtMain.ConsoleDesign(false);
            KKtMain.ConsoleDesign(true);
            Console.WriteLine();
            int.TryParse(Console.ReadLine(), NumberStyles.HexNumber, null, out format);
            string file = "";

            if (format == 1)
            {
                KKtMain.Choose(1, "bin", out string InitialDirectory, out string[] FileNames);
                foreach (string FileName in FileNames)
                {
                    file = Path.Combine(InitialDirectory, FileName);

                    string filepath = file.Replace(Path.GetExtension(file), "");
                    string ext      = Path.GetExtension(file).ToLower();

                    if (File.Exists(file))
                    {
                        if (ext == ".xml")
                        {
                            Auth.XMLReader(ref Auth.Data[0], filepath);
                            Auth.BINWriter(ref Auth.Data[0], filepath);
                        }
                        else if (ext == ".bin")
                        {
                            Auth.BINReader(ref Auth.Data[0], filepath);
                            Auth.XMLWriter(ref Auth.Data[0], filepath);
                        }
                        else
                        {
                            Console.WriteLine("File {0} doesn't exist!", Path.GetFileName(file));
                            Program.Exit();
                        }
                    }
                }
            }
            Console.Title = "PD_Tool";
        }
Exemple #3
0
        public static void Encrypt(int I, string file)
        {
            KKtIO reader = KKtIO.OpenReader(file);

            if (reader.ReadInt64() == 0x454C494641564944)
            {
                reader.Close();
                Decrypt(I, file);
            }
            else
            {
                Console.Title = "PD_Tool: DIVAFILE Encryptor - File: " + Path.GetFileName(file);
                int FileLenghtOrigin = (int)reader.Length;
                int FileLenght       = (int)KKtMain.Align((long)FileLenghtOrigin, 16);
                reader.Close();
                byte[] In      = File.ReadAllBytes(file);
                byte[] Inalign = new byte[FileLenght];
                for (int i = 0; i < In.Length; i++)
                {
                    Inalign[i] = In[i];
                }
                In = null;
                byte[] encrypted = new byte[FileLenght];
                using (AesManaged crypto = new AesManaged())
                {
                    crypto.Key     = Key;
                    crypto.IV      = new byte[16];
                    crypto.Mode    = CipherMode.ECB;
                    crypto.Padding = PaddingMode.Zeros;
                    using (CryptoStream cryptoData = new CryptoStream(new MemoryStream(Inalign),
                                                                      crypto.CreateEncryptor(crypto.Key, crypto.IV), CryptoStreamMode.Read))
                        cryptoData.Read(encrypted, 0, FileLenght);
                }
                KKtIO writer = KKtIO.OpenWriter(file, Inalign.Length);
                writer.Write(0x454C494641564944);
                writer.Write(FileLenght);
                writer.Write(FileLenghtOrigin);
                writer.Write(encrypted);
                writer.Close();
            }
            Console.Title = "PD_Tool";
        }
Exemple #4
0
        public static void BINWriter(ref AUTH Data, string file)
        {
            DateTime date = DateTime.Now;

            KKtIO writer = KKtIO.OpenWriter(file + ".bin", true);

            writer.Write("#A3DA__________\n");
            writer.Write("#" + KKtMain.ToTitleCase(date.ToString("ddd")) + " " + KKtMain.
                         ToTitleCase(date.ToString("MMM")) + " " + date.ToString("dd HH:mm:ss yyyy") + "\n");

            if (Data.Category != null)
            {
                SortWriter("category.", "", 10, Data.Category, ref writer);
                writer.Write("category.length=" + Data.Category.Length.ToString() + "\n");
            }

            if (Data.UID != null)
            {
                SortWriter("uid.", "", 10, Data.UID, ref writer);
                writer.Write("uid.length=" + Data.UID.Length.ToString() + "\n");
            }

            writer.Close();
        }
Exemple #5
0
        public static void Processor()
        {
            Console.Title = "PD_Tool: Converter Tools: A3DA Converter";
            KKtMain.Choose(1, "a3da", out string[] FileNames);

            bool MP = true;

            foreach (string file in FileNames)
            {
                if (file.EndsWith(".mp"))
                {
                    MP = false;
                    break;
                }
            }

            KKtMain.Format Format = KKtMain.Format.NULL;
            Console.Clear();
            KKtMain.ConsoleDesign(true);
            KKtMain.ConsoleDesign(" Choose type of format to export for MP files:");
            KKtMain.ConsoleDesign(false);
            KKtMain.ConsoleDesign("1. DT   PS3");
            KKtMain.ConsoleDesign("2. F    PS3/PSV");
            KKtMain.ConsoleDesign("3. FT   PS4");
            KKtMain.ConsoleDesign("4. F2nd PS3/PSV");
            KKtMain.ConsoleDesign("5. X    PS4/PSV");
            KKtMain.ConsoleDesign("6. MGF      PSV");
            if (MP)
            {
                KKtMain.ConsoleDesign("9. MessagePack");
            }
            KKtMain.ConsoleDesign(false);
            KKtMain.ConsoleDesign(true);
            Console.WriteLine();
            string a = Console.ReadLine();

            if (a == "1")
            {
                Format = KKtMain.Format.DT;
            }
            else if (a == "2")
            {
                Format = KKtMain.Format.F;
            }
            else if (a == "3")
            {
                Format = KKtMain.Format.FT;
            }
            else if (a == "4")
            {
                Format = KKtMain.Format.F2LE;
            }
            else if (a == "5")
            {
                Format = KKtMain.Format.X;
            }
            else if (a == "6")
            {
                Format = KKtMain.Format.MGF;
            }

            foreach (string file in FileNames)
            {
                try
                {
                    string ext      = Path.GetExtension(file);
                    string filepath = file.Replace(ext, "");
                    Console.Title = "PD_Tool: Converter Tools: A3DA Tools: " +
                                    Path.GetFileNameWithoutExtension(file);
                    KKtA3DA A = new KKtA3DA();
                    if (ext.ToLower() == ".a3da")
                    {
                        A.A3DAReader(filepath);
                    }
                    if (ext.ToLower() == ".mp")
                    {
                        A.MsgPackReader(filepath);
                    }

                    if (!MP || Format > KKtMain.Format.NULL)
                    {
                        A.IO = KKtLib.IO.OpenWriter(filepath + ".a3da", true);
                    }
                    if (Format > KKtMain.Format.NULL)
                    {
                        if (A.Data.Header.Format < KKtMain.Format.F2LE)
                        {
                            A.Data._.CompressF16 = Format == KKtMain.Format.MGF ? 2 : 1;
                        }
                        A.Data.Header.Format = Format;
                    }
                    if (!MP && A.Data.Header.Format > KKtMain.Format.DT && A.Data.Header.Format != KKtMain.Format.FT)
                    {
                        A.A3DCWriter(filepath);
                    }
                    else if (!MP || Format > KKtMain.Format.NULL)
                    {
                        A.A3DC = false;
                        A.A3DAWriter(filepath);
                    }
                    else
                    {
                        A.MsgPackWriter(filepath);
                    }
                }
                catch (Exception e)
                { Console.WriteLine(e); }
            }
        }
Exemple #6
0
        public void XMLReader()
        {
            DEX    = new EXP[0];
            Header = new KKtMain.Header();

            KKtXml Xml = new KKtXml();

            Xml.OpenXml(filepath + ".xml", true);
            Xml.Compact = true;
            int i = 0;

            foreach (XElement DEX_ in Xml.doc.Elements("DEX"))
            {
                foreach (XAttribute Entry in DEX_.Attributes())
                {
                    if (Entry.Name == "Format")
                    {
                        Enum.TryParse(Entry.Value, out Header.Format);
                    }
                    else if (Entry.Name == "Length")
                    {
                        DEX = new EXP[int.Parse(Entry.Value)];
                    }
                }
                foreach (XElement EXP in DEX_.Elements())
                {
                    if (EXP.Name != "EXP")
                    {
                        continue;
                    }

                    DEX[i] = new EXP {
                        Main = new List <EXPElement>(), Eyes = new List <EXPElement>()
                    };
                    foreach (XAttribute Entry in EXP.Attributes())
                    {
                        if (Entry.Name == "Name")
                        {
                            DEX[i].Name = Entry.Value;
                        }
                    }
                    foreach (XElement EXPElement in EXP.Elements())
                    {
                        if (EXPElement.Name == "Main" || EXPElement.Name == "Eyes")
                        {
                            foreach (XElement Element in EXPElement.Elements())
                            {
                                if (Element.Name != "Element")
                                {
                                    continue;
                                }

                                EXPElement element = new EXPElement();
                                foreach (XAttribute Entry in Element.Attributes())
                                {
                                    if (Entry.Name == "Frame")
                                    {
                                        element.Frame = KKtMain.ToDouble(Entry.Value);
                                    }
                                    if (Entry.Name == "Both")
                                    {
                                        element.Both = ushort.Parse(Entry.Value);
                                    }
                                    if (Entry.Name == "ID")
                                    {
                                        element.ID = ushort.Parse(Entry.Value);
                                    }
                                    if (Entry.Name == "Value")
                                    {
                                        element.Value = KKtMain.ToDouble(Entry.Value);
                                    }
                                    if (Entry.Name == "Trans")
                                    {
                                        element.Trans = KKtMain.ToDouble(Entry.Value);
                                    }
                                }
                                if (EXPElement.Name == "Main")
                                {
                                    DEX[i].Main.Add(element);
                                }
                                else if (EXPElement.Name == "Eyes")
                                {
                                    DEX[i].Eyes.Add(element);
                                }
                            }
                        }
                    }
                    i++;
                }
            }
        }
Exemple #7
0
        public void DEXWriter()
        {
            KKtIO writer = KKtIO.OpenWriter(filepath + (Header.Format > KKtMain.Format.F ? ".dex" : ".bin"), true);

            writer.Format = Header.Format;

            if (writer.Format > KKtMain.Format.F)
            {
                Header.Lenght      = 0x20;
                Header.DataSize    = 0x00;
                Header.Signature   = 0x43505845;
                Header.SectionSize = 0x00;
                writer.Write(Header);
            }

            writer.Write(0x64);
            writer.Write(DEX.Length);
            if (Header.Format == KKtMain.Format.X)
            {
                writer.Write(0x28);
                writer.Write(0x00);
                writer.Write(0x18 + (int)KKtMain.Align(DEX.Length * 3 * 8, 0x10));
                writer.Write(0x00);
                writer.Seek(KKtMain.Align(DEX.Length * 3 * 8, 0x10) + 0x20 + Header.Lenght, 0);
            }
            else
            {
                writer.Write(0x20);
                writer.Write(0x10 + (int)KKtMain.Align(DEX.Length * 3 * 4, 0x10));
                writer.Seek(KKtMain.Align(DEX.Length * 3 * 4, 0x10) + 0x30 + Header.Lenght, 0);
            }
            for (int i0 = 0; i0 < DEX.Length; i0++)
            {
                DEX[i0].MainOffset = writer.Position - Header.Lenght;
                for (int i1 = 0; i1 < DEX[i0].Main.Count; i1++)
                {
                    writer.Write((float)DEX[i0].Main[i1].Frame);
                    writer.Write(DEX[i0].Main[i1].Both);
                    writer.Write(DEX[i0].Main[i1].ID);
                    writer.Write((float)DEX[i0].Main[i1].Value);
                    writer.Write((float)DEX[i0].Main[i1].Trans);
                }
                writer.Align(0x20, true);

                DEX[i0].EyesOffset = writer.Position - Header.Lenght;
                for (int i1 = 0; i1 < DEX[i0].Eyes.Count; i1++)
                {
                    writer.Write((float)DEX[i0].Eyes[i1].Frame);
                    writer.Write(DEX[i0].Eyes[i1].Both);
                    writer.Write(DEX[i0].Eyes[i1].ID);
                    writer.Write((float)DEX[i0].Eyes[i1].Value);
                    writer.Write((float)DEX[i0].Eyes[i1].Trans);
                }
                writer.Align(0x20, true);
            }
            for (int i0 = 0; i0 < DEX.Length; i0++)
            {
                DEX[i0].NameOffset = writer.Position - Header.Lenght;
                writer.Write(DEX[i0].Name + "\0");
            }
            writer.Align(0x10, true);

            if (Header.Format == KKtMain.Format.X)
            {
                writer.Seek(Header.Lenght + 0x28, 0);
            }
            else
            {
                writer.Seek(Header.Lenght + 0x20, 0);
            }
            for (int i0 = 0; i0 < DEX.Length; i0++)
            {
                writer.Write(DEX[i0].MainOffset);
                if (Header.Format == KKtMain.Format.X)
                {
                    writer.Write(0x00);
                }
                writer.Write(DEX[i0].EyesOffset);
                if (Header.Format == KKtMain.Format.X)
                {
                    writer.Write(0x00);
                }
            }
            for (int i0 = 0; i0 < DEX.Length; i0++)
            {
                writer.Write(DEX[i0].NameOffset);
                if (Header.Format == KKtMain.Format.X)
                {
                    writer.Write(0x00);
                }
            }

            if (writer.Format > KKtMain.Format.F)
            {
                Offset = writer.Length - Header.Lenght;
                writer.Seek(writer.Length, 0);
                writer.WriteEOFC(0);
                writer.Seek(0, 0);
                Header.DataSize    = Offset;
                Header.SectionSize = Offset;
                writer.Write(Header);
            }
            writer.Close();
        }
Exemple #8
0
        public int STRReader()
        {
            KKtIO reader = KKtIO.OpenReader(filepath + ext);

            reader.Format    = KKtMain.Format.F;
            Header.Signature = reader.ReadInt32();
            if (Header.Signature == 0x41525453)
            {
                Header          = reader.ReadHeader(true);
                STR             = new List <String>();
                POF             = KKtMain.AddPOF(Header);
                reader.Position = Header.Lenght;

                Count  = reader.ReadInt32Endian();
                Offset = reader.ReadInt32Endian();
                if (Offset == 0)
                {
                    Offset         = Count;
                    OffsetX        = reader.ReadInt64();
                    Count          = reader.ReadInt64();
                    reader.XOffset = Header.Lenght;
                    reader.Format  = KKtMain.Format.X;
                }
                reader.LongPosition = reader.IsX ? Offset + reader.XOffset : Offset;

                for (int i = 0; i < Count; i++)
                {
                    String Str = new String
                    {
                        StrOffset = reader.GetOffset(ref POF).ReadInt32Endian(),
                        ID        = reader.ReadInt32Endian()
                    };
                    if (reader.IsX)
                    {
                        Str.StrOffset += (int)OffsetX;
                    }
                    STR.Add(Str);
                }
                for (int i = 0; i < Count; i++)
                {
                    reader.LongPosition = STR[i].StrOffset + (reader.IsX ? reader.XOffset : 0);
                    STR[i] = new String {
                        ID = STR[i].ID, Str = KKtText.
                                              ToUTF8(reader.NullTerminated()), StrOffset = STR[i].StrOffset
                    };
                }
                reader.Seek(POF.Offset, 0);
                reader.ReadPOF(ref POF);
            }
            else
            {
                reader.Seek(-4, (SeekOrigin)1);
                int i = 0;
                STR = new List <String>();
                while (reader.LongPosition > 0 && reader.LongPosition < reader.LongLength)
                {
                    int a = reader.ReadInt32();
                    if (a != 0)
                    {
                        reader.Seek(-4, (SeekOrigin)1);
                        STR.Add(new String {
                            Str = KKtText.ToUTF8(reader.NullTerminated()), ID = i
                        });
                        i++;
                    }
                    else
                    {
                        break;
                    }
                }
                Count = STR.Count;
            }

            reader.Close();
            return(1);
        }
Exemple #9
0
        static void MainMenu()
        {
            GC.Collect();
            ReturnCode = 0;

            KKtMain.ConsoleDesign(true);
            KKtMain.ConsoleDesign("                Choose action:");
            KKtMain.ConsoleDesign(false);
            KKtMain.ConsoleDesign("1. Extract FARC Archive");
            KKtMain.ConsoleDesign("2. Create  FARC Archive");
            KKtMain.ConsoleDesign("3. Decrypt from DIVAFILE");
            KKtMain.ConsoleDesign("4. Encrypt to   DIVAFILE");
            KKtMain.ConsoleDesign("5. DB_Tools");
            KKtMain.ConsoleDesign("6. Converting Tools");
            KKtMain.ConsoleDesign(false);
            KKtMain.ConsoleDesign(true);
            Console.WriteLine();

            function = Console.ReadLine().ToUpper();
            bool isNumber = int.TryParse(function, NumberStyles.HexNumber, null, out int result);

            if (function == "" || function == "Q")
            {
                Exit();
            }

            if (isNumber)
            {
                Functions("", 0);
            }
            else
            {
                ReturnCode = 1;
            }

            if (ReturnCode == 2)
            {
                Console.WriteLine("You must provide a path for file/directory!");
            }
            else if (ReturnCode == 31)
            {
                Console.WriteLine("This isn't file!");
            }
            else if (ReturnCode == 32)
            {
                Console.WriteLine("This isn't directory!");
            }
            else if (ReturnCode == 7)
            {
                Console.WriteLine("This file isn't PVSC!");
            }
            else if (ReturnCode == 81)
            {
                Console.WriteLine("This file isn't DIVAFILE!");
            }
            else if (ReturnCode == 82)
            {
                Console.WriteLine("This file isn't FARC Archive!");
            }
            else if (ReturnCode == 9)
            {
                Console.WriteLine("Ready.");
            }
            if (ReturnCode != 0)
            {
                Console.Read();
            }
        }
Exemple #10
0
        static bool Functions(string file, int code)
        {
            if (code != 0)
            {
                if (!Directory.Exists(file) && code != 1)
                {
                    ReturnCode = 0;
                    return(false);
                }
                else if (!File.Exists(file) && code != 1)
                {
                    ReturnCode = 0;
                    return(false);
                }
            }

            switch (function)
            {
            case "1":
            case "2":
                FARC.Processor(file, false, code, function == "1");
                break;

            case "3":
            case "4":
                KKtLib.FARC Farc = new KKtLib.FARC();
                if (Directory.Exists(file))
                {
                    Farc.Pack(file);
                }
                else if (File.Exists(file) && Path.GetExtension(file) == ".farc")
                {
                    Farc.UnPack(file, true);
                }
                else
                {
                    Console.Clear();
                    if (code != 1)
                    {
                        KKtMain.Choose(1, "", out string InitialDirectory, out string[] FileNames);
                        foreach (string FileName in FileNames)
                        {
                            DIVAFILEEncDec(0, Path.Combine(InitialDirectory, FileName), code);
                        }
                    }
                    else if (file != "")
                    {
                        DIVAFILEEncDec(0, file, code);
                    }
                    else
                    {
                        ReturnCode = 2;
                    }
                }
                break;

            case "5":
                Console.Clear();
                DB.DataBase.Processor();
                break;

            case "6":
                Console.Clear();
                Console.Title = "PD_Tool: Converter Tools";
                KKtMain.ConsoleDesign(true);
                KKtMain.ConsoleDesign("                 Choose tool:");
                KKtMain.ConsoleDesign(false);
                KKtMain.ConsoleDesign("1. A3DA Converter");
                KKtMain.ConsoleDesign("2. DEX Converter");
                KKtMain.ConsoleDesign("3. DSC Converter");
                KKtMain.ConsoleDesign("4. STR Converter");
                KKtMain.ConsoleDesign(false);
                KKtMain.ConsoleDesign(true);
                Console.WriteLine();
                string Function = Console.ReadLine();
                Console.Clear();
                switch (Function)
                {
                case "1":
                    Tools.A3D.Processor();
                    break;

                case "2":
                    Tools.DEX.Processor();
                    break;

                case "3":
                    DSC.Main.Processor();
                    break;

                case "4":
                    Tools.STR.Processor();
                    break;
                }
                Console.Clear();
                break;

            default:
                ReturnCode = 0;
                break;
            }
            Console.Title = "PD_Tool";


            if (code == 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #11
0
        public static void Processor(string file, bool Compression, int code, bool Extract)
        {
            KKtFARC FARC = new KKtFARC();

            Console.Clear();
            if (Extract)
            {
                Console.Title = "PD_Tool: FARC Extractor";
                KKtMain.Choose(1, "farc", out string InitialDirectory, out string[] FileNames);
                foreach (string FileName in FileNames)
                {
                    file = Path.Combine(InitialDirectory, FileName);
                    if (file != "" && File.Exists(file))
                    {
                        FARC.UnPack(file, true);
                    }
                    else if (!File.Exists(file))
                    {
                        Program.ReturnCode = 31;
                    }
                    else
                    {
                        Program.ReturnCode = 2;
                    }
                    GC.Collect();
                }
            }
            else
            {
                file = KKtMain.Choose(2, "", out string InitialDirectory, out string[] FileNames);
                Console.Clear();
                Console.Title = "PD_Tool: FARC Creator";
                if (file != "" && Directory.Exists(file))
                {
                    KKtMain.ConsoleDesign(true);
                    KKtMain.ConsoleDesign("         Choose type of created FARC:");
                    KKtMain.ConsoleDesign(false);
                    KKtMain.ConsoleDesign("1. FArc [DT/DT2nd/DTex/F/F2nd/X]");
                    KKtMain.ConsoleDesign("2. FArC [DT/DT2nd/DTex/F/F2nd/X] (Compressed)");
                    KKtMain.ConsoleDesign("3. FARC [F/F2nd/X] (Compressed)");
                    KKtMain.ConsoleDesign("4. FARC [FT] (Compressed)");
                    KKtMain.ConsoleDesign(false);
                    KKtMain.ConsoleDesign("Note: Creating FT FARCs currently not supported.");
                    KKtMain.ConsoleDesign(false);
                    KKtMain.ConsoleDesign(true);
                    Console.WriteLine();
                    Console.WriteLine("Choosed folder: {0}", file);
                    Console.WriteLine();
                    int.TryParse(Console.ReadLine(), out int type);
                    switch (type)
                    {
                    case 1:
                        FARC.Signature = KKtFARC.Farc.FArc;
                        break;

                    case 3:
                        FARC.Signature = KKtFARC.Farc.FARC;
                        break;

                    default:
                        FARC.Signature = KKtFARC.Farc.FArC;
                        break;
                    }
                    Console.Clear();
                    Console.Title = "PD_Tool: FARC Creator - Directory: " + Path.GetDirectoryName(file);
                    FARC.Pack(file);
                    GC.Collect();
                }
                else if (!Directory.Exists(file))
                {
                    Program.ReturnCode = 32;
                }
                else
                {
                    Program.ReturnCode = 2;
                }
                Console.Title = "PD_Tool: FARC Creator";
            }
        }