Skip to content

Commit

Permalink
ksys/qst: match Manager::setQuestStep
Browse files Browse the repository at this point in the history
I'm not a big fan of how the actual logic has to be inside the loop,
but unfortunately std::find_if doesn't match and it's clear that the
original version used iterators.
  • Loading branch information
leoetlino committed Apr 23, 2024
1 parent 726d8a2 commit a196e0c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
2 changes: 1 addition & 1 deletion data/uking_functions.csv
Original file line number Diff line number Diff line change
Expand Up @@ -84571,7 +84571,7 @@ Address,Quality,Size,Name
0x0000007100fd7a10,O,000116,_ZNK4ksys3qst7Manager5auto4EPNS_3act5ActorE
0x0000007100fd7a84,m,000172,_ZN4ksys3qst7Manager5auto0EPNS_3act5ActorE
0x0000007100fd7b30,O,000016,_ZN4ksys3qst7Manager14sub_7100FD7B30ERKN4sead14SafeStringBaseIcEES6_b
0x0000007100fd7b40,m,000624,_ZN4ksys3qst7Manager12setQuestStepERKN4sead14SafeStringBaseIcEES6_bbb
0x0000007100fd7b40,O,000624,_ZN4ksys3qst7Manager12setQuestStepERKN4sead14SafeStringBaseIcEES6_bbb
0x0000007100fd7db0,O,000020,_ZN4ksys3qst7Manager21setQuestStepFromEventERKN4sead14SafeStringBaseIcEES6_bb
0x0000007100fd7dc4,U,000680,sinitQuestManagerStrings
0x0000007100fd806c,m,000472,_ZN4ksys3qst5QuestC1ERKN4sead14SafeStringBaseIcEEPNS2_4HeapE
Expand Down
46 changes: 21 additions & 25 deletions src/KingSystem/Quest/qstManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,38 +102,34 @@ bool Manager::setQuestStepFromEvent(const sead::SafeString& quest_name,
return setQuestStep(quest_name, step_name, true, force_run_telop, setAocVersionFlag1);
}

// NON_MATCHING: quest is dereferenced several times
bool Manager::setQuestStep(const sead::SafeString& quest_name, const sead::SafeString& step_name,
bool copy_name, bool force_run_telop, bool setAocVersionFlag1) {
u32 hash = sead::HashCRC32::calcStringHash(quest_name.cstr());
Quest* quest;
for (auto& q : mQuests) {
if (q._c - 1 <= 1 && q.mNameHash == hash) {
quest = &q;
break;
}
}
if (quest == nullptr)
return false;
u32 hash = sead::HashCRC32::calcStringHash(quest_name);
for (auto it = mQuests.begin(), end = mQuests.end(); it != end; ++it) {
if ((it->_c != 1 && it->_c != 2) || it->mNameHash != hash)
continue;

quest->setField31();
it->setField31();

quest->_e8.copy(step_name);
it->_e8.copy(step_name);

quest->_e0 = false;
quest->mForceRunTelop = false;
it->_e0 = false;
it->mForceRunTelop = false;

if (copy_name) {
it->_e0 = true;
if (step_name.isEmpty())
it->_e8.copy(it->x_11());
}
if (force_run_telop)
it->mForceRunTelop = true;
if (setAocVersionFlag1)
it->mAocVersionFlags |= 1;

if (copy_name) {
quest->_e0 = true;
const char* x = quest->x_11();
if (step_name.isEmpty())
quest->_e8.copy(sead::SafeString(x));
return true;
}
if (force_run_telop)
quest->mForceRunTelop = true;
if (setAocVersionFlag1)
quest->mAocVersionFlags |= 1;
return true;

return false;
}

} // namespace ksys::qst

0 comments on commit a196e0c

Please sign in to comment.