Misc tweaks

replace linq for Encrypt/Decrypt pkmdata fetch with faster length check
& optional resize (Span pls!?)
update pk6 comment for why affection is not cleared
This commit is contained in:
Kurt 2019-02-23 16:05:01 -08:00
parent d792c0d3a0
commit 52dd2d6701
4 changed files with 18 additions and 9 deletions

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
namespace PKHeX.Core
{
@ -98,7 +99,7 @@ private void SetSpeciesValues(int value)
public override int Version { get => (int)GameVersion.RBY; set { } }
public override int PKRS_Strain { get => 0; set { } }
public override int PKRS_Days { get => 0; set { } }
public override bool CanHoldItem(ushort[] ValidArray) => false;
public override bool CanHoldItem(IList<ushort> ValidArray) => false;
// Maximums
public override int MaxMoveID => Legal.MaxMoveID_1;

View File

@ -296,7 +296,7 @@ public PK4 ConvertToPK4()
pk4.OT_Name = OT_Name;
// Set Final Data
pk4.Met_Level = Experience.GetLevel(pk4.EXP, pk4.Species, 0);
pk4.Met_Level = pk4.CurrentLevel;
pk4.Gender = PKX.GetGenderFromPID(pk4.Species, pk4.PID);
pk4.IsNicknamed = IsNicknamed;

View File

@ -395,8 +395,7 @@ public void FixMemories()
if (IsUntraded)
HT_Friendship = HT_Affection = HT_TextVar = HT_Memory = HT_Intensity = HT_Feeling = 0;
if (!Gen6)
/* OT_Affection = */
OT_TextVar = OT_Memory = OT_Intensity = OT_Feeling = 0;
OT_TextVar = OT_Memory = OT_Intensity = OT_Feeling = 0; // Don't clear OT affection; OR/AS Contest Glitch
this.SanitizeGeoLocationData();
}

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace PKHeX.Core
@ -21,10 +22,18 @@ public abstract class PKM : ITrainerID, ILangNick, IGameValueLimit
public int Box { get; set; } = -1; // Batch Editor
public int Slot { get; set; } = -1; // Batch Editor
public virtual byte[] EncryptedPartyData => Encrypt().Take(SIZE_PARTY).ToArray();
public virtual byte[] EncryptedBoxData => Encrypt().Take(SIZE_STORED).ToArray();
public virtual byte[] DecryptedPartyData => Write().Take(SIZE_PARTY).ToArray();
public virtual byte[] DecryptedBoxData => Write().Take(SIZE_STORED).ToArray();
public virtual byte[] EncryptedPartyData => Truncate(Encrypt(), SIZE_PARTY);
public virtual byte[] EncryptedBoxData => Truncate(Encrypt(), SIZE_STORED);
public virtual byte[] DecryptedPartyData => Truncate(Write(), SIZE_PARTY);
public virtual byte[] DecryptedBoxData => Truncate(Write(), SIZE_STORED);
private static byte[] Truncate(byte[] data, int newSize)
{
if (data.Length != newSize)
Array.Resize(ref data, newSize);
return data;
}
public virtual bool Valid { get => ChecksumValid && Sanity == 0; set { if (!value) return; Sanity = 0; RefreshChecksum(); } }
// Trash Bytes
@ -834,7 +843,7 @@ public bool ForcePartyData()
/// </summary>
/// <param name="ValidArray">Items that the <see cref="PKM"/> can hold.</param>
/// <returns>True/False if the <see cref="PKM"/> can hold its <see cref="HeldItem"/>.</returns>
public virtual bool CanHoldItem(ushort[] ValidArray) => ValidArray.Contains((ushort)HeldItem);
public virtual bool CanHoldItem(IList<ushort> ValidArray) => ValidArray.Contains((ushort)HeldItem);
/// <summary>
/// Deep clones the <see cref="PKM"/> object. The clone will not have any shared resources with the source.