Ejemplo n.º 1
0
        private void CheckISO(string filepath)
        {
            if (!string.IsNullOrEmpty(filepath) && File.Exists(filepath))
            {
                pnl_Params.Visible = true;

                using (Stream file = File.Open(filepath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    if (settings.WorldConditionalsRepoint)
                    {
                        if (context == Context.US_PSX)
                        {
                            int ramOffset        = PsxIso.ReadFile(file, (PsxIso.Sectors)settings.WorldConditionalsPointerSector, settings.WorldConditionalsPointerOffset, 3).ToIntLE();
                            int wldcoreRamOffset = PsxIso.GetRamOffset(PsxIso.Sectors.WORLD_WLDCORE_BIN);
                            int worldRamOffset   = PsxIso.GetRamOffset(PsxIso.Sectors.WORLD_WORLD_BIN);
                            if (ramOffset >= worldRamOffset)
                            {
                                spinner_WorldConditionals_Sector.Value = (int)PsxIso.Sectors.WORLD_WORLD_BIN;
                                spinner_WorldConditionals_Offset.Value = ramOffset - worldRamOffset;
                            }
                            else if (ramOffset >= wldcoreRamOffset)
                            {
                                spinner_WorldConditionals_Sector.Value = (int)PsxIso.Sectors.WORLD_WLDCORE_BIN;
                                spinner_WorldConditionals_Offset.Value = ramOffset - wldcoreRamOffset;
                            }
                        }
                    }
                }

                EnableActionButton();
            }
        }
Ejemplo n.º 2
0
        public static int GetRamOffset(Enum sector, Context context)
        {
            Type type = sector.GetType();

            if (type == typeof(PsxIso.Sectors))
            {
                return(PsxIso.GetRamOffset((PsxIso.Sectors)sector));
            }
            else if (type == typeof(PspIso.Sectors))
            {
                return(PspIso.GetRamOffset((PspIso.Sectors)sector));
            }
            else
            {
                return(0);
            }
        }
Ejemplo n.º 3
0
        public static uint GetRamOffsetUnsigned(Enum sector, Context context, bool useKSeg0 = true)
        {
            Type type = sector.GetType();

            if (type == typeof(PsxIso.Sectors))
            {
                return(PsxIso.GetRamOffset((PsxIso.Sectors)sector, useKSeg0));
            }
            else if (type == typeof(PspIso.Sectors))
            {
                return(PspIso.GetRamOffsetUnsigned((PspIso.Sectors)sector));
            }
            else
            {
                return(0);
            }
        }
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;
                }
            }
        }