mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-27 06:20:25 +00:00
More readonly struct tweaks
help dat compiler minor clean elsewhere
This commit is contained in:
parent
39d11f5f2f
commit
9401b7a790
16 changed files with 72 additions and 67 deletions
|
@ -1,12 +1,20 @@
|
|||
namespace PKHeX.Core
|
||||
{
|
||||
public struct BoxManipParam
|
||||
public readonly struct BoxManipParam
|
||||
{
|
||||
public int Start { get; set; }
|
||||
public int Stop { get; set; }
|
||||
public bool Reverse { get; set; }
|
||||
public readonly int Start;
|
||||
public readonly int Stop;
|
||||
public readonly bool Reverse;
|
||||
|
||||
public override bool Equals(object obj) => obj is BoxManipParam p && p.Start == Start && p.Stop == Stop && p.Reverse == Reverse;
|
||||
public BoxManipParam(int start, int stop, bool reverse = false)
|
||||
{
|
||||
Start = start;
|
||||
Stop = stop;
|
||||
Reverse = reverse;
|
||||
}
|
||||
|
||||
public bool Equals(BoxManipParam p) => p.Start == Start && p.Stop == Stop && p.Reverse == Reverse;
|
||||
public override bool Equals(object obj) => obj is BoxManipParam p && Equals(p);
|
||||
public override int GetHashCode() => -1;
|
||||
public static bool operator ==(BoxManipParam left, BoxManipParam right) => left.Equals(right);
|
||||
public static bool operator !=(BoxManipParam left, BoxManipParam right) => !(left == right);
|
||||
|
|
|
@ -18,12 +18,9 @@
|
|||
if (!usable)
|
||||
return false;
|
||||
|
||||
var param = new BoxManipParam
|
||||
{
|
||||
Reverse = reverse,
|
||||
Start = allBoxes ? 0 : box,
|
||||
Stop = allBoxes ? SAV.BoxCount - 1 : box,
|
||||
};
|
||||
var start = allBoxes ? 0 : box;
|
||||
var stop = allBoxes ? SAV.BoxCount - 1 : box;
|
||||
var param = new BoxManipParam(start, stop, reverse);
|
||||
|
||||
var prompt = manip.GetPrompt(allBoxes);
|
||||
var fail = manip.GetFail(allBoxes);
|
||||
|
|
|
@ -8,32 +8,19 @@ namespace PKHeX.Core
|
|||
/// </summary>
|
||||
public readonly struct ComboItem : IEquatable<int>
|
||||
{
|
||||
public readonly string Text;
|
||||
public readonly int Value;
|
||||
|
||||
public ComboItem(string text, int value)
|
||||
{
|
||||
Text = text;
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public string Text { get; }
|
||||
public int Value { get; }
|
||||
|
||||
public bool Equals(ComboItem other) => Value == other.Value && string.Equals(Text, other.Text);
|
||||
public bool Equals(int other) => Value == other;
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is null) return false;
|
||||
return obj is ComboItem other && Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
return ((Text?.GetHashCode() ?? 0) * 397) ^ Value;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object obj) => obj is ComboItem other && Equals(other);
|
||||
public override int GetHashCode() => Value;
|
||||
public static bool operator ==(ComboItem left, ComboItem right) => left.Equals(right);
|
||||
public static bool operator !=(ComboItem left, ComboItem right) => !(left == right);
|
||||
}
|
||||
|
|
|
@ -230,13 +230,13 @@ namespace PKHeX.Core
|
|||
};
|
||||
}
|
||||
|
||||
public override bool Equals(object obj) => obj is MemoryVariableSet v
|
||||
&& v.Handler == Handler
|
||||
&& v.MemoryID == MemoryID
|
||||
&& v.Variable == Variable
|
||||
&& v.Intensity == Intensity
|
||||
&& v.Feeling == Feeling;
|
||||
public bool Equals(MemoryVariableSet v) => v.Handler == Handler
|
||||
&& v.MemoryID == MemoryID
|
||||
&& v.Variable == Variable
|
||||
&& v.Intensity == Intensity
|
||||
&& v.Feeling == Feeling;
|
||||
|
||||
public override bool Equals(object obj) => obj is MemoryVariableSet v && Equals(v);
|
||||
public override int GetHashCode() => -1;
|
||||
public static bool operator ==(MemoryVariableSet left, MemoryVariableSet right) => left.Equals(right);
|
||||
public static bool operator !=(MemoryVariableSet left, MemoryVariableSet right) => !(left == right);
|
||||
|
|
|
@ -34,8 +34,9 @@ namespace PKHeX.Core
|
|||
}
|
||||
|
||||
public bool IsLevelUp => Level >= 0;
|
||||
public bool Equals(LearnVersion v) => v.Game == Game && v.Level == Level;
|
||||
|
||||
public override bool Equals(object obj) => obj is LearnVersion v && v.Game == Game && v.Level == Level;
|
||||
public override bool Equals(object obj) => obj is LearnVersion v && Equals(v);
|
||||
public override int GetHashCode() => -1;
|
||||
public static bool operator ==(LearnVersion left, LearnVersion right) => left.Equals(right);
|
||||
public static bool operator !=(LearnVersion left, LearnVersion right) => !(left == right);
|
||||
|
|
|
@ -13,7 +13,8 @@ namespace PKHeX.Core
|
|||
Charm3 = charm3;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj) => obj is SeedInfo s && s.Charm3 == Charm3 && s.Seed == Seed;
|
||||
public override bool Equals(object obj) => obj is SeedInfo s && Equals(s);
|
||||
public bool Equals(SeedInfo s) => s.Charm3 == Charm3 && s.Seed == Seed;
|
||||
public override int GetHashCode() => -1;
|
||||
public static bool operator ==(SeedInfo left, SeedInfo right) => left.Equals(right);
|
||||
public static bool operator !=(SeedInfo left, SeedInfo right) => !(left == right);
|
||||
|
|
|
@ -94,16 +94,16 @@ namespace PKHeX.Core
|
|||
}
|
||||
}
|
||||
|
||||
private struct Range
|
||||
private readonly struct Range
|
||||
{
|
||||
internal readonly uint Min;
|
||||
internal readonly uint Max;
|
||||
|
||||
internal Range(uint min, uint max)
|
||||
{
|
||||
Min = min;
|
||||
Max = max;
|
||||
}
|
||||
|
||||
internal uint Min { get; }
|
||||
internal uint Max { get; }
|
||||
}
|
||||
|
||||
private static Range[] GetRanges(params uint[] rates)
|
||||
|
|
|
@ -66,11 +66,18 @@ namespace PKHeX.Core
|
|||
return true;
|
||||
}
|
||||
|
||||
private struct PIDIVGroup
|
||||
private readonly struct PIDIVGroup
|
||||
{
|
||||
public uint PID;
|
||||
public uint IV1;
|
||||
public uint IV2;
|
||||
private readonly uint PID;
|
||||
private readonly uint IV1;
|
||||
private readonly uint IV2;
|
||||
|
||||
public PIDIVGroup(uint pid, uint iv1, uint iv2)
|
||||
{
|
||||
PID = pid;
|
||||
IV1 = iv1;
|
||||
IV2 = iv2;
|
||||
}
|
||||
|
||||
public bool Equals(uint pid, uint iv1, uint iv2) => PID == pid && IV1 == iv1 && IV2 == iv2;
|
||||
}
|
||||
|
@ -78,19 +85,18 @@ namespace PKHeX.Core
|
|||
private static PIDIVGroup GenerateValidColoStarterPID(ref uint uSeed, int TID, int SID)
|
||||
{
|
||||
var rng = RNG.XDRNG;
|
||||
PIDIVGroup group = new PIDIVGroup();
|
||||
|
||||
uSeed = rng.Advance(uSeed, 2); // skip fakePID
|
||||
group.IV1 = (uSeed >> 16) & 0x7FFF;
|
||||
var IV1 = (uSeed >> 16) & 0x7FFF;
|
||||
uSeed = rng.Next(uSeed);
|
||||
group.IV2 = (uSeed >> 16) & 0x7FFF;
|
||||
var IV2 = (uSeed >> 16) & 0x7FFF;
|
||||
uSeed = rng.Next(uSeed);
|
||||
uSeed = rng.Advance(uSeed, 1); // skip ability call
|
||||
group.PID = GenerateStarterPID(ref uSeed, TID, SID);
|
||||
var PID = GenerateStarterPID(ref uSeed, TID, SID);
|
||||
|
||||
uSeed = rng.Advance(uSeed, 2); // PID calls consumed
|
||||
|
||||
return group;
|
||||
return new PIDIVGroup(PID, IV1, IV2);
|
||||
}
|
||||
|
||||
private static bool IsShiny(int TID, int SID, uint PID) => (TID ^ SID ^ (PID >> 16) ^ (PID & 0xFFFF)) < 8;
|
||||
|
|
|
@ -3,9 +3,15 @@
|
|||
/// <summary>
|
||||
/// Message Passing for frame results.
|
||||
/// </summary>
|
||||
internal struct SeedFrame
|
||||
internal readonly struct SeedFrame
|
||||
{
|
||||
public uint PID;
|
||||
public int FrameID;
|
||||
public readonly uint PID;
|
||||
public readonly int FrameID;
|
||||
|
||||
internal SeedFrame(uint pid, int frame)
|
||||
{
|
||||
PID = pid;
|
||||
FrameID = frame;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -120,7 +120,7 @@ namespace PKHeX.Core
|
|||
{
|
||||
uint pid = Cache[ctr + 1] << 16 | Cache[ctr];
|
||||
if (current.MatchesLock(pid))
|
||||
yield return new SeedFrame { FrameID = ctr + (current.Seen ? 5 : 7), PID = pid };
|
||||
yield return new SeedFrame(pid, ctr + (current.Seen ? 5 : 7));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -179,7 +179,7 @@ namespace PKHeX.Core
|
|||
}
|
||||
uint pid = Cache[ctr + 1] << 16 | Cache[ctr];
|
||||
if (current.MatchesLock(pid))
|
||||
yield return new SeedFrame { FrameID = ctr + (current.Seen ? 5 : 7), PID = pid };
|
||||
yield return new SeedFrame(pid, ctr + (current.Seen ? 5 : 7));
|
||||
|
||||
ctr += 2;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ namespace PKHeX.Core
|
|||
public class SaveBlockAccessorXY : ISaveBlockAccessor<BlockInfo6>, ISaveBlock6XY
|
||||
{
|
||||
public const int boXY = SaveUtil.SIZE_G6XY - 0x200;
|
||||
public int FooterOffset => boXY;
|
||||
|
||||
public static readonly BlockInfo6[] BlocksXY =
|
||||
{
|
||||
|
|
|
@ -914,7 +914,7 @@ namespace PKHeX.Core
|
|||
IsEBerryChecksumValid = EBerryChecksum == chk;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
public RTC3 ClockInitial
|
||||
{
|
||||
get
|
||||
|
|
|
@ -40,12 +40,12 @@ namespace PKHeX.Core
|
|||
{
|
||||
get
|
||||
{
|
||||
switch (Game)
|
||||
return Game switch
|
||||
{
|
||||
case (int)GameVersion.AS: return GameVersion.AS;
|
||||
case (int)GameVersion.OR: return GameVersion.OR;
|
||||
}
|
||||
return GameVersion.Invalid;
|
||||
(int) GameVersion.AS => GameVersion.AS,
|
||||
(int) GameVersion.OR => GameVersion.OR,
|
||||
_ => GameVersion.Invalid
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
MegaEvolve = 8,
|
||||
}
|
||||
|
||||
public struct TurnActionInstruction
|
||||
public readonly struct TurnActionInstruction
|
||||
{
|
||||
public readonly int PlayerID;
|
||||
public readonly int Count;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
namespace PKHeX.Core
|
||||
{
|
||||
public struct TurnStartInstruction
|
||||
public readonly struct TurnStartInstruction
|
||||
{
|
||||
public TurnStartCode TurnCode;
|
||||
public int Count;
|
||||
public readonly TurnStartCode TurnCode;
|
||||
public readonly int Count;
|
||||
|
||||
public TurnStartInstruction(byte Op)
|
||||
{
|
||||
|
|
|
@ -86,6 +86,6 @@ namespace PKHeX.Core
|
|||
|
||||
public uint PID { get => BigEndian.ToUInt32(Data, 0x00); set => BigEndian.GetBytes(value).CopyTo(Data, 0x00); }
|
||||
public int Met_Location { get => BigEndian.ToUInt16(Data, 0x06); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x06); }
|
||||
public uint _0x08 { get => BigEndian.ToUInt32(Data, 0x08); set => BigEndian.GetBytes(value).CopyTo(Data, 0x08); }
|
||||
public uint Unk08 { get => BigEndian.ToUInt32(Data, 0x08); set => BigEndian.GetBytes(value).CopyTo(Data, 0x08); }
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue