From dd653e871f830b28968d32632caf68c02aaf8bba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 10 Jan 2021 14:36:11 +0100 Subject: [PATCH] uking/ui: Fix minor accuracy issue (don't use memcpy) Still matches, but the original code didn't use memcpy (according to the Wii U version) --- src/Game/UI/uiPauseMenuDataMgr.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Game/UI/uiPauseMenuDataMgr.cpp b/src/Game/UI/uiPauseMenuDataMgr.cpp index 03006e8c..6e5d5740 100644 --- a/src/Game/UI/uiPauseMenuDataMgr.cpp +++ b/src/Game/UI/uiPauseMenuDataMgr.cpp @@ -464,9 +464,6 @@ void PauseMenuDataMgr::restoreMasterSword(bool only_if_broken) { using SortPredicate = int (*)(const PouchItem* lhs, const PouchItem* rhs, ksys::act::InfoData* data); -static sead::SafeArray sSortPredicates{ - {sortWeapon, sortBow, sortShield, sortArmor, sortMaterial, sortFood, sortKeyItem}}; - static PouchCategory getTypeForCategory(PouchItemType type) { static constexpr sead::SafeArray sMap{{ PouchCategory::Weapon, // Weapon @@ -483,6 +480,12 @@ static PouchCategory getTypeForCategory(PouchItemType type) { return sMap[s32(type)]; } +static auto getSortPredicateTable() { + sead::SafeArray table{ + {sortWeapon, sortBow, sortShield, sortArmor, sortMaterial, sortFood, sortKeyItem}}; + return table; +} + int pouchItemSortPredicate(const PouchItem* lhs, const PouchItem* rhs) { if (!lhs || !rhs) return 0; @@ -500,8 +503,7 @@ int pouchItemSortPredicate(const PouchItem* lhs, const PouchItem* rhs) { if (cat3 != PouchCategory::Invalid && cat1 != cat3) return 0; - decltype(sSortPredicates) predicate_table{}; - sead::MemUtil::copy(&predicate_table, &sSortPredicates, sizeof(predicate_table)); + auto predicate_table = getSortPredicateTable(); const auto* fn = &predicate_table[0]; if (u32(cat1) < u32(predicate_table.size())) fn = &predicate_table(u32(cat1)); @@ -596,8 +598,7 @@ int pouchItemSortPredicateForArrow(const PouchItem* lhs, const PouchItem* rhs) { if (cat3 != PouchCategory::Invalid && cat1 != cat3) return 0; - decltype(sSortPredicates) predicate_table{}; - sead::MemUtil::copy(&predicate_table, &sSortPredicates, sizeof(predicate_table)); + const auto predicate_table = getSortPredicateTable(); const auto* fn = &predicate_table[0]; if (u32(cat1) < u32(predicate_table.size())) fn = &predicate_table(u32(cat1));