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.
This commit is contained in:
Kurt
2015-09-15 23:33:02 -07:00
parent 4cc9546504
commit 2ea5c3b2e9
2 changed files with 24 additions and 1 deletions

View File

@@ -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
//

View File

@@ -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)
{