Skip to content

Commit

Permalink
fix(skymp5-server): use GetData in GetNthForm for valid record retrie…
Browse files Browse the repository at this point in the history
…val (#2315)
  • Loading branch information
Pospelove authored Feb 9, 2025
1 parent 986cf5c commit e82760b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ VarValue PapyrusLeveledItem::GetNthForm(VarValue self,
auto& loader = compatibilityPolicy->GetWorldState()->GetEspm();
auto leveledItem = espm::Convert<espm::LVLI>(itemRecord.rec);
if (leveledItem) {
auto vec =
LeveledListUtils::EvaluateList(loader.GetBrowser(), itemRecord, 1);
auto data = leveledItem->GetData(
compatibilityPolicy->GetWorldState()->GetEspmCache());
int index = static_cast<int>(arguments[0]);
if (vec.size() > index) {
auto formId = itemRecord.ToGlobalId(vec[index].formId);
auto record = itemRecord.parent->LookupById(formId);
return VarValue(std::make_shared<EspmGameObject>(record));
if (data.numEntries > static_cast<size_t>(index)) {
auto formId = itemRecord.ToGlobalId(data.entries[index].formId);
auto lookupRes = loader.GetBrowser().LookupById(formId);
if (lookupRes.rec) {
return VarValue(std::make_shared<EspmGameObject>(lookupRes));
}
}
}
return VarValue::None();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class PapyrusLeveledItem final : public IPapyrusClass<PapyrusLeveledItem>
public:
const char* GetName() override { return "LeveledItem"; }

VarValue GetNthForm(VarValue slef, const std::vector<VarValue>& arguments);
VarValue GetNthForm(VarValue self, const std::vector<VarValue>& arguments);

void Register(VirtualMachine& vm,
std::shared_ptr<IPapyrusCompatibilityPolicy> policy) override;
Expand Down

0 comments on commit e82760b

Please sign in to comment.