From 3d1e3b6e8b8bc67a5da50ebecd1009333e072f4e Mon Sep 17 00:00:00 2001 From: Kurt Date: Wed, 26 May 2021 22:45:45 -0700 Subject: [PATCH] Revert implicit byte cast similar to earlier pkNX/pkhex commit; this wasn't an intended c# feature --- pk3DS.Core/CTR/CTR.cs | 4 ++-- pk3DS.Core/Structures/Gen7/EncounterGift7.cs | 2 +- pk3DS.Core/Structures/Gen7/TrainerData7.cs | 2 +- pk3DS.Core/Structures/PersonalInfo/PersonalInfoSM.cs | 2 +- pk3DS/Subforms/Gen6/MegaEvoEditor6.cs | 2 +- pk3DS/Subforms/Gen6/TitleScreenEditor6.cs | 5 ++--- pk3DS/Subforms/Gen7/MegaEvoEditor7.cs | 2 +- pk3DS/Subforms/ShinyRate.cs | 2 +- 8 files changed, 10 insertions(+), 11 deletions(-) diff --git a/pk3DS.Core/CTR/CTR.cs b/pk3DS.Core/CTR/CTR.cs index 36224f0..5a0f321 100644 --- a/pk3DS.Core/CTR/CTR.cs +++ b/pk3DS.Core/CTR/CTR.cs @@ -155,9 +155,9 @@ internal static NCSD SetNCSD(NCCH NCCH, bool Card2, RichTextBox TB_Progress = nu } NCSD.Header.flags = new byte[0x8]; NCSD.Header.flags[0] = 0; // 0-255 seconds of waiting for save writing. - NCSD.Header.flags[3] = NCSD.Card2 ? 2 : 1; // Media Card Device: 1 = NOR Flash, 2 = None, 3 = BT + NCSD.Header.flags[3] = NCSD.Card2 ? (byte)2 : (byte)1; // Media Card Device: 1 = NOR Flash, 2 = None, 3 = BT NCSD.Header.flags[4] = 1; // Media Platform Index: 1 = CTR - NCSD.Header.flags[5] = NCSD.Card2 ? 2 : 1; // Media Type Index: 0 = Inner Device, 1 = Card1, 2 = Card2, 3 = Extended Device + NCSD.Header.flags[5] = NCSD.Card2 ? (byte)2 : (byte)1; // Media Type Index: 0 = Inner Device, 1 = Card1, 2 = Card2, 3 = Extended Device NCSD.Header.flags[6] = 0; // Media Unit Size. Same as NCCH. NCSD.Header.flags[7] = 0; // Old Media Card Device. NCSD.Header.NCCHIdTable = new ulong[8]; diff --git a/pk3DS.Core/Structures/Gen7/EncounterGift7.cs b/pk3DS.Core/Structures/Gen7/EncounterGift7.cs index 0c1d402..b0e7674 100644 --- a/pk3DS.Core/Structures/Gen7/EncounterGift7.cs +++ b/pk3DS.Core/Structures/Gen7/EncounterGift7.cs @@ -63,7 +63,7 @@ public override int HeldItem public bool IsEgg { get => Data[0xA] == 1; - set => Data[0xA] = value ? 1 : 0; + set => Data[0xA] = value ? (byte)1 : (byte)0; } public int SpecialMove diff --git a/pk3DS.Core/Structures/Gen7/TrainerData7.cs b/pk3DS.Core/Structures/Gen7/TrainerData7.cs index 5175fd5..044d144 100644 --- a/pk3DS.Core/Structures/Gen7/TrainerData7.cs +++ b/pk3DS.Core/Structures/Gen7/TrainerData7.cs @@ -33,7 +33,7 @@ public TrainerData7(byte[] tr = null, byte[] tp = null) public int Item4 { get => BitConverter.ToUInt16(trdata, 0x0A); set => BitConverter.GetBytes((ushort)value).CopyTo(trdata, 0x0A); } public int AI { get => trdata[0x0C]; set => trdata[0x0C] = (byte)value; } - public bool Flag { get => trdata[0x0D] == 1; set => trdata[0x0D] = value ? 1 : 0; } + public bool Flag { get => trdata[0x0D] == 1; set => trdata[0x0D] = value ? (byte)1 : (byte)0; } public int Money { get => trdata[0x11]; set => trdata[0x11] = (byte)value; } public void Write(out byte[] tr, out byte[] pk) diff --git a/pk3DS.Core/Structures/PersonalInfo/PersonalInfoSM.cs b/pk3DS.Core/Structures/PersonalInfo/PersonalInfoSM.cs index 29be978..68bb119 100644 --- a/pk3DS.Core/Structures/PersonalInfo/PersonalInfoSM.cs +++ b/pk3DS.Core/Structures/PersonalInfo/PersonalInfoSM.cs @@ -34,6 +34,6 @@ public override byte[] Write() public int SpecialZ_Item { get => BitConverter.ToUInt16(Data, 0x4C); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x4C); } public int SpecialZ_BaseMove { get => BitConverter.ToUInt16(Data, 0x4E); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x4E); } public int SpecialZ_ZMove { get => BitConverter.ToUInt16(Data, 0x50); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x50); } - public bool LocalVariant { get => Data[0x52] == 1; set => Data[0x52] = value ? 1 : 0; } + public bool LocalVariant { get => Data[0x52] == 1; set => Data[0x52] = value ? (byte)1 : (byte)0; } } } diff --git a/pk3DS/Subforms/Gen6/MegaEvoEditor6.cs b/pk3DS/Subforms/Gen6/MegaEvoEditor6.cs index fe14743..19ea13b 100644 --- a/pk3DS/Subforms/Gen6/MegaEvoEditor6.cs +++ b/pk3DS/Subforms/Gen6/MegaEvoEditor6.cs @@ -132,7 +132,7 @@ private void SetEntry() { if (me.Method[i] > 1) return; // Shouldn't hit this. - me.Method[i] = checkbox_spec[i].Checked ? 1 : 0; + me.Method[i] = checkbox_spec[i].Checked ? (byte)1 : (byte)0; me.Argument[i] = (ushort)WinFormsUtil.GetIndex(item_spec[i]); me.Form[i] = (ushort)forme_spec[i].SelectedIndex; } diff --git a/pk3DS/Subforms/Gen6/TitleScreenEditor6.cs b/pk3DS/Subforms/Gen6/TitleScreenEditor6.cs index 73bd47a..ac68cea 100644 --- a/pk3DS/Subforms/Gen6/TitleScreenEditor6.cs +++ b/pk3DS/Subforms/Gen6/TitleScreenEditor6.cs @@ -139,11 +139,11 @@ private void InsertFile(string path) { if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Overwrite image?")) return; - byte[] data = File.ReadAllBytes(path); byte[] bclim; if (Path.GetExtension(path) == ".bclim") // bclim opened { + byte[] data = File.ReadAllBytes(path); var img = BCLIM.Analyze(data, path); if (img.Width != PB_Image.Width || img.Height != PB_Image.Height) { @@ -155,8 +155,7 @@ private void InsertFile(string path) } else // image { - using Stream BitmapStream = new MemoryStream(data); - Image img = Image.FromStream(BitmapStream); + Image img = Image.FromFile(path); if (img.Width != PB_Image.Width || img.Height != PB_Image.Height) { WinFormsUtil.Alert("Image sizes do not match.", diff --git a/pk3DS/Subforms/Gen7/MegaEvoEditor7.cs b/pk3DS/Subforms/Gen7/MegaEvoEditor7.cs index c823cbc..fb4ae8d 100644 --- a/pk3DS/Subforms/Gen7/MegaEvoEditor7.cs +++ b/pk3DS/Subforms/Gen7/MegaEvoEditor7.cs @@ -132,7 +132,7 @@ private void SetEntry() { if (me.Method[i] > 1) return; // Shouldn't hit this. - me.Method[i] = checkbox_spec[i].Checked ? 1 : 0; + me.Method[i] = checkbox_spec[i].Checked ? (byte)1 : (byte)0; me.Argument[i] = (ushort)WinFormsUtil.GetIndex(item_spec[i]); me.Form[i] = (ushort)forme_spec[i].SelectedIndex; } diff --git a/pk3DS/Subforms/ShinyRate.cs b/pk3DS/Subforms/ShinyRate.cs index a4a43ff..c17b45d 100644 --- a/pk3DS/Subforms/ShinyRate.cs +++ b/pk3DS/Subforms/ShinyRate.cs @@ -117,7 +117,7 @@ private void B_Save_Click(object sender, EventArgs e) { WriteCodePatch(); if (CHK_EverythingShiny.Enabled) - exefsData[alwaysIndex] = CHK_EverythingShiny.Checked ? 0xEA : 0x0A; + exefsData[alwaysIndex] = CHK_EverythingShiny.Checked ? (byte)0xEA : (byte)0x0A; File.WriteAllBytes(codebin, exefsData); Close(); }