From 88b2de90c3d016c2e3f0bcf44492c5328561a1a5 Mon Sep 17 00:00:00 2001 From: ragnarok-clanker Date: Tue, 3 Nov 2026 12:38:48 +0000 Subject: [PATCH] Maintenance: [forced, user-approved] Family G26: remove MerchantShopRefresh and StoreBackupContext (inventory rows 57, 99). Refresh 0 Batch #10251 by ragnarok-clanker: forced by an admin (2 lower score(s), 10 changed function(s)); checked with 244 compiled unit(s), including every includer of Source/Contents/Async/AsyncWorkMgr.h, Source/Contents/Store/MCStoreInfoBackup.h, Source/Contents/Store/MCStoreInfoBackupAsyncWork.h, Source/UI/Shop/UIMerchantShopMakeWnd.h, Source/UI/Shop/MerchantShopRefresh.h. Deletes: Source/UI/Shop/MerchantShopRefresh.h --- Source/Contents/Async/AsyncWorkMgr.cpp | 5 +- Source/Contents/Async/AsyncWorkMgr.h | 5 +- Source/Contents/Store/MCStoreInfoBackup.cpp | 71 +++------- Source/Contents/Store/MCStoreInfoBackup.h | 22 +-- .../Store/MCStoreInfoBackupAsyncWork.cpp | 10 +- .../Store/MCStoreInfoBackupAsyncWork.h | 11 +- Source/Contents/Store/StoreBackupData.cpp | 12 ++ Source/UI/Shop/MerchantShopRefresh.cpp | 134 ++++++++---------- Source/UI/Shop/MerchantShopRefresh.h | 34 ----- Source/UI/Shop/UIMerchantShopMakeWnd.h | 1 + 10 files changed, 105 insertions(+), 200 deletions(-) delete mode 100644 Source/UI/Shop/MerchantShopRefresh.h diff --git a/Source/Contents/Async/AsyncWorkMgr.cpp b/Source/Contents/Async/AsyncWorkMgr.cpp index abb02dae..0c3d0cf3 100644 --- a/Source/Contents/Async/AsyncWorkMgr.cpp +++ b/Source/Contents/Async/AsyncWorkMgr.cpp @@ -200,13 +200,12 @@ void CAsyncWorkMgr::LoadPartyList( // OFFSET: 0x00574B30 // FUNCTION: fn_02509 void CAsyncWorkMgr::LoadStore( - std::uint32_t accountId, std::uint32_t characterId, std::string world, std::string url, std::string token, int type, CMCStoreInfoBackup& owner, - StoreBackupContext& context + std::uint32_t accountId, std::uint32_t characterId, std::string world, std::string url, std::string token, int type ) { NAsyncWorkPtr work(this->m_pools, "MerchantStoreInformation_Load"); if (work.Get()) { - static_cast(work.Get())->Bind(url, accountId, characterId, world, token, type, owner, context); + static_cast(work.Get())->Bind(url, accountId, characterId, world, token, type); this->Submit(work); } } diff --git a/Source/Contents/Async/AsyncWorkMgr.h b/Source/Contents/Async/AsyncWorkMgr.h index 645f8fbc..570c0ab0 100644 --- a/Source/Contents/Async/AsyncWorkMgr.h +++ b/Source/Contents/Async/AsyncWorkMgr.h @@ -7,11 +7,9 @@ class CAsyncWorkRecycleObjectPoolMgr; class CConnection; class CEmblemDataMgr; -class CMCStoreInfoBackup; #include "UI/Window/WindowManagerWindows.h" struct AccountConfigLoad; struct CharacterConfigLoad; -struct StoreBackupContext; class CAsyncWorkMgr : public NAsyncWorkMgr { public: @@ -42,8 +40,7 @@ public: WindowManagerWindows& windows ); void LoadStore( - std::uint32_t accountId, std::uint32_t characterId, std::string world, std::string url, std::string token, int type, CMCStoreInfoBackup& owner, - StoreBackupContext& context + std::uint32_t accountId, std::uint32_t characterId, std::string world, std::string url, std::string token, int type ); void SaveStore(std::uint32_t accountId, std::uint32_t characterId, std::string world, std::string url, std::string token, std::string data, int type); void RegisterParty(std::uint32_t accountId, std::uint32_t characterId, std::string world, std::string url, std::string token, CAdvenPartyInfo info); diff --git a/Source/Contents/Store/MCStoreInfoBackup.cpp b/Source/Contents/Store/MCStoreInfoBackup.cpp index dfc2a264..c54e0bde 100644 --- a/Source/Contents/Store/MCStoreInfoBackup.cpp +++ b/Source/Contents/Store/MCStoreInfoBackup.cpp @@ -3,6 +3,7 @@ #include "Contents/Store/MCStoreInfoBackup.h" #include "Contents/MessageTable.h" #include "Client/Session.h" +#include "Contents/ClientItemLists.h" #include "UI/Window/UIWindowMgr.h" #include "Utility/Async/AsyncDiagnostic.h" @@ -30,55 +31,24 @@ void CMCStoreInfoBackup::Clear() { // OFFSET: 0x00606BB0 // FUNCTION: fn_04234 -int CMCStoreInfoBackup::Restore(unsigned char wholeItem, int maximum, std::list& inventory, std::list& storeItems) { - auto saved = this->items.begin(); +int CMCStoreInfoBackup::Restore(unsigned char wholeItem, int maximum) { + ClientItemLists& lists = *reinterpret_cast(&g_session); int examined = 0; + auto saved = this->items.begin(); while (saved != this->items.end() && examined < maximum) { - const auto found = std::find_if(inventory.begin(), inventory.end(), [&](const ITEM_INFO& item) { - if (item.itemId != saved->itemId || std::memcmp(item.unknown_001C, saved->unknown_001C, sizeof(item.unknown_001C)) != 0 || - item.identified != saved->identified || item.unknown_0060 != saved->unknown_0060 || item.unknown_0088 != saved->unknown_0088 || - item.unknown_0098 != saved->unknown_0098) { - return false; - } + std::pair found = lists.FindItem1750(*saved, wholeItem); - const int count = item.unknown_0098; - - if (count >= 5) { - return false; - } - - return count <= 0 || std::memcmp(item.unknown_009C, saved->unknown_009C, static_cast(count) * 5) == 0; - }); - - if (found == inventory.end()) { + if (!found.first) { saved = this->items.erase(saved); } else { - ITEM_INFO item(*found); - if (wholeItem == 0) { - item.quantity = std::min(item.quantity, saved->quantity); + found.second.quantity = std::min(found.second.quantity, saved->quantity); } - if (item.unknown_0000[0] != 0) { - const auto offered = - std::find_if(storeItems.begin(), storeItems.end(), [&](const ITEM_INFO& value) { return value.unknown_0000[1] == item.unknown_0000[1]; }); - - if (offered == storeItems.end()) { - storeItems.push_back(item); - } else if (wholeItem == 0) { - offered->quantity += item.quantity; - } - - if (wholeItem != 0) { - inventory.erase(found); - } else { - found->quantity -= item.quantity; - - if (found->quantity <= 0) { - inventory.erase(found); - } - } + if (found.second.unknown_0000[1] != 0) { + lists.AddItem1768(found.second, wholeItem, 0); + lists.RemoveItem1750(found.second, wholeItem, 0); } ++saved; @@ -119,7 +89,7 @@ void CMCStoreInfoBackup::Reset(LuaScript& settings, LuaScript& tables, const cha // OFFSET: 0x00605FA0 // FUNCTION: fn_04232 void CMCStoreInfoBackup::CompleteLoad( - AsyncDiagnostic diagnostic, std::uint32_t, std::uint32_t, std::string, std::string response, StoreBackupContext& context + AsyncDiagnostic diagnostic, std::uint32_t, std::uint32_t, std::string, std::string response ) { if (!diagnostic.success) { return; @@ -136,15 +106,9 @@ void CMCStoreInfoBackup::CompleteLoad( const int type = root["Type"].asInt(); if (type == 1) { - Json::Value& data = root["data"]; - this->ImportData(data); - - if (!data["Item"].isNull() || !this->title.empty()) { - context.RefreshShop(); - } - } - - if (type == 1 || type == 4) { + this->ImportData(root["data"]); + this->loaded = true; + } else if (type == 4) { this->loaded = true; } } @@ -177,16 +141,15 @@ void CMCStoreInfoBackup::CompleteSave(AsyncDiagnostic diagnostic, std::string re // OFFSET: 0x00606DE0 // FUNCTION: fn_04235 void CMCStoreInfoBackup::Load( - std::uint32_t accountId, std::uint32_t characterId, std::string accountName, const char* token16, int type, CAsyncWorkMgr& workManager, - StoreBackupContext& context + std::uint32_t accountId, std::uint32_t characterId, std::string accountName, int type ) { if (accountId == 0 || characterId == 0) { return; } - const std::string token(token16, 16); + const std::string token(reinterpret_cast(&g_session.unknown_807C[0x08]), 16); const std::string url = this->LoadUrl(); - workManager.LoadStore(accountId, characterId, accountName, url, token, type, *this, context); + g_asyncWorkMgr->LoadStore(accountId, characterId, accountName, url, token, type); } // OFFSET: 0x00606EB0 diff --git a/Source/Contents/Store/MCStoreInfoBackup.h b/Source/Contents/Store/MCStoreInfoBackup.h index aec39cc4..ac799fa6 100644 --- a/Source/Contents/Store/MCStoreInfoBackup.h +++ b/Source/Contents/Store/MCStoreInfoBackup.h @@ -2,7 +2,6 @@ #define RAGNAROK_SOURCE_CONTENTS_STORE_MCSTOREINFOBACKUP_H #include "Contents/Items/ItemInfo.h" -#include "UI/Window/WindowNotifications.h" #include @@ -12,36 +11,21 @@ struct AsyncDiagnostic; namespace Json { class Value; } -struct MerchantShopRefresh; - -struct StoreBackupContext { - WindowNotifications& ui; - MerchantShopRefresh* const& shop; - MerchantShopRefresh* const& otherShop; - const bool& languagePrefix; - const int& serviceType; - const std::uint16_t& language; - - void RefreshShop(); -}; - class CMCStoreInfoBackup { public: CMCStoreInfoBackup(); virtual ~CMCStoreInfoBackup(); void Clear(); - int Restore(unsigned char wholeItem, int maximum, std::list& inventory, std::list& storeItems); + int Restore(unsigned char wholeItem, int maximum); std::string LoadUrl() const; std::string SaveUrl() const; void Reset(LuaScript& settings, LuaScript& tables, const char* host, const char* port, const char* overrideKey); void CompleteLoad( - AsyncDiagnostic diagnostic, std::uint32_t accountId, std::uint32_t characterId, std::string accountName, std::string response, StoreBackupContext& context + AsyncDiagnostic diagnostic, std::uint32_t accountId, std::uint32_t characterId, std::string accountName, std::string response ); void CompleteSave(AsyncDiagnostic diagnostic, std::string response); void Load( - std::uint32_t accountId, std::uint32_t characterId, std::string accountName, const char* token16, int type, CAsyncWorkMgr& workManager, - StoreBackupContext& context - ); + std::uint32_t accountId, std::uint32_t characterId, std::string accountName, int type); void Save(int type); void ImportData(Json::Value& data); void ExportData(Json::Value& data) const; diff --git a/Source/Contents/Store/MCStoreInfoBackupAsyncWork.cpp b/Source/Contents/Store/MCStoreInfoBackupAsyncWork.cpp index b207ddd7..d7d2b501 100644 --- a/Source/Contents/Store/MCStoreInfoBackupAsyncWork.cpp +++ b/Source/Contents/Store/MCStoreInfoBackupAsyncWork.cpp @@ -24,8 +24,7 @@ namespace { // OFFSET: 0x00607B10 // FUNCTION: fn_04241 CMCStoreInfoBackupLoadAsyncWork::CMCStoreInfoBackupLoadAsyncWork() - : NAsyncWork("MerchantStoreInformation_Load"), m_accountId(0), m_characterId(0), m_diagnostic(Diagnostic(false, "unknwon", loadSource, 28)), m_type(0), - m_owner(nullptr), m_context(nullptr) { + : NAsyncWork("MerchantStoreInformation_Load"), m_accountId(0), m_characterId(0), m_diagnostic(Diagnostic(false, "unknwon", loadSource, 28)), m_type(0) { } // INLINED @@ -39,8 +38,7 @@ void CMCStoreInfoBackupLoadAsyncWork::Reset() { // OFFSET: 0x00607FE0 // FUNCTION: fn_04243 void CMCStoreInfoBackupLoadAsyncWork::Bind( - std::string url, std::uint32_t accountId, std::uint32_t characterId, std::string accountName, std::string token, int type, CMCStoreInfoBackup& owner, - StoreBackupContext& context + std::string url, std::uint32_t accountId, std::uint32_t characterId, std::string accountName, std::string token, int type ) { this->m_group = timeGetTime(); this->m_accountId = accountId; @@ -53,8 +51,6 @@ void CMCStoreInfoBackupLoadAsyncWork::Bind( AsyncDiagnostic diagnostic = Diagnostic(false, "unknwon", loadSource, 55); this->m_diagnostic.MoveFrom(diagnostic); this->m_type = type; - this->m_owner = &owner; - this->m_context = &context; } // OFFSET: 0x00608350 @@ -85,7 +81,7 @@ bool CMCStoreInfoBackupLoadAsyncWork::Execute() { // OFFSET: 0x00608280 // FUNCTION: fn_04245 void CMCStoreInfoBackupLoadAsyncWork::Complete() { - this->m_owner->CompleteLoad(this->m_diagnostic, this->m_accountId, this->m_characterId, this->m_accountName, this->m_response, *this->m_context); + g_session.m_storeInfoBackup.CompleteLoad(this->m_diagnostic, this->m_accountId, this->m_characterId, this->m_accountName, this->m_response); } // OFFSET: 0x00608D60 diff --git a/Source/Contents/Store/MCStoreInfoBackupAsyncWork.h b/Source/Contents/Store/MCStoreInfoBackupAsyncWork.h index 09e5040c..e04e0e25 100644 --- a/Source/Contents/Store/MCStoreInfoBackupAsyncWork.h +++ b/Source/Contents/Store/MCStoreInfoBackupAsyncWork.h @@ -4,9 +4,6 @@ #include "Utility/Async/AsyncDiagnostic.h" #include "Utility/Async/NAsyncWork.h" -class CMCStoreInfoBackup; -struct StoreBackupContext; - class CMCStoreInfoBackupLoadAsyncWork : public NAsyncWork { public: CMCStoreInfoBackupLoadAsyncWork(); @@ -15,8 +12,7 @@ public: bool Execute() override; void Complete() override; void Bind( - std::string url, std::uint32_t accountId, std::uint32_t characterId, std::string accountName, std::string token, int type, CMCStoreInfoBackup& owner, - StoreBackupContext& context + std::string url, std::uint32_t accountId, std::uint32_t characterId, std::string accountName, std::string token, int type ); protected: @@ -29,8 +25,7 @@ protected: /* 0090 */ AsyncDiagnostic m_diagnostic; /* 00C8 */ int m_type; - CMCStoreInfoBackup* m_owner; - StoreBackupContext* m_context; + /* 00CC */ int unknown_00CC; }; class CMCStoreInfoBackupSaveAsyncWork : public NAsyncWork { @@ -58,7 +53,7 @@ protected: }; #if defined(_WIN32) && !defined(_WIN64) -static_assert(sizeof(CMCStoreInfoBackupLoadAsyncWork) == 212); +static_assert(sizeof(CMCStoreInfoBackupLoadAsyncWork) == 208); static_assert(sizeof(CMCStoreInfoBackupSaveAsyncWork) == 232); #endif diff --git a/Source/Contents/Store/StoreBackupData.cpp b/Source/Contents/Store/StoreBackupData.cpp index b49b0804..1c028a32 100644 --- a/Source/Contents/Store/StoreBackupData.cpp +++ b/Source/Contents/Store/StoreBackupData.cpp @@ -1,6 +1,8 @@ #include "Contents/Store/MCStoreInfoBackup.h" #include "Client/Session.h" #include "Network/TextEncoding.h" +#include "UI/Shop/UIMerchantShopMakeWnd.h" +#include "UI/Window/UIWindowMgr.h" #include #include @@ -14,6 +16,10 @@ void CMCStoreInfoBackup::ImportData(Json::Value& data) { this->title = FromUtf8(data.get("Title", "").asString(), g_textCodePage); Json::Value values = data["Item"]; + if (values.isNull() && this->title.empty()) { + return; + } + for (auto entry = values.begin(); entry != values.end(); ++entry) { Json::Value& value = *entry; @@ -53,6 +59,12 @@ void CMCStoreInfoBackup::ImportData(Json::Value& data) { item.unknown_0014[0] = static_cast(value.get("Price", 0).asInt()); this->items.push_back(item); } + + UIWindow* window = g_windowMgr.unknown_02FC ? g_windowMgr.unknown_02FC : g_windowMgr.unknown_040C; + + if (window) { + static_cast(window)->Refresh(); + } } // OFFSET: 0x00607240 diff --git a/Source/UI/Shop/MerchantShopRefresh.cpp b/Source/UI/Shop/MerchantShopRefresh.cpp index afabbbb9..916c4974 100644 --- a/Source/UI/Shop/MerchantShopRefresh.cpp +++ b/Source/UI/Shop/MerchantShopRefresh.cpp @@ -1,108 +1,100 @@ +#include "Client/Session.h" +#include "Contents/ClientItemLists.h" #include "Contents/Store/MCStoreInfoBackup.h" -#include "UI/Shop/MerchantShopRefresh.h" #include "UI/Shop/PriceColor.h" +#include "UI/Shop/UIMerchantShopMakeWnd.h" +#include "UI/Buttons/UIBasicButton.h" #include "UI/Edit/UIEditCtrl.h" -#include "UI/Window/UIWindow.h" +#include "UI/Window/UIWindowMgr.h" #include "Utility/Text/GroupedInteger.h" -#include -#include +#include +#include + +struct SessionMessengerContext { + int GetList11Size() const; +}; // OFFSET: 0x00970E60 // FUNCTION: fn_13262 -void MerchantShopRefresh::Refresh() { - if (this->backup.title.empty()) { - this->buttonDisabled = 0; - this->button.Invalidate(); +void UIMerchantShopMakeWnd::Refresh() { + CMCStoreInfoBackup& backup = g_session.m_storeInfoBackup; + + if (std::string(backup.title).empty()) { + this->unknown_0168->SetDisabled(0); + this->unknown_0168->Invalidate(); return; } - this->titleEdit.SetText(this->backup.title.c_str()); - this->titleEdit.Invalidate(); + this->unknown_00CC->SetText(std::string(backup.title).c_str()); + this->unknown_00CC->Invalidate(); - for (int index = 0; index < this->maximum; ++index) { - UIEditCtrl& edit = *this->priceEdits[index]; - edit.SetText(""); + for (int index = 0; index < this->unknown_012C; ++index) { + UIEditCtrl* edit = this->priceEdits[index]; + edit->SetText(""); - if (this->mode == 0) { - edit.disabled = 1; - edit.Invalidate(); - } + int background; - const int background = this->mode != 0 ? 232 : 182; - edit.Background(background, background, background); - } - - for (const ITEM_INFO& item : this->offered) { - const auto found = - std::find_if(this->inventory.begin(), this->inventory.end(), [&](const ITEM_INFO& value) { return value.unknown_0000[1] == item.unknown_0000[1]; }); - - if (found == this->inventory.end()) { - this->inventory.push_back(item); + if (this->mode != 0) { + background = 232; } else { - found->quantity = (found->quantity + item.quantity); + edit->disabled = 1; + edit->Invalidate(); + background = 182; } + + edit->Background(background, background, background); } - this->offered.clear(); - this->backup.Restore(this->mode != 0, this->maximum, this->inventory, this->offered); + const int count = reinterpret_cast(&g_session)->GetList11Size(); - const std::vector displayed(this->backup.items); + for (int index = 0; index < count; ++index) { + const ITEM_INFO item = g_session.GetItem1768At(index); + reinterpret_cast(&g_session)->AddItem1750(item, this->mode, 0); + } + + reinterpret_cast(&g_session)->ClearItems1768(); + backup.Restore(this->mode != 0, this->unknown_012C); + + const std::vector displayed(backup.items); int index = 0; + UIEditCtrl** edit = this->priceEdits; for (const ITEM_INFO& item : displayed) { - if (index >= this->maximum) { + if (index >= this->unknown_012C) { break; } - UIEditCtrl& edit = *this->priceEdits[index]; const int price = static_cast(item.unknown_0014[0]); char value[24] = {}; - std::snprintf(value, sizeof(value), "%d", price); - edit.disabled = 0; - edit.Invalidate(); - edit.Background(232, 232, 232); - edit.SelectAll(); - edit.SetText(value); + _itoa(price, value, 10); + (*edit)->disabled = 0; + (*edit)->Invalidate(); + (*edit)->Background(232, 232, 232); + (*edit)->SelectAll(); + (*edit)->SetText(value); if (this->mode != 0 && index < 5) { - std::snprintf(value, sizeof(value), "%d", item.quantity); - UIEditCtrl& count = *this->countEdits[index]; - count.SetText(value); - count.Invalidate(); + char quantity[24] = {}; + _itoa(item.quantity, quantity, 10); + this->quantityEdits[index]->SetText(quantity); + this->quantityEdits[index]->Invalidate(); } else { const PriceColors colors = PriceColor(price); - edit.TextColor(colors.primary, colors.secondary); - FormatGroupedInteger(price, value, sizeof(value)); - edit.SetText(value); - this->titleLength = edit.Length(); + (*edit)->TextColor(colors.primary, colors.secondary); + char grouped[24] = {}; + FormatGroupedInteger(price, grouped, sizeof(grouped)); + (*edit)->SetText(grouped); + this->unknown_016C = (*edit)->Length(); } + ++edit; ++index; } - UIWindow* store = this->mode != 0 ? this->otherStoreWindow : this->storeWindow; - - if (store) { - store->SendMsg(nullptr, 23, 0, 0, 0, 0); - } - - UIWindow* inventory = this->mode == 1 ? this->otherInventoryWindow : this->mode == 2 ? this->extraInventoryWindow : this->inventoryWindow; - - if (inventory) { - inventory->SendMsg(nullptr, 23, 0, 0, 0, 0); - } - - this->buttonDisabled = 0; - this->button.Invalidate(); - this->backup.Clear(); -} - -// INLINED -void StoreBackupContext::RefreshShop() { - MerchantShopRefresh* window = this->shop ? this->shop : this->otherShop; - - if (window) { - window->Refresh(); - } + g_session.RefreshItem1768Window(this->mode != 0, 0); + g_session.RefreshItem1750Window(this->mode); + this->unknown_0168->SetDisabled(0); + this->unknown_0168->Invalidate(); + backup.Clear(); } diff --git a/Source/UI/Shop/MerchantShopRefresh.h b/Source/UI/Shop/MerchantShopRefresh.h deleted file mode 100644 index b1149e2d..00000000 --- a/Source/UI/Shop/MerchantShopRefresh.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef RAGNAROK_SOURCE_UI_SHOP_MERCHANTSHOPREFRESH_H -#define RAGNAROK_SOURCE_UI_SHOP_MERCHANTSHOPREFRESH_H - -#include "Contents/Items/ItemInfo.h" - -#include -#include - -class UIWindow; -class CMCStoreInfoBackup; -class UIEditCtrl; - -struct MerchantShopRefresh { - CMCStoreInfoBackup& backup; - std::list& inventory; - std::list& offered; - UIEditCtrl& titleEdit; - std::span priceEdits; - std::span countEdits; - const int& maximum; - const int& mode; - int& titleLength; - UIWindow& button; - unsigned char& buttonDisabled; - UIWindow* const& storeWindow; - UIWindow* const& otherStoreWindow; - UIWindow* const& inventoryWindow; - UIWindow* const& otherInventoryWindow; - UIWindow* const& extraInventoryWindow; - - void Refresh(); -}; - -#endif diff --git a/Source/UI/Shop/UIMerchantShopMakeWnd.h b/Source/UI/Shop/UIMerchantShopMakeWnd.h index fb35b183..a55a1bf9 100644 --- a/Source/UI/Shop/UIMerchantShopMakeWnd.h +++ b/Source/UI/Shop/UIMerchantShopMakeWnd.h @@ -34,6 +34,7 @@ public: int CommitPrice(int next); void PrintBuyList(); void PrintSellList(); + void Refresh(); void Slot32(int x, int y) override; void Paint() override;