14 Commits
Author SHA1 Message Date
donnyandClaude Opus 5.5 4cd908d7af contract: Tag shared Extra Deck rows, changelog v1.6.0, probe suite (TICKET-433)
Release / release (push) Successful in 4s
Release / attach-windows (push) Successful in 1s
Release / linux (push) Successful in 1m19s
Release / windows (push) Successful in 41s
Release / android (push) Successful in 52s
The suite plays a pair-present and a pair-absent Tag room: a Summon of the
waiting partner's monster, the partner value across a move, and the replay
played back through the library. The contract states that bit 0x100000 stays
unused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 00:54:35 -07:00
donnyandClaude Opus 5.5 c0dfa8ef19 binding: FeatureFlags.TagSharedExtra, protocol 11 (TICKET-433, v1.6.0)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 00:54:35 -07:00
donnyandClaude Opus 5.5 fa14698115 server: ygol.tag.extra=shared, FEATURE_TAG_SHARED_EXTRA 0x4000, protocol 11 (TICKET-433, v1.6.0)
The fourth server-read pair. TagDuel sets the option in opt, sends the sum of
both partners' Extra Decks in the opening MSG_START, runs the opening
RefreshExtra after start_duel, and adds QUERY_TAG_MEMBER in RefreshExtra. A Tag
room refuses a joiner without the bit; a Single room keeps it. Without the pair
every stream is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 00:54:35 -07:00
donnyandClaude Opus 5.5 8a73120dbb core: a Tag team can share one Extra Deck, each card keeps its partner (TICKET-433, v1.6.0)
Option DUEL_TAG_SHARED_EXTRA 0x200: start_duel moves tag_list_extra into
list_extra and renumbers, for both teams; tag_swap skips its Extra block.
card::tag_member is 0 from new_card and 1 from new_tag_card. QUERY_TAG_MEMBER
0x1000000 is written last in get_infos. Bit 0x100000 stays unused: old flags
(0xf81fff, 0x181fff, 0xFFFFFF) set it with no value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 00:54:34 -07:00
donnyandClaude Fable 5.1 c2eca90644 server: FEATURE_TAG_TWO_FIELDS 0x1000, protocol 10, a Tag room refuses a joiner without it (TICKET-384, v1.5.0)
Release / release (push) Successful in 3s
Release / attach-windows (push) Successful in 0s
Release / linux (push) Successful in 1m27s
Release / windows (push) Successful in 36s
Release / android (push) Successful in 48s
Single and Tag rooms advertise the bit; TagDuel::Capability answers a client whose
capability lacks it with ERRMSG_VERERROR and closes the connection. Binding:
FeatureFlags.TagTwoFields (in All), Capability.ProtocolVersion 10, tests pinned.
Probe: the tag two Field slots rooms (placement on turns 1, 3 and 5 with the core's
own view reported by the Probe Field's script, the Tag refusal, the Single room that
keeps an old client); the capability pins move to 10 / 0x37FF. Contract: the 0x1000
row, the v1.5.0 behaviour row, the Lua note; CHANGELOG v1.5.0.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-24 18:35:21 -07:00
donnyandClaude Fable 5.1 bcd19c9cd0 core: a Tag team on Master Rule 4/5 has a Field slot per partner (TICKET-384, v1.5.0)
Proposal 45. field::has_two_fields() (DUEL_TAG_MODE on Master Rule 4 or 5) gives
each team Spell/Trap sequence 5 for the partner who plays the team's first turn and
6 for the other; player_info::tag_partner flips in tag_swap and get_szone_size is 7
there. A Field Spell lands in the playing partner's slot (get_fzone_landing) and
replaces only that card; a control change takes the free slot when the playing
partner's is taken; a Set offers only the landing slot's bit. LOCATION_FZONE covers
both slots in card_state::is_location, filter_matching_card, filter_field_card,
is_location_useable and Duel.IsEnvironment; get_field_card(p, LOCATION_FZONE, 0) is
the playing partner's field, else the other, and 1 the remaining one. Singles, Match
and Master Rule 3 (slot 6 = a Pendulum Zone) are unchanged.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-24 18:35:20 -07:00
donnyandClaude Opus 5.5 10ade7fc41 server: tag partner cards are sent again whenever they change (TICKET-424, v1.4.2)
Release / release (push) Successful in 4s
Release / windows (push) Successful in 37s
Release / linux (push) Successful in 1m18s
Release / android (push) Successful in 42s
Release / attach-windows (push) Successful in 1s
After every engine batch, beside FlushDeckLists, TagDuel::FlushTagPartnerCards
queries ygol_query_tag_cards per side and broadcasts STOC_TAG_PARTNER_CARDS
0x5F when the bytes differ from the last broadcast for that side. Every
broadcast (start, swap, change) records its bytes, so a swap is never sent
twice; a resync to one player does not record. Same id and payload, no new
capability bit, protocol 9. Probe: the TICKET-415 room checks that the Summon
out of the waiting partner's Extra Deck gives side 1's seats exactly one
fresh 0x5F with an empty Extra Deck, and the other team none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 16:07:21 -07:00
donnyandClaude Fable 5.1 5286cb2bfd core: a card the waiting tag partner holds leaves its own list (TICKET-415, v1.4.1)
Release / windows (push) Successful in 38s
Release / linux (push) Successful in 1m25s
Release / android (push) Successful in 48s
Release / release (push) Successful in 6s
Release / attach-windows (push) Successful in 1s
The Editor crashed in a Tag duel at a turn change: field::remove_card
erased list_extra past its end (memcpy off the vector) from move_to_field.
Reproduced outside Unity with the four real decks: Zane's Time Fusion
(810000954) picks a Fusion from the Extra Deck on his turn and Summons it
"during your next Standby Phase"; by then the partners have swapped, the
Fusion sits in tag_list_extra (still LOCATION_EXTRA, sequence into THAT
list), and remove_card erased the ACTIVE Extra Deck at that sequence:
Adrian's is empty, so the erase ran past the end. With a longer active
list it silently dropped the wrong card. The core is upstream's here; the
fork's swap order (core patch 0015) only decides which turn it lands on.

- field::tag_list_holding(card*): the tag_list_main / hand / extra of the
  card's controller that holds it, else null (Tag duels only).
- remove_card: such a card is erased from that list, the list's sequences
  are renumbered, STATUS_TO_HAND_WITHOUT_CONFIRM and tag_extra_p_count are
  kept honest; move_card never treats it as a same-location reorder, so
  it goes through remove_card + add_card like any other move.
- Probe: tag_across_swap_suite hosts a Tag room where seat 3's "Probe Time
  Fusion" (a workspace script) picks its Fusion on turn 4 and seat 2, with
  an empty Extra Deck, reaches its Standby Phase on turn 6: the Fusion is
  Summoned, the duel plays on, no MSG_RETRY, and turn 8's MSG_TAG_SWAP
  brings seat 3 back with an empty Extra Deck. The shipped v1.4.0 engine
  dies in this case.
