Skip to content

Commit 6e405aa

Browse files
committed
Fixed issue where new perk functions did not work correctly on player reference
1 parent 6ef16e9 commit 6e405aa

File tree

1 file changed

+68
-26
lines changed

1 file changed

+68
-26
lines changed

src/Papyrus/PapyrusActor.cpp

Lines changed: 68 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,30 @@ namespace PapyrusActor
3939
return -1;
4040
}
4141

42-
if (const auto actorBase = a_actor->GetActorBase(); actorBase) {
43-
if (const auto perkArray = actorBase->As<RE::BGSPerkRankArray>(); perkArray) {
44-
for (std::uint32_t i = 0; i < perkArray->perkCount; ++i) {
45-
const auto perkData = perkArray->perks[i];
46-
47-
if (const auto perk = perkData.perk; perk) {
42+
if (auto player = RE::PlayerCharacter::GetSingleton(); player == a_actor) {
43+
if (const auto perkArray = player->addedPerks; !perkArray.empty()) {
44+
for (auto perkData : perkArray) {
45+
if (const auto perk = perkData->perk; perk) {
4846
if (auto it = std::find(a_perks.begin(), a_perks.end(), perk); it != a_perks.end()) {
4947
return static_cast<std::int32_t>(it - a_perks.begin());
5048
}
5149
}
5250
}
5351
}
52+
} else {
53+
if (const auto actorBase = a_actor->GetActorBase(); actorBase) {
54+
if (const auto perkArray = actorBase->As<RE::BGSPerkRankArray>(); perkArray) {
55+
for (std::uint32_t i = 0; i < perkArray->perkCount; ++i) {
56+
const auto perkData = perkArray->perks[i];
57+
58+
if (const auto perk = perkData.perk; perk) {
59+
if (auto it = std::find(a_perks.begin(), a_perks.end(), perk); it != a_perks.end()) {
60+
return static_cast<std::int32_t>(it - a_perks.begin());
61+
}
62+
}
63+
}
64+
}
65+
}
5466
}
5567

5668
return -1;
@@ -94,16 +106,26 @@ namespace PapyrusActor
94106
return false;
95107
}
96108

97-
if (const auto actorBase = a_actor->GetActorBase(); actorBase) {
98-
if (const auto perkArray = actorBase->As<RE::BGSPerkRankArray>(); perkArray) {
99-
for (std::uint32_t i = 0; i < perkArray->perkCount; ++i) {
100-
const auto perkData = perkArray->perks[i];
101-
102-
if (const auto perk = perkData.perk; perk && a_perk == perk && a_rank == static_cast<std::int32_t>(perkData.currentRank)) {
109+
if (auto player = RE::PlayerCharacter::GetSingleton(); player == a_actor) {
110+
if (const auto perkArray = player->addedPerks; !perkArray.empty()) {
111+
for (auto perkData : perkArray) {
112+
if (const auto perk = perkData->perk; perk && a_perk == perk && a_rank == static_cast<std::int32_t>(perkData->currentRank)) {
103113
return true;
104114
}
105115
}
106116
}
117+
} else {
118+
if (const auto actorBase = a_actor->GetActorBase(); actorBase) {
119+
if (const auto perkArray = actorBase->As<RE::BGSPerkRankArray>(); perkArray) {
120+
for (std::uint32_t i = 0; i < perkArray->perkCount; ++i) {
121+
const auto perkData = perkArray->perks[i];
122+
123+
if (const auto perk = perkData.perk; perk && a_perk == perk && a_rank == static_cast<std::int32_t>(perkData.currentRank)) {
124+
return true;
125+
}
126+
}
127+
}
128+
}
107129
}
108130

109131
return false;
@@ -267,13 +289,23 @@ namespace PapyrusActor
267289
return -1;
268290
}
269291

270-
if (const auto actorBase = a_actor->GetActorBase(); actorBase) {
271-
if (const auto perkArray = actorBase->As<RE::BGSPerkRankArray>(); perkArray) {
272-
for (std::uint32_t i = 0; i < perkArray->perkCount; ++i) {
273-
const auto perkData = perkArray->perks[i];
274-
275-
if (const auto perk = perkData.perk; perk && a_perk == perk) {
276-
return static_cast<std::int32_t>(perkData.currentRank);
292+
if (auto player = RE::PlayerCharacter::GetSingleton(); player == a_actor) {
293+
if (const auto perkArray = player->addedPerks; !perkArray.empty()) {
294+
for (auto perkData : perkArray) {
295+
if (const auto perk = perkData->perk; perk && a_perk == perk) {
296+
return static_cast<std::int32_t>(perkData->currentRank);
297+
}
298+
}
299+
}
300+
} else {
301+
if (const auto actorBase = a_actor->GetActorBase(); actorBase) {
302+
if (const auto perkArray = actorBase->As<RE::BGSPerkRankArray>(); perkArray) {
303+
for (std::uint32_t i = 0; i < perkArray->perkCount; ++i) {
304+
const auto perkData = perkArray->perks[i];
305+
306+
if (const auto perk = perkData.perk; perk && a_perk == perk) {
307+
return static_cast<std::int32_t>(perkData.currentRank);
308+
}
277309
}
278310
}
279311
}
@@ -291,16 +323,26 @@ namespace PapyrusActor
291323
return result;
292324
}
293325

294-
if (const auto actorBase = a_actor->GetActorBase(); actorBase) {
295-
if (const auto perkArray = actorBase->As<RE::BGSPerkRankArray>(); perkArray) {
296-
for (std::uint32_t i = 0; i < perkArray->perkCount; ++i) {
297-
const auto perkData = perkArray->perks[i];
298-
299-
if (const auto perk = perkData.perk; perk) {
326+
if (auto player = RE::PlayerCharacter::GetSingleton(); player == a_actor) {
327+
if (const auto perkArray = player->addedPerks; !perkArray.empty()) {
328+
for (auto perkData : perkArray) {
329+
if (const auto perk = perkData->perk; perk) {
300330
result.emplace_back(perk);
301331
}
302332
}
303333
}
334+
} else {
335+
if (const auto actorBase = a_actor->GetActorBase(); actorBase) {
336+
if (const auto perkArray = actorBase->As<RE::BGSPerkRankArray>(); perkArray) {
337+
for (std::uint32_t i = 0; i < perkArray->perkCount; ++i) {
338+
const auto perkData = perkArray->perks[i];
339+
340+
if (const auto perk = perkData.perk; perk) {
341+
result.emplace_back(perk);
342+
}
343+
}
344+
}
345+
}
304346
}
305347

306348
return result;
@@ -382,7 +424,7 @@ namespace PapyrusActor
382424

383425
if (!a_slots.empty()) {
384426
for (const auto slot : a_slots) {
385-
auto* const armor = changes->GetArmorInSlot(slot); // NOLINT(cppcoreguidelines-narrowing-conversions)
427+
auto* const armor = changes->GetArmorInSlot(slot); // NOLINT(cppcoreguidelines-narrowing-conversions)
386428
vec.push_back(armor);
387429
}
388430
}

0 commit comments

Comments
 (0)