diff --git a/common/pathfind.cpp b/common/pathfind.cpp index c04ade9aa..2ce88935d 100644 --- a/common/pathfind.cpp +++ b/common/pathfind.cpp @@ -3,8 +3,46 @@ #include #include +#include -const uint32_t nav_mesh_file_version = 1; +namespace Pathfind +{ + uint32_t InflateData(const char* buffer, uint32_t len, char* out_buffer, uint32_t out_len_max) { + z_stream zstream; + int zerror = 0; + int i; + + zstream.next_in = const_cast(reinterpret_cast(buffer)); + zstream.avail_in = len; + zstream.next_out = reinterpret_cast(out_buffer);; + zstream.avail_out = out_len_max; + zstream.zalloc = Z_NULL; + zstream.zfree = Z_NULL; + zstream.opaque = Z_NULL; + + i = inflateInit2(&zstream, 15); + if (i != Z_OK) { + return 0; + } + + zerror = inflate(&zstream, Z_FINISH); + if (zerror == Z_STREAM_END) { + inflateEnd(&zstream); + return zstream.total_out; + } + else { + if (zerror == -4 && zstream.msg == 0) + { + return 0; + } + + zerror = inflateEnd(&zstream); + return 0; + } + } +} + +const uint32_t nav_mesh_file_version = 2; const float max_dest_drift = 10.0f; const float at_waypoint_eps = 1.0f; EQEmu::Random path_rng; @@ -67,63 +105,67 @@ void PathfindingManager::Load(const std::string &zone_name) return; } + uint32_t data_size; + if (fread(&data_size, sizeof(data_size), 1, f) != 1) { + fclose(f); + return; + } + + uint32_t buffer_size; + if (fread(&buffer_size, sizeof(buffer_size), 1, f) != 1) { + fclose(f); + return; + } + + std::vector data; + data.resize(data_size); + if (fread(&data[0], data_size, 1, f) != 1) { + fclose(f); + return; + } + + std::vector buffer; + buffer.resize(buffer_size); + uint32_t v = Pathfind::InflateData(&data[0], data_size, &buffer[0], buffer_size); + fclose(f); + + char *buf = &buffer[0]; m_nav_mesh = dtAllocNavMesh(); - uint32_t number_of_tiles = 0; - if (fread(&number_of_tiles, sizeof(uint32_t), 1, f) != 1) { - Clear(); - fclose(f); - return; - } + uint32_t number_of_tiles = *(uint32_t*)buf; + buf += sizeof(uint32_t); - dtNavMeshParams params; - if (fread(¶ms, sizeof(dtNavMeshParams), 1, f) != 1) { - Clear(); - fclose(f); - return; - } + dtNavMeshParams params = *(dtNavMeshParams*)buf; + buf += sizeof(dtNavMeshParams); dtStatus status = m_nav_mesh->init(¶ms); if (dtStatusFailed(status)) { - Clear(); - fclose(f); + dtFreeNavMesh(m_nav_mesh); + m_nav_mesh = nullptr; return; } for (unsigned int i = 0; i < number_of_tiles; ++i) { - uint32_t tile_ref = 0; - if (fread(&tile_ref, sizeof(uint32_t), 1, f) != 1) { - Clear(); - fclose(f); - return; - } + uint32_t tile_ref = *(uint32_t*)buf; + buf += sizeof(uint32_t); - int32_t data_size = 0; - if (fread(&data_size, sizeof(int32_t), 1, f) != 1) { - Clear(); - fclose(f); - return; - } + int32_t data_size = *(uint32_t*)buf; + buf += sizeof(uint32_t); if (!tile_ref || !data_size) { - Clear(); - fclose(f); + dtFreeNavMesh(m_nav_mesh); + m_nav_mesh = nullptr; return; } unsigned char* data = (unsigned char*)dtAlloc(data_size, DT_ALLOC_PERM); - if (fread(data, data_size, 1, f) != 1) { - Clear(); - fclose(f); - return; - } + memcpy(data, buf, data_size); + buf += data_size; m_nav_mesh->addTile(data, data_size, DT_TILE_FREE_DATA, tile_ref, 0); } - - fclose(f); } } diff --git a/zone/pathing.cpp b/zone/pathing.cpp index 911a43c77..d04bb21aa 100644 --- a/zone/pathing.cpp +++ b/zone/pathing.cpp @@ -55,7 +55,7 @@ glm::vec3 Mob::UpdatePath(float ToX, float ToY, float ToZ, float Speed, bool &Wa Teleport(current.position); } - TrySnapToMap(); + //TrySnapToMap(); } return current.position; diff --git a/zone/spell_effects.cpp b/zone/spell_effects.cpp index e866d1e0f..93643b2cf 100644 --- a/zone/spell_effects.cpp +++ b/zone/spell_effects.cpp @@ -3362,7 +3362,7 @@ void Mob::BuffProcess() { --buffs[buffs_i].ticsremaining; - if ((buffs[buffs_i].ticsremaining == 0 && !(IsShortDurationBuff(buffs[buffs_i].spellid) || IsBardSong(buffs[buffs_i].spellid))) || buffs[buffs_i].ticsremaining < 0) { + if (buffs[buffs_i].ticsremaining < 0) { Log.Out(Logs::Detail, Logs::Spells, "Buff %d in slot %d has expired. Fading.", buffs[buffs_i].spellid, buffs_i); BuffFadeBySlot(buffs_i); } diff --git a/zone/waypoints.cpp b/zone/waypoints.cpp index d79e3fa00..8e3200aca 100644 --- a/zone/waypoints.cpp +++ b/zone/waypoints.cpp @@ -667,7 +667,7 @@ bool Mob::MakeNewPositionAndSendUpdate(float x, float y, float z, int speed, boo } //fix up pathing Z - if(!NPCFlyMode && checkZ && zone->HasMap() && RuleB(Map, FixPathingZWhenMoving)) { + if(!NPCFlyMode && checkZ && !zone->pathing.Loaded() && zone->HasMap() && RuleB(Map, FixPathingZWhenMoving)) { if(!RuleB(Watermap, CheckForWaterWhenMoving) || !zone->HasWaterMap() || (zone->HasWaterMap() && !zone->watermap->InWater(glm::vec3(m_Position))))