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:
donnyandClaude Fable 5.1 committed 2026-10-15 23:26:39 -07:00
1 parent c3b5e6e13b
commit 2344e5dae1
20 files changed
+444 -36

No files matched your search

+3
View File
@@ -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
}
}