Skip to content

Commit

Permalink
add jsoncpp for json serialization
Browse files Browse the repository at this point in the history
add ability to read json input
add ability to save json input as d2s character file
fix dead character bug
fix up level req for set and unique items
  • Loading branch information
WalterCouto committed Dec 7, 2021
1 parent 9bd57f9 commit 33f3d44
Show file tree
Hide file tree
Showing 68 changed files with 57,136 additions and 12,281 deletions.
Binary file modified D2Editor.exe
Binary file not shown.
14 changes: 13 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,25 @@ 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.07 (Dec 6, 2021)**<br>
- Updated: json export to use jsoncpp for easier export/import logic<br>
- Updated: fix bug where Hardcore characters would be detected as dead<br>
- Updated: get proper level requirement information for Set and Unique items<br>
<br>

- Added: tests for the serialized Json export/import functionality<br>
- Added: ability to directly load and edit Json files via the File Open and File Save commands.<br>
- Added: ability to convert a JSON character file to a D2S character file.<br>
<br>

**Version 2.06 (Nov 22, 2021)**<br>
- Added: Context menu for Gem, Potion or Skull items in Items Form<br>
- Added: Reading/Writing and Json export of the menu appearance section<br>
- Added: New Serialized Json Export compatable with D2SLib format. This format contains only the information available in the d2s file without the detailed interpretation given by the existing Json export logic. The previous JSON export is now called "Detailed" while the new JSON export is called "Serialized" in the menu.<br>
<br>

**Version 2.05 (Nov 14, 2021)**<br>
- Updated: Updated: Fix up handling of reading files with a corpse<br>
- Updated: Fix up handling of reading files with a corpse<br>
- Updated: Fix up setting/clearing the is potion bit<br>
<br>

