Skip to content

Commit

Permalink
add race nullptr checks
Browse files Browse the repository at this point in the history
  • Loading branch information
powerof3 committed Nov 30, 2023
1 parent 5dbd507 commit bc52d74
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 27 deletions.
2 changes: 1 addition & 1 deletion SPID/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.20)
set(NAME "po3_SpellPerkItemDistributor" CACHE STRING "")
set(VERSION 6.7.0 CACHE STRING "")
set(VERSION 6.7.1 CACHE STRING "")
set(AE_VERSION 1)
set(VR_VERSION 1)

Expand Down
4 changes: 4 additions & 0 deletions SPID/src/DistributeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ namespace Distribute
{
func(a_this, a_templateForms);

if (!a_this) {
return;
}

std::call_once(distributeInit, []() {
if (shouldDistribute = Lookup::DoFormLookup(); shouldDistribute) {
SetupDistribution();
Expand Down
58 changes: 33 additions & 25 deletions SPID/src/LookupNPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,50 +31,58 @@ namespace NPC
npc(a_npc),
actor(nullptr),
name(a_npc->GetName()),
race(npc->GetRace()),
level(npc->GetLevel()),
sex(npc->GetSex()),
unique(npc->IsUnique()),
summonable(npc->IsSummonable()),
child(race->IsChildRace() || race->formEditorID.contains("RaceChild")),
race(a_npc->GetRace()),
level(a_npc->GetLevel()),
sex(a_npc->GetSex()),
unique(a_npc->IsUnique()),
summonable(a_npc->IsSummonable()),
child(race && (race->IsChildRace() || race->formEditorID.contains("RaceChild"))),
leveled(a_npc->UsesTemplate())
{
npc->ForEachKeyword([&](const RE::BGSKeyword& a_keyword) {
keywords.emplace(a_keyword.GetFormEditorID());
return RE::BSContainer::ForEachResult::kContinue;
});
race->ForEachKeyword([&](const RE::BGSKeyword& a_keyword) {
a_npc->ForEachKeyword([&](const RE::BGSKeyword& a_keyword) {
keywords.emplace(a_keyword.GetFormEditorID());
return RE::BSContainer::ForEachResult::kContinue;
});
IDs.emplace_back(npc);

if (race) {
race->ForEachKeyword([&](const RE::BGSKeyword& a_keyword) {
keywords.emplace(a_keyword.GetFormEditorID());
return RE::BSContainer::ForEachResult::kContinue;
});
}

IDs.emplace_back(a_npc);

std::call_once(init, [&] { potentialFollowerFaction = RE::TESForm::LookupByID<RE::TESFaction>(0x0005C84D); });
if (potentialFollowerFaction) {
teammate = npc->IsInFaction(potentialFollowerFaction);
teammate = a_npc->IsInFaction(potentialFollowerFaction);
}
}

Data::Data(RE::Actor* a_actor, RE::TESNPC* a_npc) :
npc(a_npc),
actor(a_actor),
name(actor->GetName()),
race(npc->GetRace()),
level(npc->GetLevel()),
sex(npc->GetSex()),
unique(npc->IsUnique()),
summonable(npc->IsSummonable()),
child(actor->IsChild() || race->formEditorID.contains("RaceChild"))
name(a_actor->GetName()),
race(a_npc->GetRace()),
level(a_npc->GetLevel()),
sex(a_npc->GetSex()),
unique(a_npc->IsUnique()),
summonable(a_npc->IsSummonable()),
child(a_actor->IsChild() || race && race->formEditorID.contains("RaceChild"))
{
npc->ForEachKeyword([&](const RE::BGSKeyword& a_keyword) {
keywords.emplace(a_keyword.GetFormEditorID());
return RE::BSContainer::ForEachResult::kContinue;
});
race->ForEachKeyword([&](const RE::BGSKeyword& a_keyword) {
keywords.emplace(a_keyword.GetFormEditorID());
return RE::BSContainer::ForEachResult::kContinue;
});
if (const auto extraLvlCreature = actor->extraList.GetByType<RE::ExtraLeveledCreature>()) {

if (race) {
race->ForEachKeyword([&](const RE::BGSKeyword& a_keyword) {
keywords.emplace(a_keyword.GetFormEditorID());
return RE::BSContainer::ForEachResult::kContinue;
});
}

if (const auto extraLvlCreature = a_actor->extraList.GetByType<RE::ExtraLeveledCreature>()) {
if (const auto originalBase = extraLvlCreature->originalBase) {
IDs.emplace_back(originalBase);
}
Expand Down
2 changes: 1 addition & 1 deletion SPID/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spid",
"version-string": "6.7.0",
"version-string": "6.7.1",
"description": "Spell Perk Item Distributor",
"homepage": "https://github.com/powerof3/Spell-Perk-Item-Distributor",
"license": "MIT",
Expand Down

0 comments on commit bc52d74

Please sign in to comment.