Example #1
0
        public static void LogFileData(string path, string comment = null)
        {
            if (!LoggingEnabled)
            {
                return;
            }

            var sb = new StringBuilder();

            try {
                sb.Append(Patcher.CalcMd5(path));
            } catch (Exception ex) {
                sb.Append(ex.ToString());
            }
            sb.Append('\t');
            sb.Append(path);

            if (comment != null)
            {
                sb.Append('\t');
                sb.Append(comment);
            }
            LogAny("patching.log", sb.ToString());
        }
Example #2
0
        public static void PatchElf(string ebootPath, string patchDir, string outDir, string outMd5 = null, BackgroundWorker worker = null)
        {
            string ebootModPath = Path.GetFullPath("ebootmod/ebootMOD.exe");

            ebootPath = Path.GetFullPath(ebootPath);
            patchDir  = Path.GetFullPath(patchDir);
            outDir    = Path.GetFullPath(outDir);

            if (!File.Exists(ebootPath))
            {
                throw new PatchingException("File not found: " + ebootPath);
            }
            if (worker != null)
            {
                worker.ReportProgress(0, "Confirming source file...");
            }
            Patcher.CompareMd5(ebootPath, "3171173bba33c43be95e840733ca40a8");

            // decrypt
            if (worker != null)
            {
                worker.ReportProgress(0, "Decrypting...");
            }
            string elfPath = Path.Combine(Path.GetDirectoryName(ebootModPath), Path.GetFileName(ebootPath) + "-mod.ELF");
            int    tries   = 5;

            while (!(File.Exists(elfPath) && Patcher.CalcMd5(elfPath) == "a424aa775b707539dbff08cdb2e61ff5"))
            {
                if (--tries < 0)
                {
                    throw new PatchingException("Could not decrypt EBOOT. Confirm that EBOOT is correctly ripped and ebootMOD is working correctly.");
                }

                // this is super ugly but the only sensible way since calling unself directly searches the keys who-knows-where
                try {
                    RunEbootModAndKill(ebootModPath, "\"" + ebootPath + "\"");
                } catch (Exception e) {
                    throw new PatchingException("Failed during execution of ebootMOD. Make sure you copied _everything_ from the ebootmod archive into the ebootmod folder and try again.", e);
                }
                // sleep a bit to reduce chance of ebootMod still having the file handle
                System.Threading.Thread.Sleep(250);
            }

            // patch the elf
            if (worker != null)
            {
                worker.ReportProgress(0, "Patching...");
            }
            string patchedElf = TempUtil.GetTempFileName();

            Patcher.XdeltaApply(elfPath, patchedElf, Path.Combine(patchDir, "ToV.elf.xdelta3"));

            if (outMd5 != null)
            {
                Patcher.CompareMd5Output(patchedElf, outMd5);
            }

            // encrypt
            if (worker != null)
            {
                worker.ReportProgress(0, "Encrypting...");
            }
            string outPath = Path.Combine(outDir, "EBOOT.BIN");

            RunEbootMod(ebootModPath, ebootPath, patchedElf, outPath);

            File.Delete(patchedElf);
        }