diff --git a/.clang-format b/.clang-format index ce3f9a42e..6e789c574 100644 --- a/.clang-format +++ b/.clang-format @@ -23,21 +23,23 @@ PointerAlignment: Right AllowShortBlocksOnASingleLine: false AllowShortCaseLabelsOnASingleLine: false AllowShortFunctionsOnASingleLine: None -AllowShortIfStatementsOnASingleLine: false +AllowShortIfStatementsOnASingleLine: Never AllowShortLambdasOnASingleLine: Inline AllowShortLoopsOnASingleLine: false ##-- Braces -BreakBeforeBraces: Custom +BreakBeforeBraces: Custom #Allman BraceWrapping: - #Allman - AfterControlStatement: MultiLine - AfterEnum: false - AfterFunction: false - AfterNamespace: false - AfterStruct: false - AfterUnion: false - BeforeCatch: false + AfterCaseLabel: true + AfterClass: false + AfterControlStatement: Always + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterStruct: true + AfterUnion: true + BeforeCatch: true + BeforeElse: true BeforeLambdaBody: true IndentBraces: false SplitEmptyFunction: false diff --git a/src/common/CPointBase.cpp b/src/common/CPointBase.cpp index 057f52300..5f09b249c 100644 --- a/src/common/CPointBase.cpp +++ b/src/common/CPointBase.cpp @@ -170,7 +170,7 @@ int CPointBase::GetDistBase( const CPointBase & pt ) const noexcept // Distance // This is even faster. const int dx = (m_x > pt.m_x) * (m_x - pt.m_x) + (m_x < pt.m_x) * (pt.m_x - m_x); const int dy = (m_y > pt.m_y) * (m_y - pt.m_y) + (m_y < pt.m_y) * (pt.m_y - m_y); - return (dx > dy) * dx + (dx < dy) * dy; + return (dx >= dy) * dx + (dx < dy) * dy; } case DISTANCE_FORMULA_DIAGONAL_NOZ: @@ -221,7 +221,7 @@ int CPointBase::GetDistSightBase( const CPointBase & pt ) const noexcept // Dist //return maximum(dx, dy); const int dx = (m_x > pt.m_x) * (m_x - pt.m_x) + (m_x < pt.m_x) * (pt.m_x - m_x); const int dy = (m_y > pt.m_y) * (m_y - pt.m_y) + (m_y < pt.m_y) * (pt.m_y - m_y); - return (dx > dy) * dx + (dx < dy) * dy; + return (dx >= dy) * dx + (dx < dy) * dy; } int CPointBase::GetDistSight( const CPointBase & pt ) const noexcept // Distance between points based on UO sight @@ -238,7 +238,7 @@ int CPointBase::GetDistSight( const CPointBase & pt ) const noexcept // Distance //return maximum(dx, dy); const int dx = (m_x > pt.m_x) * (m_x - pt.m_x) + (m_x < pt.m_x) * (pt.m_x - m_x); const int dy = (m_y > pt.m_y) * (m_y - pt.m_y) + (m_y < pt.m_y) * (pt.m_y - m_y); - return (dx > dy) * dx + (dx < dy) * dy; + return (dx >= dy) * dx + (dx < dy) * dy; } int CPointBase::GetDist3D( const CPointBase & pt ) const noexcept // Distance between points @@ -258,7 +258,7 @@ int CPointBase::GetDist3D( const CPointBase & pt ) const noexcept // Distance be dz /= (PLAYER_HEIGHT / 2); // Take player height into consideration //return maximum(dz, dist); - return (dz > dist) * dz + (dz < dist) * dist; + return (dz >= dist) * dz + (dz < dist) * dist; } case DISTANCE_FORMULA_DIAGONAL_Z: { diff --git a/src/common/CScriptObj.cpp b/src/common/CScriptObj.cpp index a896a9fea..b887bdb5a 100644 --- a/src/common/CScriptObj.cpp +++ b/src/common/CScriptObj.cpp @@ -2043,7 +2043,10 @@ size_t CScriptObj::ParseScriptText(tchar * ptcResponse, CTextConsole * pSrc, int ptcDest = ptcResponse + iBegin; memcpy(ptcDest, sVal.GetBuffer(), iWriteValLen); - i = iBegin + iWriteValLen - 1; + //i = iBegin + iWriteValLen - 1; + i = iBegin + iWriteValLen; + if (i != 0) + i -= 1; if (fNoRecurseBrackets) // just do this one then bail out. { @@ -2623,6 +2626,9 @@ TRIGRET_TYPE CScriptObj::OnTriggerLoopGeneric(CScript& s, int iType, CTextConsol if (rid.IsValidUID()) { const dword dwTotal = g_World.GetUIDCount(); + if (dwTotal == 0) + return TRIGRET_ENDIF; + dword dwCount = dwTotal - 1; dword dwTotalInstances = 0; // Will acquire the correct value for this during the loop dword dwUID = 0; diff --git a/src/common/sphere_library/CSQueue.cpp b/src/common/sphere_library/CSQueue.cpp index 01a0130f0..22b76e8d1 100644 --- a/src/common/sphere_library/CSQueue.cpp +++ b/src/common/sphere_library/CSQueue.cpp @@ -29,7 +29,7 @@ byte * CSQueueBytes::AddNewDataLock( size_t iLen ) // re-alloc a bigger buffer. as needed. ASSERT(m_iDataQty<=m_Mem.GetDataLength()); - m_Mem.Resize( ( iLenNew + 0x1000 ) &~ 0xFFF ); + m_Mem.Resize( ( iLenNew + 0x1000u ) & (size_t)~0xFFF ); } return ( m_Mem.GetData() + m_iDataQty ); diff --git a/src/common/sphere_library/sstring.cpp b/src/common/sphere_library/sstring.cpp index ac5bc006b..fe107df3b 100644 --- a/src/common/sphere_library/sstring.cpp +++ b/src/common/sphere_library/sstring.cpp @@ -454,6 +454,9 @@ size_t Str_LengthUTF8(const char* strInUTF8MB) noexcept // Adapted from: OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 size_t Str_ConcatLimitNull(tchar *dst, const tchar *src, size_t siz) noexcept { + if (siz == 0) + return 0; + tchar *d = dst; size_t n = siz; size_t dlen; @@ -489,7 +492,7 @@ size_t Str_ConcatLimitNull(tchar *dst, const tchar *src, size_t siz) noexcept tchar* Str_FindSubstring(tchar* str, const tchar* substr, size_t str_len, size_t substr_len) noexcept { - if (substr_len == 0) + if (str_len == 0 || substr_len == 0) return nullptr; tchar c, sc; diff --git a/src/game/CObjBase.cpp b/src/game/CObjBase.cpp index a6d31dbd0..18fbbb946 100644 --- a/src/game/CObjBase.cpp +++ b/src/game/CObjBase.cpp @@ -202,7 +202,7 @@ void CObjBase::DeletePrepare() CObjBase::_GoSleep(); // virtual, but superclass methods are called in their ::DeletePrepare methods const SERVMODE_TYPE servMode = g_Serv.GetServerMode(); - const bool fDestroyingWorld = (servMode != SERVMODE_Exiting && servMode != SERVMODE_Loading); + const bool fDestroyingWorld = (servMode == SERVMODE_Exiting || servMode == SERVMODE_Loading); if (!fDestroyingWorld) { RemoveFromView(); diff --git a/src/game/CObjBase.h b/src/game/CObjBase.h index 85e39c1b1..41b68084b 100644 --- a/src/game/CObjBase.h +++ b/src/game/CObjBase.h @@ -603,7 +603,7 @@ public: virtual bool IsDeleted() const override; public: /** - * @fn virtual bool CObjBase::MoveTo(CPointMap pt, bool fCheckLocation = true, bool fForceFix = false) = 0; + * @fn virtual bool CObjBase::MoveTo(CPointMap pt, bool fCheckLocationEffects = true, bool fForceFix = false) = 0; * * @brief Move To Location. * diff --git a/src/game/CSector.cpp b/src/game/CSector.cpp index f83d6d400..d792531e2 100644 --- a/src/game/CSector.cpp +++ b/src/game/CSector.cpp @@ -1077,8 +1077,8 @@ void CSector::Close(bool fClosingWorld) m_Chars_Active.ClearContainer(fClosingWorld); m_Chars_Disconnect.ClearContainer(fClosingWorld); - // These are resource type things. - //m_Teleports.clear(); + // These are resource type things, loaded from scripts, not save files. Do not delete them. + //m_Teleports.ClearFree(); //m_RegionLinks.clear(); } diff --git a/src/game/CServerConfig.cpp b/src/game/CServerConfig.cpp index b47488bd8..56c6df51d 100644 --- a/src/game/CServerConfig.cpp +++ b/src/game/CServerConfig.cpp @@ -3975,7 +3975,7 @@ CResourceID CServerConfig::ResourceGetNewID( RES_TYPE restype, lpctstr pszName, { // For a book the page is... the page number // For a REGIONTYPE block, the page (pArg2) is the landtile type associated with the REGIONTYPE - int iArgPage = ResGetIndex(Exp_GetVal(pArg2)); + int iArgPage = ResGetIndex(Exp_GetDWVal(pArg2)); if ( iArgPage < RES_PAGE_MAX ) wPage = (word)iArgPage; else diff --git a/src/game/chars/CChar.h b/src/game/chars/CChar.h index 24fca98a3..6a7a52fcd 100644 --- a/src/game/chars/CChar.h +++ b/src/game/chars/CChar.h @@ -490,7 +490,7 @@ public: void StatFlag_Mod(uint64 uiStatFlag, bool fMod) noexcept; bool MoveToRegion(CRegionWorld* pNewArea, bool fAllowReject); bool MoveToRegionReTest( dword dwType ); - bool MoveToChar(const CPointMap& pt, bool fStanding = true, bool fCheckLocation = true, bool fForceFix = false, bool fAllowReject = true); + bool MoveToChar(const CPointMap& pt, bool fStanding = true, bool fCheckLocationEffects = true, bool fForceFix = false, bool fAllowReject = true); virtual bool MoveTo(const CPointMap& pt, bool fForceFix = false) override; virtual void SetTopZ( char z ) override; virtual bool MoveNearObj( const CObjBaseTemplate *pObj, ushort iSteps = 0 ) override; @@ -502,7 +502,7 @@ public: void StatFlag_Mod(uint64 uiStatFlag, bool fMod) noexcept; bool CanStandAt(CPointMap *ptDest, const CRegion* pArea, uint64 uiMyMovementFlags, height_t uiMyHeight, CServerMapBlockingState* blockingState, bool fPathfinding) const; CRegion * CanMoveWalkTo( CPointMap & pt, bool fCheckChars = true, bool fCheckOnly = false, DIR_TYPE dir = DIR_QTY, bool fPathFinding = false ); void CheckRevealOnMove(); - TRIGRET_TYPE CheckLocation(bool fCanCheckRecursively, bool fStanding); + TRIGRET_TYPE CheckLocationEffects(bool fStanding); public: // Client Player specific stuff. ------------------------- diff --git a/src/game/chars/CCharAct.cpp b/src/game/chars/CCharAct.cpp index 387a2ad6a..71ae37737 100644 --- a/src/game/chars/CCharAct.cpp +++ b/src/game/chars/CCharAct.cpp @@ -3640,15 +3640,17 @@ void CChar::CheckRevealOnMove() } // We are at this location. What will happen? -// This function is called at every second on ALL chars +// This function is called at every second (or more) on ALL chars // (even walking or not), so avoid heavy codes here. // RETURN: // true = we can move there // false = we can't move there // default = we teleported -TRIGRET_TYPE CChar::CheckLocation(bool fCanCheckRecursively, bool fStanding) +TRIGRET_TYPE CChar::CheckLocationEffects(bool fStanding) { - ADDTOCALLSTACK("CChar::CheckLocation"); + ADDTOCALLSTACK("CChar::CheckLocationEffects"); + // This can also be called from char periodic ticks (not classic timer). + static thread_local uint _uiRecursingStep = 0; static thread_local uint _uiRecursingItemStep = 0; static constexpr uint _kuiRecursingStepLimit = 20; @@ -3678,153 +3680,146 @@ TRIGRET_TYPE CChar::CheckLocation(bool fCanCheckRecursively, bool fStanding) _SetTimeoutD(1); } - // This could get REALLY EXPENSIVE! (If not cause a buffer overflow for excessive recursion...) - if (fCanCheckRecursively) + if (_uiRecursingStep >= _kuiRecursingStepLimit) { - if (_uiRecursingStep >= _kuiRecursingStepLimit) - { - g_Log.EventError("Calling recursively @STEP for more than %u times. Skipping trigger call.\n", _kuiRecursingStepLimit); - } - else + g_Log.EventError("Calling recursively @STEP for more than %u times. Skipping trigger call.\n", _kuiRecursingStepLimit); + } + else + { + if (m_pArea && IsTrigUsed(TRIGGER_STEP)) //Check if m_pArea is exists because it may be invalid if it try to walk while multi removing? { - if (m_pArea && IsTrigUsed(TRIGGER_STEP)) //Check if m_pArea is exists because it may be invalid if it try to walk while multi removing? + _uiRecursingStep += 1; + if (m_pArea->OnRegionTrigger(this, RTRIG_STEP) == TRIGRET_RET_TRUE) { - _uiRecursingStep += 1; - if (m_pArea->OnRegionTrigger(this, RTRIG_STEP) == TRIGRET_RET_TRUE) - { - _uiRecursingStep -= 1; - return TRIGRET_RET_FALSE; - } + _uiRecursingStep -= 1; + return TRIGRET_RET_FALSE; + } - CRegion *pRoom = GetTopPoint().GetRegion(REGION_TYPE_ROOM); - if (pRoom && pRoom->OnRegionTrigger(this, RTRIG_STEP) == TRIGRET_RET_TRUE) - { - _uiRecursingStep -= 1; - return TRIGRET_RET_FALSE; - } + CRegion *pRoom = GetTopPoint().GetRegion(REGION_TYPE_ROOM); + if (pRoom && pRoom->OnRegionTrigger(this, RTRIG_STEP) == TRIGRET_RET_TRUE) + { _uiRecursingStep -= 1; + return TRIGRET_RET_FALSE; } + _uiRecursingStep -= 1; } } } - if (fCanCheckRecursively) + bool fStepCancel = false; + bool fSpellHit = false; + auto AreaItems = CWorldSearchHolder::GetInstance(GetTopPoint()); + for (;;) { - // We are safe to skip it, since this doesn't have checks that would negate the movement here (except for the trigger). - - bool fStepCancel = false; - bool fSpellHit = false; - auto AreaItems = CWorldSearchHolder::GetInstance(GetTopPoint()); - for (;;) - { - CItem *pItem = AreaItems->GetItem(); - if (!pItem) - break; + CItem *pItem = AreaItems->GetItem(); + if (!pItem) + break; - int zdiff = pItem->GetTopZ() - GetTopZ(); - int height = pItem->Item_GetDef()->GetHeight(); - if (height < 3) - height = 3; + int zdiff = pItem->GetTopZ() - GetTopZ(); + int height = pItem->Item_GetDef()->GetHeight(); + if (height < 3) + height = 3; - if ((zdiff > height) || (zdiff < -3)) - continue; + if ((zdiff > height) || (zdiff < -3)) + continue; - if (IsTrigUsed(TRIGGER_STEP) || IsTrigUsed(TRIGGER_ITEMSTEP)) + if (IsTrigUsed(TRIGGER_STEP) || IsTrigUsed(TRIGGER_ITEMSTEP)) + { + if (_uiRecursingItemStep >= _kuiRecursingItemStepLimit) { - if (_uiRecursingItemStep >= _kuiRecursingItemStepLimit) - { - g_Log.EventError("Calling recursively @ITEMSTEP for more than %u times. Skipping trigger call.\n", _kuiRecursingStepLimit); - } - else + g_Log.EventError("Calling recursively @ITEMSTEP for more than %u times. Skipping trigger call.\n", _kuiRecursingStepLimit); + } + else + { + _uiRecursingItemStep += 1; + CScriptTriggerArgs Args(fStanding ? 1 : 0); + TRIGRET_TYPE iRet = pItem->OnTrigger(ITRIG_STEP, this, &Args); + _uiRecursingItemStep -= 1; + if (iRet == TRIGRET_RET_TRUE) // block walk { - _uiRecursingItemStep += 1; - CScriptTriggerArgs Args(fStanding ? 1 : 0); - TRIGRET_TYPE iRet = pItem->OnTrigger(ITRIG_STEP, this, &Args); - _uiRecursingItemStep -= 1; - if (iRet == TRIGRET_RET_TRUE) // block walk - { - fStepCancel = true; - continue; - } - if (iRet == TRIGRET_RET_HALFBAKED) // allow walk, skipping hardcoded checks below - continue; + fStepCancel = true; + continue; } + if (iRet == TRIGRET_RET_HALFBAKED) // allow walk, skipping hardcoded checks below + continue; } + } - switch (pItem->GetType()) - { - case IT_WEB: + switch (pItem->GetType()) + { + case IT_WEB: if (fStanding) continue; - if (Use_Item_Web(pItem)) // we got stuck in a spider web + if (Use_Item_Web(pItem)) // we got stuck in a spider web return TRIGRET_RET_TRUE; continue; - case IT_FIRE: - { - int iSkillLevel = pItem->m_itSpell.m_spelllevel; // heat level (0-1000) - iSkillLevel = g_Rand.GetVal2(iSkillLevel/2, iSkillLevel); - if (IsStatFlag(STATF_FLY)) - iSkillLevel /= 2; + case IT_FIRE: + { + int iSkillLevel = pItem->m_itSpell.m_spelllevel; // heat level (0-1000) + iSkillLevel = g_Rand.GetVal2(iSkillLevel / 2, iSkillLevel); + if (IsStatFlag(STATF_FLY)) + iSkillLevel /= 2; - int iDmg = OnTakeDamage(g_Cfg.GetSpellEffect(SPELL_Fire_Field, iSkillLevel), nullptr, DAMAGE_FIRE|DAMAGE_GENERAL, 0, 100, 0, 0, 0); - if (iDmg > 0) + int iDmg = OnTakeDamage(g_Cfg.GetSpellEffect(SPELL_Fire_Field, iSkillLevel), nullptr, DAMAGE_FIRE | DAMAGE_GENERAL, 0, 100, 0, 0, 0); + if (iDmg > 0) + { + Sound(0x15f); // fire noise + if (m_pNPC && fStanding) { - Sound(0x15f); // fire noise - if (m_pNPC && fStanding) - { - m_Act_p.Move((DIR_TYPE)(g_Rand.GetVal(DIR_QTY))); - NPC_WalkToPoint(true); // run away from the threat - } + m_Act_p.Move((DIR_TYPE)(g_Rand.GetVal(DIR_QTY))); + NPC_WalkToPoint(true); // run away from the threat } } + } continue; - case IT_SPELL: - // Workaround: only hit 1 spell on each loop. If we hit all spells (eg: multiple field spells) - // it will allow weird exploits like cast many Fire Fields on the same spot to take more damage, - // or Paralyze Field + Fire Field to make the target get stuck forever being damaged with no way - // to get out of the field, since the damage won't allow cast any spell and the Paralyze Field - // will immediately paralyze again with 0ms delay at each damage tick. - // On OSI if the player cast multiple fields on the same tile, it will remove the previous field - // tile that got overlapped. But Sphere doesn't use this method, so this workaround is needed. + case IT_SPELL: + // Workaround: only hit 1 spell on each loop. If we hit all spells (eg: multiple field spells) + // it will allow weird exploits like cast many Fire Fields on the same spot to take more damage, + // or Paralyze Field + Fire Field to make the target get stuck forever being damaged with no way + // to get out of the field, since the damage won't allow cast any spell and the Paralyze Field + // will immediately paralyze again with 0ms delay at each damage tick. + // On OSI if the player cast multiple fields on the same tile, it will remove the previous field + // tile that got overlapped. But Sphere doesn't use this method, so this workaround is needed. if (fSpellHit) continue; - fSpellHit = OnSpellEffect((SPELL_TYPE)(ResGetIndex(pItem->m_itSpell.m_spell)), - pItem->m_uidLink.CharFind(), pItem->m_itSpell.m_spelllevel, pItem); + fSpellHit = + OnSpellEffect((SPELL_TYPE)(ResGetIndex(pItem->m_itSpell.m_spell)), pItem->m_uidLink.CharFind(), pItem->m_itSpell.m_spelllevel, pItem); if (fSpellHit && m_pNPC && fStanding) { m_Act_p.Move((DIR_TYPE)(g_Rand.GetVal(DIR_QTY))); - NPC_WalkToPoint(true); // run away from the threat + NPC_WalkToPoint(true); // run away from the threat } continue; - case IT_TRAP: - case IT_TRAP_ACTIVE: + case IT_TRAP: + case IT_TRAP_ACTIVE: + { + int iDmg = OnTakeDamage(pItem->Use_Trap(), nullptr, DAMAGE_HIT_BLUNT | DAMAGE_GENERAL); + if ((iDmg > 0) && m_pNPC && fStanding) { - int iDmg = OnTakeDamage(pItem->Use_Trap(), nullptr, DAMAGE_HIT_BLUNT|DAMAGE_GENERAL); - if ((iDmg > 0) && m_pNPC && fStanding) - { - m_Act_p.Move((DIR_TYPE)(g_Rand.GetVal(DIR_QTY))); - NPC_WalkToPoint(true); // run away from the threat - } - continue; + m_Act_p.Move((DIR_TYPE)(g_Rand.GetVal(DIR_QTY))); + NPC_WalkToPoint(true); // run away from the threat } + continue; + } - case IT_SWITCH: + case IT_SWITCH: if (pItem->m_itSwitch.m_wStep) Use_Item(pItem); continue; - case IT_MOONGATE: - case IT_TELEPAD: + + case IT_MOONGATE: + case IT_TELEPAD: if (fStanding) continue; Use_MoonGate(pItem); return TRIGRET_RET_DEFAULT; - case IT_SHIP_PLANK: - case IT_ROPE: + case IT_SHIP_PLANK: + case IT_ROPE: if (!fStanding && !IsStatFlag(STATF_HOVERING) && !pItem->IsAttr(ATTR_STATIC)) { // Check if we can go out of the ship (in the same direction of plank) @@ -3836,20 +3831,14 @@ TRIGRET_TYPE CChar::CheckLocation(bool fCanCheckRecursively, bool fStanding) } } continue; - default: + + default: continue; - } } - - if (fStepCancel) - return TRIGRET_RET_FALSE; } - if (fCanCheckRecursively && !_IsTimerSet()) - { - // We want it to check for the consequences only on the next tick. - SetTimeoutD(1); - } + if (fStepCancel) + return TRIGRET_RET_FALSE; if (fStanding) return TRIGRET_RET_TRUE; @@ -4071,8 +4060,12 @@ bool CChar::MoveToRegionReTest( dword dwType ) // This could be us just taking a step or being teleported. // Low level: DOES NOT UPDATE DISPLAYS or container flags. (may be offline) // This does not check for gravity. -bool CChar::MoveToChar(const CPointMap& pt, bool fStanding, bool fCheckLocation, bool fForceFix, bool fAllowReject) +bool CChar::MoveToChar(const CPointMap& pt, bool fStanding, bool fCheckLocationEffects, bool fForceFix, bool fAllowReject) { + // WARNING: If you are using fCheckLocationEffects = true, be sure to NOT create situations where this call to CheckLocationEffects + // makes it recursively call itself (moving to something that moves again the char and so on). + // Using CheckLocationEffects here is often not necessary, since it's called at each char PeriodicTick. + ADDTOCALLSTACK("CChar::MoveToChar"); if ( !pt.IsValidPoint() ) @@ -4122,7 +4115,7 @@ bool CChar::MoveToChar(const CPointMap& pt, bool fStanding, bool fCheckLocation, } } - if (fCheckLocation && (CheckLocation(false, fStanding) == TRIGRET_RET_FALSE) && ptOld.IsValidPoint()) + if (fCheckLocationEffects && (CheckLocationEffects(fStanding) == TRIGRET_RET_FALSE) && ptOld.IsValidPoint()) { SetTopPoint(ptOld); return false; @@ -4132,8 +4125,10 @@ bool CChar::MoveToChar(const CPointMap& pt, bool fStanding, bool fCheckLocation, bool CChar::MoveTo(const CPointMap& pt, bool fForceFix) { + ADDTOCALLSTACK_DEBUG("CChar::MoveTo"); + m_fClimbUpdated = false; // update climb height - return MoveToChar(pt, true, fForceFix); + return MoveToChar(pt, true, false, fForceFix); } void CChar::SetTopZ( char z ) @@ -4780,7 +4775,7 @@ bool CChar::OnTickPeriodic() { // Check location periodically for standing in fire fields, traps, etc. EXC_SET_BLOCK("check location"); - CheckLocation(true, true); + CheckLocationEffects(true); } EXC_SET_BLOCK("update stats"); diff --git a/src/game/chars/CCharNPCAct.cpp b/src/game/chars/CCharNPCAct.cpp index 4c24b8535..eb79497c2 100644 --- a/src/game/chars/CCharNPCAct.cpp +++ b/src/game/chars/CCharNPCAct.cpp @@ -572,7 +572,8 @@ int CChar::NPC_WalkToPoint( bool fRun ) CheckRevealOnMove(); EXC_SET_BLOCK("MoveToChar"); - if (!MoveToChar(pMe, false, true)) + //if (!MoveToChar(pMe, false, true)) + if (!MoveToChar(pMe, false, false)) return 2; EXC_SET_BLOCK("Move Update"); diff --git a/src/game/chars/CCharSpell.cpp b/src/game/chars/CCharSpell.cpp index 560420048..c97448fc3 100644 --- a/src/game/chars/CCharSpell.cpp +++ b/src/game/chars/CCharSpell.cpp @@ -110,7 +110,7 @@ bool CChar::Spell_Teleport( CPointMap ptNew, bool fTakePets, bool fCheckAntiMagi return false; ptNew.m_z = GetFixZ(ptNew); - + if (!IsPriv(PRIV_GM)) { if ( g_Cfg.m_iMountHeight ) @@ -215,7 +215,7 @@ bool CChar::Spell_Teleport( CPointMap ptNew, bool fTakePets, bool fCheckAntiMagi } } - MoveToChar(ptNew, true, true); // move character + MoveToChar(ptNew, true, false); // move character CClient *pClient = GetClientActive(); CClient *pClientIgnore = nullptr; @@ -313,7 +313,7 @@ bool CChar::Spell_CreateGate(CPointMap ptDest, bool fCheckAntiMagic) pGateOrig->SetAttr(ATTR_MOVE_NEVER); pGateOrig->m_itNormal.m_more1 = (dword)GetUID(); pGateOrig->m_itTelepad.m_ptMark = ptDest; - + CItem *pGateDest = CItem::CreateBase(idDest); ASSERT(pGateDest); pGateDest->SetType(IT_TELEPAD); @@ -500,7 +500,7 @@ bool CChar::Spell_Resurrection(CItemCorpse * pCorpse, CChar * pCharSrc, bool fNo Effect(EFFECT_OBJ, pSpellDef->m_idEffect, this, 10, 16); Sound(pSpellDef->m_sound); } - + if (IsClientActive()) { CClient *pClient = GetClientActive(); @@ -1320,7 +1320,7 @@ void CChar::Spell_Effect_Add( CItem * pSpell ) CCPropsChar* pCCPChar = GetComponentProps(); CCPropsChar* pBaseCCPChar = Base_GetDef()->GetComponentProps(); - + ModPropNum(pCCPChar, PROPCH_RESFIRE, - pSpell->m_itSpell.m_PolyDex, pBaseCCPChar); ModPropNum(pCCPChar, PROPCH_RESPOISON, - pSpell->m_itSpell.m_PolyDex, pBaseCCPChar); ModPropNum(pCCPChar, PROPCH_RESCOLD, + pSpell->m_itSpell.m_PolyStr, pBaseCCPChar); @@ -1649,7 +1649,7 @@ void CChar::Spell_Effect_Add( CItem * pSpell ) ushort uiMyMagicResistance = Skill_GetBase(SKILL_MAGICRESISTANCE), uiMyInscription = Skill_GetBase(SKILL_INSCRIPTION); wStatEffectRef = (uiCasterEvalInt + uiCasterMeditation + uiCasterInscription) / 40; wStatEffectRef = minimum(75, wStatEffectRef); - + iPhysicalResist = 15 - (uiCasterInscription / 200); int iPhysicalResistMin = minimum(INT16_MAX, iPhysicalResist); pSpell->m_itSpell.m_PolyStr = (short)(maximum(-INT16_MAX, iPhysicalResistMin )); @@ -1704,7 +1704,7 @@ void CChar::Spell_Effect_Add( CItem * pSpell ) Skill_AddBase( SKILL_MEDITATION, + wStatEffectRef ); return; } - + /*case SPELL_Chameleon: // 106 // makes your skin match the colors of whatever is behind you. case SPELL_BeastForm: // 107 // polymorphs you into an animal for a while. @@ -1732,7 +1732,7 @@ bool CChar::Spell_Equip_OnTick( CItem * pItem ) int iEffect = 0; DAMAGE_TYPE iDmgType = 0; int64 iSecondsDelay = 5; //default value for custom spells, can be overriden by Sphere spells below. - + switch ( spell ) { case SPELL_Ale: // 90 = drunkeness ? @@ -1771,7 +1771,7 @@ bool CChar::Spell_Equip_OnTick( CItem * pItem ) if (iCharges <=0 || iLevel <= 0) return false; iSecondsDelay = g_Rand.GetLLVal2(15, 30); - + if (IsClientActive()) { static const SOUND_TYPE sm_sounds[] = { 0x243, 0x244 }; @@ -1856,7 +1856,7 @@ bool CChar::Spell_Equip_OnTick( CItem * pItem ) pItem->m_itSpell.m_spelllevel -= 50; // gets weaker too. Only on old formulas iEffect = IMulDiv(Stat_GetMaxAdjusted(STAT_STR), iLevel * 2, 100); iSecondsDelay = (5 + g_Rand.GetLLVal(4)); - + static lpctstr const sm_Poison_Message[] = { g_Cfg.GetDefaultMsg(DEFMSG_SPELL_POISON_1), @@ -1874,11 +1874,11 @@ bool CChar::Spell_Equip_OnTick( CItem * pItem ) Emote(pszMsg, GetClientActive()); SysMessagef(g_Cfg.GetDefaultMsg(DEFMSG_SPELL_YOUFEEL), sm_Poison_Message[iLevel]); } - + static const int sm_iPoisonMax[] = { 2, 4, 6, 8, 10 }; iEffect = maximum(sm_iPoisonMax[iLevel], iEffect); iDmgType = DAMAGE_MAGIC | DAMAGE_POISON | DAMAGE_NODISTURB | DAMAGE_NOREVEAL; - + // We will have this effect again. if (IsSetOF(OF_Buffs) && IsClientActive()) { @@ -1946,7 +1946,7 @@ bool CChar::Spell_Equip_OnTick( CItem * pItem ) Args.m_VarsLocal.SetNum("Delay", iSecondsDelay); Args.m_VarsLocal.SetNum("DamageType", iDmgType); Args.m_VarsLocal.SetNum("Effect", iEffect); - + if (IsTrigUsed(TRIGGER_SPELLEFFECTTICK)) { switch (OnTrigger(CTRIG_SpellEffectTick, this, &Args)) @@ -2446,7 +2446,7 @@ bool CChar::Spell_CanCast( SPELL_TYPE &spellRef, bool fTest, CObjBase * pSrc, bo SysMessagef( g_Cfg.GetDefaultMsg( DEFMSG_SPELL_TRY_NOREGS ), pReagDef ? pReagDef->GetName() : g_Cfg.GetDefaultMsg( DEFMSG_SPELL_TRY_THEREG ) ); } return false; - } + } // Check for Tithing CVarDefContNum* pVarTithing = GetDefKeyNum("Tithing", false); @@ -2505,51 +2505,51 @@ CChar * CChar::Spell_Summon_Try(SPELL_TYPE spell, CPointMap ptTarg, CREID_TYPE i { switch (spell) { - /*The creature ID for the Summon Spell is already stored in m_atMagery.m_iSummonID when the creature + /*The creature ID for the Summon Spell is already stored in m_atMagery.m_iSummonID when the creature is chosen from the summoning menu.*/ - case SPELL_Summon: - break; + case SPELL_Summon: + break; case SPELL_Blade_Spirit: - m_atMagery.m_iSummonID = CREID_BLADE_SPIRIT; + m_atMagery.m_iSummonID = CREID_BLADE_SPIRIT; break; - case SPELL_Vortex: - m_atMagery.m_iSummonID = CREID_ENERGY_VORTEX; + case SPELL_Vortex: + m_atMagery.m_iSummonID = CREID_ENERGY_VORTEX; break; - case SPELL_Air_Elem: - m_atMagery.m_iSummonID = CREID_AIR_ELEM; + case SPELL_Air_Elem: + m_atMagery.m_iSummonID = CREID_AIR_ELEM; break; - case SPELL_Daemon: - m_atMagery.m_iSummonID = CREID_DEMON; + case SPELL_Daemon: + m_atMagery.m_iSummonID = CREID_DEMON; break; - case SPELL_Earth_Elem: - m_atMagery.m_iSummonID = CREID_EARTH_ELEM; + case SPELL_Earth_Elem: + m_atMagery.m_iSummonID = CREID_EARTH_ELEM; break; - case SPELL_Fire_Elem: - m_atMagery.m_iSummonID = CREID_FIRE_ELEM; + case SPELL_Fire_Elem: + m_atMagery.m_iSummonID = CREID_FIRE_ELEM; break; - case SPELL_Water_Elem: - m_atMagery.m_iSummonID = CREID_WATER_ELEM; + case SPELL_Water_Elem: + m_atMagery.m_iSummonID = CREID_WATER_ELEM; break; - case SPELL_Vengeful_Spirit: - m_atMagery.m_iSummonID = CREID_REVENANT; + case SPELL_Vengeful_Spirit: + m_atMagery.m_iSummonID = CREID_REVENANT; break; case SPELL_Rising_Colossus: - m_atMagery.m_iSummonID = CREID_RISING_COLOSSUS; + m_atMagery.m_iSummonID = CREID_RISING_COLOSSUS; break; case SPELL_Summon_Undead: //Sphere custom spell. switch (g_Rand.GetVal(15)) { - case 1: - m_atMagery.m_iSummonID = CREID_LICH; + case 1: + m_atMagery.m_iSummonID = CREID_LICH; break; case 3: case 5: case 7: - case 9: - m_atMagery.m_iSummonID = CREID_SKELETON; + case 9: + m_atMagery.m_iSummonID = CREID_SKELETON; break; - default: - m_atMagery.m_iSummonID = CREID_ZOMBIE; + default: + m_atMagery.m_iSummonID = CREID_ZOMBIE; break; } break; @@ -2579,7 +2579,7 @@ CChar * CChar::Spell_Summon_Try(SPELL_TYPE spell, CPointMap ptTarg, CREID_TYPE i } break; } - default: + default: m_atMagery.m_iSummonID = CREID_INVALID; break; } @@ -2749,7 +2749,7 @@ bool CChar::Spell_TargCheck() return false; } } - + // Is it a valid teleport location that allows this ? CRegion* pArea = CheckValidMove(m_Act_p, nullptr, DIR_QTY, nullptr); if (!pArea) @@ -3281,7 +3281,7 @@ void CChar::Spell_CastFail(bool fAbort) HUE_TYPE iColor = (HUE_TYPE)(Args.m_VarsLocal.GetKeyNum("EffectColor")); dword dwRender = (dword)Args.m_VarsLocal.GetKeyNum("EffectRender"); - + iT1 = (ITEMID_TYPE)(ResGetIndex((dword)Args.m_VarsLocal.GetKeyNum("CreateObject1"))); if (iT1) Effect(EFFECT_OBJ, iT1, this, 1, 30, false, iColor, dwRender); @@ -3542,7 +3542,7 @@ bool CChar::OnSpellEffect( SPELL_TYPE spell, CChar * pCharSrc, int iSkillLevel, iSkillLevel = (iSkillLevel / 2) + g_Rand.GetVal(iSkillLevel / 2); // randomize the potency int iEffect = g_Cfg.GetSpellEffect(spell, iSkillLevel); - if (pSpellDef->m_idLayer && !iDuration) //By using SPELLEFFECT command (and the spell has a layer where to store properties) we need to calculate the duration. + if (pSpellDef->m_idLayer && !iDuration) //By using SPELLEFFECT command (and the spell has a layer where to store properties) we need to calculate the duration. iDuration = GetSpellDuration(spell, iSkillLevel, pCharSrc); // tenths of second SOUND_TYPE iSound = pSpellDef->m_sound; @@ -3842,7 +3842,7 @@ bool CChar::OnSpellEffect( SPELL_TYPE spell, CChar * pCharSrc, int iSkillLevel, } } break; - + case SPELL_Protection: case SPELL_Arch_Prot: diff --git a/src/game/clients/CClientEvent.cpp b/src/game/clients/CClientEvent.cpp index 1de247304..1397e3da0 100644 --- a/src/game/clients/CClientEvent.cpp +++ b/src/game/clients/CClientEvent.cpp @@ -888,7 +888,7 @@ bool CClient::Event_Walk( byte rawdir, byte sequence ) // Player moves } // Check if I stepped on any item/teleport - TRIGRET_TYPE iRet = m_pChar->CheckLocation(true, false); + TRIGRET_TYPE iRet = m_pChar->CheckLocationEffects(false); if (iRet == TRIGRET_RET_FALSE) { m_pChar->SetUnkPoint(ptOld); // we already moved, so move back to previous location diff --git a/src/game/clients/CClientMsg_AOSTooltip.cpp b/src/game/clients/CClientMsg_AOSTooltip.cpp index d49c6f7f6..0b79e0d56 100644 --- a/src/game/clients/CClientMsg_AOSTooltip.cpp +++ b/src/game/clients/CClientMsg_AOSTooltip.cpp @@ -16,7 +16,7 @@ uint HashString(lpctstr str, size_t length) { uint hash = 5381; for (size_t i = 0; i < length; ++i) - hash = ((hash << 5) + hash) + *(str++); + hash = ((hash << 5) + hash) + (uint)(*(str++)); return hash; } @@ -111,7 +111,7 @@ bool CClient::addAOSTooltip(CObjBase * pObj, bool fRequested, bool fShop) pObj->AddPropsTooltipData(pObj); } - + if (IsTrigUsed(TRIGGER_CLIENTTOOLTIP_AFTERDEFAULT) || (pItem && IsTrigUsed(TRIGGER_ITEMCLIENTTOOLTIP_AFTERDEFAULT)) || (pChar && IsTrigUsed(TRIGGER_CHARCLIENTTOOLTIP_AFTERDEFAULT))) { CScriptTriggerArgs args(pObj); @@ -165,7 +165,7 @@ bool CClient::addAOSTooltip(CObjBase * pObj, bool fRequested, bool fShop) pObj->SetPropertyList(propertyList); } } - + if (propertyList->isEmpty() == false) { switch (g_Cfg.m_iTooltipMode) @@ -661,7 +661,7 @@ void CClient::AOSTooltip_addDefaultItemData(CItem * pItem) t->FormatArgs("Time range\t%hu min / %hu max", pSpawn->GetTimeLo(), pSpawn->GetTimeHi()); PUSH_BACK_TOOLTIP(pItem, t = new CClientTooltip(1060660)); // ~1_val~: ~2_val~ t->FormatArgs("Time until next spawn\t%" PRId64 " sec", pItem->GetTimerSAdjusted()); - + } break; case IT_SPAWN_ITEM: diff --git a/src/game/items/CItemShip.cpp b/src/game/items/CItemShip.cpp index 2acf705ea..67bdffee5 100644 --- a/src/game/items/CItemShip.cpp +++ b/src/game/items/CItemShip.cpp @@ -56,7 +56,7 @@ bool CItem::Ship_Plank(bool fOpen) m_itShipPlank.m_wSideType = (word)oldType; if ( !IsTimerSet() ) { - SetTimeoutS(5); // autoclose the plank + SetTimeoutS(5); // autoclose the plank SetAttr(ATTR_DECAY); // For preventing Decay Warning on the console. } } @@ -126,7 +126,7 @@ void CItemShip::r_Write(CScript & s) } } -enum IMCS_TYPE +enum IMCS_TYPE : int { IMCS_HATCH, IMCS_PLANK, @@ -197,7 +197,7 @@ bool CItemShip::r_LoadVal(CScript & s) EXC_TRY("LoadVal"); lpctstr ptcKey = s.GetKey(); IMCS_TYPE index = (IMCS_TYPE)FindTableHeadSorted(ptcKey, sm_szLoadKeys, ARRAY_COUNT(sm_szLoadKeys) - 1); - if (g_Serv.IsLoading()) + if (index >= 0 && g_Serv.IsLoading()) { switch (index) { diff --git a/src/network/CNetworkOutput.cpp b/src/network/CNetworkOutput.cpp index 269411253..b2168ec91 100644 --- a/src/network/CNetworkOutput.cpp +++ b/src/network/CNetworkOutput.cpp @@ -67,10 +67,10 @@ bool CNetworkOutput::processOutput() ASSERT(!m_thread->isActive() || m_thread->isCurrentThread()); const ProfileTask networkTask(PROFILE_NETWORK_TX); + static thread_local uchar tick = 0; - static uchar tick = 0; EXC_TRY("CNetworkOutput"); - ++tick; + tick = (tick == 16) ? 0 : (tick + 1); // decide which queues need to be processed bool toProcess[PacketSend::PRI_QTY]; diff --git a/src/network/packet.cpp b/src/network/packet.cpp index e95b2d91c..fd6a48f3e 100644 --- a/src/network/packet.cpp +++ b/src/network/packet.cpp @@ -184,7 +184,7 @@ void Packet::resize(uint newsize) memcpy(buffer, m_buffer, m_bufferSize); delete[] m_buffer; } - + m_buffer = buffer; m_bufferSize = newsize; m_length = m_bufferSize; @@ -205,9 +205,13 @@ void Packet::skip(int count) { // ensure we can't go lower than 0 if (count < 0 && (uint)SphereAbs(count) > m_position) + { m_position = 0; - else - m_position += (uint)count; + return; + } + + ASSERT((int64)m_position + count < UINT32_MAX); + m_position += (uint)count; } byte &Packet::operator[](uint index) @@ -235,7 +239,7 @@ void Packet::writeCharASCII(const char value) { if ((m_position + sizeof(char)) > m_bufferSize) expand(sizeof(char)); - + ASSERT((m_position + sizeof(char)) <= m_bufferSize); m_buffer[m_position++] = (byte)(value); } @@ -244,7 +248,7 @@ void Packet::writeCharUTF16(const wchar value) { if ((m_position + sizeof(wchar)) > m_bufferSize) expand(sizeof(wchar)); - + ASSERT((m_position + sizeof(wchar)) <= m_bufferSize); m_buffer[m_position++] = (byte)(value); m_buffer[m_position++] = (byte)(value >> 8); @@ -254,7 +258,7 @@ void Packet::writeCharNETUTF16(const wchar value) { if ((m_position + sizeof(wchar)) > m_bufferSize) expand(sizeof(wchar)); - + ASSERT((m_position + sizeof(wchar)) <= m_bufferSize); // Big endian m_buffer[m_position++] = (byte)(value >> 8); @@ -265,7 +269,7 @@ void Packet::writeByte(const byte value) { if ((m_position + sizeof(byte)) > m_bufferSize) expand(sizeof(byte)); - + ASSERT((m_position + sizeof(byte)) <= m_bufferSize); m_buffer[m_position++] = value; } @@ -274,7 +278,7 @@ void Packet::writeData(const byte* buffer, uint size) { if ((m_position + (sizeof(byte) * size)) > m_bufferSize) expand((sizeof(byte) * size)); - + ASSERT((m_position + (sizeof(byte) * size)) <= m_bufferSize); memcpy(&m_buffer[m_position], buffer, sizeof(byte) * size); m_position += size; @@ -284,7 +288,7 @@ void Packet::writeInt16(const word value) { if ((m_position + sizeof(word)) > m_bufferSize) expand(sizeof(word)); - + ASSERT((m_position + sizeof(word)) <= m_bufferSize); m_buffer[m_position++] = (byte)(value >> 8); m_buffer[m_position++] = (byte)(value); @@ -294,7 +298,7 @@ void Packet::writeInt32(const dword value) { if ((m_position + sizeof(dword)) > m_bufferSize) expand(sizeof(dword)); - + ASSERT((m_position + sizeof(dword)) <= m_bufferSize); m_buffer[m_position++] = (byte)(value >> 24); m_buffer[m_position++] = (byte)(value >> 16); @@ -306,7 +310,7 @@ void Packet::writeInt64(const int64 value) { if ((m_position + sizeof(int64)) > m_bufferSize) expand(sizeof(int64)); - + ASSERT((m_position + sizeof(int64)) <= m_bufferSize); m_buffer[m_position++] = (byte)(value >> 56); m_buffer[m_position++] = (byte)(value >> 48); @@ -322,7 +326,7 @@ void Packet::writeInt64(const dword hi, const dword lo) { if ((m_position + sizeof(int64)) > m_bufferSize) expand(sizeof(int64)); - + ASSERT((m_position + sizeof(int64)) <= m_bufferSize); m_buffer[m_position++] = (byte)(hi); m_buffer[m_position++] = (byte)(hi >> 8); @@ -378,7 +382,7 @@ void Packet::writeStringASCII(const wchar* value, bool terminate) value++; } delete[] buffer; - + if (terminate) writeCharASCII('\0'); #else @@ -436,7 +440,7 @@ void Packet::writeStringFixedASCII(const wchar* value, uint size, bool terminate reinterpret_cast(buffer)[i] = reinterpret_cast(value)[i]; reinterpret_cast(buffer)[i] = '\0'; } - + CvtNETUTF16ToSystem(buffer, THREAD_STRING_LENGTH, reinterpret_cast(buffer), THREAD_STRING_LENGTH); writeStringFixedASCII(buffer, size, terminate); @@ -458,12 +462,12 @@ void Packet::writeStringUTF16(const char* value, bool terminate) if (terminate) writeCharUTF16('\0'); #else - + ASSERT(value != nullptr); wchar * buffer = reinterpret_cast(Str_GetTemp()); CvtSystemToNETUTF16(reinterpret_cast(buffer), THREAD_STRING_LENGTH / sizeof(wchar), value, (int)(strlen(value))); - + writeStringNETUTF16(buffer, terminate); #endif } @@ -490,12 +494,12 @@ void Packet::writeStringFixedUTF16(const char* value, uint size, bool terminate) } } #else - + ASSERT(value != nullptr); wchar * buffer = reinterpret_cast(Str_GetTemp()); CvtSystemToNETUTF16(reinterpret_cast(buffer), THREAD_STRING_LENGTH / sizeof(wchar), value, (int)(strlen(value))); - + writeStringFixedNETUTF16(buffer, size, terminate); #endif } @@ -577,7 +581,7 @@ void Packet::writeStringNETUTF16(const char* value, bool terminate) wchar* buffer = reinterpret_cast(Str_GetTemp()); CvtSystemToNETUTF16(reinterpret_cast(buffer), THREAD_STRING_LENGTH / sizeof(wchar), value, (int)(strlen(value))); - + writeStringUTF16(buffer, terminate); #endif } @@ -606,10 +610,10 @@ void Packet::writeStringFixedNETUTF16(const char* value, uint size, bool termina #else ASSERT(value != nullptr); - + wchar* buffer = reinterpret_cast(Str_GetTemp()); CvtSystemToNETUTF16(reinterpret_cast(buffer), THREAD_STRING_LENGTH / sizeof(wchar), value, (int)(strlen(value))); - + writeStringFixedUTF16(buffer, size, terminate); #endif } @@ -744,8 +748,8 @@ word Packet::readInt16(void) if ((m_position + sizeof(word)) > m_length) return 0; - word w =(( m_buffer[m_position] << 8 ) | - ( m_buffer[m_position + 1])); + word w =(((word)m_buffer[m_position] << 8u) | + ((word)m_buffer[m_position + 1u])); m_position += 2; return w; @@ -756,10 +760,10 @@ dword Packet::readInt32(void) if ((m_position + sizeof(dword)) > m_length) return 0; - dword dw = ((m_buffer[m_position] << 24) | - (m_buffer[m_position + 1] << 16) | - (m_buffer[m_position + 2] << 8) | - (m_buffer[m_position + 3])); + dword dw = (((dword)m_buffer[m_position] << 24u) | + ((dword)m_buffer[m_position + 1u] << 16u) | + ((dword)m_buffer[m_position + 2u] << 8u) | + ((dword)m_buffer[m_position + 3u])); m_position += 4; return dw; @@ -819,7 +823,7 @@ void Packet::readStringASCII(wchar* buffer, uint length, bool includeNull) #endif delete[] bufferReal; #else - + char* bufferReal = new char[(size_t)length + 1](); readStringASCII(bufferReal, length, includeNull); CvtSystemToNETUTF16(reinterpret_cast(buffer), (int)(length), bufferReal, (int)(length)); @@ -1253,7 +1257,7 @@ void PacketSend::send(const CClient *client, bool appendTransaction) fixLength(); if (client != nullptr) target(client); - + // check target is set and can receive this packet if (m_target == nullptr || canSendTo(m_target) == false) return; diff --git a/src/sphere/threads.cpp b/src/sphere/threads.cpp index cde2cbf8f..bd69b5e74 100644 --- a/src/sphere/threads.cpp +++ b/src/sphere/threads.cpp @@ -13,11 +13,9 @@ #if defined(_WIN32) #include #include -#elif !defined(_BSD) -#ifndef __APPLE__ +#elif !defined(_BSD) && !defined(__APPLE__) #include #endif -#endif // number of exceptions after which we restart thread and think that the thread have gone in exceptioning loops @@ -66,7 +64,7 @@ typedef struct tagTHREADNAME_INFO } THREADNAME_INFO; #pragma pack(pop) -constexpr DWORD MS_VC_EXCEPTION = 0x406D1388; +static constexpr DWORD MS_VC_EXCEPTION = 0x406D1388; #endif void IThread::setThreadName(const char* name) @@ -161,7 +159,6 @@ IThread* ThreadHolder::current() throw CSError(LOGL_FATAL, 0, "Thread handle not found in vector?"); } - //auto thread = static_cast((*handle_found).second); auto thread = static_cast(found->second); ASSERT(thread->m_threadHolderId != -1); @@ -755,7 +752,6 @@ void AbstractSphereThread::pushStackCall(const char *name) NOEXCEPT_NODEBUG ++m_stackPos; _stackpos = m_stackPos; m_stackInfo[m_stackPos].functionName = name; - //printf("[%s]++++Pushed at pos %zd function: %s.\n", getName(), m_stackPos, name); } void AbstractSphereThread::popStackCall() NOEXCEPT_NODEBUG @@ -763,18 +759,9 @@ void AbstractSphereThread::popStackCall() NOEXCEPT_NODEBUG if (m_freezeCallStack == true) return; - //std::cout << "--Pos pre-pop: " << m_stackPos << "\n"; - /* - printf("[%s]--Popping at pos %zd function: %s.\n", getName(), m_stackPos, m_stackInfo[m_stackPos].functionName); - if (m_stackPos != _stackpos) { - printf("m_pos %zd, global %zu.\n", m_stackPos, _stackpos); - fflush(stdin); - NotifyDebugger(); - } - */ --m_stackPos; _stackpos = m_stackPos; - //DEBUG_ASSERT(m_stackPos >= -1); + ASSERT(m_stackPos >= -1); }