Expand Down
12 changes: 12 additions & 0 deletions source/D2Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@
Revision History
================
Version 2.07 (Dec 6, 2021)
- Updated: json export to use jsoncpp for easier export/import logic
- Updated: fix bug where Hardcore characters would be detected as dead
- Updated: get proper level requirement information for Set and Unique
items
- Added: tests for the serialized Json export/import functionality
- Added: ability to directly load and edit Json files via the File
Open and File Save commands.
- Added: ability to convert a JSON character file to a D2S character
file.
Version 2.06 (Nov 22, 2021)
- Added: Context menu for Gem, Potion or Skull items in Items Form
- Added: Reading/Writing and Json export of the menu appearance section
Expand Down
Binary file modified source/D2Editor.rc
Binary file not shown.
39 changes: 35 additions & 4 deletions source/D2Editor.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<TreatWarningAsError>true</TreatWarningAsError>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalIncludeDirectories>.\</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>.\;$(SolutionDir)d2ce\thirdparty\jsoncpp\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -120,7 +120,7 @@
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<LanguageStandard>stdcpp17</LanguageStandard>
<TreatWarningAsError>true</TreatWarningAsError>
<AdditionalIncludeDirectories>.\</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>.\;$(SolutionDir)d2ce\thirdparty\jsoncpp\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -147,7 +147,7 @@
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<TreatWarningAsError>true</TreatWarningAsError>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalIncludeDirectories>.\</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>.\;$(SolutionDir)d2ce\thirdparty\jsoncpp\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down Expand Up @@ -182,7 +182,7 @@
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<TreatWarningAsError>true</TreatWarningAsError>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalIncludeDirectories>.\</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>.\;$(SolutionDir)d2ce\thirdparty\jsoncpp\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down Expand Up @@ -216,6 +216,18 @@
<ClInclude Include="d2ce\Constants.h" />
<ClInclude Include="d2ce\Mercenary.h" />
<ClInclude Include="d2ce\MercenaryConstants.h" />
<ClInclude Include="d2ce\thirdparty\jsoncpp\include\json\allocator.h" />
<ClInclude Include="d2ce\thirdparty\jsoncpp\include\json\assertions.h" />
<ClInclude Include="d2ce\thirdparty\jsoncpp\include\json\config.h" />
<ClInclude Include="d2ce\thirdparty\jsoncpp\include\json\forwards.h" />
<ClInclude Include="d2ce\thirdparty\jsoncpp\include\json\historic_map.h" />
<ClInclude Include="d2ce\thirdparty\jsoncpp\include\json\json.h" />
<ClInclude Include="d2ce\thirdparty\jsoncpp\include\json\json_features.h" />
<ClInclude Include="d2ce\thirdparty\jsoncpp\include\json\reader.h" />
<ClInclude Include="d2ce\thirdparty\jsoncpp\include\json\value.h" />
<ClInclude Include="d2ce\thirdparty\jsoncpp\include\json\version.h" />
<ClInclude Include="d2ce\thirdparty\jsoncpp\include\json\writer.h" />
<ClInclude Include="d2ce\thirdparty\jsoncpp\src\lib_json\json_tool.h" />
<ClInclude Include="D2Editor.h" />
<ClInclude Include="D2GemsForm.h" />
<ClInclude Include="D2ItemsForm.h" />
Expand Down Expand Up @@ -243,6 +255,24 @@
<ClCompile Include="d2ce\Character.cpp" />
<ClCompile Include="d2ce\CharacterStats.cpp" />
<ClCompile Include="d2ce\Mercenary.cpp" />
<ClCompile Include="d2ce\thirdparty\jsoncpp\src\lib_json\json_reader.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="d2ce\thirdparty\jsoncpp\src\lib_json\json_value.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="d2ce\thirdparty\jsoncpp\src\lib_json\json_writer.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="D2Editor.cpp" />
<ClCompile Include="D2GemsForm.cpp" />
<ClCompile Include="D2ItemsForm.cpp" />
Expand All @@ -265,6 +295,7 @@
<ResourceCompile Include="D2Editor.rc" />
</ItemGroup>
<ItemGroup>
<None Include="d2ce\thirdparty\jsoncpp\src\lib_json\json_valueiterator.inl" />
<None Include="res\D2Editor.rc2" />
</ItemGroup>
<ItemGroup>
Expand Down
54 changes: 54 additions & 0 deletions source/D2Editor.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
<Filter Include="Source Files\d2ce">
<UniqueIdentifier>{817a2518-8b00-48b6-bb76-9ea239b3c9b8}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\jsoncpp">
<UniqueIdentifier>{b431c38b-1f2a-4ee4-9f3c-d7baea1c4d35}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\jsoncpp">
<UniqueIdentifier>{769a1865-760b-454e-ab34-77f19cbfb1af}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="D2Editor.h">
Expand Down Expand Up @@ -111,6 +117,42 @@
<ClInclude Include="D2ItemsForm.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="d2ce\thirdparty\jsoncpp\include\json\allocator.h">
<Filter>Header Files\jsoncpp</Filter>
</ClInclude>
<ClInclude Include="d2ce\thirdparty\jsoncpp\include\json\assertions.h">
<Filter>Header Files\jsoncpp</Filter>
</ClInclude>
<ClInclude Include="d2ce\thirdparty\jsoncpp\include\json\config.h">
<Filter>Header Files\jsoncpp</Filter>
</ClInclude>
<ClInclude Include="d2ce\thirdparty\jsoncpp\include\json\forwards.h">
<Filter>Header Files\jsoncpp</Filter>
</ClInclude>
<ClInclude Include="d2ce\thirdparty\jsoncpp\include\json\json.h">
<Filter>Header Files\jsoncpp</Filter>
</ClInclude>
<ClInclude Include="d2ce\thirdparty\jsoncpp\include\json\json_features.h">
<Filter>Header Files\jsoncpp</Filter>
</ClInclude>
<ClInclude Include="d2ce\thirdparty\jsoncpp\include\json\reader.h">
<Filter>Header Files\jsoncpp</Filter>
</ClInclude>
<ClInclude Include="d2ce\thirdparty\jsoncpp\include\json\value.h">
<Filter>Header Files\jsoncpp</Filter>
</ClInclude>
<ClInclude Include="d2ce\thirdparty\jsoncpp\include\json\version.h">
<Filter>Header Files\jsoncpp</Filter>
</ClInclude>
<ClInclude Include="d2ce\thirdparty\jsoncpp\include\json\writer.h">
<Filter>Header Files\jsoncpp</Filter>
</ClInclude>
<ClInclude Include="d2ce\thirdparty\jsoncpp\src\lib_json\json_tool.h">
<Filter>Header Files\jsoncpp</Filter>
</ClInclude>
<ClInclude Include="d2ce\thirdparty\jsoncpp\include\json\historic_map.h">
<Filter>Header Files\jsoncpp</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="D2Editor.cpp">
Expand Down Expand Up @@ -161,6 +203,15 @@
<ClCompile Include="D2ItemsForm.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="d2ce\thirdparty\jsoncpp\src\lib_json\json_reader.cpp">
<Filter>Source Files\jsoncpp</Filter>
</ClCompile>
<ClCompile Include="d2ce\thirdparty\jsoncpp\src\lib_json\json_value.cpp">
<Filter>Source Files\jsoncpp</Filter>
</ClCompile>
<ClCompile Include="d2ce\thirdparty\jsoncpp\src\lib_json\json_writer.cpp">
<Filter>Source Files\jsoncpp</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="D2Editor.rc">
Expand All @@ -171,6 +222,9 @@
<None Include="res\D2Editor.rc2">
<Filter>Resource Files</Filter>
</None>
<None Include="d2ce\thirdparty\jsoncpp\src\lib_json\json_valueiterator.inl">
<Filter>Source Files\jsoncpp</Filter>
</None>
</ItemGroup>
<ItemGroup>
<Image Include="res\D2Editor.ico">
Expand Down
20 changes: 12 additions & 8 deletions source/D2GemsForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

