From 2ea5c3b2e9f512bc1a17f717fa1d4a382c6ed6e5 Mon Sep 17 00:00:00 2001 From: Kurt Date: Tue, 15 Sep 2015 23:33:02 -0700 Subject: [PATCH] Enable Egg RNG Seed Editing Played around with a few solutions, was happiest with (the probably slower) linq as I didn't feel like using regex. Supports copy/paste as all the filtering is done when the text changes; any successful update will refresh the value in the save file. --- PKX/f1-Main.Designer.cs | 3 ++- PKX/f1-Main.cs | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/PKX/f1-Main.Designer.cs b/PKX/f1-Main.Designer.cs index b9fb80379..e9d36869c 100644 --- a/PKX/f1-Main.Designer.cs +++ b/PKX/f1-Main.Designer.cs @@ -3577,11 +3577,12 @@ public void InitializeComponent() // this.TB_RNGSeed.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.TB_RNGSeed.Location = new System.Drawing.Point(61, 140); + this.TB_RNGSeed.MaxLength = 16; this.TB_RNGSeed.Name = "TB_RNGSeed"; - this.TB_RNGSeed.ReadOnly = true; this.TB_RNGSeed.Size = new System.Drawing.Size(120, 20); this.TB_RNGSeed.TabIndex = 8; this.TB_RNGSeed.Text = "0123456789ABCDEF"; + this.TB_RNGSeed.TextChanged += new System.EventHandler(this.updateEggRNGSeed); // // dcpkx2 // diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index f24d73bdb..19c49dfb9 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -2878,6 +2878,28 @@ private void clickClone(object sender, EventArgs e) savedited = true; } + private void updateEggRNGSeed(object sender, EventArgs e) + { + // Run through a LINQ filter for fun; works fine for GUI purposes, although LINQ may not be the fastest way to do it! + string filterText = TB_RNGSeed.Text.Select(char.ToUpper).Where("0123456789ABCDEF".Contains).Aggregate("", (str, c) => str + c); + if (filterText.Length != TB_RNGSeed.Text.Length) + { + Util.Alert("Expected HEX (0-9, A-F).", "Received: " + Environment.NewLine + TB_RNGSeed.Text); + // Reset to Stored Value + TB_RNGSeed.Text = BitConverter.ToUInt64(savefile, SaveGame.Daycare + (0x7F000 * savindex) + 0x1E8).ToString("X16"); + return; // recursively triggers this method, no need to continue + } + + if (TB_RNGSeed.Text.Length == 0) + { + // Reset to 0 + TB_RNGSeed.Text = 0.ToString("X16"); + return; // recursively triggers this method, no need to continue + } + + // Write final value back to the save + Array.Copy(BitConverter.GetBytes(Convert.ToUInt64(TB_RNGSeed.Text, 16)), 0, savefile, SaveGame.Daycare + 0x7F000 * savindex + 0x1E8, 0x8); + } // Generic Subfunctions // private void setPokedex(byte[] pkxdata) {