Example #1
0
        private static void PatchISO(KH1ISOReader input, KH1ISOWriter output, PatchManager files, bool ocompress,
                                     string oextHead)
        {
            int number = 1;

            output.writeHeader(oextHead);//Let's copy the header
            //Console.WriteLine("Adding header using {0} source",  ? "external" : "internal");//TODO: Delete this Console.WriteLine
            for (int i = 0, idxC = input.idxEntries.Count; i < idxC; ++i)
            {
                IDXEntry entry = input.idxEntries[i];
                if (entry.hash == 0x0392ebe4)
                {
                    continue;
                } //kingdom.img

                if (entry.hash == 0x0393eba4) //kingdom.idx
                {
                    Console.WriteLine("[KINGDOM: {0}/{1}]\tKINGDOM.IDX", number, input.idxEntries.Count - 1);
                    //-1 'cause of the file KINGDOM.IMG
                    number++;
                    output.writeDummyIDX(idxC);
                    continue;
                }

                //Loading the patch
                UInt32             flags = 0;
                PatchManager.Patch patch;
                Stream             s = null;
                uint h = 0;
                // Could make sure the parents match perfectly, but there's only 1 of every name anyway.
                // So I'll settle for just making sure the file isn't made for the ISO.
                if (Patches.patches.TryGetValue(entry.hash, out patch) && /*patch.Parent == parenthash*/ !patch.IsinISO)
                {
                    s = patch.Stream; h = patch.Hash;
                }
                string name;
                if (!HashList.pairs.TryGetValue(entry.hash, out name))
                {
                    name = String.Format("@noname/{0:x8}.bin", entry.hash);
                }
                if (s == null)
                {
                    flags = entry.flags;//FLAGS NEEDS TO BE OR 0 IF NOTHING, OR 1 IF COMPRESSED, OR THE NAME TO RELINK TO IF IT NEEDS TO

                    if (h != 0)
                    {
                        if (patch.Compressed)
                        {
                            flags = 1;
                        }
                        else if (patch.IsRelink)
                        {
                            flags = patch.Relink;
                        }
                    }

                    if (flags > 1)
                    {
                        Console.WriteLine("[KINGDOM: {0}/{1}]\t{2}\tRelinking...", number, input.idxEntries.Count - 1, name);     //-1 'cause of the file KINGDOM.IMG
                        number++;

                        /*if (!HashList.pairs.TryGetValue(flags, out name))
                         * {
                         *  name = String.Format("@noname/{0:x8}.bin", flags);
                         * }
                         * Console.WriteLine("{0}", name);*///Err...what is this crappy code? No but srsly
                        output.addRelink(entry.hash, flags);
                    }
                    else
                    {
                        Console.WriteLine("[KINGDOM: {0}/{1}]\t{2}", number, input.idxEntries.Count - 1, name);
                        //-1 'cause of the file KINGDOM.IMG
                        number++;
                        output.copyFile(entry);
                    }
                }
                else
                {
                    Console.WriteLine("[KINGDOM: {0}/{1}]\t{2}\tPatching...", number, input.idxEntries.Count - 1, name);     //-1 'cause of the file KINGDOM.IMG
                    number++;
                    output.importFile(s, entry.hash, flags);
                }
            }
            output.finalize();
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("New ISO finished!");
            Console.ResetColor();
        }
