tag partner cards: ygol_query_tag_cards + STOC_TAG_PARTNER_CARDS 0x5F, capability 0x2000, protocol 9 (TICKET-405)
Core: ygol_query_tag_cards(pduel, playerid, out) reads the waiting tag partner's tag_list_hand / tag_list_extra (bit 31 = face-up, like MSG_TAG_SWAP) and tag_list_main sorted ascending; returns the byte length, 0 when not a tag duel. Read only. Server: STOC_TAG_PARTNER_CARDS 0x5F = u8 side + those bytes, no stamp, to that side's two seats only (never the other team, never an observer): after start_duel, after every MSG_TAG_SWAP, and in a seated duelist's field resync. FEATURE_TAG_PARTNER_CARDS 0x2000 advertised by single_duel and tag_duel; FEATURE_PROTOCOL 8 -> 9. 0x800 / 0x1000 stay reserved for proposals 44 / 45. Binding: StocMessage.TagPartnerCards, FeatureFlags.TagPartnerCards, the TagPartnerCards record + StocCodecs.TagPartnerCards, EngineApi.ygol_query_tag_cards, Capability.ProtocolVersion 9, tests. Contract rows, CHANGELOG v1.2.0, the probe's tag partner cards room, the export gates 334 / 855 / 849 -> 335 / 856 / 850. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
c3b5e6e13b
commit
2344e5dae1
20 files changed
+444
-36
No files matched your search
@@ -40,9 +40,9 @@ namespace YGOLegacy.Engine.Tests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HeaderHas45Exports()
|
||||
public void HeaderHas46Exports()
|
||||
{
|
||||
Assert.That(HeaderNames().Count, Is.EqualTo(45));
|
||||
Assert.That(HeaderNames().Count, Is.EqualTo(46));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -158,7 +158,7 @@ namespace YGOLegacy.Protocol.Tests
|
||||
Assert.That((int)StocCodecs.SeatResumeResult.Id, Is.EqualTo(0x57));
|
||||
Assert.That((int)StocCodecs.RestartOpened.Id, Is.EqualTo(0x58));
|
||||
Assert.That(FeatureFlags.RulesRestart, Is.EqualTo(0x10));
|
||||
Assert.That(FeatureFlags.All, Is.EqualTo(0x7FB));
|
||||
Assert.That(FeatureFlags.All, Is.EqualTo(0x27FB));
|
||||
|
||||
var id = Enumerable.Repeat((byte)0xAB, 16).ToArray();
|
||||
var token = Enumerable.Range(1, 16).Select(i => (byte)i).ToArray();
|
||||
@@ -207,13 +207,12 @@ namespace YGOLegacy.Protocol.Tests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Profile_Id_Flag_Protocol_AndSizes_ArePinned_0x5D_0x200_7_98_100()
|
||||
public void Profile_Id_Flag_AndSizes_ArePinned_0x5D_0x200_98_100()
|
||||
{
|
||||
Assert.That((int)LobbyCodecs.Profile.Id, Is.EqualTo(0x5D));
|
||||
Assert.That((int)StocCodecs.Profile.Id, Is.EqualTo(0x5D));
|
||||
Assert.That(FeatureFlags.Profile, Is.EqualTo(0x200));
|
||||
Assert.That(FeatureFlags.All & FeatureFlags.Profile, Is.EqualTo(FeatureFlags.Profile));
|
||||
Assert.That(Capability.ProtocolVersion, Is.EqualTo(8));
|
||||
Assert.That(ProfileCodec.Size, Is.EqualTo(98));
|
||||
Assert.That(ProfileCodec.StampedSize, Is.EqualTo(100));
|
||||
var sent = Bytes(w => LobbyCodecs.Profile.Write(w, new ProfileState("atem", "gold")));
|
||||
@@ -239,13 +238,12 @@ namespace YGOLegacy.Protocol.Tests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AttackPreview_Id_Flag_Protocol_AndSizes_ArePinned_0x5E_0x400_8_4_28()
|
||||
public void AttackPreview_Id_Flag_AndSizes_ArePinned_0x5E_0x400_4_28()
|
||||
{
|
||||
Assert.That((int)LobbyCodecs.AttackPreview.Id, Is.EqualTo(0x5E));
|
||||
Assert.That((int)StocCodecs.AttackPreview.Id, Is.EqualTo(0x5E));
|
||||
Assert.That(FeatureFlags.AttackPreview, Is.EqualTo(0x400));
|
||||
Assert.That(FeatureFlags.All & FeatureFlags.AttackPreview, Is.EqualTo(FeatureFlags.AttackPreview));
|
||||
Assert.That(Capability.ProtocolVersion, Is.EqualTo(8));
|
||||
Assert.That(AttackPreviewPair.Size, Is.EqualTo(4));
|
||||
Assert.That(AttackPreviewEntry.Size, Is.EqualTo(28));
|
||||
|
||||
@@ -274,6 +272,44 @@ namespace YGOLegacy.Protocol.Tests
|
||||
Assert.Throws<EndOfStreamException>(() => StocCodecs.AttackPreview.Read(Reader(new byte[] { 1 })));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TagPartnerCards_Id_Flag_Protocol_AndRoundTrip_ArePinned_0x5F_0x2000_9()
|
||||
{
|
||||
Assert.That((int)StocCodecs.TagPartnerCards.Id, Is.EqualTo(0x5F));
|
||||
Assert.That(FeatureFlags.TagPartnerCards, Is.EqualTo(0x2000));
|
||||
Assert.That(FeatureFlags.All & FeatureFlags.TagPartnerCards, Is.EqualTo(FeatureFlags.TagPartnerCards));
|
||||
Assert.That(Capability.ProtocolVersion, Is.EqualTo(9));
|
||||
Assert.That(TagPartnerCardsCodec.HeaderSize, Is.EqualTo(7));
|
||||
|
||||
var faceUpPendulum = 0x80000000u | 16178681u;
|
||||
var payload = new TagPartnerCards(1, new uint[] { 89631139u, 46986414u }, new uint[] { faceUpPendulum, 44508094u }, new[] { 10, 20, 30 });
|
||||
var bytes = Bytes(w => StocCodecs.TagPartnerCards.Write(w, payload));
|
||||
Assert.That(bytes.Length, Is.EqualTo(7 + 4 * 7));
|
||||
Assert.That(bytes.Take(7).ToArray(), Is.EqualTo(new byte[] { 1, 1, 2, 2, 0, 3, 0 }));
|
||||
Assert.That(BitConverter.ToUInt32(bytes, 7), Is.EqualTo(89631139u));
|
||||
Assert.That(BitConverter.ToUInt32(bytes, 15), Is.EqualTo(faceUpPendulum));
|
||||
Assert.That(BitConverter.ToUInt32(bytes, 23), Is.EqualTo(10u));
|
||||
|
||||
var read = StocCodecs.TagPartnerCards.Read(Reader(bytes));
|
||||
Assert.That(read.Version, Is.EqualTo(1));
|
||||
Assert.That(read.Side, Is.EqualTo(1));
|
||||
Assert.That(read.Hand, Is.EqualTo(payload.Hand));
|
||||
Assert.That(read.Extra, Is.EqualTo(payload.Extra));
|
||||
Assert.That(read.Deck, Is.EqualTo(payload.Deck));
|
||||
Assert.That(TagPartnerCards.IsFaceUp(read.Extra[0]), Is.True);
|
||||
Assert.That(TagPartnerCards.CodeOf(read.Extra[0]), Is.EqualTo(16178681));
|
||||
Assert.That(TagPartnerCards.IsFaceUp(read.Extra[1]), Is.False);
|
||||
|
||||
var empty = StocCodecs.TagPartnerCards.Read(Reader(new byte[] { 0, 1, 0, 0, 0, 0, 0 }));
|
||||
Assert.That(empty.Side, Is.EqualTo(0));
|
||||
Assert.That(empty.Hand, Is.Empty);
|
||||
Assert.That(empty.Extra, Is.Empty);
|
||||
Assert.That(empty.Deck, Is.Empty);
|
||||
Assert.Throws<EndOfStreamException>(() => StocCodecs.TagPartnerCards.Read(Reader(bytes.Take(bytes.Length - 1).ToArray())));
|
||||
Assert.Throws<EndOfStreamException>(() => StocCodecs.TagPartnerCards.Read(Reader(new byte[] { 0, 1, 0 })));
|
||||
Assert.Throws<InvalidDataException>(() => StocCodecs.TagPartnerCards.Read(Reader(new byte[] { 0, 1, 0, 0, 0, 0xFB, 0 })));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SeatState_Id_Flag_AndSizes_ArePinned_0x59_0x20_4_6()
|
||||
{
|
||||
@@ -386,7 +422,7 @@ namespace YGOLegacy.Protocol.Tests
|
||||
{
|
||||
var bytes = Bytes(w => LobbyCodecs.Capability.Write(w, new Capability(Capability.ProtocolVersion, FeatureFlags.All)));
|
||||
|
||||
Assert.That(bytes, Is.EqualTo(Concat(Le16(8), Le32(0x7FB))));
|
||||
Assert.That(bytes, Is.EqualTo(Concat(Le16(9), Le32(0x27FB))));
|
||||
|
||||
var read = LobbyCodecs.Capability.Read(Reader(bytes));
|
||||
Assert.That(read.Protocol, Is.EqualTo(Capability.ProtocolVersion));
|
||||
|
||||
@@ -283,7 +283,7 @@ namespace YGOLegacy.Protocol.Tests
|
||||
AssertCatalogParity(typeof(StocMessage),
|
||||
new[] { typeof(YGOSharp.Network.Enums.StocMessage) },
|
||||
new[] { "DeckCount", "FieldFinish", "SrvproRoomList", "Capability", "Appearance", "Dialogue", "SetupPairs", "SeatPlan",
|
||||
"RoomRestarting", "RestartStatus", "SeatResumeResult", "RestartOpen", "SeatState", "MatchOver", "CoinToss", "DeckList", "Profile", "AttackPreview" });
|
||||
"RoomRestarting", "RestartStatus", "SeatResumeResult", "RestartOpen", "SeatState", "MatchOver", "CoinToss", "DeckList", "Profile", "AttackPreview", "TagPartnerCards" });
|
||||
}
|
||||
|
||||
private static void AssertCatalogParity(Type catalog, Type[] legacyEnums, string[] expectedExtras)
|
||||
|
||||
@@ -88,6 +88,9 @@ namespace YGOLegacy.Engine
|
||||
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int ygol_preview_attack(IntPtr pduel, byte playerid, byte location, byte sequence, byte target_location, byte target_sequence, byte[] @out);
|
||||
|
||||
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int ygol_query_tag_cards(IntPtr pduel, byte playerid, byte[] @out);
|
||||
|
||||
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int get_registry_value(IntPtr pduel, [MarshalAs(UnmanagedType.LPUTF8Str)] string key, byte[] out_buf);
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ namespace YGOLegacy.Protocol.Codecs
|
||||
public static readonly DeckListCodec DeckList = new DeckListCodec();
|
||||
public static readonly StampedCodec<ProfileState> Profile = new StampedCodec<ProfileState>(StocMessage.Profile, LobbyCodecs.Profile, ProfileCodec.Size);
|
||||
public static readonly AttackPreviewResultCodec AttackPreview = new AttackPreviewResultCodec();
|
||||
public static readonly TagPartnerCardsCodec TagPartnerCards = new TagPartnerCardsCodec();
|
||||
|
||||
internal static long Remaining(BinaryReader reader)
|
||||
{
|
||||
@@ -164,6 +165,54 @@ namespace YGOLegacy.Protocol.Codecs
|
||||
}
|
||||
}
|
||||
|
||||
// Side, version, hand count, extra count, pad, uint16 deck count, then the hand, extra and deck codes as uint32; no sender stamp (v1.2.0, TICKET-405).
|
||||
public sealed class TagPartnerCardsCodec : IStocCodec<TagPartnerCards>
|
||||
{
|
||||
public const int HeaderSize = 7;
|
||||
|
||||
public StocMessage Id => StocMessage.TagPartnerCards;
|
||||
|
||||
public TagPartnerCards Read(BinaryReader reader)
|
||||
{
|
||||
StocCodecs.Require(reader, HeaderSize, Id);
|
||||
var side = reader.ReadByte();
|
||||
var version = reader.ReadByte();
|
||||
int handCount = reader.ReadByte();
|
||||
int extraCount = reader.ReadByte();
|
||||
reader.ReadByte();
|
||||
int deckCount = reader.ReadUInt16();
|
||||
if (deckCount > TagPartnerCards.MaxDeckCards)
|
||||
throw new InvalidDataException("STOC " + Id + ": " + deckCount + " deck cards, at most " + TagPartnerCards.MaxDeckCards);
|
||||
StocCodecs.Require(reader, (handCount + extraCount + deckCount) * 4, Id);
|
||||
var hand = new uint[handCount];
|
||||
for (var i = 0; i < handCount; i++)
|
||||
hand[i] = reader.ReadUInt32();
|
||||
var extra = new uint[extraCount];
|
||||
for (var i = 0; i < extraCount; i++)
|
||||
extra[i] = reader.ReadUInt32();
|
||||
var deck = new int[deckCount];
|
||||
for (var i = 0; i < deckCount; i++)
|
||||
deck[i] = (int)reader.ReadUInt32();
|
||||
return new TagPartnerCards(version, side, hand, extra, deck);
|
||||
}
|
||||
|
||||
public void Write(BinaryWriter writer, TagPartnerCards payload)
|
||||
{
|
||||
writer.Write(payload.Side);
|
||||
writer.Write(payload.Version);
|
||||
writer.Write((byte)payload.Hand.Length);
|
||||
writer.Write((byte)payload.Extra.Length);
|
||||
writer.Write((byte)0);
|
||||
writer.Write((ushort)payload.Deck.Length);
|
||||
foreach (var raw in payload.Hand)
|
||||
writer.Write(raw);
|
||||
foreach (var raw in payload.Extra)
|
||||
writer.Write(raw);
|
||||
foreach (var code in payload.Deck)
|
||||
writer.Write((uint)code);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class HostInfoCodec : IStocCodec<HostInfo>
|
||||
{
|
||||
public StocMessage Id => StocMessage.JoinGame;
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace YGOLegacy.Protocol.Contracts
|
||||
{
|
||||
public const uint Appearance = 0x1;
|
||||
public const uint Dialogue = 0x2;
|
||||
public const uint All = Appearance | Dialogue | SeatPlan | RulesRestart | SeatState | LobbyAfterMatch | CoinToss | DeckList | Profile | AttackPreview;
|
||||
public const uint All = Appearance | Dialogue | SeatPlan | RulesRestart | SeatState | LobbyAfterMatch | CoinToss | DeckList | Profile | AttackPreview | TagPartnerCards;
|
||||
// Server-only: the host relays setup pairs (0x43); a client never advertises it.
|
||||
public const uint SetupPairs = 0x4;
|
||||
// Server: chosen seats (0x50-0x53). Client: it renders the seat plan.
|
||||
@@ -25,6 +25,8 @@ namespace YGOLegacy.Protocol.Contracts
|
||||
public const uint Profile = 0x200;
|
||||
// Server: attack preview (0x5E): the seat whose battle prompt is open asks for its pairs, the host's core answers. Client: it shows the badge.
|
||||
public const uint AttackPreview = 0x400;
|
||||
// Server: tag partner cards (0x5F): the waiting teammate's hand, Extra Deck and deck go to that side's two seats. Client: the partner view shows them. 0x800 and 0x1000 are reserved by proposals 44 and 45.
|
||||
public const uint TagPartnerCards = 0x2000;
|
||||
// Client role, not a feature: set only on the room host's own line, so every peer can badge the host's seat.
|
||||
public const uint RoomHost = 0x80000000;
|
||||
}
|
||||
@@ -54,7 +56,7 @@ namespace YGOLegacy.Protocol.Contracts
|
||||
|
||||
public readonly struct Capability
|
||||
{
|
||||
public const ushort ProtocolVersion = 8;
|
||||
public const ushort ProtocolVersion = 9;
|
||||
public const int ServerSender = 0xFF;
|
||||
|
||||
public ushort Protocol { get; }
|
||||
@@ -549,6 +551,37 @@ namespace YGOLegacy.Protocol.Contracts
|
||||
}
|
||||
}
|
||||
|
||||
// STOC 0x5F (v1.2.0, TICKET-405): the waiting tag partner's hand, Extra Deck and deck of one side; to that side's two seats only, no sender stamp.
|
||||
public readonly struct TagPartnerCards
|
||||
{
|
||||
public const byte CurrentVersion = 1;
|
||||
public const int MaxDeckCards = 250;
|
||||
public const uint FaceUpBit = 0x80000000;
|
||||
|
||||
public byte Version { get; }
|
||||
public byte Side { get; }
|
||||
// Raw codes: bit 31 set = face-up (a Pendulum in the Extra Deck), like MSG_TAG_SWAP.
|
||||
public uint[] Hand { get; }
|
||||
public uint[] Extra { get; }
|
||||
// Sorted ascending; the real order never leaves the engine.
|
||||
public int[] Deck { get; }
|
||||
|
||||
public TagPartnerCards(byte side, uint[] hand, uint[] extra, int[] deck) : this(CurrentVersion, side, hand, extra, deck) { }
|
||||
|
||||
public TagPartnerCards(byte version, byte side, uint[] hand, uint[] extra, int[] deck)
|
||||
{
|
||||
Version = version;
|
||||
Side = side;
|
||||
Hand = hand ?? Array.Empty<uint>();
|
||||
Extra = extra ?? Array.Empty<uint>();
|
||||
Deck = deck ?? Array.Empty<int>();
|
||||
}
|
||||
|
||||
public static int CodeOf(uint raw) => (int)(raw & ~FaceUpBit);
|
||||
|
||||
public static bool IsFaceUp(uint raw) => (raw & FaceUpBit) != 0;
|
||||
}
|
||||
|
||||
public static class SeatIds
|
||||
{
|
||||
public static bool IsZero(byte[] value)
|
||||
|
||||
@@ -78,6 +78,7 @@ namespace YGOLegacy.Protocol.Contracts
|
||||
CoinToss = 0x5B,
|
||||
DeckList = 0x5C,
|
||||
Profile = 0x5D,
|
||||
AttackPreview = 0x5E
|
||||
AttackPreview = 0x5E,
|
||||
TagPartnerCards = 0x5F
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user