Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5286cb2bfd | ||
|
|
65fcc307bb | ||
|
|
14a4f80aab | ||
|
|
f52eca74ce | ||
|
|
2789a82ef4 | ||
|
|
2344e5dae1 | ||
|
|
c3b5e6e13b |
No files matched your search
@@ -57,7 +57,7 @@ jobs:
|
||||
git clean -fdx -e out
|
||||
if ($LASTEXITCODE -ne 0) { exit 1 }
|
||||
|
||||
- name: Build (contract check, export gate 334, engine.json)
|
||||
- name: Build (contract check, export gate 335, engine.json)
|
||||
id: build
|
||||
run: |
|
||||
$version = "local"
|
||||
@@ -104,7 +104,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Build (contract check, export gate 855, engine.json)
|
||||
- name: Build (contract check, export gate 856, engine.json)
|
||||
run: |
|
||||
version=local
|
||||
case "$GITHUB_REF" in refs/tags/v*) version="$GITHUB_REF_NAME";; esac
|
||||
@@ -126,7 +126,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Build (contract check, export gate 849, engine.json)
|
||||
- name: Build (contract check, export gate 850, engine.json)
|
||||
run: |
|
||||
version=local
|
||||
case "$GITHUB_REF" in refs/tags/v*) version="$GITHUB_REF_NAME";; esac
|
||||
|
||||
@@ -5,6 +5,53 @@ wire protocol, the engine message stream, the setup pairs and the Lua API. A row
|
||||
change first shipped in the Unity repo, the ticket, and the contract part it touched. Rows 0001-0024
|
||||
are the fork patches replayed into this repo as commits (`git log --oneline -- server/gframe core`).
|
||||
|
||||
## v1.4.1 — 2026-10-16
|
||||
|
||||
Tag: a card the waiting partner holds can be moved. No new export or capability bit: exports 335 / 856 /
|
||||
850, protocol 9, capabilities `0x27FF`.
|
||||
|
||||
| Date | Change | Ticket | Contract part |
|
||||
|---|---|---|---|
|
||||
| 2026-10-16 | Fix in the core's tag lists (upstream code, reached through core patch 0015's swap order): an effect that keeps a card across the tag swap and moves it later (Time Fusion: the Fusion picked from the Extra Deck at activation, Summoned at the team's next Standby Phase, when the partner's Extra Deck is the active one) moved a card of `tag_list_main` / `tag_list_hand` / `tag_list_extra`; `remove_card` erased the ACTIVE list at the card's sequence, past the end of a shorter list (an empty Extra Deck: `memcpy` crash in `field::remove_card`) or the wrong card. Such a card now leaves the list that holds it (`field::tag_list_holding`) and goes where the move says; the next `MSG_TAG_SWAP` lists one card fewer. Core. | TICKET-415 | Engine message stream: `MSG_TAG_SWAP` (rules only) |
|
||||
|
||||
## v1.4.0 — 2026-10-16
|
||||
|
||||
Life points per side: the setup pair `ygol.side.b.lp=<n>` gives seat side B its own start LP. No new
|
||||
export or capability bit: exports 335 / 856 / 850, protocol 9, capabilities `0x27FF`.
|
||||
|
||||
| Date | Change | Ticket | Contract part |
|
||||
|---|---|---|---|
|
||||
| 2026-10-16 | `ygol.side.b.lp=<n>`: seat side B (seat 1; Tag seats 2 and 3) starts at `n` LP, side A at slot 8; `set_player_info` per duel player, `MSG_START` (start and late-watcher snapshot) carries `lp[0]`, `lp[1]` in duel player order through the first-turn swap, and the replay gets flag `0x20000000` + `i32 lp[0]`, `i32 lp[1]` after `opt` when the two differ. Single, Match, Tag. Server. | - | Setup pair `ygol.side.b.lp`; engine message stream `MSG_START`; replay flag `0x20000000` |
|
||||
|
||||
## v1.3.0 — 2026-10-16
|
||||
|
||||
Spectators with Show all get the Tag partner cards of both teams. Same message, same payload, no new
|
||||
export or capability bit: exports 335 / 856 / 850, protocol 9, capabilities `0x27FF`.
|
||||
|
||||
| Date | Change | Ticket | Contract part |
|
||||
|---|---|---|---|
|
||||
| 2026-10-16 | `STOC_TAG_PARTNER_CARDS` `0x5F` also goes to every observer, both sides, when spectators see all (no `ygol.room.spectatorview=hidden`): after `start_duel`, after every `MSG_TAG_SWAP`, and both sides in an observer's field resync and the late-watcher snapshot. Hidden rooms and seated duelists unchanged. Server. | TICKET-412 | Wire: STOC `0x5F` recipients; join snapshot |
|
||||
|
||||
## v1.2.0 — 2026-10-15
|
||||
|
||||
Tag partner cards: the waiting teammate's hand, Extra Deck and deck reach that team's two seats. One new
|
||||
export (Windows 335, Linux 856, Android 850), one new message, capability `0x2000`, protocol 9 (capabilities
|
||||
`0x27FF`).
|
||||
|
||||
| Date | Change | Ticket | Contract part |
|
||||
|---|---|---|---|
|
||||
| 2026-10-15 | `ygol_query_tag_cards(pduel, playerid, out)`: the waiting tag partner's hand, Extra Deck (bit 31 = face-up) and deck codes (sorted) of one side, read only; returns the byte length, 0 when not a tag duel. Core. | TICKET-405 | C API: 1 export |
|
||||
| 2026-10-15 | `STOC_TAG_PARTNER_CARDS` `0x5F` = `u8 side` + the export's 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` (`0x800` and `0x1000` stay reserved for proposals 44 and 45), protocol 8 -> 9. Server. | TICKET-405 | Wire: STOC `0x5F`, capability bit `0x2000`, protocol 9 |
|
||||
| 2026-10-15 | Binding: `StocMessage.TagPartnerCards`, `FeatureFlags.TagPartnerCards`, the `TagPartnerCards` record + `StocCodecs.TagPartnerCards`, `EngineApi.ygol_query_tag_cards`, `Capability.ProtocolVersion` 9. | TICKET-405 | (e) C# binding |
|
||||
|
||||
## v1.1.1 — 2026-10-15
|
||||
|
||||
A rules fix in the core only. No contract change: same exports, protocol 8, capabilities `0x7FF`.
|
||||
|
||||
| Date | Change | Ticket | Contract part |
|
||||
|---|---|---|---|
|
||||
| 2026-10-15 | Tag duel opening turns: no Battle Phase on turns 1, 2 and 3 (duelists 1A, 2A, 1B); the fourth duelist (2B) is the first who can battle, as the official Tag Duel rules say. Single duels keep turn 1 only. `DUEL_ATTACK_FIRST_TURN` still lifts the block. Core (`field::is_opening_turn_without_bp`, used by the idle command and `Duel.IsAbleToEnterBP`). | - | Rules only; no contract change |
|
||||
|
||||
## v1.1.0 — 2026-10-15
|
||||
|
||||
The C# binding joins the release: `ygol-engine-binding.zip` (`YGOLegacy.Engine.dll` + `.pdb`) beside
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace YGOLegacy.Protocol.Contracts
|
||||
{
|
||||
// Fork replay header flags (contract section (b), Replay). The stock flags stay 0x1 (compressed) and 0x2 (tag).
|
||||
public static class ReplayFlags
|
||||
{
|
||||
// Patch 0009: u32 length + the setup pairs block before the player names.
|
||||
public const int SetupPairs = 0x40000000;
|
||||
// v1.4.0, life points per side: i32 lp[0] + i32 lp[1] (duel player order) after opt.
|
||||
public const int SideLp = 0x20000000;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -125,7 +125,7 @@ RUN SERVER_ZIP_SUPPORT=1 SERVER_TAG_SURRENDER_CONFIRM=1 premake5 gmake \
|
||||
&& make -C build config=release -j"$(nproc)" ygopro \
|
||||
&& cp bin/release/ygopro /out/ygoserver
|
||||
RUN file /out/libygol-engine.so /out/ygoserver \
|
||||
&& export-gate nm /out/libygol-engine.so 855 "$VERSION" /out
|
||||
&& export-gate nm /out/libygol-engine.so 856 "$VERSION" /out
|
||||
|
||||
FROM scratch AS linux
|
||||
COPY --from=linux-build /out/ /
|
||||
@@ -140,7 +140,7 @@ RUN YGOL_ENGINE_VERSION=$VERSION premake5 gmake \
|
||||
&& make -C build config=release_android_arm64 -j"$(nproc)" ygoserver \
|
||||
&& mkdir -p /out && cp bin/android_arm64/release/libygol-engine.so /out/
|
||||
RUN file /out/libygol-engine.so \
|
||||
&& export-gate "$NDK_DIR"/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-nm /out/libygol-engine.so 849 "$VERSION" /out
|
||||
&& export-gate "$NDK_DIR"/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-nm /out/libygol-engine.so 850 "$VERSION" /out
|
||||
|
||||
FROM scratch AS android
|
||||
COPY --from=android-build /out/ /
|
||||
+2
-2
@@ -21,7 +21,7 @@
|
||||
binding is the version of the C# binding released with this engine (the same tag).
|
||||
|
||||
Output: out\win64\ygol-engine.dll (+ .pdb). The export gate is the truth:
|
||||
the script FAILS unless the DLL exports exactly 334 symbols (start_server,
|
||||
the script FAILS unless the DLL exports exactly 335 symbols (start_server,
|
||||
stop_server, ygol_engine_version, and the core C API re-exported, ygol_sb_*
|
||||
and ygol_preview_attack included). The Unity repo's old ygoserver.dll had 327:
|
||||
its own core copy never carried patch 0008's six ygol_sb_* exports.
|
||||
@@ -30,7 +30,7 @@
|
||||
param(
|
||||
[string]$Premake = "C:\premake\premake5.exe",
|
||||
[string]$Version = "local",
|
||||
[int]$ExpectedExports = 334
|
||||
[int]$ExpectedExports = 335
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
+31
-15
@@ -25,9 +25,9 @@ next to the library (`out/win64/engine.json` on Windows):
|
||||
```json
|
||||
{
|
||||
"version": "v0.0.1",
|
||||
"exports": 334,
|
||||
"protocol": 8,
|
||||
"capabilities": 2047,
|
||||
"exports": 335,
|
||||
"protocol": 9,
|
||||
"capabilities": 10239,
|
||||
"binding": "v0.0.1"
|
||||
}
|
||||
```
|
||||
@@ -35,9 +35,9 @@ next to the library (`out/win64/engine.json` on Windows):
|
||||
| Key | Type | Source |
|
||||
|---|---|---|
|
||||
| `version` | string | The `-Version` the build was given; `local` when none. The same string `ygol_engine_version()` returns. |
|
||||
| `exports` | integer | The library's export count after the gate passed (Windows: 334). |
|
||||
| `protocol` | integer | `FEATURE_PROTOCOL` in `server/gframe/network.h` (8 as of 2026-10-13). |
|
||||
| `capabilities` | integer | The OR of every `FEATURE_*` bit `SendServerCapability` advertises (`single_duel.cpp` and `tag_duel.cpp` must agree), as a decimal integer. 2047 = `0x7FF` = bits `0x1` to `0x400`. |
|
||||
| `exports` | integer | The library's export count after the gate passed (Windows: 335). |
|
||||
| `protocol` | integer | `FEATURE_PROTOCOL` in `server/gframe/network.h` (9 as of 2026-10-15). |
|
||||
| `capabilities` | integer | The OR of every `FEATURE_*` bit `SendServerCapability` advertises (`single_duel.cpp` and `tag_duel.cpp` must agree), as a decimal integer. 10239 = `0x27FF` = bits `0x1` to `0x400` plus `0x2000` (`0x800` and `0x1000` are reserved by proposals 44 and 45). |
|
||||
| `binding` | string | The version of the C# binding released with this engine (section (e)); the same string as `version`. |
|
||||
|
||||
The build reads `protocol` and `capabilities` from the source every time; nothing types them in.
|
||||
@@ -52,7 +52,7 @@ the caller's.
|
||||
The library also exports 289 `sqlite3_*` symbols because the server links SQLite with
|
||||
`SQLITE_API=__declspec(dllexport)`. They are NOT part of this contract: nothing of ours calls them
|
||||
through the library, and they are counted by the export gate only so that the number stays exact
|
||||
(Windows: 44 contract exports + 289 SQLite + 1 = 334; the extra 1 is `ygol_engine_version`, see below).
|
||||
(Windows: 45 contract exports + 289 SQLite + 1 = 335; the extra 1 is `ygol_engine_version`, see below).
|
||||
|
||||
### Server exports (`server/gframe/serverapi.h`)
|
||||
|
||||
@@ -73,7 +73,7 @@ The host string is space-separated tokens, in this order (`server/gframe/gframe.
|
||||
| 5 | duel rule: `T` (previous master rule), `F` (default), or a numeric `duel_flags` |
|
||||
| 6 | `T` = no deck check |
|
||||
| 7 | `T` = no deck shuffle |
|
||||
| 8 | start LP |
|
||||
| 8 | start LP (seat side A; side B too unless the setup pair `ygol.side.b.lp` names its own) |
|
||||
| 9 | start hand |
|
||||
| 10 | draw count |
|
||||
| 11 | time limit (seconds; 0 = none) |
|
||||
@@ -110,6 +110,7 @@ The host string is space-separated tokens, in this order (`server/gframe/gframe.
|
||||
| `preload_script` | `int32_t preload_script(intptr_t pduel, const char* script_name)` | Upstream |
|
||||
| `default_script_reader` | `byte* default_script_reader(const char* script_name, int* len)` | Upstream |
|
||||
| `ygol_preview_attack` | `int32_t ygol_preview_attack(intptr_t pduel, uint8_t playerid, uint8_t location, uint8_t sequence, uint8_t target_location, uint8_t target_sequence, uint8_t* out)` | Patch 0022 (TICKET-374) + 0024 (TICKET-379), 2026-10-13. A read-only dry run of the damage step. Returns 1 answered, 0 refused (bad pointer, no such card, attacker not a face-up monster on `playerid`'s field, target not a monster on the other field); a refusal writes nothing. `target_location` `0xFF` = direct. `out` is 24 bytes: version (1), flags (bit 0 direct, bit 1 unknown, bit 2 attacker destroyed, bit 3 target destroyed, bit 4 pierce, bit 5 illegal), 2 pad bytes, then five `int32`: attacker value, target value, damage to player 0, damage to player 1, reserved 0. A face-down target answers unknown with every number 0. A pair the battle menu (`field::get_attack_target`) would not offer answers illegal alone with every number 0. Call it only while the engine is parked on a prompt; the duel is byte-identical afterwards. |
|
||||
| `ygol_query_tag_cards` | `int32_t ygol_query_tag_cards(intptr_t pduel, uint8_t playerid, uint8_t* out)` | v1.2.0 (TICKET-405), 2026-10-15. The waiting tag partner's cards of `playerid`'s side, read only. Returns the byte length written, 0 refused (bad pointer, bad player, not a tag duel); a refusal writes nothing. `out`: `u8 version` (1), `u8 hand_count`, `u8 extra_count`, `u8 pad` (0), `u16 deck_count`, then `u32 hand[hand_count]`, `u32 extra[extra_count]` (bit 31 = face-up, as in `MSG_TAG_SWAP`), `u32 deck[deck_count]` sorted ascending (the order stays secret). At most 7 + 4 x (255 + 255 + 250) bytes in practice; size the buffer for your deck limits. The duel is byte-identical afterwards. |
|
||||
| `get_registry_value` | `int32_t get_registry_value(intptr_t pduel, const char* key, byte* out_buf)` | Upstream (koishi) |
|
||||
| `set_registry_value` | `void set_registry_value(intptr_t pduel, const char* key, const char* value)` | Upstream (koishi). The server writes every setup pair here before `special.lua` (patch 0009). |
|
||||
| `get_registry_keys` | `int32_t get_registry_keys(intptr_t pduel, byte* out_buf)` | Upstream (koishi) |
|
||||
@@ -131,7 +132,7 @@ The host string is space-separated tokens, in this order (`server/gframe/gframe.
|
||||
|
||||
Locations the sandbox exports accept: DECK, HAND, MZONE, SZONE, GRAVE, REMOVED, EXTRA.
|
||||
|
||||
Export count on Windows: 3 server + 42 core = 45 contract exports, + 289 `sqlite3_*` = 334. The
|
||||
Export count on Windows: 3 server + 43 core = 46 contract exports, + 289 `sqlite3_*` = 335. The
|
||||
Unity repo's old `ygoserver.dll` had 327: its own core copy never carried patch 0008, and it had no
|
||||
`ygol_engine_version`.
|
||||
|
||||
@@ -164,14 +165,15 @@ the server itself speaks. The STOC form of a relayed message is always the CTOS
|
||||
stamp in front. "Stamp" in the tables below says whether the STOC message carries one.
|
||||
|
||||
**Capability.** The server sends `STOC_CAPABILITY` (stamp `0xFF`) to every connection between
|
||||
`STOC_JOIN_GAME` and `STOC_TYPE_CHANGE`: `protocol` = `FEATURE_PROTOCOL` (8) and `flags` = the OR of
|
||||
the bits below (`0x7FF`). A client sends its own `CTOS_CAPABILITY` after joining. A client refuses a
|
||||
`STOC_JOIN_GAME` and `STOC_TYPE_CHANGE`: `protocol` = `FEATURE_PROTOCOL` (9) and `flags` = the OR of
|
||||
the bits below (`0x27FF`). A client sends its own `CTOS_CAPABILITY` after joining. A client refuses a
|
||||
host without bit `0x4` as out of date.
|
||||
|
||||
**Join snapshot.** A joiner gets, per occupied seat, right after that seat's `STOC_HS_PLAYER_ENTER`:
|
||||
the seat's stored capability, appearance (0006), seat state (0013) and profile (0020) when present,
|
||||
then the setup pairs (0009), the seat plan (0011) if one was ever sent, and, during a duel, the field
|
||||
resync (0005) and the deck lists the audience may see (0019).
|
||||
resync (0005), the deck lists the audience may see (0019) and the Tag partner cards: a seated
|
||||
duelist's own side (v1.2.0), both sides for an observer when spectators see all (v1.3.0).
|
||||
|
||||
### Client to server
|
||||
|
||||
@@ -212,6 +214,7 @@ resync (0005) and the deck lists the audience may see (0019).
|
||||
| `0x5C` | `STOC_DECK_LIST` | `STOC_DeckList` (5): `u8 version` (1), `u8 side`, `u8 kind`, `u16 count`, then `u32 codes[count]` | No | Kind 0 (the deck's remaining cards, SORTED) to its owner (both teammates in Tag); kind 1 (real order, top first) and kind 2 (the submitted Main Deck of the duelist whose deck is in the zone, sorted) to observers only when spectators see all. Sent when a list differs from the last one that audience got; in the late-watcher snapshot | `0x100` | 6 | 0019 |
|
||||
| `0x5D` | `STOC_PROFILE` | `u16 sender` + `CTOS_Profile` (100) | Yes | Everyone; stored per seat, in the snapshot after APPEARANCE, swapped with the seat, kept across the 0014 lobby reset, cleared when the seat empties | `0x200` | 7 | 0020 |
|
||||
| `0x5E` | `STOC_ATTACK_PREVIEW` | `u8 version` (1), `u8 count`, then per pair the 4 ask bytes echoed + the 24-byte `ygol_preview_attack` answer | No | The asker only. Only attackers the open prompt listed; a pair the engine refuses is left out (the count shrinks); a valid ask whose every pair is left out still gets count 0 | `0x400` | 8 | 0023 |
|
||||
| `0x5F` | `STOC_TAG_PARTNER_CARDS` | `u8 side` + the `ygol_query_tag_cards` bytes (7 + 4 x the three counts) | No | The two seats of `side`, never the other team. Sent after `start_duel` (the waiting members' opening hands), after every `MSG_TAG_SWAP` for the side that swapped (the member that just left is the waiting one), and to a seated duelist in its field resync (`CTOS_REQUEST_FIELD`, after the `MSG_RELOAD_FIELD`). **v1.3.0 (TICKET-412): when spectators see all (no `ygol.room.spectatorview=hidden`), every observer gets the same bytes for BOTH sides at the start and after every swap, and an observer's field resync and a late watcher's snapshot carry both sides (after the deck lists); with the pair, an observer never gets one.** Tag rooms only; a Single / Match room never sends it | `0x2000` | 9 | v1.2.0, v1.3.0 |
|
||||
|
||||
### Capability bits and protocol numbers
|
||||
|
||||
@@ -228,6 +231,9 @@ resync (0005) and the deck lists the audience may see (0019).
|
||||
| `0x100` | `FEATURE_DECK_LIST` | 6 | 0019 | Deck lists |
|
||||
| `0x200` | `FEATURE_PROFILE` | 7 | 0020 | Profile |
|
||||
| `0x400` | `FEATURE_ATTACK_PREVIEW` | 8 | 0023 | Attack preview over the wire |
|
||||
| `0x800` | reserved | - | - | Proposal 44 (agreed, not shipped) |
|
||||
| `0x1000` | reserved | - | - | Proposal 45 (agreed, not shipped) |
|
||||
| `0x2000` | `FEATURE_TAG_PARTNER_CARDS` | 9 | v1.2.0 | Tag partner cards (`STOC_TAG_PARTNER_CARDS`, `ygol_query_tag_cards`) |
|
||||
|
||||
`FEATURE_PROTOCOL` is bumped by every patch that adds a message a client must understand; the join
|
||||
list hides hosts older than the client's number. Rule 4 (proposal 47): one feature, one door. Never
|
||||
@@ -243,6 +249,9 @@ carry a new feature inside another feature's message.
|
||||
| 0016 | Tag: team B is loaded as seat 2 main deck + seat 3 tag deck, the prompt owner starts at seat 2; with core patch 0015 the turn order is seat 0, 2, 1, 3. |
|
||||
| 0018 | Spectators see all: every observer gets the UNMASKED stream (both hands, draws, set cards, extra, banished, the 0005 snapshot) unless the setup pair `ygol.room.spectatorview=hidden` is present, which restores the stock masked stream byte for byte. Duelists' streams never change. |
|
||||
| 0021 | START ends a rules-restart reservation window and stops the lobby clock, so an untimed duel no longer ends at once on "time limit up". |
|
||||
| v1.1.1 | Tag: no Battle Phase on turns 1, 2 and 3 (1A, 2A, 1B); the fourth duelist (2B) is the first who can battle. `MSG_SELECT_IDLECMD` carries `to_bp` = 0 on those turns and `Duel.IsAbleToEnterBP` answers false. Single duels: turn 1 only, as stock. |
|
||||
| v1.3.0 | Tag partner cards reach observers: when spectators see all, `STOC_TAG_PARTNER_CARDS` goes to every observer for both sides at every send point, plus both sides in an observer's resync and the late-watcher snapshot. Same id, same payload, no new capability bit (TICKET-412). |
|
||||
| v1.4.0 | Life points per side: with the setup pair `ygol.side.b.lp=<n>` (section (d)) seat side B (seat 1; Tag seats 2 and 3) starts at `n` LP and side A at slot 8; without it both sides start at slot 8, as before. `set_player_info` gets each duel player its own LP, and `MSG_START` (the start and the late-watcher snapshot) carries `lp[0]`, `lp[1]` in duel player order: the side that goes first is player 0, so the two values swap when side B won the toss. `STOC_JOIN_GAME`'s `start_lp` stays side A's. Single, Match (every duel) and Tag; no new message, no capability bit. |
|
||||
|
||||
### Replay
|
||||
|
||||
@@ -251,6 +260,11 @@ carries, before the player names, `u32 length` + the setup pairs block (`u16 cou
|
||||
`u16 length` + `key=value`). Limits: `SETUP_PAIRS_MAX` 64 pairs, `SETUP_PAIR_MAX_LEN` 512 bytes per
|
||||
pair.
|
||||
|
||||
v1.4.0 adds the replay flag `REPLAY_YGOL_SIDE_LP` = `0x20000000`, set only when the two duel players
|
||||
start with different LP (`ygol.side.b.lp`). When set, `i32 lp[0]` + `i32 lp[1]` (duel player order)
|
||||
follow the stock `opt` field, before the decks; a reader without the flag keeps the stock layout and
|
||||
gives both players the header's `start_lp`.
|
||||
|
||||
## (c) Engine message stream
|
||||
|
||||
`process` + `get_message` hand the consumer a buffer of messages; each is `u8 id` + payload. The
|
||||
@@ -350,7 +364,7 @@ fork-related rows are marked.
|
||||
| 142 | `MSG_ANNOUNCE_CARD` | `u8 player`; `n` x 4 | yes |
|
||||
| 143 | `MSG_ANNOUNCE_NUMBER` | `u8 player`; `n` x 4 | yes |
|
||||
| 160 | `MSG_CARD_HINT` | 9 | - |
|
||||
| 161 | `MSG_TAG_SWAP` | `u8 player`, `u8 main count`, `u8 extra count`, `u8 extra pendulum count`, `u8 hand count`, `u32 top code`, then `u32` x hand, `u32` x extra. Not in `Scan` (the bot host never runs Tag). **Fork (core patch 0015): never emitted on a team's first turn; the first swap comes on turn 3 or later.** | - |
|
||||
| 161 | `MSG_TAG_SWAP` | `u8 player`, `u8 main count`, `u8 extra count`, `u8 extra pendulum count`, `u8 hand count`, `u32 top code`, then `u32` x hand, `u32` x extra. Not in `Scan` (the bot host never runs Tag). **Fork (core patch 0015): never emitted on a team's first turn; the first swap comes on turn 3 or later. v1.2.0: the server follows every swap with `STOC_TAG_PARTNER_CARDS` to the swapping side's two seats; v1.3.0: and to every observer when spectators see all. v1.4.1 (TICKET-415): a card an effect moves out of the waiting member's hand, deck or Extra Deck (one it kept across the swap, e.g. Time Fusion's Fusion) leaves that list, so the next swap lists one card fewer; its `MSG_MOVE` `from` sequence counts into the waiting list, not the active one.** | - |
|
||||
| 162 | `MSG_RELOAD_FIELD` | `u8 duel rule`; per player: `u32 lp`, 7 monster zones (`u8 present`, +2 when present), 8 spell zones (`u8 present`, +1 when present), 6 count bytes; then ONE chain block `n` x 15 after both players. Produced by `query_field_info` and `Debug.ReloadFieldEnd()`; the server sends it as the 0005 field resync | - |
|
||||
| 163 | `MSG_AI_NAME` | `u16 len` + bytes + 1 | - |
|
||||
| 164 | `MSG_SHOW_HINT` | `u16 len` + bytes + 1 | - |
|
||||
@@ -373,12 +387,13 @@ never interprets a pair: it stores the ordered list (max 64 pairs, 512 bytes eac
|
||||
`0x40000000`) and sends them to every joiner as `STOC_SETUP_PAIRS` (`0x43`). Values that need `,`,
|
||||
`=`, `%` or a space are percent-encoded by the client (`MatchSetup.cs`).
|
||||
|
||||
Two pairs ARE read by the server itself:
|
||||
Three pairs ARE read by the server itself:
|
||||
|
||||
| Key | Value | Read by |
|
||||
|---|---|---|
|
||||
| `ygol.room.watchers` | `0` = no observers: every observer join and HsToObserver is refused | 0012 |
|
||||
| `ygol.room.spectatorview` | `hidden` = the stock masked observer stream; absent = spectators see all | 0018, 0019 |
|
||||
| `ygol.side.b.lp` | a positive integer: seat side B's start LP (seat 1; Tag seats 2 and 3); side A keeps slot 8. Absent, `0`, negative or not a number = both sides at slot 8 | v1.4.0 |
|
||||
|
||||
Keys the Unity client sends today (`Assets/YGOLegacy/Scripts/Core/Duel/MatchSetup.cs`,
|
||||
`SetupPairKeys`); the rules Lua reads them from the registry:
|
||||
@@ -414,7 +429,7 @@ Namespaces:
|
||||
|
||||
| Namespace | What |
|
||||
|---|---|
|
||||
| `YGOLegacy.Protocol.{Contracts, Codecs, Framing, Routing}` | Section (b) in C#: the message ids and payload records, the CTOS / STOC codecs, the frame codec and the STOC router. Unchanged from the Unity repo (TICKET-397). |
|
||||
| `YGOLegacy.Protocol.{Contracts, Codecs, Framing, Routing}` | Section (b) in C#: the message ids and payload records, the CTOS / STOC codecs, the frame codec and the STOC router. Unchanged from the Unity repo (TICKET-397); v1.2.0 adds `StocMessage.TagPartnerCards`, `FeatureFlags.TagPartnerCards`, the `TagPartnerCards` record and `StocCodecs.TagPartnerCards`, and `Capability.ProtocolVersion` is 9; v1.4.0 adds `ReplayFlags` (`SetupPairs` = `0x40000000`, `SideLp` = `0x20000000`). |
|
||||
| `YGOLegacy.Engine` | The four types below (TICKET-398). |
|
||||
|
||||
| Type | What |
|
||||
@@ -455,6 +470,7 @@ Every row is one export of section (a) with its managed signature. A `string` pa
|
||||
| `preload_script` | `int preload_script(IntPtr pduel, string script_name)` |
|
||||
| `default_script_reader` | `IntPtr default_script_reader(string script_name, int* len)` |
|
||||
| `ygol_preview_attack` | `int ygol_preview_attack(IntPtr pduel, byte playerid, byte location, byte sequence, byte target_location, byte target_sequence, byte[] @out)` |
|
||||
| `ygol_query_tag_cards` | `int ygol_query_tag_cards(IntPtr pduel, byte playerid, byte[] @out)` |
|
||||
| `get_registry_value` | `int get_registry_value(IntPtr pduel, string key, byte[] out_buf)` |
|
||||
| `set_registry_value` | `void set_registry_value(IntPtr pduel, string key, string value)` |
|
||||
| `get_registry_keys` | `int get_registry_keys(IntPtr pduel, byte[] out_buf)` |
|
||||
|
||||
@@ -83,6 +83,13 @@ OCGCORE_API byte* default_script_reader(const char* script_name, int* len);
|
||||
// the duel is byte-identical afterwards (proposal 43).
|
||||
OCGCORE_API int32_t ygol_preview_attack(intptr_t pduel, uint8_t playerid, uint8_t location, uint8_t sequence, uint8_t target_location, uint8_t target_sequence, uint8_t* out);
|
||||
|
||||
// [YGOL] v1.2.0 (tag partner cards, TICKET-405): the waiting tag partner's cards of playerid's side, read
|
||||
// only. out: version (1), hand count, extra count, one pad byte, uint16 deck count, then the uint32 hand
|
||||
// codes, the uint32 extra codes (bit 31 = face-up, like MSG_TAG_SWAP) and the uint32 deck codes sorted
|
||||
// ascending (the order stays secret). Returns the byte length, 0 refused (bad pointer, bad player, not a
|
||||
// tag duel); a refusal writes nothing. The duel is byte-identical afterwards (proposal 33 Rule 11).
|
||||
OCGCORE_API int32_t ygol_query_tag_cards(intptr_t pduel, uint8_t playerid, uint8_t* out);
|
||||
|
||||
// koishi specific
|
||||
OCGCORE_API int32_t get_registry_value(intptr_t pduel, const char* key, byte* out_buf);
|
||||
OCGCORE_API void set_registry_value(intptr_t pduel, const char* key, const char* value);
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
# python Tools/YGOLegacy/probe-feature-messages.py --dll <path\to\ygoserver.dll>
|
||||
# hosts its own lobby from that DLL (cwd must be the repo root, like
|
||||
# BotArena: the DLL reads ./expansions and friends) on --port (default
|
||||
# 7961) and stops it at the end. This is how a freshly built, not yet
|
||||
# 27961) and stops it at the end. This is how a freshly built, not yet
|
||||
# installed DLL is probed.
|
||||
#
|
||||
# With --dll it then gates patch 0009 (TICKET-258, setup pairs): it hosts five
|
||||
@@ -113,7 +113,8 @@
|
||||
#
|
||||
# With --dll it also gates patch 0023 (TICKET-378, attack preview): the server's
|
||||
# capability says protocol 8 + flag 0x400; each side summons a Probe Knight and
|
||||
# the second seat enters its Battle Phase; its ATTACK_PREVIEW ask (0x5E: version,
|
||||
# the second seat enters its Battle Phase (Tag: the fourth duelist on turn 4, since
|
||||
# v1.1.1 allows no Battle Phase on tag turns 1-3); its ATTACK_PREVIEW ask (0x5E: version,
|
||||
# count, 4 bytes per pair) is answered to that seat alone (0x5E: version, count,
|
||||
# per pair the 4 bytes echoed + the engine's 24-byte answer): the knight into the
|
||||
# knight says both die, a direct attack says illegal, a pair the prompt does not
|
||||
@@ -121,6 +122,27 @@
|
||||
# a wrong version, too many pairs and a wrong length are dropped without a reply;
|
||||
# a seat that never asks gets no 0x5E and the duel goes on. Single and Tag.
|
||||
#
|
||||
# With --dll it also gates v1.2.0 (TICKET-405, tag partner cards): the server's
|
||||
# capability says protocol 9 + flag 0x2000 (single and tag); in a Tag room each
|
||||
# seat gets TAG_PARTNER_CARDS (0x5F: side, version 1, hand count, extra count,
|
||||
# pad, u16 deck count, then the hand, Extra Deck and deck codes) for its own side
|
||||
# only -- at the start the waiting member's 5-card opening hand, its two Probe
|
||||
# Fusions and its 35 remaining cards SORTED; after each MSG_TAG_SWAP the member
|
||||
# that just left, hand = every card it drew, deck = its deck minus them; a seat's
|
||||
# field resync (CTOS_REQUEST_FIELD) carries the same list again to that seat
|
||||
# alone -- and the other team never gets one. The hand a swap brings in is the
|
||||
# hand the opening 0x5F announced. TICKET-412: when the room shows all, the
|
||||
# watcher gets the same bytes for BOTH sides at every send point, its resync and
|
||||
# a late watcher's snapshot carry both sides; with ygol.room.spectatorview=hidden
|
||||
# the watcher, its resync and the late watcher's snapshot never get one.
|
||||
#
|
||||
# With --dll it also gates v1.4.0 (life points per side): two more setup-pair
|
||||
# rooms (Single and Tag) with ygol.side.b.lp=4000 start a duel; every seat's
|
||||
# MSG_START carries 8000 for seat side A and 4000 for side B in DUEL PLAYER
|
||||
# order (the side that goes first is player 0, so the two values swap when
|
||||
# side B won the toss), and the replay has flag 0x20000000 with the same two
|
||||
# values after opt. Every other room's replay has no such flag.
|
||||
#
|
||||
# Exit 0 only when every check passed. Stock DLL: the first check fails; the
|
||||
# 0011 DLL fails at the capability flags.
|
||||
import argparse, base64, ctypes, lzma, os, shutil, socket, sqlite3, struct, sys, tempfile, threading, time
|
||||
@@ -266,7 +288,7 @@ def check_snapshot(who, pkts, expect_seat_appearance, forbid_seat):
|
||||
check(len(server_caps) == 1 and j < server_caps[0][0] < t, "%s: the server's CAPABILITY(0xFF) sits between JOIN_GAME and TYPE_CHANGE" % who)
|
||||
if server_caps:
|
||||
proto, flags = struct.unpack_from("<HI", server_caps[0][1], 2)
|
||||
check(proto == 8 and flags == 0x7FF, "%s: server capability is protocol 8, flags 0x7FF (appearance | dialogue | setup pairs | seat plan | rules restart | seat state | lobby after match | coin toss | deck lists | profile | attack preview), got %d / 0x%x" % (who, proto, flags))
|
||||
check(proto == 9 and flags == 0x27FF, "%s: server capability is protocol 9, flags 0x27FF (appearance | dialogue | setup pairs | seat plan | rules restart | seat state | lobby after match | coin toss | deck lists | profile | attack preview | tag partner cards), got %d / 0x%x" % (who, proto, flags))
|
||||
for seat, expected in expect_seat_appearance.items():
|
||||
enters = [i for i, (p, d) in enumerate(pkts) if p == STOC_HS_PLAYER_ENTER and d[40] == seat]
|
||||
apps = [i for i, (p, d) in enumerate(pkts) if p == STOC_APPEARANCE and struct.unpack_from("<H", d, 0)[0] == seat]
|
||||
@@ -295,7 +317,7 @@ def host_dll(path, port, mode=0, tail=""):
|
||||
deadline = time.time() + 20
|
||||
while time.time() < deadline:
|
||||
if not t.is_alive():
|
||||
sys.exit("ygoserver thread ended before it listened (cwd must be the repo root; port %d free?)" % port)
|
||||
sys.exit("ygoserver thread ended before it listened (cwd must be the repo root; port %d free? a port inside the OS dynamic range collides with the probe's own connections)" % port)
|
||||
try:
|
||||
socket.create_connection(("127.0.0.1", port), timeout=0.3).close()
|
||||
return dll, t
|
||||
@@ -310,7 +332,10 @@ def main():
|
||||
ap.add_argument("--port", type=int, default=None)
|
||||
ap.add_argument("--dll", default=None, help="host a lobby from this ygoserver.dll instead of connecting to one")
|
||||
o = ap.parse_args()
|
||||
port = o.port or (7961 if o.dll else 7911)
|
||||
# Above every OS dynamic (ephemeral) port range: this machine hands outgoing connections ports
|
||||
# 1024-15000 (netsh int ipv4 show dynamicport tcp), and a probe client that drew the next room's
|
||||
# port made that room's bind fail ("0", then "ended before it listened") on most runs.
|
||||
port = o.port or (27961 if o.dll else 7911)
|
||||
feature_suite(o, port)
|
||||
if o.dll:
|
||||
setup_suite(o.dll, port + 1)
|
||||
@@ -323,6 +348,8 @@ def main():
|
||||
deck_list_suite(o.dll, port + 80)
|
||||
profile_suite(o.dll, port + 90)
|
||||
attack_preview_suite(o.dll, port + 100)
|
||||
tag_partner_suite(o.dll, port + 110)
|
||||
tag_across_swap_suite(o.dll, port + 120)
|
||||
print()
|
||||
if failures:
|
||||
print("FAILED: %d check(s)" % len(failures))
|
||||
@@ -442,6 +469,7 @@ CTOS_UPDATE_DECK, CTOS_HAND_RESULT, CTOS_TP_RESULT, CTOS_SURRENDER, CTOS_HS_STAR
|
||||
STOC_SELECT_HAND, STOC_SELECT_TP, STOC_CHANGE_SIDE, STOC_REPLAY = 0x03, 0x04, 0x07, 0x17
|
||||
STOC_SETUP_PAIRS = 0x43
|
||||
REPLAY_COMPRESSED, REPLAY_TAG, REPLAY_YGOL_SETUP_PAIRS = 0x1, 0x2, 0x40000000
|
||||
REPLAY_YGOL_SIDE_LP = 0x20000000
|
||||
PROBE_CARD = 89631139
|
||||
PROBE_KNIGHT = PROBE_CARD + 500 # patch 0023: level 4, 1800 / 1000
|
||||
NAMES.update({0x03: "SELECT_HAND", 0x04: "SELECT_TP", 0x05: "HAND_RESULT", 0x07: "CHANGE_SIDE", 0x09: "DECK_COUNT",
|
||||
@@ -494,8 +522,16 @@ def make_workspace():
|
||||
# patch 0023: a level-4 normal monster, so a seat can summon without a tribute and attack with it
|
||||
db.execute("INSERT INTO datas VALUES(?, 3, 0, 0, 17, 1800, 1000, 4, 1, 16, 0)", (PROBE_KNIGHT,))
|
||||
db.execute("INSERT INTO texts VALUES(?, 'Probe Knight', ''" + ", ''" * 16 + ")", (PROBE_KNIGHT,))
|
||||
# v1.2.0 (TICKET-405): a Fusion monster, so a submitted deck has an Extra Deck
|
||||
db.execute("INSERT INTO datas VALUES(?, 3, 0, 0, 65, 2000, 2000, 6, 1, 16, 0)", (PROBE_FUSION,))
|
||||
db.execute("INSERT INTO texts VALUES(?, 'Probe Fusion', ''" + ", ''" * 16 + ")", (PROBE_FUSION,))
|
||||
# TICKET-415: a Spell that keeps a card across the tag swap (its script is read from ./script)
|
||||
db.execute("INSERT INTO datas VALUES(?, 3, 0, 0, 2, 0, 0, 0, 0, 0, 0)", (PROBE_TIME_FUSION,))
|
||||
db.execute("INSERT INTO texts VALUES(?, 'Probe Time Fusion', ''" + ", ''" * 16 + ")", (PROBE_TIME_FUSION,))
|
||||
db.commit()
|
||||
db.close()
|
||||
with open(os.path.join(root, "script", "c%d.lua" % PROBE_TIME_FUSION), "w", newline="\n") as f:
|
||||
f.write(TIME_FUSION_LUA)
|
||||
return root
|
||||
|
||||
|
||||
@@ -586,11 +622,19 @@ def check_snapshot_pairs(who, pkts, pairs):
|
||||
check(decoded == pairs and size == len(got[0]) - 2, "%s: SETUP_PAIRS carries the %d pairs in host-string order, nothing else" % (who, len(pairs)))
|
||||
|
||||
|
||||
def check_replay(who, c, pairs, seed_tag, tag=False):
|
||||
def check_replay(who, c, pairs, seed_tag, tag=False, lp=None):
|
||||
reps = replays(c)
|
||||
if not check(len(reps) >= 1, "%s: a REPLAY arrived at duel end" % who):
|
||||
return
|
||||
flag, seeds, body = reps[-1]
|
||||
seats = 4 if tag else 2
|
||||
lp_at = (4 + struct.unpack_from("<I", body, 0)[0] if pairs else 0) + 40 * seats + 16
|
||||
if lp is not None:
|
||||
if check(flag & REPLAY_YGOL_SIDE_LP, "%s: replay flag has the side LP bit 0x20000000 (flag 0x%x)" % (who, flag)):
|
||||
got = struct.unpack_from("<ii", body, lp_at)
|
||||
check(got == tuple(lp), "%s: replay carries int32 lp[0], lp[1] after opt in duel player order %s (got %s)" % (who, tuple(lp), got))
|
||||
else:
|
||||
check(not flag & REPLAY_YGOL_SIDE_LP, "%s: replay flag has NO side LP bit (flag 0x%x)" % (who, flag))
|
||||
if pairs:
|
||||
if not check(flag & REPLAY_YGOL_SETUP_PAIRS, "%s: replay flag has the setup pairs bit 0x40000000 (flag 0x%x)" % (who, flag)):
|
||||
return
|
||||
@@ -627,7 +671,27 @@ def start_duel(clients, port, hand):
|
||||
clients[0].send(CTOS_HS_START)
|
||||
|
||||
|
||||
def run_case(dll_path, root, port, label, pairs, mode=0, seed_tag=None, junk=(), watcher=False):
|
||||
def starts_of(c):
|
||||
return [d for p, d in c.log if p == 0x01 and len(d) >= 11 and d[0] == MSG_START]
|
||||
|
||||
|
||||
def check_side_lp(label, clients, lp):
|
||||
# lp = (side A, side B) by SEAT side; MSG_START lists duel players, and the side that goes first is player 0
|
||||
duel_lp = None
|
||||
for c in clients:
|
||||
side = 1 if c.seat >= 2 else (1 if c.seat == 1 and len(clients) == 2 else 0)
|
||||
got = starts_of(c)
|
||||
if not check(len(got) == 1, "%s: seat %d got one MSG_START (got %d)" % (label, c.seat, len(got))):
|
||||
continue
|
||||
player = got[0][1] & 0xF
|
||||
want = tuple(lp) if player == side else (lp[1], lp[0])
|
||||
pair = struct.unpack_from("<ii", got[0], 3)
|
||||
check(pair == want, "%s: seat %d (duel player %d) MSG_START lp = %s in duel player order (got %s)" % (label, c.seat, player, want, pair))
|
||||
duel_lp = duel_lp or pair
|
||||
return duel_lp
|
||||
|
||||
|
||||
def run_case(dll_path, root, port, label, pairs, mode=0, seed_tag=None, junk=(), watcher=False, lp=None):
|
||||
print("== setup pairs, %s: %d pair(s), mode %d" % (label, len(pairs), mode))
|
||||
write_special(root, pairs)
|
||||
tokens = list(pairs[:len(pairs) // 2]) + list(junk) + list(pairs[len(pairs) // 2:])
|
||||
@@ -649,6 +713,10 @@ def run_case(dll_path, root, port, label, pairs, mode=0, seed_tag=None, junk=(),
|
||||
"%s: special.lua saw exactly the pairs in the registry, before it ran (%s)" % (label, want_verdict))
|
||||
if mode == 1:
|
||||
check(bool(lines) and lines[0].endswith("count=0"), "%s: duel 1 ran with duel_count=0" % label)
|
||||
duel_lp = None
|
||||
if lp is not None:
|
||||
pump(clients, lambda: all(starts_of(c) for c in clients), limit=5, hand=hand)
|
||||
duel_lp = check_side_lp(label, clients, lp)
|
||||
everyone = list(clients)
|
||||
if watcher:
|
||||
w = Client("127.0.0.1", port, "pair-watch")
|
||||
@@ -661,7 +729,7 @@ def run_case(dll_path, root, port, label, pairs, mode=0, seed_tag=None, junk=(),
|
||||
for c in surrender:
|
||||
c.send(CTOS_SURRENDER)
|
||||
pump(everyone, lambda: all(replays(c) for c in clients), limit=10, hand=hand)
|
||||
check_replay(label, clients[0], pairs, seed_tag, tag=(mode == 2))
|
||||
check_replay(label, clients[0], pairs, seed_tag, tag=(mode == 2), lp=duel_lp)
|
||||
if watcher:
|
||||
check_replay("%s late watcher" % label, everyone[-1], pairs, seed_tag)
|
||||
if mode == 1:
|
||||
@@ -702,6 +770,8 @@ def setup_suite(dll_path, port):
|
||||
run_case(dll_path, root, port + 2, "twenty", many, seed_tag=2, junk=["ygol.noequals", "ygol.=nokey"])
|
||||
run_case(dll_path, root, port + 3, "match", ["ygol.ruleset=rush", "ygol.scripts=rulesets/rush.lua"], mode=1)
|
||||
run_case(dll_path, root, port + 4, "tag", ["ygol.ruleset=rush", "ygol.scripts=rulesets/rush.lua"], mode=2)
|
||||
run_case(dll_path, root, port + 5, "side b lp", ["ygol.side.b.lp=4000"], lp=(8000, 4000))
|
||||
run_case(dll_path, root, port + 6, "side b lp tag", ["ygol.side.b.lp=4000"], mode=2, lp=(8000, 4000))
|
||||
finally:
|
||||
os.chdir(here)
|
||||
shutil.rmtree(root, ignore_errors=True)
|
||||
@@ -2393,7 +2463,7 @@ def preview_answer(flags, attacker=0, target=0, damage0=0, damage1=0):
|
||||
|
||||
def attack_preview_room(dll_path, port, label, mode):
|
||||
seats = 4 if mode == 2 else 2
|
||||
print("== attack preview, %s (%d seats + a watcher: a summon each, then the second seat's Battle Phase)" % (label, seats))
|
||||
print("== attack preview, %s (%d seats + a watcher: a summon each, then the %s Battle Phase)" % (label, seats, "fourth duelist's turn-4" if mode == 2 else "second seat's"))
|
||||
root = make_workspace()
|
||||
here = os.getcwd()
|
||||
os.chdir(root)
|
||||
@@ -2456,6 +2526,16 @@ def attack_preview_room(dll_path, port, label, mode):
|
||||
second = summon("turn 2")
|
||||
if not second:
|
||||
return
|
||||
if mode == 2:
|
||||
# v1.1.1: a Tag duel has no Battle Phase on turns 1-3; the fourth duelist (2B) is the first who may battle
|
||||
for stage in ("turn 3", "turn 4"):
|
||||
before = marks_of(everyone)
|
||||
answer(second, struct.pack("<i", 7)) # idle command 7: to the End Phase
|
||||
ok = pump(everyone, lambda: any(game_msgs(since(c, before), MSG_SELECT_IDLECMD) for c in seated if c is not second), limit=8, chain=True)
|
||||
holders = [c for c in seated if game_msgs(since(c, before), MSG_SELECT_IDLECMD)]
|
||||
if not check(ok and len(holders) == 1, "%s: %s: the turn passed and one swapped-in seat holds the idle prompt (%s)" % (label, stage, [c.name for c in holders])):
|
||||
return
|
||||
second = holders[0]
|
||||
before = marks_of(everyone)
|
||||
answer(second, struct.pack("<i", 6)) # idle command 6: to the Battle Phase
|
||||
ok = pump(everyone, lambda: game_msgs(since(second, before), MSG_SELECT_BATTLECMD), limit=6, chain=True)
|
||||
@@ -2525,5 +2605,377 @@ def attack_preview_suite(dll_path, port):
|
||||
attack_preview_room(dll_path, port + 1, "tag", 2)
|
||||
|
||||
|
||||
# --- v1.2.0 (TICKET-405): tag partner cards --------------------------------------
|
||||
STOC_TAG_PARTNER_CARDS, CTOS_REQUEST_FIELD, MSG_RELOAD_FIELD = 0x5F, 0x30, 162
|
||||
NAMES.update({0x5F: "TAG_PARTNER_CARDS"})
|
||||
PROBE_FUSION = PROBE_CARD + 600 # a Fusion monster: it goes to the Extra Deck
|
||||
TAG_PARTNER_DECKS = [DECK_LIST_CODES[seat] + [PROBE_FUSION, PROBE_FUSION] for seat in range(4)]
|
||||
|
||||
|
||||
def partner_cards(pkts, side=None):
|
||||
# (side, version, hand, extra, deck, size); hand / extra / deck are None when the size does not match the counts
|
||||
out = []
|
||||
for p, d in pkts:
|
||||
if p != STOC_TAG_PARTNER_CARDS or len(d) < 7:
|
||||
continue
|
||||
s, version, hand_n, extra_n, _pad, deck_n = struct.unpack_from("<BBBBBH", d, 0)
|
||||
if side is not None and s != side:
|
||||
continue
|
||||
n = hand_n + extra_n + deck_n
|
||||
if len(d) != 7 + 4 * n:
|
||||
out.append((s, version, None, None, None, len(d)))
|
||||
continue
|
||||
codes = list(struct.unpack_from("<%dI" % n, d, 7))
|
||||
out.append((s, version, codes[:hand_n], codes[hand_n:hand_n + extra_n], codes[hand_n + extra_n:], len(d)))
|
||||
return out
|
||||
|
||||
|
||||
def server_capability(pkts):
|
||||
for p, d in pkts:
|
||||
if p == STOC_CAPABILITY and len(d) == 8 and struct.unpack_from("<H", d, 0)[0] == SERVER:
|
||||
return struct.unpack_from("<HI", d, 2)
|
||||
return None
|
||||
|
||||
|
||||
def tag_swap_hand(d):
|
||||
# MSG_TAG_SWAP: player, main count, extra count, pendulum count, hand count, u32 top, u32 x hand, u32 x extra
|
||||
hcount = d[5]
|
||||
return [c & 0x7FFFFFFF for c in struct.unpack_from("<%dI" % hcount, d, 10)]
|
||||
|
||||
|
||||
def tag_partner_room(dll_path, port, label, hidden):
|
||||
print("== tag partner cards, %s (4 seats + a watcher: the opening hands, both swaps, a seat's and the watcher's field resync, a late watcher)" % label)
|
||||
root = make_workspace()
|
||||
here = os.getcwd()
|
||||
os.chdir(root)
|
||||
try:
|
||||
write_special(root, [])
|
||||
dll, thread = host_dll(dll_path, port, 2, SPECTATOR_HIDDEN if hidden else "")
|
||||
clients = []
|
||||
|
||||
def client(name):
|
||||
c = Client("127.0.0.1", port, name)
|
||||
c.log = list(c.join())
|
||||
clients.append(c)
|
||||
return c
|
||||
|
||||
seated = [client("tp-seat%d" % i) for i in range(4)]
|
||||
w = client("tp-watch")
|
||||
everyone = seated + [w]
|
||||
check([c.seat for c in everyone] == [0, 1, 2, 3, OBSERVER], "%s: four seats and a watcher (%r)" % (label, [c.seat for c in everyone]))
|
||||
cap = server_capability(seated[0].log)
|
||||
check(cap == (9, 0x27FF), "%s: the tag server's capability is protocol 9, flags 0x27FF (got %s)" % (label, cap))
|
||||
drain_all(everyone)
|
||||
for c in seated:
|
||||
c.send(CTOS_UPDATE_DECK, deck_bytes(TAG_PARTNER_DECKS[c.seat]))
|
||||
pump(everyone, lambda: False, limit=0.8)
|
||||
marks = start_duel_on(label, seated[0], everyone, None, "tag partner cards")
|
||||
ok = pump(everyone, lambda: all(len(draws(since(c, marks))) >= 2 for c in everyone) and any(game_msgs(since(c, marks), MSG_SELECT_IDLECMD) for c in seated), limit=10)
|
||||
check(ok, "%s: the opening draws and the first idle prompt reached the seats" % label)
|
||||
side_of = {}
|
||||
for c in seated:
|
||||
s = starts(since(c, marks))
|
||||
side_of[c] = s[0] if len(s) == 1 else -1
|
||||
by_side = {p: [c for c in seated if side_of[c] == p] for p in (0, 1)}
|
||||
if not check(all(len(by_side[p]) == 2 for p in (0, 1)), "%s: every seat got one MSG_START naming its side (%s)" % (label, {k: [c.name for c in v] for k, v in by_side.items()})):
|
||||
return
|
||||
first_seat = {p: min(c.seat for c in by_side[p]) for p in (0, 1)}
|
||||
partner_seat = {p: max(c.seat for c in by_side[p]) for p in (0, 1)}
|
||||
extra_expected = [PROBE_FUSION, PROBE_FUSION]
|
||||
|
||||
def check_cards(side, since_marks, stage, waiting_seat, expect_hand=None):
|
||||
pool = set(DECK_LIST_CODES[waiting_seat])
|
||||
latest = None
|
||||
for c in by_side[side]:
|
||||
got = partner_cards(since(c, since_marks), side)
|
||||
check(len(got) == 1, "%s: %s: seat %d got exactly one TAG_PARTNER_CARDS for its side %d (%d)" % (label, stage, c.seat, side, len(got)))
|
||||
check(not partner_cards(since(c, since_marks), 1 - side), "%s: %s: seat %d got none for the other side" % (label, stage, c.seat))
|
||||
if not got:
|
||||
continue
|
||||
s, version, hand, extra, deck, size = got[-1]
|
||||
if not check(hand is not None, "%s: %s: seat %d's TAG_PARTNER_CARDS is 7 + 4 x counts bytes (%d)" % (label, stage, c.seat, size)):
|
||||
continue
|
||||
check(version == 1, "%s: %s: seat %d's list is version 1 (%d)" % (label, stage, c.seat, version))
|
||||
if expect_hand is None:
|
||||
check(len(hand) == 5 and set(hand) <= pool, "%s: %s: seat %d's partner hand is 5 cards of seat %d's deck (%s)" % (label, stage, c.seat, waiting_seat, hand))
|
||||
else:
|
||||
check(sorted(hand) == sorted(expect_hand), "%s: %s: seat %d's partner hand is every card seat %d drew (%d; expected %d)" % (label, stage, c.seat, waiting_seat, len(hand), len(expect_hand)))
|
||||
check(extra == extra_expected, "%s: %s: seat %d's partner Extra Deck is the two Probe Fusions, face-down (%s)" % (label, stage, c.seat, extra))
|
||||
check(deck == sorted(deck) and len(deck) == len(set(deck)), "%s: %s: seat %d's partner deck is sorted ascending" % (label, stage, c.seat))
|
||||
check(deck == sorted(pool - set(hand)), "%s: %s: seat %d's partner deck is seat %d's Main Deck minus the hand (%d)" % (label, stage, c.seat, waiting_seat, len(deck)))
|
||||
latest = got[-1]
|
||||
for c in by_side[1 - side]:
|
||||
check(not partner_cards(since(c, since_marks), side), "%s: %s: seat %d (the other team) got no TAG_PARTNER_CARDS for side %d" % (label, stage, c.seat, side))
|
||||
check_watcher(w, since_marks, stage, side, latest)
|
||||
return latest
|
||||
|
||||
def check_watcher(c, since_marks, stage, side, latest):
|
||||
if hidden:
|
||||
check(not partner_cards(since(c, since_marks)), "%s: %s: %s got no TAG_PARTNER_CARDS (hidden)" % (label, stage, c.name))
|
||||
return
|
||||
got = partner_cards(since(c, since_marks), side)
|
||||
check(len(got) == 1, "%s: %s: %s got exactly one TAG_PARTNER_CARDS for side %d (%d)" % (label, stage, c.name, side, len(got)))
|
||||
check(bool(got) and bool(latest) and got[-1][1:5] == latest[1:5], "%s: %s: %s's side %d list is the bytes the seats got" % (label, stage, c.name, side))
|
||||
|
||||
opening = {}
|
||||
for p in (0, 1):
|
||||
opening[p] = check_cards(p, marks, "opening", partner_seat[p])
|
||||
|
||||
def end_turn(stage):
|
||||
holders = [c for c in seated if game_msgs(since(c, end_turn.marks), MSG_SELECT_IDLECMD)]
|
||||
check(len(holders) == 1, "%s: %s: exactly one seat holds the idle prompt (%s)" % (label, stage, [c.name for c in holders]))
|
||||
if not holders:
|
||||
return None
|
||||
before = marks_of(everyone)
|
||||
holders[0].send(CTOS_TIME_CONFIRM) # the timed server holds the seat until the clock is acknowledged
|
||||
holders[0].send(CTOS_RESPONSE, struct.pack("<i", 7)) # idle command 7: to the End Phase
|
||||
ok = pump(everyone, lambda: any(draws(since(c, before)) for c in seated) and any(game_msgs(since(c, before), MSG_SELECT_IDLECMD) for c in seated), limit=10, chain=True)
|
||||
check(ok, "%s: %s: the turn passed and the next seat drew" % (label, stage))
|
||||
end_turn.marks = before
|
||||
return before
|
||||
end_turn.marks = marks
|
||||
|
||||
def check_swap(side, before, stage):
|
||||
owner = by_side[side][0]
|
||||
new = since(owner, before)
|
||||
cut = next((i for i, (pid, _) in enumerate(new) if pid == STOC_TAG_PARTNER_CARDS), None)
|
||||
if not check(cut is not None, "%s: %s: side %d got a TAG_PARTNER_CARDS after its swap" % (label, stage, side)):
|
||||
return
|
||||
pre = owner.log[marks[owner]:before[owner] + cut]
|
||||
drawn = [x for d in draws(pre, side) for x in draw_codes(d)]
|
||||
check(len(drawn) >= 5, "%s: %s: seat %d drew %d cards before the swap" % (label, stage, first_seat[side], len(drawn)))
|
||||
check_cards(side, before, stage, first_seat[side], expect_hand=drawn)
|
||||
check(not partner_cards(since(w, before), 1 - side), "%s: %s: the watcher got none for the other side" % (label, stage))
|
||||
swaps = [d for d in game_msgs(new, MSG_TAG_SWAP) if len(d) > 10 and d[1] == side]
|
||||
check(len(swaps) == 1, "%s: %s: side %d saw one MSG_TAG_SWAP for itself (%d)" % (label, stage, side, len(swaps)))
|
||||
if swaps and opening.get(side) and opening[side][2] is not None:
|
||||
check(sorted(tag_swap_hand(swaps[0])) == sorted(opening[side][2]), "%s: %s: the hand the swap brought in is the hand the opening TAG_PARTNER_CARDS announced" % (label, stage))
|
||||
|
||||
before = end_turn("pass 1") # turn 2: side 1's first turn, no swap
|
||||
if before:
|
||||
check(all(not partner_cards(since(c, before)) for c in everyone), "%s: pass 1: a turn without a swap sent nobody a TAG_PARTNER_CARDS" % label)
|
||||
before = end_turn("pass 2") # turn 3: side 0 swaps to its partner
|
||||
if before:
|
||||
check_swap(0, before, "pass 2")
|
||||
before = end_turn("pass 3") # turn 4: side 1 swaps to its partner
|
||||
if before:
|
||||
check_swap(1, before, "pass 3")
|
||||
|
||||
asker = by_side[0][1]
|
||||
last = {p: partner_cards(by_side[p][0].log[marks[by_side[p][0]]:], p) for p in (0, 1)}
|
||||
marks3 = marks_of(everyone)
|
||||
asker.send(CTOS_REQUEST_FIELD)
|
||||
w.send(CTOS_REQUEST_FIELD)
|
||||
pump(everyone, lambda: partner_cards(since(asker, marks3)) and game_msgs(since(w, marks3), MSG_RELOAD_FIELD) and (hidden or len(partner_cards(since(w, marks3))) >= 2), limit=3)
|
||||
got = partner_cards(since(asker, marks3), 0)
|
||||
check(len(got) == 1 and bool(game_msgs(since(asker, marks3), MSG_RELOAD_FIELD)), "%s: a seat's field resync carried one TAG_PARTNER_CARDS for its side (%d)" % (label, len(got)))
|
||||
check(bool(got) and bool(last[0]) and got[0][2:5] == last[0][-1][2:5], "%s: the resync list equals the last list that seat got" % label)
|
||||
check(bool(game_msgs(since(w, marks3), MSG_RELOAD_FIELD)) and all(not partner_cards(since(c, marks3)) for c in everyone if c is not asker and c is not w), "%s: the watcher's resync reloaded its field and the other seats got no TAG_PARTNER_CARDS" % label)
|
||||
for p in (0, 1):
|
||||
check_watcher(w, marks3, "watcher resync", p, last[p][-1] if last[p] else None)
|
||||
|
||||
l = client("tp-late")
|
||||
l.log += l.drain(quiet=0.6)
|
||||
check(l.seat == OBSERVER and STOC_DUEL_START in ids_of(l.log), "%s: a mid-duel joiner is an observer and got DUEL_START" % label)
|
||||
late_marks = {l: 0}
|
||||
for p in (0, 1):
|
||||
check_watcher(l, late_marks, "late snapshot", p, last[p][-1] if last[p] else None)
|
||||
|
||||
marks4 = marks_of(everyone + [l])
|
||||
for c in by_side[0]:
|
||||
c.send(CTOS_SURRENDER)
|
||||
ok = pump(everyone + [l], lambda: all(match_overs(since(c, marks4)) for c in everyone + [l]), limit=10)
|
||||
check(ok, "%s: side 0 surrendered: MATCH_OVER reached everyone" % label)
|
||||
for c in clients:
|
||||
c.close()
|
||||
stop_dll(dll, thread, label)
|
||||
finally:
|
||||
os.chdir(here)
|
||||
shutil.rmtree(root, ignore_errors=True)
|
||||
|
||||
|
||||
def tag_partner_suite(dll_path, port):
|
||||
print()
|
||||
print("hosting the tag partner cards rooms from %s" % dll_path)
|
||||
tag_partner_room(dll_path, port, "tag, see all", hidden=False)
|
||||
tag_partner_room(dll_path, port + 1, "tag, hidden", hidden=True)
|
||||
|
||||
|
||||
|
||||
# --- TICKET-415: a card the waiting tag partner holds --------------------------------------------
|
||||
# Time Fusion picks a Fusion from the Extra Deck and Summons it at the team's next Standby Phase. By
|
||||
# then the partners have swapped: the Fusion sits in the waiting partner's tag_list_extra, and the core
|
||||
# erased the ACTIVE Extra Deck at its sequence (past the end of an empty one: the Editor crash of
|
||||
# 2026-10-16). The fixed core takes the card out of the list that holds it.
|
||||
PROBE_TIME_FUSION = PROBE_CARD + 700
|
||||
MSG_RETRY, MSG_SELECT_CARD, MSG_SELECT_POSITION, MSG_SPSUMMONING, MSG_NEW_TURN = 1, 15, 19, 62, 40
|
||||
MSG_SELECT_EFFECTYN, MSG_SELECT_YESNO, MSG_SELECT_OPTION, MSG_SELECT_DISFIELD, MSG_SELECT_TRIBUTE = 12, 13, 14, 24, 20
|
||||
TIME_FUSION_LUA = """--Probe Time Fusion (TICKET-415): banish 1 other card from the hand; pick 1 Fusion Monster in the Extra Deck.
|
||||
--During the next Standby Phase of the player who activated this: Special Summon that Fusion Monster.
|
||||
local s,id,o=GetID()
|
||||
function s.initial_effect(c)
|
||||
local e1=Effect.CreateEffect(c)
|
||||
e1:SetType(EFFECT_TYPE_ACTIVATE)
|
||||
e1:SetCode(EVENT_FREE_CHAIN)
|
||||
e1:SetCost(s.cost)
|
||||
e1:SetTarget(s.target)
|
||||
e1:SetOperation(s.activate)
|
||||
c:RegisterEffect(e1)
|
||||
end
|
||||
function s.costfilter(c)
|
||||
return c:IsAbleToRemoveAsCost()
|
||||
end
|
||||
function s.cost(e,tp,eg,ep,ev,re,r,rp,chk)
|
||||
if chk==0 then return Duel.IsExistingMatchingCard(s.costfilter,tp,LOCATION_HAND,0,1,e:GetHandler()) end
|
||||
local g=Duel.SelectMatchingCard(tp,s.costfilter,tp,LOCATION_HAND,0,1,1,e:GetHandler())
|
||||
Duel.Remove(g,POS_FACEUP,REASON_COST)
|
||||
end
|
||||
function s.ffilter(c)
|
||||
return c:IsType(TYPE_FUSION)
|
||||
end
|
||||
function s.target(e,tp,eg,ep,ev,re,r,rp,chk)
|
||||
if chk==0 then return Duel.IsExistingMatchingCard(s.ffilter,tp,LOCATION_EXTRA,0,1,nil) end
|
||||
end
|
||||
function s.activate(e,tp,eg,ep,ev,re,r,rp)
|
||||
local tc=Duel.SelectMatchingCard(tp,s.ffilter,tp,LOCATION_EXTRA,0,1,1,nil):GetFirst()
|
||||
if not tc then return end
|
||||
local e1=Effect.CreateEffect(e:GetHandler())
|
||||
e1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
|
||||
e1:SetCode(EVENT_PHASE+PHASE_STANDBY)
|
||||
e1:SetCountLimit(1)
|
||||
e1:SetLabelObject(tc)
|
||||
e1:SetCondition(s.spcon)
|
||||
e1:SetOperation(s.spop)
|
||||
e1:SetReset(RESET_PHASE+PHASE_STANDBY+RESET_SELF_TURN)
|
||||
Duel.RegisterEffect(e1,tp)
|
||||
end
|
||||
function s.spcon(e,tp,eg,ep,ev,re,r,rp)
|
||||
return Duel.GetTurnPlayer()==tp
|
||||
end
|
||||
function s.spop(e,tp,eg,ep,ev,re,r,rp)
|
||||
local tc=e:GetLabelObject()
|
||||
if tc:IsLocation(LOCATION_EXTRA) then
|
||||
Duel.SpecialSummon(tc,0,tp,tp,true,false,POS_FACEUP)
|
||||
end
|
||||
end
|
||||
"""
|
||||
|
||||
|
||||
def first_free_zone(d):
|
||||
# MSG_SELECT_PLACE / DISFIELD: player, min, u32 flag (a set bit = that zone is NOT available)
|
||||
player = d[1]
|
||||
(flag,) = struct.unpack_from("<I", d, 3)
|
||||
for side in (0, 1):
|
||||
for seq in range(7):
|
||||
if not flag & (1 << (side * 16 + seq)):
|
||||
return bytes([player if side == 0 else 1 - player, 0x04, seq])
|
||||
for seq in range(8):
|
||||
if not flag & (1 << (side * 16 + 8 + seq)):
|
||||
return bytes([player if side == 0 else 1 - player, 0x08, seq])
|
||||
return bytes([player, 0x04, 0])
|
||||
|
||||
|
||||
def tag_across_swap_room(dll_path, port, label):
|
||||
print("== tag card across the swap, %s (TICKET-415: seat 3 picks its Fusion on turn 4; the team's next Standby Phase is seat 2's turn 6, whose Extra Deck is empty)" % label)
|
||||
root = make_workspace()
|
||||
here = os.getcwd()
|
||||
os.chdir(root)
|
||||
try:
|
||||
write_special(root, [])
|
||||
dll, thread = host_dll(dll_path, port, 2)
|
||||
seated = []
|
||||
for i in range(4):
|
||||
c = Client("127.0.0.1", port, "ts-seat%d" % i)
|
||||
c.log = list(c.join())
|
||||
seated.append(c)
|
||||
check([c.seat for c in seated] == [0, 1, 2, 3], "%s: four seats (%r)" % (label, [c.seat for c in seated]))
|
||||
drain_all(seated)
|
||||
decks = {0: [PROBE_CARD] * 40, 1: [PROBE_CARD] * 40, 2: [PROBE_CARD] * 40, 3: [PROBE_TIME_FUSION] * 40 + [PROBE_FUSION]}
|
||||
for c in seated:
|
||||
c.send(CTOS_UPDATE_DECK, deck_bytes(decks[c.seat]))
|
||||
pump(seated, lambda: False, limit=0.8)
|
||||
seated[0].send(CTOS_HS_START)
|
||||
state = {"turn": 0, "activated": False, "retries": 0, "summoned": [], "idle_after_summon": 0, "swap8": None}
|
||||
|
||||
def answer(c, payload):
|
||||
c.send(CTOS_TIME_CONFIRM)
|
||||
c.send(CTOS_RESPONSE, payload)
|
||||
|
||||
def play(until, limit):
|
||||
deadline = time.time() + limit
|
||||
while time.time() < deadline:
|
||||
for c in seated:
|
||||
for pid, d in c.drain(quiet=0.02, limit=0.2):
|
||||
c.log.append((pid, d))
|
||||
if pid == STOC_SELECT_TP:
|
||||
c.send(CTOS_TP_RESULT, bytes([1 if c.seat == 0 else 0])) # side A (seats 0 + 1) goes first
|
||||
continue
|
||||
if pid != 0x01 or not d:
|
||||
continue
|
||||
t = d[0]
|
||||
if t == MSG_NEW_TURN and c.seat == 0:
|
||||
state["turn"] += 1
|
||||
elif t == MSG_TAG_SWAP and c.seat == 2 and d[1] == 1 and state["turn"] == 8:
|
||||
state["swap8"] = d
|
||||
elif t == MSG_SPSUMMONING and c.seat == 2:
|
||||
state["summoned"].append((state["turn"], struct.unpack_from("<I", d, 1)[0]))
|
||||
elif t == MSG_RETRY:
|
||||
state["retries"] += 1
|
||||
elif t == MSG_SELECT_IDLECMD:
|
||||
n = 2
|
||||
for k in range(5):
|
||||
n += 1 + d[n] * 7
|
||||
activatable = d[n]
|
||||
if c.seat == 3 and activatable and not state["activated"]:
|
||||
state["activated"] = state["turn"]
|
||||
answer(c, struct.pack("<i", 5)) # activate the first card: the Spell
|
||||
else:
|
||||
if c.seat == 2 and state["summoned"]:
|
||||
state["idle_after_summon"] += 1
|
||||
answer(c, struct.pack("<i", 7)) # to the End Phase
|
||||
elif t in (MSG_SELECT_CARD, MSG_SELECT_TRIBUTE):
|
||||
answer(c, bytes([1, 0]))
|
||||
elif t == MSG_SELECT_CHAIN:
|
||||
answer(c, struct.pack("<i", -1))
|
||||
elif t in (MSG_SELECT_PLACE, MSG_SELECT_DISFIELD):
|
||||
answer(c, first_free_zone(d))
|
||||
elif t == MSG_SELECT_POSITION:
|
||||
answer(c, struct.pack("<i", next(b for b in (1, 2, 4, 8) if d[6] & b)))
|
||||
elif t in (MSG_SELECT_EFFECTYN, MSG_SELECT_YESNO):
|
||||
answer(c, struct.pack("<i", 1))
|
||||
elif t in (MSG_SELECT_OPTION, MSG_SELECT_BATTLECMD):
|
||||
answer(c, struct.pack("<i", 0 if t == MSG_SELECT_OPTION else 3))
|
||||
if until():
|
||||
return True
|
||||
if any(c.closed for c in seated):
|
||||
return False
|
||||
return until()
|
||||
|
||||
ok = play(lambda: state["turn"] >= 6 and state["idle_after_summon"] >= 1, limit=40)
|
||||
check(state["activated"] == 4, "%s: seat 3 activated the Spell on turn 4, its first turn (turn %s)" % (label, state["activated"]))
|
||||
check(ok, "%s: turn 6 (seat 2's second turn) played on: the engine survived the Standby Phase" % label)
|
||||
check(state["summoned"] == [(6, PROBE_FUSION)], "%s: the Fusion seat 3 picked was Special Summoned in seat 2's Standby Phase of turn 6, out of the waiting partner's Extra Deck (%s)" % (label, state["summoned"]))
|
||||
check(state["retries"] == 0, "%s: no answer was refused (MSG_RETRY x%d)" % (label, state["retries"]))
|
||||
ok = play(lambda: state["swap8"] is not None, limit=20)
|
||||
check(ok and state["swap8"] is not None and state["swap8"][3] == 0, "%s: the swap of turn 8 brings seat 3 back with an empty Extra Deck: the Fusion left the list that held it (%s)" % (label, None if state["swap8"] is None else state["swap8"][3]))
|
||||
check(all(not c.closed for c in seated), "%s: every seat is still connected" % label)
|
||||
marks = marks_of(seated)
|
||||
for c in seated[:2]:
|
||||
c.send(CTOS_SURRENDER)
|
||||
ok = pump(seated, lambda: all(match_overs(since(c, marks)) for c in seated), limit=10)
|
||||
check(ok, "%s: side 0 surrendered: MATCH_OVER reached everyone" % label)
|
||||
for c in seated:
|
||||
c.close()
|
||||
stop_dll(dll, thread, label)
|
||||
finally:
|
||||
os.chdir(here)
|
||||
shutil.rmtree(root, ignore_errors=True)
|
||||
|
||||
|
||||
def tag_across_swap_suite(dll_path, port):
|
||||
print()
|
||||
print("hosting the tag card across the swap room from %s" % dll_path)
|
||||
tag_across_swap_room(dll_path, port, "tag")
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
+44
-2
@@ -205,6 +205,16 @@ void field::remove_card(card* pcard) {
|
||||
if (!check_playerid(pcard->current.controler) || pcard->current.location == 0)
|
||||
return;
|
||||
uint8_t playerid = pcard->current.controler;
|
||||
if(card_vector* tag_list = tag_list_holding(pcard)) { // [YGOL] TICKET-415, see tag_list_holding
|
||||
tag_list->erase(std::find(tag_list->begin(), tag_list->end(), pcard));
|
||||
uint8_t seq = 0;
|
||||
for(auto& tcard : *tag_list)
|
||||
tcard->current.sequence = seq++;
|
||||
if(pcard->current.location == LOCATION_HAND)
|
||||
pcard->set_status(STATUS_TO_HAND_WITHOUT_CONFIRM, FALSE);
|
||||
else if(pcard->current.location == LOCATION_EXTRA && (pcard->data.type & TYPE_PENDULUM) && (pcard->current.position & POS_FACEUP))
|
||||
--player[playerid].tag_extra_p_count;
|
||||
} else
|
||||
switch (pcard->current.location) {
|
||||
case LOCATION_MZONE:
|
||||
player[playerid].list_mzone[pcard->current.sequence] = 0;
|
||||
@@ -259,7 +269,7 @@ void field::move_card(uint8_t playerid, card* pcard, uint8_t location, uint8_t s
|
||||
pcard->sendto_param.position = POS_FACEDOWN_DEFENSE;
|
||||
}
|
||||
if (pcard->current.location) {
|
||||
if (pcard->current.location == location && pcard->current.pzone == !!pzone) {
|
||||
if (pcard->current.location == location && pcard->current.pzone == !!pzone && !tag_list_holding(pcard)) { // [YGOL] TICKET-415
|
||||
if (pcard->current.location == LOCATION_DECK) {
|
||||
if(preplayer == playerid) {
|
||||
pduel->write_buffer8(MSG_MOVE);
|
||||
@@ -1146,6 +1156,32 @@ void field::refresh_player_info(uint8_t playerid) {
|
||||
}
|
||||
player[playerid].used_location = used_flag;
|
||||
}
|
||||
// [YGOL] TICKET-415: the lists of the waiting tag partner (tag_list_main / tag_list_hand / tag_list_extra)
|
||||
// hold cards that still say LOCATION_DECK / HAND / EXTRA with a sequence into THAT list. An effect that
|
||||
// kept a card across the tag swap moves it later (Time Fusion: the Fusion picked from the Extra Deck at
|
||||
// activation, Summoned at the team's next Standby Phase, when the partner's Extra Deck is the active one);
|
||||
// remove_card then erased the ACTIVE list at the card's sequence: past the end of a shorter list (an
|
||||
// empty Extra Deck: the owner's crash) or the wrong card. Such a card leaves the list that holds it.
|
||||
card_vector* field::tag_list_holding(card* pcard) {
|
||||
if(!(core.duel_options & DUEL_TAG_MODE) || !check_playerid(pcard->current.controler))
|
||||
return nullptr;
|
||||
auto& p = player[pcard->current.controler];
|
||||
card_vector* tag_list = nullptr;
|
||||
switch(pcard->current.location) {
|
||||
case LOCATION_DECK:
|
||||
tag_list = &p.tag_list_main;
|
||||
break;
|
||||
case LOCATION_HAND:
|
||||
tag_list = &p.tag_list_hand;
|
||||
break;
|
||||
case LOCATION_EXTRA:
|
||||
tag_list = &p.tag_list_extra;
|
||||
break;
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
return std::find(tag_list->begin(), tag_list->end(), pcard) != tag_list->end() ? tag_list : nullptr;
|
||||
}
|
||||
void field::tag_swap(uint8_t playerid) {
|
||||
//main
|
||||
for(auto& pcard : player[playerid].list_main) {
|
||||
@@ -3704,8 +3740,14 @@ int32_t field::check_spself_from_hand_trigger(const chain& ch) const {
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
// [YGOL] Tag: the first three duelists (1A, 2A, 1B) have no Battle Phase; the fourth is the first who can battle.
|
||||
int32_t field::is_opening_turn_without_bp() {
|
||||
if(core.duel_options & DUEL_ATTACK_FIRST_TURN)
|
||||
return FALSE;
|
||||
return infos.turn_id <= ((core.duel_options & DUEL_TAG_MODE) ? 3 : 1);
|
||||
}
|
||||
int32_t field::is_able_to_enter_bp() {
|
||||
return ((core.duel_options & DUEL_ATTACK_FIRST_TURN) || infos.turn_id != 1)
|
||||
return !is_opening_turn_without_bp()
|
||||
&& infos.phase < PHASE_BATTLE_START
|
||||
&& !is_player_affected_by_effect(infos.turn_player, EFFECT_CANNOT_BP);
|
||||
}
|
||||
@@ -424,6 +424,7 @@ public:
|
||||
void swap_deck_and_grave(uint8_t playerid);
|
||||
void reverse_deck(uint8_t playerid);
|
||||
void refresh_player_info(uint8_t playerid);
|
||||
card_vector* tag_list_holding(card* pcard); // [YGOL] TICKET-415
|
||||
void tag_swap(uint8_t playerid);
|
||||
|
||||
void add_effect(effect* peffect, uint8_t owner_player = PLAYER_NONE);
|
||||
@@ -531,6 +532,7 @@ public:
|
||||
int32_t check_trigger_effect(const chain& ch) const;
|
||||
int32_t check_spself_from_hand_trigger(const chain& ch) const;
|
||||
int32_t is_able_to_enter_bp();
|
||||
int32_t is_opening_turn_without_bp();
|
||||
|
||||
void add_process(uint16_t type, uint16_t step, effect* peffect, group* target, int32_t arg1, int32_t arg2, int32_t arg3 = 0, int32_t arg4 = 0, void* ptr1 = nullptr, void* ptr2 = nullptr);
|
||||
uint32_t process();
|
||||
|
||||
@@ -441,6 +441,34 @@ OCGCORE_API int32_t ygol_preview_attack(intptr_t pduel, uint8_t playerid, uint8_
|
||||
buffer_write<int32_t>(ptr, 0);
|
||||
return 1;
|
||||
}
|
||||
// [YGOL] v1.2.0 (tag partner cards) -- see ocgapi.h. Reads the three tag_list_* vectors the core keeps for the
|
||||
// waiting member; nothing is moved, nothing is written to the duel.
|
||||
OCGCORE_API int32_t ygol_query_tag_cards(intptr_t pduel, uint8_t playerid, uint8_t* out) {
|
||||
duel* pd = (duel*)pduel;
|
||||
if(!pd || !out || !duel_set.count(pd) || !pd->game_field)
|
||||
return 0;
|
||||
if(!check_playerid(playerid) || !(pd->game_field->core.duel_options & DUEL_TAG_MODE))
|
||||
return 0;
|
||||
const auto& p = pd->game_field->player[playerid];
|
||||
std::vector<uint32_t> deck;
|
||||
deck.reserve(p.tag_list_main.size());
|
||||
for(auto& pcard : p.tag_list_main)
|
||||
deck.push_back(pcard->data.code);
|
||||
std::sort(deck.begin(), deck.end());
|
||||
byte* ptr = out;
|
||||
buffer_write<uint8_t>(ptr, 1);
|
||||
buffer_write<uint8_t>(ptr, (uint8_t)p.tag_list_hand.size());
|
||||
buffer_write<uint8_t>(ptr, (uint8_t)p.tag_list_extra.size());
|
||||
buffer_write<uint8_t>(ptr, 0);
|
||||
buffer_write<uint16_t>(ptr, (uint16_t)deck.size());
|
||||
for(auto& pcard : p.tag_list_hand)
|
||||
buffer_write<uint32_t>(ptr, pcard->data.code | (pcard->is_position(POS_FACEUP) ? 0x80000000 : 0));
|
||||
for(auto& pcard : p.tag_list_extra)
|
||||
buffer_write<uint32_t>(ptr, pcard->data.code | (pcard->is_position(POS_FACEUP) ? 0x80000000 : 0));
|
||||
for(auto code : deck)
|
||||
buffer_write<uint32_t>(ptr, code);
|
||||
return (int32_t)(ptr - out);
|
||||
}
|
||||
OCGCORE_API int32_t get_registry_value(intptr_t pduel, const char* key, byte* out_buf) {
|
||||
if (!pduel || !key || !out_buf) return -1;
|
||||
|
||||
|
||||
@@ -80,6 +80,13 @@ OCGCORE_API byte* default_script_reader(const char* script_name, int* len);
|
||||
// the duel is byte-identical afterwards (proposal 43).
|
||||
OCGCORE_API int32_t ygol_preview_attack(intptr_t pduel, uint8_t playerid, uint8_t location, uint8_t sequence, uint8_t target_location, uint8_t target_sequence, uint8_t* out);
|
||||
|
||||
// [YGOL] v1.2.0 (tag partner cards, TICKET-405): the waiting tag partner's cards of playerid's side, read
|
||||
// only. out: version (1), hand count, extra count, one pad byte, uint16 deck count, then the uint32 hand
|
||||
// codes, the uint32 extra codes (bit 31 = face-up, like MSG_TAG_SWAP) and the uint32 deck codes sorted
|
||||
// ascending (the order stays secret). Returns the byte length, 0 refused (bad pointer, bad player, not a
|
||||
// tag duel); a refusal writes nothing. The duel is byte-identical afterwards (proposal 33 Rule 11).
|
||||
OCGCORE_API int32_t ygol_query_tag_cards(intptr_t pduel, uint8_t playerid, uint8_t* out);
|
||||
|
||||
// koishi specific
|
||||
OCGCORE_API int32_t get_registry_value(intptr_t pduel, const char* key, byte* out_buf);
|
||||
OCGCORE_API void set_registry_value(intptr_t pduel, const char* key, const char* value);
|
||||
|
||||
+1
-1
@@ -2078,7 +2078,7 @@ int32_t field::process_idle_command(uint16_t step) {
|
||||
chain newchain;
|
||||
core.to_bp = TRUE;
|
||||
core.to_ep = TRUE;
|
||||
if((!(core.duel_options & DUEL_ATTACK_FIRST_TURN) && infos.turn_id == 1) || infos.phase == PHASE_MAIN2 || is_player_affected_by_effect(infos.turn_player, EFFECT_CANNOT_BP))
|
||||
if(is_opening_turn_without_bp() || infos.phase == PHASE_MAIN2 || is_player_affected_by_effect(infos.turn_player, EFFECT_CANNOT_BP))
|
||||
core.to_bp = FALSE;
|
||||
if(infos.phase == PHASE_MAIN1) {
|
||||
for(auto& pcard : player[infos.turn_player].list_mzone) {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
#include <algorithm> // [YGOL] std::find (attack preview); MSVC includes it transitively, GCC does not
|
||||
#include <cstdlib> // [YGOL] std::strtol (life points per side)
|
||||
#include <event2/event.h>
|
||||
#include <event2/listener.h>
|
||||
#include <event2/bufferevent.h>
|
||||
@@ -786,6 +787,19 @@ bool SpectatorsSeeAll() { // YGOL spectators see all
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
int32_t SideBStartLp(int32_t fallback) { // YGOL life points per side
|
||||
static const char key[] = "ygol.side.b.lp=";
|
||||
constexpr size_t key_len = sizeof(key) - 1;
|
||||
for(const auto& pair : setup_pairs) {
|
||||
if(pair.compare(0, key_len, key) != 0)
|
||||
continue;
|
||||
char* end = nullptr;
|
||||
const long value = std::strtol(pair.c_str() + key_len, &end, 10);
|
||||
if(end && *end == '\0' && value > 0 && value <= 0x7FFFFFFFL)
|
||||
return (int32_t)value;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
size_t WriteSetupPairsBlock(unsigned char* dst) {
|
||||
auto pdst = dst;
|
||||
BufferIO::Write<uint16_t>(pdst, (uint16_t)setup_pairs.size());
|
||||
|
||||
@@ -224,7 +224,7 @@ static_assert(sizeof(CTOS_Appearance) == 352, "size mismatch: CTOS_Appearance");
|
||||
check_trivially_copyable(CTOS_Dialogue);
|
||||
static_assert(sizeof(CTOS_Dialogue) == 204, "size mismatch: CTOS_Dialogue");
|
||||
constexpr int SIZE_STOC_FEATURE = sizeof(uint16_t) + sizeof(CTOS_Appearance);
|
||||
constexpr uint16_t FEATURE_PROTOCOL = 8; // YGOL host seats: 1 -> 2; YGOL seat state: 2 -> 3; YGOL lobby after match: 3 -> 4; YGOL coin toss: 4 -> 5; YGOL deck lists: 5 -> 6; YGOL profile: 6 -> 7; YGOL attack preview: 7 -> 8
|
||||
constexpr uint16_t FEATURE_PROTOCOL = 9; // YGOL host seats: 1 -> 2; YGOL seat state: 2 -> 3; YGOL lobby after match: 3 -> 4; YGOL coin toss: 4 -> 5; YGOL deck lists: 5 -> 6; YGOL profile: 6 -> 7; YGOL attack preview: 7 -> 8; YGOL tag partner cards: 8 -> 9
|
||||
constexpr uint32_t FEATURE_APPEARANCE = 0x1;
|
||||
constexpr uint32_t FEATURE_DIALOGUE = 0x2;
|
||||
constexpr uint16_t FEATURE_SENDER_SERVER = 0xff;
|
||||
@@ -234,6 +234,8 @@ constexpr size_t SETUP_PAIRS_MAX = 64;
|
||||
constexpr size_t SETUP_PAIR_MAX_LEN = 512;
|
||||
constexpr size_t SETUP_PAIRS_BLOCK_MAX = sizeof(uint16_t) + SETUP_PAIRS_MAX * (sizeof(uint16_t) + SETUP_PAIR_MAX_LEN);
|
||||
constexpr uint32_t REPLAY_YGOL_SETUP_PAIRS = 0x40000000; // replay flag: uint32_t length + the block, before the names
|
||||
// YGOL life points per side: the setup pair ygol.side.b.lp gives seat side B (seat 1; Tag seats 2 and 3) its own start LP
|
||||
constexpr uint32_t REPLAY_YGOL_SIDE_LP = 0x20000000; // replay flag: int32_t lp[0], int32_t lp[1] in duel player order, after opt
|
||||
extern std::vector<std::string> setup_pairs;
|
||||
bool IsSetupPairToken(const char* token);
|
||||
bool AddSetupPair(const char* token);
|
||||
@@ -462,6 +464,9 @@ constexpr uint8_t ATTACK_PREVIEW_VERSION = 1;
|
||||
constexpr uint8_t ATTACK_PREVIEW_DIRECT = 0xFF;
|
||||
constexpr int ATTACK_PREVIEW_MAX_PAIRS = 64;
|
||||
constexpr int ATTACK_PREVIEW_ANSWER_SIZE = 24; // the ygol_preview_attack answer, echoed after the pair
|
||||
// YGOL tag partner cards: the waiting teammate's hand, Extra Deck and deck (ygol_query_tag_cards), sent to that side's two seats only; 0x800 and 0x1000 are reserved by proposals 44 and 45
|
||||
constexpr uint32_t FEATURE_TAG_PARTNER_CARDS = 0x2000;
|
||||
constexpr uint8_t TAG_PARTNER_CARDS_VERSION = 1;
|
||||
// the one-use bootstrap secret of a replacement server: a host-string token parsed apart from the ygol.* pairs, never stored anywhere else
|
||||
extern uint8_t bootstrap_secret[16];
|
||||
extern bool bootstrap_closed;
|
||||
@@ -469,6 +474,7 @@ bool IsBootstrapToken(const char* token);
|
||||
void SetBootstrapSecret(const char* token);
|
||||
bool WatchersAllowed();
|
||||
bool SpectatorsSeeAll(); // YGOL spectators see all
|
||||
int32_t SideBStartLp(int32_t fallback); // YGOL life points per side: ygol.side.b.lp, else fallback
|
||||
inline bool IsZeroId(const uint8_t* id) {
|
||||
for(int i = 0; i < 16; ++i)
|
||||
if(id[i])
|
||||
@@ -666,6 +672,7 @@ inline bool IsFeatureMessage(unsigned char pktType) {
|
||||
#define STOC_DECK_LIST 0x5C // STOC_DeckList + uint32_t codes[count], no sender stamp (YGOL deck lists)
|
||||
#define STOC_PROFILE 0x5D // uint16_t + CTOS_Profile (YGOL profile)
|
||||
#define STOC_ATTACK_PREVIEW 0x5E // uint8_t version, uint8_t count, count x (CTOS_AttackPreviewPair + 24-byte answer), no sender stamp, to the asker only (YGOL attack preview)
|
||||
#define STOC_TAG_PARTNER_CARDS 0x5F // uint8_t side + the ygol_query_tag_cards bytes, no sender stamp, to that side's two seats only (YGOL tag partner cards)
|
||||
|
||||
// STOC_GAME_MSG header
|
||||
#define MSG_WAITING 3
|
||||
|
||||
@@ -98,7 +98,7 @@ void SingleDuel::AttackPreview(DuelPlayer* dp, unsigned char* pdata, int len) {
|
||||
void SingleDuel::SendServerCapability(DuelPlayer* dp) {
|
||||
CTOS_Capability cap;
|
||||
cap.protocol = FEATURE_PROTOCOL;
|
||||
cap.flags = FEATURE_APPEARANCE | FEATURE_DIALOGUE | FEATURE_SETUP_PAIRS | FEATURE_SEAT_PLAN | FEATURE_RULES_RESTART | FEATURE_SEAT_STATE | FEATURE_LOBBY_AFTER_MATCH | FEATURE_COIN_TOSS | FEATURE_DECK_LIST | FEATURE_PROFILE | FEATURE_ATTACK_PREVIEW; // YGOL setup pairs + host seats + rules restart + seat state + lobby after match + coin toss + deck lists + profile + attack preview
|
||||
cap.flags = FEATURE_APPEARANCE | FEATURE_DIALOGUE | FEATURE_SETUP_PAIRS | FEATURE_SEAT_PLAN | FEATURE_RULES_RESTART | FEATURE_SEAT_STATE | FEATURE_LOBBY_AFTER_MATCH | FEATURE_COIN_TOSS | FEATURE_DECK_LIST | FEATURE_PROFILE | FEATURE_ATTACK_PREVIEW | FEATURE_TAG_PARTNER_CARDS; // YGOL setup pairs + host seats + rules restart + seat state + lobby after match + coin toss + deck lists + profile + attack preview + tag partner cards
|
||||
unsigned char buf[SIZE_STOC_FEATURE];
|
||||
const auto size = NetServer::CreateStampedPacket((unsigned char*)&cap, sizeof cap, buf, FEATURE_SENDER_SERVER);
|
||||
NetServer::SendBufferToPlayer(dp, STOC_CAPABILITY, buf, size);
|
||||
@@ -1222,6 +1222,9 @@ void SingleDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
|
||||
swapped = true;
|
||||
}
|
||||
dp->state = CTOS_RESPONSE;
|
||||
const int32_t side_b_lp = SideBStartLp(host_info.start_lp); // YGOL life points per side: seat side B keeps its LP through the swap
|
||||
player_lp[0] = swapped ? side_b_lp : host_info.start_lp;
|
||||
player_lp[1] = swapped ? host_info.start_lp : side_b_lp;
|
||||
std::random_device rd;
|
||||
ExtendedReplayHeader rh;
|
||||
rh.base.id = REPLAY_ID_YRP2;
|
||||
@@ -1238,6 +1241,8 @@ void SingleDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
|
||||
mtrandom rnd(rh.seed_sequence, SEED_COUNT);
|
||||
if(!setup_pairs.empty()) // YGOL setup pairs
|
||||
rh.base.flag |= REPLAY_YGOL_SETUP_PAIRS;
|
||||
if(player_lp[0] != player_lp[1]) // YGOL life points per side
|
||||
rh.base.flag |= REPLAY_YGOL_SIDE_LP;
|
||||
last_replay.BeginRecord();
|
||||
last_replay.WriteHeader(rh);
|
||||
if(!setup_pairs.empty()) {
|
||||
@@ -1285,8 +1290,8 @@ void SingleDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
|
||||
const auto eq = pair.find('=');
|
||||
set_registry_value(pduel, pair.substr(0, eq).c_str(), pair.c_str() + eq + 1);
|
||||
}
|
||||
set_player_info(pduel, 0, host_info.start_lp, host_info.start_hand, host_info.draw_count);
|
||||
set_player_info(pduel, 1, host_info.start_lp, host_info.start_hand, host_info.draw_count);
|
||||
set_player_info(pduel, 0, player_lp[0], host_info.start_hand, host_info.draw_count); // YGOL life points per side
|
||||
set_player_info(pduel, 1, player_lp[1], host_info.start_hand, host_info.draw_count);
|
||||
preload_script(pduel, "./script/patches/entry.lua");
|
||||
preload_script(pduel, "./script/special.lua");
|
||||
preload_script(pduel, "./script/init.lua");
|
||||
@@ -1298,6 +1303,10 @@ void SingleDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
|
||||
last_replay.WriteInt32(host_info.start_hand, false);
|
||||
last_replay.WriteInt32(host_info.draw_count, false);
|
||||
last_replay.WriteInt32(opt, false);
|
||||
if(player_lp[0] != player_lp[1]) { // YGOL life points per side: REPLAY_YGOL_SIDE_LP
|
||||
last_replay.WriteInt32(player_lp[0], false);
|
||||
last_replay.WriteInt32(player_lp[1], false);
|
||||
}
|
||||
last_replay.Flush();
|
||||
auto load = [&](const std::vector<const CardDataC*>& deck_container, uint8_t p, uint8_t location) {
|
||||
last_replay.WriteInt32(deck_container.size(), false);
|
||||
@@ -1334,8 +1343,8 @@ void SingleDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
|
||||
BufferIO::Write<uint8_t>(pbuf, MSG_START);
|
||||
BufferIO::Write<uint8_t>(pbuf, 0);
|
||||
BufferIO::Write<uint8_t>(pbuf, host_info.duel_rule);
|
||||
BufferIO::Write<int32_t>(pbuf, host_info.start_lp);
|
||||
BufferIO::Write<int32_t>(pbuf, host_info.start_lp);
|
||||
BufferIO::Write<int32_t>(pbuf, player_lp[0]); // YGOL life points per side
|
||||
BufferIO::Write<int32_t>(pbuf, player_lp[1]);
|
||||
BufferIO::Write<uint16_t>(pbuf, query_field_count(pduel, 0, LOCATION_DECK));
|
||||
BufferIO::Write<uint16_t>(pbuf, query_field_count(pduel, 0, LOCATION_EXTRA));
|
||||
BufferIO::Write<uint16_t>(pbuf, query_field_count(pduel, 1, LOCATION_DECK));
|
||||
@@ -2700,8 +2709,8 @@ void SingleDuel::RequestField(DuelPlayer* dp) {
|
||||
BufferIO::Write<uint8_t>(pbuf, MSG_START);
|
||||
BufferIO::Write<uint8_t>(pbuf, watcher ? ((players[0] == pplayer[0]) ? 0x10 : 0x11) : player); // [YGOL] late watcher: the observer byte lobby watchers get
|
||||
BufferIO::Write<uint8_t>(pbuf, host_info.duel_rule);
|
||||
BufferIO::Write<int32_t>(pbuf, host_info.start_lp);
|
||||
BufferIO::Write<int32_t>(pbuf, host_info.start_lp);
|
||||
BufferIO::Write<int32_t>(pbuf, player_lp[0]); // YGOL life points per side
|
||||
BufferIO::Write<int32_t>(pbuf, player_lp[1]);
|
||||
BufferIO::Write<uint16_t>(pbuf, 0);
|
||||
BufferIO::Write<uint16_t>(pbuf, 0);
|
||||
BufferIO::Write<uint16_t>(pbuf, 0);
|
||||
|
||||
@@ -147,6 +147,7 @@ protected:
|
||||
bool ygol_started{};
|
||||
DuelPlayer* players[2]{};
|
||||
DuelPlayer* pplayer[2]{};
|
||||
int32_t player_lp[2]{}; // YGOL life points per side: start LP in duel player order, set at every duel start
|
||||
bool ready[2]{};
|
||||
Deck pdeck[2];
|
||||
int deck_error[2]{};
|
||||
|
||||
@@ -96,7 +96,7 @@ void TagDuel::AttackPreview(DuelPlayer* dp, unsigned char* pdata, int len) {
|
||||
void TagDuel::SendServerCapability(DuelPlayer* dp) {
|
||||
CTOS_Capability cap;
|
||||
cap.protocol = FEATURE_PROTOCOL;
|
||||
cap.flags = FEATURE_APPEARANCE | FEATURE_DIALOGUE | FEATURE_SETUP_PAIRS | FEATURE_SEAT_PLAN | FEATURE_RULES_RESTART | FEATURE_SEAT_STATE | FEATURE_LOBBY_AFTER_MATCH | FEATURE_COIN_TOSS | FEATURE_DECK_LIST | FEATURE_PROFILE | FEATURE_ATTACK_PREVIEW; // YGOL setup pairs + host seats + rules restart + seat state + lobby after match + coin toss + deck lists + profile + attack preview
|
||||
cap.flags = FEATURE_APPEARANCE | FEATURE_DIALOGUE | FEATURE_SETUP_PAIRS | FEATURE_SEAT_PLAN | FEATURE_RULES_RESTART | FEATURE_SEAT_STATE | FEATURE_LOBBY_AFTER_MATCH | FEATURE_COIN_TOSS | FEATURE_DECK_LIST | FEATURE_PROFILE | FEATURE_ATTACK_PREVIEW | FEATURE_TAG_PARTNER_CARDS; // YGOL setup pairs + host seats + rules restart + seat state + lobby after match + coin toss + deck lists + profile + attack preview + tag partner cards
|
||||
unsigned char buf[SIZE_STOC_FEATURE];
|
||||
const auto size = NetServer::CreateStampedPacket((unsigned char*)&cap, sizeof cap, buf, FEATURE_SENDER_SERVER);
|
||||
NetServer::SendBufferToPlayer(dp, STOC_CAPABILITY, buf, size);
|
||||
@@ -1214,6 +1214,9 @@ void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
|
||||
std::swap(pdeck[1], pdeck[3]);
|
||||
swapped = true;
|
||||
}
|
||||
const int32_t side_b_lp = SideBStartLp(host_info.start_lp); // YGOL life points per side: seat side B keeps its LP through the swap
|
||||
player_lp[0] = swapped ? side_b_lp : host_info.start_lp;
|
||||
player_lp[1] = swapped ? host_info.start_lp : side_b_lp;
|
||||
turn_count = 0;
|
||||
cur_player[0] = players[0];
|
||||
cur_player[1] = players[2]; // YGOL first seat holds the hand: the engine skips the swap on a team's first turn
|
||||
@@ -1234,6 +1237,8 @@ void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
|
||||
mtrandom rnd(rh.seed_sequence, SEED_COUNT);
|
||||
if(!setup_pairs.empty()) // YGOL setup pairs
|
||||
rh.base.flag |= REPLAY_YGOL_SETUP_PAIRS;
|
||||
if(player_lp[0] != player_lp[1]) // YGOL life points per side
|
||||
rh.base.flag |= REPLAY_YGOL_SIDE_LP;
|
||||
last_replay.BeginRecord();
|
||||
last_replay.WriteHeader(rh);
|
||||
if(!setup_pairs.empty()) {
|
||||
@@ -1282,8 +1287,8 @@ void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
|
||||
const auto eq = pair.find('=');
|
||||
set_registry_value(pduel, pair.substr(0, eq).c_str(), pair.c_str() + eq + 1);
|
||||
}
|
||||
set_player_info(pduel, 0, host_info.start_lp, host_info.start_hand, host_info.draw_count);
|
||||
set_player_info(pduel, 1, host_info.start_lp, host_info.start_hand, host_info.draw_count);
|
||||
set_player_info(pduel, 0, player_lp[0], host_info.start_hand, host_info.draw_count); // YGOL life points per side
|
||||
set_player_info(pduel, 1, player_lp[1], host_info.start_hand, host_info.draw_count);
|
||||
preload_script(pduel, "./script/patches/entry.lua");
|
||||
preload_script(pduel, "./script/special.lua");
|
||||
preload_script(pduel, "./script/init.lua");
|
||||
@@ -1296,6 +1301,10 @@ void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
|
||||
last_replay.WriteInt32(host_info.start_hand, false);
|
||||
last_replay.WriteInt32(host_info.draw_count, false);
|
||||
last_replay.WriteInt32(opt, false);
|
||||
if(player_lp[0] != player_lp[1]) { // YGOL life points per side: REPLAY_YGOL_SIDE_LP
|
||||
last_replay.WriteInt32(player_lp[0], false);
|
||||
last_replay.WriteInt32(player_lp[1], false);
|
||||
}
|
||||
last_replay.Flush();
|
||||
auto load_single = [&](const std::vector<const CardDataC*>& deck_container, uint8_t p, uint8_t location) {
|
||||
last_replay.WriteInt32(deck_container.size(), false);
|
||||
@@ -1347,8 +1356,8 @@ void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
|
||||
BufferIO::Write<uint8_t>(pbuf, MSG_START);
|
||||
BufferIO::Write<uint8_t>(pbuf, 0);
|
||||
BufferIO::Write<uint8_t>(pbuf, host_info.duel_rule);
|
||||
BufferIO::Write<int32_t>(pbuf, host_info.start_lp);
|
||||
BufferIO::Write<int32_t>(pbuf, host_info.start_lp);
|
||||
BufferIO::Write<int32_t>(pbuf, player_lp[0]); // YGOL life points per side
|
||||
BufferIO::Write<int32_t>(pbuf, player_lp[1]);
|
||||
BufferIO::Write<uint16_t>(pbuf, query_field_count(pduel, 0, LOCATION_DECK));
|
||||
BufferIO::Write<uint16_t>(pbuf, query_field_count(pduel, 0, LOCATION_EXTRA));
|
||||
BufferIO::Write<uint16_t>(pbuf, query_field_count(pduel, 1, LOCATION_DECK));
|
||||
@@ -1375,6 +1384,8 @@ void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
|
||||
RefreshExtra(0);
|
||||
RefreshExtra(1);
|
||||
start_duel(pduel, opt);
|
||||
SendTagPartnerCards(0); // YGOL tag partner cards: the waiting members' opening hands
|
||||
SendTagPartnerCards(1);
|
||||
if(host_info.time_limit) {
|
||||
time_elapsed = 0;
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
@@ -2722,6 +2733,7 @@ int TagDuel::Analyze(unsigned char* msgbuffer, unsigned int len) {
|
||||
RefreshSzone(1, 0x681fff, 0);
|
||||
RefreshHand(0, 0x781fff, 0);
|
||||
RefreshHand(1, 0x781fff, 0);
|
||||
SendTagPartnerCards(player); // YGOL tag partner cards: the member that just left is the waiting one now
|
||||
break;
|
||||
}
|
||||
case MSG_MATCH_KILL: {
|
||||
@@ -2849,8 +2861,8 @@ void TagDuel::RequestField(DuelPlayer* dp) {
|
||||
BufferIO::Write<uint8_t>(pbuf, MSG_START);
|
||||
BufferIO::Write<uint8_t>(pbuf, watcher ? ((players[0] == pplayer[0]) ? 0x10 : 0x11) : player); // [YGOL] late watcher: the observer byte lobby watchers get
|
||||
BufferIO::Write<uint8_t>(pbuf, host_info.duel_rule);
|
||||
BufferIO::Write<int32_t>(pbuf, host_info.start_lp);
|
||||
BufferIO::Write<int32_t>(pbuf, host_info.start_lp);
|
||||
BufferIO::Write<int32_t>(pbuf, player_lp[0]); // YGOL life points per side
|
||||
BufferIO::Write<int32_t>(pbuf, player_lp[1]);
|
||||
BufferIO::Write<uint16_t>(pbuf, 0);
|
||||
BufferIO::Write<uint16_t>(pbuf, 0);
|
||||
BufferIO::Write<uint16_t>(pbuf, 0);
|
||||
@@ -2892,17 +2904,21 @@ void TagDuel::RequestField(DuelPlayer* dp) {
|
||||
|
||||
// YGOL deck lists: the snapshot carries the lists this connection may see
|
||||
if(watcher) {
|
||||
if(SpectatorsSeeAll())
|
||||
if(SpectatorsSeeAll()) {
|
||||
for(int i = 0; i < 2; ++i)
|
||||
for(uint8_t kind = DECK_LIST_ORDERED; kind <= DECK_LIST_SUBMITTED; ++kind) {
|
||||
std::vector<uint32_t> codes;
|
||||
if(BuildDeckList(i, kind, codes))
|
||||
SendDeckList(dp, i, kind, codes);
|
||||
}
|
||||
SendTagPartnerCards(0, dp); // YGOL tag partner cards: a watcher that sees all gets both sides (TICKET-412)
|
||||
SendTagPartnerCards(1, dp);
|
||||
}
|
||||
} else {
|
||||
std::vector<uint32_t> codes;
|
||||
if(BuildDeckList(player, DECK_LIST_SORTED, codes))
|
||||
SendDeckList(dp, player, DECK_LIST_SORTED, codes);
|
||||
SendTagPartnerCards(player, dp); // YGOL tag partner cards: a seat's field resync carries its side's waiting cards
|
||||
}
|
||||
|
||||
uint8_t query_buffer[SIZE_QUERY_BUFFER];
|
||||
@@ -3032,6 +3048,28 @@ void TagDuel::FlushDeckLists() {
|
||||
}
|
||||
}
|
||||
}
|
||||
// YGOL tag partner cards: STOC_TAG_PARTNER_CARDS 0x5F = uint8_t side + the ygol_query_tag_cards bytes, to that side's two
|
||||
// seats (never the other team) and, when spectators see all, to every observer: after start_duel, after every
|
||||
// MSG_TAG_SWAP, in a seat's field resync (its side) and in an observer's resync / late-watcher snapshot (both sides).
|
||||
void TagDuel::SendTagPartnerCards(int side, DuelPlayer* dp) {
|
||||
if(!pduel)
|
||||
return;
|
||||
unsigned char buf[1 + 6 + (2 * UINT8_MAX + MAINC_MAX) * sizeof(uint32_t)];
|
||||
buf[0] = (uint8_t)side;
|
||||
const int len = ygol_query_tag_cards(pduel, (uint8_t)side, buf + 1);
|
||||
if(len <= 0)
|
||||
return;
|
||||
if(dp) {
|
||||
NetServer::SendBufferToPlayer(dp, STOC_TAG_PARTNER_CARDS, buf, 1 + len);
|
||||
return;
|
||||
}
|
||||
for(int seat = side * 2; seat < side * 2 + 2; ++seat)
|
||||
if(players[seat])
|
||||
NetServer::SendBufferToPlayer(players[seat], STOC_TAG_PARTNER_CARDS, buf, 1 + len);
|
||||
if(SpectatorsSeeAll()) // YGOL spectators see all: every observer gets both sides (TICKET-412)
|
||||
for(auto oit = observers.begin(); oit != observers.end(); ++oit)
|
||||
NetServer::SendBufferToPlayer(*oit, STOC_TAG_PARTNER_CARDS, buf, 1 + len);
|
||||
}
|
||||
void TagDuel::TimeConfirm(DuelPlayer* dp) {
|
||||
if(host_info.time_limit == 0)
|
||||
return;
|
||||
|
||||
@@ -99,6 +99,7 @@ protected:
|
||||
bool has_profile[4]{};
|
||||
CTOS_Profile profile[4]{};
|
||||
std::vector<uint16_t> preview_attackers; // YGOL attack preview: location << 8 | sequence of every attacker the open battle prompt lists
|
||||
void SendTagPartnerCards(int side, DuelPlayer* dp = nullptr); // YGOL tag partner cards: STOC 0x5F to the side's two seats (+ every observer when they see all), or to dp alone
|
||||
// YGOL coin toss
|
||||
void BeginChoose(int chooser, uint8_t face);
|
||||
int choose_seat{};
|
||||
@@ -150,6 +151,7 @@ protected:
|
||||
bool ygol_started{};
|
||||
DuelPlayer* players[4]{};
|
||||
DuelPlayer* pplayer[4]{};
|
||||
int32_t player_lp[2]{}; // YGOL life points per side: start LP in duel player order, set at every duel start
|
||||
DuelPlayer* cur_player[2]{};
|
||||
std::set<DuelPlayer*> observers;
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
|
||||
Reference in new issue
Block a user