Merge pull request #1166 from pokecal/master

add BW2 KeySystem Unlock
This commit is contained in:
Kurt 2017-05-27 08:32:49 -07:00 committed by GitHub
commit f368e963fb
3 changed files with 130 additions and 22 deletions

View File

@ -947,7 +947,7 @@ public bool ToggleInterface()
B_CGearSkin.Enabled = SAV.Generation == 5;
B_OpenTrainerInfo.Enabled = B_OpenItemPouch.Enabled = SAV.HasParty; // Box RS
B_OpenMiscEditor.Enabled = SAV is SAV3 || SAV.DP || SAV.HGSS || SAV.BW;
B_OpenMiscEditor.Enabled = SAV.Generation <= 5 && SAV.Generation >= 3 && !SAV.Pt;
B_OpenHoneyTreeEditor.Enabled = SAV.DP || SAV.Pt;
B_OpenRTCEditor.Enabled = SAV.RS || SAV.E;

View File

@ -42,16 +42,20 @@ private void InitializeComponent()
this.GB_FlyDest = new System.Windows.Forms.GroupBox();
this.CLB_FlyDest = new System.Windows.Forms.CheckedListBox();
this.B_AllFlyDest = new System.Windows.Forms.Button();
this.GB_KeySystem = new System.Windows.Forms.GroupBox();
this.CLB_KeySystem = new System.Windows.Forms.CheckedListBox();
this.B_AllKeys = new System.Windows.Forms.Button();
this.TC_Misc.SuspendLayout();
this.TAB_Main.SuspendLayout();
this.GB_Roamer.SuspendLayout();
this.GB_FlyDest.SuspendLayout();
this.GB_KeySystem.SuspendLayout();
this.SuspendLayout();
//
// B_Cancel
//
this.B_Cancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.B_Cancel.Location = new System.Drawing.Point(52, 281);
this.B_Cancel.Location = new System.Drawing.Point(52, 316);
this.B_Cancel.Name = "B_Cancel";
this.B_Cancel.Size = new System.Drawing.Size(75, 23);
this.B_Cancel.TabIndex = 0;
@ -62,7 +66,7 @@ private void InitializeComponent()
// B_Save
//
this.B_Save.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.B_Save.Location = new System.Drawing.Point(133, 281);
this.B_Save.Location = new System.Drawing.Point(133, 316);
this.B_Save.Name = "B_Save";
this.B_Save.Size = new System.Drawing.Size(75, 23);
this.B_Save.TabIndex = 1;
@ -79,18 +83,19 @@ private void InitializeComponent()
this.TC_Misc.Location = new System.Drawing.Point(12, 12);
this.TC_Misc.Name = "TC_Misc";
this.TC_Misc.SelectedIndex = 0;
this.TC_Misc.Size = new System.Drawing.Size(196, 263);
this.TC_Misc.Size = new System.Drawing.Size(196, 298);
this.TC_Misc.TabIndex = 2;
//
// TAB_Main
//
this.TAB_Main.Controls.Add(this.GB_KeySystem);
this.TAB_Main.Controls.Add(this.CHK_LibertyPass);
this.TAB_Main.Controls.Add(this.GB_Roamer);
this.TAB_Main.Controls.Add(this.GB_FlyDest);
this.TAB_Main.Location = new System.Drawing.Point(4, 22);
this.TAB_Main.Name = "TAB_Main";
this.TAB_Main.Padding = new System.Windows.Forms.Padding(3);
this.TAB_Main.Size = new System.Drawing.Size(188, 237);
this.TAB_Main.Size = new System.Drawing.Size(188, 272);
this.TAB_Main.TabIndex = 0;
this.TAB_Main.Text = "Main";
this.TAB_Main.UseVisualStyleBackColor = true;
@ -182,11 +187,41 @@ private void InitializeComponent()
this.B_AllFlyDest.UseVisualStyleBackColor = true;
this.B_AllFlyDest.Click += new System.EventHandler(this.B_AllFlyDest_Click);
//
// GB_KeySystem
//
this.GB_KeySystem.Controls.Add(this.B_AllKeys);
this.GB_KeySystem.Controls.Add(this.CLB_KeySystem);
this.GB_KeySystem.Location = new System.Drawing.Point(6, 139);
this.GB_KeySystem.Name = "GB_KeySystem";
this.GB_KeySystem.Size = new System.Drawing.Size(140, 127);
this.GB_KeySystem.TabIndex = 3;
this.GB_KeySystem.TabStop = false;
this.GB_KeySystem.Text = "Unlocked Keys";
//
// CLB_KeySystem
//
this.CLB_KeySystem.CheckOnClick = true;
this.CLB_KeySystem.FormattingEnabled = true;
this.CLB_KeySystem.Location = new System.Drawing.Point(6, 47);
this.CLB_KeySystem.Name = "CLB_KeySystem";
this.CLB_KeySystem.Size = new System.Drawing.Size(128, 74);
this.CLB_KeySystem.TabIndex = 0;
//
// B_AllKeys
//
this.B_AllKeys.Location = new System.Drawing.Point(6, 18);
this.B_AllKeys.Name = "B_AllKeys";
this.B_AllKeys.Size = new System.Drawing.Size(75, 23);
this.B_AllKeys.TabIndex = 1;
this.B_AllKeys.Text = "Check All";
this.B_AllKeys.UseVisualStyleBackColor = true;
this.B_AllKeys.Click += new System.EventHandler(this.B_AllKeys_Click);
//
// SAV_Misc5
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(220, 316);
this.ClientSize = new System.Drawing.Size(220, 351);
this.Controls.Add(this.TC_Misc);
this.Controls.Add(this.B_Save);
this.Controls.Add(this.B_Cancel);
@ -199,6 +234,7 @@ private void InitializeComponent()
this.TAB_Main.PerformLayout();
this.GB_Roamer.ResumeLayout(false);
this.GB_FlyDest.ResumeLayout(false);
this.GB_KeySystem.ResumeLayout(false);
this.ResumeLayout(false);
}
@ -218,5 +254,8 @@ private void InitializeComponent()
private System.Windows.Forms.GroupBox GB_FlyDest;
private System.Windows.Forms.CheckedListBox CLB_FlyDest;
private System.Windows.Forms.Button B_AllFlyDest;
private System.Windows.Forms.GroupBox GB_KeySystem;
private System.Windows.Forms.Button B_AllKeys;
private System.Windows.Forms.CheckedListBox CLB_KeySystem;
}
}

