Bag crashes upon hover. Need to debug.

This commit is contained in:
Hash Borgir 2024-05-05 18:08:33 -06:00
parent 3a7be104d9
commit 95f7d9bed3
8 changed files with 254 additions and 71 deletions

View File

@ -15,6 +15,8 @@ namespace d2_tweaks {
bool show_runes;
bool show_gems;
bool m_show_r01;
bool quality_settings[static_cast<size_t>(diablo2::structures::item_quality_t::ITEM_QUALITY_COUNT)];
char reserved[1004];

View File

@ -26,6 +26,56 @@ namespace d2_tweaks {
ui::controls::checkbox* m_show_runes;
ui::controls::checkbox* m_show_gems;
ui::controls::checkbox* m_show_ruby;
ui::controls::checkbox* m_show_sapphire;
ui::controls::checkbox* m_show_emerald;
ui::controls::checkbox* m_show_diamond;
ui::controls::checkbox* m_show_topaz;
ui::controls::checkbox* m_show_amethyst;
ui::controls::checkbox* m_show_skull;
ui::controls::checkbox* m_show_r01;
ui::controls::checkbox* m_show_r02;
ui::controls::checkbox* m_show_r03;
ui::controls::checkbox* m_show_r04;
ui::controls::checkbox* m_show_r05;
ui::controls::checkbox* m_show_r06;
ui::controls::checkbox* m_show_r07;
ui::controls::checkbox* m_show_r08;
ui::controls::checkbox* m_show_r09;
ui::controls::checkbox* m_show_r10;
ui::controls::checkbox* m_show_r11;
ui::controls::checkbox* m_show_r12;
ui::controls::checkbox* m_show_r13;
ui::controls::checkbox* m_show_r14;
ui::controls::checkbox* m_show_r15;
ui::controls::checkbox* m_show_r16;
ui::controls::checkbox* m_show_r17;
ui::controls::checkbox* m_show_r18;
ui::controls::checkbox* m_show_r19;
ui::controls::checkbox* m_show_r20;
ui::controls::checkbox* m_show_r21;
ui::controls::checkbox* m_show_r22;
ui::controls::checkbox* m_show_r23;
ui::controls::checkbox* m_show_r24;
ui::controls::checkbox* m_show_r25;
ui::controls::checkbox* m_show_r26;
ui::controls::checkbox* m_show_r27;
ui::controls::checkbox* m_show_r28;
ui::controls::checkbox* m_show_r29;
ui::controls::checkbox* m_show_r30;
ui::controls::checkbox* m_show_r31;
ui::controls::checkbox* m_show_r32;
ui::controls::checkbox* m_show_r33;
ui::controls::checkbox* m_show_chipped;
ui::controls::checkbox* m_show_flawed;
ui::controls::checkbox* m_show_normal;
ui::controls::checkbox* m_show_flawless;
ui::controls::checkbox* m_show_perfect;
void(__fastcall* m_draw_dropped_items_names_original)(void*, void*);
void(__fastcall* m_handle_dropped_items_original)(void*, void*);
public:
@ -39,6 +89,7 @@ namespace d2_tweaks {
void register_quality_checkboxes();
void update_alt_only(bool value);
void extract_r01(bool value);
void update_show_gold(bool value);
void update_show_runes(bool value);
void update_show_gems(bool value);

View File

@ -20,9 +20,12 @@ namespace d2_tweaks {
ui::controls::button* m_btn_toggle_help;
ui::controls::button* m_btn_toggle_cube;
ui::controls::button* m_btn_toggle_stash;
ui::controls::button* m_btn_toggle_bag;
menu* m_filter_settings_menu;
menu* m_menu;
bool m_show;
bool m_show_bag;
public:
explicit loot_filter_settings_toggle_menu(token);
@ -31,6 +34,7 @@ namespace d2_tweaks {
void toggle_help_click();
void toggle_cube_click();
void toggle_stash_click();
void toggle_bag_click();
void draw() override;
bool key_event(uint32_t key, bool up) override;

View File

@ -54,5 +54,7 @@ namespace diablo2 {
//D2Game.0x6FC4A660
static int32_t __fastcall D2GAME_Transmogrify_6FC4A660(structures::game* pGame, structures::unit* pPlayer, structures::unit* pItem);
static diablo2::structures::unit* __fastcall diablo2::d2_game::QUESTS_CreateItem(diablo2::structures::game* pGame, diablo2::structures::unit* pPlayer, uint32_t dwCode, int32_t nLevel, uint8_t nQuality, int32_t bDroppable);
};
}

View File

@ -25,6 +25,19 @@ namespace diablo2 {
struct quest_record;
struct npc_record;
enum D2C_ItemQualities
{
ITEMQUAL_INFERIOR = 0x01, //0x01 Inferior
ITEMQUAL_NORMAL = 0x02, //0x02 Normal
ITEMQUAL_SUPERIOR = 0x03, //0x03 Superior
ITEMQUAL_MAGIC = 0x04, //0x04 Magic
ITEMQUAL_SET = 0x05, //0x05 Set
ITEMQUAL_RARE = 0x06, //0x06 Rare
ITEMQUAL_UNIQUE = 0x07, //0x07 Unique
ITEMQUAL_CRAFT = 0x08, //0x08 Crafted
ITEMQUAL_TEMPERED = 0x09 //0x09 Tempered
};
enum class unit_type_t : int32_t {
UNIT_TYPE_PLAYER = 0,
UNIT_TYPE_MONSTER = 1,

View File

@ -16,6 +16,65 @@
#include <d2tweaks/ui/controls/checkbox.h>
#include <DllNotify.h>
#include <D2Template.h>
#include <d2tweaks/common/protocol.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 <vector>
#include <string>
#include <map>
#include <DllNotify.h>
#include <D2Template.h>
#include <diablo2/d2gfx.h>
#include <string>
#include <vector>
#include <sstream>
#include <string>
#include <locale>
#include <codecvt>
d2_tweaks::client::modules::loot_filter_settings_menu::loot_filter_settings_menu(token) {
menu::set_enabled(false);
@ -53,6 +112,63 @@ void d2_tweaks::client::modules::loot_filter_settings_menu::register_misc_checkb
m_show_runes = get_control<ui::controls::checkbox>("m_show_runes");
m_show_gems = get_control<ui::controls::checkbox>("m_show_gems");
m_show_amethyst = get_control<ui::controls::checkbox>("m_show_amethyst");
m_show_diamond = get_control<ui::controls::checkbox>("m_show_diamond");
m_show_emerald = get_control<ui::controls::checkbox>("m_show_emerald");
m_show_ruby = get_control<ui::controls::checkbox>("m_show_ruby");
m_show_sapphire = get_control<ui::controls::checkbox>("m_show_sapphire");
m_show_skull = get_control<ui::controls::checkbox>("m_show_skull");
m_show_topaz = get_control<ui::controls::checkbox>("m_show_topaz");
m_show_r01 = get_control<ui::controls::checkbox>("m_show_r01");
m_show_r02 = get_control<ui::controls::checkbox>("m_show_r02");
m_show_r03 = get_control<ui::controls::checkbox>("m_show_r03");
m_show_r04 = get_control<ui::controls::checkbox>("m_show_r04");
m_show_r05 = get_control<ui::controls::checkbox>("m_show_r05");
m_show_r06 = get_control<ui::controls::checkbox>("m_show_r06");
m_show_r07 = get_control<ui::controls::checkbox>("m_show_r07");
m_show_r08 = get_control<ui::controls::checkbox>("m_show_r08");
m_show_r09 = get_control<ui::controls::checkbox>("m_show_r09");
m_show_r10 = get_control<ui::controls::checkbox>("m_show_r10");
m_show_r11 = get_control<ui::controls::checkbox>("m_show_r11");
m_show_r12 = get_control<ui::controls::checkbox>("m_show_r12");
m_show_r13 = get_control<ui::controls::checkbox>("m_show_r13");
m_show_r14 = get_control<ui::controls::checkbox>("m_show_r14");
m_show_r15 = get_control<ui::controls::checkbox>("m_show_r15");
m_show_r16 = get_control<ui::controls::checkbox>("m_show_r16");
m_show_r17 = get_control<ui::controls::checkbox>("m_show_r17");
m_show_r18 = get_control<ui::controls::checkbox>("m_show_r18");
m_show_r19 = get_control<ui::controls::checkbox>("m_show_r19");
m_show_r20 = get_control<ui::controls::checkbox>("m_show_r20");
m_show_r21 = get_control<ui::controls::checkbox>("m_show_r21");
m_show_r22 = get_control<ui::controls::checkbox>("m_show_r22");
m_show_r23 = get_control<ui::controls::checkbox>("m_show_r23");
m_show_r24 = get_control<ui::controls::checkbox>("m_show_r24");
m_show_r25 = get_control<ui::controls::checkbox>("m_show_r25");
m_show_r26 = get_control<ui::controls::checkbox>("m_show_r26");
m_show_r27 = get_control<ui::controls::checkbox>("m_show_r27");
m_show_r28 = get_control<ui::controls::checkbox>("m_show_r28");
m_show_r29 = get_control<ui::controls::checkbox>("m_show_r29");
m_show_r30 = get_control<ui::controls::checkbox>("m_show_r30");
m_show_r31 = get_control<ui::controls::checkbox>("m_show_r31");
m_show_r32 = get_control<ui::controls::checkbox>("m_show_r32");
m_show_r33 = get_control<ui::controls::checkbox>("m_show_r33");
m_show_chipped = get_control<ui::controls::checkbox>("m_show_chipped");
m_show_flawed = get_control<ui::controls::checkbox>("m_show_flawed");
m_show_normal = get_control<ui::controls::checkbox>("m_show_normal");
m_show_flawless = get_control<ui::controls::checkbox>("m_show_flawless");
m_show_perfect = get_control<ui::controls::checkbox>("m_show_perfect");
if (m_show_r01) {
m_show_r01->set_state(loot_filter_settings::get().m_show_r01);
m_show_r01->set_on_click(std::bind(&loot_filter_settings_menu::extract_r01,
this, std::placeholders::_1));
}
if (m_altonly) {
m_altonly->set_state(loot_filter_settings::get().alt_only);
m_altonly->set_on_click(std::bind(&loot_filter_settings_menu::update_alt_only,
@ -97,6 +213,50 @@ void d2_tweaks::client::modules::loot_filter_settings_menu::update_alt_only(bool
loot_filter_settings::get().save(diablo2::d2_client::get_local_player_name());
}
void d2_tweaks::client::modules::loot_filter_settings_menu::extract_r01(bool value) {
loot_filter_settings::get().m_show_r01 = value;
// display m_show_r01 value in a messagebox
//MessageBoxA(NULL, value ? "true" : "false", "m_show_r01", MB_OK);
auto player = diablo2::d2_client::get_local_player();
auto inventory = player->inventory;
diablo2::structures::unit* bag;
uint32_t bagGuid;
uint32_t statValue;
// iterate over all items in player inventory
for (auto item = 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);
auto recordType = diablo2::d2_common::get_item_type_record(record->type);
char* normCode1 = record->string_code;
if (strncmp(normCode1, "ib1", 3) == 0) {
bag = item;
bagGuid = item->guid;
// get item stat
statValue = diablo2::d2_common::get_stat(item, diablo2::UNIT_STAT_runebag_RunesA, NULL);
}
}
// show statValue in a messagebox
std::string statValueStr = std::to_string(statValue);
MessageBoxA(NULL, statValueStr.c_str(), "statValue", MB_OK);
// Create the packet
//static d2_tweaks::common::item_move_cs packet;
//packet.item_guid = bagGuid;
//packet.target_page = 0;
//packet.extract = 1;
//packet.iCode = 'r01 ';
//diablo2::d2_client::send_to_server(&packet, sizeof packet);
}
void d2_tweaks::client::modules::loot_filter_settings_menu::update_show_gold(bool value) {
loot_filter_settings::get().show_gold = value;
loot_filter_settings::get().save(diablo2::d2_client::get_local_player_name());

View File

@ -26,31 +26,8 @@
#include <iomanip> // For std::setw
enum D2C_ItemQualities
{
ITEMQUAL_INFERIOR = 0x01, //0x01 Inferior
ITEMQUAL_NORMAL = 0x02, //0x02 Normal
ITEMQUAL_SUPERIOR = 0x03, //0x03 Superior
ITEMQUAL_MAGIC = 0x04, //0x04 Magic
ITEMQUAL_SET = 0x05, //0x05 Set
ITEMQUAL_RARE = 0x06, //0x06 Rare
ITEMQUAL_UNIQUE = 0x07, //0x07 Unique
ITEMQUAL_CRAFT = 0x08, //0x08 Crafted
ITEMQUAL_TEMPERED = 0x09 //0x09 Tempered
};
void serialize_item(const std::string& itemcode, const diablo2::structures::unit& item, std::ofstream& file) {
// Write item code
file << itemcode << ":";
// Write serialized data
for (size_t i = 0; i < sizeof(item); ++i) {
file << std::hex << std::setw(2) << std::setfill('0') << static_cast<unsigned>(reinterpret_cast<const char*>(&item)[i]);
}
// Add a newline after each item
file << std::endl;
static uint32_t reverseDWORD(uint32_t dw) {
return ((dw << 24) & 0xFF000000) | ((dw << 8) & 0x00FF0000) | ((dw >> 8) & 0x0000FF00) | ((dw >> 24) & 0x000000FF);
}
MODULE_INIT(item_move)
@ -86,57 +63,26 @@ bool d2_tweaks::server::modules::item_move::handle_packet(diablo2::structures::g
const char* itemcode = itemMove->item_code;
const auto bag = instance.get_server_unit(game, itemMove->bag_guid, diablo2::structures::unit_type_t::UNIT_TYPE_ITEM); //0x4 = item
if (itemMove->tmog == 1) {
//if (itemMove->extract == 1) {
// // display bag guid in a messagebox
// std::string bag_guid = std::to_string(itemMove->bag_guid);
// MessageBox(NULL, bag_guid.c_str(), "Bag GUID", MB_OK | MB_ICONINFORMATION);
// diablo2::d2_game::QUESTS_CreateItem(game, player, reverseDWORD(itemMove->iCode), 1, diablo2::structures::ITEMQUAL_NORMAL, true);
// return true;
//}
// else
if (itemMove->tmog == 1) {
// here we need to add item to inventory
const auto item = instance.get_server_unit(game, itemMove->item_guid, diablo2::structures::unit_type_t::UNIT_TYPE_ITEM); //0x4 = item
diablo2::d2_game::D2GAME_Transmogrify_6FC4A660(game, player, item);
//auto gemCode = diablo2::d2_common::get_item_id_from_item_code(' vfg');
//diablo2::structures::D2ItemDropStrc itemDrop = {};
//diablo2::structures::D2CoordStrc pReturnCoords = {};
//auto player = diablo2::d2_client::get_local_player();
//itemDrop.pSeed = nullptr;
//itemDrop.nX = pReturnCoords.nX;
//itemDrop.nY = pReturnCoords.nY;
//itemDrop.wItemFormat = game->item_format;
//itemDrop.pRoom = 0;
//itemDrop.nQuality = ITEMQUAL_NORMAL;
//itemDrop.pUnit = player;
//itemDrop.pGame = game;
//itemDrop.nId = gemCode;
//itemDrop.nSpawnType = 4;
//itemDrop.wUnitInitFlags = 1;
//itemDrop.nItemLvl = 1;
//diablo2::structures::unit* nItem = diablo2::d2_game::D2GAME_CreateItemEx_6FC4ED80(game, &itemDrop, 0);
//Display nITem->guid in a messagebox
//std::string guid = std::to_string(nItem->guid);
//MessageBox(NULL, guid.c_str(), "Item GUID", MB_OK | MB_ICONINFORMATION);
//const auto inventoryIndex = diablo2::d2_common::get_inventory_index(player, 0, game->item_format == 101);
//uint32_t tx, ty;
//if (!find_free_space(player->inventory, nItem, inventoryIndex, 0, tx, ty))
// return true; //block further packet processing
//
//nItem->item_data->page = 0;
//diablo2::d2_common::inv_add_item(player->inventory, nItem, tx, ty, inventoryIndex, false, nItem->item_data->page);
//diablo2::d2_common::inv_update_item(player->inventory, nItem, false);
//diablo2::d2_game::update_inventory_items(game, player);
////send update packet
//resp.item_guid = nItem->guid;
//resp.target_page = 0;
//resp.tx = tx;
//resp.ty = ty;
//const auto client = player->player_data->net_client;
//diablo2::d2_net::send_to_client(1, client->client_id, &resp, sizeof resp);
diablo2::d2_game::QUESTS_CreateItem(game, player, reverseDWORD('gfv '), 1, diablo2::structures::ITEMQUAL_NORMAL, true);
}
else {

View File

@ -152,6 +152,11 @@ int32_t __fastcall diablo2::d2_game::D2GAME_Transmogrify_6FC4A660(diablo2::struc
return D2GAME_Transmogrify_6FC4A660(pGame, pPlayer, pItem);
}
//D2Game.0x6FC95DF0
//D2UnitStrc* __fastcall QUESTS_CreateItem(D2GameStrc* pGame, D2UnitStrc* pPlayer, uint32_t dwCode, int32_t nLevel, uint8_t nQuality, int32_t bDroppable)
diablo2::structures::unit* __fastcall diablo2::d2_game::QUESTS_CreateItem(diablo2::structures::game* pGame, diablo2::structures::unit* pPlayer, uint32_t dwCode, int32_t nLevel, uint8_t nQuality, int32_t bDroppable) {
static wrap_func_fast< diablo2::structures::unit* (diablo2::structures::game*, diablo2::structures::unit*, uint32_t, int32_t, uint8_t, int32_t)>QUESTS_CreateItem(0x65DF0, get_base());
return QUESTS_CreateItem(pGame, pPlayer, dwCode, nLevel, nQuality, bDroppable);
}