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>
YGOPro script engine
Introduction
The core logic and lua script processor of YGOPro. This library can be made external of the project and used to power server technologies. It maintains a state engine that is manipulated by Lua scripts using manipulation functions it exposes.
Compiling
In most cases, what you want to compile is the main program of YGOPro. You should refer to the main YGOPro project's wiki. If you want to compile the dynamic link library of this repository (ocgcore.dll), you can refer to this script.
For WebAssembly builds, use Emscripten 3.1.1 through 3.1.7.
Exposed Functions
The 3 functions need to be provided to the core so it can get card and database information.
-
void set_script_reader(script_reader f);
Interface provided returns scripts based on number that corresponds to a lua file, send in a string. -
void set_card_reader(card_reader f);
Interface provided function that provides database information from thedatastable ofcards.cdb. -
void set_message_handler(message_handler f);
Interface provided function that handles error messages.
These functions create the game itself and then manipulate it.
-
intptr_t create_duel(uint_fast32_t seed);
(Deprecated) Create an instance ofduelwith 1 uint32 PRNG seed.
This function is reserved for replay mode only. -
intptr_t create_duel_v2(uint32_t seed_sequence[]);
Create an instance ofduelwith PRNG seedseed_sequence[]of lengthSEED_COUNT. -
void start_duel(intptr_t pduel, uint32_t options);
Start the duel. -
void end_duel(intptr_t pduel);
End the duel. -
void set_player_info(intptr_t pduel, int32_t playerid, int32_t lp, int32_t startcount, int32_t drawcount);
Set up the duel information. -
void get_log_message(intptr_t pduel, char* buf); -
int32_t get_message(intptr_t pduel, byte* buf); -
int32_t process(intptr_t pduel);
Do a game tick. -
void new_card(intptr_t pduel, uint32_t code, uint8_t owner, uint8_t playerid, uint8_t location, uint8_t sequence, uint8_t position);
Add a card to the duel state. -
void new_tag_card(intptr_t pduel, uint32_t code, uint8_t owner, uint8_t location);
Add a new card to the tag pool. -
int32_t query_card(intptr_t pduel, uint8_t playerid, uint8_t location, uint8_t sequence, uint32_t query_flag, byte* buf, int32_t use_cache);
Get a card in a specific location. -
int32_t query_field_count(intptr_t pduel, uint8_t playerid, uint8_t location);
Get the number of cards in a specific location. -
int32_t query_field_card(intptr_t pduel, uint8_t playerid, uint8_t location, uint32_t query_flag, byte* buf, int32_t use_cache);
Get all cards in some location. -
int32_t query_field_info(intptr_t pduel, byte* buf); -
void set_responsei(intptr_t pduel, int32_t value); -
void set_responseb(intptr_t pduel, byte* buf); -
int32_t preload_script(intptr_t pduel, const char* script_name); -
byte* default_script_reader(const char* script_name, int* len);
The default script reader usingfread.
Lua functions
libcard.cpplibdebug.cpplibduel.cpplibeffect.cpplibgroup.cpp