From e8c64d6ea231b7bfc40579ffeb48d36833cfda9c Mon Sep 17 00:00:00 2001 From: ragnarok-clanker Date: Fri, 30 Oct 2026 01:20:46 +0000 Subject: [PATCH] Decompile fn_08146 (CRuneSystemMgr::LoadScripts) Batch #4127 by Gravity: 0 byte-identical, 1 confirmed by peer review. - fn_08146 CRuneSystemMgr::LoadScripts: logic confirmed by peer review Peer-reviewed-by: youko, KWDev Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes). --- Source/Contents/Items/RuneSystem.cpp | 106 +++++++++++++++++++++++++++ Source/Contents/Items/RuneSystem.h | 1 + 2 files changed, 107 insertions(+) diff --git a/Source/Contents/Items/RuneSystem.cpp b/Source/Contents/Items/RuneSystem.cpp index 7c86c123..4aa33c09 100644 --- a/Source/Contents/Items/RuneSystem.cpp +++ b/Source/Contents/Items/RuneSystem.cpp @@ -4,15 +4,22 @@ #include "Contents/Items/ItemInfo.h" #include "Network/Connection/Connection.h" #include "Network/Packets/PacketLengths.h" +#include "Script/LuaFileOperations.h" #include "Script/LuaScript.h" +#include "Script/NLuaState.h" #include "Utility/Text/FormatString.h" extern "C" { +#include #include +#include } +#include #include #include +#include +#include // GLOBAL: gl_24845 CRuneSystemMgr* g_runeSystemMgr; @@ -448,6 +455,105 @@ const char* RuneData::GetResName() const { return this->m_resName.c_str(); } +// OFFSET: 0x00767250 +// FUNCTION: fn_08146 +bool CRuneSystemMgr::LoadScripts() { + NLuaState lua; + if (!lua.IsValid()) { + return false; + } + + lua_State* state = lua.GetState(); + luaL_openlibs(state); + lua_register(state, "Add_Decom_ItemNum", AddDecomItemNum); + lua_register(state, "AdditemDecomType", AddItemDecomType); + lua_register(state, "AdditemDecom", AddItemDecom); + lua_register(state, "AddGradeType_Fail", AddGradeTypeFail); + lua_register(state, "AddGradeType", AddGradeType); + lua_register(state, "AddItemListTable_Type", AddItemListTableType); + lua_register(state, "AddTag", AddTag); + lua_register(state, "SetRuneSysteminfo", SetRuneSystemInfo); + lua_register(state, "AddRune", AddRuneData); + lua_register(state, "SetRune_UpGradeTable", SetRuneUpGradeTable); + lua_register(state, "AddRune_SlotCollectionList", AddRuneSlotCollectionList); + lua_register(state, "AddRune_GradeList", AddRuneGradeList); + lua_register(state, "SetRune_DisplayName", SetRuneDisplayName); + lua_register(state, "AddRune_Description", AddRuneDescription); + lua_register(state, "AddRuneSetReward", AddRuneSetReward); + + if (!LoadLuaResource(state, "System\\Rune\\runeSystem_table.lub", 0) || lua_pcall(state, 0, 0, 0) != 0) { + MessageBoxA(nullptr, lua_tostring(state, -1), "System\\Rune\\runeSystem_table.lub", 0); + return false; + } + + if (!LoadLuaResource(state, "System\\Rune\\itemDecom.lub", 0) || lua_pcall(state, 0, 0, 0) != 0) { + MessageBoxA(nullptr, lua_tostring(state, -1), "System\\Rune\\itemDecom.lub", 0); + return false; + } + + if (!LoadLuaResource(state, "System\\Rune\\runesystemid.lub", 0) || lua_pcall(state, 0, 0, 0) != 0) { + MessageBoxA(nullptr, lua_tostring(state, -1), "System\\Rune\\runesystemid.lub", 0); + return false; + } + + if (!LoadLuaResource(state, "System\\Rune\\rune_info.lub", 0) || lua_pcall(state, 0, 0, 0) != 0) { + MessageBoxA(nullptr, lua_tostring(state, -1), "System\\Rune\\collection_info.lub", 0); + return false; + } + + if (!LoadLuaResource(state, "System\\Rune\\rune_desc.lub", 0) || lua_pcall(state, 0, 0, 0) != 0) { + MessageBoxA(nullptr, lua_tostring(state, -1), "System\\Rune\\collection_desc.lub", 0); + return false; + } + + if (!LoadLuaResource(state, "System\\Rune\\runeset_info.lub", 0) || lua_pcall(state, 0, 0, 0) != 0) { + MessageBoxA(nullptr, lua_tostring(state, -1), "System\\Rune\\rune_info.lub", 0); + return false; + } + + if (!LoadLuaResource(state, "System\\Rune\\runeset_desc.lub", 0) || lua_pcall(state, 0, 0, 0) != 0) { + MessageBoxA(nullptr, lua_tostring(state, -1), "System\\Rune\\rune_desc.lub", 0); + return false; + } + + if (!LoadLuaResource(state, "System\\Rune\\runesystem_f.lub", 0) || lua_pcall(state, 0, 0, 0) != 0) { + MessageBoxA(nullptr, lua_tostring(state, -1), "System\\Rune\\runesystem_f.lub", 0); + return false; + } + + if (!LoadLuaResource(state, "System\\Rune\\runeset_reward.lub", 0) || lua_pcall(state, 0, 0, 0) != 0) { + MessageBoxA(nullptr, lua_tostring(state, -1), "System\\Rune\\runeset_reward.lub", 0); + return false; + } + + lua_getglobal(state, "main_rune"); + if (lua_pcall(state, 0, 2, 0) != 0) { + MessageBoxA(nullptr, lua_tostring(state, -1), "CRuneSystemMgr main_rune X", 0); + return false; + } + + lua_getglobal(state, "main_runeset_reward"); + if (lua_pcall(state, 0, 2, 0) != 0) { + MessageBoxA(nullptr, lua_tostring(state, -1), "CRuneSystemMgr main_runeset_reward X", 0); + return false; + } + + if (!lua_isstring(state, -1)) { + MessageBoxA(nullptr, "second return value is not string...", "CRuneSystemMgr", 0); + return false; + } + + if (!lua_toboolean(state, -2)) { + std::string message = std::string("error found :") + lua_tostring(state, -1); + MessageBoxA(nullptr, message.c_str(), "CRuneSystemMgr", 0); + return false; + } + + std::sort(this->m_tags.begin(), this->m_tags.end(), [](const CTagData* left, const CTagData* right) { return left->m_id < right->m_id; }); + this->LoadDefaultTag(); + return true; +} + // OFFSET: 0x00767D20 // FUNCTION: fn_08147 void CRuneSystemMgr::Reset() { diff --git a/Source/Contents/Items/RuneSystem.h b/Source/Contents/Items/RuneSystem.h index 33af6df7..2f5147d4 100644 --- a/Source/Contents/Items/RuneSystem.h +++ b/Source/Contents/Items/RuneSystem.h @@ -162,6 +162,7 @@ public: int GetSelectTag() const; std::vector* GetDecomList(int itemId, int which); bool IsRequestPending() const; + bool LoadScripts(); void Reset(); void ClearCurRuneSet(); void LoadDefaultTag();