Files

132 lines
7.6 KiB
C++

#pragma once
#include "gateway/world.hpp"
#include "gateway/legacy_stream.hpp"
#include "gateway/transport_periods.hpp"
#include <cstddef>
#include <map>
#include <optional>
#include <tuple>
namespace gateway {
// Stationary profiles; moving transports and map objects need their own
// create/lifecycle schemas. Shared by the serializer and identity tracker.
constexpr bool turtle_static_game_object_type(uint32_t type) {
// QUESTGIVER=2 in both pinned protocols; includes source Wind Stones.
// Presentation does not establish support for their query/use/gossip flow.
return type==0 || type==1 || type==2 || type==3 || type==5 || type==6 ||
type==7 || type==8 || type==9 || type==10 || type==17 || type==18 || type==19 || type==23 || type==25;
// #99 (2026-11-26): FISHINGNODE(17) is the bobber a Fishing cast summons; without it the bobber, the line
// (channel object) and the fishing loop never showed.
}
// Source ACTIVE/READY/ACTIVE_ALTERNATIVE and native ACTIVE/READY/DESTROYED
// select the same three stationary model animation states (including the
// cannon-open alternative). Transport stop-frame states are a separate schema.
constexpr bool turtle_static_game_object_state(uint32_t state) { return state<=2; }
// Explicit shared interaction roles only. Source TRIGGERED(0x40) is not native
// AI_OBSTACLE(0x40); source transport and unknown bits are never copied here.
constexpr uint32_t turtle_static_game_object_flags(uint32_t flags) {
return (flags&0x01u ? 0x01u:0u) | (flags&0x02u ? 0x02u:0u) |
(flags&0x04u ? 0x04u:0u) | (flags&0x10u ? 0x10u:0u) |
(flags&0x20u ? 0x20u:0u);
}
inline constexpr uint16_t turtle_game_object_dynamic_flags_field = 19;
constexpr uint32_t forever_chest_dynamic_flags(uint32_t source_flags) {
// Tortoise resolves ACTIVATE (low bit 0) for this viewer. A conditional
// 70334 chest presents that decision with ACTIVATE, SPARKLE and HIGHLIGHT.
return (source_flags & 0x01u) ? (0x0004u | 0x0020u | 0x4000u) : 0u;
}
constexpr bool turtle_presentable_static_game_object(uint32_t type,uint32_t display) {
// Actual70334 CGameObject assertion permits a null model for spell foci,
// not traps/chests/etc. Retain unsupported source objects in diagnostics;
// never invent a model or alter their authoritative server behavior.
return turtle_static_game_object_type(type) && (display!=0 || type==8);
}
// TRANSPORT(11) elevators, Undercity lift doors and the Deeprun tram: the client animates them itself from
// its TransportAnimation rows, so only entries with a client loop period are presented (as TrinityCore
// Classic does: state TRANSPORT_ACTIVE, ServerTime + GameObject PathProgress in the create). Source
// elevators have no stop frames (data all 0) and the Source server never moves or tracks them.
constexpr bool turtle_presentable_transport(uint32_t type,uint32_t entry,uint32_t display) {
return (type==11 && display!=0 && turtle_transport_period(entry)!=0) ||
// MO_TRANSPORT ships/zeppelins: only routes whose client TaxiPathNode rows equal the server's.
(type==15 && display!=0 && turtle_mo_transport_client_path(entry)!=0);
}
constexpr bool turtle_presentable_game_object(uint32_t type,uint32_t entry,uint32_t display,uint32_t state) {
return turtle_presentable_transport(type,entry,display) ||
(turtle_presentable_static_game_object(type,display) && turtle_static_game_object_state(state));
}
// Local reference Source ONTRANSPORT data; native attachment semantics are
// not established and this snapshot is not forwarded to the native client.
struct SourceTransportSnapshot {
uint64_t guid=0;
std::array<float,4> relative_position{};
};
struct LegacyObjectUpdate {
uint8_t kind=0,type=0,update_flags=0;
uint64_t guid=0;
std::optional<GroundMovement> movement;
std::optional<SourceTransportSnapshot> source_transport;
std::array<float,6> speeds{};
std::map<uint16_t,uint32_t> fields;
std::vector<uint64_t> removed;
// UPDATEFLAG_MELEE_ATTACKING carries a packed source victim GUID after
// movement/high/all data. Engaged zero differs from an absent flag.
std::optional<uint64_t> melee_victim={};
// Complete source Living MovementInfo tails, retained without altering the
// existing GroundMovement view used by established NPC/self consumers.
std::optional<BasicMovement> basic_movement;
// UPDATEFLAG_TRANSPORT word: an MO_TRANSPORT's path progress (ms into its period), else server ms time.
std::optional<uint32_t> transport_time;
bool is_self_player_create(uint64_t selected_guid) const {
return (kind == 2 || kind == 3) && type == 4 && (update_flags & 1) && guid == selected_guid;
}
};
// This type crosses the gateway_protocol/codec C++ boundary. Include the
// compiled record layout in the required link symbol so an archive built
// against a different definition cannot silently corrupt a returned vector.
template<typename Types, std::size_t... Layout>
struct LegacyObjectUpdateLayoutTag {};
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winvalid-offsetof"
#elif defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Winvalid-offsetof"
#endif
using LegacyObjectUpdateLayout = LegacyObjectUpdateLayoutTag<
std::tuple<decltype(LegacyObjectUpdate::kind), decltype(LegacyObjectUpdate::type),
decltype(LegacyObjectUpdate::update_flags), decltype(LegacyObjectUpdate::guid),
decltype(LegacyObjectUpdate::movement), decltype(LegacyObjectUpdate::speeds),
decltype(LegacyObjectUpdate::fields),
decltype(LegacyObjectUpdate::removed), decltype(LegacyObjectUpdate::melee_victim),
decltype(LegacyObjectUpdate::basic_movement), decltype(LegacyObjectUpdate::transport_time)>,
sizeof(LegacyObjectUpdate), alignof(LegacyObjectUpdate),
sizeof(GroundMovement), alignof(GroundMovement), sizeof(BasicMovement), alignof(BasicMovement),
offsetof(LegacyObjectUpdate, kind), offsetof(LegacyObjectUpdate, type),
offsetof(LegacyObjectUpdate, update_flags), offsetof(LegacyObjectUpdate, guid),
offsetof(LegacyObjectUpdate, movement), offsetof(LegacyObjectUpdate, speeds),
offsetof(LegacyObjectUpdate, fields),
offsetof(LegacyObjectUpdate, removed), offsetof(LegacyObjectUpdate, melee_victim),
offsetof(LegacyObjectUpdate, basic_movement), offsetof(LegacyObjectUpdate, transport_time)>;
#if defined(__clang__)
#pragma clang diagnostic pop
#elif defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
void require_legacy_object_update_layout(LegacyObjectUpdateLayout*) noexcept;
struct LegacyMovementRecord { uint16_t opcode; Bytes body; };
std::vector<LegacyMovementRecord> turtle_compressed_moves(std::span<const uint8_t>);
Guid128 forever_game_object_guid(uint64_t legacy,uint32_t entry,uint16_t realm,uint32_t map);
// 70334 GUID of a Turtle MO transport (0x1FC0 high); throws for anything else. Same GUID the transport create uses.
Guid128 forever_mo_transport_guid(uint64_t legacy);
Guid128 forever_creature_guid(uint64_t legacy,uint32_t entry,uint16_t realm,uint32_t map);
Bytes forever_object_removal(uint16_t map,std::span<const Guid128> destroyed,std::span<const Guid128> out_of_range);
// Retain selected blocks verbatim in an uncompressed, client-bound presentation packet.
LegacyPacket turtle_object_update_subset(const LegacyPacket&,std::span<const size_t> selected);
std::vector<LegacyObjectUpdate> turtle_object_updates(uint32_t opcode,std::span<const uint8_t>);
// Native living creates reject zero walk speed. Normalize only a separate
// presentation copy of nonself creature creates; Source state stays intact.
LegacyPacket turtle_creature_create_presentation(const LegacyPacket&,uint64_t self);
}