Skip to content

Commit

Permalink
add shared stash class and form
Browse files Browse the repository at this point in the history
fix reading null values from json files
Add other jewel images
add more context menu items to Items form
fix up images
  • Loading branch information
WalterCouto committed Mar 7, 2022
1 parent ad818b6 commit 22f443a
Show file tree
Hide file tree
Showing 73 changed files with 56,918 additions and 622 deletions.
Binary file modified D2Editor.exe
Binary file not shown.
8 changes: 8 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ Check the following site for updates at https://github.com/WalterCouto/D2CE<br>
* [d2s Binary File Format](d2s_File_Format.md)<br>

### Revision History
**Version 2.14 (Mar 7, 2022)**
- Updated: Updated jewel alternate images.<br>
- Updated: Updated item context menus across forms showing items.<br>
<br>

- Added: Shared Stash support. Users can now view and edit items in the shared stash if the file is present in the same location as their character.<br>
<br>

**Version 2.13 (Feb 28, 2022)**
- Updated: Fix detection of ID for set items.<br>
- Updated: Fix up logic for reading/writing 1.00 - 1.06 files<br>
Expand Down
196 changes: 114 additions & 82 deletions source/D2AddGemsForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@ CD2AddGemsForm::CD2AddGemsForm(CD2MainForm& form)

}
//---------------------------------------------------------------------------
CD2AddGemsForm::CD2AddGemsForm(CD2ItemsForm& form, d2ce::Item* itemPtr)
: CDialogEx(CD2AddGemsForm::IDD, (CWnd*)&form), MainForm(form.MainForm), ItemsFormPtr(&form), ItemPtr(itemPtr)
CD2AddGemsForm::CD2AddGemsForm(CD2ItemsForm& form)
: CDialogEx(CD2AddGemsForm::IDD, (CWnd*)&form), MainForm(form.MainForm), ItemsFormPtr(&form), ItemPtr(form.CurrItem)
{
}
//---------------------------------------------------------------------------
CD2AddGemsForm::CD2AddGemsForm(CD2SharedStashForm& form)
: CDialogEx(CD2AddGemsForm::IDD, (CWnd*)&form), MainForm(form.MainForm), SharedStashFormPtr(&form), ItemPtr(form.CurrItem)
{
}
//---------------------------------------------------------------------------
Expand Down Expand Up @@ -123,63 +128,72 @@ BOOL CD2AddGemsForm::OnInitDialog()
}

