binding/YGOLegacy.Engine (netstandard2.1, LangVersion 9, unsafe, no package, no Unity
reference) holds the Unity repo's Assets/YGOLegacy/Scripts/Protocol/ as
Protocol/{Contracts,Codecs,Framing,Routing}: 12 files copied byte-identical (LF), namespaces
YGOLegacy.Protocol.* unchanged. EngineVersion (default local) is stamped as the informational
version, so the DLL's ProductVersion is the tag it was built for.
binding/YGOLegacy.Engine.Tests (net8.0, NUnit 3.14) holds the six fixtures. 114 tests pass,
the Unity Edit Mode count. Two deviations from "as-is", lead-approved 2026-10-15:
LegacyReaders.cs is a frozen test-only copy of the legacy MDPro3 / YGOSharp readers and enums
the parity tests compare against (they live only in the Unity repo), and FrameCodecTests.cs
line 35 casts (short) instead of (byte): BitConverter.GetBytes((byte)) is ambiguous on
net8.0 (the Half overload), same bytes written.
The windows job builds and tests the binding after the native gates (both with
-p:EngineVersion so the test's project reference does not restamp the DLL as local), checks
the ProductVersion and stages ygol-engine-binding.zip (YGOLegacy.Engine.dll + .pdb) beside
ygol-engine-win64.zip; attach-windows attaches both. engine.json gains "binding": "<version>"
on every platform (windows.ps1 and the Dockerfile's export-gate, the only writers) and the
release job's agreement check includes it. README gains the Binding section and the asset row;
.gitignore ignores binding/**/bin and obj.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DJUFwdiGCHipsxLkgxssSR
206 lines
5.6 KiB
C#
206 lines
5.6 KiB
C#
namespace YGOLegacy.Protocol.Contracts
|
|
{
|
|
public readonly struct ErrorMsg
|
|
{
|
|
public byte Msg { get; }
|
|
public int Code { get; }
|
|
|
|
public ErrorMsg(byte msg, int code)
|
|
{
|
|
Msg = msg;
|
|
Code = code;
|
|
}
|
|
}
|
|
|
|
public readonly struct HandResultAnnounce
|
|
{
|
|
public byte First { get; }
|
|
public byte Second { get; }
|
|
|
|
public HandResultAnnounce(byte first, byte second)
|
|
{
|
|
First = first;
|
|
Second = second;
|
|
}
|
|
}
|
|
|
|
// STOC 0x5B (patch 0017), to every seat and spectator before SELECT_TP: who chooses the turn order and how the coin landed.
|
|
public readonly struct CoinTossAnnounce
|
|
{
|
|
public const byte CurrentVersion = 1;
|
|
public const byte Heads = 0;
|
|
public const byte Tails = 1;
|
|
// No toss: game 2+ of a match, the loser chooses.
|
|
public const byte NoFace = 0xFF;
|
|
|
|
public byte Version { get; }
|
|
public byte ChooserSeat { get; }
|
|
public byte Face { get; }
|
|
public byte ChooseSeconds { get; }
|
|
|
|
public CoinTossAnnounce(byte chooserSeat, byte face, byte chooseSeconds) : this(CurrentVersion, chooserSeat, face, chooseSeconds) { }
|
|
|
|
public CoinTossAnnounce(byte version, byte chooserSeat, byte face, byte chooseSeconds)
|
|
{
|
|
Version = version;
|
|
ChooserSeat = chooserSeat;
|
|
Face = face;
|
|
ChooseSeconds = chooseSeconds;
|
|
}
|
|
|
|
public bool Tossed => Face != NoFace;
|
|
}
|
|
|
|
public readonly struct HostInfo
|
|
{
|
|
public uint Lflist { get; }
|
|
public byte Rule { get; }
|
|
public byte Mode { get; }
|
|
public byte DuelRule { get; }
|
|
public bool NoCheckDeck { get; }
|
|
public bool NoShuffleDeck { get; }
|
|
public int StartLp { get; }
|
|
public byte StartHand { get; }
|
|
public byte DrawCount { get; }
|
|
public ushort TimeLimit { get; }
|
|
|
|
public HostInfo(uint lflist, byte rule, byte mode, byte duelRule, bool noCheckDeck, bool noShuffleDeck,
|
|
int startLp, byte startHand, byte drawCount, ushort timeLimit)
|
|
{
|
|
Lflist = lflist;
|
|
Rule = rule;
|
|
Mode = mode;
|
|
DuelRule = duelRule;
|
|
NoCheckDeck = noCheckDeck;
|
|
NoShuffleDeck = noShuffleDeck;
|
|
StartLp = startLp;
|
|
StartHand = startHand;
|
|
DrawCount = drawCount;
|
|
TimeLimit = timeLimit;
|
|
}
|
|
}
|
|
|
|
public readonly struct TypeChange
|
|
{
|
|
public byte Position { get; }
|
|
public bool IsHost { get; }
|
|
|
|
public TypeChange(byte position, bool isHost)
|
|
{
|
|
Position = (byte)(position & 0xF);
|
|
IsHost = isHost;
|
|
}
|
|
}
|
|
|
|
public readonly struct TimeLimit
|
|
{
|
|
public byte Player { get; }
|
|
public ushort LeftTime { get; }
|
|
|
|
public TimeLimit(byte player, ushort leftTime)
|
|
{
|
|
Player = player;
|
|
LeftTime = leftTime;
|
|
}
|
|
}
|
|
|
|
public readonly struct ServerChat
|
|
{
|
|
public ushort Player { get; }
|
|
public string Text { get; }
|
|
|
|
public ServerChat(ushort player, string text)
|
|
{
|
|
Player = player;
|
|
Text = text ?? string.Empty;
|
|
}
|
|
}
|
|
|
|
public readonly struct PlayerEnter
|
|
{
|
|
public string Name { get; }
|
|
public byte Position { get; }
|
|
|
|
public PlayerEnter(string name, byte position)
|
|
{
|
|
Name = name ?? string.Empty;
|
|
Position = position;
|
|
}
|
|
}
|
|
|
|
public enum PlayerChangeKind
|
|
{
|
|
MoveTo,
|
|
Observe,
|
|
Ready,
|
|
NotReady,
|
|
Leave,
|
|
Unknown
|
|
}
|
|
|
|
public readonly struct PlayerChange
|
|
{
|
|
public const byte ObserveState = 0x8;
|
|
public const byte ReadyState = 0x9;
|
|
public const byte NotReadyState = 0xA;
|
|
public const byte LeaveState = 0xB;
|
|
|
|
public byte Position { get; }
|
|
public byte State { get; }
|
|
public PlayerChangeKind Kind { get; }
|
|
public byte TargetSeat { get; }
|
|
|
|
public PlayerChange(byte position, byte state)
|
|
{
|
|
Position = (byte)(position & 0xF);
|
|
State = (byte)(state & 0xF);
|
|
Kind = KindOf(State);
|
|
TargetSeat = Kind == PlayerChangeKind.MoveTo ? State : (byte)0;
|
|
}
|
|
|
|
public static PlayerChangeKind KindOf(byte state)
|
|
{
|
|
if (state < ObserveState)
|
|
return PlayerChangeKind.MoveTo;
|
|
switch (state)
|
|
{
|
|
case ObserveState: return PlayerChangeKind.Observe;
|
|
case ReadyState: return PlayerChangeKind.Ready;
|
|
case NotReadyState: return PlayerChangeKind.NotReady;
|
|
case LeaveState: return PlayerChangeKind.Leave;
|
|
default: return PlayerChangeKind.Unknown;
|
|
}
|
|
}
|
|
}
|
|
|
|
public readonly struct WatchChange
|
|
{
|
|
public ushort Count { get; }
|
|
|
|
public WatchChange(ushort count)
|
|
{
|
|
Count = count;
|
|
}
|
|
}
|
|
|
|
public readonly struct DeckCount
|
|
{
|
|
public short Main0 { get; }
|
|
public short Extra0 { get; }
|
|
public short Side0 { get; }
|
|
public short Main1 { get; }
|
|
public short Extra1 { get; }
|
|
public short Side1 { get; }
|
|
|
|
public DeckCount(short main0, short extra0, short side0, short main1, short extra1, short side1)
|
|
{
|
|
Main0 = main0;
|
|
Extra0 = extra0;
|
|
Side0 = side0;
|
|
Main1 = main1;
|
|
Extra1 = extra1;
|
|
Side1 = side1;
|
|
}
|
|
}
|
|
}
|