Ejemplo n.º 1
0
 private void UpdateIso(Stream iso)
 {
     if (psxPos != null)
     {
         PsxIso.PatchPsxIso(iso, psxPos.GetPatchedByteArray(ToByteArray()));
     }
     else if (pspPos != null)
     {
         PspIso.ApplyPatch(iso, pspInfo, pspPos.GetPatchedByteArray(ToByteArray()));
     }
 }
Ejemplo n.º 2
0
        public static void PatchISO(EntryData entryData, string filepath, Context context, DataHelper dataHelper = null)
        {
            if (!string.IsNullOrEmpty(filepath))
            {
                List <PatchedByteArray> patches = GetISOPatches(entryData, context, dataHelper);

                using (Stream file = File.Open(filepath, FileMode.Open, FileAccess.ReadWrite, FileShare.Read))
                {
                    PsxIso.PatchPsxIso(file, patches);
                }
            }
        }
Ejemplo n.º 3
0
        public static PatchResult PatchISO(string filename, List <AsmPatch> asmPatches, ASMEncoding.ASMEncodingUtility asmUtility)
        {
            ConflictResolveResult conflictResolveResult = ConflictHelper.ResolveConflicts(asmPatches, asmUtility);

            asmPatches = conflictResolveResult.Patches;
            string conflictResolveMessage = conflictResolveResult.Message;

            List <PatchedByteArray> patches = new List <PatchedByteArray>();

            foreach (AsmPatch asmPatch in asmPatches)
            {
                asmPatch.Update(asmUtility);
                foreach (PatchedByteArray innerPatch in asmPatch)
                {
                    patches.Add(innerPatch);

                    if ((asmUtility.EncodingMode == ASMEncodingMode.PSP) && (innerPatch.Sector == (int)PspIso.Sectors.PSP_GAME_SYSDIR_BOOT_BIN))
                    {
                        patches.Add(innerPatch.GetCopyForSector(PspIso.Sectors.PSP_GAME_SYSDIR_EBOOT_BIN));
                    }
                }
            }

            using (Stream file = File.Open(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.Read))
            {
                if (asmUtility.EncodingMode == ASMEncoding.ASMEncodingMode.PSX)
                {
                    PsxIso.PatchPsxIso(file, patches);
                }
                else if (asmUtility.EncodingMode == ASMEncoding.ASMEncodingMode.PSP)
                {
                    PspIso.PatchISO(file, patches);
                }
            }

            StringBuilder sbResultMessage = new StringBuilder();

            sbResultMessage.AppendLine("Complete!");
            sbResultMessage.AppendLine();

            if (!string.IsNullOrEmpty(conflictResolveMessage))
            {
                sbResultMessage.AppendLine(conflictResolveMessage);
                sbResultMessage.AppendLine();
            }

            // DEBUG
            //File.WriteAllText("./output.xml", PatchXmlReader.CreatePatchXML(patches), Encoding.UTF8);

            return(new PatchResult(true, sbResultMessage.ToString()));
        }
Ejemplo n.º 4
0
        private void btn_Patch_Click(object sender, EventArgs e)
        {
            btn_Patch.Enabled = false;
            string filepath = txt_ISO.Text;

            if (!string.IsNullOrEmpty(filepath))
            {
                List <PatchedByteArray> patches = new List <PatchedByteArray>();

                if (chk_BattleConditionals.Checked)
                {
                    PsxIso.Sectors battleSector = (PsxIso.Sectors)spinner_BattleConditionals_Sector.Value;
                    int            battleOffset = (int)spinner_BattleConditionals_Offset.Value;
                    byte[]         battleBytes  = _dataHelper.ConditionalSetsToByteArray(CommandType.BattleConditional, _entryData.BattleConditionals);
                    patches.Add(new PatchedByteArray(battleSector, battleOffset, battleBytes));

                    if ((settings.BattleConditionalsApplyLimitPatch) && (DataHelper.GetMaxBlocks(_entryData.BattleConditionals) > 10))
                    {
                        patches.Add(new PatchedByteArray(settings.BattleConditionalsLimitPatchSector, settings.BattleConditionalsLimitPatchOffset, settings.BattleConditionalsLimitPatchBytes));
                    }
                }

                if (chk_WorldConditionals.Checked)
                {
                    PsxIso.Sectors worldSector = (PsxIso.Sectors)spinner_WorldConditionals_Sector.Value;
                    int            worldOffset = (int)spinner_WorldConditionals_Offset.Value;
                    byte[]         worldBytes  = _dataHelper.ConditionalSetsToByteArray(CommandType.WorldConditional, _entryData.WorldConditionals);
                    patches.Add(new PatchedByteArray(worldSector, worldOffset, worldBytes));

                    if (settings.WorldConditionalsRepoint)
                    {
                        byte[] patchBytes = (((uint)(PsxIso.GetRamOffset(worldSector) + worldOffset)) | PsxIso.KSeg0Mask).ToBytes();
                        patches.Add(new PatchedByteArray(settings.WorldConditionalsPointerSector, settings.WorldConditionalsPointerOffset, patchBytes));
                    }
                }

                if (chk_Events.Checked)
                {
                    PsxIso.Sectors eventSector = (PsxIso.Sectors)spinner_Events_Sector.Value;
                    int            eventOffset = (int)spinner_Events_Offset.Value;
                    byte[]         eventBytes  = _dataHelper.EventsToByteArray(_entryData.Events);
                    patches.Add(new PatchedByteArray(eventSector, eventOffset, eventBytes));
                }

                try
                {
                    using (Stream file = File.Open(filepath, FileMode.Open, FileAccess.ReadWrite, FileShare.Read))
                    {
                        PsxIso.PatchPsxIso(file, patches);
                    }

                    DialogResult = DialogResult.OK;
                    Close();
                }
                catch (Exception ex)
                {
                    PatcherLib.MyMessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK);
                    btn_Patch.Enabled = true;
                }
            }
        }
Ejemplo n.º 5
0
        public static void WritePsxDirectoryEntries(Stream iso, int sector, int numSectors, IList <DirectoryEntry> entries)
        {
            var patches = GetPsxDirectoryEntryPatches(sector, numSectors, entries);

            patches.ForEach(p => PsxIso.PatchPsxIso(iso, patches));
        }