Beispiel #1
0
        public static ZtFile Create(string unmodifiedFile, string modifiedFile)
        {
            byte[] unmodifiedBytes = File.ReadAllBytes(unmodifiedFile);
            byte[] modifiedBytes   = File.ReadAllBytes(modifiedFile);

            return(ZtFile.Create(unmodifiedBytes, modifiedBytes));
        }
        private void Create202Button_Click(object sender, RoutedEventArgs e)
        {
            var source = (FrameworkElement)sender;
            var patch  = (PatchModel)source.Tag;

            string filename = Get202SaveFileName(patch.Name);

            if (string.IsNullOrEmpty(filename))
            {
                return;
            }

            try
            {
                var zt = new ZtFile();

                foreach (PatchItemModel item in patch.Items)
                {
                    zt.Patches.Add(item.Offset, item.NewValues);
                }

                zt.Save(filename);

                MessageBox.Show(".202 created.", patch.Name);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.ToString());
            }
        }
Beispiel #3
0
        public static ZtFile FromFile(string fileName)
        {
            var zt = new ZtFile
            {
                FileName = fileName
            };

            FileStream filestream = null;

            try
            {
                filestream = new FileStream(fileName, FileMode.Open, FileAccess.Read);

                using (BinaryReader file = new BinaryReader(filestream))
                {
                    filestream = null;

                    zt.TargetName = Encoding.ASCII.GetString(file.ReadBytes(13)).TrimEnd('\0');

                    int count = file.ReadUInt16();

                    for (int i = 0; i < count; i++)
                    {
                        int    offset = file.ReadInt32();
                        byte   length = file.ReadByte();
                        byte[] bytes  = file.ReadBytes(length);

                        zt.Patches.Add(offset, bytes);
                    }

                    if (file.BaseStream.Position != file.BaseStream.Length)
                    {
                        byte[] commentBytes = file.ReadBytes((int)file.BaseStream.Length - (int)file.BaseStream.Position);

                        zt.Comment = Encoding.UTF8.GetString(commentBytes);
                    }

                    zt.Compact();
                }
            }
            finally
            {
                if (filestream != null)
                {
                    filestream.Dispose();
                }
            }

            return(zt);
        }
Beispiel #4
0
        public static ZtFile Create(byte[] unmodifiedBytes, byte[] modifiedBytes)
        {
            if (unmodifiedBytes == null)
            {
                throw new ArgumentNullException("unmodifiedBytes");
            }

            if (modifiedBytes == null)
            {
                throw new ArgumentNullException("modifiedBytes");
            }

            if (unmodifiedBytes.Length != modifiedBytes.Length)
            {
                throw new InvalidOperationException();
            }

            ZtFile zt = new ZtFile();

            for (int offset = 0; offset < unmodifiedBytes.Length; offset++)
            {
                int start = offset;
                int count = 0;

                while (offset < unmodifiedBytes.Length && unmodifiedBytes[offset] != modifiedBytes[offset])
                {
                    offset++;
                    count++;
                }

                if (count != 0)
                {
                    byte[] bytes = new byte[count];
                    Array.Copy(modifiedBytes, start, bytes, 0, count);

                    zt.Add(start, bytes);
                }
            }

            return(zt);
        }