Everything ini configurable

This commit is contained in:
Hash Borgir
2024-05-03 07:34:36 -06:00
parent 7fd617abd7
commit 06c28f4d56
48 changed files with 254 additions and 153 deletions

View File

@@ -236,15 +236,9 @@ public:
for (const auto& stat : stats) {
int param = stat.param;
int op = stat.op;
int32_t spirits = diablo2::d2_common::get_stat(player, static_cast<diablo2::unit_stats_t>(185), NULL);
int32_t soulscaptured = statValue = diablo2::d2_common::get_stat(player, static_cast<diablo2::unit_stats_t>(184), NULL);
auto statline = diablo2::d2_common::get_item_stat_cost_record(stat.stat);
auto opBase = statline->wOpBase;
auto opStat = statline->wOpStat[0];
auto opBaseValue = diablo2::d2_common::get_stat(player, static_cast<diablo2::unit_stats_t>(opBase), NULL);
auto opStatValue = diablo2::d2_common::get_stat(player, static_cast<diablo2::unit_stats_t>(opStat), NULL);
@@ -299,8 +293,6 @@ public:
if (!diablo2::d2_client::get_ui_window_state(diablo2::UI_WINDOW_STASH)
&& !diablo2::d2_client::get_ui_window_state(diablo2::UI_WINDOW_CHARACTER)
// && !diablo2::d2_client::get_ui_window_state(diablo2::UI_WINDOW_INVENTORY)
// && !diablo2::d2_client::get_ui_window_state(diablo2::UI_WINDOW_SKILL)
&& !diablo2::d2_client::get_ui_window_state(diablo2::UI_WINDOW_CHAT)
&& !diablo2::d2_client::get_ui_window_state(diablo2::UI_WINDOW_NPCMENU)
&& !diablo2::d2_client::get_ui_window_state(diablo2::UI_WINDOW_MAINMENU)
@@ -329,34 +321,25 @@ public:
//diablo2::d2_win::draw_boxed_text(const_cast<wchar_t*>(statText.c_str()), stat.x1, stat.y1 + textOffset, 1, 0, stat.colorStat);
//diablo2::d2_win::draw_boxed_text(const_cast<wchar_t*>(statValueStr.c_str()), stat.x2, stat.y2 + textOffset, 1, 4, stat.colorStatValue);
// diablo2::d2_win::set_current_font(diablo2::UI_FONT_16); // Set font to FONT16
//diablo2::structures::d2_cmp::init_gfx_data(&g_gfxdata);
//diablo2::d2_gfx::draw_image(&g_gfxdata, 200, 200, 1, 5, 0);
// instead try to load direct jpg with gdi and insetad ofloading jpg file, specify it bb64 encoded and decode it.
}
}
if (m_help_enabled) {
const int windowWidth = 1280;
const int windowHeight = 768;
const int boxWidth = 1000;
const int boxHeight = 680;
const int boxX = (windowWidth - boxWidth) / 2;
const int boxY = (windowHeight - boxHeight) / 2;
const std::string helpText = "This is a sample help screen! You can put help text in here!?";
// Draw filled background box
diablo2::d2_gfx::draw_filled_rect(boxX, boxY, boxX + boxWidth, boxY + boxHeight, 0, 255);
// Draw justified text inside the box with padding
drawJustifiedTextInBox(helpText, boxX, boxY, boxWidth, boxHeight, 0);
//const int windowWidth = 1280;
//const int windowHeight = 768;
//const int boxWidth = 1000;
//const int boxHeight = 680;
//const int boxX = (windowWidth - boxWidth) / 2;
//const int boxY = (windowHeight - boxHeight) / 2;
//const std::string helpText = "This is a sample help screen! You can put help text in here!?";
//// Draw filled background box
//diablo2::d2_gfx::draw_filled_rect(boxX, boxY, boxX + boxWidth, boxY + boxHeight, 0, 255);
//// Draw justified text inside the box with padding
//drawJustifiedTextInBox(helpText, boxX, boxY, boxWidth, boxHeight, 0);
}
diablo2::ui_color_t::UI_COLOR_WHITE;
@@ -391,8 +374,6 @@ public:
int sHCenter = sHeight / 2;
int sWCenter = sWidth / 2;
//spdlog::info("healthPercentage: {}", healthPercentage);
// Define default bar color
DWORD barColor = 0;
@@ -407,42 +388,54 @@ public:
barColor = 5;
}
//spdlog::info("barColor: {}", barColor);
// Define the dimensions for the bars
int barWidth = 200; // Width of the bars
int barHeight = 16; // Height of the bars
int pbarWidth = GetPrivateProfileIntA("Options", "pbarWidth", 200, "./d2tweaks.ini");
int pbarHeight = GetPrivateProfileIntA("Options", "pbarHeight", 16, "./d2tweaks.ini");
// Define the coordinates for the bars
int barX = 245; // Left coordinate of the bars
int barY_HP = 728; // Top coordinate of the HP bar
int barY_Mana = barY_HP + barHeight + 4; // Top coordinate of the Mana bar with separator
int barY_Stamina = barY_Mana + barHeight + 4; // Top coordinate of the Stamina bar with separator
int barY_Mana = barY_HP + pbarHeight + 4; // Top coordinate of the Mana bar with separator
int barY_Stamina = barY_Mana + pbarHeight + 4; // Top coordinate of the Stamina bar with separator
std::wstring life = strHP + L" / " + strMaxHP;
std::wstring mana = strMana + L" / " + strMaxMana;
std::wstring stamina = strStamina + L" / " + strMaxStamina;
// Calculate the filled widths of the bars
int filledHPWidth = static_cast<int>(healthPercentage * barWidth);
int filledManaWidth = static_cast<int>(manaPercentage * barWidth);
int filledStaminaWidth = static_cast<int>(staminaPercentage * barWidth);
int filledHPWidth = static_cast<int>(healthPercentage * pbarWidth);
int filledManaWidth = static_cast<int>(manaPercentage * pbarWidth);
int filledStaminaWidth = static_cast<int>(staminaPercentage * pbarWidth);
// at 345 we need to minus the width of the text
sWCenter = barX + 100 - (diablo2::d2_win::get_text_pixel_width(const_cast<wchar_t*>(mana.c_str())) / 2);
HWND diabloIIWnd = FindDiabloIIWindow();
// Draw the filled HP bar
diablo2::d2_gfx::draw_filled_rect(barX, barY_HP, barX + filledHPWidth, barY_HP + barHeight, barColor, 255);
//DrawFilledRect(diabloIIWnd, barX, barY_HP, barX + filledHPWidth, barY_HP + barHeight, RGB(255, 0, 0)); // Red color for HP
diablo2::d2_win::draw_text(const_cast<wchar_t*>(life.c_str()), sWCenter, barY_HP + 15, diablo2::UI_COLOR_WHITE, 0);
// Get player_bars_enabled from [Options] in d2tweaks.ini
int player_bars_enabled_hp = GetPrivateProfileIntA("Options", "player_bars_hp_enabled", 1, "./d2tweaks.ini");
int player_bars_X_hp = GetPrivateProfileIntA("Options", "player_bars_hp_X", barX, "./d2tweaks.ini");
int player_bars_Y_hp = GetPrivateProfileIntA("Options", "player_bars_hp_Y", barY_HP, "./d2tweaks.ini");
// Draw the filled Mana bar
diablo2::d2_gfx::draw_filled_rect(barX, barY_Mana, barX + filledManaWidth, barY_Mana + barHeight, 140, 255);
//DrawFilledRect(diabloIIWnd, barX, barY_Mana, barX + filledManaWidth, barY_Mana + barHeight, RGB(100, 100, 255)); // Blue color for Mana
diablo2::d2_win::draw_text(const_cast<wchar_t*>(mana.c_str()), sWCenter, barY_Mana + 15, diablo2::UI_COLOR_WHITE, 0);
int player_bars_enabled_mana = GetPrivateProfileIntA("Options", "player_bars_mana_enabled", 1, "./d2tweaks.ini");
int player_bars_X_mana = GetPrivateProfileIntA("Options", "player_bars_mana_X", barX, "./d2tweaks.ini");
int player_bars_Y_mana = GetPrivateProfileIntA("Options", "player_bars_mana_Y", barY_Mana, "./d2tweaks.ini");
if (player_bars_enabled_hp == 1) {
// Draw the filled HP bar
diablo2::d2_gfx::draw_filled_rect(player_bars_X_hp, player_bars_Y_hp, barX + filledHPWidth, barY_HP + pbarHeight, barColor, 255);
//DrawFilledRect(diabloIIWnd, barX, barY_HP, barX + filledHPWidth, barY_HP + barHeight, RGB(255, 0, 0)); // Red color for HP
diablo2::d2_win::draw_text(const_cast<wchar_t*>(life.c_str()), sWCenter, barY_HP + 15, diablo2::UI_COLOR_WHITE, 0);
}
if (player_bars_enabled_mana == 1) {
// Draw the filled Mana bar
diablo2::d2_gfx::draw_filled_rect(player_bars_X_mana, player_bars_Y_mana, barX + filledManaWidth, barY_Mana + pbarHeight, 140, 255);
//DrawFilledRect(diabloIIWnd, barX, barY_Mana, barX + filledManaWidth, barY_Mana + barHeight, RGB(100, 100, 255)); // Blue color for Mana
diablo2::d2_win::draw_text(const_cast<wchar_t*>(mana.c_str()), sWCenter, barY_Mana + 15, diablo2::UI_COLOR_WHITE, 0);
}
/*
// Define the number of separators
int numColors = 256;

View File

@@ -5,91 +5,45 @@
#include <d2tweaks/ui/controls/button.h>
#include <d2tweaks/client/client.h>
#include <diablo2/d2client.h>
#include <d2tweaks/ui/ui_manager.h>
#include <diablo2/d2gfx.h>
#include <DllNotify.h>
#include <D2Template.h>
#include <diablo2/d2gfx.h>
#include <string>
#include <vector>
#include <sstream>
#include <string>
#include <locale>
#include <codecvt>
#include <cstdlib> // For system function
#include <shellapi.h> // For ShellExecute
#include <diablo2/d2common.h>
#include <d2tweaks/ui/ui_manager.h>
#include <cstdlib> // For system function
#include <shellapi.h> // For ShellExecute
#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
@@ -123,40 +77,57 @@ d2_tweaks::client::modules::loot_filter_settings_toggle_menu::loot_filter_settin
m_filter_settings_menu = singleton<ui::ui_manager>::instance().get_menu("loot_filter_settings_menu");
// toggle stats button
m_btn_toggle_stats = static_cast<ui::controls::button*>(get_control("m_toggle_stats"));
m_btn_toggle_stats->set_enabled(true);
m_btn_toggle_stats->set_visible(true);
m_btn_toggle_stats->set_on_click(std::bind(&loot_filter_settings_toggle_menu::toggle_stats_settings_click, this));
// help button
m_btn_toggle_help = static_cast<ui::controls::button*>(get_control("m_toggle_help"));
m_btn_toggle_help->set_enabled(true);
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));
// toggle open/close cube button
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);
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, "box", 3) == 0) {
m_btn_toggle_cube->set_enabled(true);
m_btn_toggle_cube->set_visible(true);
break;
}
else {
m_btn_toggle_cube->set_enabled(false);
m_btn_toggle_cube->set_visible(false);
}
}
m_btn_toggle_cube->set_on_click(std::bind(&loot_filter_settings_toggle_menu::toggle_cube_click, this));
// toggle open/close stash button
m_btn_toggle_stash = static_cast<ui::controls::button*>(get_control("m_toggle_stash"));
m_btn_toggle_stash->set_enabled(true);
m_btn_toggle_stash->set_visible(true);
//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;
// }
// else {
// m_btn_toggle_stash->set_enabled(false);
// m_btn_toggle_stash->set_visible(false);
// }
//}
//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;
}
else {
m_btn_toggle_stash->set_enabled(false);
m_btn_toggle_stash->set_visible(false);
}
}
m_btn_toggle_stash->set_on_click(std::bind(&loot_filter_settings_toggle_menu::toggle_stash_click, this));
}
@@ -244,9 +215,7 @@ void d2_tweaks::client::modules::loot_filter_settings_toggle_menu::toggle_stash_
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);
}
@@ -255,7 +224,11 @@ void d2_tweaks::client::modules::loot_filter_settings_toggle_menu::toggle_stash_
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
const std::string url = "https://im.stoned.io";
// read the url from the ./d2tweaks.ini file
char urlBuffer[256];
GetPrivateProfileStringA("Options", "help_url", "", urlBuffer, sizeof(urlBuffer), "./d2tweaks.ini");
const std::string url(urlBuffer);
#ifdef _WIN32
// For Windows
ShellExecute(nullptr, "open", url.c_str(), nullptr, nullptr, SW_SHOWNORMAL);

View File

@@ -71,6 +71,12 @@
#include <d2tweaks/client/client.h>
#include <chrono> // Include chrono for time-based operations
// Define a static variable to keep track of the last time the stash window was toggled
static std::chrono::steady_clock::time_point lastToggleTime;
#pragma pack(push, 1)
using namespace std;
@@ -247,37 +253,101 @@ LRESULT d2_tweaks::ui::ui_manager::wnd_proc(HWND hWnd, UINT msg, WPARAM wParam,
}
if (wParam == 'V') {
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;
// Define a cooldown duration in milliseconds
constexpr int cooldownDuration = 500; // Adjust this value as needed
// Get the current time
auto currentTime = std::chrono::steady_clock::now();
// Calculate the time elapsed since the last stash toggle
auto timeElapsed = std::chrono::duration_cast<std::chrono::milliseconds>(currentTime - lastToggleTime).count();
// Check if enough time has elapsed since the last toggle
if (timeElapsed >= cooldownDuration) {
// Update the last toggle time
lastToggleTime = currentTime;
if (!diablo2::d2_client::get_ui_window_state(diablo2::UI_WINDOW_STASH)) {
// Code to open stash
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);
block = true;
// MessageBoxA(NULL, "Stash opened", "Stash", MB_OK);
// spdlog::info("Stash opened");
}
else {
// Code to close stash
// Close stash
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);
block = true;
}
}
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);
m_stash_enabled = false;
block = true;
}
//if (wParam == 'V') {
// 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);
// m_stash_enabled = false;
// block = true;
//}
// Send item move packet + transmute packet for certain codes only for runes and gems
if (wParam == 'G') {
// Call the item_click function using the function pointer