// Fill in to combo
CComboBox* pToCombo = (CComboBox*)GetDlgItem(IDC_TO_COMBO);
if (pToCombo != nullptr)
CComboBox* pLocationCombo = (CComboBox*)GetDlgItem(IDC_LOCATION_COMBO);
if (pLocationCombo != nullptr)
{
std::array< std::uint8_t, 2> locationCode = { 0x00, 0x00 };
std::uint16_t& itemData = *reinterpret_cast<std::uint16_t*>(locationCode.data());
std::uint8_t& locationID = locationCode[0];
std::uint8_t& altLocationId = locationCode[1];

std::uint16_t selectedItemData = 0;
if (ItemPtr != nullptr)
if (SharedStashFormPtr != nullptr)
{
locationID = static_cast<std::underlying_type_t<d2ce::EnumItemLocation>>(ItemPtr->getLocation());
altLocationId = static_cast<std::underlying_type_t<d2ce::EnumAltItemLocation>>(ItemPtr->getAltPositionId());
selectedItemData = itemData;
CString str;
str.Format(_T("Shared Stash %ld"), SharedStashFormPtr->getCurrentPage() + 1);
auto insertedIdx = pLocationCombo->AddString(str);
pLocationCombo->SetItemData(insertedIdx, std::uint64_t(SharedStashFormPtr->getCurrentPage()));
pLocationCombo->SetCurSel(0);
}
int selectedIdx = isPotionSelected ? 0 : 1;

locationID = static_cast<std::underlying_type_t<d2ce::EnumItemLocation>>(d2ce::EnumItemLocation::BELT);
altLocationId = static_cast<std::underlying_type_t<d2ce::EnumAltItemLocation>>(d2ce::EnumAltItemLocation::UNKNOWN);
auto insertedIdx = pToCombo->AddString(_T("Belt"));
pToCombo->SetItemData(insertedIdx, std::uint64_t(itemData));
if (itemData == selectedItemData)
else
{
selectedIdx = insertedIdx;
}
std::array< std::uint8_t, 2> locationCode = { 0x00, 0x00 };
std::uint16_t& itemData = *reinterpret_cast<std::uint16_t*>(locationCode.data());
std::uint8_t& locationID = locationCode[0];
std::uint8_t& altLocationId = locationCode[1];

std::uint16_t selectedItemData = 0;
if (ItemsFormPtr != nullptr)
{
selectedItemData = *reinterpret_cast<std::uint16_t*>(ItemsFormPtr->CurrItemLocation.data());
}
int selectedIdx = isPotionSelected ? 0 : 1;

locationID = static_cast<std::underlying_type_t<d2ce::EnumItemLocation>>(d2ce::EnumItemLocation::BELT);
altLocationId = static_cast<std::underlying_type_t<d2ce::EnumAltItemLocation>>(d2ce::EnumAltItemLocation::UNKNOWN);
auto insertedIdx = pLocationCombo->AddString(_T("Belt"));
pLocationCombo->SetItemData(insertedIdx, std::uint64_t(itemData));
if (itemData == selectedItemData)
{
selectedIdx = insertedIdx;
}

if (MainForm.getHasHoradricCube())
{
locationID = static_cast<std::underlying_type_t<d2ce::EnumItemLocation>>(d2ce::EnumItemLocation::STORED);
altLocationId = static_cast<std::underlying_type_t<d2ce::EnumAltItemLocation>>(d2ce::EnumAltItemLocation::HORADRIC_CUBE);
insertedIdx = pLocationCombo->AddString(_T("Horadric Cube"));
pLocationCombo->SetItemData(insertedIdx, std::uint64_t(itemData));
if (itemData == selectedItemData)
{
selectedIdx = insertedIdx;
}
}

if (MainForm.getHasHoradricCube())
{
locationID = static_cast<std::underlying_type_t<d2ce::EnumItemLocation>>(d2ce::EnumItemLocation::STORED);
altLocationId = static_cast<std::underlying_type_t<d2ce::EnumAltItemLocation>>(d2ce::EnumAltItemLocation::HORADRIC_CUBE);
insertedIdx = pToCombo->AddString(_T("Horadric Cube"));
pToCombo->SetItemData(insertedIdx, std::uint64_t(itemData));
altLocationId = static_cast<std::underlying_type_t<d2ce::EnumAltItemLocation>>(d2ce::EnumAltItemLocation::INVENTORY);
insertedIdx = pLocationCombo->AddString(_T("Inventory"));
pLocationCombo->SetItemData(insertedIdx, std::uint64_t(itemData));
if (itemData == selectedItemData)
{
selectedIdx = insertedIdx;
}
}

locationID = static_cast<std::underlying_type_t<d2ce::EnumItemLocation>>(d2ce::EnumItemLocation::STORED);
altLocationId = static_cast<std::underlying_type_t<d2ce::EnumAltItemLocation>>(d2ce::EnumAltItemLocation::INVENTORY);
insertedIdx = pToCombo->AddString(_T("Inventory"));
pToCombo->SetItemData(insertedIdx, std::uint64_t(itemData));
if (itemData == selectedItemData)
{
selectedIdx = insertedIdx;
}
locationID = static_cast<std::underlying_type_t<d2ce::EnumItemLocation>>(d2ce::EnumItemLocation::STORED);
altLocationId = static_cast<std::underlying_type_t<d2ce::EnumAltItemLocation>>(d2ce::EnumAltItemLocation::STASH);
insertedIdx = pLocationCombo->AddString(_T("Stash"));
pLocationCombo->SetItemData(insertedIdx, std::uint64_t(itemData));
if (itemData == selectedItemData)
{
selectedIdx = insertedIdx;
}

locationID = static_cast<std::underlying_type_t<d2ce::EnumItemLocation>>(d2ce::EnumItemLocation::STORED);
altLocationId = static_cast<std::underlying_type_t<d2ce::EnumAltItemLocation>>(d2ce::EnumAltItemLocation::STASH);
insertedIdx = pToCombo->AddString(_T("Stash"));
pToCombo->SetItemData(insertedIdx, std::uint64_t(itemData));
if (itemData == selectedItemData)
{
selectedIdx = insertedIdx;
pLocationCombo->SetCurSel(selectedIdx);
}

pToCombo->SetCurSel(selectedIdx);
}

