From df8d43422ec36b47d675c0c53f4fc4adf9ab49a4 Mon Sep 17 00:00:00 2001 From: Hash Borgir Date: Sun, 19 May 2024 20:46:16 -0600 Subject: [PATCH] middle clicks gems to store --- src/d2tweaks/ui/ui_manager.cpp | 47 ++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/d2tweaks/ui/ui_manager.cpp b/src/d2tweaks/ui/ui_manager.cpp index 32ffa11..8464c56 100644 --- a/src/d2tweaks/ui/ui_manager.cpp +++ b/src/d2tweaks/ui/ui_manager.cpp @@ -1259,8 +1259,55 @@ LRESULT d2_tweaks::ui::ui_manager::wnd_proc(HWND hWnd, UINT msg, WPARAM wParam, } + // get current page + char currentPage = diablo2::d2_common::get_item_page(g_hoverItem); + if (( + diablo2::d2_client::get_ui_window_state(diablo2::UI_WINDOW_INVENTORY) || + diablo2::d2_client::get_ui_window_state(diablo2::UI_WINDOW_STASH) || + diablo2::d2_client::get_ui_window_state(diablo2::UI_WINDOW_CUBE) + ) && currentPage == 0) { + // Iterate through each gem type in the gemTypes map + for (const auto& gem : gemTypes) { + // Accessing the key and value of the gemTypes map + const std::string& _key = gem.first; + auto key = gem.first.c_str(); + const GemType& value = gem.second; + + // Check if the code of the hovered item matches the current gem type + if (strncmp(normCode, key, 3) == 0) { + // Create a D2PropertyStrc structure to represent the gem property + D2PropertyStrc itemProperty = {}; + itemProperty.nProperty = value.rowID - 3; // Adjust the property ID + itemProperty.nLayer = 0; + itemProperty.nMin = value.chippedCount; + itemProperty.nMax = value.chippedCount; + + // Add the gem property to the gem bag + diablo2::d2_common::add_property(gemBag, &itemProperty, 0); + + // Play the drop sound associated with the hovered item + diablo2::d2_client::play_sound(record->drop_sound, nullptr, 0, 0, 0); + + // Create and send a packet to the server to move the item + static d2_tweaks::common::item_move_cs packet; + packet.item_guid = g_hoverItem->guid; + packet.item_code = key; + packet.bag_guid = gemBagGuid; + packet.updateBag = 1; + packet.prop = itemProperty.nProperty; + packet.val = itemProperty.nMin; + packet.target_page = 99; + diablo2::d2_client::send_to_server(&packet, sizeof packet); + + diablo2::d2_common::inv_remove_item(player->inventory, g_hoverItem); + + // Clear the hovered item after processing + (*reinterpret_cast(diablo2::d2_client::get_base() + 0x1158F4)) = nullptr; + } + } + }