From 3b3229669d963dd4235cef5f952058dbe3e9f2da Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Mon, 2 May 2016 17:14:39 -0700 Subject: [PATCH] Fix pass-by-reference bug. --- Rhydon/MainForm.cs | 3 ++- Rhydon/PK1.cs | 9 +++++++++ Rhydon/PokemonList.cs | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Rhydon/MainForm.cs b/Rhydon/MainForm.cs index c7b6c82..eec78e1 100644 --- a/Rhydon/MainForm.cs +++ b/Rhydon/MainForm.cs @@ -131,9 +131,10 @@ private void InitializeFields() { TB_OT.Text = "Rhydon"; TB_Nickname.Text = "RHYDON"; + TB_TID.Text = 12345.ToString(); pk1.OT_Name = RBY_Encoding.GetBytes(TB_OT.Text); pk1.Nickname = RBY_Encoding.GetBytes(TB_Nickname.Text); - TB_TID.Text = 12345.ToString(); + pk1.TID = 12345; CB_PPu1.SelectedIndex = CB_PPu2.SelectedIndex = CB_PPu3.SelectedIndex = CB_PPu4.SelectedIndex = 0; } } diff --git a/Rhydon/PK1.cs b/Rhydon/PK1.cs index f15b18f..6febf37 100644 --- a/Rhydon/PK1.cs +++ b/Rhydon/PK1.cs @@ -18,6 +18,15 @@ public PK1(byte[] d = null, string i = "") } } + public PK1 Clone() + { + PK1 new_pk1 = new PK1(); + Array.Copy(Data, 0, new_pk1.Data, 0, Data.Length); + Array.Copy(otname, 0, new_pk1.otname, 0, otname.Length); + Array.Copy(nick, 0, new_pk1.nick, 0, nick.Length); + return new_pk1; + } + // Internal Attributes set on creation public byte[] Data; // Raw Storage public string Identifier; // User or Form Custom Attribute diff --git a/Rhydon/PokemonList.cs b/Rhydon/PokemonList.cs index b862613..18254c6 100644 --- a/Rhydon/PokemonList.cs +++ b/Rhydon/PokemonList.cs @@ -98,7 +98,7 @@ public PK1 this[int i] set { if (value == null) return; - Pokemon[i] = value; + Pokemon[i] = value.Clone(); } }