예제 #1
0
        private ZtFile CreateFillPatch()
        {
            string exeFileName = GetOpenFileName();

            if (string.IsNullOrEmpty(exeFileName))
            {
                return(null);
            }

            var exeBytes = File.ReadAllBytes(exeFileName);

            var zt = new ZtFile();
            var sb = new StringBuilder();

            sb.AppendLine("Fill patch");

            if (this.SpeciesSlotSelected)
            {
                sb.AppendLine("Species Slot: " + this.SpeciesSlot.ToString(CultureInfo.InvariantCulture));

                int start = SpeciesTableOffset + this.SpeciesSlot * SpeciesTableEntrySize;
                int size  = SpeciesTableEntrySize;
                var bytes = new byte[size];
                Array.Copy(exeBytes, start, bytes, 0, size);

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

            if (this.ObjectSlotSelected)
            {
                sb.AppendLine("Object Slot: " + this.ObjectSlot.ToString(CultureInfo.InvariantCulture));

                int start = ObjectTableOffset + this.ObjectSlot * ObjectTableEntrySize;
                int size  = ObjectTableEntrySize;
                var bytes = new byte[size];
                Array.Copy(exeBytes, start, bytes, 0, size);

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

            if (this.CraftSlotSelected)
            {
                sb.AppendLine("Craft Slot: " + this.CraftSlot.ToString(CultureInfo.InvariantCulture));

                int start = CraftTableOffset + this.CraftSlot * CraftTableEntrySize;
                int size  = CraftTableEntrySize;
                var bytes = new byte[size];
                Array.Copy(exeBytes, start, bytes, 0, size);

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

            zt.Comment = sb.ToString();

            return(zt);
        }
예제 #2
0
        private ZtFile CreateBlankPatch(byte value)
        {
            var zt = new ZtFile();
            var sb = new StringBuilder();

            sb.AppendLine("Blank patch: " + value.ToString(CultureInfo.InvariantCulture));

            if (this.SpeciesSlotSelected)
            {
                sb.AppendLine("Species Slot: " + this.SpeciesSlot.ToString(CultureInfo.InvariantCulture));

                var bytes = new byte[SpeciesTableEntrySize];
                BlankArray(bytes, value);
                zt.Patches.Add(SpeciesTableOffset + this.SpeciesSlot * SpeciesTableEntrySize, bytes);
            }

            if (this.ObjectSlotSelected)
            {
                sb.AppendLine("Object Slot: " + this.ObjectSlot.ToString(CultureInfo.InvariantCulture));

                var bytes = new byte[ObjectTableEntrySize];
                BlankArray(bytes, value);
                zt.Patches.Add(ObjectTableOffset + this.ObjectSlot * ObjectTableEntrySize, bytes);
            }

            if (this.CraftSlotSelected)
            {
                sb.AppendLine("Craft Slot: " + this.CraftSlot.ToString(CultureInfo.InvariantCulture));

                var bytes = new byte[CraftTableEntrySize];
                BlankArray(bytes, value);
                zt.Patches.Add(CraftTableOffset + this.CraftSlot * CraftTableEntrySize, bytes);
            }

            zt.Comment = sb.ToString();

            return(zt);
        }
예제 #3
0
        private void OpenPatchButton_Click(object sender, RoutedEventArgs e)
        {
            string filename = this.GetOpenFileName();

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

            this.RunBusyAction(disp =>
            {
                try
                {
                    this.PatchFile = ZtFile.FromFile(filename);

                    disp(() => this.UpdateDataContext());
                }
                catch (Exception ex)
                {
                    disp(() => Xceed.Wpf.Toolkit.MessageBox.Show(this, ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error));
                }
            });
        }
예제 #4
0
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(this.UnmodifiedFile))
            {
                return;
            }

            if (string.IsNullOrEmpty(this.ModifiedFile))
            {
                return;
            }

            string fileName = this.GetSaveFileName();

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

            this.RunBusyAction(disp =>
            {
                try
                {
                    var zt = ZtFile.Create(this.UnmodifiedFile, this.ModifiedFile);

                    zt.Comment = this.Comment;

                    zt.Save(fileName);

                    disp(() => Xceed.Wpf.Toolkit.MessageBox.Show(this, string.Concat(fileName, " created."), this.Title, MessageBoxButton.OK));
                }
                catch (Exception ex)
                {
                    disp(() => Xceed.Wpf.Toolkit.MessageBox.Show(this, ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error));
                }
            });
        }