From 0950f7dae3d0623ec59efe69dacdf5a6459395ff Mon Sep 17 00:00:00 2001 From: VDm Date: Tue, 5 Aug 2025 23:33:45 +0400 Subject: [PATCH] feat(console): add "script" command to debug LUA code --- src/console/CMakeLists.txt | 1 + src/console/Command.cpp | 2 +- src/console/command/Commands.hpp | 1 + src/console/command/default/Script.cpp | 8 +++++++ src/gameui/CGWorldFrame.cpp | 1 + src/gameui/GameScriptFunctions.cpp | 10 +++++++- src/ui/LuaExtraFuncs.cpp | 32 +++++++++++++++++++++++++- 7 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 src/console/command/default/Script.cpp diff --git a/src/console/CMakeLists.txt b/src/console/CMakeLists.txt index e17ebf9..eb8e56b 100644 --- a/src/console/CMakeLists.txt +++ b/src/console/CMakeLists.txt @@ -17,6 +17,7 @@ target_link_libraries(console PUBLIC common gx + ui storm PRIVATE client diff --git a/src/console/Command.cpp b/src/console/Command.cpp index cb5baba..fda37cb 100644 --- a/src/console/Command.cpp +++ b/src/console/Command.cpp @@ -231,7 +231,7 @@ void ConsoleInitializeCommonCommand() { } void ConsoleInitializeDebugCommand() { - // TODO + ConsoleCommandRegister("script", ConsoleCommand_Script, DEFAULT, nullptr); } int32_t ConsoleCommandComplete(const char* partial, const char** previous, int32_t direction) { diff --git a/src/console/command/Commands.hpp b/src/console/command/Commands.hpp index 93a427f..d439bc0 100644 --- a/src/console/command/Commands.hpp +++ b/src/console/command/Commands.hpp @@ -12,6 +12,7 @@ int32_t CCGxRestart(const char* command, const char* argument); DECLARE_COMMAND(Quit); DECLARE_COMMAND(Ver); DECLARE_COMMAND(SetMap); +DECLARE_COMMAND(Script); DECLARE_COMMAND(Help); DECLARE_COMMAND(FontColor); diff --git a/src/console/command/default/Script.cpp b/src/console/command/default/Script.cpp new file mode 100644 index 0000000..a8f8651 --- /dev/null +++ b/src/console/command/default/Script.cpp @@ -0,0 +1,8 @@ +#include "console/Command.hpp" +#include "console/command/Commands.hpp" +#include "ui/FrameScript.hpp" + +DECLARE_COMMAND(Script) { + FrameScript_Execute(arguments, "CONSOLE", nullptr); + return 1; +} diff --git a/src/gameui/CGWorldFrame.cpp b/src/gameui/CGWorldFrame.cpp index f9b2b28..d5fe728 100644 --- a/src/gameui/CGWorldFrame.cpp +++ b/src/gameui/CGWorldFrame.cpp @@ -9,6 +9,7 @@ #include "world/CWorldScene.hpp" #include "gameui/camera/CGCamera.hpp" #include "event/EvtKeyDown.hpp" +#include "console/Console.hpp" #include "model/Model2.hpp" diff --git a/src/gameui/GameScriptFunctions.cpp b/src/gameui/GameScriptFunctions.cpp index 1b5b62a..c674e1a 100644 --- a/src/gameui/GameScriptFunctions.cpp +++ b/src/gameui/GameScriptFunctions.cpp @@ -7,6 +7,7 @@ #include "gameui/CGDressUpModelFrame.hpp" #include "gameui/CGTabardModelFrame.hpp" #include "gameui/CGQuestPOIFrame.hpp" +#include "console/Console.hpp" #include "ui/FrameXML.hpp" #include "ui/FrameScript.hpp" #include "util/Lua.hpp" @@ -1262,7 +1263,14 @@ static int32_t Script_IsThreatWarningEnabled(lua_State* L) { } static int32_t Script_ConsoleAddMessage(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + if (!lua_isstring(L, 1)) { + return luaL_error(L, "Usage: ConsoleAddMessage(string)"); + } + auto text = lua_tolstring(L, 1, 0); + if (text && *text) { + ConsolePrintf("%s", text); + } + return 0; } static int32_t Script_GetItemUniqueness(lua_State* L) { diff --git a/src/ui/LuaExtraFuncs.cpp b/src/ui/LuaExtraFuncs.cpp index f7362a3..9bde9ef 100644 --- a/src/ui/LuaExtraFuncs.cpp +++ b/src/ui/LuaExtraFuncs.cpp @@ -60,7 +60,37 @@ int32_t strsplit(lua_State* L) { } int32_t strjoin(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + size_t length = 0; + auto v9 = luaL_checklstring(L, 1, &length); + int32_t v1 = lua_gettop(L); + int32_t v2 = v1 - 1; + if (length) { + if (v1 == 1) { + lua_pushstring(L, ""); + return 1; + } else { + int32_t v4 = 2 * v2; + int32_t v8 = 2 * v2; + if (!lua_checkstack(L, 2 * v2)) + return luaL_error(L, "strjoin(): Stack overflow"); + if (v2 > 1) { + int32_t v5 = 3; + int32_t v6 = v2 - 1; + do { + lua_pushlstring(L, v9, length); + lua_insert(L, v5); + v5 += 2; + --v6; + } while (v6); + v4 = v8; + } + lua_concat(L, v4 - 1); + return 1; + } + } else { + lua_concat(L, v1); + return 1; + } } int32_t sub_816C40(lua_State* L) {