Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Crash] Add Checks for valid pointers or fix existing logic. #3164

Merged
merged 1 commit into from
Apr 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion zone/aggro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,7 @@ void Mob::ClearFeignMemory() {
while (remembered_feigned_mobid != feign_memory_list.end())
{
Mob* remembered_mob = entity_list.GetMob(*remembered_feigned_mobid);
if (remembered_mob->IsClient() && remembered_mob != nullptr) { //Still in zone
if (remembered_mob && remembered_mob->IsClient()) { //Still in zone
remembered_mob->CastToClient()->RemoveXTarget(this, false);
}
++remembered_feigned_mobid;
Expand Down
5 changes: 3 additions & 2 deletions zone/attack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2835,8 +2835,9 @@ bool NPC::Death(Mob* killer_mob, int64 damage, uint16 spell, EQ::skills::SkillTy
if (emote_id) {
oos->CastToNPC()->DoNPCEmote(EQ::constants::EmoteEventTypes::KilledNPC, emote_id);
}

killer_mob->TrySpellOnKill(killed_level, spell);
if (killer_mob) {
killer_mob->TrySpellOnKill(killed_level, spell);
}
}
}

Expand Down
10 changes: 8 additions & 2 deletions zone/aura.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,10 @@ bool ZoneDatabase::GetAuraEntry(uint16 spell_id, AuraRecord &record)

void Mob::AddAura(Aura *aura, AuraRecord &record)
{
if (!aura) {
return;
}

LogAura(
"aura owner [{}] spawn_id [{}] aura_name [{}]",
GetCleanName(),
Expand All @@ -971,7 +975,6 @@ void Mob::AddAura(Aura *aura, AuraRecord &record)
);

// this is called only when it's safe
assert(aura != nullptr);
strn0cpy(aura_mgr.auras[aura_mgr.count].name, aura->GetCleanName(), 64);
aura_mgr.auras[aura_mgr.count].spawn_id = aura->GetID();
aura_mgr.auras[aura_mgr.count].aura = aura;
Expand All @@ -998,6 +1001,10 @@ void Mob::AddAura(Aura *aura, AuraRecord &record)

void Mob::AddTrap(Aura *aura, AuraRecord &record)
{
if (!aura) {
return;
}

LogAura(
"aura owner [{}] spawn_id [{}] aura_name [{}]",
GetCleanName(),
Expand All @@ -1006,7 +1013,6 @@ void Mob::AddTrap(Aura *aura, AuraRecord &record)
);

// this is called only when it's safe
assert(aura != nullptr);
strn0cpy(trap_mgr.auras[trap_mgr.count].name, aura->GetCleanName(), 64);
trap_mgr.auras[trap_mgr.count].spawn_id = aura->GetID();
trap_mgr.auras[trap_mgr.count].aura = aura;
Expand Down
35 changes: 20 additions & 15 deletions zone/bot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4669,7 +4669,9 @@ void Bot::Damage(Mob *from, int64 damage, uint16 spell_id, EQ::skills::SkillType
int64 healed = GetActSpellHealing(spell_id, damage);
LogCombatDetail("Applying lifetap heal of [{}] to [{}]", healed, GetCleanName());
HealDamage(healed);
entity_list.FilteredMessageClose(this, true, RuleI(Range, SpellMessages), Chat::Emote, FilterSocials, "%s beams a smile at %s", GetCleanName(), from->GetCleanName() );
if (from) {
entity_list.FilteredMessageClose(this, true, RuleI(Range, SpellMessages), Chat::Emote, FilterSocials, "%s beams a smile at %s", GetCleanName(), from->GetCleanName());
}
}

CommonDamage(from, damage, spell_id, attack_skill, avoidable, buffslot, iBuffTic, special);
Expand Down Expand Up @@ -8752,22 +8754,25 @@ std::vector<Mob*> Bot::GetApplySpellList(

if (apply_type == ApplySpellType::Raid && IsRaidGrouped()) {
auto* r = GetRaid();
auto group_id = r->GetGroup(GetCleanName());
if (r && EQ::ValueWithin(group_id, 0, (MAX_RAID_GROUPS - 1))) {
for (const auto& m : r->members) {
if (m.is_bot) {
continue;
}
if (m.member && m.member->IsClient() && (!is_raid_group_only || r->GetGroup(m.member) == group_id)) {
l.push_back(m.member);

if (allow_pets && m.member->HasPet()) {
l.push_back(m.member->GetPet());
if (r) {
auto group_id = r->GetGroup(GetCleanName());
if (EQ::ValueWithin(group_id, 0, (MAX_RAID_GROUPS - 1))) {
for (const auto& m: r->members) {
if (m.is_bot) {
continue;
}
if (m.member && m.member->IsClient() &&
(!is_raid_group_only || r->GetGroup(m.member) == group_id)) {
l.push_back(m.member);

const auto& sbl = entity_list.GetBotListByCharacterID(m.member->CharacterID());
for (const auto& b : sbl) {
l.push_back(b);
if (allow_pets && m.member->HasPet()) {
l.push_back(m.member->GetPet());
}

const auto& sbl = entity_list.GetBotListByCharacterID(m.member->CharacterID());
for (const auto& b: sbl) {
l.push_back(b);
}
}
}
}
Expand Down
27 changes: 20 additions & 7 deletions zone/botspellsai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1888,11 +1888,15 @@ bool Bot::AIHealRotation(Mob* tar, bool useFastHeals) {
std::list<BotSpell> Bot::GetBotSpellsForSpellEffect(Bot* botCaster, int spellEffect) {
std::list<BotSpell> result;

if (!botCaster) {
return result;
}

if (auto bot_owner = botCaster->GetBotOwner(); !bot_owner) {
return result;
}

if (botCaster && botCaster->AI_HasSpells()) {
if (botCaster->AI_HasSpells()) {
std::vector<BotSpells_Struct> botSpellList = botCaster->AIBot_spells;

for (int i = botSpellList.size() - 1; i >= 0; i--) {
Expand All @@ -1919,11 +1923,15 @@ std::list<BotSpell> Bot::GetBotSpellsForSpellEffect(Bot* botCaster, int spellEff
std::list<BotSpell> Bot::GetBotSpellsForSpellEffectAndTargetType(Bot* botCaster, int spellEffect, SpellTargetType targetType) {
std::list<BotSpell> result;

if (!botCaster) {
return result;
}

if (auto bot_owner = botCaster->GetBotOwner(); !bot_owner) {
return result;
}

if (botCaster && botCaster->AI_HasSpells()) {
if (botCaster->AI_HasSpells()) {
std::vector<BotSpells_Struct> botSpellList = botCaster->AIBot_spells;

for (int i = botSpellList.size() - 1; i >= 0; i--) {
Expand Down Expand Up @@ -1955,11 +1963,15 @@ std::list<BotSpell> Bot::GetBotSpellsForSpellEffectAndTargetType(Bot* botCaster,
std::list<BotSpell> Bot::GetBotSpellsBySpellType(Bot* botCaster, uint32 spellType) {
std::list<BotSpell> result;

if (!botCaster) {
return result;
}

if (auto bot_owner = botCaster->GetBotOwner(); !bot_owner) {
return result;
}

if (botCaster && botCaster->AI_HasSpells()) {
if (botCaster->AI_HasSpells()) {
std::vector<BotSpells_Struct> botSpellList = botCaster->AIBot_spells;

for (int i = botSpellList.size() - 1; i >= 0; i--) {
Expand Down Expand Up @@ -2694,21 +2706,22 @@ BotSpell Bot::GetBestBotSpellForResistDebuff(Bot* botCaster, Mob *tar) {
result.SpellIndex = 0;
result.ManaCost = 0;

if (!tar)
if (!tar || !botCaster) {
return result;
}

int level_mod = (tar->GetLevel() - botCaster->GetLevel())* (tar->GetLevel() - botCaster->GetLevel()) / 2;
if (tar->GetLevel() - botCaster->GetLevel() < 0)
{
if (tar->GetLevel() - botCaster->GetLevel() < 0) {
level_mod = -level_mod;
}

bool needsMagicResistDebuff = (tar->GetMR() + level_mod) > 100;
bool needsColdResistDebuff = (tar->GetCR() + level_mod) > 100;
bool needsFireResistDebuff = (tar->GetFR() + level_mod) > 100;
bool needsPoisonResistDebuff = (tar->GetPR() + level_mod) > 100;
bool needsDiseaseResistDebuff = (tar->GetDR() + level_mod) > 100;

if (botCaster && botCaster->AI_HasSpells()) {
if (botCaster->AI_HasSpells()) {
std::vector<BotSpells_Struct> botSpellList = botCaster->AIBot_spells;

for (int i = botSpellList.size() - 1; i >= 0; i--) {
Expand Down
46 changes: 25 additions & 21 deletions zone/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7470,15 +7470,17 @@ const char* Client::GetClassPlural(Client* client) {

void Client::SendWebLink(const char *website)
{
size_t len = strlen(website) + 1;
if(website != 0 && len > 1)
{
auto outapp = new EQApplicationPacket(OP_Weblink, sizeof(Weblink_Struct) + len);
Weblink_Struct *wl = (Weblink_Struct*)outapp->pBuffer;
memcpy(wl->weblink, website, len);
wl->weblink[len] = '\0';
if (website) {
size_t len = strlen(website) + 1;
if (len > 1)
{
auto outapp = new EQApplicationPacket(OP_Weblink, sizeof(Weblink_Struct) + len);
Weblink_Struct* wl = (Weblink_Struct*)outapp->pBuffer;
memcpy(wl->weblink, website, len);
wl->weblink[len] = '\0';

FastQueuePacket(&outapp);
FastQueuePacket(&outapp);
}
}
}

Expand Down Expand Up @@ -11734,20 +11736,22 @@ std::vector<Mob*> Client::GetApplySpellList(

if (apply_type == ApplySpellType::Raid && IsRaidGrouped()) {
auto* r = GetRaid();
auto group_id = r->GetGroup(this);
if (r && EQ::ValueWithin(group_id, 0, (MAX_RAID_GROUPS - 1))) {
for (const auto& m : r->members) {
if (m.member && m.member->IsClient() && (!is_raid_group_only || r->GetGroup(m.member) == group_id)) {
l.push_back(m.member);

if (allow_pets && m.member->HasPet()) {
l.push_back(m.member->GetPet());
}
if (r) {
auto group_id = r->GetGroup(this);
if (EQ::ValueWithin(group_id, 0, (MAX_RAID_GROUPS - 1))) {
for (const auto& m : r->members) {
if (m.member && m.member->IsClient() && (!is_raid_group_only || r->GetGroup(m.member) == group_id)) {
l.push_back(m.member);

if (allow_pets && m.member->HasPet()) {
l.push_back(m.member->GetPet());
}

if (allow_bots) {
const auto& sbl = entity_list.GetBotListByCharacterID(m.member->CharacterID());
for (const auto& b : sbl) {
l.push_back(b);
if (allow_bots) {
const auto& sbl = entity_list.GetBotListByCharacterID(m.member->CharacterID());
for (const auto& b : sbl) {
l.push_back(b);
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions zone/client_packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11775,13 +11775,13 @@ void Client::Handle_OP_RaidCommand(const EQApplicationPacket* app)
Bot* player_to_invite = nullptr;

if (RuleB(Bots, Enabled) && entity_list.GetBotByBotName(raid_command_packet->player_name)) {
Bot* player_to_invite = entity_list.GetBotByBotName(raid_command_packet->player_name);
Group* player_to_invite_group = player_to_invite->GetGroup();

if (!player_to_invite) {
break;
}

Bot* player_to_invite = entity_list.GetBotByBotName(raid_command_packet->player_name);
Group* player_to_invite_group = player_to_invite->GetGroup();

if (player_to_invite_group && player_to_invite_group->IsGroupMember(this)) {
MessageString(Chat::Red, ALREADY_IN_PARTY);
break;
Expand Down
1 change: 1 addition & 0 deletions zone/client_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,7 @@ void Client::OPMemorizeSpell(const EQApplicationPacket* app)
const auto* item = inst->GetItem();

if (
item &&
RuleB(Character, RestrictSpellScribing) &&
!item->IsEquipable(GetRace(), GetClass())
) {
Expand Down
5 changes: 3 additions & 2 deletions zone/embparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,6 @@ bool PerlembParser::SpellHasQuestSub(uint32 spell_id, QuestEventID evt)

bool PerlembParser::ItemHasQuestSub(EQ::ItemInstance *itm, QuestEventID evt)
{
std::stringstream package_name;
package_name << "qst_item_" << itm->GetID();

if (!perl) {
return false;
Expand All @@ -535,6 +533,9 @@ bool PerlembParser::ItemHasQuestSub(EQ::ItemInstance *itm, QuestEventID evt)
return false;
}

std::stringstream package_name;
package_name << "qst_item_" << itm->GetID();

const char *subname = QuestEventSubroutines[evt];

auto iter = item_quest_status_.find(itm->GetID());
Expand Down
8 changes: 4 additions & 4 deletions zone/groups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ bool Group::AddMember(Mob* newmember, const char *NewMemberName, uint32 Characte
}

//put existing group member(s) into the new member's list
if(InZone && newmember->IsClient())
if(InZone && newmember && newmember->IsClient())
{
if(IsLeader(members[i]))
{
Expand All @@ -307,13 +307,13 @@ bool Group::AddMember(Mob* newmember, const char *NewMemberName, uint32 Characte
else
{
strcpy(newmember->CastToClient()->GetPP().groupMembers[x], members[i]->GetCleanName());
x++;
++x;
}
}
}
}

if(InZone)
if(InZone && newmember)
{
//put new member in his own list.
newmember->SetGrouped(true);
Expand Down Expand Up @@ -2491,4 +2491,4 @@ bool Group::IsLeader(const char* name) {
}

return false;
}
}