- CHANGELOG v1.4.1 row; contract note on MSG_TAG_SWAP (the next swap lists
  one card fewer; MSG_MOVE's from-sequence counts into the waiting list).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-16 13:38:08 -07:00
donnyandClaude Fable 5.1 65fcc307bb server: life points per side through the setup pair ygol.side.b.lp (v1.4.0)
Release / linux (push) Successful in 1m21s
Release / windows (push) Successful in 52s
Release / android (push) Successful in 42s
Release / release (push) Successful in 5s
Release / attach-windows (push) Successful in 1s
The room's "Life Points - Side B" field had nowhere to go: the host string
carries ONE start LP and the server gave it to both duel players. Now the
setup pair ygol.side.b.lp=<n> gives seat side B (seat 1; Tag seats 2 and 3)
its own start LP while side A keeps slot 8; absent, both sides start at
slot 8 exactly as before.

- SideBStartLp(fallback) reads the pair (positive integer, else fallback).
- single_duel / tag_duel keep player_lp[2] in DUEL PLAYER order, so the
  side that goes first keeps its own LP through the first-turn swap, in
  every duel of a Match: set_player_info per player, MSG_START at the
  start and in the late-watcher snapshot carry lp[0], lp[1].
- Replay flag REPLAY_YGOL_SIDE_LP 0x20000000: set only when the two
  differ; i32 lp[0], i32 lp[1] follow opt, before the decks. The binding
  gets ReplayFlags { SetupPairs, SideLp } for the readers.
- Probe: two more setup-pair rooms (Single and Tag) check MSG_START on
  every seat in duel player order and the replay's flag + values; every
  other room's replay must have no such flag.
- Contract: slot 8 row, the behaviour table, the Replay section, the
  server-read pairs table (three now), the binding row; CHANGELOG v1.4.0.

No new export or capability bit: exports 335 / 856 / 850, protocol 9,
capabilities 0x27FF.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-16 11:45:49 -07:00
donnyandClaude Fable 5.1 14a4f80aab tag partner cards: observers who see all get 0x5F for both sides (TICKET-412)
Release / windows (push) Successful in 33s
Release / android (push) Successful in 41s
Release / linux (push) Successful in 1m14s
Release / release (push) Successful in 4s
Release / attach-windows (push) Successful in 1s
SendTagPartnerCards also sends to every observer under SpectatorsSeeAll(), so the
start and every MSG_TAG_SWAP reach the audience; an observer's field resync and the
late-watcher snapshot carry both sides after the deck lists. Hidden rooms and seated
duelists are unchanged. Same id, same payload, no new capability bit.

Contract row 0x5F + join snapshot + MSG_TAG_SWAP note, a behaviour row; the probe's
tag partner room runs twice (see all: the watcher gets both sides at every send
point, its resync and a late snapshot; hidden: never); CHANGELOG v1.3.0.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-16 10:10:20 -07:00
donnyandClaude Fable 5.1 f52eca74ce contract: the probe's tag attack preview room battles on turn 4
Release / windows (push) Successful in 40s
Release / android (push) Successful in 40s
Release / release (push) Successful in 5s
Release / attach-windows (push) Successful in 1s
Release / linux (push) Successful in 1m22s
v1.1.1 took the Battle Phase away from tag turns 1-3, and the room still
asked the turn-2 duelist to enter it, so the probe failed there on every
run since. The room now passes turns 3 and 4 (both swaps) and the fourth
duelist asks the preview; the checks are unchanged.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-15 23:26:39 -07:00
donnyandClaude Fable 5.1 2789a82ef4 contract: the probe hosts above the OS dynamic port range (27961)
The probe's rooms sat on 7961-8071, inside this machine's dynamic port
range (1024-15000). A probe client that drew the next room's port as its
source port made that room's bind fail: the server printed "0" and the
probe died with "ended before it listened", on most runs. --port still
overrides.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-15 23:26:39 -07:00
donnyandClaude Fable 5.1 2344e5dae1 tag partner cards: ygol_query_tag_cards + STOC_TAG_PARTNER_CARDS 0x5F, capability 0x2000, protocol 9 (TICKET-405)
Core: ygol_query_tag_cards(pduel, playerid, out) reads the waiting tag
partner's tag_list_hand / tag_list_extra (bit 31 = face-up, like
MSG_TAG_SWAP) and tag_list_main sorted ascending; returns the byte length,
0 when not a tag duel. Read only.

Server: STOC_TAG_PARTNER_CARDS 0x5F = u8 side + those bytes, no stamp, to
that side's two seats only (never the other team, never an observer):
after start_duel, after every MSG_TAG_SWAP, and in a seated duelist's
field resync. FEATURE_TAG_PARTNER_CARDS 0x2000 advertised by single_duel
and tag_duel; FEATURE_PROTOCOL 8 -> 9. 0x800 / 0x1000 stay reserved for
proposals 44 / 45.

Binding: StocMessage.TagPartnerCards, FeatureFlags.TagPartnerCards, the
TagPartnerCards record + StocCodecs.TagPartnerCards,
EngineApi.ygol_query_tag_cards, Capability.ProtocolVersion 9, tests.

Contract rows, CHANGELOG v1.2.0, the probe's tag partner cards room, the
export gates 334 / 855 / 849 -> 335 / 856 / 850.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-15 23:26:39 -07:00
donnyandClaude Fable 5.1 c3b5e6e13b core: Tag duel has no Battle Phase on turns 1-3; the fourth duelist battles first
Release / linux (push) Successful in 1m15s
Release / release (push) Successful in 13s
Release / attach-windows (push) Successful in 1s
Release / android (push) Successful in 35s
Release / windows (push) Successful in 41s
The official Tag Duel rules: duelists 1A, 2A and 1B cannot enter their Battle
Phase; 2B (turn 4) is the first who can. The core blocked turn 1 only, so team
B's first duelist could attack on turn 2. One helper,
field::is_opening_turn_without_bp, now decides for the idle command and for
Duel.IsAbleToEnterBP: turns 1-3 in DUEL_TAG_MODE, turn 1 otherwise,
DUEL_ATTACK_FIRST_TURN still lifts it. Rules only; no contract change.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-15 21:04:13 -07:00
31 changed files with 1774 additions and 124 deletions

No files matched your search

