Skip to content

Commit c917f56

Browse files
committed
Fix load/save for custom items
1 parent 2e5ee71 commit c917f56

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

Source/cursor.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,6 @@ void FreeCursor()
461461
{
462462
pCursCels = std::nullopt;
463463
pCursCels2 = std::nullopt;
464-
FreeCustomCursorSprites();
465464
ClearCursor();
466465
}
467466

Source/loadsave.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,14 @@ void LoadMatchingItems(LoadHelper &file, const Player &player, const int n, Item
10851085
const bool success = LoadItemData(file, heroItem);
10861086
if (!success) {
10871087
heroItem.clear();
1088-
unpackedItem = Item();
1088+
// Do not clear unpackedItem: if the hero pack recreated it, keep it.
1089+
}
1090+
// If heroitems has valid data but the hero pack could not recreate
1091+
// the item (e.g. a custom mod item not in the drop tables), use
1092+
// heroitems as the primary source.
1093+
if (unpackedItem.isEmpty() && !heroItem.isEmpty()) {
1094+
unpackedItem = heroItem;
1095+
continue;
10891096
}
10901097
if (unpackedItem.isEmpty() || heroItem.isEmpty())
10911098
continue;

Source/tables/itemdat.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <fmt/format.h>
1313

14+
#include "cursor.h"
1415
#include "data/file.hpp"
1516
#include "data/iterators.hpp"
1617
#include "data/record_reader.hpp"
@@ -611,6 +612,8 @@ namespace {
611612

612613
void LoadItemDat()
613614
{
615+
FreeCustomCursorSprites();
616+
614617
const std::string_view filename = "txtdata\\items\\itemdat.tsv";
615618
DataFile dataFile = DataFile::loadOrDie(filename);
616619

0 commit comments

Comments
 (0)