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).
This commit is contained in:
parent
151d6b8bd9
commit
08de49f13d
2 changed files with 122 additions and 1 deletions
|
|
@ -1,10 +1,11 @@
|
|||
#include "Contents/Items/SelectPackageItemMgr.h"
|
||||
#include "Network/TextEncoding.h"
|
||||
|
||||
#include "Script/LuaInstance.h"
|
||||
extern "C" {
|
||||
#include <lua.h>
|
||||
}
|
||||
#include <new>
|
||||
#include <windows.h>
|
||||
|
||||
// GLOBAL: gl_24790
|
||||
template <>
|
||||
|
|
@ -44,6 +45,27 @@ std::optional<std::vector<ITEM_INFO>*> 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<CSelectPackageItemMgr>::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<int>(lua_tonumber(L, -10));
|
||||
int tabIndex = static_cast<int>(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<ITEM_INFO>& items = CSelectPackageItemMgr::GetInstance()->m_packages[packageId][tabIndex].items;
|
||||
const int slot = static_cast<int>(index);
|
||||
if (slot >= 0 && static_cast<std::size_t>(slot) < items.size()) {
|
||||
ITEM_INFO& item = items[slot];
|
||||
item.Reset();
|
||||
item.SetItemId(static_cast<int>(itemId));
|
||||
item.identified = 1;
|
||||
item.quantity = static_cast<int>(quantity);
|
||||
item.unknown_0000[0] = static_cast<unsigned char>(static_cast<int>(kind));
|
||||
item.unknown_0060 = static_cast<int>(value);
|
||||
item.unknown_0088 = static_cast<short>(static_cast<int>(refine));
|
||||
const int optionValue = static_cast<int>(option);
|
||||
if (optionValue != 0) {
|
||||
item.unknown_0066 = 1;
|
||||
item.unknown_0068 = optionValue;
|
||||
}
|
||||
if (placeholder) {
|
||||
*reinterpret_cast<short*>(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) {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@
|
|||
|
||||
struct lua_State;
|
||||
|
||||
extern short g_itemOptionPlaceholderId;
|
||||
|
||||
struct SelectPackageTab {
|
||||
/* 0000 */ std::string name;
|
||||
/* 0018 */ std::vector<ITEM_INFO> items;
|
||||
|
|
@ -20,6 +22,8 @@ struct SelectPackageTab {
|
|||
class CSelectPackageItemMgr : public Singleton<CSelectPackageItemMgr> {
|
||||
public:
|
||||
static int LuaAddTab(lua_State* L);
|
||||
static int LuaAddItem(lua_State* L);
|
||||
static bool LoadScript();
|
||||
|
||||
/* 0004 */ std::map<int, std::map<int, SelectPackageTab>> m_packages;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue