Files
yugioh-legacy-engine/core/ocgapi.h
T
donnyandClaude Fable 5.1 26f9baf9b4 core: import the rules core (ygopro-core 973672dc + fork patches)
The vendored ocgcore from the Unity repo (Tools/YGOLegacy/ocgcore at dev
HEAD). Upstream is nanahira/ygopro-core at 973672dc9ce7cb49f47173277ab1ad0e318b7593;
the seven files that differ from it carry the fork's core patches, already
applied: 0001 face-down Token setcode, 0004 effect damage step outside a
chain, 0008 Sandbox god mode, 0015 tag first seat holds the hand, 0022
attack preview, 0024 attack preview legality. Generated build/ output is
left out.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-14 20:58:16 -07:00

109 lines
5.6 KiB
C

/*
* interface.h
*
* Created on: 2010-4-28
* Author: Argon
*/
#ifndef OCGAPI_H_
#define OCGAPI_H_
#include "common.h"
#ifdef __cplusplus
#define EXTERN_C extern "C"
#else
#define EXTERN_C
#endif
#ifndef OCGCORE_API
#if defined(__EMSCRIPTEN__)
#include <emscripten/emscripten.h>
#define OCGCORE_API EXTERN_C EMSCRIPTEN_KEEPALIVE
#elif defined(_WIN32)
#define OCGCORE_API EXTERN_C __declspec(dllexport)
#else
#define OCGCORE_API EXTERN_C __attribute__ ((visibility ("default")))
#endif
#endif
#define SEED_COUNT 8
#define LEN_FAIL 0
#define LEN_EMPTY 4
#define LEN_HEADER 8
#define TEMP_CARD_ID 0
struct card_data;
typedef byte* (*script_reader)(const char* script_name, int* len);
typedef uint32_t (*card_reader)(uint32_t code, card_data* data);
typedef uint32_t (*message_handler)(intptr_t pduel, uint32_t msg_type);
OCGCORE_API void set_script_reader(script_reader f);
OCGCORE_API void set_card_reader(card_reader f);
OCGCORE_API void set_message_handler(message_handler f);
byte* read_script(const char* script_name, int* len);
uint32_t read_card(uint32_t code, card_data* data);
uint32_t handle_message(void* pduel, uint32_t message_type);
OCGCORE_API intptr_t create_duel(uint_fast32_t seed);
OCGCORE_API intptr_t create_duel_v2(uint32_t seed_sequence[]);
OCGCORE_API intptr_t create_duel_ex(uint_fast32_t seed, uint32_t create_flags);
OCGCORE_API intptr_t create_duel_v2_ex(uint32_t seed_sequence[], uint32_t create_flags);
OCGCORE_API void start_duel(intptr_t pduel, uint32_t options);
OCGCORE_API void end_duel(intptr_t pduel);
OCGCORE_API void set_player_info(intptr_t pduel, int32_t playerid, int32_t lp, int32_t startcount, int32_t drawcount);
OCGCORE_API void get_log_message(intptr_t pduel, char* buf);
OCGCORE_API int32_t get_message(intptr_t pduel, byte* buf);
OCGCORE_API uint32_t process(intptr_t pduel);
OCGCORE_API void new_card(intptr_t pduel, uint32_t code, uint8_t owner, uint8_t playerid, uint8_t location, uint8_t sequence, uint8_t position);
OCGCORE_API void new_tag_card(intptr_t pduel, uint32_t code, uint8_t owner, uint8_t location);
OCGCORE_API 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);
OCGCORE_API int32_t query_field_count(intptr_t pduel, uint8_t playerid, uint8_t location);
OCGCORE_API int32_t query_field_card(intptr_t pduel, uint8_t playerid, uint8_t location, uint32_t query_flag, byte* buf, int32_t use_cache);
OCGCORE_API int32_t query_field_info(intptr_t pduel, byte* buf);
OCGCORE_API void set_responsei(intptr_t pduel, int32_t value);
OCGCORE_API void set_responseb(intptr_t pduel, byte* buf);
OCGCORE_API int32_t preload_script(intptr_t pduel, const char* script_name);
OCGCORE_API byte* default_script_reader(const char* script_name, int* len);
// [YGOL] patch 0022 (attack preview): a read-only dry run of the damage step for one attacker and one
// target (target_location 0xFF = direct). 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. 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 field::get_attack_target would not offer answers
// illegal alone with every number 0 (patch 0024). Call it only while the engine is parked on a prompt;
// 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);
// 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);
OCGCORE_API int32_t get_registry_keys(intptr_t pduel, byte* out_buf);
OCGCORE_API void clear_registry(intptr_t pduel);
OCGCORE_API int32_t dump_registry(intptr_t pduel, byte* out_buf);
OCGCORE_API void load_registry(intptr_t pduel, const byte* in_buf, int32_t in_len);
OCGCORE_API int32_t get_lua_coverage_dump_size(intptr_t pduel, const char* name);
OCGCORE_API int32_t dump_lua_coverage(intptr_t pduel, const char* name, byte* out_buf, int32_t out_len);
OCGCORE_API int32_t get_all_lua_coverages_dump_size(intptr_t pduel);
OCGCORE_API int32_t dump_all_lua_coverages(intptr_t pduel, byte* out_buf, int32_t out_len);
OCGCORE_API void clear_lua_coverage(intptr_t pduel, const char* name);
OCGCORE_API void clear_all_lua_coverages(intptr_t pduel);
// [YGOL] patch 0008 (sandbox god mode): additive, Sandbox-only exports. Nothing a normal
// duel, replay, BotArena or YGOSharp calls. Each returns 1 when it did the work, 0 when it
// refused and changed nothing.
OCGCORE_API int32_t ygol_sb_add(intptr_t pduel, uint32_t code, uint8_t owner, uint8_t playerid, uint8_t location, uint8_t sequence, uint8_t position);
OCGCORE_API int32_t ygol_sb_move(intptr_t pduel, uint8_t playerid, uint8_t location, uint8_t sequence, uint8_t dst_playerid, uint8_t dst_location, uint8_t dst_sequence, uint8_t position);
OCGCORE_API int32_t ygol_sb_remove(intptr_t pduel, uint8_t playerid, uint8_t location, uint8_t sequence);
OCGCORE_API int32_t ygol_sb_set_position(intptr_t pduel, uint8_t playerid, uint8_t location, uint8_t sequence, uint8_t position);
OCGCORE_API int32_t ygol_sb_set_lp(intptr_t pduel, uint8_t playerid, int32_t lp);
OCGCORE_API int32_t ygol_sb_reask(intptr_t pduel);
#endif /* OCGAPI_H_ */