Skip to content

Commit

Permalink
EnumPresetUnits randomly crashes if called (it might just be randomly…
Browse files Browse the repository at this point in the history
… when called while the area is loading)

Flee no longer checks for nearby wp's before opening a portal to avoid a crash
  • Loading branch information
nooperation committed Jul 22, 2023
1 parent a1c0260 commit be58334
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
9 changes: 6 additions & 3 deletions D2Hackit/Core/Server20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,9 @@ BOOL RevealPresetUnits(CArrayEx<PRESETUNIT, const PRESETUNIT&>& aUnits)

void FindPresetUnitsFromRoom2(RoomOther *ro, CArrayEx<DWORD, DWORD>& aChecked, CArrayEx<PRESETUNIT, const PRESETUNIT&>& aUnits)
{
if(ro->ptDrlgLevel->LevelNo!=GetCurrentMapID())
const auto currentMapId = GetCurrentMapID();

if(ro->ptDrlgLevel->LevelNo != currentMapId)
return;

if (aChecked.Find((DWORD)ro) != -1)
Expand All @@ -1433,8 +1435,9 @@ void FindPresetUnitsFromRoom2(RoomOther *ro, CArrayEx<DWORD, DWORD>& aChecked, C
if(!ro->pRoom)
{
add_room=TRUE;
auto currentPlayerUnit = D2CLIENT_GetPlayerUnit();
D2COMMON_AddRoomData(currentPlayerUnit->ptAct, GetCurrentMapID(), ro->xPos, ro->yPos, currentPlayerUnit);
const auto currentPlayerUnit = D2CLIENT_GetPlayerUnit();

D2COMMON_AddRoomData(currentPlayerUnit->ptAct, currentMapId, ro->xPos, ro->yPos, currentPlayerUnit);
}

aChecked.Add((DWORD)ro);
Expand Down
19 changes: 1 addition & 18 deletions D2Hackit/Modules/flee/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,24 +310,7 @@ VOID EXPORT OnThisPlayerMessage(UINT nMessage, WPARAM wParam, LPARAM lParam)
fleePortalRequested = false;
break;
case PM_LEAVETOWN:
if (!isSuppressingAutoTpWhenLeavingTown && createPortalWhenLeavingTown)
{
// Only create the portal if the waypoint is far enough away (we didn't just use a wp to leave town)
PRESETUNIT unit = {0};
if(server->EnumPresetUnits(enumPresetsForWaypoints, (LPARAM)&unit))
{
RequestTP(false);
break;
}

auto myPosition = me->GetPosition();
auto distanceToWaypoint = server->GetDistance(myPosition.x, myPosition.y, unit.x, unit.y);
if (distanceToWaypoint > 10)
{
RequestTP(false);
return;
}
}
// EnumPresetUnits can cause a crash so, enjoy your portals every time you leave town!
break;
}
}
Expand Down

0 comments on commit be58334

Please sign in to comment.