From 3df4e5eeeb975e5c2ae51bb4cd645fe9f7d4390f Mon Sep 17 00:00:00 2001 From: VDm Date: Tue, 5 Aug 2025 01:49:09 +0400 Subject: [PATCH 1/2] feat(ui): implement CSimpleFrame_CreateTexture method --- src/ui/CSimpleFrameScript.cpp | 58 +++++++++++++++++++++++++++++++++-- src/ui/FrameScript.cpp | 10 +++++- 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/src/ui/CSimpleFrameScript.cpp b/src/ui/CSimpleFrameScript.cpp index 2f85412..739e317 100644 --- a/src/ui/CSimpleFrameScript.cpp +++ b/src/ui/CSimpleFrameScript.cpp @@ -1,10 +1,14 @@ #include "ui/CSimpleFrameScript.hpp" -#include "gx/Coordinate.hpp" #include "ui/CSimpleFrame.hpp" +#include "ui/CSimpleTexture.hpp" +#include "gx/Coordinate.hpp" #include "ui/FrameScript.hpp" +#include "ui/FrameXML.hpp" #include "ui/CBackdropGenerator.hpp" #include "util/Lua.hpp" #include "util/Unimplemented.hpp" +#include "util/StringTo.hpp" +#include #include #include #include @@ -19,7 +23,57 @@ int32_t CSimpleFrame_CreateTitleRegion(lua_State* L) { } int32_t CSimpleFrame_CreateTexture(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + int32_t type = CSimpleFrame::GetObjectType(); + CSimpleFrame* frame = static_cast(FrameScript_GetObjectThis(L, type)); + + const char* name = lua_isstring(L, 2) ? lua_tolstring(L, 2, nullptr) : nullptr; + + int32_t drawLayer = 2; + if (lua_isstring(L, 3)) { + StringToDrawLayer(lua_tolstring(L, 3, nullptr), drawLayer); + } + + XMLNode* frameNode = nullptr; + + if (lua_type(L, 4) == LUA_TSTRING) { + const char* tainted; + bool locked; + + const char* inheritName = lua_tolstring(L, 4, nullptr); + const char* frameName = frame->GetName(); + if (!frameName) { + frameName = ""; + } + + frameNode = FrameXML_AcquireHashNode(inheritName, tainted, locked); + if (!frameNode) { + luaL_error(L, "%s:CreateTexture(): Couldn't find inherited node \"%s\"", frameName, inheritName); + } + + if (locked) { + luaL_error(L, "%s:CreateTexture(): Recursively inherited node \"%s\"", frameName, inheritName); + } + } + + auto texture = NEW(CSimpleTexture, frame, drawLayer, 1); + if (name && *name) { + texture->SetName(name); + } + + if (frameNode) { + CStatus status; + texture->PostLoadXML(frameNode, &status); + FrameXML_ReleaseHashNode(lua_tolstring(L, 4, nullptr)); + } + + // TODO + + if (!texture->lua_registered) { + texture->RegisterScriptObject(nullptr); + } + + lua_rawgeti(L, LUA_REGISTRYINDEX, texture->lua_objectRef); + return 1; } int32_t CSimpleFrame_CreateFontString(lua_State* L) { diff --git a/src/ui/FrameScript.cpp b/src/ui/FrameScript.cpp index 7539bd7..597b4d4 100644 --- a/src/ui/FrameScript.cpp +++ b/src/ui/FrameScript.cpp @@ -418,7 +418,15 @@ int32_t FrameScript_ExecuteFile(const char* filePath, const char* a2, MD5_CTX* m MD5Update(md5, static_cast(fileBuffer), fileBytes); } - int32_t v10 = FrameScript_ExecuteBuffer(static_cast(fileBuffer), fileBytes, v11, status, a2); + char* cleanBuffer = static_cast(fileBuffer); + + // Skip UTF8 BOM + if (fileBytes >= 3 && memcmp(fileBuffer, "\xEF\xBB\xBF", 3) == 0) { + cleanBuffer += 3; + fileBytes -= 3; + } + + int32_t v10 = FrameScript_ExecuteBuffer(cleanBuffer, fileBytes, v11, status, a2); SFile::Unload(fileBuffer); From 0a0c327c464f948e949c8616b89613e8e5a9131c Mon Sep 17 00:00:00 2001 From: VDm Date: Tue, 5 Aug 2025 02:11:42 +0400 Subject: [PATCH 2/2] feat(gameui): make stubs of script methods --- src/gameui/GameScriptFunctions.cpp | 4 +++- src/gameui/scripts/GameScriptFunctionsActionBar.cpp | 4 +++- src/gameui/scripts/GameScriptFunctionsScriptEvents.cpp | 4 +++- src/gameui/scripts/GameScriptFunctionsTradeInfo.cpp | 8 ++++++-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/gameui/GameScriptFunctions.cpp b/src/gameui/GameScriptFunctions.cpp index f356375..28e27a9 100644 --- a/src/gameui/GameScriptFunctions.cpp +++ b/src/gameui/GameScriptFunctions.cpp @@ -493,7 +493,9 @@ static int32_t Script_ForceQuit(lua_State* L) { } static int32_t Script_GetCursorMoney(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + // TODO + lua_pushnumber(L, 0.0); + return 1; } static int32_t Script_DropCursorMoney(lua_State* L) { diff --git a/src/gameui/scripts/GameScriptFunctionsActionBar.cpp b/src/gameui/scripts/GameScriptFunctionsActionBar.cpp index 5f710e3..bc3edef 100644 --- a/src/gameui/scripts/GameScriptFunctionsActionBar.cpp +++ b/src/gameui/scripts/GameScriptFunctionsActionBar.cpp @@ -93,7 +93,9 @@ static int32_t Script_ChangeActionBarPage(lua_State* L) { } static int32_t Script_GetActionBarPage(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + // TODO + lua_pushinteger(L, 1); + return 1; } static int32_t Script_GetActionBarToggles(lua_State* L) { diff --git a/src/gameui/scripts/GameScriptFunctionsScriptEvents.cpp b/src/gameui/scripts/GameScriptFunctionsScriptEvents.cpp index c668e21..5435459 100644 --- a/src/gameui/scripts/GameScriptFunctionsScriptEvents.cpp +++ b/src/gameui/scripts/GameScriptFunctionsScriptEvents.cpp @@ -250,7 +250,9 @@ static int32_t Script_UnitLevel(lua_State* L) { } static int32_t Script_GetMoney(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + // TODO + lua_pushnumber(L, 10.0); + return 1; } static int32_t Script_GetHonorCurrency(lua_State* L) { diff --git a/src/gameui/scripts/GameScriptFunctionsTradeInfo.cpp b/src/gameui/scripts/GameScriptFunctionsTradeInfo.cpp index 4b0c8d7..3505ac4 100644 --- a/src/gameui/scripts/GameScriptFunctionsTradeInfo.cpp +++ b/src/gameui/scripts/GameScriptFunctionsTradeInfo.cpp @@ -41,11 +41,15 @@ static int32_t Script_CancelTradeAccept(lua_State* L) { } static int32_t Script_GetPlayerTradeMoney(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + // TODO + lua_pushnumber(L, 0.0); + return 1; } static int32_t Script_GetTargetTradeMoney(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + // TODO + lua_pushnumber(L, 0.0); + return 1; } static int32_t Script_PickupTradeMoney(lua_State* L) {