Files
yugioh-legacy-engine/binding/YGOLegacy.Engine/EngineApi.cs
T
donnyandClaude Fable 5.1 ffd50fa147
Release / windows (push) Successful in 32s
Release / android (push) Successful in 36s
Release / linux (push) Successful in 1m4s
Release / release (push) Successful in 5s
Release / attach-windows (push) Successful in 1s
binding: EngineApi, MessageScan, GameMessage, EngineBinding; contract section (e); v1.1.0 changelog (TICKET-398)
Namespace YGOLegacy.Engine in binding/YGOLegacy.Engine:
- EngineApi: one DllImport("ygol-engine", Cdecl) extern per export of contract/ocgapi.h (45),
  C names kept, types by the contract's type rule; delegates ScriptReader, CardReader,
  MessageHandler beside it.
- MessageScan: MsgInfo, Scan, Blank, BlankPileCodes, PromptName moved from the Unity bot host
  (LocalDuelHost), public, bodies unchanged (+ the private FieldOffset helper and the five
  constants they read).
- GameMessage: enum : byte, one member per #define MSG_* in core/common.h (84), PascalCase names.
- EngineBinding: const Version generated at build from the EngineVersion property into
  obj/EngineBindingVersion.cs (local by default); CheckNative() compares it with
  ygol_engine_version() and throws InvalidOperationException naming both.

Tests: EngineApiParityTests (header names vs extern names, both ways; public, Cdecl, no
CharSet.Unicode, no overloads) and GameMessageParityTests (missing, extra, renumbered).
114 -> 122 tests, green.

contract/engine-contract.md: five parts; "(e) C# binding" with the 45-row extern table, the type
rule and the version rule; engine.json's binding key documented. CHANGELOG.md: Unreleased ->
v1.1.0 with the TICKET-397 and TICKET-398 rows. README.md: the Binding section names the four
types and CheckNative().

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DJUFwdiGCHipsxLkgxssSR
2026-10-15 16:30:24 -07:00

155 lines
8.2 KiB
C#

using System;
using System.Runtime.InteropServices;
namespace YGOLegacy.Engine
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate IntPtr ScriptReader([MarshalAs(UnmanagedType.LPUTF8Str)] string script_name, int* len);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate uint CardReader(uint code, IntPtr data);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate uint MessageHandler(IntPtr pduel, uint msg_type);
public static unsafe class EngineApi
{
private const string Library = "ygol-engine";
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern void set_script_reader(ScriptReader f);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern void set_card_reader(CardReader f);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern void set_message_handler(MessageHandler f);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr create_duel(uint seed);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr create_duel_v2(uint[] seed_sequence);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr create_duel_ex(uint seed, uint create_flags);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr create_duel_v2_ex(uint[] seed_sequence, uint create_flags);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern void start_duel(IntPtr pduel, uint options);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern void end_duel(IntPtr pduel);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern void set_player_info(IntPtr pduel, int playerid, int lp, int startcount, int drawcount);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern void get_log_message(IntPtr pduel, byte[] buf);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern int get_message(IntPtr pduel, byte[] buf);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern uint process(IntPtr pduel);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern void new_card(IntPtr pduel, uint code, byte owner, byte playerid, byte location, byte sequence, byte position);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern void new_tag_card(IntPtr pduel, uint code, byte owner, byte location);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern int query_card(IntPtr pduel, byte playerid, byte location, byte sequence, uint query_flag, byte[] buf, int use_cache);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern int query_field_count(IntPtr pduel, byte playerid, byte location);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern int query_field_card(IntPtr pduel, byte playerid, byte location, uint query_flag, byte[] buf, int use_cache);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern int query_field_info(IntPtr pduel, byte[] buf);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern void set_responsei(IntPtr pduel, int value);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern void set_responseb(IntPtr pduel, byte[] buf);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern int preload_script(IntPtr pduel, [MarshalAs(UnmanagedType.LPUTF8Str)] string script_name);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr default_script_reader([MarshalAs(UnmanagedType.LPUTF8Str)] string script_name, int* len);
[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 get_registry_value(IntPtr pduel, [MarshalAs(UnmanagedType.LPUTF8Str)] string key, byte[] out_buf);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern void set_registry_value(IntPtr pduel, [MarshalAs(UnmanagedType.LPUTF8Str)] string key, [MarshalAs(UnmanagedType.LPUTF8Str)] string value);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern int get_registry_keys(IntPtr pduel, byte[] out_buf);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern void clear_registry(IntPtr pduel);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern int dump_registry(IntPtr pduel, byte[] out_buf);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern void load_registry(IntPtr pduel, byte[] in_buf, int in_len);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern int get_lua_coverage_dump_size(IntPtr pduel, [MarshalAs(UnmanagedType.LPUTF8Str)] string name);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern int dump_lua_coverage(IntPtr pduel, [MarshalAs(UnmanagedType.LPUTF8Str)] string name, byte[] out_buf, int out_len);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern int get_all_lua_coverages_dump_size(IntPtr pduel);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern int dump_all_lua_coverages(IntPtr pduel, byte[] out_buf, int out_len);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern void clear_lua_coverage(IntPtr pduel, [MarshalAs(UnmanagedType.LPUTF8Str)] string name);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern void clear_all_lua_coverages(IntPtr pduel);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern int ygol_sb_add(IntPtr pduel, uint code, byte owner, byte playerid, byte location, byte sequence, byte position);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern int ygol_sb_move(IntPtr pduel, byte playerid, byte location, byte sequence, byte dst_playerid, byte dst_location, byte dst_sequence, byte position);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern int ygol_sb_remove(IntPtr pduel, byte playerid, byte location, byte sequence);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern int ygol_sb_set_position(IntPtr pduel, byte playerid, byte location, byte sequence, byte position);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern int ygol_sb_set_lp(IntPtr pduel, byte playerid, int lp);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern int ygol_sb_reask(IntPtr pduel);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern int start_server([MarshalAs(UnmanagedType.LPUTF8Str)] string args);
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern void stop_server();
[DllImport(Library, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr ygol_engine_version();
}
}