mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-12 23:37:07 +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
|
namespace PKHeX.Core
|
||||||
{
|
{
|
||||||
public struct BoxManipParam
|
public readonly struct BoxManipParam
|
||||||
{
|
{
|
||||||
public int Start { get; set; }
|
public readonly int Start;
|
||||||
public int Stop { get; set; }
|
public readonly int Stop;
|
||||||
public bool Reverse { get; set; }
|
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 override int GetHashCode() => -1;
|
||||||
public static bool operator ==(BoxManipParam left, BoxManipParam right) => left.Equals(right);
|
public static bool operator ==(BoxManipParam left, BoxManipParam right) => left.Equals(right);
|
||||||
public static bool operator !=(BoxManipParam left, BoxManipParam right) => !(left == right);
|
public static bool operator !=(BoxManipParam left, BoxManipParam right) => !(left == right);
|
||||||
|
|
|
@ -18,12 +18,9 @@
|
||||||
if (!usable)
|
if (!usable)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var param = new BoxManipParam
|
var start = allBoxes ? 0 : box;
|
||||||
{
|
var stop = allBoxes ? SAV.BoxCount - 1 : box;
|
||||||
Reverse = reverse,
|
var param = new BoxManipParam(start, stop, reverse);
|
||||||
Start = allBoxes ? 0 : box,
|
|
||||||
Stop = allBoxes ? SAV.BoxCount - 1 : box,
|
|
||||||
};
|
|
||||||
|
|
||||||
var prompt = manip.GetPrompt(allBoxes);
|
var prompt = manip.GetPrompt(allBoxes);
|
||||||
var fail = manip.GetFail(allBoxes);
|
var fail = manip.GetFail(allBoxes);
|
||||||
|
|
|
@ -8,32 +8,19 @@ namespace PKHeX.Core
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly struct ComboItem : IEquatable<int>
|
public readonly struct ComboItem : IEquatable<int>
|
||||||
{
|
{
|
||||||
|
public readonly string Text;
|
||||||
|
public readonly int Value;
|
||||||
|
|
||||||
public ComboItem(string text, int value)
|
public ComboItem(string text, int value)
|
||||||
{
|
{
|
||||||
Text = text;
|
Text = text;
|
||||||
Value = value;
|
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(ComboItem other) => Value == other.Value && string.Equals(Text, other.Text);
|
||||||
public bool Equals(int other) => Value == other;
|
public bool Equals(int other) => Value == other;
|
||||||
|
public override bool Equals(object obj) => obj is ComboItem other && Equals(other);
|
||||||
public override bool Equals(object obj)
|
public override int GetHashCode() => Value;
|
||||||
{
|
|
||||||
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 static bool operator ==(ComboItem left, ComboItem right) => left.Equals(right);
|
public static bool operator ==(ComboItem left, ComboItem right) => left.Equals(right);
|
||||||
public static bool operator !=(ComboItem left, ComboItem right) => !(left == 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
|
public bool Equals(MemoryVariableSet v) => v.Handler == Handler
|
||||||
&& v.Handler == Handler
|
&& v.MemoryID == MemoryID
|
||||||
&& v.MemoryID == MemoryID
|
&& v.Variable == Variable
|
||||||
&& v.Variable == Variable
|
&& v.Intensity == Intensity
|
||||||
&& v.Intensity == Intensity
|
&& v.Feeling == Feeling;
|
||||||
&& v.Feeling == Feeling;
|
|
||||||
|
|
||||||
|
public override bool Equals(object obj) => obj is MemoryVariableSet v && Equals(v);
|
||||||
public override int GetHashCode() => -1;
|
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.Equals(right);
|
||||||
public static bool operator !=(MemoryVariableSet left, MemoryVariableSet right) => !(left == 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 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 override int GetHashCode() => -1;
|
||||||
public static bool operator ==(LearnVersion left, LearnVersion right) => left.Equals(right);
|
public static bool operator ==(LearnVersion left, LearnVersion right) => left.Equals(right);
|
||||||
public static bool operator !=(LearnVersion left, LearnVersion right) => !(left == right);
|
public static bool operator !=(LearnVersion left, LearnVersion right) => !(left == right);
|
||||||
|
|
|
@ -13,7 +13,8 @@ namespace PKHeX.Core
|
||||||
Charm3 = charm3;
|
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 override int GetHashCode() => -1;
|
||||||
public static bool operator ==(SeedInfo left, SeedInfo right) => left.Equals(right);
|
public static bool operator ==(SeedInfo left, SeedInfo right) => left.Equals(right);
|
||||||
public static bool operator !=(SeedInfo left, SeedInfo right) => !(left == 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)
|
internal Range(uint min, uint max)
|
||||||
{
|
{
|
||||||
Min = min;
|
Min = min;
|
||||||
Max = max;
|
Max = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal uint Min { get; }
|
|
||||||
internal uint Max { get; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Range[] GetRanges(params uint[] rates)
|
private static Range[] GetRanges(params uint[] rates)
|
||||||
|
|
|
@ -66,11 +66,18 @@ namespace PKHeX.Core
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private struct PIDIVGroup
|
private readonly struct PIDIVGroup
|
||||||
{
|
{
|
||||||
public uint PID;
|
private readonly uint PID;
|
||||||
public uint IV1;
|
private readonly uint IV1;
|
||||||
public uint IV2;
|
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;
|
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)
|
private static PIDIVGroup GenerateValidColoStarterPID(ref uint uSeed, int TID, int SID)
|
||||||
{
|
{
|
||||||
var rng = RNG.XDRNG;
|
var rng = RNG.XDRNG;
|
||||||
PIDIVGroup group = new PIDIVGroup();
|
|
||||||
|
|
||||||
uSeed = rng.Advance(uSeed, 2); // skip fakePID
|
uSeed = rng.Advance(uSeed, 2); // skip fakePID
|
||||||
group.IV1 = (uSeed >> 16) & 0x7FFF;
|
var IV1 = (uSeed >> 16) & 0x7FFF;
|
||||||
uSeed = rng.Next(uSeed);
|
uSeed = rng.Next(uSeed);
|
||||||
group.IV2 = (uSeed >> 16) & 0x7FFF;
|
var IV2 = (uSeed >> 16) & 0x7FFF;
|
||||||
uSeed = rng.Next(uSeed);
|
uSeed = rng.Next(uSeed);
|
||||||
uSeed = rng.Advance(uSeed, 1); // skip ability call
|
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
|
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;
|
private static bool IsShiny(int TID, int SID, uint PID) => (TID ^ SID ^ (PID >> 16) ^ (PID & 0xFFFF)) < 8;
|
||||||
|
|
|
@ -3,9 +3,15 @@
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Message Passing for frame results.
|
/// Message Passing for frame results.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal struct SeedFrame
|
internal readonly struct SeedFrame
|
||||||
{
|
{
|
||||||
public uint PID;
|
public readonly uint PID;
|
||||||
public int FrameID;
|
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];
|
uint pid = Cache[ctr + 1] << 16 | Cache[ctr];
|
||||||
if (current.MatchesLock(pid))
|
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>
|
/// <summary>
|
||||||
|
@ -179,7 +179,7 @@ namespace PKHeX.Core
|
||||||
}
|
}
|
||||||
uint pid = Cache[ctr + 1] << 16 | Cache[ctr];
|
uint pid = Cache[ctr + 1] << 16 | Cache[ctr];
|
||||||
if (current.MatchesLock(pid))
|
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;
|
ctr += 2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ namespace PKHeX.Core
|
||||||
public class SaveBlockAccessorXY : ISaveBlockAccessor<BlockInfo6>, ISaveBlock6XY
|
public class SaveBlockAccessorXY : ISaveBlockAccessor<BlockInfo6>, ISaveBlock6XY
|
||||||
{
|
{
|
||||||
public const int boXY = SaveUtil.SIZE_G6XY - 0x200;
|
public const int boXY = SaveUtil.SIZE_G6XY - 0x200;
|
||||||
public int FooterOffset => boXY;
|
|
||||||
|
|
||||||
public static readonly BlockInfo6[] BlocksXY =
|
public static readonly BlockInfo6[] BlocksXY =
|
||||||
{
|
{
|
||||||
|
|
|
@ -914,7 +914,7 @@ namespace PKHeX.Core
|
||||||
IsEBerryChecksumValid = EBerryChecksum == chk;
|
IsEBerryChecksumValid = EBerryChecksum == chk;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public RTC3 ClockInitial
|
public RTC3 ClockInitial
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
|
@ -40,12 +40,12 @@ namespace PKHeX.Core
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
switch (Game)
|
return Game switch
|
||||||
{
|
{
|
||||||
case (int)GameVersion.AS: return GameVersion.AS;
|
(int) GameVersion.AS => GameVersion.AS,
|
||||||
case (int)GameVersion.OR: return GameVersion.OR;
|
(int) GameVersion.OR => GameVersion.OR,
|
||||||
}
|
_ => GameVersion.Invalid
|
||||||
return GameVersion.Invalid;
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
MegaEvolve = 8,
|
MegaEvolve = 8,
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct TurnActionInstruction
|
public readonly struct TurnActionInstruction
|
||||||
{
|
{
|
||||||
public readonly int PlayerID;
|
public readonly int PlayerID;
|
||||||
public readonly int Count;
|
public readonly int Count;
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
namespace PKHeX.Core
|
namespace PKHeX.Core
|
||||||
{
|
{
|
||||||
public struct TurnStartInstruction
|
public readonly struct TurnStartInstruction
|
||||||
{
|
{
|
||||||
public TurnStartCode TurnCode;
|
public readonly TurnStartCode TurnCode;
|
||||||
public int Count;
|
public readonly int Count;
|
||||||
|
|
||||||
public TurnStartInstruction(byte Op)
|
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 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 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