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; /* * string sectorName = Enum.GetName(typeof(PatcherLib.Iso.PsxIso.Sectors), patchRange.Sector); * int fileToRamOffset = 0; * try * { * fileToRamOffset = (int)(PatcherLib.Iso.PsxIso.FileToRamOffsets)Enum.Parse(typeof(PatcherLib.Iso.PsxIso.FileToRamOffsets), "OFFSET_" + sectorName.ToUpper().Trim()); * } * catch (Exception) { } */ uint fileToRamOffset = PatcherLib.Iso.PsxIso.GetRamOffset(patchRange.Sector); 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); } } }
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); } } }