Beispiel #1
0
        private void SavePatchXML()
        {
            List <AsmPatch> patches = GetAllSelectedPatches();

            foreach (AsmPatch patch in patches)
            {
                patch.Update(AsmUtility);
            }

            FreeSpaceMode mode = FreeSpace.GetMode(AsmUtility);
            string        xml  = PatchXmlReader.CreatePatchXML(patches, mode);

            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter          = "XML file (*.xml)|*.xml";
            saveFileDialog.FileName        = string.Empty;
            saveFileDialog.CheckFileExists = false;

            if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                btn_SavePatchXML.Enabled = false;
                System.IO.File.WriteAllText(saveFileDialog.FileName, xml, Encoding.UTF8);
                PatcherLib.MyMessageBox.Show(this, "Complete!", "Complete!", MessageBoxButtons.OK);
                Close();
            }
        }
Beispiel #2
0
        private void btn_OpenConflictChecker_Click(object sender, EventArgs e)
        {
            FreeSpaceMode       mode = FreeSpace.GetMode(asmUtility);
            ConflictCheckerForm conflictCheckerForm = new ConflictCheckerForm(GetCurrentFilePatches(), mode);

            conflictCheckerForm.Show();
        }
Beispiel #3
0
        public MainForm()
        {
            InitializeComponent();
            System.IO.Directory.SetCurrentDirectory(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));

            string versionText = string.Format("v0.{0}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Revision.ToString());

            versionLabel.Text = versionText;
            Text = string.Format("FFTorgASM ({0})", versionText);

            asmUtility = new ASMEncodingUtility(ASMEncodingMode.PSX);
            SetupModes();

            //LoadFiles();
            FreeSpace.ReadFreeSpaceXML();

            btnPatch.Click                        += new EventHandler(btnPatch_Click);
            reloadButton.Click                    += new EventHandler(reloadButton_Click);
            clb_Patches.ItemCheck                 += new ItemCheckEventHandler(clb_Patches_ItemCheck);
            btnPatch.Enabled                       = false;
            clb_Patches.SelectedIndexChanged      += new EventHandler(clb_Patches_SelectedIndexChanged);
            variableSpinner.ValueChanged          += new EventHandler(variableSpinner_ValueChanged);
            variableComboBox.SelectedIndexChanged += new EventHandler(variableComboBox_SelectedIndexChanged);

            lsb_FilesList.SelectedIndex = 0;
            OriginalVariableSpinnerX    = variableSpinner.Location.X;
        }
Beispiel #4
0
        private void LoadItems(int freeSpacePositionIndex)
        {
            lbl_NumberOfPatches.Text = "0";
            lbl_NumberOfWrites.Text  = "0";

            if (freeSpacePositionIndex < 0)
            {
                return;
            }

            dgv_FreeSpace.Rows.Clear();
            txtAddress.Clear();

            rowPatchMap = new Dictionary <DataGridViewRow, PatchedByteArray>();

            PatchRange range = FreeSpace.GetRanges(mode)[freeSpacePositionIndex];

            if (!freeSpaceMaps.PatchRangeMap.ContainsKey(range))
            {
                return;
            }

            //long positionEndOffset = position.StartLocation + position.Length - 1;
            List <PatchedByteArray> patchedByteArrayList = freeSpaceMaps.PatchRangeMap[range];
            HashSet <AsmPatch>      asmPatchSet          = freeSpaceMaps.OuterPatchRangeMap[range];

            for (int index = 0; index < patchedByteArrayList.Count; index++)
            {
                PatchedByteArray patchedByteArray = patchedByteArrayList[index];
                AsmPatch         asmPatch         = freeSpaceMaps.InnerPatchMap[patchedByteArray];

                // Column order: Number, Address, Length, Next Address, Space to Next Patch, File, Name
                int  length                     = patchedByteArray.GetBytes().Length;
                long nextAddress                = patchedByteArray.Offset + length;
                long nextPatchLocation          = (index < (patchedByteArrayList.Count - 1)) ? patchedByteArrayList[index + 1].Offset : range.EndOffset;
                long spaceToNextPatch           = nextPatchLocation - nextAddress;
                bool isSpaceToNextPatchNegative = (spaceToNextPatch < 0);
                //string strSpaceToNextPatch = isSpaceToNextPatchNegative ? ("-" + (-spaceToNextPatch).ToString("X")) : spaceToNextPatch.ToString("X");

                //dgv_FreeSpace.Rows.Add(index, patchedByteArray.Offset.ToString("X"), length.ToString("X"), nextAddress.ToString("X"), strSpaceToNextPatch, asmPatch.Filename, asmPatch.Name);
                dgv_FreeSpace.Rows.Add(index, patchedByteArray.Offset, length, nextAddress, spaceToNextPatch, asmPatch.Filename, asmPatch.Name);

                if (isSpaceToNextPatchNegative)
                {
                    dgv_FreeSpace.Rows[index].Cells[4].Style.BackColor = Color.FromArgb(225, 125, 125);
                }

                rowPatchMap.Add(dgv_FreeSpace.Rows[index], patchedByteArray);
            }

            lbl_NumberOfPatches.Text = asmPatchSet.Count.ToString();
            lbl_NumberOfWrites.Text  = patchedByteArrayList.Count.ToString();
        }