+3 -3
View File
@@ -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
+78
View File
@@ -5,6 +5,84 @@ 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.6.0 — 2026-11-02
Tag shared Extra Deck (proposal 53): a setup pair gives a Tag team one Extra Deck, and each card keeps the partner who
brought it. No new export or message; capability `0x4000`, protocol 11: exports 335 / 856 / 850, capabilities `0x77FF`.
| Date | Change | Ticket | Contract part |
|---|---|---|---|
| 2026-11-02 | Core: option `DUEL_TAG_SHARED_EXTRA` `0x200`: `start_duel` moves `tag_list_extra` into `list_extra` and renumbers, for both teams; `tag_swap` skips its Extra block. `card::tag_member` (0 `new_card`, 1 `new_tag_card`), `QUERY_TAG_MEMBER` `0x1000000` written last in `get_infos`. Bit `0x100000` stays unused: old flags set it with no value. | TICKET-433 | (a) `start_duel` option; (c) Query records |
| 2026-11-02 | Server: `ygol.tag.extra=shared` is the fourth server-read pair. `TagDuel` sets the option in `opt`, sends the sum of both partners' Extra Decks in the opening `MSG_START`, runs the opening `RefreshExtra` after `start_duel`, and adds `QUERY_TAG_MEMBER` in `RefreshExtra`. `FEATURE_TAG_SHARED_EXTRA` `0x4000` advertised by Single and Tag rooms, protocol 10 -> 11; a Tag room refuses a joiner without the bit. | TICKET-433 | Wire: capability bit `0x4000`, protocol 11; (d) setup pair `ygol.tag.extra`; `0x5F` Extra count 0 in such a duel |
| 2026-11-02 | Binding: `FeatureFlags.TagSharedExtra` (in `All`), `Capability.ProtocolVersion` 11. Probe: the tag shared Extra Deck rooms (pair present, pair absent, a Summon of the waiting partner's monster, the replay played back through the library, the Tag refusal, the Single room that keeps an old client). | TICKET-433 | (e) C# binding |
## v1.5.0 — 2026-10-24
Tag two Field slots (proposal 45): a Tag team on Master Rule 4/5 holds one Field Spell per partner. No new
export or message; capability `0x1000`, protocol 10: exports 335 / 856 / 850, capabilities `0x37FF`.
| Date | Change | Ticket | Contract part |
|---|---|---|---|
| 2026-10-24 | Core: `field::has_two_fields()` (`DUEL_TAG_MODE` on Master Rule 4 or 5) gives each team a Field slot per partner, Spell/Trap sequence 5 for the partner who plays the team's first turn and 6 for the other (`player_info::tag_partner`, flipped in `tag_swap`; `get_szone_size` is 7 there). A Field Spell lands in the playing partner's slot (`get_fzone_landing`) and replaces only that card; a control change takes the free slot when the playing partner's is taken. A Set offers only the landing slot's bit. `LOCATION_FZONE` covers both slots in `card_state::is_location`, `filter_matching_card`, `filter_field_card`, `is_location_useable` and `Duel.IsEnvironment`; `get_field_card(p, LOCATION_FZONE, 0)` is the playing partner's field, else the other, and 1 the remaining one. Singles, Match and Master Rule 3 unchanged. | TICKET-384 | (c) `MSG_MOVE` / `MSG_RELOAD_FIELD` carry Spell/Trap sequence 6 (rules only); (d) Lua API: a second answer for `Duel.GetFieldCard` / `Duel.CheckLocation` with `LOCATION_FZONE` |
| 2026-10-24 | Server: `FEATURE_TAG_TWO_FIELDS` `0x1000` advertised by Single and Tag rooms, protocol 9 -> 10; a Tag room answers a `CTOS_CAPABILITY` without the bit with `STOC_ERROR_MSG` `ERRMSG_VERERROR` and closes the connection (`TagDuel::Capability`). | TICKET-384 | Wire: capability bit `0x1000`, protocol 10 |
| 2026-10-24 | Binding: `FeatureFlags.TagTwoFields` (in `All`), `Capability.ProtocolVersion` 10. Probe: the tag two Field slots rooms (a Tag room's placement on turns 1, 3 and 5 with the core's own view reported by the Probe Field's script, the Tag refusal, the Single room that keeps an old client). | TICKET-384 | (e) C# binding |
## v1.4.2 — 2026-10-24
Tag partner cards follow every change. 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-24 | `STOC_TAG_PARTNER_CARDS 0x5F` has a fourth send point: after every engine batch (beside `FlushDeckLists`, not when the duel ended) `TagDuel::FlushTagPartnerCards` queries `ygol_query_tag_cards` per side and broadcasts it when the bytes differ from the last broadcast for that side (a Summon out of the waiting member's Extra Deck, Time Fusion), to the same receivers. Every broadcast (start, swap, change) records its bytes; a resync to one player does not. Server. | TICKET-424 | Wire `0x5F` |
## 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(0x77FB));
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,58 @@ namespace YGOLegacy.Protocol.Tests
Assert.Throws<EndOfStreamException>(() => StocCodecs.AttackPreview.Read(Reader(new byte[] { 1 })));
}
[Test]
public void TagTwoFields_Flag_IsPinned_0x1000()
{
Assert.That(FeatureFlags.TagTwoFields, Is.EqualTo(0x1000));
Assert.That(FeatureFlags.All & FeatureFlags.TagTwoFields, Is.EqualTo(FeatureFlags.TagTwoFields));
}
[Test]
public void TagSharedExtra_Flag_AndProtocol_ArePinned_0x4000_11()
{
Assert.That(FeatureFlags.TagSharedExtra, Is.EqualTo(0x4000));
Assert.That(FeatureFlags.All & FeatureFlags.TagSharedExtra, Is.EqualTo(FeatureFlags.TagSharedExtra));
Assert.That(Capability.ProtocolVersion, Is.EqualTo(11));
}
[Test]
public void 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(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 +436,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(11), Le32(0x77FB))));
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)
+3
View File
@@ -88,6 +88,9 @@ namespace YGOLegacy.Engine
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern int ygol_preview_attack(IntPtr pduel, byte playerid, byte location, byte sequence, byte target_location, byte target_sequence, byte[] @out);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern int ygol_query_tag_cards(IntPtr pduel, byte playerid, byte[] @out);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern int get_registry_value(IntPtr pduel, [MarshalAs(UnmanagedType.LPUTF8Str)] string key, byte[] out_buf);
@@ -42,6 +42,7 @@ namespace YGOLegacy.Protocol.Codecs
public static readonly DeckListCodec DeckList = new DeckListCodec();
public static readonly StampedCodec<ProfileState> Profile = new StampedCodec<ProfileState>(StocMessage.Profile, LobbyCodecs.Profile, ProfileCodec.Size);
public static readonly AttackPreviewResultCodec AttackPreview = new AttackPreviewResultCodec();
public static readonly TagPartnerCardsCodec TagPartnerCards = new TagPartnerCardsCodec();
internal static long Remaining(BinaryReader reader)
{
@@ -164,6 +165,54 @@ namespace YGOLegacy.Protocol.Codecs
}
}
// Side, version, hand count, extra count, pad, uint16 deck count, then the hand, extra and deck codes as uint32; no sender stamp (v1.2.0, TICKET-405).
public sealed class TagPartnerCardsCodec : IStocCodec<TagPartnerCards>
{
public const int HeaderSize = 7;
public StocMessage Id => StocMessage.TagPartnerCards;
public TagPartnerCards Read(BinaryReader reader)
{
StocCodecs.Require(reader, HeaderSize, Id);
var side = reader.ReadByte();
var version = reader.ReadByte();
int handCount = reader.ReadByte();
int extraCount = reader.ReadByte();
reader.ReadByte();
int deckCount = reader.ReadUInt16();
if (deckCount > TagPartnerCards.MaxDeckCards)
throw new InvalidDataException("STOC " + Id + ": " + deckCount + " deck cards, at most " + TagPartnerCards.MaxDeckCards);
StocCodecs.Require(reader, (handCount + extraCount + deckCount) * 4, Id);
var hand = new uint[handCount];
for (var i = 0; i < handCount; i++)
hand[i] = reader.ReadUInt32();
var extra = new uint[extraCount];
for (var i = 0; i < extraCount; i++)
extra[i] = reader.ReadUInt32();
var deck = new int[deckCount];
for (var i = 0; i < deckCount; i++)
deck[i] = (int)reader.ReadUInt32();
return new TagPartnerCards(version, side, hand, extra, deck);
}
public void Write(BinaryWriter writer, TagPartnerCards payload)
{
writer.Write(payload.Side);
writer.Write(payload.Version);
writer.Write((byte)payload.Hand.Length);
writer.Write((byte)payload.Extra.Length);
writer.Write((byte)0);
writer.Write((ushort)payload.Deck.Length);
foreach (var raw in payload.Hand)
writer.Write(raw);
foreach (var raw in payload.Extra)
writer.Write(raw);
foreach (var code in payload.Deck)
writer.Write((uint)code);
}
}
public sealed class HostInfoCodec : IStocCodec<HostInfo>
{
public StocMessage Id => StocMessage.JoinGame;
@@ -6,7 +6,7 @@ namespace YGOLegacy.Protocol.Contracts
{
public const uint Appearance = 0x1;
public const uint Dialogue = 0x2;
public const uint All = Appearance | Dialogue | SeatPlan | RulesRestart | SeatState | LobbyAfterMatch | CoinToss | DeckList | Profile | AttackPreview;
public const uint All = Appearance | Dialogue | SeatPlan | RulesRestart | SeatState | LobbyAfterMatch | CoinToss | DeckList | Profile | AttackPreview | TagTwoFields | TagPartnerCards | TagSharedExtra;
// 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,12 @@ 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 on Master Rule 4/5 gives each partner a Field slot (Spell/Trap sequence 5 and 6); a Tag room refuses a joiner without the bit. Client: it shows sequence 6 as the Field Zone and refuses a host without the bit. 0x800 is reserved by proposal 44.
public const uint TagTwoFields = 0x1000;
// 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.
public const uint TagPartnerCards = 0x2000;
// Server: with the setup pair ygol.tag.extra=shared a Tag team has one Extra Deck and its Extra Deck refreshes carry the partner each card came from; a Tag room refuses a joiner without the bit. Client: it reads the value and refuses a host without the bit.
public const uint TagSharedExtra = 0x4000;
// 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 +60,7 @@ namespace YGOLegacy.Protocol.Contracts
public readonly struct Capability
{
public const ushort ProtocolVersion = 8;
public const ushort ProtocolVersion = 11;
public const int ServerSender = 0xFF;
public ushort Protocol { get; }
@@ -549,6 +555,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
View File
@@ -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
View File
@@ -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"
+58 -18
View File
@@ -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": 11,
"capabilities": 30719,
"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` (11 as of 2026-11-02). |
| `capabilities` | integer | The OR of every `FEATURE_*` bit `SendServerCapability` advertises (`single_duel.cpp` and `tag_duel.cpp` must agree), as a decimal integer. 30719 = `0x77FF` = bits `0x1` to `0x400` plus `0x1000`, `0x2000` and `0x4000` (`0x800` is reserved by proposal 44). |
| `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) |
@@ -93,7 +93,7 @@ The host string is space-separated tokens, in this order (`server/gframe/gframe.
| `create_duel_v2` | `intptr_t create_duel_v2(uint32_t seed_sequence[])` | Upstream (`SEED_COUNT` = 8 words) |
| `create_duel_ex` | `intptr_t create_duel_ex(uint_fast32_t seed, uint32_t create_flags)` | Upstream |
| `create_duel_v2_ex` | `intptr_t create_duel_v2_ex(uint32_t seed_sequence[], uint32_t create_flags)` | Upstream |
| `start_duel` | `void start_duel(intptr_t pduel, uint32_t options)` | Upstream |
| `start_duel` | `void start_duel(intptr_t pduel, uint32_t options)` | Upstream. v1.6.0: option `DUEL_TAG_SHARED_EXTRA` `0x200` with `DUEL_TAG_MODE` merges each team's Extra Decks (section (b), behaviour v1.6.0). |
| `end_duel` | `void end_duel(intptr_t pduel)` | Upstream |
| `set_player_info` | `void set_player_info(intptr_t pduel, int32_t playerid, int32_t lp, int32_t startcount, int32_t drawcount)` | Upstream |
| `get_log_message` | `void get_log_message(intptr_t pduel, char* buf)` | Upstream |
@@ -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,17 @@ 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
host without bit `0x4` as out of date.
`STOC_JOIN_GAME` and `STOC_TYPE_CHANGE`: `protocol` = `FEATURE_PROTOCOL` (11) and `flags` = the OR of
the bits below (`0x77FF`). A client sends its own `CTOS_CAPABILITY` after joining. A client refuses a
host without bit `0x4` as out of date, and without bit `0x1000` too (v1.5.0). A Tag room refuses a
client whose `CTOS_CAPABILITY` lacks `0x1000` or `0x4000` (v1.6.0): `STOC_ERROR_MSG` `ERRMSG_VERERROR`
(code = `FEATURE_PROTOCOL`), then the connection is closed; a Single room keeps it.
**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 +216,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.** **v1.4.2 (TICKET-424): after every engine batch (beside the deck lists, not when the duel ended), a side whose bytes differ from the last ones broadcast for it is sent again to the same receivers (an effect that moves a waiting member's card mid-turn); every broadcast records its bytes, so a swap is never sent twice; a resync to one player does not record.** Tag rooms only; a Single / Match room never sends it | `0x2000` | 9 | v1.2.0, v1.3.0, v1.4.2 |
### Capability bits and protocol numbers
@@ -228,6 +233,10 @@ 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` | `FEATURE_TAG_TWO_FIELDS` | 10 | v1.5.0 | Tag two Field slots: Spell/Trap sequence 6 is a team's second Field Zone (no message); a Tag room refuses a joiner without it |
| `0x2000` | `FEATURE_TAG_PARTNER_CARDS` | 9 | v1.2.0 | Tag partner cards (`STOC_TAG_PARTNER_CARDS`, `ygol_query_tag_cards`) |
| `0x4000` | `FEATURE_TAG_SHARED_EXTRA` | 11 | v1.6.0 | Tag shared Extra Deck: the setup pair `ygol.tag.extra=shared`, `QUERY_TAG_MEMBER` on Extra Deck refreshes; a Tag room refuses a joiner without it |
`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 +252,11 @@ 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. |
| v1.5.0 | Tag two Field slots (proposal 45, TICKET-384; core `field::has_two_fields` = `DUEL_TAG_MODE` on Master Rule 4 or 5): a team has a Field slot per partner, Spell/Trap sequence 5 for the partner who plays the team's first turn and 6 for the other (`player_info::tag_partner` flips in `tag_swap`). A Field Spell that lands (activated, Set, `Duel.MoveToField` to `LOCATION_FZONE`) goes to the playing partner's slot and replaces only the card there; one that changes control while that slot is taken and the other is free takes the free one. A Set opens only the landing slot's bit in `MSG_SELECT_PLACE`. `LOCATION_FZONE` covers both slots (`Card.IsLocation`, `Duel.GetMatchingGroup` and the other filters, `Duel.IsEnvironment`, `Duel.CheckLocation(p, LOCATION_FZONE, 0/1)`), `Duel.GetFieldCard(p, LOCATION_FZONE, 0)` is the playing partner's field, else the other one, and sequence 1 the remaining one; `Duel.GetFieldCard(p, LOCATION_SZONE, 6)` works. The second field reaches a client as `MSG_MOVE` to Spell/Trap sequence 6 and in `MSG_RELOAD_FIELD`'s sixth Spell/Trap entry: no new message. Singles, Match and Master Rule 3 (where slot 6 is a Pendulum Zone) are unchanged. Scripts that name Spell/Trap sequence 5 by number see one field (the TICKET-384 closing note lists them). Capability `0x1000`, protocol 9 -> 10. |
| v1.6.0 | Tag shared Extra Deck (proposal 53, TICKET-433): with the setup pair `ygol.tag.extra=shared` (section (d)) `TagDuel` sets the duel option `DUEL_TAG_SHARED_EXTRA` `0x200`. `start_duel` moves each team's `tag_list_extra` into `list_extra` (the first partner's cards first) and renumbers the sequences, so either partner can Summon any of the cards; `tag_swap` leaves the Extra Deck alone, `MSG_TAG_SWAP` keeps its layout and sends the one list, and `ygol_query_tag_cards` / `0x5F` report an Extra count of 0. The opening `MSG_START` carries the sum of both partners' Extra Decks, and the opening Extra Deck refreshes run after `start_duel`. The core has one `owner` per team, so each card has `card::tag_member`, set once when it is loaded (0 `new_card`, 1 `new_tag_card`), and `RefreshExtra` adds `QUERY_TAG_MEMBER` to its flag in such a duel (section (c), Query records). Replays need no format change: `opt` holds the option and every reader passes `opt` to `start_duel`; a reader that writes its own `MSG_START` before `start_duel` must add the partner's Extra count. An older engine ignores the option and plays such a replay wrongly. Without the pair every stream is unchanged. Capability `0x4000`, protocol 10 -> 11. |
### Replay
@@ -251,6 +265,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 +369,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 | - |
@@ -362,6 +381,21 @@ fork-related rows are marked.
Ids 6, 7 and 34 are server-side (`network.h`); the core's `common.h` lists the rest. Any other id is
an error for the consumer.
### Query records
`query_card`, `query_field_card` and the query buffer of `MSG_UPDATE_DATA` / `MSG_UPDATE_CARD` hold one
record per card: `i32 length`, `u32 flag`, then one value per set `QUERY_*` bit in bit order, the bits
in `core/common.h`. The fork adds one bit:
| Bit | Name | Value | Since |
|---|---|---|---|
| `0x1000000` | `QUERY_TAG_MEMBER` | `u32`, written LAST, after `QUERY_LINK`: the partner who brought the card, 0 from `new_card`, 1 from `new_tag_card`. It never changes when the card moves. The core writes it for any caller that sets the bit; the server sets it only on `RefreshExtra` in a duel with `ygol.tag.extra=shared` | v1.6.0 |
**Bit `0x100000` stays unused.** Old flags set it with no value after it: `RefreshSingle`'s default
`0xf81fff`, the hand refresh `0x181fff` and YGOSharp's `0xFFFFFF` mask, and saved `.yrp3d` replays are
recorded streams of them. A value for that bit would shift every later field of those records, with no
error.
## (d) Setup pairs and the Lua API
### Setup pairs (patch 0009, TICKET-258; ADR 0004 in the Unity repo)
@@ -373,12 +407,14 @@ 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:
Four 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 |
| `ygol.tag.extra` | `shared` = a Tag team has one Extra Deck (option `0x200`, section (b) v1.6.0); anything else or absent = separate Extra Decks. A Single or Match room ignores it | v1.6.0 |
Keys the Unity client sends today (`Assets/YGOLegacy/Scripts/Core/Duel/MatchSetup.cs`,
`SetupPairKeys`); the rules Lua reads them from the registry:
@@ -399,7 +435,10 @@ into `contract/lua-reference/`: `api-card.md`, `api-duel.md`, `api-effect.md`, `
the core sets). A name that is not there is not in the core; the card scripts' `library/` defines the
rest. Regenerate with `python contract/lua-reference/generate.py` after any core change to those
files and commit the result with it. The fork's core patches add no Lua function (0001 adds the
setcode `0xFDF`, `SETCODE_FACEDOWN_TOKEN`, as a cdb convention, not an API).
setcode `0xFDF`, `SETCODE_FACEDOWN_TOKEN`, as a cdb convention, not an API). v1.5.0 gives two
existing calls a second answer in Tag on Master Rule 4/5: `Duel.GetFieldCard(p, LOCATION_FZONE, 1)`
is the other partner's field and `Duel.CheckLocation(p, LOCATION_FZONE, 1)` asks about its slot
(both say nothing elsewhere, as before).
## (e) C# binding
@@ -414,7 +453,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`); v1.5.0 adds `FeatureFlags.TagTwoFields` (`0x1000`, in `All`) and `Capability.ProtocolVersion` is 10. |
| `YGOLegacy.Engine` | The four types below (TICKET-398). |
| Type | What |
@@ -455,6 +494,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)` |
+7
View File
@@ -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);
File diff suppressed because it is too large. Load diff
+5 -1
View File
@@ -67,7 +67,8 @@ uint32_t card::get_summon_info() {
}
bool card_state::is_location(uint32_t loc) const {
if((loc & LOCATION_FZONE) && location == LOCATION_SZONE && sequence == 5)
// [YGOL] proposal 45: slot 6 is the second Field slot in Tag (Master Rule 4/5); a Master Rule 3 Pendulum Zone card there has pzone set
if((loc & LOCATION_FZONE) && location == LOCATION_SZONE && (sequence == 5 || (sequence == 6 && !pzone)))
return true;
if((loc & LOCATION_PZONE) && location == LOCATION_SZONE && pzone)
return true;
@@ -430,6 +431,9 @@ int32_t card::get_infos(byte* buf, uint32_t query_flag, int32_t use_cache) {
query_flag &= ~QUERY_LINK;
}
}
if(query_flag & QUERY_TAG_MEMBER) {
buffer_write<uint32_t>(p, tag_member);
}
byte* finalize = buf;
buffer_write<int32_t>(finalize, (int32_t)(p - buf));
buffer_write<uint32_t>(finalize, query_flag);
+1
View File
@@ -164,6 +164,7 @@ public:
card_state spsummon;
query_cache q_cache;
uint8_t owner{ PLAYER_NONE };
uint8_t tag_member{ 0 }; // [YGOL] proposal 53: the partner who brought it, 0 from new_card, 1 from new_tag_card
uint8_t summon_player{ PLAYER_NONE };
uint32_t summon_info{};
uint32_t status{};
+2
View File
@@ -271,6 +271,7 @@ enum LuaParamType : int32_t {
#define QUERY_LSCALE 0x200000
#define QUERY_RSCALE 0x400000
#define QUERY_LINK 0x800000
#define QUERY_TAG_MEMBER 0x1000000 // [YGOL] proposal 53. Never 0x100000: old flags (0xf81fff, 0x181fff, 0xFFFFFF) set it with no value
//Link markers
#define LINK_MARKER_BOTTOM_LEFT 0x001
@@ -452,6 +453,7 @@ enum LuaParamType : int32_t {
#define DUEL_SIMPLE_AI 0x40
#define DUEL_RETURN_DECK_TOP 0x80
#define DUEL_REVEAL_DECK_SEQ 0x100
#define DUEL_TAG_SHARED_EXTRA 0x200 // [YGOL] proposal 53: one Extra Deck per Tag team
//Activity
#define ACTIVITY_SUMMON 1
+123 -35
View File
@@ -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);
@@ -293,7 +303,7 @@ void field::move_card(uint8_t playerid, card* pcard, uint8_t location, uint8_t s
if(sequence >= (int32_t)player[playerid].list_mzone.size() || player[playerid].list_mzone[sequence])
return;
} else {
if(sequence >= player[playerid].szone_size || player[playerid].list_szone[sequence])
if(sequence >= get_szone_size(playerid) || player[playerid].list_szone[sequence])
return;
}
if(preplayer == playerid) {
@@ -559,18 +569,23 @@ card* field::get_field_card(uint8_t playerid, uint32_t general_location, uint8_t
break;
}
case LOCATION_SZONE: {
if(sequence < player[playerid].szone_size)
if(sequence < get_szone_size(playerid))
return player[playerid].list_szone[sequence];
else
return nullptr;
break;
}
case LOCATION_FZONE: {
if(sequence == 0)
return player[playerid].list_szone[5];
else
// [YGOL] proposal 45 Rule 3: 0 = the playing partner's field, else the other one; 1 = the remaining one
if(sequence > 1 || (sequence == 1 && !has_two_fields()))
return nullptr;
break;
card* first = player[playerid].list_szone[get_fzone_sequence(playerid, 0)];
card* second = has_two_fields() ? player[playerid].list_szone[get_fzone_sequence(playerid, 1)] : nullptr;
if(!first) {
first = second;
second = nullptr;
}
return sequence == 0 ? first : second;
}
case LOCATION_PZONE: {
if(sequence == 0 || sequence == 1) {
@@ -598,14 +613,14 @@ int32_t field::is_location_useable(uint8_t playerid, uint32_t general_location,
return FALSE;
}
} else if (general_location == LOCATION_SZONE) {
if (sequence >= player[playerid].szone_size)
if (sequence >= get_szone_size(playerid))
return FALSE;
if(flag & (0x100U << sequence))
return FALSE;
} else if (general_location == LOCATION_FZONE) {
if (sequence >= 1)
if (sequence >= (has_two_fields() ? 2 : 1))
return FALSE;
if(flag & (0x100U << (5 + sequence)))
if(flag & (0x100U << get_fzone_sequence(playerid, sequence)))
return FALSE;
} else if (general_location == LOCATION_PZONE) {
if (sequence >= 2)
@@ -615,6 +630,40 @@ int32_t field::is_location_useable(uint8_t playerid, uint32_t general_location,
}
return TRUE;
}
// [YGOL] proposal 45: in Tag on Master Rule 4/5 a team has a Field slot per partner: Spell/Trap sequence 5 for the
// partner who plays the team's first turn, 6 for the other (slot 6 is free there: Master Rule 3 alone uses it as a
// Pendulum Zone). LOCATION_FZONE covers both; Singles, Match and Master Rule 3 keep the one slot.
bool field::has_two_fields() const {
return (core.duel_options & DUEL_TAG_MODE) && core.duel_rule >= NEW_MASTER_RULE;
}
int32_t field::get_szone_size(uint8_t playerid) const {
return has_two_fields() ? 7 : player[playerid].szone_size;
}
// fseq 0 = the playing partner's slot, 1 = the other partner's
uint8_t field::get_fzone_sequence(uint8_t playerid, uint8_t fseq) const {
if(!has_two_fields())
return 5;
return (player[playerid].tag_partner ^ fseq) ? 6 : 5;
}
// a zone flag that names the Field Zone (callers pass 1 << 5 for "the Field Zone" and the engine picks the slot)
bool field::is_fzone_zone(uint32_t zone) const {
return zone == (0x1U << 5) || (has_two_fields() && zone == (0x1U << 6));
}
// the slot a Field Spell lands in for playerid: the playing partner's, which it replaces; a card that changes control
// while the playing partner's slot is taken and the other is free takes the free one
uint8_t field::get_fzone_landing(card* pcard, uint8_t playerid) const {
if(!has_two_fields())
return 5;
if(pcard->current.location == LOCATION_SZONE && pcard->current.controler == playerid
&& (pcard->current.sequence == 5 || pcard->current.sequence == 6))
return pcard->current.sequence;
uint8_t mine = get_fzone_sequence(playerid, 0);
uint8_t other = get_fzone_sequence(playerid, 1);
if(player[playerid].list_szone[mine] && !player[playerid].list_szone[other]
&& pcard->current.location == LOCATION_SZONE && pcard->current.controler != playerid)
return other;
return mine;
}
/**
* Return usable count in `zone` when `uplayer` moves `pcard` to the MZONE or SZONE(0~4) of `playerid` (can be negative).
* For LOCATION_MZONE, "usable" means not used, not disabled, satisfying EFFECT_MUST_USE_MZONE, satisfying EFFECT_MAX_MZONE.
@@ -1140,12 +1189,38 @@ void field::refresh_player_info(uint8_t playerid) {
if (player[playerid].list_mzone[i])
used_flag |= 0x1U << i;
}
for (int32_t i = 0; i < player[playerid].szone_size; ++i) {
for (int32_t i = 0; i < get_szone_size(playerid); ++i) {
if (player[playerid].list_szone[i])
used_flag |= 0x100U << i;
}
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) {
@@ -1168,16 +1243,19 @@ void field::tag_swap(uint8_t playerid) {
pcard->enable_field_effect(true);
}
//extra
for(auto& pcard : player[playerid].list_extra) {
pcard->enable_field_effect(false);
pcard->cancel_field_effect();
}
std::swap(player[playerid].list_extra, player[playerid].tag_list_extra);
std::swap(player[playerid].extra_p_count, player[playerid].tag_extra_p_count);
for(auto& pcard : player[playerid].list_extra) {
pcard->apply_field_effect();
pcard->enable_field_effect(true);
if(!(core.duel_options & DUEL_TAG_SHARED_EXTRA)) { // [YGOL] proposal 53: a shared Extra Deck stays live for both partners
for(auto& pcard : player[playerid].list_extra) {
pcard->enable_field_effect(false);
pcard->cancel_field_effect();
}
std::swap(player[playerid].list_extra, player[playerid].tag_list_extra);
std::swap(player[playerid].extra_p_count, player[playerid].tag_extra_p_count);
for(auto& pcard : player[playerid].list_extra) {
pcard->apply_field_effect();
pcard->enable_field_effect(true);
}
}
player[playerid].tag_partner ^= 1; // [YGOL] proposal 45: the other partner's Field slot is the live one now
pduel->write_buffer8(MSG_TAG_SWAP);
pduel->write_buffer8(playerid);
pduel->write_buffer8((uint8_t)player[playerid].list_main.size());
@@ -1529,18 +1607,20 @@ int32_t field::filter_matching_card(lua_State* L, int32_t findex, uint8_t self,
}
}
if(location & LOCATION_FZONE) {
card* pcard = player[self].list_szone[5];
if(pcard && !pcard->is_treated_as_not_on_field()
&& pcard != pexception && !(pexgroup && pexgroup->has_card(pcard))
&& pduel->lua->check_filter(L, pcard, findex, extraargs)
&& (!is_target || pcard->is_capable_be_effect_target(core.reason_effect, core.reason_player))) {
if(pret) {
*pret = pcard;
return TRUE;
for(uint8_t fseq = 0, fzones = has_two_fields() ? 2 : 1; fseq < fzones; ++fseq) { // [YGOL] proposal 45: both Field slots
card* pcard = player[self].list_szone[get_fzone_sequence(self, fseq)];
if(pcard && !pcard->is_treated_as_not_on_field()
&& pcard != pexception && !(pexgroup && pexgroup->has_card(pcard))
&& pduel->lua->check_filter(L, pcard, findex, extraargs)
&& (!is_target || pcard->is_capable_be_effect_target(core.reason_effect, core.reason_player))) {
if(pret) {
*pret = pcard;
return TRUE;
}
result.insert(pcard);
if (fcount && (int32_t)result.size() >= fcount)
return TRUE;
}
result.insert(pcard);
if (fcount && (int32_t)result.size() >= fcount)
return TRUE;
}
}
if(location & LOCATION_PZONE) {
@@ -1664,9 +1744,11 @@ int32_t field::filter_field_card(uint8_t self, uint32_t location1, uint32_t loca
}
}
if(location & LOCATION_FZONE) {
card* pcard = player[self].list_szone[5];
if(pcard) {
result.insert(pcard);
for(uint8_t fseq = 0, fzones = has_two_fields() ? 2 : 1; fseq < fzones; ++fseq) { // [YGOL] proposal 45: both Field slots
card* pcard = player[self].list_szone[get_fzone_sequence(self, fseq)];
if(pcard) {
result.insert(pcard);
}
}
}
if(location & LOCATION_PZONE) {
@@ -3704,8 +3786,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);
}
+9
View File
@@ -87,6 +87,7 @@ struct player_info {
uint32_t extra_p_count{ 0 };
uint32_t tag_extra_p_count{ 0 };
int32_t szone_size{ 6 };
uint8_t tag_partner{ 0 }; // [YGOL] proposal 45: 0 = the partner who plays the team's first turn (Field slot 5), 1 = the other (slot 6); flips in tag_swap
card_vector list_mzone;
card_vector list_szone;
card_vector list_main;
@@ -402,6 +403,12 @@ public:
const card_vector* get_field_vector(uint8_t playerid, uint8_t location) const;
card* get_field_card(uint8_t playerid, uint32_t general_location, uint8_t sequence) const;
int32_t is_location_useable(uint8_t playerid, uint32_t general_location, uint8_t sequence) const;
// [YGOL] proposal 45: Tag on Master Rule 4/5 gives each partner a Field slot (Spell/Trap sequence 5 and 6)
bool has_two_fields() const;
int32_t get_szone_size(uint8_t playerid) const;
uint8_t get_fzone_sequence(uint8_t playerid, uint8_t fseq) const;
uint8_t get_fzone_landing(card* pcard, uint8_t playerid) const;
bool is_fzone_zone(uint32_t zone) const;
int32_t get_useable_count(card* pcard, uint8_t playerid, uint8_t location, uint8_t uplayer, uint32_t reason, uint32_t zone = 0xff, uint32_t* list = nullptr);
int32_t get_useable_count_fromex(card* pcard, uint8_t playerid, uint8_t uplayer, uint32_t zone = 0xff, uint32_t* list = nullptr);
int32_t get_spsummonable_count(card* pcard, uint8_t playerid, uint32_t zone = 0xff, uint32_t* list = nullptr);
@@ -424,6 +431,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 +539,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();
+10 -11
View File
@@ -1575,17 +1575,16 @@ int32_t scriptlib::duel_is_environment(lua_State *L) {
duel* pduel = interpreter::get_duel_info(L);
int32_t ret = 0, fc = 0;
if(loc & (LOCATION_FZONE + LOCATION_SZONE)) {
card* pcard = pduel->game_field->player[0].list_szone[5];
if(pcard && pcard->is_position(POS_FACEUP)) {
fc = 1;
if(code == pcard->get_code() && (playerid == 0 || playerid == PLAYER_ALL))
ret = 1;
}
pcard = pduel->game_field->player[1].list_szone[5];
if(pcard && pcard->is_position(POS_FACEUP)) {
fc = 1;
if(code == pcard->get_code() && (playerid == 1 || playerid == PLAYER_ALL))
ret = 1;
field* pfield = pduel->game_field;
for(uint8_t p = 0; p < 2; ++p) {
for(uint8_t fseq = 0, fzones = pfield->has_two_fields() ? 2 : 1; fseq < fzones; ++fseq) { // [YGOL] proposal 45: both Field slots
card* pcard = pfield->player[p].list_szone[pfield->get_fzone_sequence(p, fseq)];
if(pcard && pcard->is_position(POS_FACEUP)) {
fc = 1;
if(code == pcard->get_code() && (playerid == p || playerid == PLAYER_ALL))
ret = 1;
}
}
}
}
if(!ret && (loc & LOCATION_SZONE)) {
+41
View File
@@ -109,6 +109,18 @@ OCGCORE_API void start_duel(intptr_t pduel, uint32_t options) {
pd->game_field->core.shuffle_hand_check[1] = FALSE;
pd->game_field->core.shuffle_deck_check[0] = FALSE;
pd->game_field->core.shuffle_deck_check[1] = FALSE;
if((options & DUEL_TAG_MODE) && (options & DUEL_TAG_SHARED_EXTRA)) { // [YGOL] proposal 53: the team has one live Extra Deck
for(uint8_t p = 0; p < 2; ++p) {
auto& team = pd->game_field->player[p];
for(auto& pcard : team.tag_list_extra) {
team.list_extra.push_back(pcard);
pcard->apply_field_effect();
pcard->enable_field_effect(true);
}
team.tag_list_extra.clear();
pd->game_field->reset_sequence(p, LOCATION_EXTRA);
}
}
if(pd->game_field->player[0].start_count > 0)
pd->game_field->draw(0, REASON_RULE, PLAYER_NONE, 0, pd->game_field->player[0].start_count);
if(pd->game_field->player[1].start_count > 0)
@@ -198,6 +210,7 @@ OCGCORE_API void new_tag_card(intptr_t pduel, uint32_t code, uint8_t owner, uint
if(owner > 1 || !(location & (LOCATION_DECK | LOCATION_EXTRA)))
return;
card* pcard = ptduel->new_card(code);
pcard->tag_member = 1; // [YGOL] proposal 53
switch(location) {
case LOCATION_DECK:
ptduel->game_field->player[owner].tag_list_main.push_back(pcard);
@@ -441,6 +454,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;
+7
View File
@@ -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);
+11 -8
View File
@@ -2459,7 +2459,7 @@ int32_t field::sset(uint16_t step, uint8_t setplayer, uint8_t toplayer, card * t
return TRUE;
uint32_t flag = 0;
if(target->data.type & TYPE_FIELD) {
flag = ~(0x1U << 13);
flag = ~(0x1U << (8 + get_fzone_landing(target, toplayer))); // [YGOL] proposal 45: the partner's Field slot
} else {
get_useable_count(target, setplayer, LOCATION_SZONE, toplayer, LOCATION_REASON_TOFIELD, zone ? zone : 0xff, &flag);
flag = ((flag & 0xff) << 8) | 0xffff00ff;
@@ -2567,7 +2567,7 @@ int32_t field::sset_g(uint16_t step, uint8_t setplayer, uint8_t toplayer, group*
card_set* set_cards = (card_set*)ptarget;
card* target = *set_cards->begin();
if(target->data.type & TYPE_FIELD) {
returns.bvalue[2] = 5;
returns.bvalue[2] = get_fzone_landing(target, toplayer); // [YGOL] proposal 45
return FALSE;
}
uint32_t flag;
@@ -2606,7 +2606,7 @@ int32_t field::sset_g(uint16_t step, uint8_t setplayer, uint8_t toplayer, group*
target->enable_field_effect(false);
uint32_t zone;
if(target->data.type & TYPE_FIELD) {
zone = 0x1U << 5;
zone = 0x1U << get_fzone_landing(target, toplayer); // [YGOL] proposal 45
} else {
for(int32_t i = 0; i < 7; i++) {
zone = 0x1U << i;
@@ -2676,6 +2676,8 @@ int32_t field::sset_g(uint16_t step, uint8_t setplayer, uint8_t toplayer, group*
uint8_t ct = (uint8_t)core.operated_set.size();
if(core.set_group_used_zones & (0x1U << 5))
--ct;
if(core.set_group_used_zones & (0x1U << 6)) // [YGOL] proposal 45: the second Field slot
--ct;
if(ct <= 1)
return FALSE;
pduel->write_buffer8(MSG_SHUFFLE_SET_CARD);
@@ -4602,9 +4604,10 @@ int32_t field::move_to_field(uint16_t step, card* target, uint32_t enable, uint3
returns.ivalue[0] = FALSE;
if((ret == RETURN_TEMP_REMOVE_TO_FIELD) && (!(target->current.reason & REASON_TEMPORARY) || (target->current.reason_effect->owner != core.reason_effect->owner)))
return TRUE;
if(location == LOCATION_SZONE && zone == 0x1U << 5 && (target->data.type & TYPE_FIELD) && (target->data.type & TYPE_SPELL)) {
card* pcard = get_field_card(playerid, LOCATION_SZONE, 5);
if(pcard) {
if(location == LOCATION_SZONE && is_fzone_zone(zone) && (target->data.type & TYPE_FIELD) && (target->data.type & TYPE_SPELL)) {
// [YGOL] proposal 45: the card replaces only the Field slot it lands in
card* pcard = get_field_card(playerid, LOCATION_SZONE, get_fzone_landing(target, playerid));
if(pcard && pcard != target) {
if(core.duel_rule >= 3)
send_to(pcard, 0, REASON_RULE, pcard->current.controler, PLAYER_NONE, LOCATION_GRAVE, 0, 0);
else
@@ -4683,8 +4686,8 @@ int32_t field::move_to_field(uint16_t step, card* target, uint32_t enable, uint3
}
case 1: {
uint32_t seq = returns.bvalue[2];
if(location == LOCATION_SZONE && zone == 0x1U << 5 && (target->data.type & TYPE_FIELD) && (target->data.type & TYPE_SPELL))
seq = 5;
if(location == LOCATION_SZONE && is_fzone_zone(zone) && (target->data.type & TYPE_FIELD) && (target->data.type & TYPE_SPELL))
seq = get_fzone_landing(target, playerid); // [YGOL] proposal 45
if(ret != RETURN_TEMP_REMOVE_TO_FIELD) {
if(location != target->current.location) {
uint32_t resetflag = 0;
+1 -1
View File
@@ -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) {
+20
View File
@@ -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,25 @@ 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;
}
bool TagSharedExtra() { // YGOL tag shared extra
for(const auto& pair : setup_pairs)
if(pair == "ygol.tag.extra=shared")
return true;
return false;
}
size_t WriteSetupPairsBlock(unsigned char* dst) {
auto pdst = dst;
BufferIO::Write<uint16_t>(pdst, (uint16_t)setup_pairs.size());
+16 -1
View File
@@ -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 = 11; // 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; YGOL tag two fields: 9 -> 10; YGOL tag shared extra: 10 -> 11
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,16 @@ 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 two fields (proposal 45): in Tag on Master Rule 4/5 each partner has a Field slot (Spell/Trap sequence 5 and 6, the core's
// field::has_two_fields); no message, the second field reaches a client as sequence 6. A Tag room refuses a joiner without the bit
// (ERRMSG_VERERROR), a Single room does not care; 0x800 is reserved by proposal 44
constexpr uint32_t FEATURE_TAG_TWO_FIELDS = 0x1000;
// 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
constexpr uint32_t FEATURE_TAG_PARTNER_CARDS = 0x2000;
// YGOL tag shared extra (proposal 53): with the setup pair ygol.tag.extra=shared a Tag team has one Extra Deck (option DUEL_TAG_SHARED_EXTRA)
// and its Extra Deck refreshes carry QUERY_TAG_MEMBER; a Tag room refuses a joiner without the bit (ERRMSG_VERERROR)
constexpr uint32_t FEATURE_TAG_SHARED_EXTRA = 0x4000;
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 +481,8 @@ 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
bool TagSharedExtra(); // YGOL tag shared extra: ygol.tag.extra=shared
inline bool IsZeroId(const uint8_t* id) {
for(int i = 0; i < 16; ++i)
if(id[i])
@@ -666,6 +680,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
+16 -7
View File
@@ -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_TWO_FIELDS | FEATURE_TAG_PARTNER_CARDS | FEATURE_TAG_SHARED_EXTRA; // YGOL setup pairs + host seats + rules restart + seat state + lobby after match + coin toss + deck lists + profile + attack preview + tag two fields + tag partner cards + tag shared extra
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);
+1
View File
@@ -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 -13
View File
@@ -50,6 +50,16 @@ void TagDuel::BroadcastFeature(unsigned char proto, unsigned char* pdata, int le
void TagDuel::Capability(DuelPlayer* dp, unsigned char* pdata, int len) {
std::memcpy(&dp->capability, pdata, sizeof dp->capability);
dp->has_capability = true;
// YGOL tag two fields: a client without the bit shows the second Field slot as a Pendulum Zone, so a Tag room refuses it as out of date
// YGOL tag shared extra: a client without the bit misreads a shared Extra Deck refresh, the same refusal
if((dp->capability.flags & (FEATURE_TAG_TWO_FIELDS | FEATURE_TAG_SHARED_EXTRA)) != (FEATURE_TAG_TWO_FIELDS | FEATURE_TAG_SHARED_EXTRA)) {
STOC_ErrorMsg scem;
scem.msg = ERRMSG_VERERROR;
scem.code = FEATURE_PROTOCOL;
NetServer::SendPacketToPlayer(dp, STOC_ERROR_MSG, scem);
NetServer::DisconnectAfterFlush(dp);
return;
}
BroadcastFeature(STOC_CAPABILITY, pdata, len, dp->type);
}
void TagDuel::Appearance(DuelPlayer* dp, unsigned char* pdata, int len) {
@@ -96,7 +106,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_TWO_FIELDS | FEATURE_TAG_PARTNER_CARDS | FEATURE_TAG_SHARED_EXTRA; // YGOL setup pairs + host seats + rules restart + seat state + lobby after match + coin toss + deck lists + profile + attack preview + tag two fields + tag partner cards + tag shared extra
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 +1224,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 +1247,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 +1297,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");
@@ -1292,10 +1307,17 @@ void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
if(host_info.no_shuffle_deck)
opt |= DUEL_PSEUDO_SHUFFLE;
opt |= DUEL_TAG_MODE;
const bool shared_extra = TagSharedExtra(); // YGOL tag shared extra
if(shared_extra)
opt |= DUEL_TAG_SHARED_EXTRA;
last_replay.WriteInt32(host_info.start_lp, false);
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);
@@ -1304,7 +1326,10 @@ void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
last_replay.WriteInt32((*cit)->code, false);
}
};
uint16_t merged_extra[2]{}; // YGOL tag shared extra: what start_duel adds to each team's Extra Deck
auto load_tag = [&](const std::vector<const CardDataC*>& deck_container, uint8_t p, uint8_t location) {
if(shared_extra && location == LOCATION_EXTRA)
merged_extra[p] = (uint16_t)deck_container.size();
last_replay.WriteInt32(deck_container.size(), false);
for (auto cit = deck_container.rbegin(); cit != deck_container.rend(); ++cit) {
new_tag_card(pduel, (*cit)->code, p, location);
@@ -1347,12 +1372,12 @@ 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, 0, LOCATION_EXTRA) + merged_extra[0]);
BufferIO::Write<uint16_t>(pbuf, query_field_count(pduel, 1, LOCATION_DECK));
BufferIO::Write<uint16_t>(pbuf, query_field_count(pduel, 1, LOCATION_EXTRA));
BufferIO::Write<uint16_t>(pbuf, query_field_count(pduel, 1, LOCATION_EXTRA) + merged_extra[1]);
NetServer::SendBufferToPlayer(players[0], STOC_GAME_MSG, startbuf, 19);
NetServer::ReSendToPlayer(players[1]);
startbuf[1] = 1;
@@ -1372,9 +1397,18 @@ void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
phase = 1;
deck_reversed = false;
#endif
RefreshExtra(0);
RefreshExtra(1);
if(!shared_extra) {
RefreshExtra(0);
RefreshExtra(1);
}
start_duel(pduel, opt);
if(shared_extra) { // YGOL tag shared extra: start_duel merged the lists
RefreshExtra(0);
RefreshExtra(1);
}
tag_cards_known[0] = tag_cards_known[1] = false;
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
@@ -1409,8 +1443,10 @@ void TagDuel::Process() {
stop = Analyze(engineBuffer.data(), engLen);
}
}
if(stop != 2) // YGOL deck lists: after every engine batch, before a prompt waits
if(stop != 2) { // YGOL deck lists + tag partner cards: after every engine batch, before a prompt waits
FlushDeckLists();
FlushTagPartnerCards();
}
if(stop == 2)
DuelEndProc();
}
@@ -2722,6 +2758,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 +2886,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 +2929,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 +3073,46 @@ 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, after any engine batch that changed the side's bytes (TICKET-424), in a seat's field resync (its side)
// and in an observer's resync / late-watcher snapshot (both sides). A broadcast records the bytes it sent; a send to
// one player (a resync) does not, so it never hides a change the others have not had.
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;
}
tag_cards_sent[side].assign(buf + 1, buf + 1 + len);
tag_cards_known[side] = true;
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::FlushTagPartnerCards() {
if(!pduel)
return;
unsigned char buf[1 + 6 + (2 * UINT8_MAX + MAINC_MAX) * sizeof(uint32_t)];
for(int side = 0; side < 2; ++side) {
const int len = ygol_query_tag_cards(pduel, (uint8_t)side, buf);
if(len <= 0)
continue;
if(tag_cards_known[side] && tag_cards_sent[side].size() == (size_t)len
&& std::equal(tag_cards_sent[side].begin(), tag_cards_sent[side].end(), buf))
continue;
SendTagPartnerCards(side);
}
}
void TagDuel::TimeConfirm(DuelPlayer* dp) {
if(host_info.time_limit == 0)
return;
@@ -3306,6 +3387,8 @@ void TagDuel::RefreshExtra(int player, int flag, int use_cache, DuelPlayer* dp)
void TagDuel::RefreshExtra(int player, int flag, int use_cache)
#endif //YGOPRO_SERVER_MODE
{
if(TagSharedExtra()) // YGOL tag shared extra
flag |= QUERY_TAG_MEMBER;
std::array<unsigned char, SIZE_QUERY_BUFFER> query_buffer;
auto qbuf = query_buffer.data();
auto len = WriteUpdateData(player, LOCATION_EXTRA, flag, qbuf, use_cache);
+5
View File
@@ -99,6 +99,10 @@ 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
void FlushTagPartnerCards(); // YGOL tag partner cards: after every engine batch, a side whose bytes changed since its last broadcast sends again (TICKET-424)
std::vector<unsigned char> tag_cards_sent[2];
bool tag_cards_known[2]{};
// YGOL coin toss
void BeginChoose(int chooser, uint8_t face);
int choose_seat{};
@@ -150,6 +154,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