Esempio n. 1
0
 private void RevertPatch(GamePatch patch)
 {
     if (_file[patch.Offset] == patch.Patched)
     {
         _file[patch.Offset] = patch.Original;
     }
     else
     {
         throw new Exception("RevertPatch: Original doesn't match");
     }
 }
Esempio n. 2
0
        public bool IsPatched(GamePatch patch)
        {
            if (patch.Offset > _file.Length)
            {
                throw new Exception(String.Format("A patch offset ({0}) is larger than the file size ({1}).", patch.Offset, _file.Length));
            }

            if (_file[patch.Offset] != patch.Patched)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 3
0
 public GamePatch(GamePatch patch, bool revert = false)
 {
     if (revert)
     {
         Offset          = patch.Offset;
         Original        = patch.Patched;
         Patched         = patch.Original;
         OriginalDefined = patch.OriginalDefined;
     }
     else
     {
         Offset          = patch.Offset;
         Original        = patch.Original;
         Patched         = patch.Patched;
         OriginalDefined = patch.OriginalDefined;
     }
 }
Esempio n. 4
0
 private void ApplyPatch(GamePatch patch)
 {
     if (patch.OriginalDefined)
     {
         if (_file[patch.Offset] == patch.Original)
         {
             _file[patch.Offset] = patch.Patched;
         }
         else
         {
             throw new Exception("ApplyPatch: Original doesn't match");
         }
     }
     else
     {
         patch.Original      = _file[patch.Offset];
         _file[patch.Offset] = patch.Patched;
     }
 }
Esempio n. 5
0
        public static List <GamePatch> CreateIpPatch(string ip, int offset)
        {
            byte[] ipBytes = Encoding.UTF8.GetBytes(ip);
            if (ipBytes.Length > 15)
            {
                throw new Exception("IP is to long max 15byte");
            }

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

            byte[] data = new byte[15];
            Array.Copy(ipBytes, data, ipBytes.Length);
            for (int i = 0; i < data.Length; i++)
            {
                GamePatch patch = new GamePatch(offset + i, data[i]);
                patches.Add(patch);
            }

            return(patches);
        }
Esempio n. 6
0
        public void AddPatch(GamePatch patch)
        {
            if (_patched)
            {
                throw new Exception("Can only add patches to unpatched file.");
            }

            GamePatch clone = new GamePatch(patch);

            if (clone.Offset > _file.Length)
            {
                throw new Exception(String.Format("A patch offset ({0}) is larger than the file size ({1}).", clone.Offset, _file.Length));
            }

            if (clone.OriginalDefined && _file[clone.Offset] != clone.Original)
            {
                throw new Exception(String.Format("Patch Original ({0}) doesn't match file ({1}) value.", clone.Original, _file[clone.Offset]));
            }

            _patches.Add(clone);
        }