return TRUE; // return TRUE unless you set the focus to a control
Expand All @@ -191,8 +205,8 @@ BOOL CD2AddGemsForm::OnInitDialog()
void CD2AddGemsForm::OnBnClickedAdd()
{
CComboBox* pFromCombo = (CComboBox*)GetDlgItem(IDC_FROM_COMBO);
CComboBox* pToCombo = (CComboBox*)GetDlgItem(IDC_TO_COMBO);
if (pFromCombo == nullptr || pToCombo == nullptr)
CComboBox* pLocationCombo = (CComboBox*)GetDlgItem(IDC_LOCATION_COMBO);
if (pFromCombo == nullptr || pLocationCombo == nullptr)
{
return;
}
Expand All @@ -202,56 +216,74 @@ void CD2AddGemsForm::OnBnClickedAdd()
std::array<std::uint8_t, 4> gemCode;
*reinterpret_cast<std::uint32_t*>(gemCode.data()) = std::uint32_t(itemDataFrom);

auto toIdx = pToCombo->GetCurSel();
std::array< std::uint8_t, 2> locationCode = { 0x00, 0x00 };
std::uint8_t& locationID = locationCode[0];
std::uint8_t& altLocationId = locationCode[1];
std::uint64_t itemDataTo = pToCombo->GetItemData(toIdx);
*reinterpret_cast<std::uint16_t*>(locationCode.data()) = std::uint16_t(itemDataTo);

if (ItemsFormPtr != nullptr)
auto toIdx = pLocationCombo->GetCurSel();
if (SharedStashFormPtr != nullptr)
{
if (!ItemsFormPtr->addItem(static_cast<d2ce::EnumItemLocation>(locationID), static_cast<d2ce::EnumAltItemLocation>(altLocationId), gemCode))
auto stashPage = size_t(pLocationCombo->GetItemData(toIdx));
if (!SharedStashFormPtr->addItem(gemCode, stashPage))
{
CString msg(_T("A "));
CString temp;
pFromCombo->GetLBText(fromIdx, temp);
msg += temp;
msg += _T(" was added to ");
pToCombo->GetLBText(toIdx, temp);
pLocationCombo->GetLBText(toIdx, temp);
msg += temp;
AfxMessageBox(msg, MB_ICONINFORMATION | MB_OK);
}
}
else if (!MainForm.addItem(static_cast<d2ce::EnumItemLocation>(locationID), static_cast<d2ce::EnumAltItemLocation>(altLocationId), gemCode))
{
CString msg(_T("A "));
CString temp;
pFromCombo->GetLBText(fromIdx, temp);
msg += temp;
msg += _T(" could not be added to ");
pToCombo->GetLBText(toIdx, temp);
msg += temp;
AfxMessageBox(msg, MB_ICONEXCLAMATION | MB_OK);
}
else
{
CString msg(_T("A "));
CString temp;
pFromCombo->GetLBText(fromIdx, temp);
msg += temp;
msg += _T(" was added to ");
pToCombo->GetLBText(toIdx, temp);
msg += temp;
AfxMessageBox(msg, MB_ICONINFORMATION | MB_OK);
std::array< std::uint8_t, 2> locationCode = { 0x00, 0x00 };
std::uint8_t& locationID = locationCode[0];
std::uint8_t& altLocationId = locationCode[1];
std::uint64_t itemDataTo = pLocationCombo->GetItemData(toIdx);
*reinterpret_cast<std::uint16_t*>(locationCode.data()) = std::uint16_t(itemDataTo);

if (ItemsFormPtr != nullptr)
{
if (!ItemsFormPtr->addItem(static_cast<d2ce::EnumItemLocation>(locationID), static_cast<d2ce::EnumAltItemLocation>(altLocationId), gemCode))
{
CString msg(_T("A "));
CString temp;
pFromCombo->GetLBText(fromIdx, temp);
msg += temp;
msg += _T(" was added to ");
pLocationCombo->GetLBText(toIdx, temp);
msg += temp;
AfxMessageBox(msg, MB_ICONINFORMATION | MB_OK);
}
}
else if (!MainForm.addItem(static_cast<d2ce::EnumItemLocation>(locationID), static_cast<d2ce::EnumAltItemLocation>(altLocationId), gemCode))
{
CString msg(_T("A "));
CString temp;
pFromCombo->GetLBText(fromIdx, temp);
msg += temp;
msg += _T(" could not be added to ");
pLocationCombo->GetLBText(toIdx, temp);
msg += temp;
AfxMessageBox(msg, MB_ICONEXCLAMATION | MB_OK);
}
else
{
CString msg(_T("A "));
CString temp;
pFromCombo->GetLBText(fromIdx, temp);
msg += temp;
msg += _T(" was added to ");
pLocationCombo->GetLBText(toIdx, temp);
msg += temp;
AfxMessageBox(msg, MB_ICONINFORMATION | MB_OK);
}
}
}
//---------------------------------------------------------------------------
void CD2AddGemsForm::OnBnClickedFill()
{
CComboBox* pFromCombo = (CComboBox*)GetDlgItem(IDC_FROM_COMBO);
CComboBox* pToCombo = (CComboBox*)GetDlgItem(IDC_TO_COMBO);
if (pFromCombo == nullptr || pToCombo == nullptr)
CComboBox* pLocationCombo = (CComboBox*)GetDlgItem(IDC_LOCATION_COMBO);
if (pFromCombo == nullptr || pLocationCombo == nullptr)
{
return;
}
Expand All @@ -261,11 +293,11 @@ void CD2AddGemsForm::OnBnClickedFill()
std::array<std::uint8_t, 4> gemCode;
*reinterpret_cast<std::uint32_t*>(gemCode.data()) = std::uint32_t(itemDataFrom);

auto toIdx = pToCombo->GetCurSel();
auto toIdx = pLocationCombo->GetCurSel();
std::array< std::uint8_t, 2> locationCode = { 0x00, 0x00 };
std::uint8_t& locationID = locationCode[0];
std::uint8_t& altLocationId = locationCode[1];
std::uint64_t itemDataTo = pToCombo->GetItemData(toIdx);
std::uint64_t itemDataTo = pLocationCombo->GetItemData(toIdx);
*reinterpret_cast<std::uint16_t*>(locationCode.data()) = std::uint16_t(itemDataTo);

size_t numAdded = 0;
Expand All @@ -283,7 +315,7 @@ void CD2AddGemsForm::OnBnClickedFill()
pFromCombo->GetLBText(fromIdx, temp);
msg += temp;
msg += _T(" were added to ");
pToCombo->GetLBText(toIdx, temp);
pLocationCombo->GetLBText(toIdx, temp);
msg += temp;
temp.Format(msg, numAdded);
AfxMessageBox(temp, MB_ICONINFORMATION | MB_OK);
Expand Down
5 changes: 4 additions & 1 deletion source/D2AddGemsForm.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
//---------------------------------------------------------------------------
#include "D2MainForm.h"
#include "D2ItemsForm.h"
#include "D2SharedStashForm.h"

//---------------------------------------------------------------------------
class CD2AddGemsForm : public CDialogEx
Expand All @@ -30,7 +31,8 @@ class CD2AddGemsForm : public CDialogEx

public:
CD2AddGemsForm(CD2MainForm& form);
CD2AddGemsForm(CD2ItemsForm& form, d2ce::Item* itemPtr = nullptr);
CD2AddGemsForm(CD2ItemsForm& form);
CD2AddGemsForm(CD2SharedStashForm& form);
virtual ~CD2AddGemsForm();

// Dialog Data
Expand All @@ -48,6 +50,7 @@ class CD2AddGemsForm : public CDialogEx
std::map<size_t, std::uint64_t> GemIdxMap;
std::map<std::uint64_t, size_t> NumGemMap;
CD2ItemsForm* ItemsFormPtr = nullptr;
CD2SharedStashForm* SharedStashFormPtr = nullptr;
d2ce::Item * ItemPtr = nullptr;

public:
Expand Down
9 changes: 9 additions & 0 deletions source/D2Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
Revision History
================
Version 2.14 (Mar 7, 2022)
- Updated: Updated jewel alternate images.
- Updated: Updated item context menus across forms showing
items.
- Added: Shared Stash support. Users can now view and edit
items in the shared stash if the file is present in the
same location as their character.
Version 2.13 (Feb 28, 2022)
- Updated: Fix detection of ID for set items.
- Updated: Fix up logic for reading/writing 1.00 - 1.06 files
Expand Down
Binary file modified source/D2Editor.rc
Binary file not shown.
Loading

0 comments on commit 22f443a

Please sign in to comment.