From 2690520ffcdec768e1e765ad44e5abaafaf16399 Mon Sep 17 00:00:00 2001 From: Kurt Date: Thu, 11 Jan 2018 21:50:38 -0800 Subject: [PATCH] Add everything shiny checkbox automating the following patch: https://twitter.com/SciresM/status/799853435340423168 --- pk3DS/Subforms/ShinyRate.Designer.cs | 13 ++++++++++++ pk3DS/Subforms/ShinyRate.cs | 30 +++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/pk3DS/Subforms/ShinyRate.Designer.cs b/pk3DS/Subforms/ShinyRate.Designer.cs index 60462c6..88ea1ce 100644 --- a/pk3DS/Subforms/ShinyRate.Designer.cs +++ b/pk3DS/Subforms/ShinyRate.Designer.cs @@ -42,6 +42,7 @@ private void InitializeComponent() this.GB_RerollHelper = new System.Windows.Forms.GroupBox(); this.GB_Rerolls = new System.Windows.Forms.GroupBox(); this.label1 = new System.Windows.Forms.Label(); + this.checkBox1 = new System.Windows.Forms.CheckBox(); ((System.ComponentModel.ISupportInitialize)(this.NUD_Rerolls)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.NUD_Rate)).BeginInit(); this.GB_RerollHelper.SuspendLayout(); @@ -194,12 +195,23 @@ private void InitializeComponent() this.label1.TabIndex = 13; this.label1.Text = "Note:\r\nThe above reroll count will overwrite the existing code.\r\n\r\nTo revert chan" + "ges, use the button below."; + // + // checkBox1 + // + this.checkBox1.AutoSize = true; + this.checkBox1.Location = new System.Drawing.Point(281, 184); + this.checkBox1.Name = "checkBox1"; + this.checkBox1.Size = new System.Drawing.Size(96, 30); + this.checkBox1.TabIndex = 14; + this.checkBox1.Text = "EVERYTHING\r\nSHINY"; + this.checkBox1.UseVisualStyleBackColor = true; // // ShinyRate // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(384, 271); + this.Controls.Add(this.checkBox1); this.Controls.Add(this.label1); this.Controls.Add(this.GB_Rerolls); this.Controls.Add(this.GB_RerollHelper); @@ -241,5 +253,6 @@ private void InitializeComponent() private System.Windows.Forms.GroupBox GB_RerollHelper; private System.Windows.Forms.GroupBox GB_Rerolls; private System.Windows.Forms.Label label1; + private System.Windows.Forms.CheckBox checkBox1; } } \ No newline at end of file diff --git a/pk3DS/Subforms/ShinyRate.cs b/pk3DS/Subforms/ShinyRate.cs index 25a7715..0ff8dca 100644 --- a/pk3DS/Subforms/ShinyRate.cs +++ b/pk3DS/Subforms/ShinyRate.cs @@ -52,6 +52,8 @@ public ShinyRate() modified = true; } changeRerolls(null, null); + + CheckAlwaysShiny(); } private readonly List InstructionList = new List(); @@ -83,10 +85,36 @@ public byte[] Bytes } } + private int alwaysIndex; + private void CheckAlwaysShiny() + { + byte[] pattern = {0x00, 0x20, 0x22, 0xE0, 0x02, 0x30, 0x21, 0xE2, 0x03, 0x20, 0x92, 0xE1, 0x1C, 0x00, 0x00}; + int index = alwaysIndex = Util.IndexOfBytes(exefsData, pattern, 0, 0) + pattern.Length; + + if (index < 0) + { + checkBox1.Enabled = checkBox1.Visible = false; + return; + } + + bool original = exefsData[index] == 0x0A; + bool always = exefsData[index] == 0xEA; + + if (!original && !always) // oh no + { + checkBox1.Enabled = checkBox1.Visible = false; + return; + } + + checkBox1.Checked = always; + } + private void B_Cancel_Click(object sender, EventArgs e) => Close(); private void B_Save_Click(object sender, EventArgs e) { writeCodePatch(); + if (checkBox1.Enabled) + exefsData[alwaysIndex] = (byte)(checkBox1.Checked ? 0xEA : 0x0A); File.WriteAllBytes(codebin, exefsData); Close(); } @@ -133,7 +161,7 @@ private void changePercent(object sender, EventArgs e) var inv = (int)Math.Log(1 - (float)pct/100, (float) (bc - 1)/bc); if (pct == 0) pct = 0.00001m; // arbitrary nonzero - L_RerollCount.Text = $"Count: {inv.ToString("0")} = 1:{(int)(1/(pct/100))}"; + L_RerollCount.Text = $"Count: {inv:0} = 1:{(int)(1/(pct/100))}"; } } } \ No newline at end of file