Match PauseMenuDataMgr::removeGrabbedItem

This commit is contained in:
Léo Lam
2022-02-27 23:32:26 +01:00
parent a1fd80bd1c
commit 63bf3d2fa4
2 changed files with 32 additions and 34 deletions
+31 -33
View File
@@ -1338,44 +1338,42 @@ void PauseMenuDataMgr::removeGrabbedItems() {
saveToGameData(items);
}
// NON_MATCHING: mostly branching (which leads to other differences), but visibly equivalent
bool PauseMenuDataMgr::removeGrabbedItem(ksys::act::BaseProcLink* link) {
if (!link || !link->hasProc())
return false;
ksys::act::ActorConstDataAccess accessor;
ksys::act::acquireActor(link, &accessor);
const auto name = accessor.getName();
auto& cs = mCritSection;
const auto& items = getItems();
bool found = false;
if (link && link->hasProc()) {
ksys::act::ActorConstDataAccess accessor;
ksys::act::acquireActor(link, &accessor);
const auto name = accessor.getName();
auto& cs = mCritSection;
const auto& items = getItems();
for (s32 i = 0; i < NumGrabbableItems; ++i) {
auto& entry = mGrabbedItems[i];
if (found) {
mGrabbedItems[i - 1].item = entry.item;
mGrabbedItems[i - 1]._8 = entry._8;
mGrabbedItems[i - 1]._9 = entry._9;
continue;
for (s32 i = 0; i < NumGrabbableItems; ++i) {
auto& entry = mGrabbedItems[i];
if (found) {
mGrabbedItems[i - 1].item = entry.item;
mGrabbedItems[i - 1]._8 = entry._8;
mGrabbedItems[i - 1]._9 = entry._9;
continue;
}
if (!entry.item || name != entry.item->getName())
continue;
if (entry.item->getValue() == 0 && !entry._9) {
const auto lock = sead::makeScopedLock(cs);
auto* item = entry.item;
destroyAndRecycleItem(mItemLists, item);
updateInventoryInfo(items);
updateListHeads();
saveToGameData(items);
mLastAddedItem = nullptr;
}
found = true;
entry = {};
}
if (!entry.item || name != entry.item->getName())
continue;
if (entry.item->getValue() == 0 && !entry._9) {
const auto lock = sead::makeScopedLock(cs);
auto* item = entry.item;
destroyAndRecycleItem(mItemLists, item);
updateInventoryInfo(items);
updateListHeads();
saveToGameData(items);
mLastAddedItem = nullptr;
}
found = true;
entry = {};
mGrabbedItems[4] = {};
}
mGrabbedItems[4] = {};
return found;
}