mirror of
https://github.com/kwsch/PKHeX
synced 2025-02-16 13:28:35 +00:00
Revise WC8+ ribbon set logic
For making fake WC*'s, revise logic to use the ribbon span instead of the entire range of bytes. Fix Partner Ribbon not showing up in Ribbon Editor affix list. Closes #4369 (superset, I wanted to change the underlying usage) Co-Authored-By: Manu <52102823+Manu098vm@users.noreply.github.com>
This commit is contained in:
parent
325649b19b
commit
48abd8d080
5 changed files with 25 additions and 25 deletions
|
@ -196,9 +196,9 @@ public sealed class WA8(byte[] Data) : DataMysteryGift(Data), ILangNick, INature
|
|||
// Ribbons 0x24C-0x26C
|
||||
private const int RibbonBytesOffset = 0x244;
|
||||
private const int RibbonBytesCount = 0x20;
|
||||
private const int RibbonByteNone = 0xFF; // signed -1
|
||||
private const byte RibbonByteNone = 0xFF; // signed -1
|
||||
|
||||
private ReadOnlySpan<byte> RibbonSpan => Data.AsSpan(RibbonBytesOffset, RibbonBytesCount);
|
||||
private Span<byte> RibbonSpan => Data.AsSpan(RibbonBytesOffset, RibbonBytesCount);
|
||||
|
||||
public bool HasMarkEncounter8
|
||||
{
|
||||
|
@ -218,13 +218,13 @@ public sealed class WA8(byte[] Data) : DataMysteryGift(Data), ILangNick, INature
|
|||
public byte GetRibbonAtIndex(int byteIndex)
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual<uint>((uint)byteIndex, RibbonBytesCount);
|
||||
return Data[RibbonBytesOffset + byteIndex];
|
||||
return RibbonSpan[byteIndex];
|
||||
}
|
||||
|
||||
public void SetRibbonAtIndex(int byteIndex, byte ribbonIndex)
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual<uint>((uint)byteIndex, RibbonBytesCount);
|
||||
Data[RibbonBytesOffset + byteIndex] = ribbonIndex;
|
||||
RibbonSpan[byteIndex] = ribbonIndex;
|
||||
}
|
||||
|
||||
public int IV_HP { get => Data[0x264]; set => Data[0x264] = (byte)value; }
|
||||
|
@ -804,7 +804,7 @@ public sealed class WA8(byte[] Data) : DataMysteryGift(Data), ILangNick, INature
|
|||
public bool RibbonTwinklingStar { get => this.GetRibbonIndex(TwinklingStar); set => this.SetRibbonIndex(TwinklingStar, value); }
|
||||
public bool RibbonHisui { get => this.GetRibbonIndex(Hisui); set => this.SetRibbonIndex(Hisui, value); }
|
||||
|
||||
public int GetRibbonByte(int index) => Array.IndexOf(Data, (byte)index, RibbonBytesOffset, RibbonBytesCount);
|
||||
public int GetRibbonByte(int index) => RibbonSpan.IndexOf((byte)index);
|
||||
public bool GetRibbon(int index) => GetRibbonByte(index) >= 0;
|
||||
|
||||
public void SetRibbon(int index, bool value = true)
|
||||
|
@ -814,7 +814,7 @@ public sealed class WA8(byte[] Data) : DataMysteryGift(Data), ILangNick, INature
|
|||
{
|
||||
if (GetRibbon(index))
|
||||
return;
|
||||
var openIndex = Array.IndexOf(Data, RibbonByteNone, RibbonBytesOffset, RibbonBytesCount);
|
||||
var openIndex = RibbonSpan.IndexOf(RibbonByteNone);
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(openIndex, nameof(openIndex)); // Full?
|
||||
SetRibbonAtIndex(openIndex, (byte)index);
|
||||
}
|
||||
|
|
|
@ -197,9 +197,9 @@ public sealed class WB8(byte[] Data) : DataMysteryGift(Data),
|
|||
// Ribbons 0x292-0x2B2
|
||||
private const int RibbonBytesOffset = 0x292;
|
||||
private const int RibbonBytesCount = 0x20;
|
||||
private const int RibbonByteNone = 0xFF; // signed -1
|
||||
private const byte RibbonByteNone = 0xFF; // signed -1
|
||||
|
||||
private ReadOnlySpan<byte> RibbonSpan => Data.AsSpan(RibbonBytesOffset, RibbonBytesCount);
|
||||
private Span<byte> RibbonSpan => Data.AsSpan(RibbonBytesOffset, RibbonBytesCount);
|
||||
|
||||
public bool HasMarkEncounter8
|
||||
{
|
||||
|
@ -219,13 +219,13 @@ public sealed class WB8(byte[] Data) : DataMysteryGift(Data),
|
|||
public byte GetRibbonAtIndex(int byteIndex)
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual<uint>((uint)byteIndex, RibbonBytesCount);
|
||||
return Data[RibbonBytesOffset + byteIndex];
|
||||
return RibbonSpan[byteIndex];
|
||||
}
|
||||
|
||||
public void SetRibbonAtIndex(int byteIndex, byte ribbonIndex)
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual<uint>((uint)byteIndex, RibbonBytesCount);
|
||||
Data[RibbonBytesOffset + byteIndex] = ribbonIndex;
|
||||
RibbonSpan[byteIndex] = ribbonIndex;
|
||||
}
|
||||
|
||||
public int IV_HP { get => Data[CardStart + 0x2B2]; set => Data[CardStart + 0x2B2] = (byte)value; }
|
||||
|
@ -821,7 +821,7 @@ public sealed class WB8(byte[] Data) : DataMysteryGift(Data),
|
|||
public bool RibbonTwinklingStar { get => this.GetRibbonIndex(TwinklingStar); set => this.SetRibbonIndex(TwinklingStar, value); }
|
||||
public bool RibbonHisui { get => this.GetRibbonIndex(Hisui); set => this.SetRibbonIndex(Hisui, value); }
|
||||
|
||||
public int GetRibbonByte(int index) => Array.IndexOf(Data, (byte)index, RibbonBytesOffset, RibbonBytesCount);
|
||||
public int GetRibbonByte(int index) => RibbonSpan.IndexOf((byte)index);
|
||||
public bool GetRibbon(int index) => RibbonSpan.Contains((byte)index);
|
||||
|
||||
public void SetRibbon(int index, bool value = true)
|
||||
|
@ -831,7 +831,7 @@ public sealed class WB8(byte[] Data) : DataMysteryGift(Data),
|
|||
{
|
||||
if (GetRibbon(index))
|
||||
return;
|
||||
var openIndex = Array.IndexOf(Data, RibbonByteNone, RibbonBytesOffset, RibbonBytesCount);
|
||||
var openIndex = RibbonSpan.IndexOf(RibbonByteNone);
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(openIndex, nameof(openIndex)); // Full?
|
||||
SetRibbonAtIndex(openIndex, (byte)index);
|
||||
}
|
||||
|
|
|
@ -194,9 +194,9 @@ public sealed class WC8(byte[] Data) : DataMysteryGift(Data), ILangNick, INature
|
|||
// Ribbons 0x24C-0x26C
|
||||
private const int RibbonBytesOffset = 0x24C;
|
||||
private const int RibbonBytesCount = 0x20;
|
||||
private const int RibbonByteNone = 0xFF; // signed -1
|
||||
private const byte RibbonByteNone = 0xFF; // signed -1
|
||||
|
||||
private ReadOnlySpan<byte> RibbonSpan => Data.AsSpan(RibbonBytesOffset, RibbonBytesCount);
|
||||
private Span<byte> RibbonSpan => Data.AsSpan(RibbonBytesOffset, RibbonBytesCount);
|
||||
|
||||
public bool HasMarkEncounter8
|
||||
{
|
||||
|
@ -217,13 +217,13 @@ public sealed class WC8(byte[] Data) : DataMysteryGift(Data), ILangNick, INature
|
|||
public byte GetRibbonAtIndex(int byteIndex)
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual<uint>((uint)byteIndex, RibbonBytesCount);
|
||||
return Data[RibbonBytesOffset + byteIndex];
|
||||
return RibbonSpan[byteIndex];
|
||||
}
|
||||
|
||||
public void SetRibbonAtIndex(int byteIndex, byte ribbonIndex)
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual<uint>((uint)byteIndex, RibbonBytesCount);
|
||||
Data[RibbonBytesOffset + byteIndex] = ribbonIndex;
|
||||
RibbonSpan[byteIndex] = ribbonIndex;
|
||||
}
|
||||
|
||||
public int IV_HP { get => Data[CardStart + 0x26C]; set => Data[CardStart + 0x26C] = (byte)value; }
|
||||
|
@ -871,7 +871,7 @@ public sealed class WC8(byte[] Data) : DataMysteryGift(Data), ILangNick, INature
|
|||
public bool RibbonTwinklingStar { get => this.GetRibbonIndex(TwinklingStar); set => this.SetRibbonIndex(TwinklingStar, value); }
|
||||
public bool RibbonHisui { get => this.GetRibbonIndex(Hisui); set => this.SetRibbonIndex(Hisui, value); }
|
||||
|
||||
public int GetRibbonByte(int index) => Array.IndexOf(Data, (byte)index, RibbonBytesOffset, RibbonBytesCount);
|
||||
public int GetRibbonByte(int index) => RibbonSpan.IndexOf((byte)index);
|
||||
public bool GetRibbon(int index) => RibbonSpan.Contains((byte)index);
|
||||
|
||||
public void SetRibbon(int index, bool value = true)
|
||||
|
@ -881,7 +881,7 @@ public sealed class WC8(byte[] Data) : DataMysteryGift(Data), ILangNick, INature
|
|||
{
|
||||
if (GetRibbon(index))
|
||||
return;
|
||||
var openIndex = Array.IndexOf(Data, RibbonByteNone, RibbonBytesOffset, RibbonBytesCount);
|
||||
var openIndex = RibbonSpan.IndexOf(RibbonByteNone);
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(openIndex, nameof(openIndex)); // Full?
|
||||
SetRibbonAtIndex(openIndex, (byte)index);
|
||||
}
|
||||
|
|
|
@ -217,9 +217,9 @@ public sealed class WC9(byte[] Data) : DataMysteryGift(Data), ILangNick, INature
|
|||
// Ribbons 0x24C-0x26C
|
||||
private const int RibbonBytesOffset = 0x248;
|
||||
private const int RibbonBytesCount = 0x20;
|
||||
private const int RibbonByteNone = 0xFF; // signed -1
|
||||
private const byte RibbonByteNone = 0xFF; // signed -1
|
||||
|
||||
private ReadOnlySpan<byte> RibbonSpan => Data.AsSpan(RibbonBytesOffset, RibbonBytesCount);
|
||||
private Span<byte> RibbonSpan => Data.AsSpan(RibbonBytesOffset, RibbonBytesCount);
|
||||
|
||||
public bool HasMarkEncounter8
|
||||
{
|
||||
|
@ -250,13 +250,13 @@ public sealed class WC9(byte[] Data) : DataMysteryGift(Data), ILangNick, INature
|
|||
public byte GetRibbonAtIndex(int byteIndex)
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual<uint>((uint)byteIndex, RibbonBytesCount);
|
||||
return Data[RibbonBytesOffset + byteIndex];
|
||||
return RibbonSpan[byteIndex];
|
||||
}
|
||||
|
||||
public void SetRibbonAtIndex(int byteIndex, byte ribbonIndex)
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual<uint>((uint)byteIndex, RibbonBytesCount);
|
||||
Data[RibbonBytesOffset + byteIndex] = ribbonIndex;
|
||||
RibbonSpan[byteIndex] = ribbonIndex;
|
||||
}
|
||||
|
||||
public int IV_HP { get => Data[CardStart + 0x268]; set => Data[CardStart + 0x268] = (byte)value; }
|
||||
|
@ -900,7 +900,7 @@ public sealed class WC9(byte[] Data) : DataMysteryGift(Data), ILangNick, INature
|
|||
public bool RibbonMarkTitan { get => this.GetRibbonIndex(MarkTitan); set => this.SetRibbonIndex(MarkTitan, value); }
|
||||
public bool RibbonPartner { get => this.GetRibbonIndex(Partner); set => this.SetRibbonIndex(Partner, value); }
|
||||
|
||||
public int GetRibbonByte(int index) => Array.IndexOf(Data, (byte)index, RibbonBytesOffset, RibbonBytesCount);
|
||||
public int GetRibbonByte(int index) => RibbonSpan.IndexOf((byte)index);
|
||||
public bool GetRibbon(int index) => RibbonSpan.Contains((byte)index);
|
||||
|
||||
public void SetRibbon(int index, bool value = true)
|
||||
|
@ -910,7 +910,7 @@ public sealed class WC9(byte[] Data) : DataMysteryGift(Data), ILangNick, INature
|
|||
{
|
||||
if (GetRibbon(index))
|
||||
return;
|
||||
var openIndex = Array.IndexOf(Data, RibbonByteNone, RibbonBytesOffset, RibbonBytesCount);
|
||||
var openIndex = RibbonSpan.IndexOf(RibbonByteNone);
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(openIndex, nameof(openIndex)); // Full?
|
||||
SetRibbonAtIndex(openIndex, (byte)index);
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ public partial class RibbonEditor : Form
|
|||
return;
|
||||
}
|
||||
|
||||
const int count = AffixedRibbon.Max;
|
||||
const int count = AffixedRibbon.Max + 1; // 0 is a valid index, and max is inclusive with that index.
|
||||
static string GetRibbonPropertyName(int z) => RibbonStrings.GetName($"Ribbon{(RibbonIndex)z}");
|
||||
static ComboItem GetComboItem(int ribbonIndex) => new(GetRibbonPropertyName(ribbonIndex), ribbonIndex);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue