From f793aa6e80def0934aff4879fb0e78a479cbbc23 Mon Sep 17 00:00:00 2001 From: ragnarok-clanker Date: Thu, 5 Nov 2026 12:25:12 +0000 Subject: [PATCH] Decompile 3 functions in Source/Contents/Items/RuneSystem.cpp Batch #12226 by Yommy: 0 byte-identical, 3 confirmed by peer review. - fn_08136 CRuneSystemMgr::GetGradeValue: logic confirmed by peer review - fn_08146 CRuneSystemMgr::LoadScripts: logic confirmed by peer review - fn_08152 CRuneSystemMgr::SendRequest: logic confirmed by peer review Peer-reviewed-by: KWDev, Toshiro, cremane Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes). --- Source/Contents/Items/RuneSystem.cpp | 165 ++++++++++++++------------- 1 file changed, 86 insertions(+), 79 deletions(-) diff --git a/Source/Contents/Items/RuneSystem.cpp b/Source/Contents/Items/RuneSystem.cpp index ced8bf6a..56681655 100644 --- a/Source/Contents/Items/RuneSystem.cpp +++ b/Source/Contents/Items/RuneSystem.cpp @@ -360,13 +360,14 @@ int CRuneSystemMgr::GetGradeValue(RuneSetData* runeSet) { const auto found = this->m_gradeTypes.find(runeSet->m_gradeType); if (found != this->m_gradeTypes.end()) { const unsigned int grade = runeSet->m_grade; - if (grade < found->second.size()) { + if (found->second.size() > grade) { + int failValue = 0; const auto fail = this->m_gradeFailTypes.find(runeSet->m_gradeFailType); - if (fail != this->m_gradeFailTypes.end() && grade < fail->second.size()) { - return runeSet->m_gradeLevel * fail->second[grade] + found->second[grade]; + if (fail != this->m_gradeFailTypes.end() && fail->second.size() > grade) { + failValue = fail->second[grade]; } - return found->second[grade]; + return runeSet->m_gradeLevel * failValue + found->second[grade]; } } } @@ -470,88 +471,87 @@ bool CRuneSystemMgr::LoadScripts() { 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); + luaL_openlibs(lua.GetState()); + lua_register(lua.GetState(), "Add_Decom_ItemNum", AddDecomItemNum); + lua_register(lua.GetState(), "AdditemDecomType", AddItemDecomType); + lua_register(lua.GetState(), "AdditemDecom", AddItemDecom); + lua_register(lua.GetState(), "AddGradeType_Fail", AddGradeTypeFail); + lua_register(lua.GetState(), "AddGradeType", AddGradeType); + lua_register(lua.GetState(), "AddItemListTable_Type", AddItemListTableType); + lua_register(lua.GetState(), "AddTag", AddTag); + lua_register(lua.GetState(), "SetRuneSysteminfo", SetRuneSystemInfo); + lua_register(lua.GetState(), "AddRune", AddRuneData); + lua_register(lua.GetState(), "SetRune_UpGradeTable", SetRuneUpGradeTable); + lua_register(lua.GetState(), "AddRune_SlotCollectionList", AddRuneSlotCollectionList); + lua_register(lua.GetState(), "AddRune_GradeList", AddRuneGradeList); + lua_register(lua.GetState(), "SetRune_DisplayName", SetRuneDisplayName); + lua_register(lua.GetState(), "AddRune_Description", AddRuneDescription); + lua_register(lua.GetState(), "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); + if (!LoadLuaResource(lua.GetState(), "System\\Rune\\runeSystem_table.lub", 0) || lua_pcall(lua.GetState(), 0, 0, 0) != 0) { + MessageBoxA(nullptr, lua_tostring(lua.GetState(), -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); + if (!LoadLuaResource(lua.GetState(), "System\\Rune\\itemDecom.lub", 0) || lua_pcall(lua.GetState(), 0, 0, 0) != 0) { + MessageBoxA(nullptr, lua_tostring(lua.GetState(), -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); + if (!LoadLuaResource(lua.GetState(), "System\\Rune\\runesystemid.lub", 0) || lua_pcall(lua.GetState(), 0, 0, 0) != 0) { + MessageBoxA(nullptr, lua_tostring(lua.GetState(), -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); + if (!LoadLuaResource(lua.GetState(), "System\\Rune\\rune_info.lub", 0) || lua_pcall(lua.GetState(), 0, 0, 0) != 0) { + MessageBoxA(nullptr, lua_tostring(lua.GetState(), -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); + if (!LoadLuaResource(lua.GetState(), "System\\Rune\\rune_desc.lub", 0) || lua_pcall(lua.GetState(), 0, 0, 0) != 0) { + MessageBoxA(nullptr, lua_tostring(lua.GetState(), -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); + if (!LoadLuaResource(lua.GetState(), "System\\Rune\\runeset_info.lub", 0) || lua_pcall(lua.GetState(), 0, 0, 0) != 0) { + MessageBoxA(nullptr, lua_tostring(lua.GetState(), -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); + if (!LoadLuaResource(lua.GetState(), "System\\Rune\\runeset_desc.lub", 0) || lua_pcall(lua.GetState(), 0, 0, 0) != 0) { + MessageBoxA(nullptr, lua_tostring(lua.GetState(), -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); + if (!LoadLuaResource(lua.GetState(), "System\\Rune\\runesystem_f.lub", 0) || lua_pcall(lua.GetState(), 0, 0, 0) != 0) { + MessageBoxA(nullptr, lua_tostring(lua.GetState(), -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); + if (!LoadLuaResource(lua.GetState(), "System\\Rune\\runeset_reward.lub", 0) || lua_pcall(lua.GetState(), 0, 0, 0) != 0) { + MessageBoxA(nullptr, lua_tostring(lua.GetState(), -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); + lua_getglobal(lua.GetState(), "main_rune"); + if (lua_pcall(lua.GetState(), 0, 2, 0) != 0) { + MessageBoxA(nullptr, lua_tostring(lua.GetState(), -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); + lua_getglobal(lua.GetState(), "main_runeset_reward"); + if (lua_pcall(lua.GetState(), 0, 2, 0) != 0) { + MessageBoxA(nullptr, lua_tostring(lua.GetState(), -1), "CRuneSystemMgr main_runeset_reward X", 0); return false; } - if (!lua_isstring(state, -1)) { + if (!lua_isstring(lua.GetState(), -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); + if (!lua_toboolean(lua.GetState(), -2)) { + std::string message = std::string("error found :") + lua_tostring(lua.GetState(), -1); MessageBoxA(nullptr, message.c_str(), "CRuneSystemMgr", 0); return false; } @@ -651,8 +651,16 @@ int CRuneSystemMgr::SendRequest(int packetId, RuneData* rune, int value) { return 0; } - int listId; switch (packetId) { + case 0x0C16: { + RuneSelectPacket packet; + packet.id = static_cast(packetId); + packet.tagId = static_cast(rune->m_tagId); + packet.runeId = static_cast(rune->m_id); + packet.value = static_cast(value); + GetRagConnection().Send(reinterpret_cast(GetRagConnection()).FixedLength(packetId), &packet); + return 1; + } case 0x0BCB: { CTagData* tag = this->GetTag(value); if (!tag) { @@ -666,53 +674,52 @@ int CRuneSystemMgr::SendRequest(int packetId, RuneData* rune, int value) { RuneTagPacket packet; packet.id = static_cast(packetId); packet.tagId = static_cast(tag->m_id); - GetRagConnection().Send(g_packetLengths.FixedLength(packetId), &packet); + GetRagConnection().Send(reinterpret_cast(GetRagConnection()).FixedLength(packetId), &packet); return 1; } case 0x0BCE: - case 0x0BD0: - listId = rune->m_activeType; - break; - case 0x0BD2: - listId = static_cast(rune)->GetGradeValue(); - break; + case 0x0BD0: { + if (!this->HasRequiredItems(rune->m_activeType)) { + return 0; + } + + RuneItemPacket packet; + packet.id = static_cast(packetId); + packet.tagId = static_cast(rune->m_tagId); + packet.runeId = static_cast(rune->m_id); + GetRagConnection().Send(reinterpret_cast(GetRagConnection()).FixedLength(packetId), &packet); + this->m_requestPending = true; + return 1; + } + case 0x0BD2: { + if (!this->HasRequiredItems(static_cast(rune)->GetGradeValue())) { + return 0; + } + + RuneItemPacket packet; + packet.id = static_cast(packetId); + packet.tagId = static_cast(rune->m_tagId); + packet.runeId = static_cast(rune->m_id); + GetRagConnection().Send(reinterpret_cast(GetRagConnection()).FixedLength(packetId), &packet); + this->m_requestPending = true; + return 1; + } case 0x0BD4: { RuneHeaderPacket packet; packet.id = static_cast(packetId); - GetRagConnection().Send(g_packetLengths.FixedLength(packetId), &packet); + GetRagConnection().Send(reinterpret_cast(GetRagConnection()).FixedLength(packetId), &packet); return 1; } case 0x0BD6: { RuneIdPacket packet; packet.id = static_cast(packetId); packet.runeId = static_cast(rune->m_id); - GetRagConnection().Send(g_packetLengths.FixedLength(packetId), &packet); - return 1; - } - case 0x0C16: { - RuneSelectPacket packet; - packet.id = static_cast(packetId); - packet.tagId = static_cast(rune->m_tagId); - packet.runeId = static_cast(rune->m_id); - packet.value = static_cast(value); - GetRagConnection().Send(g_packetLengths.FixedLength(packetId), &packet); + GetRagConnection().Send(reinterpret_cast(GetRagConnection()).FixedLength(packetId), &packet); return 1; } default: return 1; } - - if (!this->HasRequiredItems(listId)) { - return 0; - } - - RuneItemPacket packet; - packet.id = static_cast(packetId); - packet.tagId = static_cast(rune->m_tagId); - packet.runeId = static_cast(rune->m_id); - GetRagConnection().Send(g_packetLengths.FixedLength(packetId), &packet); - this->m_requestPending = true; - return 1; } // OFFSET: 0x007684C0