View File

@ -35,6 +35,17 @@ private void B_Save_Click(object sender, EventArgs e)
protected int ofsLibPass = 0x212BC;
protected uint keyLibPass = 0x0132B536;
private uint valLibPass;
private bool bLibPass;
protected int ofsKS = 0x25828;
protected uint[] keyKS = new uint[] {
// 0x34525, 0x11963, // Selected City
// 0x31239, 0x15657, 0x49589, // Selected Difficulty
// 0x94525, 0x81963, 0x38569, // Selected Mystery Door
0x35691, 0x18256, 0x59389, 0x48292, 0x09892, // Obtained Keys(EasyMode, Challenge, City, Iron, Iceberg)
0x93389, 0x22843, 0x34771, 0xAB031, 0xB3818, // Unlocked(EasyMode, Challenge, City, Iron, Iceberg)
};
private uint[] valKS;
private bool[] bKS;
private void readMain()
{
string[] FlyDestA = null;
@ -55,20 +66,42 @@ private void readMain()
10, 13, 12, 14,
};
break;
/* case GameVersion.B2W2:
ofsFly = 0;
FlyDestA = new[];
FlyDestC = new[];
break; */
case GameVersion.B2W2:
ofsFly = 0x20392;
FlyDestA = new[] {
"Aspertia City", "Floccesy Town", "Virbank City",
"Nuvema Town", "Accumula Town", "Striaton City", "Nacrene City",
"Castelia City", "Nimbasa City", "Driftveil City", "Mistralton City",
"Icirrus City", "Opelucid City",
"Lacunosa Town", "Undella Town", "Black City/White Forest",
"Lentimas Town", "Humilau City", "Victory Road", "Pokemon League",
"Pokestar Studios", "Join Avenue", "PWT", "(Unity Tower)",
};
FlyDestC = new[] {
24, 27, 25,
8, 9, 10, 11,
12, 13, 14, 15,
16, 17,
18, 21, 20,
28, 26, 66, 19,
5, 6, 7, 22,
};
break;
}
ushort val = BitConverter.ToUInt16(SAV.Data, ofsFly);
uint valFly = BitConverter.ToUInt32(SAV.Data, ofsFly);
CLB_FlyDest.Items.Clear();
CLB_FlyDest.Items.AddRange(FlyDestA);
for (int i = 0; i < CLB_FlyDest.Items.Count; i++)
CLB_FlyDest.SetItemChecked(i, (val & 1 << FlyDestC[i]) != 0);
{
if (FlyDestC[i] < 32)
CLB_FlyDest.SetItemChecked(i, (valFly & (uint)1 << FlyDestC[i]) != 0);
else
CLB_FlyDest.SetItemChecked(i, (SAV.Data[ofsFly + (FlyDestC[i] >> 3)] & 1 << (FlyDestC[i] & 7)) != 0);
}
if (SAV.BW)
{
GB_KeySystem.Visible = false;
// Roamer
cbr = new ComboBox[] { CB_Roamer642, CB_Roamer641 };
ComboItem[] states = new[] {
@ -94,20 +127,43 @@ private void readMain()
// LibertyPass
valLibPass = keyLibPass ^ (uint)(SAV.SID << 16 | SAV.TID);
CHK_LibertyPass.Checked = BitConverter.ToUInt32(SAV.Data, ofsLibPass) == valLibPass;
bLibPass = BitConverter.ToUInt32(SAV.Data, ofsLibPass) == valLibPass;
CHK_LibertyPass.Checked = bLibPass;
}
else
else if (SAV.B2W2)
{
GB_Roamer.Visible = CHK_LibertyPass.Visible = false;
// KeySystem
string[] KeySystemA = new[] {
"Obtain EasyKey", "Obtain ChallengeKey", "Obtain CityKey", "Obtain IronKey", "Obtain IcebergKey",
"Unlock EasyMode", "Unlock ChallengeMode", "Unlock City", "Unlock IronChamber", "Unlock IcebergChamber",
};
uint KSID = BitConverter.ToUInt32(SAV.Data, ofsKS + 0x34);
valKS = new uint[keyKS.Length];
bKS = new bool[keyKS.Length];
CLB_KeySystem.Items.Clear();
for (int i = 0; i < valKS.Length; i++)
{
valKS[i] = keyKS[i] ^ KSID;
bKS[i] = BitConverter.ToUInt32(SAV.Data, ofsKS + (i << 2)) == valKS[i];
CLB_KeySystem.Items.Add(KeySystemA[i], bKS[i]);
}
}
else GB_KeySystem.Visible = GB_Roamer.Visible = CHK_LibertyPass.Visible = false;
}
private void saveMain()
{
ushort valFly = BitConverter.ToUInt16(SAV.Data, ofsFly);
uint valFly = BitConverter.ToUInt32(SAV.Data, ofsFly);
for (int i = 0; i < CLB_FlyDest.Items.Count; i++)
{
if (CLB_FlyDest.GetItemChecked(i))
valFly |= (ushort)(1 << FlyDestC[i]);
else
valFly &= (ushort)~(1 << FlyDestC[i]);
if (FlyDestC[i] < 32)
{
if (CLB_FlyDest.GetItemChecked(i))
valFly |= (uint)1 << FlyDestC[i];
else
valFly &= ~((uint)1 << FlyDestC[i]);
}
else SAV.Data[ofsFly + (FlyDestC[i] >> 3)] = (byte)(SAV.Data[ofsFly + (FlyDestC[i] >> 3)] & ~(1 << (FlyDestC[i] & 7)) | ((CLB_FlyDest.GetItemChecked(i) ? 1 : 0) << (FlyDestC[i] & 7)));
}
BitConverter.GetBytes(valFly).CopyTo(SAV.Data, ofsFly);
@ -130,8 +186,15 @@ private void saveMain()
}
// LibertyPass
if (CHK_LibertyPass.Checked ^ BitConverter.ToUInt32(SAV.Data, ofsLibPass) == valLibPass)
BitConverter.GetBytes(CHK_LibertyPass.Checked ? valLibPass : (uint)0).CopyTo(SAV.Data, ofsLibPass);
if (CHK_LibertyPass.Checked ^ bLibPass)
BitConverter.GetBytes(bLibPass ? (uint)0 : valLibPass).CopyTo(SAV.Data, ofsLibPass);
}
else if (SAV.B2W2)
{
// KeySystem
for (int i = 0; i < CLB_KeySystem.Items.Count; i++)
if (CLB_KeySystem.GetItemChecked(i) ^ bKS[i])
BitConverter.GetBytes(bKS[i] ? (uint)0 : valKS[i]).CopyTo(SAV.Data, ofsKS + (i << 2));
}
}
private void B_AllFlyDest_Click(object sender, EventArgs e)
@ -139,5 +202,11 @@ private void B_AllFlyDest_Click(object sender, EventArgs e)
for (int i = 0; i < CLB_FlyDest.Items.Count; i++)
CLB_FlyDest.SetItemChecked(i, true);
}
private void B_AllKeys_Click(object sender, EventArgs e)
{
for (int i = 0; i < CLB_KeySystem.Items.Count; i++)
CLB_KeySystem.SetItemChecked(i, true);
}
}
}