Example #1
0
        static void EnsureGameSelection()
        {
            if (NPK.CurrentKey != null)
            {
                return;
            }

            int Custom  = 0;
            int Current = 0;

            if (Games.Length > 1)
            {
                foreach (var Game in Games)
                {
                    Console.WriteLine($"Type {Current++} to \"{Game.Game}\"");
                }

                Console.WriteLine($"Type {Custom = Current} to manually specify a encryption key.");

                while (!int.TryParse(Console.ReadLine(), out Current))
                {
                    continue;
                }
            }

            if (Current == Custom)
            {
                Console.WriteLine("Type the 256bits key hex:");
                NPK.SetKey(Console.ReadLine());
                Console.WriteLine("Use what encoding to read the NPK? (UTF8/SJIS)");
                NPK.SetEncoding(Console.ReadLine());
                return;
            }

            Console.WriteLine($"Game \"{Games[Current].Game}\" Selected");
            NPK.CurrentKey         = Games[Current].Key;
            NPK.Encoding           = Games[Current].Encoding;
            NPK.NPKVersion         = Games[Current].NPKVersion;
            NPK.EnableSegmentation = Games[Current].NPKSegmentation;
            NPK.NPKMinorVersion    = Games[Current].NPKMinorVersion;
        }
Example #2
0
        static void Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            //System.Diagnostics.Debugger.Launch();

            Console.OutputEncoding = Encoding.Unicode;
            Console.Title          = "NPK3Tool - By Marcussacana";

            if (args == null || args.Length == 0)
            {
                args = new[] { "-h" }
            }
            ;

            for (int i = 0; i < args.Length; i++)
            {
                var flag = args[i].ToLower().TrimStart('-', '/', '\\');
                switch (flag)
                {
                case "h":
                case "?":
                case "help":
                    Console.WriteLine("Usage:");
                    Console.WriteLine($"{CurrentExe} [Options] -u Input.npk OutDir");
                    Console.WriteLine($"{CurrentExe} [Options] -r InputDir Output.npk");
                    Console.WriteLine();
                    Console.WriteLine("Options:");
                    Console.WriteLine("-IV [128bit hex]\t\t\tSet the repack IV");
                    Console.WriteLine("-MS 0x20000\t\t\t\tSet the NPK section Size");
                    Console.WriteLine("-EC UTF8\t\t\t\tSet the NPK filename encoding");
                    Console.WriteLine("-KY [256bit hex]\t\t\tSet a custom encyption key");
                    Console.WriteLine("-VS [3/2]\t\t\t\tSet the NPK repack version");
                    Console.WriteLine("-MV [1/2]\t\t\t\tSet the NPK repack minor version");
                    Console.WriteLine("-SG [1/0]\t\t\t\tEnable/Disable NPK Segmentation");
                    Console.WriteLine("-CP [1/0]\t\t\t\tEnable/Disable NPK Compression");
                    Console.WriteLine("-GM 0\t\t\t\t\tSet the NPK Game ID");
                    Console.WriteLine();
                    Console.WriteLine("Valid Game IDs:");
                    for (int x = 0; x < Games.Length; x++)
                    {
                        Console.WriteLine($"{x}: {Games[x].Game}");
                    }

                    Console.WriteLine();
                    Console.WriteLine("It's hard?");
                    Console.WriteLine("... then just Drag&Drop");
                    Console.WriteLine();
                    Console.WriteLine("Debug:");
                    Console.WriteLine("-DumpTable Input.npk\t\t\tDump File Table from the NPK");
                    Console.ReadKey();
                    break;

                case "u":
                    EnsureGameSelection();
                    NPK.Unpack(args[++i], args[++i]);
                    break;

                case "r":
                    EnsureGameSelection();
                    NPK.Repack(args[++i], args[++i]);
                    break;

                case "iv":
                    NPK.SetIV(args[++i]);
                    break;

                case "ms":
                    NPK.SetMaxSectionSize(args[++i]);
                    break;

                case "ec":
                    NPK.SetEncoding(args[++i]);
                    break;

                case "ky":
                    NPK.SetKey(args[++i]);
                    break;

                case "vs":
                    if (int.TryParse(args[++i], out int VS))
                    {
                        if (VS != 2 && VS != 3)
                        {
                            Console.WriteLine("Unsupported NPK Version");
                            continue;
                        }
                        NPK.NPKVersion = VS;
                    }
                    break;

                case "mv":
                    if (uint.TryParse(args[++i], out uint MV))
                    {
                        NPK.NPKMinorVersion = MV;
                    }
                    break;

                case "sg":
                    string SG = args[++i].Trim().ToLower();
                    NPK.EnableSegmentation = SG == "1" || SG == "true" || SG == "yes" || SG == "y";
                    break;

                case "cp":
                    string CP = args[++i].Trim().ToLower();
                    NPK.EnableCompression = CP == "1" || CP == "true" || CP == "yes" || CP == "y";
                    break;

                case "gm":
                    if (int.TryParse(args[++i], out int GM))
                    {
                        NPK.CurrentKey         = Games[GM].Item2;
                        NPK.Encoding           = Games[GM].Item3;
                        NPK.NPKVersion         = Games[GM].Item4;
                        NPK.EnableSegmentation = Games[GM].Item5;
                        NPK.NPKMinorVersion    = Games[GM].Item6;
                    }
                    break;

                case "dumptable":
                    EnsureGameSelection();
                    using (var Input = File.Open(args[++i], FileMode.Open))
                        using (var Output = File.Create(args[i] + ".tbl"))
                        {
                            NPK.CurrentIV = Input.ReadBytes(8, 0x10);
                            var Table = NPK.GetEntryTable(Input);
                            Table.Position = 0;
                            Table.CopyTo(Output);
                        }
                    break;

                default:
                    if (File.Exists(args[i]))
                    {
                        EnsureGameSelection();
                        NPK.Unpack(args[i]);
                    }
                    else if (Directory.Exists(args[i]))
                    {
                        EnsureGameSelection();
                        NPK.Repack(args[i]);
                    }
                    break;
                }
            }
        }