binding: PromptContext record + codec, FeatureFlags.PromptContext, protocol 12 (TICKET-451, v1.7.0)
StocMessage.PromptContext 0x44, PromptContextCodec (23 bytes), EngineApi.ygol_query_prompt_context, Capability.ProtocolVersion 12, tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
50706080c2
commit
458c9df105
7 files changed
+156
-9
No files matched your search
@@ -40,9 +40,9 @@ namespace YGOLegacy.Engine.Tests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HeaderHas46Exports()
|
||||
public void HeaderHas47Exports()
|
||||
{
|
||||
Assert.That(HeaderNames().Count, Is.EqualTo(46));
|
||||
Assert.That(HeaderNames().Count, Is.EqualTo(47));
|
||||
}
|
||||
|
||||
[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(0x77FB));
|
||||
Assert.That(FeatureFlags.All, Is.EqualTo(0xF7FB));
|
||||
|
||||
var id = Enumerable.Repeat((byte)0xAB, 16).ToArray();
|
||||
var token = Enumerable.Range(1, 16).Select(i => (byte)i).ToArray();
|
||||
@@ -280,11 +280,56 @@ namespace YGOLegacy.Protocol.Tests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TagSharedExtra_Flag_AndProtocol_ArePinned_0x4000_11()
|
||||
public void TagSharedExtra_Flag_IsPinned_0x4000()
|
||||
{
|
||||
Assert.That(FeatureFlags.TagSharedExtra, Is.EqualTo(0x4000));
|
||||
Assert.That(FeatureFlags.All & FeatureFlags.TagSharedExtra, Is.EqualTo(FeatureFlags.TagSharedExtra));
|
||||
Assert.That(Capability.ProtocolVersion, Is.EqualTo(11));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PromptContext_Id_Flag_Protocol_AndRoundTrip_ArePinned_0x44_0x8000_12_23()
|
||||
{
|
||||
Assert.That((int)StocCodecs.PromptContext.Id, Is.EqualTo(0x44));
|
||||
Assert.That((int)StocMessage.PromptContext, Is.EqualTo(0x44));
|
||||
Assert.That(FeatureFlags.PromptContext, Is.EqualTo(0x8000));
|
||||
Assert.That(FeatureFlags.All & FeatureFlags.PromptContext, Is.EqualTo(FeatureFlags.PromptContext));
|
||||
Assert.That(Capability.ProtocolVersion, Is.EqualTo(12));
|
||||
Assert.That(PromptContextCodec.Size, Is.EqualTo(23));
|
||||
|
||||
const ulong description = 12960005233ul;
|
||||
var payload = new PromptContext(true, 16178681u, 1, 0x04, 2, 0x1, description, 3, PromptContext.PhaseOperation, 2, 13);
|
||||
var bytes = Bytes(w => StocCodecs.PromptContext.Write(w, payload));
|
||||
Assert.That(bytes.Length, Is.EqualTo(23));
|
||||
Assert.That(bytes[0], Is.EqualTo(1));
|
||||
Assert.That(bytes[1], Is.EqualTo(1));
|
||||
Assert.That(BitConverter.ToUInt32(bytes, 2), Is.EqualTo(16178681u));
|
||||
Assert.That(bytes.Skip(6).Take(4).ToArray(), Is.EqualTo(new byte[] { 1, 0x04, 2, 0x1 }));
|
||||
Assert.That(BitConverter.ToUInt64(bytes, 10), Is.EqualTo(description));
|
||||
Assert.That(BitConverter.ToUInt16(bytes, 18), Is.EqualTo(3));
|
||||
Assert.That(bytes.Skip(20).ToArray(), Is.EqualTo(new byte[] { 3, 2, 13 }));
|
||||
|
||||
var read = StocCodecs.PromptContext.Read(Reader(bytes));
|
||||
Assert.That(read.Version, Is.EqualTo(1));
|
||||
Assert.That(read.HasEffect, Is.True);
|
||||
Assert.That(read.IsHidden, Is.False);
|
||||
Assert.That(read.Code, Is.EqualTo(16178681u));
|
||||
Assert.That(read.Controller, Is.EqualTo(1));
|
||||
Assert.That(read.Location, Is.EqualTo(0x04));
|
||||
Assert.That(read.Sequence, Is.EqualTo(2));
|
||||
Assert.That(read.Position, Is.EqualTo(0x1));
|
||||
Assert.That(read.Description, Is.EqualTo(description));
|
||||
Assert.That(read.EffectIndex, Is.EqualTo(3));
|
||||
Assert.That(read.Phase, Is.EqualTo(PromptContext.PhaseOperation));
|
||||
Assert.That(read.ChainLink, Is.EqualTo(2));
|
||||
Assert.That(read.Prompt, Is.EqualTo(13));
|
||||
|
||||
var none = Bytes(w => StocCodecs.PromptContext.Write(w, PromptContext.None(10)));
|
||||
Assert.That(none, Is.EqualTo(new byte[] { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0, 0, 10 }));
|
||||
Assert.That(StocCodecs.PromptContext.Read(Reader(none)).HasEffect, Is.False);
|
||||
var hidden = StocCodecs.PromptContext.Read(Reader(Bytes(w => StocCodecs.PromptContext.Write(w, new PromptContext(true, 0, 1, 0x02, 0, 0x8, 0, PromptContext.UnknownIndex, PromptContext.PhaseCost, 1, 13)))));
|
||||
Assert.That(hidden.IsHidden, Is.True);
|
||||
Assert.That(hidden.EffectIndex, Is.EqualTo(PromptContext.UnknownIndex));
|
||||
Assert.Throws<EndOfStreamException>(() => StocCodecs.PromptContext.Read(Reader(bytes.Take(22).ToArray())));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -436,7 +481,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(11), Le32(0x77FB))));
|
||||
Assert.That(bytes, Is.EqualTo(Concat(Le16(12), Le32(0xF7FB))));
|
||||
|
||||
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", "TagPartnerCards" });
|
||||
"RoomRestarting", "RestartStatus", "SeatResumeResult", "RestartOpen", "SeatState", "MatchOver", "CoinToss", "DeckList", "Profile", "AttackPreview", "TagPartnerCards", "PromptContext" });
|
||||
}
|
||||
|
||||
private static void AssertCatalogParity(Type catalog, Type[] legacyEnums, string[] expectedExtras)
|
||||
|
||||
@@ -91,6 +91,9 @@ namespace YGOLegacy.Engine
|
||||
[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 ygol_query_prompt_context(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);
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ namespace YGOLegacy.Protocol.Codecs
|
||||
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();
|
||||
public static readonly PromptContextCodec PromptContext = new PromptContextCodec();
|
||||
|
||||
internal static long Remaining(BinaryReader reader)
|
||||
{
|
||||
@@ -213,6 +214,48 @@ namespace YGOLegacy.Protocol.Codecs
|
||||
}
|
||||
}
|
||||
|
||||
// The 22-byte ygol_query_prompt_context record (version, has effect, uint32 code, controller, location, sequence, position, uint64 description, uint16 effect index, phase, chain link) + the prompt's MSG id; no sender stamp (v1.7.0, TICKET-451).
|
||||
public sealed class PromptContextCodec : IStocCodec<PromptContext>
|
||||
{
|
||||
public const int Size = 23;
|
||||
|
||||
public StocMessage Id => StocMessage.PromptContext;
|
||||
|
||||
public PromptContext Read(BinaryReader reader)
|
||||
{
|
||||
StocCodecs.Require(reader, Size, Id);
|
||||
var version = reader.ReadByte();
|
||||
var hasEffect = reader.ReadByte() != 0;
|
||||
var code = reader.ReadUInt32();
|
||||
var controller = reader.ReadByte();
|
||||
var location = reader.ReadByte();
|
||||
var sequence = reader.ReadByte();
|
||||
var position = reader.ReadByte();
|
||||
var description = reader.ReadUInt64();
|
||||
var effectIndex = reader.ReadUInt16();
|
||||
var phase = reader.ReadByte();
|
||||
var chainLink = reader.ReadByte();
|
||||
var prompt = reader.ReadByte();
|
||||
return new PromptContext(version, hasEffect, code, controller, location, sequence, position, description, effectIndex, phase, chainLink, prompt);
|
||||
}
|
||||
|
||||
public void Write(BinaryWriter writer, PromptContext payload)
|
||||
{
|
||||
writer.Write(payload.Version);
|
||||
writer.Write((byte)(payload.HasEffect ? 1 : 0));
|
||||
writer.Write(payload.Code);
|
||||
writer.Write(payload.Controller);
|
||||
writer.Write(payload.Location);
|
||||
writer.Write(payload.Sequence);
|
||||
writer.Write(payload.Position);
|
||||
writer.Write(payload.Description);
|
||||
writer.Write(payload.EffectIndex);
|
||||
writer.Write(payload.Phase);
|
||||
writer.Write(payload.ChainLink);
|
||||
writer.Write(payload.Prompt);
|
||||
}
|
||||
}
|
||||
|
||||
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 | TagTwoFields | TagPartnerCards | TagSharedExtra;
|
||||
public const uint All = Appearance | Dialogue | SeatPlan | RulesRestart | SeatState | LobbyAfterMatch | CoinToss | DeckList | Profile | AttackPreview | TagTwoFields | TagPartnerCards | TagSharedExtra | PromptContext;
|
||||
// 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.
|
||||
@@ -31,6 +31,8 @@ namespace YGOLegacy.Protocol.Contracts
|
||||
public const uint TagPartnerCards = 0x2000;
|
||||
// Server: with the setup pair ygol.tag.extra=shared a Tag team has one Extra Deck and its Extra Deck refreshes carry the partner each card came from; a Tag room refuses a joiner without the bit. Client: it reads the value and refuses a host without the bit.
|
||||
public const uint TagSharedExtra = 0x4000;
|
||||
// Server: right before every relayed prompt but rock-paper-scissors, the answering seat gets which card and which effect asks (0x44); never observers, never a replay. Client: it keeps the context on the open prompt.
|
||||
public const uint PromptContext = 0x8000;
|
||||
// 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;
|
||||
}
|
||||
@@ -60,7 +62,7 @@ namespace YGOLegacy.Protocol.Contracts
|
||||
|
||||
public readonly struct Capability
|
||||
{
|
||||
public const ushort ProtocolVersion = 11;
|
||||
public const ushort ProtocolVersion = 12;
|
||||
public const int ServerSender = 0xFF;
|
||||
|
||||
public ushort Protocol { get; }
|
||||
@@ -586,6 +588,59 @@ namespace YGOLegacy.Protocol.Contracts
|
||||
public static bool IsFaceUp(uint raw) => (raw & FaceUpBit) != 0;
|
||||
}
|
||||
|
||||
// STOC 0x44 (v1.7.0, TICKET-451): which card and which effect asks the prompt that follows; to the answering seat only, no sender stamp.
|
||||
public readonly struct PromptContext
|
||||
{
|
||||
public const byte CurrentVersion = 1;
|
||||
public const ushort UnknownIndex = 0xFFFF;
|
||||
public const byte PhaseOther = 0;
|
||||
public const byte PhaseCost = 1;
|
||||
public const byte PhaseTarget = 2;
|
||||
public const byte PhaseOperation = 3;
|
||||
|
||||
public byte Version { get; }
|
||||
// False: no effect function runs (battle and idle commands, a plain summon); every other value is zero and EffectIndex is UnknownIndex.
|
||||
public bool HasEffect { get; }
|
||||
// The handler's current code; 0 when the answering player cannot see the card (EffectIndex and Description are then unknown too).
|
||||
public uint Code { get; }
|
||||
public byte Controller { get; }
|
||||
public byte Location { get; }
|
||||
public byte Sequence { get; }
|
||||
public byte Position { get; }
|
||||
// The effect's description (the aux.Stringid value), 0 when it has none.
|
||||
public ulong Description { get; }
|
||||
// The order the card's script registered the effect (the same in every duel); UnknownIndex for an effect the script did not register at load.
|
||||
public ushort EffectIndex { get; }
|
||||
public byte Phase { get; }
|
||||
// The chain link the effect is, 0 when it is not on the chain.
|
||||
public byte ChainLink { get; }
|
||||
// The MSG_* id of the prompt this context belongs to.
|
||||
public byte Prompt { get; }
|
||||
|
||||
public PromptContext(bool hasEffect, uint code, byte controller, byte location, byte sequence, byte position, ulong description, ushort effectIndex, byte phase, byte chainLink, byte prompt)
|
||||
: this(CurrentVersion, hasEffect, code, controller, location, sequence, position, description, effectIndex, phase, chainLink, prompt) { }
|
||||
|
||||
public PromptContext(byte version, bool hasEffect, uint code, byte controller, byte location, byte sequence, byte position, ulong description, ushort effectIndex, byte phase, byte chainLink, byte prompt)
|
||||
{
|
||||
Version = version;
|
||||
HasEffect = hasEffect;
|
||||
Code = code;
|
||||
Controller = controller;
|
||||
Location = location;
|
||||
Sequence = sequence;
|
||||
Position = position;
|
||||
Description = description;
|
||||
EffectIndex = effectIndex;
|
||||
Phase = phase;
|
||||
ChainLink = chainLink;
|
||||
Prompt = prompt;
|
||||
}
|
||||
|
||||
public static PromptContext None(byte prompt) => new PromptContext(false, 0, 0, 0, 0, 0, 0, UnknownIndex, PhaseOther, 0, prompt);
|
||||
|
||||
public bool IsHidden => HasEffect && Code == 0;
|
||||
}
|
||||
|
||||
public static class SeatIds
|
||||
{
|
||||
public static bool IsZero(byte[] value)
|
||||
|
||||
@@ -68,6 +68,7 @@ namespace YGOLegacy.Protocol.Contracts
|
||||
Appearance = 0x41,
|
||||
Dialogue = 0x42,
|
||||
SetupPairs = 0x43,
|
||||
PromptContext = 0x44,
|
||||
SeatPlan = 0x50,
|
||||
RoomRestarting = 0x54,
|
||||
RestartStatus = 0x56,
|
||||
|
||||
Reference in new issue
Block a user