diff --git a/D2Hackit/Core/Server20.cpp b/D2Hackit/Core/Server20.cpp index 0c2633e..b73f8d9 100644 --- a/D2Hackit/Core/Server20.cpp +++ b/D2Hackit/Core/Server20.cpp @@ -375,7 +375,8 @@ BOOL EXPORT FindUnitByClassID(DWORD dwUnitClassID, DWORD dwUnitType, LPGAMEUNIT ::memset(lpBuffer, 0, sizeof(GAMEUNIT)); - Room* pRoom = D2COMMON_GetRoomFromUnit(D2CLIENT_GetPlayerUnit()); + const auto currentPlayerUnit = D2CLIENT_GetPlayerUnit(); + Room* pRoom = D2COMMON_GetRoomFromUnit(currentPlayerUnit); if (!pRoom) return FALSE; // not in a game? @@ -406,7 +407,8 @@ BOOL EXPORT FindUnitByName(LPCSTR lpszUnitName, DWORD dwUnitType, LPGAMEUNIT lpB wchar_t wszName[256] = {0}; ConvertToUnicode(lpszUnitName, wszName, 255); - Room* pRoom = D2COMMON_GetRoomFromUnit(D2CLIENT_GetPlayerUnit()); + const auto currentPlayerUnit = D2CLIENT_GetPlayerUnit(); + Room* pRoom = D2COMMON_GetRoomFromUnit(currentPlayerUnit); if (!pRoom) return FALSE; // not in a game? @@ -702,7 +704,8 @@ BOOL EXPORT GetMyMercUnit(LPGAMEUNIT lpBuffer) // Get player's mercenary if (PID == 0) return FALSE; - Room* pRoom = D2COMMON_GetRoomFromUnit(D2CLIENT_GetPlayerUnit()); + const auto currentPlayerUnit = D2CLIENT_GetPlayerUnit(); + Room* pRoom = D2COMMON_GetRoomFromUnit(currentPlayerUnit); if (!pRoom) return FALSE; // not in a game? @@ -751,7 +754,8 @@ BOOL EXPORT EnumUnits(DWORD dwUnitType, fnEnumUnitProc lpfnEnumUnitProc, LPARAM if (lpfnEnumUnitProc == NULL) return FALSE; - Room* pRoom = D2COMMON_GetRoomFromUnit(D2CLIENT_GetPlayerUnit()); + const auto currentPlayerUnit = D2CLIENT_GetPlayerUnit(); + Room* pRoom = D2COMMON_GetRoomFromUnit(currentPlayerUnit); if (!pRoom) return FALSE; // not in a game? @@ -894,7 +898,8 @@ int EXPORT GetMyCorpseCount() wchar_t wszName[256] = {0}; ConvertToUnicode(GetSafePlayerName(), wszName, 255); - Room* pRoom = D2COMMON_GetRoomFromUnit(D2CLIENT_GetPlayerUnit()); + const auto currentPlayerUnit = D2CLIENT_GetPlayerUnit(); + Room* pRoom = D2COMMON_GetRoomFromUnit(currentPlayerUnit); if (!pRoom) return 0; // not in a game? @@ -927,7 +932,8 @@ BOOL EXPORT PickMyCorpse() wchar_t wszName[256] = {0}; ConvertToUnicode(GetSafePlayerName(), wszName, 255); - Room* pRoom = D2COMMON_GetRoomFromUnit(D2CLIENT_GetPlayerUnit()); + const auto currentPlayerUnit = D2CLIENT_GetPlayerUnit(); + Room* pRoom = D2COMMON_GetRoomFromUnit(currentPlayerUnit); if (!pRoom) return 0; // not in a game? @@ -1355,7 +1361,8 @@ void GetRoomsRecursive(RoomOther *ro, CArrayEx& aChecked, std::vec if(!ro->pRoom) { add_room=TRUE; - D2COMMON_AddRoomData(D2CLIENT_GetPlayerUnit()->ptAct, GetCurrentMapID(), ro->xPos, ro->yPos, D2CLIENT_GetPlayerUnit()); + auto currentPlayerUnit = D2CLIENT_GetPlayerUnit(); + D2COMMON_AddRoomData(currentPlayerUnit->ptAct, GetCurrentMapID(), ro->xPos, ro->yPos, currentPlayerUnit); } aChecked.Add((DWORD)ro); @@ -1373,7 +1380,8 @@ void GetRoomsRecursive(RoomOther *ro, CArrayEx& aChecked, std::vec } if(add_room) { - D2COMMON_RemoveRoomData(D2CLIENT_GetPlayerUnit()->ptAct, GetCurrentMapID(), ro->xPos, ro->yPos, D2CLIENT_GetPlayerUnit()); + auto currentPlayerUnit = D2CLIENT_GetPlayerUnit(); + D2COMMON_RemoveRoomData(currentPlayerUnit->ptAct, GetCurrentMapID(), ro->xPos, ro->yPos, currentPlayerUnit); } } @@ -1415,7 +1423,9 @@ BOOL RevealPresetUnits(CArrayEx& aUnits) void FindPresetUnitsFromRoom2(RoomOther *ro, CArrayEx& aChecked, CArrayEx& aUnits) { - if(ro->ptDrlgLevel->LevelNo!=GetCurrentMapID()) + const auto currentMapId = GetCurrentMapID(); + + if(ro->ptDrlgLevel->LevelNo != currentMapId) return; if (aChecked.Find((DWORD)ro) != -1) @@ -1425,7 +1435,9 @@ void FindPresetUnitsFromRoom2(RoomOther *ro, CArrayEx& aChecked, C if(!ro->pRoom) { add_room=TRUE; - D2COMMON_AddRoomData(D2CLIENT_GetPlayerUnit()->ptAct, GetCurrentMapID(), ro->xPos, ro->yPos, D2CLIENT_GetPlayerUnit()); + const auto currentPlayerUnit = D2CLIENT_GetPlayerUnit(); + + D2COMMON_AddRoomData(currentPlayerUnit->ptAct, currentMapId, ro->xPos, ro->yPos, currentPlayerUnit); } aChecked.Add((DWORD)ro); @@ -1453,7 +1465,8 @@ void FindPresetUnitsFromRoom2(RoomOther *ro, CArrayEx& aChecked, C } if(add_room) { - D2COMMON_RemoveRoomData(D2CLIENT_GetPlayerUnit()->ptAct, GetCurrentMapID(), ro->xPos, ro->yPos, D2CLIENT_GetPlayerUnit()); + auto currentPlayerUnit = D2CLIENT_GetPlayerUnit(); + D2COMMON_RemoveRoomData(currentPlayerUnit->ptAct, GetCurrentMapID(), ro->xPos, ro->yPos, currentPlayerUnit); } } diff --git a/D2Hackit/Core/me.cpp b/D2Hackit/Core/me.cpp index 5f7cb81..c6689ec 100644 --- a/D2Hackit/Core/me.cpp +++ b/D2Hackit/Core/me.cpp @@ -1136,7 +1136,14 @@ BYTE EXPORT GetCurrentMapID() if (!pRoom) return MAP_UNKNOWN; - return D2COMMON_GetLevelIdFromRoom(pRoom); + if (!pRoom->ptRoomOther) { + return MAP_UNKNOWN; + } + if (!pRoom->ptRoomOther->ptDrlgLevel) { + return MAP_UNKNOWN; + } + + return pRoom->ptRoomOther->ptDrlgLevel->LevelNo; } BYTE EXPORT GetBeltRows() // Row number of the player's belt(1-4) @@ -2064,7 +2071,8 @@ void EXPORT CloseAllUIs() DWORD EXPORT GetStashGoldLimit() // stash gold limit { - return D2COMMON_GetStashGoldLimit(D2CLIENT_GetPlayerUnit()); + const auto currentPlayerUnit = D2CLIENT_GetPlayerUnit(); + return D2COMMON_GetStashGoldLimit(currentPlayerUnit); } DWORD EXPORT GetInventoryGoldLimit() // inventory gold limit @@ -2097,7 +2105,8 @@ BOOL EXPORT GetAlwaysRun() // is "always run" on? DWORD EXPORT GetCursorItem() // returns ID of the item on cursor, if any { - UnitAny* p = D2COMMON_GetCursorItem(D2CLIENT_GetPlayerUnit()->ptInventory); + const auto currentPlayerUnit = D2CLIENT_GetPlayerUnit(); + UnitAny* p = D2COMMON_GetCursorItem(currentPlayerUnit->ptInventory); return p ? p ->dwId : 0; } diff --git a/D2Hackit/Modules/flee/main.cpp b/D2Hackit/Modules/flee/main.cpp index 71e8ae8..5e197b5 100644 --- a/D2Hackit/Modules/flee/main.cpp +++ b/D2Hackit/Modules/flee/main.cpp @@ -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; } }