Example #2
0
        private static void Main(string[] args)
        {
            bool obatch = false;
            try
            {
                // Some functions work with raw bits, so we HAVE to be using little endian.
                // .NET, however, supports running the same code on both types.
                if (BitConverter.IsLittleEndian != true)
                {
                    throw new PlatformNotSupportedException(
                        "Platform not supported, not using a little endian bitconverter");
                }
                HashList.loadHashPairs();
                Console.Title = KH1ISOReader.program.ProductName + " " + KH1ISOReader.program.FileVersion + " [" +
                                KH1ISOReader.program.CompanyName + "]";
                bool ocompress = true, oupdateHeads = true, extract = false;
                string iso = "", oextHead = "", NewIso;

                #region Arguments

                for (int i = 0, argc = args.Length; i < argc; ++i)
                {
                    switch (args[i].ToLower())
                    {
                        case "-batch":
                            obatch = true;
                            break;
                        case "-nocompress":
                            ocompress = false;
                            break;
                        case "-extractor":
                            extract = true;
                            break;
                        case "-advancedinfo":
                            _advanced = true;
                            break;
            #if DEBUG
                        case "-noupisohead":
                            oupdateHeads = false;
                            break;
                        case "-externalhead":
                            if (++i < argc && (oextHead = args[i]).Length != 0)
                            {
                                break;
                            }
                            oextHead = "KH1ISOMake-head.bin";
                            break;
            #endif
                        case "-patchmaker":
                            KH1_Patch_Maker.Program.Mainp(args);
                            break;
                        default:
                            if (File.Exists(args[i]))
                            {
                                if (args[i].EndsWith(".iso", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    iso = args[i];
                                }
                                else if (args[i].EndsWith(".kh1patch", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    Patches.AddPatch(args[i]);
                                }
                            }
                            break;
                    }
                }

                #endregion

                #region Description
                using (var files = new PatchManager())
                {
                    if (iso.Length == 0)
                    {
                        iso = "KHFM.ISO";
                    }
                    Console.ForegroundColor = ConsoleColor.Gray;
                    DateTime Builddate = RetrieveLinkerTimestamp();
                    Console.Write("{0}\nBuild Date: {2}\nVersion {1}", KH1ISOReader.program.ProductName,
                        KH1ISOReader.program.FileVersion, Builddate);
                    Console.ResetColor();
            #if DEBUG
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write("\nPRIVATE RELEASE\n");
                    Console.ResetColor();
            #else
                Console.Write("\nPUBLIC RELEASE\n");
            #endif

                    Console.ForegroundColor = ConsoleColor.DarkMagenta;
                    Console.Write(
                        "\nProgrammed by {0}\nhttp://www.govanify.com\nhttp://www.twitter.com/GovanifY",
                        KH1ISOReader.program.CompanyName);
                    Console.ForegroundColor = ConsoleColor.Gray;
                    if (extract)
                    {
                        Console.Write(
                            "\n\nThis tool is able to extract the files of the game Kingdom Hearts 1(Final Mix).\nHe's using a list for extracting files with their real name which isn't completeBut this is the most complete one for now.\nHe can extract the files stored which got a reference into KINGDOM.IDX.\n\n");
                    }
                    else
                    {
                        Console.Write(
                            "\n\nThis tool is able to patch the game Kingdom Hearts 1(Final Mix).\nHe can modify iso files, like the elf and internal files,\nwich are stored inside the hidden file KINGDOM.IMG\nThis tool is recreating too new hashes into the idx files for avoid\na corrupted game. He can add some files too.\n\n");
                    }
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.Write("\nPress enter to run using the file:");
                    Console.ResetColor();
                    Console.Write(" {0}", iso);
                    Console.ReadLine();

                    #endregion

                    NewIso = Path.ChangeExtension(iso, "NEW.ISO");
                    using (var input = new KH1ISOReader(iso))
                    {
                        if (extract)
                        {
                            ExtractISO(iso, input);
                        }
                        else
                        {
                            if (Patches.patches.Count == 0)
                            {
                                WriteWarning("No patches loaded!");
                            }
                            else
                            {
                                try
                                {
                                    using (var output = new KH1ISOWriter(NewIso, input, oupdateHeads))
                                    {
                                        PatchISO(input, output, files, ocompress, oextHead);
                                    }
                                }
                                catch (Exception)
                                {
                                    //Delete the new "incomplete" iso
                                    File.Delete(NewIso);
                                    throw;
                                }
                            }
                        }
                    }
                }
            }
            catch (FileNotFoundException e)
            {
                WriteWarning("Failed to open file: " + e.Message);
            }
            catch (Exception e)
            {
                WriteWarning(
                    "An error has occured when trying to open your iso:\n{1}: {0}\n{2}",
                    e.Message, e.GetType().FullName, e.StackTrace);
            }
            Patches.Dispose();
            if (!obatch)
            {
                Console.Write("Press enter to exit..."); Console.ReadLine();
            }
        }
Example #3
0
        private static void Main(string[] args)
        {
            bool obatch = false;

            try
            {
                // Some functions work with raw bits, so we HAVE to be using little endian.
                // .NET, however, supports running the same code on both types.
                if (BitConverter.IsLittleEndian != true)
                {
                    throw new PlatformNotSupportedException(
                              "Platform not supported, not using a little endian bitconverter");
                }
                HashList.loadHashPairs();
                Console.Title = KH1ISOReader.program.ProductName + " " + KH1ISOReader.program.FileVersion + " [" +
                                KH1ISOReader.program.CompanyName + "]";
                bool   ocompress = true, oupdateHeads = true, extract = false;
                string iso = "", oextHead = "", NewIso;

                #region Arguments

                for (int i = 0, argc = args.Length; i < argc; ++i)
                {
                    switch (args[i].ToLower())
                    {
                    case "-batch":
                        obatch = true;
                        break;

                    case "-nocompress":
                        ocompress = false;
                        break;

                    case "-extractor":
                        extract = true;
                        break;

                    case "-advancedinfo":
                        _advanced = true;
                        break;

#if DEBUG
                    case "-noupisohead":
                        oupdateHeads = false;
                        break;

                    case "-externalhead":
                        if (++i < argc && (oextHead = args[i]).Length != 0)
                        {
                            break;
                        }
                        oextHead = "KH1ISOMake-head.bin";
                        break;
#endif
                    case "-patchmaker":
                        KH1_Patch_Maker.Program.Mainp(args);
                        break;

                    default:
                        if (File.Exists(args[i]))
                        {
                            if (args[i].EndsWith(".iso", StringComparison.InvariantCultureIgnoreCase))
                            {
                                iso = args[i];
                            }
                            else if (args[i].EndsWith(".kh1patch", StringComparison.InvariantCultureIgnoreCase))
                            {
                                Patches.AddPatch(args[i]);
                            }
                        }
                        break;
                    }
                }

                #endregion

                #region Description
                using (var files = new PatchManager())
                {
                    if (iso.Length == 0)
                    {
                        iso = "KHFM.ISO";
                    }
                    Console.ForegroundColor = ConsoleColor.Gray;
                    DateTime Builddate = RetrieveLinkerTimestamp();
                    Console.Write("{0}\nBuild Date: {2}\nVersion {1}", KH1ISOReader.program.ProductName,
                                  KH1ISOReader.program.FileVersion, Builddate);
                    Console.ResetColor();
#if DEBUG
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write("\nPRIVATE RELEASE\n");
                    Console.ResetColor();
#else
                    Console.Write("\nPUBLIC RELEASE\n");
#endif

                    Console.ForegroundColor = ConsoleColor.DarkMagenta;
                    Console.Write(
                        "\nProgrammed by {0}\nhttp://www.govanify.com\nhttp://www.twitter.com/GovanifY",
                        KH1ISOReader.program.CompanyName);
                    Console.ForegroundColor = ConsoleColor.Gray;
                    if (extract)
                    {
                        Console.Write(
                            "\n\nThis tool is able to extract the files of the game Kingdom Hearts 1(Final Mix).\nHe's using a list for extracting files with their real name which isn't completeBut this is the most complete one for now.\nHe can extract the files stored which got a reference into KINGDOM.IDX.\n\n");
                    }
                    else
                    {
                        Console.Write(
                            "\n\nThis tool is able to patch the game Kingdom Hearts 1(Final Mix).\nHe can modify iso files, like the elf and internal files,\nwich are stored inside the hidden file KINGDOM.IMG\nThis tool is recreating too new hashes into the idx files for avoid\na corrupted game. He can add some files too.\n\n");
                    }
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.Write("\nPress enter to run using the file:");
                    Console.ResetColor();
                    Console.Write(" {0}", iso);
                    Console.ReadLine();

                    #endregion

                    NewIso = Path.ChangeExtension(iso, "NEW.ISO");
                    using (var input = new KH1ISOReader(iso))
                    {
                        if (extract)
                        {
                            ExtractISO(iso, input);
                        }
                        else
                        {
                            if (Patches.patches.Count == 0)
                            {
                                WriteWarning("No patches loaded!");
                            }
                            else
                            {
                                try
                                {
                                    using (var output = new KH1ISOWriter(NewIso, input, oupdateHeads))
                                    {
                                        PatchISO(input, output, files, ocompress, oextHead);
                                    }
                                }
                                catch (Exception)
                                {
                                    //Delete the new "incomplete" iso
                                    File.Delete(NewIso);
                                    throw;
                                }
                            }
                        }
                    }
                }
            }
            catch (FileNotFoundException e)
            {
                WriteWarning("Failed to open file: " + e.Message);
            }
            catch (Exception e)
            {
                WriteWarning(
                    "An error has occured when trying to open your iso:\n{1}: {0}\n{2}",
                    e.Message, e.GetType().FullName, e.StackTrace);
            }
            Patches.Dispose();
            if (!obatch)
            {
                Console.Write("Press enter to exit..."); Console.ReadLine();
            }
        }
Example #4
0
        private static void PatchISO(KH1ISOReader input, KH1ISOWriter output, PatchManager files, bool ocompress,
            string oextHead)
        {
            int number = 1;
            output.writeHeader(oextHead);//Let's copy the header
            //Console.WriteLine("Adding header using {0} source",  ? "external" : "internal");//TODO: Delete this Console.WriteLine
            for (int i = 0, idxC = input.idxEntries.Count; i < idxC; ++i)
            {
                IDXEntry entry = input.idxEntries[i];
                if (entry.hash == 0x0392ebe4)
                {
                    continue;
                } //kingdom.img

                if (entry.hash == 0x0393eba4) //kingdom.idx
                {
                    Console.WriteLine("[KINGDOM: {0}/{1}]\tKINGDOM.IDX", number, input.idxEntries.Count - 1);
                        //-1 'cause of the file KINGDOM.IMG
                    number++;
                    output.writeDummyIDX(idxC);
                    continue;
                }

                //Loading the patch
                UInt32 flags = 0;
                PatchManager.Patch patch;
                Stream s = null;
                uint h = 0;
                // Could make sure the parents match perfectly, but there's only 1 of every name anyway.
                // So I'll settle for just making sure the file isn't made for the ISO.
                if (Patches.patches.TryGetValue(entry.hash, out patch) && /*patch.Parent == parenthash*/!patch.IsinISO) {s = patch.Stream; h = patch.Hash; }
                    string name;
                    if (!HashList.pairs.TryGetValue(entry.hash, out name))
                    {
                        name = String.Format("@noname/{0:x8}.bin", entry.hash);
                    }
                    if (s == null)
                    {
                    flags = entry.flags;//FLAGS NEEDS TO BE OR 0 IF NOTHING, OR 1 IF COMPRESSED, OR THE NAME TO RELINK TO IF IT NEEDS TO

                    if (h != 0)
                    {
                        if (patch.Compressed) { flags = 1; }
                        else if (patch.IsRelink) { flags = patch.Relink; }
                    }

                    if (flags > 1)
                        {
                            Console.WriteLine("[KINGDOM: {0}/{1}]\t{2}\tRelinking...", number, input.idxEntries.Count - 1, name); //-1 'cause of the file KINGDOM.IMG
                            number++;
                            /*if (!HashList.pairs.TryGetValue(flags, out name))
                            {
                                name = String.Format("@noname/{0:x8}.bin", flags);
                            }
                            Console.WriteLine("{0}", name);*///Err...what is this crappy code? No but srsly
                            output.addRelink(entry.hash, flags);
                        }
                        else
                        {
                            Console.WriteLine("[KINGDOM: {0}/{1}]\t{2}", number, input.idxEntries.Count - 1, name);
                                //-1 'cause of the file KINGDOM.IMG
                            number++;
                            output.copyFile(entry);
                        }
                    }
                    else
                    {
                        Console.WriteLine("[KINGDOM: {0}/{1}]\t{2}\tPatching...", number, input.idxEntries.Count - 1, name); //-1 'cause of the file KINGDOM.IMG
                        number++;
                            output.importFile(s, entry.hash, flags);
                    }
            }
            output.finalize();
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("New ISO finished!");
            Console.ResetColor();
        }