Beispiel #5
0
        public MainForm()
        {
            InitializeComponent();

            asmUtility        = new ASMEncodingUtility(ASMEncodingMode.PSX);
            versionLabel.Text = string.Format("v0.{0}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Revision.ToString());

            LoadFiles();
            FreeSpace.ReadFreeSpaceXML();

            btnPatch.Click                        += new EventHandler(btnPatch_Click);
            reloadButton.Click                    += new EventHandler(reloadButton_Click);
            clb_Patches.ItemCheck                 += new ItemCheckEventHandler(clb_Patches_ItemCheck);
            btnPatch.Enabled                       = false;
            clb_Patches.SelectedIndexChanged      += new EventHandler(clb_Patches_SelectedIndexChanged);
            variableSpinner.ValueChanged          += new EventHandler(variableSpinner_ValueChanged);
            variableComboBox.SelectedIndexChanged += new EventHandler(variableComboBox_SelectedIndexChanged);

            //lsb_FilesList.Scrollable = true;
            //lsb_FilesList.View = View.List;
            //lsb_FilesList.HeaderStyle = ColumnHeaderStyle.None;
            //lsb_FilesList.Columns.Add("", -2, HorizontalAlignment.Left);
        }
Beispiel #6
0
        private void ShowConflicts(AsmPatch patch)
        {
            List <PatchRangeConflict> conflictList = conflictPatchData.ConflictMap[patch];

            foreach (PatchRangeConflict conflict in conflictList)
            {
                //PsxIso.Sectors sector = (PsxIso.Sectors)(conflict.ConflictRange.Sector);
                //string strSector = Enum.GetName(typeof(PsxIso.Sectors), sector);
                //string strSector = PatcherLib.Iso.PsxIso.GetSectorName(sector);

                /*
                 * Type sectorType = (mode == FreeSpaceMode.PSP) ? typeof(PspIso.Sectors) : typeof(PsxIso.Sectors);
                 * Enum sector = (Enum)Enum.ToObject(sectorType, conflict.ConflictRange.Sector);
                 * string strSector = (mode == FreeSpaceMode.PSP) ? PspIso.GetSectorName((PspIso.Sectors)sector) : PsxIso.GetSectorName((PsxIso.Sectors)sector);
                 */

                string strSector = ISOHelper.GetSectorName(conflict.ConflictRange.Sector, FreeSpace.GetContext(mode));

                // Patch #, Sector, Location, Conflict Location
                ListViewItem item = new ListViewItem();
                item.Text = conflict.ConflictPatchNumber.ToString();
                item.SubItems.Add(strSector);
                item.SubItems.Add(conflict.Range.StartOffset.ToString("X"));
                item.SubItems.Add(conflict.ConflictRange.StartOffset.ToString("X"));
                item.BackColor = conflict.IsInFreeSpace ? backColor_Conflict_FreeSpace : backColor_Conflict_NonFreeSpace;
                lv_Conflicts.Items.Add(item);
            }
        }
Beispiel #7
0
 private void Init(List <AsmPatch> patchList, ASMEncoding.ASMEncodingUtility asmUtility, FreeSpaceMode mode)
 {
     this.patchList     = patchList;
     this.asmUtility    = asmUtility;
     this.freeSpaceMaps = FreeSpace.GetFreeSpaceMaps(patchList, mode);
 }
Beispiel #8
0
 private void InitFiles(FreeSpaceMode mode)
 {
     this.Filelistbox.Items.Clear();
     this.Filelistbox.Items.AddRange(FreeSpace.GetRangeNames(mode));
 }
Beispiel #9
0
 private void btn_ViewFreeSpace_Click(object sender, EventArgs e)
 {
     FreeSpace FS = new FreeSpace();
     FS.Show();
 }
Beispiel #10
0
        public void MoveBlocks(ASMEncoding.ASMEncodingUtility utility, IEnumerable <MovePatchRange> movePatchRanges)
        {
            /*
             * Dictionary<PatchRange, bool> isSequentialAdd = new Dictionary<PatchRange, bool>();
             * foreach (KeyValuePair<PatchRange, uint> blockMove in blockMoves)
             * {
             *  isSequentialAdd[blockMove.Key] = false;
             * }
             */
            List <ASMEncoding.Helpers.BlockMove> blockMoves = new List <ASMEncoding.Helpers.BlockMove>();

            foreach (MovePatchRange patchRange in movePatchRanges)
            {
                //PatchRange patchRange = movePair.Key;
                //uint fileToRamOffset = PatcherLib.Iso.PsxIso.GetRamOffset(patchRange.Sector, true);
                FreeSpaceMode mode            = FreeSpace.GetMode(utility);
                Type          sectorType      = (mode == FreeSpaceMode.PSP) ? typeof(PatcherLib.Iso.PspIso.Sectors) : typeof(PatcherLib.Iso.PsxIso.Sectors);
                Enum          sector          = (Enum)Enum.ToObject(sectorType, patchRange.Sector);
                uint          fileToRamOffset = (mode == FreeSpaceMode.PSP)
                    ? PatcherLib.Iso.PspIso.GetRamOffsetUnsigned((PatcherLib.Iso.PspIso.Sectors)sector)
                    : PatcherLib.Iso.PsxIso.GetRamOffset((PatcherLib.Iso.PsxIso.Sectors)sector, true);

                ASMEncoding.Helpers.BlockMove blockMove = new ASMEncoding.Helpers.BlockMove();
                blockMove.Location    = (uint)patchRange.StartOffset + fileToRamOffset;
                blockMove.EndLocation = (uint)patchRange.EndOffset + fileToRamOffset;
                blockMove.Offset      = patchRange.MoveOffset;
                blockMoves.Add(blockMove);
            }

            List <PatchedByteArray> allPatchList = GetAllPatches();

            //foreach (PatchedByteArray patchedByteArray in innerList)
            foreach (PatchedByteArray patchedByteArray in allPatchList)
            {
                if (patchedByteArray is InputFilePatch)
                {
                    continue;
                }

                byte[] bytes = patchedByteArray.GetBytes();

                foreach (MovePatchRange patchRange in movePatchRanges)
                {
                    //PatchRange patchRange = movePair.Key;
                    //uint offset = movePair.Value;

                    //if ((patchedByteArray.RamOffset == blockMove.Location) && ((patchedByteArray.RamOffset + bytes.Length) == blockMove.EndLocation))
                    //if (patchedByteArray.RamOffset == blockMove.Location)
                    //PatchRange patchRange = new PatchRange(patchedByteArray);
                    //PatchRange patchRange2 = new PatchRange(
                    //if (
                    //if (blockMove.Key
                    if (patchRange.HasOverlap(patchedByteArray))
                    {
                        patchedByteArray.Offset    += patchRange.MoveOffset; // offset;
                        patchedByteArray.RamOffset += patchRange.MoveOffset; // offset;
                        //isSequentialAdd[patchRange] = true;
                    }

                    /*
                     * else if ((isSequentialAdd[patchRange]) && (patchedByteArray.IsSequentialOffset))
                     * {
                     *  patchedByteArray.Offset += offset;
                     *  patchedByteArray.RamOffset += offset;
                     *  //patchRange.EndOffset += (uint)bytes.Length;
                     * }
                     * else
                     * {
                     *  isSequentialAdd[patchRange] = false;
                     * }
                     */
                }

                if ((patchedByteArray.IsCheckedAsm) && (!patchedByteArray.IsMoveSimple))
                {
                    byte[] newBytes = utility.UpdateBlockReferences(bytes, (uint)patchedByteArray.RamOffset, true, blockMoves);
                    patchedByteArray.SetBytes(newBytes);
                }
            }

            foreach (ASMEncoding.Helpers.BlockMove blockMove in blockMoves)
            {
                bool isAlreadyPresent = false;
                foreach (ASMEncoding.Helpers.BlockMove listBlockMove in blockMoveList)
                {
                    if (blockMove.IsEqual(listBlockMove))
                    {
                        isAlreadyPresent = true;
                        break;
                    }
                }

                if (!isAlreadyPresent)
                {
                    blockMoveList.Add(blockMove);
                }
            }
        }
Beispiel #11
0
        private void btn_ViewFreeSpace_Click(object sender, EventArgs e)
        {
            FreeSpace FS = new FreeSpace();

            FS.Show();
        }
Beispiel #12
0
        private ConflictCheckResult CheckConflicts(List <AsmPatch> patchList)
        {
            List <AsmPatch> resultPatchList = new List <AsmPatch>();
            Dictionary <AsmPatch, List <PatchRangeConflict> > conflictMap          = new Dictionary <AsmPatch, List <PatchRangeConflict> >();
            Dictionary <AsmPatch, List <PatchedByteArray> >   combinedPatchListMap = new Dictionary <AsmPatch, List <PatchedByteArray> >();

            foreach (AsmPatch patch in patchList)
            {
                combinedPatchListMap[patch] = patch.GetCombinedPatchList();
            }

            for (int patchIndex = 0; patchIndex < patchList.Count; patchIndex++)
            {
                AsmPatch patch = patchList[patchIndex];

                List <PatchedByteArray> combinedPatchList = combinedPatchListMap[patch];
                foreach (PatchedByteArray patchedByteArray in combinedPatchList)
                {
                    if (patchedByteArray is InputFilePatch)
                    {
                        continue;
                    }

                    PatchRange range = new PatchRange(patchedByteArray);
                    for (int conflictPatchIndex = patchIndex + 1; conflictPatchIndex < patchList.Count; conflictPatchIndex++)
                    {
                        AsmPatch conflictPatch = patchList[conflictPatchIndex];

                        List <PatchedByteArray> conflictCombinedPatchList = combinedPatchListMap[conflictPatch];
                        foreach (PatchedByteArray conflictPatchedByteArray in conflictCombinedPatchList)
                        {
                            if (conflictPatchedByteArray is InputFilePatch)
                            {
                                continue;
                            }

                            //if (patchedByteArray.IsPatchEqual(conflictPatchedByteArray))
                            if (!patchedByteArray.HasConflict(conflictPatchedByteArray))
                            {
                                continue;
                            }

                            PatchRange conflictRange = new PatchRange(conflictPatchedByteArray);
                            if (range.HasOverlap(conflictRange))
                            {
                                bool isInFreeSpace = FreeSpace.IsContainedWithinPsxFreeSpace(range);

                                PatchRangeConflict patchConflict        = new PatchRangeConflict(range, conflictPatch, conflictRange, isInFreeSpace);
                                PatchRangeConflict reversePatchConflict = new PatchRangeConflict(conflictRange, patch, range, isInFreeSpace);

                                if (conflictMap.ContainsKey(patch))
                                {
                                    conflictMap[patch].Add(patchConflict);
                                }
                                else
                                {
                                    conflictMap.Add(patch, new List <PatchRangeConflict> {
                                        patchConflict
                                    });
                                }

                                if (conflictMap.ContainsKey(conflictPatch))
                                {
                                    conflictMap[conflictPatch].Add(reversePatchConflict);
                                }
                                else
                                {
                                    conflictMap.Add(conflictPatch, new List <PatchRangeConflict> {
                                        reversePatchConflict
                                    });
                                }
                            }
                        }
                    }
                }

                if (conflictMap.ContainsKey(patch))
                {
                    resultPatchList.Add(patch);
                }
            }

            return(new ConflictCheckResult(resultPatchList, conflictMap));
        }
        public static ConflictResolveResult ResolveConflicts(IList <AsmPatch> patchList, ASMEncoding.ASMEncodingUtility asmUtility, int maxConflictResolveAttempts = MaxConflictResolveAttempts)
        {
            List <AsmPatch>            resultPatchList = new List <AsmPatch>();
            Dictionary <AsmPatch, int> patchIndexMap   = new Dictionary <AsmPatch, int>();
            StringBuilder sbMessage    = new StringBuilder();
            bool          hasConflicts = false;

            for (int index = 0; index < patchList.Count; index++)
            {
                resultPatchList.Add(patchList[index]);
                patchIndexMap.Add(patchList[index], index);
            }

            Context       context       = (asmUtility.EncodingMode == ASMEncoding.ASMEncodingMode.PSP) ? Context.US_PSP : Context.US_PSX;
            FreeSpaceMode mode          = FreeSpace.GetMode(context);
            FreeSpaceMaps freeSpaceMaps = FreeSpace.GetFreeSpaceMaps(resultPatchList, mode);

            foreach (PatchRange freeSpaceRange in freeSpaceMaps.PatchRangeMap.Keys)
            {
                List <PatchedByteArray> innerPatches  = freeSpaceMaps.PatchRangeMap[freeSpaceRange];
                FreeSpaceAnalyzeResult  analyzeResult = FreeSpace.Analyze(innerPatches, freeSpaceRange, true);
                int conflictResolveAttempts           = 0;

                /*
                 * Type sectorType = ISOHelper.GetSectorType(context);
                 * Enum sector = (Enum)Enum.ToObject(sectorType, freeSpaceRange.Sector);
                 * string strSector = (mode == FreeSpaceMode.PSP) ? PspIso.GetSectorName((PspIso.Sectors)sector) : PsxIso.GetSectorName((PsxIso.Sectors)sector);
                 */

                string strSector = ISOHelper.GetSectorName(freeSpaceRange.Sector, context);

                while ((analyzeResult.HasConflicts) && (conflictResolveAttempts < maxConflictResolveAttempts))
                {
                    bool isStatic   = false;
                    bool stayStatic = false;

                    int endIndex = innerPatches.Count - 1;
                    for (int index = 0; index < endIndex; index++)
                    {
                        PatchedByteArray innerPatch = innerPatches[index];
                        isStatic   = innerPatch.IsStatic || stayStatic;
                        stayStatic = (innerPatch.IsStatic) && (innerPatch.IsPatchEqual(innerPatches[index + 1]));

                        if ((analyzeResult.ConflictIndexes.Contains(index)) && (!isStatic))
                        {
                            long           moveOffset     = analyzeResult.LargestGapOffset - innerPatch.Offset;
                            MovePatchRange movePatchRange = new MovePatchRange(new PatchRange(innerPatch), moveOffset);

                            AsmPatch asmPatch         = freeSpaceMaps.InnerPatchMap[innerPatch];
                            int      resultPatchIndex = patchIndexMap[asmPatch];
                            patchIndexMap.Remove(asmPatch);

                            asmPatch = asmPatch.Copy();
                            resultPatchList[resultPatchIndex] = asmPatch;
                            patchIndexMap.Add(asmPatch, resultPatchIndex);
                            asmPatch.MoveBlock(asmUtility, movePatchRange);
                            asmPatch.Update(asmUtility);

                            sbMessage.AppendLine("Conflict resolved by moving segment of patch \"" + asmPatch.Name + "\" in sector " + strSector + " from offset "
                                                 + innerPatch.Offset.ToString("X") + " to " + analyzeResult.LargestGapOffset.ToString("X") + ".");

                            freeSpaceMaps = FreeSpace.GetFreeSpaceMaps(resultPatchList, mode);
                            innerPatches  = freeSpaceMaps.PatchRangeMap[freeSpaceRange];
                            analyzeResult = FreeSpace.Analyze(innerPatches, freeSpaceRange, false);
                            conflictResolveAttempts++;
                            break;
                        }
                    }
                }

                if (analyzeResult.HasConflicts)
                {
                    hasConflicts = true;
                    int endIndex = innerPatches.Count - 1;
                    for (int index = 0; index < endIndex; index++)
                    {
                        if (analyzeResult.ConflictIndexes.Contains(index))
                        {
                            sbMessage.Length = 0;
                            sbMessage.AppendLine("Conflict in sector " + strSector + " at offset " + innerPatches[index].Offset.ToString("X") + "!");
                            break;
                        }
                    }
                }
            }

            return(new ConflictResolveResult(resultPatchList, hasConflicts, sbMessage.ToString()));
        }