diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index b5a9fc1..f6f0bb8 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -57,7 +57,7 @@ jobs: git clean -fdx -e out if ($LASTEXITCODE -ne 0) { exit 1 } - - name: Build (contract check, export gate 335, engine.json) + - name: Build (contract check, export gate 336, 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 856, engine.json) + - name: Build (contract check, export gate 857, 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 850, engine.json) + - name: Build (contract check, export gate 851, engine.json) run: | version=local case "$GITHUB_REF" in refs/tags/v*) version="$GITHUB_REF_NAME";; esac diff --git a/build/Dockerfile b/build/Dockerfile index b27520d..5831abe 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -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 856 "$VERSION" /out + && export-gate nm /out/libygol-engine.so 857 "$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 850 "$VERSION" /out + && export-gate "$NDK_DIR"/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-nm /out/libygol-engine.so 851 "$VERSION" /out FROM scratch AS android COPY --from=android-build /out/ / diff --git a/build/windows.ps1 b/build/windows.ps1 index 2f17d1b..c6c3738 100644 --- a/build/windows.ps1 +++ b/build/windows.ps1 @@ -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 335 symbols (start_server, + the script FAILS unless the DLL exports exactly 336 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 = 335 + [int]$ExpectedExports = 336 ) $ErrorActionPreference = "Stop" diff --git a/contract/ocgapi.h b/contract/ocgapi.h index 08eac25..d487a4d 100644 --- a/contract/ocgapi.h +++ b/contract/ocgapi.h @@ -90,6 +90,15 @@ OCGCORE_API int32_t ygol_preview_attack(intptr_t pduel, uint8_t playerid, uint8_ // 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); +// [YGOL] v1.7.0 (prompt context, TICKET-451): which effect asks the prompt the engine is parked on, read only. +// playerid = the answering player. out (22 bytes): version (1), has_effect, uint32 code (the handler's current +// code), controller, location, sequence, position, uint64 description, uint16 effect_index (the order the +// card's script registered the effect in initial_effect; 0xffff unknown), phase (1 cost, 2 target, 3 operation), +// chain link (0 none). has_effect 0 = no effect function runs: every other byte 0, effect_index 0xffff. A +// handler playerid does not control and that is not face-up writes code 0, effect_index 0xffff, description 0. +// Returns 22, 0 refused (bad pointer, bad player); a refusal writes nothing. +OCGCORE_API int32_t ygol_query_prompt_context(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); diff --git a/core/card.cpp b/core/card.cpp index 78fe41c..219adda 100644 --- a/core/card.cpp +++ b/core/card.cpp @@ -1958,10 +1958,14 @@ int32_t card::add_effect(effect* peffect) { return 0; peffect->id = pduel->game_field->infos.field_id++; peffect->card_type = data.type; - if (get_status(STATUS_INITIALIZING)) + if (get_status(STATUS_INITIALIZING)) { peffect->flag[0] |= EFFECT_FLAG_INITIAL; - else if (get_status(STATUS_COPYING_EFFECT)) - peffect->flag[0] |= EFFECT_FLAG_COPY; + peffect->ygol_script_index = (uint16_t)initial_effect.size(); // [YGOL] v1.7.0 prompt context: the script's registration order + } else { + peffect->ygol_script_index = 0xffff; + if (get_status(STATUS_COPYING_EFFECT)) + peffect->flag[0] |= EFFECT_FLAG_COPY; + } if (get_status(STATUS_COPYING_EFFECT)) { peffect->copy_id = pduel->game_field->infos.copy_id; peffect->reset_flag |= pduel->game_field->core.copy_reset; diff --git a/core/effect.h b/core/effect.h index 566c612..473d8cb 100644 --- a/core/effect.h +++ b/core/effect.h @@ -65,6 +65,7 @@ public: int32_t operation{ 0 }; uint8_t cost_checked{ FALSE }; uint8_t is_granted{ 0 }; + uint16_t ygol_script_index{ 0xffff }; // [YGOL] v1.7.0 prompt context: registration order in the card's initial_effect, 0xffff = not from it effect_set required_handorset_effects; LuaParamType object_type{ PARAM_TYPE_INT }; diff --git a/core/field.h b/core/field.h index eda1490..fb85cea 100644 --- a/core/field.h +++ b/core/field.h @@ -342,6 +342,15 @@ struct processor { uint8_t selfdes_disabled{ FALSE }; uint8_t overdraw[2]{}; int32_t check_level{ 0 }; + // [YGOL] v1.7.0 prompt context: the effect functions running now (cost / target / operation), innermost last + struct ygol_running_effect { + card* handler{ nullptr }; + uint32_t description{ 0 }; + uint16_t script_index{ 0xffff }; + uint8_t phase{ 0 }; + uint8_t chain_link{ 0 }; + }; + std::vector ygol_running; uint8_t shuffle_check_disabled{ FALSE }; uint8_t shuffle_hand_check[2]{}; uint8_t shuffle_deck_check[2]{}; diff --git a/core/ocgapi.cpp b/core/ocgapi.cpp index a071482..7be4e17 100644 --- a/core/ocgapi.cpp +++ b/core/ocgapi.cpp @@ -482,6 +482,45 @@ OCGCORE_API int32_t ygol_query_tag_cards(intptr_t pduel, uint8_t playerid, uint8 buffer_write(ptr, code); return (int32_t)(ptr - out); } +// [YGOL] v1.7.0 (prompt context) -- see ocgapi.h. Reads field::core.ygol_running, the cost / target / operation +// functions running now (processor.cpp); the innermost one is the effect that asks. +OCGCORE_API int32_t ygol_query_prompt_context(intptr_t pduel, uint8_t playerid, uint8_t* out) { + duel* pd = (duel*)pduel; + if(!pd || !out || !duel_set.count(pd) || !pd->game_field || !check_playerid(playerid)) + return 0; + const auto& running = pd->game_field->core.ygol_running; + card* handler = running.empty() ? nullptr : running.back().handler; + if(handler && !pd->cards.count(handler)) + handler = nullptr; + byte* ptr = out; + buffer_write(ptr, 1); + if(!handler) { + buffer_write(ptr, 0); + buffer_write(ptr, 0); + buffer_write(ptr, 0); + buffer_write(ptr, 0); + buffer_write(ptr, 0); + buffer_write(ptr, 0); + buffer_write(ptr, 0); + buffer_write(ptr, 0xffff); + buffer_write(ptr, 0); + buffer_write(ptr, 0); + return (int32_t)(ptr - out); + } + const auto& top = running.back(); + const bool visible = handler->current.controler == playerid || handler->is_position(POS_FACEUP); + buffer_write(ptr, 1); + buffer_write(ptr, visible ? handler->get_code() : 0); + buffer_write(ptr, handler->current.controler); + buffer_write(ptr, handler->current.location); + buffer_write(ptr, handler->current.sequence); + buffer_write(ptr, handler->current.position); + buffer_write(ptr, visible ? top.description : 0); + buffer_write(ptr, visible ? top.script_index : 0xffff); + buffer_write(ptr, top.phase); + buffer_write(ptr, top.chain_link); + 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; diff --git a/core/ocgapi.h b/core/ocgapi.h index 1ddc05b..d496450 100644 --- a/core/ocgapi.h +++ b/core/ocgapi.h @@ -87,6 +87,15 @@ OCGCORE_API int32_t ygol_preview_attack(intptr_t pduel, uint8_t playerid, uint8_ // 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); +// [YGOL] v1.7.0 (prompt context, TICKET-451): which effect asks the prompt the engine is parked on, read only. +// playerid = the answering player. out (22 bytes): version (1), has_effect, uint32 code (the handler's current +// code), controller, location, sequence, position, uint64 description, uint16 effect_index (the order the +// card's script registered the effect in initial_effect; 0xffff unknown), phase (1 cost, 2 target, 3 operation), +// chain link (0 none). has_effect 0 = no effect function runs: every other byte 0, effect_index 0xffff. A +// handler playerid does not control and that is not face-up writes code 0, effect_index 0xffff, description 0. +// Returns 22, 0 refused (bad pointer, bad player); a refusal writes nothing. +OCGCORE_API int32_t ygol_query_prompt_context(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); diff --git a/core/processor.cpp b/core/processor.cpp index 301c3e8..1c804a3 100644 --- a/core/processor.cpp +++ b/core/processor.cpp @@ -727,6 +727,28 @@ uint32_t field::process() { #ifdef _MSC_VER #pragma warning(pop) #endif +// [YGOL] v1.7.0 prompt context: remember which effect function runs, so ygol_query_prompt_context can name it at a prompt +static void ygol_push_running(field* pfield, effect* peffect, uint8_t phase) { + processor::ygol_running_effect running; + running.handler = peffect->get_handler(); + if(!running.handler) + running.handler = peffect->owner; + running.description = peffect->description; + running.script_index = peffect->ygol_script_index; + running.phase = phase; + auto& chain = pfield->core.current_chain; + for(auto it = chain.rbegin(); it != chain.rend(); ++it) { + if(it->triggering_effect == peffect) { + running.chain_link = it->chain_count; + break; + } + } + pfield->core.ygol_running.push_back(running); +} +static void ygol_pop_running(field* pfield) { + if(!pfield->core.ygol_running.empty()) + pfield->core.ygol_running.pop_back(); +} int32_t field::execute_cost(uint16_t step, effect * triggering_effect, uint8_t triggering_player) { if(!triggering_effect->cost) { core.solving_event.splice(core.solving_event.begin(), core.sub_solving_event); @@ -754,6 +776,7 @@ int32_t field::execute_cost(uint16_t step, effect * triggering_effect, uint8_t t core.units.begin()->arg2 = core.shuffle_check_disabled; core.shuffle_check_disabled = FALSE; ++core.check_level; + ygol_push_running(this, triggering_effect, 1); } core.reason_effect = triggering_effect; core.reason_player = triggering_player; @@ -765,6 +788,7 @@ int32_t field::execute_cost(uint16_t step, effect * triggering_effect, uint8_t t core.reason_effect = 0; core.reason_player = PLAYER_NONE; --core.check_level; + ygol_pop_running(this); if(core.check_level == 0) { if(core.shuffle_hand_check[0]) shuffle(0, LOCATION_HAND); @@ -806,6 +830,7 @@ int32_t field::execute_operation(uint16_t step, effect * triggering_effect, uint core.units.begin()->arg2 = core.shuffle_check_disabled; core.shuffle_check_disabled = FALSE; ++core.check_level; + ygol_push_running(this, triggering_effect, 3); } core.reason_effect = triggering_effect; core.reason_player = triggering_player; @@ -817,6 +842,7 @@ int32_t field::execute_operation(uint16_t step, effect * triggering_effect, uint core.reason_effect = 0; core.reason_player = PLAYER_NONE; --core.check_level; + ygol_pop_running(this); if(core.check_level == 0) { if(core.shuffle_hand_check[0]) shuffle(0, LOCATION_HAND); @@ -863,6 +889,7 @@ int32_t field::execute_target(uint16_t step, effect * triggering_effect, uint8_t core.units.begin()->arg2 = core.shuffle_check_disabled; core.shuffle_check_disabled = FALSE; ++core.check_level; + ygol_push_running(this, triggering_effect, 2); } core.reason_effect = triggering_effect; core.reason_player = triggering_player; @@ -874,6 +901,7 @@ int32_t field::execute_target(uint16_t step, effect * triggering_effect, uint8_t core.reason_effect = 0; core.reason_player = PLAYER_NONE; --core.check_level; + ygol_pop_running(this); if(core.check_level == 0) { if(core.shuffle_hand_check[0]) shuffle(0, LOCATION_HAND);