From 08de49f13dcebf307b1c0433f3caa43e3a3bc8e2 Mon Sep 17 00:00:00 2001 From: ragnarok-clanker Date: Fri, 30 Oct 2026 04:03:33 +0000 Subject: [PATCH] Decompile 2 functions in Source/Contents/Items/SelectPackageItemMgr.cpp, Source/Contents/Items/SelectPackageItemMgr.h Batch #4585 by eAthena: 0 byte-identical, 2 confirmed by peer review. - fn_04447 CSelectPackageItemMgr::LoadScript: logic confirmed by peer review - fn_04455 CSelectPackageItemMgr::LuaAddItem: logic confirmed by peer review Peer-reviewed-by: alisonrag, willerthal Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes). --- .../Contents/Items/SelectPackageItemMgr.cpp | 119 +++++++++++++++++- Source/Contents/Items/SelectPackageItemMgr.h | 4 + 2 files changed, 122 insertions(+), 1 deletion(-) diff --git a/Source/Contents/Items/SelectPackageItemMgr.cpp b/Source/Contents/Items/SelectPackageItemMgr.cpp index 986412ce..d9453dbe 100644 --- a/Source/Contents/Items/SelectPackageItemMgr.cpp +++ b/Source/Contents/Items/SelectPackageItemMgr.cpp @@ -1,10 +1,11 @@ #include "Contents/Items/SelectPackageItemMgr.h" #include "Network/TextEncoding.h" - +#include "Script/LuaInstance.h" extern "C" { #include } #include +#include // GLOBAL: gl_24790 template <> @@ -44,6 +45,27 @@ std::optional*> CSelectPackageItemMgr::FindItems(int pack return std::nullopt; } +// OFFSET: 0x0061EFF0 +// FUNCTION: fn_04447 +bool CSelectPackageItemMgr::LoadScript() { + CLuaInstance script; + script.SetGlobal("AddTab", CSelectPackageItemMgr::LuaAddTab); + script.SetGlobal("AddItem", CSelectPackageItemMgr::LuaAddItem); + if (script.LoadFile("LuaFiles514\\Lua Files\\SelectPackage\\SelectPackageItem_Cln.lub") == true) { + lua_State* state = script.GetState(); + if (state) { + lua_getfield(state, LUA_GLOBALSINDEX, "LoadTable"); + if (lua_pcall(state, 0, 0, 0) != 0) { + MessageBoxA(nullptr, lua_tolstring(state, -1, nullptr), "CSelectPackageItemMgr", 0); + } else { + lua_settop(state, -2); + } + } + } + + return false; +} + // OFFSET: 0x0061F9A0 // FUNCTION: fn_04454 template <> @@ -55,6 +77,101 @@ CSelectPackageItemMgr* Singleton::GetInstance() { return s_instance; } +// GLOBAL: gl_24907 +short g_itemOptionPlaceholderId = 9999; + +// OFFSET: 0x0061FA50 +// FUNCTION: fn_04455 +int CSelectPackageItemMgr::LuaAddItem(lua_State* L) { + if (!lua_isnumber(L, -10)) { + lua_pushboolean(L, 0); + lua_pushstring(L, "L_AddTab : 1st argument must be number"); + return 2; + } + if (!lua_isnumber(L, -9)) { + lua_pushboolean(L, 0); + lua_pushstring(L, "L_AddTab : 2nd argument must be number"); + return 2; + } + if (!lua_isnumber(L, -8)) { + lua_pushboolean(L, 0); + lua_pushstring(L, "L_AddTab : 3rd argument must be number"); + return 2; + } + if (!lua_isnumber(L, -7)) { + lua_pushboolean(L, 0); + lua_pushstring(L, "L_AddTab : 4th argument must be number"); + return 2; + } + if (!lua_isnumber(L, -6)) { + lua_pushboolean(L, 0); + lua_pushstring(L, "L_AddTab : 5th argument must be number"); + return 2; + } + if (!lua_isnumber(L, -5)) { + lua_pushboolean(L, 0); + lua_pushstring(L, "L_AddTab : 6th argument must be number"); + return 2; + } + if (!lua_isnumber(L, -4)) { + lua_pushboolean(L, 0); + lua_pushstring(L, "L_AddTab : 7th argument must be number"); + return 2; + } + if (lua_type(L, -3) != LUA_TBOOLEAN) { + lua_pushboolean(L, 0); + lua_pushstring(L, "L_AddTab : 8th argument must be boolean"); + return 2; + } + if (!lua_isnumber(L, -2)) { + lua_pushboolean(L, 0); + lua_pushstring(L, "L_AddTab : 9th argument must be number"); + return 2; + } + if (!lua_isnumber(L, -1)) { + lua_pushboolean(L, 0); + lua_pushstring(L, "L_AddTab : 10th argument must be number"); + return 2; + } + + int packageId = static_cast(lua_tonumber(L, -10)); + int tabIndex = static_cast(lua_tonumber(L, -9)); + const double index = lua_tonumber(L, -8); + const double itemId = lua_tonumber(L, -7); + const double quantity = lua_tonumber(L, -6); + const double option = lua_tonumber(L, -5); + const double value = lua_tonumber(L, -4); + const bool placeholder = lua_toboolean(L, -3) != 0; + const double refine = lua_tonumber(L, -2); + const double kind = lua_tonumber(L, -1); + + std::vector& items = CSelectPackageItemMgr::GetInstance()->m_packages[packageId][tabIndex].items; + const int slot = static_cast(index); + if (slot >= 0 && static_cast(slot) < items.size()) { + ITEM_INFO& item = items[slot]; + item.Reset(); + item.SetItemId(static_cast(itemId)); + item.identified = 1; + item.quantity = static_cast(quantity); + item.unknown_0000[0] = static_cast(static_cast(kind)); + item.unknown_0060 = static_cast(value); + item.unknown_0088 = static_cast(static_cast(refine)); + const int optionValue = static_cast(option); + if (optionValue != 0) { + item.unknown_0066 = 1; + item.unknown_0068 = optionValue; + } + if (placeholder) { + *reinterpret_cast(item.unknown_009C) = g_itemOptionPlaceholderId; + item.unknown_0098 = 3; + } + } + + lua_pushboolean(L, 1); + lua_pushstring(L, "good"); + return 2; +} + // OFFSET: 0x0061FD90 // FUNCTION: fn_04456 int CSelectPackageItemMgr::LuaAddTab(lua_State* L) { diff --git a/Source/Contents/Items/SelectPackageItemMgr.h b/Source/Contents/Items/SelectPackageItemMgr.h index a7476120..1becb6bf 100644 --- a/Source/Contents/Items/SelectPackageItemMgr.h +++ b/Source/Contents/Items/SelectPackageItemMgr.h @@ -12,6 +12,8 @@ struct lua_State; +extern short g_itemOptionPlaceholderId; + struct SelectPackageTab { /* 0000 */ std::string name; /* 0018 */ std::vector items; @@ -20,6 +22,8 @@ struct SelectPackageTab { class CSelectPackageItemMgr : public Singleton { public: static int LuaAddTab(lua_State* L); + static int LuaAddItem(lua_State* L); + static bool LoadScript(); /* 0004 */ std::map> m_packages;