close remtoe stash works

This commit is contained in:
Hash Borgir 2024-05-01 13:42:06 -06:00
parent d33c619372
commit f8349e6ba1
39 changed files with 259 additions and 64 deletions

Binary file not shown.

View File

@ -1,2 +1,3 @@
 ui_manager.cpp
 loot_filter.cpp
loot_filter_settings_toggle_menu.cpp
D2tweaks.vcxproj -> D:\Diablo II\MODS\ironman-dev\D2tweaks.dll

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -30,6 +30,9 @@ extern bool m_stats_enabled;
extern bool m_help_enabled;
extern bool m_cube_enabled;
extern bool m_stash_enabled;
namespace diablo2 {
namespace structures {

View File

@ -18,6 +18,8 @@ namespace d2_tweaks {
ui::controls::button* m_toggle_filter_settings_btn;
ui::controls::button* m_btn_toggle_stats;
ui::controls::button* m_btn_toggle_help;
ui::controls::button* m_btn_toggle_cube;
ui::controls::button* m_btn_toggle_stash;
menu* m_filter_settings_menu;
bool m_show;
public:
@ -26,7 +28,8 @@ namespace d2_tweaks {
void toggle_filter_settings_click();
void toggle_stats_settings_click();
void toggle_help_click();
void toggle_cube_click();
void toggle_stash_click();
void draw() override;
bool key_event(uint32_t key, bool up) override;

View File

@ -89,7 +89,7 @@ namespace diablo2 {
static int32_t send_to_server_9(BYTE type, DWORD num, DWORD unk1);
static void set_ui_toggle(int nToggle, int nUIState, BOOL bToggle);
};
}

View File

@ -218,6 +218,7 @@ public:
int textOffset = 40; // Initial offset for the first line
const auto player = diablo2::d2_client::get_local_player();
auto name = player->player_data->name;
// Add all items to vector
std::vector<diablo2::structures::unit*> items;

View File

@ -23,10 +23,85 @@
#include <cstdlib> // For system function
#include <shellapi.h> // For ShellExecute
#include <diablo2/d2common.h>
#include <d2tweaks/ui/ui_manager.h>
#include <Windows.h>
#include <algorithm>
#include <common/hooking.h>
#include <d2tweaks/common/protocol.h>
#include <d2tweaks/ui/menu.h>
#include <diablo2/d2win.h>
#include <diablo2/d2client.h>
#include <diablo2/d2common.h>
#include <diablo2/d2game.h>
#include <spdlog/spdlog.h>
#include <Windows.h>
#include <d2tweaks/client/modules/autosort/autosort_client.h>
#include <d2tweaks/client/client.h>
#include <spdlog/spdlog.h>
#include <d2tweaks/common/common.h>
#include <d2tweaks/common/protocol.h>
#include <d2tweaks/common/asset_manager.h>
#include <d2tweaks/ui/menu.h>
#include <d2tweaks/ui/ui_manager.h>
#include <d2tweaks/ui/controls/control.h>
#include <d2tweaks/ui/controls/button.h>
#include <diablo2/d2common.h>
#include <diablo2/d2client.h>
#include <diablo2/d2win.h>
#include <diablo2/d2gfx.h>
#include <diablo2/d2cmp.h>
#include <diablo2/structures/unit.h>
#include <diablo2/structures/inventory.h>
#include <diablo2/structures/item_data.h>
#include <diablo2/structures/player_data.h>
#include <diablo2/structures/path.h>
#include <diablo2/structures/game.h>
#include <diablo2/structures/data/items_line.h>
#include <diablo2/structures/data/item_types_line.h>
#include <iostream>
#include <fstream>
#include <string>
#include <filesystem>
#include <unordered_map>
#include <time.h>
#include <cmath>
#include <random>
#include <algorithm>
#include <functional>
#include <map>
#include <iomanip> // For std::setw
#include <sstream>
#include <stdexcept> // For std::invalid_argument
#include <iostream>
#include <vector>
#include <string>
#include <CommCtrl.h> // Include for edit control
#pragma pack(push, 1)
using namespace d2_tweaks::client::modules;
bool m_stats_enabled = false;
bool m_help_enabled = false;
bool m_cube_enabled = false;
bool m_stash_enabled = false;
d2_tweaks::client::modules::loot_filter_settings_toggle_menu::loot_filter_settings_toggle_menu(token) {
m_show = false;
@ -61,6 +136,27 @@ d2_tweaks::client::modules::loot_filter_settings_toggle_menu::loot_filter_settin
m_btn_toggle_help->set_visible(true);
m_btn_toggle_help->set_on_click(std::bind(&loot_filter_settings_toggle_menu::toggle_help_click, this));
m_btn_toggle_cube = static_cast<ui::controls::button*>(get_control("m_toggle_cube"));
m_btn_toggle_cube->set_enabled(true);
m_btn_toggle_cube->set_visible(true);
m_btn_toggle_cube->set_on_click(std::bind(&loot_filter_settings_toggle_menu::toggle_cube_click, this));
m_btn_toggle_stash = static_cast<ui::controls::button*>(get_control("m_toggle_stash"));
m_btn_toggle_stash->set_enabled(false);
m_btn_toggle_stash->set_visible(false);
auto player = diablo2::d2_client::get_local_player();
//iterate over all items in player inventory
for (auto item = player->inventory->first_item; item != nullptr; item = item->item_data->pt_next_item) {
const auto record = diablo2::d2_common::get_item_record(item->data_record_index);
char* normCode1 = record->string_code;
if (strncmp(normCode1, "st0", 3) == 0) {
m_btn_toggle_stash->set_enabled(true);
m_btn_toggle_stash->set_visible(true);
break;
}
}
m_btn_toggle_stash->set_on_click(std::bind(&loot_filter_settings_toggle_menu::toggle_stash_click, this));
}
void d2_tweaks::client::modules::loot_filter_settings_toggle_menu::toggle_filter_settings_click() {
@ -77,6 +173,90 @@ void d2_tweaks::client::modules::loot_filter_settings_toggle_menu::toggle_stats_
m_stats_enabled = !m_stats_enabled;
}
void d2_tweaks::client::modules::loot_filter_settings_toggle_menu::toggle_cube_click() {
m_cube_enabled = !m_cube_enabled;
if (m_cube_enabled) {
const auto player = diablo2::d2_client::get_local_player();
int32_t boxGuid = 0;
uint32_t boxX = 0;
uint32_t boxY = 0;
diablo2::structures::unit* box{};
for (auto item = player->inventory->first_item; item != nullptr; item = item->item_data->pt_next_item) {
const auto record = diablo2::d2_common::get_item_record(item->data_record_index);
char* normCode1 = record->string_code;
if (strncmp(normCode1, "box", 3) == 0) {
box = item;
boxGuid = box->guid;
boxX = player->path->mapx;
boxY = player->path->mapy;
}
}
struct D2GSPacketClt20 {
uint8_t PacketId; // 0x01
//uint8_t MsgID; // 0x02
uint32_t guid; // 0x06
uint32_t tx; // 0x07
uint32_t ty; // 0x09
};
D2GSPacketClt20 packet;
packet.PacketId = 0x20;
packet.guid = boxGuid;
packet.tx = boxX;
packet.ty = boxY;
diablo2::d2_client::send_to_server(&packet, sizeof packet);
}
else {
diablo2::d2_client::set_ui_toggle(0x1A, 1, FALSE);
// send to server7 to close cube packet 0x4F
diablo2::d2_client::send_to_server_7(0x4F, 0x17, 0, 0);
}
}
void d2_tweaks::client::modules::loot_filter_settings_toggle_menu::toggle_stash_click() {
m_stash_enabled = !m_stash_enabled;
if (m_stash_enabled) {
const auto player = diablo2::d2_client::get_local_player();
int32_t st0Guid = 0;
uint32_t st0X = 0;
uint32_t st0Y = 0;
diablo2::structures::unit* box{};
for (auto item = player->inventory->first_item; item != nullptr; item = item->item_data->pt_next_item) {
const auto record = diablo2::d2_common::get_item_record(item->data_record_index);
char* st0Code = record->string_code;
if (strncmp(st0Code, "st0", 3) == 0) {
box = item;
st0Guid = box->guid;
st0X = player->path->mapx;
st0Y = player->path->mapy;
}
}
struct D2GSPacketClt20 {
uint8_t PacketId; // 0x01
uint32_t guid; // 0x06
uint32_t tx; // 0x07
uint32_t ty; // 0x09
};
D2GSPacketClt20 packet;
packet.PacketId = 0x20;
packet.guid = st0Guid;
packet.tx = st0X;
packet.ty = st0Y;
diablo2::d2_client::send_to_server(&packet, sizeof packet);
}
else {
//run a for loop and send th set_ui_toggle packet 255 times from 1 to 255
diablo2::d2_client::set_ui_toggle(0x19, 1, FALSE);
// send to server7 to close cube packet 0x4F
diablo2::d2_client::send_to_server_7(0x4F, 0x17, 0, 0);
}
}
void d2_tweaks::client::modules::loot_filter_settings_toggle_menu::toggle_help_click() {
//m_help_enabled = !m_help_enabled;
// Open the default OS browser to the URL
@ -115,3 +295,5 @@ bool d2_tweaks::client::modules::loot_filter_settings_toggle_menu::key_event(uin
return menu::key_event(key, up);
}
#pragma pack(pop)

View File

@ -69,10 +69,8 @@
#include <string>
#include <CommCtrl.h> // Include for edit control
#pragma pack(push, 1)
using namespace std;
diablo2::structures::unit* g_item1;
@ -567,6 +565,7 @@ LRESULT d2_tweaks::ui::ui_manager::wnd_proc(HWND hWnd, UINT msg, WPARAM wParam,
auto pInventory = player->inventory;
int32_t gemBagGuid = 0;
int32_t harvesterGuid = 0;
int32_t boxGuid;
uint32_t boxX;
uint32_t boxY;
@ -624,6 +623,8 @@ LRESULT d2_tweaks::ui::ui_manager::wnd_proc(HWND hWnd, UINT msg, WPARAM wParam,
std::vector<diablo2::structures::unit*> items;
diablo2::structures::unit* gemBag{};
diablo2::structures::unit* box{};
diablo2::structures::unit* harvester{};
// get the gembag item
for (auto item = player->inventory->first_item; item != nullptr; item = item->item_data->pt_next_item) {
@ -634,21 +635,15 @@ LRESULT d2_tweaks::ui::ui_manager::wnd_proc(HWND hWnd, UINT msg, WPARAM wParam,
gemBagGuid = gemBag->guid;
}
if (strncmp(normCode1, "box", 3) == 0) {
diablo2::structures::unit* box = item;
box = item;
boxGuid = box->guid;
// Get the x, y coordinates of the box in the inventory
boxX = player->path->x;
boxY = player->path->y;
MessageBoxA(0, std::to_string(boxX).c_str(), "boxX", 0);
MessageBoxA(0, std::to_string(boxY).c_str(), "boxY", 0);
//MessageBoxA(0, std::to_string(boxGuid).c_str(), "boxGuid", 0);
boxX = player->path->mapx;
boxY = player->path->mapy;
}
if (strncmp(normCode1, "ib3", 3) == 0) {
harvester = item;
harvesterGuid = harvester->guid;
}
}
// Actual ID to use is 378 for Ruby, but actual row number is 381
@ -1570,8 +1565,8 @@ LRESULT d2_tweaks::ui::ui_manager::wnd_proc(HWND hWnd, UINT msg, WPARAM wParam,
strncmp(normCode, "ooc", 3) == 0 ||
strncmp(normCode, "eaq", 3) == 0 ||
strncmp(normCode, "ebq", 3) == 0 ||
record->type == 109
record->type == 109
|| record->type == 111
|| record->type == 112
|| record->type == 113
@ -1613,53 +1608,63 @@ LRESULT d2_tweaks::ui::ui_manager::wnd_proc(HWND hWnd, UINT msg, WPARAM wParam,
) {
// open the cube
struct D2GSPacketClt20 {
uint8_t PacketId; // 0x01
uint32_t guid; // 0x06
uint32_t tx; // 0x07
uint32_t ty; // 0x09
};
D2GSPacketClt20 D2GSPacketClt20;
D2GSPacketClt20.PacketId = 0x20;
D2GSPacketClt20.guid = boxGuid;
D2GSPacketClt20.tx = player->path->mapx;
D2GSPacketClt20.ty = player->path->mapy;
diablo2::d2_client::send_to_server(&D2GSPacketClt20, sizeof D2GSPacketClt20);
struct packet1 {
uint8_t PacketId; // 0x01
//uint8_t MsgID; // 0x02
uint32_t guid; // 0x06
uint32_t tx; // 0x07
uint32_t ty; // 0x09
};
Sleep(100);
packet1 packet1;
packet1.PacketId = 0x20;
packet1.guid = boxGuid;
packet1.tx = player->path->mapx;
packet1.ty = player->path->mapy;
// now move the harvester guid to the cube
// Create the packet
static d2_tweaks::common::item_move_cs hpacket;
hpacket.item_guid = harvesterGuid;
if (currentPage == 0) { //item is in inventory
if (diablo2::d2_client::get_ui_window_state(diablo2::UI_WINDOW_STASH))
hpacket.target_page = 4;
if (diablo2::d2_client::get_ui_window_state(diablo2::UI_WINDOW_CUBE))
hpacket.target_page = 3;
}
else {
hpacket.target_page = 0;
}
diablo2::d2_client::send_to_server(&hpacket, sizeof hpacket);
diablo2::d2_client::send_to_server(&packet1, sizeof packet1);
// Create the packet
static d2_tweaks::common::item_move_cs packet;
packet.item_guid = g_hoverItem->guid;
if (currentPage == 0) { //item is in inventory
if (diablo2::d2_client::get_ui_window_state(diablo2::UI_WINDOW_STASH))
packet.target_page = 4;
//MessageBoxA(0, std::to_string(boxX).c_str(), "boxX", 0);
//MessageBoxA(0, std::to_string(boxY).c_str(), "boxY", 0);
//MessageBoxA(0, std::to_string(boxGuid).c_str(), "boxGuid", 0);
if (diablo2::d2_client::get_ui_window_state(diablo2::UI_WINDOW_CUBE))
packet.target_page = 3;
}
else {
packet.target_page = 0;
}
diablo2::d2_client::send_to_server(&packet, sizeof packet);
diablo2::d2_client::send_to_server_7(0x4F, 0x18, 0, 0);
// now move the harvester back to the inv
//static d2_tweaks::common::item_move_cs h1packet;
//h1packet.item_guid = harvesterGuid;
//h1packet.target_page = 0;
//diablo2::d2_client::send_to_server(&h1packet, sizeof h1packet);
// find diablo 2 window and simulate right click at 700x200 coordinates
(*reinterpret_cast<diablo2::structures::unit**>(diablo2::d2_client::get_base() + 0x1158F4)) = nullptr;
// Create the packet
static d2_tweaks::common::item_move_cs packet;
packet.item_guid = g_hoverItem->guid;
if (currentPage == 0) { //item is in inventory
if (diablo2::d2_client::get_ui_window_state(diablo2::UI_WINDOW_STASH))
packet.target_page = 4;
if (diablo2::d2_client::get_ui_window_state(diablo2::UI_WINDOW_CUBE))
packet.target_page = 3;
}
else {
packet.target_page = 0;
}
diablo2::d2_client::send_to_server(&packet, sizeof packet);
(*reinterpret_cast<diablo2::structures::unit**>(diablo2::d2_client::get_base() + 0x1158F4)) = nullptr;
}
}
@ -1680,7 +1685,6 @@ LRESULT d2_tweaks::ui::ui_manager::wnd_proc(HWND hWnd, UINT msg, WPARAM wParam,
if (zDelta > 0) {
diablo2::d2_client::send_to_server_7(0x4F, 0x18, 0, 0);
block = instance.process_mouse_wheel(true);
}
else if (zDelta < 0) {
diablo2::d2_client::send_to_server_7(0x4F, 0x18, 0, 0);
@ -1689,9 +1693,6 @@ LRESULT d2_tweaks::ui::ui_manager::wnd_proc(HWND hWnd, UINT msg, WPARAM wParam,
break;
}
case WM_MBUTTONUP:
{
block = instance.process_middle_mouse(true);
@ -1799,7 +1800,6 @@ bool d2_tweaks::ui::ui_manager::process_mouse_wheel(bool up) {
return block;
}
bool d2_tweaks::ui::ui_manager::process_right_mouse(bool up) {
auto block = false;

View File

@ -31,6 +31,11 @@ diablo2::structures::client_unit_list* diablo2::d2_client::get_client_unit_list(
return unit_list;
}
void diablo2::d2_client::set_ui_toggle(int nToggle, int nUIState, BOOL bToggle) {
static wrap_func_fast<void(int, int, BOOL)> set_ui_toggle(0x83260, get_base());
set_ui_toggle(nToggle, nUIState, bToggle);
}
int32_t diablo2::d2_client::get_view_offset_x() {
static wrap_func_std<int32_t()> get_view_offset_x(0x15890, get_base());
return get_view_offset_x();