public bool HasConflict(PatchedByteArray patchedByteArray)
        {
            if (patchedByteArray == null)
            {
                return(false);
            }

            if (Sector != patchedByteArray.Sector)
            {
                return(false);
            }

            byte[] compareBytes = patchedByteArray.GetBytes();

            if ((bytes == null) || (compareBytes == null))
            {
                return(false);
            }

            if ((bytes.Length == 0) || (compareBytes.Length == 0))
            {
                return(false);
            }

            PatchRange range      = new PatchRange(this);
            PatchRange inputRange = new PatchRange(patchedByteArray);

            if (!range.HasOverlap(inputRange))
            {
                return(false);
            }

            uint greaterStartOffset = Math.Max(range.StartOffset, inputRange.StartOffset);
            uint lesserEndOffset    = Math.Min(range.EndOffset, inputRange.EndOffset);
            uint length             = lesserEndOffset - greaterStartOffset + 1;

            System.Collections.Generic.IList <byte> overlapBytes      = GetBytes().SubLength(greaterStartOffset - range.StartOffset, length);
            System.Collections.Generic.IList <byte> inputOverlapBytes = patchedByteArray.GetBytes().SubLength(greaterStartOffset - inputRange.StartOffset, length);

            for (int index = 0; index < length; index++)
            {
                if (overlapBytes[index] != inputOverlapBytes[index])
                {
                    return(true);
                }
            }

            return(false);
        }
        public bool IsPatchEqual(PatchedByteArray patchedByteArray)
        {
            if (patchedByteArray == null)
            {
                return(false);
            }

            if ((Sector != patchedByteArray.Sector) || (Offset != patchedByteArray.Offset))
            {
                return(false);
            }

            byte[] compareBytes = patchedByteArray.GetBytes();

            if ((bytes == null) || (compareBytes == null))
            {
                return(false);
            }

            if (bytes.Length != compareBytes.Length)
            {
                return(false);
            }

            for (int index = 0; index < bytes.Length; index++)
            {
                if (bytes[index] != compareBytes[index])
                {
                    return(false);
                }
            }

            return(true);
        }
Example #3
0
 public static void ApplyPatch(Stream stream, PspIsoInfo info, PatcherLib.Datatypes.PatchedByteArray patch)
 {
     if (patch.SectorEnum != null)
     {
         if (patch.SectorEnum.GetType() == typeof(PspIso.Sectors))
         {
             stream.WriteArrayToPosition(patch.GetBytes(), (int)(info[(PspIso.Sectors)patch.SectorEnum] * 2048) + patch.Offset);
         }
         else if (patch.SectorEnum.GetType() == typeof(FFTPack.Files))
         {
             FFTPack.PatchFile(stream, info, (int)((FFTPack.Files)patch.SectorEnum), (int)patch.Offset, patch.GetBytes());
         }
         else
         {
             throw new ArgumentException("invalid type");
         }
     }
 }
Example #4
0
 public PatchRange(PatchedByteArray patchedByteArray) : this(patchedByteArray.Sector, (uint)patchedByteArray.Offset, (uint)(patchedByteArray.Offset + patchedByteArray.GetBytes().Length - 1))
 {
 }