From 69007704fb2b1c222bd554fefc449fc6fbd84ec3 Mon Sep 17 00:00:00 2001 From: anxiousintrovert <82425472+anxiousintrovert@users.noreply.github.com> Date: Mon, 19 Oct 2026 07:54:18 -0500 Subject: [PATCH] Keep town world-map script result pointers in port-owned storage --- port/CMakeLists.txt | 7 ++++- port/include/stubs/edit.hpp | 3 +++ port/include/stubs/editloop3.hpp | 3 +++ port/src/world_map_result.cpp | 46 ++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 port/include/stubs/edit.hpp create mode 100644 port/src/world_map_result.cpp diff --git a/port/CMakeLists.txt b/port/CMakeLists.txt index d26cdde04..9db8f1750 100644 --- a/port/CMakeLists.txt +++ b/port/CMakeLists.txt @@ -71,6 +71,10 @@ add_custom_command(OUTPUT ${PORT_OVERRIDES} # of ps2/src: it declares what the port defines in place of code PORT leaves # out, and supplies or renames what the unit takes from MWCC alone. foreach(unit IN LISTS PS2_SOURCES) + set(private_overrides "") + if(unit STREQUAL "editloop3.cpp") + set(private_overrides --private-variables --private-functions) + endif() set(copy ${CMAKE_BINARY_DIR}/ps2_src/${unit}) string(REGEX REPLACE "\\.cpp$" ".hpp" header ${CMAKE_SOURCE_DIR}/port/include/stubs/${unit}) if(EXISTS ${header}) @@ -81,7 +85,7 @@ foreach(unit IN LISTS PS2_SOURCES) endif() add_custom_command(OUTPUT ${copy} COMMAND ${Python3_EXECUTABLE} ${PORT_OVERRIDE_SCRIPT} strip --overrides ${PORT_OVERRIDES} ${stubs} - ${port_override_defines} ${PS2_DIR}/${unit} ${copy} + ${private_overrides} ${port_override_defines} ${PS2_DIR}/${unit} ${copy} DEPENDS ${PS2_DIR}/${unit} ${PORT_OVERRIDES} ${PORT_OVERRIDE_SOURCES} ${PORT_OVERRIDE_SCRIPT} ${header} COMMENT "Removing overridden definitions from ps2/src/${unit}" VERBATIM) @@ -97,6 +101,7 @@ endforeach() set(PORT_OVERRIDES_CHECKED ${CMAKE_BINARY_DIR}/port_overrides.checked) add_custom_command(OUTPUT ${PORT_OVERRIDES_CHECKED} COMMAND ${Python3_EXECUTABLE} ${PORT_OVERRIDE_SCRIPT} check --overrides ${PORT_OVERRIDES} + --private-variables --private-functions --private-function-unit editloop3.cpp --stubs ${CMAKE_SOURCE_DIR}/port/include/stubs ${port_override_defines} ${PS2_DIR} -o ${PORT_OVERRIDES_CHECKED} DEPENDS ${PS2_ORIGINALS} ${PORT_OVERRIDES} ${PORT_OVERRIDE_SOURCES} ${PORT_OVERRIDE_SCRIPT} diff --git a/port/include/stubs/edit.hpp b/port/include/stubs/edit.hpp new file mode 100644 index 000000000..eb2d7306d --- /dev/null +++ b/port/include/stubs/edit.hpp @@ -0,0 +1,3 @@ +#pragma once + +#define EdMenuMode PortOriginalEdMenuMode diff --git a/port/include/stubs/editloop3.hpp b/port/include/stubs/editloop3.hpp index 491f5df07..c5856612e 100644 --- a/port/include/stubs/editloop3.hpp +++ b/port/include/stubs/editloop3.hpp @@ -1,5 +1,8 @@ #pragma once +#define menu_mode PortEventMenuMode +#define _WORLD_MAP PortWorldMapCommand + // The port's EdMoveVillager and EdMoveVillagerSubMap (port/src/editloop3.cpp) call this unit's // static EdSetVillagerNextPos, which gets a global forwarder; that also keeps clang from dropping // the static as unused. diff --git a/port/src/world_map_result.cpp b/port/src/world_map_result.cpp new file mode 100644 index 000000000..2cb838565 --- /dev/null +++ b/port/src/world_map_result.cpp @@ -0,0 +1,46 @@ +#include "common.h" + +#include + +#include "battlemenu.hpp" +#include "edit.hpp" +#include "runscript.hpp" + +/** + * Runs the original town menu handler. + */ +int PortOriginalEdMenuMode(); + +/** The menu requested by the current town event. */ +PORT_OVERRIDE int PortEventMenuMode = ED_MENU_NONE; + +namespace { + +/** The world-map command's native-width script result destination. */ +RS_STACKDATA *world_map_result = nullptr; + +} // namespace + +/** + * Opens the world map while retaining the script result pointer at native width. + */ +PORT_OVERRIDE int PortWorldMapCommand(RS_STACKDATA *stack, int argument_count) { + if (stack->type != RS_PTR) { + return 0; + } + world_map_result = stack->p; + PortEventMenuMode = ED_MENU_WORLD_MAP; + return 1; +} + +/** + * Publishes the world-map choice when its menu finishes. + */ +int EdMenuMode() { + const int done = PortOriginalEdMenuMode(); + if (done && PortEventMenuMode == ED_MENU_WORLD_MAP && world_map_result != nullptr) { + world_map_result->i = MenuMapJumpMode + 1; + world_map_result = nullptr; + } + return done; +}