Skip to content

Commit fcfa7db

Browse files
authored
Check for caster in spelleffect_add (#1538) (#1563)
1 parent dadab44 commit fcfa7db

File tree

2 files changed

+66
-33
lines changed

2 files changed

+66
-33
lines changed

Changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4119,3 +4119,4 @@ When setting a property like MORE to the a spell or skill defname, trying to rea
41194119
- Fixed: IncreaseDefChance on AOS formula (2) is now properly calculated from defender, not the attacker.
41204120
- Fixed: Hit chance to paralyzed targets with sphere custom (0) formula is now 80-100% (was 0-10%).
41214121
- Added: Implemented Hit chance increase / decrease to sphere custom formula (0).
4122+
- Fixed: Equiping armor and weapon with spelleffect could crash the SphereServer (#1538)

src/game/chars/CCharSpell.cpp

Lines changed: 65 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,10 @@ void CChar::Spell_Effect_Add( CItem * pSpell )
12241224
pClient->removeBuff(BI_STRANGLE);
12251225
pClient->addBuff(BI_STRANGLE, 1075794, 1075795, wTimerEffect);
12261226
}
1227-
wStatEffectRef = (pCaster->Skill_GetBase(SKILL_SPIRITSPEAK) / 100);
1227+
if (pCaster != nullptr)
1228+
{
1229+
wStatEffectRef = (pCaster->Skill_GetBase(SKILL_SPIRITSPEAK) / 100);
1230+
}
12281231
if (wStatEffectRef < 4)
12291232
wStatEffectRef = 4;
12301233
pSpell->m_itSpell.m_spellcharges = wStatEffectRef;
@@ -1302,10 +1305,13 @@ void CChar::Spell_Effect_Add( CItem * pSpell )
13021305
pSpell->m_itSpell.m_spellcharges += 2;
13031306
//TO-DO If the spell targets someone already affected by the Pain Spike spell, only 3 to 7 points of DIRECT damage will be inflicted.
13041307
}
1305-
if (m_pNPC)
1306-
wStatEffectRef = ((pCaster->Skill_GetBase(SKILL_SPIRITSPEAK) - Skill_GetBase(SKILL_MAGICRESISTANCE)) / 10) + 30;
1307-
else
1308-
wStatEffectRef = ((pCaster->Skill_GetBase(SKILL_SPIRITSPEAK) - Skill_GetBase(SKILL_MAGICRESISTANCE)) / 100) + 18;
1308+
if (pCaster != nullptr)
1309+
{
1310+
if (m_pNPC)
1311+
wStatEffectRef = ((pCaster->Skill_GetBase(SKILL_SPIRITSPEAK) - Skill_GetBase(SKILL_MAGICRESISTANCE)) / 10) + 30;
1312+
else
1313+
wStatEffectRef = ((pCaster->Skill_GetBase(SKILL_SPIRITSPEAK) - Skill_GetBase(SKILL_MAGICRESISTANCE)) / 100) + 18;
1314+
}
13091315
pSpell->m_itSpell.m_spellcharges = 10;
13101316
}
13111317
return;
@@ -1315,18 +1321,24 @@ void CChar::Spell_Effect_Add( CItem * pSpell )
13151321
{
13161322
if (pClient)
13171323
{
1318-
Str_CopyLimitNull(NumBuff[0], pCaster->GetName(), uiBuffElemSize);
1319-
Str_CopyLimitNull(NumBuff[1], pCaster->GetName(), uiBuffElemSize);
1324+
if (pCaster != nullptr)
1325+
{
1326+
Str_CopyLimitNull(NumBuff[0], pCaster->GetName(), uiBuffElemSize);
1327+
Str_CopyLimitNull(NumBuff[1], pCaster->GetName(), uiBuffElemSize);
1328+
}
13201329
pClient->removeBuff(BI_BLOODOATHCURSE);
13211330
pClient->addBuff(BI_BLOODOATHCURSE, 1075659, 1075660, wTimerEffect, pNumBuff, 2);
13221331
}
1323-
CClient *pCasterClient = pCaster->GetClientActive();
1324-
if (pCasterClient)
1325-
{
1326-
Str_CopyLimitNull(NumBuff[0], GetName(), uiBuffElemSize);
1327-
pCasterClient->removeBuff(BI_BLOODOATHCASTER);
1328-
pCasterClient->addBuff(BI_BLOODOATHCASTER, 1075661, 1075662, wTimerEffect, pNumBuff, 1);
1329-
}
1332+
if (pCaster != nullptr)
1333+
{
1334+
CClient *pCasterClient = pCaster->GetClientActive();
1335+
if (pCasterClient)
1336+
{
1337+
Str_CopyLimitNull(NumBuff[0], GetName(), uiBuffElemSize);
1338+
pCasterClient->removeBuff(BI_BLOODOATHCASTER);
1339+
pCasterClient->addBuff(BI_BLOODOATHCASTER, 1075661, 1075662, wTimerEffect, pNumBuff, 1);
1340+
}
1341+
}
13301342
}
13311343
return;
13321344
case LAYER_SPELL_Corpse_Skin:
@@ -1392,7 +1404,10 @@ void CChar::Spell_Effect_Add( CItem * pSpell )
13921404
case SPELL_Reactive_Armor:
13931405
if (IsSetCombatFlags(COMBAT_ELEMENTAL_ENGINE) && !pSpellDef->IsSpellType(SPELLFLAG_NO_ELEMENTALENGINE))
13941406
{
1395-
wStatEffectRef = 15 + (pCaster->Skill_GetBase(SKILL_INSCRIPTION) / 200);
1407+
if (pCaster != nullptr)
1408+
{
1409+
wStatEffectRef = 15 + (pCaster->Skill_GetBase(SKILL_INSCRIPTION) / 200);
1410+
}
13961411

13971412
CCPropsChar* pCCPChar = GetComponentProps<CCPropsChar>();
13981413
CCPropsChar* pBaseCCPChar = Base_GetDef()->GetComponentProps<CCPropsChar>();
@@ -1408,7 +1423,11 @@ void CChar::Spell_Effect_Add( CItem * pSpell )
14081423
int iSkill = -1;
14091424
const bool fValidSkill = pSpellDef->GetPrimarySkill(&iSkill, nullptr);
14101425
ASSERT_ALWAYS(fValidSkill);
1411-
pSpell->m_itSpell.m_PolyStr = (int16)pSpellDef->m_vcEffect.GetLinear(pCaster->Skill_GetBase((SKILL_TYPE)iSkill)) / 10; // % of damage reflected.
1426+
1427+
if (pCaster != nullptr)
1428+
{
1429+
pSpell->m_itSpell.m_PolyStr = (int16)pSpellDef->m_vcEffect.GetLinear(pCaster->Skill_GetBase((SKILL_TYPE)iSkill)) / 10; // % of damage reflected.
1430+
}
14121431
}
14131432
if (pClient && IsSetOF(OF_Buffs))
14141433
{
@@ -1618,18 +1637,22 @@ void CChar::Spell_Effect_Add( CItem * pSpell )
16181637
{
16191638
if ( IsSetMagicFlags(MAGICF_OSIFORMULAS) )
16201639
wStatEffectRef = (400 + pCaster->Skill_GetBase(SKILL_EVALINT) - Skill_GetBase(SKILL_MAGICRESISTANCE)) / 10;
1621-
1622-
if ( wStatEffectRef > Stat_GetVal(STAT_INT) )
1623-
wStatEffectRef = (word)(Stat_GetVal(STAT_INT));
16241640
}
1641+
1642+
if ( wStatEffectRef > Stat_GetVal(STAT_INT) )
1643+
wStatEffectRef = (word)(Stat_GetVal(STAT_INT));
1644+
16251645
UpdateStatVal( STAT_INT, -wStatEffectRef );
16261646
}
16271647
return;
16281648
case SPELL_Magic_Reflect:
16291649
StatFlag_Set( STATF_REFLECTION );
16301650
if (IsSetCombatFlags(COMBAT_ELEMENTAL_ENGINE) && !pSpellDef->IsSpellType(SPELLFLAG_NO_ELEMENTALENGINE))
16311651
{
1632-
wStatEffectRef = 25 - (pCaster->Skill_GetBase(SKILL_INSCRIPTION) / 200);
1652+
if (pCaster != nullptr)
1653+
{
1654+
wStatEffectRef = 25 - (pCaster->Skill_GetBase(SKILL_INSCRIPTION) / 200);
1655+
}
16331656

16341657
CCPropsChar* pCCPChar = GetComponentProps<CCPropsChar>();
16351658
CCPropsChar* pBaseCCPChar = Base_GetDef()->GetComponentProps<CCPropsChar>();
@@ -1665,19 +1688,28 @@ void CChar::Spell_Effect_Add( CItem * pSpell )
16651688
int iMagicResist = 0;
16661689
if (IsSetCombatFlags(COMBAT_ELEMENTAL_ENGINE) && !pSpellDef->IsSpellType(SPELLFLAG_NO_ELEMENTALENGINE))
16671690
{
1668-
ushort uiCasterEvalInt = pCaster->Skill_GetBase(SKILL_EVALINT), uiCasterMeditation = pCaster->Skill_GetBase(SKILL_MEDITATION);
1669-
ushort uiCasterInscription = pCaster->Skill_GetBase(SKILL_INSCRIPTION);
1670-
ushort uiMyMagicResistance = Skill_GetBase(SKILL_MAGICRESISTANCE), uiMyInscription = Skill_GetBase(SKILL_INSCRIPTION);
1671-
wStatEffectRef = (uiCasterEvalInt + uiCasterMeditation + uiCasterInscription) / 40;
1672-
wStatEffectRef = minimum(75, wStatEffectRef);
1673-
1674-
iPhysicalResist = 15 - (uiCasterInscription / 200);
1675-
int iPhysicalResistMin = minimum(INT16_MAX, iPhysicalResist);
1676-
pSpell->m_itSpell.m_PolyStr = (short)(maximum(-INT16_MAX, iPhysicalResistMin ));
1677-
1678-
iMagicResist = minimum(uiMyMagicResistance, 350 - (uiMyInscription / 20));
1679-
int iMagicResistMin = minimum(INT16_MAX, iMagicResist);
1680-
pSpell->m_itSpell.m_PolyDex = (short)(maximum(-INT16_MAX, iMagicResistMin));
1691+
int iPhysicalResistMin = 0;
1692+
1693+
if (pCaster != nullptr)
1694+
{
1695+
ushort uiCasterEvalInt = pCaster->Skill_GetBase(SKILL_EVALINT);
1696+
ushort uiCasterMeditation = pCaster->Skill_GetBase(SKILL_MEDITATION);
1697+
ushort uiCasterInscription = pCaster->Skill_GetBase(SKILL_INSCRIPTION);
1698+
wStatEffectRef = (uiCasterEvalInt + uiCasterMeditation + uiCasterInscription) / 40;
1699+
1700+
iPhysicalResist = 15 - (uiCasterInscription / 200);
1701+
iPhysicalResistMin = minimum(INT16_MAX, iPhysicalResist);
1702+
}
1703+
1704+
wStatEffectRef = minimum(75, wStatEffectRef);
1705+
pSpell->m_itSpell.m_PolyStr = (short)(maximum(-INT16_MAX, iPhysicalResistMin ));
1706+
1707+
ushort uiMyMagicResistance = Skill_GetBase(SKILL_MAGICRESISTANCE);
1708+
ushort uiMyInscription = Skill_GetBase(SKILL_INSCRIPTION);
1709+
iMagicResist = minimum(uiMyMagicResistance, 350 - (uiMyInscription / 20));
1710+
int iMagicResistMin = minimum(INT16_MAX, iMagicResist);
1711+
1712+
pSpell->m_itSpell.m_PolyDex = (short)(maximum(-INT16_MAX, iMagicResistMin));
16811713

16821714
/*
16831715
* The method _CheckLimitEffectSkill checks if the skill will go above the current skill cap value, but because

0 commit comments

Comments
 (0)