namespace
{
CString GetGPSNameFromCode(const std::uint8_t(&gemCode)[4])
CString GetGPSNameFromCode(const std::array<std::uint8_t, 4>& gemCode)
{
const std::uint8_t& gem = gemCode[0];
const std::uint8_t& gemCondition = gemCode[1];
Expand Down Expand Up @@ -348,7 +348,7 @@ namespace
return _T(""); // unknown
}

size_t GetGPSSortIndex(const std::uint8_t(&gemCode)[4])
size_t GetGPSSortIndex(const std::array<std::uint8_t, 4>& gemCode)
{
size_t idx = 0;
const std::uint8_t& gem = gemCode[0];
Expand Down Expand Up @@ -647,13 +647,14 @@ BOOL CD2GemsForm::OnInitDialog()
if (pFromCombo != nullptr)
{
std::uint64_t itemData = 0;
std::uint8_t(&gemCode)[4] = *reinterpret_cast<std::uint8_t(*)[4]>((std::uint8_t*)&itemData);
std::array<std::uint8_t, 4> gemCode;
*reinterpret_cast<std::uint32_t*>(gemCode.data()) = std::uint32_t(itemData);
if (ItemPtr == nullptr)
{
auto& gems = MainForm.getGPSs();
for (auto& item : gems)
{
std::memset(gemCode, 0, sizeof(gemCode));
gemCode.fill(0);
if (!item.get().getItemCode(gemCode))
{
continue;
Expand All @@ -674,7 +675,7 @@ BOOL CD2GemsForm::OnInitDialog()
else
{
// Only add selected item
std::memset(gemCode, 0, sizeof(gemCode));
gemCode.fill(0);
if (ItemPtr->getItemCode(gemCode))
{
GemIdxMap.emplace(GetGPSSortIndex(gemCode), itemData);
Expand Down Expand Up @@ -703,7 +704,8 @@ BOOL CD2GemsForm::OnInitDialog()
if (pToCombo != nullptr)
{
std::uint64_t itemData = 0;
std::uint8_t(&gemCode)[4] = *reinterpret_cast<std::uint8_t(*)[4]>((std::uint8_t*)&itemData);
std::array< std::uint8_t, 4> gemCode;
*reinterpret_cast<std::uint32_t*>(gemCode.data()) = std::uint32_t(itemData);
std::uint8_t& gem = gemCode[0];
std::uint8_t& gemCondition = gemCode[1];
std::uint8_t& gemColour = gemCode[2];
Expand Down Expand Up @@ -890,10 +892,12 @@ void CD2GemsForm::OnBnClickedConvert()
if (fromIdx >= 0 && toIdx >= 0 && pFromCombo->GetItemData(fromIdx) != pToCombo->GetItemData(toIdx))
{
std::uint64_t itemDataFrom = pFromCombo->GetItemData(fromIdx);
std::uint8_t(&gemCodeFrom)[4] = *reinterpret_cast<std::uint8_t(*)[4]>((std::uint8_t*)&itemDataFrom);
std::array<std::uint8_t, 4> gemCodeFrom;
*reinterpret_cast<std::uint32_t*>(gemCodeFrom.data()) = std::uint32_t(itemDataFrom);

std::uint64_t itemDataTo = pToCombo->GetItemData(toIdx);
std::uint8_t(&gemCodeTo)[4] = *reinterpret_cast<std::uint8_t(*)[4]>((std::uint8_t*)&itemDataTo);
std::array<std::uint8_t, 4> gemCodeTo;
*reinterpret_cast<std::uint32_t*>(gemCodeTo.data()) = std::uint32_t(itemDataTo);

if (ItemPtr == nullptr)
{
Expand Down
2 changes: 1 addition & 1 deletion source/D2ItemsForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1533,7 +1533,7 @@ void CD2ItemsForm::CheckToolTipCtrl()
}
}
//---------------------------------------------------------------------------
bool CD2ItemsForm::updateGem(d2ce::Item& item, const std::uint8_t(&newgem)[4])
bool CD2ItemsForm::updateGem(d2ce::Item& item, const std::array<std::uint8_t, 4>& newgem)
{
if (!MainForm.updateGem(item, newgem))
{
Expand Down
2 changes: 1 addition & 1 deletion source/D2ItemsForm.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class CD2ItemsForm : public CDialogEx, public CD2ItemToolTipCtrlCallback, public

void CheckToolTipCtrl();

bool updateGem(d2ce::Item& item, const std::uint8_t(&newgem)[4]);
bool updateGem(d2ce::Item& item, const std::array<std::uint8_t, 4>& newgem);
bool upgradeGem(d2ce::Item& item);
bool upgradePotion(d2ce::Item& item);
bool upgradeToFullRejuvenationPotion(d2ce::Item& item);
Expand Down
Loading

0 comments on commit 33f3d44

Please sign in to comment.