From 99baca5f5e86b413b2c0a58d2e1161ca8a7786d8 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 16 Mar 2019 20:04:44 -0700 Subject: [PATCH] Use min parameter count PK2 doesn't like getting passed null for the byte[] parameter (rightly so); don't depend on the src code order having the first constructor being the one with the least arguments fix it in pk1/2 so that the first constructor has the least args, anyway --- PKHeX.Core/PKM/PK1.cs | 2 +- PKHeX.Core/PKM/PK2.cs | 2 +- PKHeX.Core/PKM/Util/PKMConverter.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/PKHeX.Core/PKM/PK1.cs b/PKHeX.Core/PKM/PK1.cs index 924b234c9..d1427e68d 100644 --- a/PKHeX.Core/PKM/PK1.cs +++ b/PKHeX.Core/PKM/PK1.cs @@ -16,8 +16,8 @@ public sealed class PK1 : _K12 public override int Format => 1; - public PK1(byte[] decryptedData, bool jp = false) : base(decryptedData, jp) { } public PK1(bool jp = false) : base(new byte[PKX.SIZE_1PARTY], jp) { } + public PK1(byte[] decryptedData, bool jp = false) : base(decryptedData, jp) { } public override PKM Clone() => new PK1((byte[])Data.Clone(), Japanese) { diff --git a/PKHeX.Core/PKM/PK2.cs b/PKHeX.Core/PKM/PK2.cs index f8bf91a63..a27aadb95 100644 --- a/PKHeX.Core/PKM/PK2.cs +++ b/PKHeX.Core/PKM/PK2.cs @@ -15,8 +15,8 @@ public sealed class PK2 : _K12 public override int Format => 2; - public PK2(byte[] decryptedData, bool jp = false) : base(decryptedData, jp) { } public PK2(bool jp = false) : base(new byte[PKX.SIZE_2PARTY], jp) { } + public PK2(byte[] decryptedData, bool jp = false) : base(decryptedData, jp) { } public override PKM Clone() => new PK2((byte[])Data.Clone(), Japanese) { diff --git a/PKHeX.Core/PKM/Util/PKMConverter.cs b/PKHeX.Core/PKM/Util/PKMConverter.cs index 3b9b3824d..3e27e1cec 100644 --- a/PKHeX.Core/PKM/Util/PKMConverter.cs +++ b/PKHeX.Core/PKM/Util/PKMConverter.cs @@ -445,7 +445,7 @@ public static string GetIncompatibleGBMessage(PKM pk, bool destJP) public static PKM GetBlank(Type t) { var constructors = t.GetTypeInfo().DeclaredConstructors.Where(z => !z.IsStatic); - var argCount = constructors.First().GetParameters().Length; + var argCount = constructors.Min(z => z.GetParameters().Length); return (PKM)Activator.CreateInstance(t, new object[argCount]); }