164 lines
8.4 KiB
C++
164 lines
8.4 KiB
C++
#pragma once
|
|
#include <cstdint>
|
|
#include <array>
|
|
#include <optional>
|
|
#include "gateway/race_slot_hide_profile.hpp"
|
|
namespace gateway {
|
|
// These source flags affect destination visual slots only, never inventory.
|
|
inline constexpr uint32_t SourceHideHelm=0x400,SourceHideCloak=0x800;
|
|
inline constexpr unsigned VisibilitySlots[2]={0,14}; // Original Player.h enums.
|
|
inline constexpr uint32_t visibility_mask(unsigned slot) noexcept {
|
|
return slot==0?SourceHideHelm:slot==14?SourceHideCloak:0;
|
|
}
|
|
inline constexpr uint32_t forever_visible_item_id(uint32_t flags,unsigned slot,uint32_t item) noexcept {
|
|
return (flags&visibility_mask(slot))?0:item;
|
|
}
|
|
// The explicit display is the visible Source display after transmog, never
|
|
// an equipped item's base display or a native donor display inferred by race.
|
|
inline constexpr uint32_t forever_visible_item_id(uint32_t flags,unsigned slot,uint32_t item,
|
|
uint8_t race,uint8_t gender,uint32_t source_visible_display) noexcept {
|
|
return race_slot_hide_profile::hidden(race,gender,slot,source_visible_display)?0:
|
|
forever_visible_item_id(flags,slot,item);
|
|
}
|
|
// Sending is not an ACK. Repeated commands coalesce until actual source flags.
|
|
struct EquipmentVisibilityState {
|
|
uint64_t guid=0,generation=0;uint16_t realm=0;uint32_t map=0,flags=0;
|
|
bool known=false,dirty=false;
|
|
std::array<std::optional<bool>,2> pending{};
|
|
bool bound(uint64_t self,uint16_t r,uint32_t m)const noexcept {
|
|
return known && generation && self && guid==self && realm==r && map==m;
|
|
}
|
|
void clear()noexcept{guid=0;known=false;dirty=false;pending={};++generation;}
|
|
void begin(uint64_t self,uint16_t r,uint32_t m,uint32_t source_flags)noexcept{
|
|
clear();guid=self;realm=r;map=m;known=true;flags=source_flags;dirty=true;
|
|
}
|
|
bool hidden(unsigned part)const noexcept{return (flags&visibility_mask(VisibilitySlots[part]))!=0;}
|
|
void observe(uint32_t source_flags)noexcept{
|
|
if(!known)return;
|
|
dirty|=((flags^source_flags)&(SourceHideHelm|SourceHideCloak))!=0;flags=source_flags;
|
|
for(unsigned part=0;part<2;++part)if(pending[part] && *pending[part]==hidden(part)){
|
|
pending[part].reset();dirty=true;
|
|
}
|
|
}
|
|
// action: -1 toggle, 0 hide, 1 show, 2 status.
|
|
bool needs_toggle(unsigned part,int action)const noexcept{
|
|
return known && part<2 && !pending[part] && action!=2 &&
|
|
(action==-1 || hidden(part)==bool(action));
|
|
}
|
|
void sent(unsigned part)noexcept{
|
|
if(known && part<2 && !pending[part])pending[part]=!hidden(part);
|
|
}
|
|
};
|
|
// Pinned Player.h enums: group/AFK/DND/GM/ghost/resting, contested PvP,
|
|
// played-long/too-long, taxi benchmark and PvP timer retain these meanings.
|
|
// Original70334 GetPVPDesired (RVA17C8017) consumes the shared0x200
|
|
// desired-state bit. Source acknowledgment owns it, independently of actual
|
|
// UnitData.PvpFlags and the delayed-disable timer.
|
|
// Source FFA, hide-helm/cloak, sanctuary and event/unknown bits
|
|
// must not become modern voice/War Mode/developer/raid/uber capabilities.
|
|
// Turtle PLAYER_BYTES_3 bits 1..15 = drunk value 0..0xFFFE (Player::GetDrunkenstateByValue: tipsy >0, drunk >=12800,
|
|
// smashed >=23000); native PlayerData::Inebriation is 0..100 (tipsy >0, drunk >=50, smashed >=90). Band to band, so the
|
|
// client's drunk camera/walk and state follow the server (#67, report 20261125-211515).
|
|
// Wired 2026-11-28 (#34/Q96): full creates and sparse PLAYER_BYTES_3 updates set PlayerData::Inebriation (forever bit 20,
|
|
// classic wire bit 21). The earlier JamScopedSize "Expected 14, received 15" assert came from the generated classic
|
|
// PlayerData::WriteUpdate (codec closure generated/uf_create.cpp), which set the bit but skipped the value write
|
|
// (`if constexpr (false)`); closure 7ac3d5a2 writes it. LOCAL: drunk 100 shows the client's drunk blur, no assert.
|
|
constexpr uint8_t forever_inebriation(uint32_t bytes3) {
|
|
const uint32_t v = bytes3 & 0xFFFEu;
|
|
if (v >= 23000) return uint8_t(90 + (v - 23000) * 10 / (65535 - 23000));
|
|
if (v >= 12800) return uint8_t(50 + (v - 12800) * 40 / (23000 - 12800));
|
|
return v ? uint8_t(1 + v * 49 / 12800) : uint8_t(0);
|
|
}
|
|
|
|
constexpr uint32_t forever_player_flags(uint32_t flags) {
|
|
return flags & 0x0006333f;
|
|
}
|
|
// Tortoise PlayerFieldByteFlags live in PLAYER_FIELD_BYTES byte0, whereas
|
|
// the original native ActivePlayerData has a separate LocalFlags word.
|
|
// Only shared TRACK_STEALTHED, RELEASE_TIMER and NO_RELEASE_WINDOW meanings.
|
|
constexpr uint32_t forever_player_local_flags(uint32_t packed) {
|
|
return packed & 0x1a;
|
|
}
|
|
// Tortoise SpellAuras::{HandleModStealth,HandleInvisibility} sends these
|
|
// source bytes; native UnitDefines/Player.h use distinct presentation fields.
|
|
// Source byte1 flag1 means ALWAYS_STAND, never native INVISIBLE.
|
|
constexpr uint8_t forever_aura_vision(uint32_t player_bytes2) {
|
|
return uint8_t(player_bytes2 >> 8) & 0x60;
|
|
}
|
|
constexpr uint8_t forever_unit_vis_flags(uint32_t unit_bytes1,uint32_t player_bytes2=0) {
|
|
return (uint8_t(unit_bytes1 >> 24) & 6) |
|
|
((forever_aura_vision(player_bytes2) & 0x40) ? 1 : 0);
|
|
}
|
|
}
|
|
|
|
namespace gateway {
|
|
// Source ChrRaces.model_m/f and the pinned native GetChrModel race/sex ->
|
|
// ChrModel.DisplayID -> CreatureDisplayInfo chain. Legacy default CDIs are
|
|
// not the native player defaults. This destination projection never changes
|
|
// the authoritative source snapshot or source race/faction identity.
|
|
// Pinned legacy UNIT_FIELD_DISPLAYID/NATIVEDISPLAYID field roles.
|
|
inline constexpr uint16_t SourceUnitDisplayIdField=131;
|
|
inline constexpr uint16_t SourceUnitNativeDisplayIdField=132;
|
|
// Legacy OBJECT_FIELD_SCALE_X (absolute size; 70334 multiplies Scale by its own model scale).
|
|
inline constexpr uint16_t SourceObjectScaleField=4;
|
|
// Turtle Unit::InitPlayerDisplayIds sets player scale = race display scale (server DBC: Tauren male 1.35, female 1.25,
|
|
// Gnome 1.15, others 1.0). 70334 sizes races from its own models and native servers send 1.0, so the race base is divided
|
|
// out; Enlarge/shrink effects keep their relative factor.
|
|
inline float forever_native_player_scale(float source,uint32_t race,uint32_t sex){
|
|
if(!(source>0) || source>1000)return 1.0f;
|
|
const float base=race==6?(sex?1.25f:1.35f):race==7?1.15f:1.0f;
|
|
return source/base;
|
|
}
|
|
// Shapeshift forms and morphs (potions, transforms, illusions) replace the race display; the server's scale is then that
|
|
// display's scale (Unit::SetTransformScale), and 70334 multiplies by its own model scale for it, so divide that out instead.
|
|
// display==native (or unknown) keeps the race-base rule. client_model_scale = forever_display_scale::client.
|
|
template<class ClientModelScale>
|
|
inline float forever_native_player_scale(float source,uint32_t race,uint32_t sex,uint32_t display,uint32_t native_display,
|
|
ClientModelScale client_model_scale){
|
|
if(!display || !native_display || display==native_display)return forever_native_player_scale(source,race,sex);
|
|
if(!(source>0) || source>1000)return 1.0f;
|
|
const float model=client_model_scale(display);
|
|
return model>0?source/model:source;
|
|
}
|
|
struct PlayerDefaultDisplayBinding {
|
|
uint8_t race,sex;
|
|
uint32_t source_default,native_default;
|
|
};
|
|
inline constexpr PlayerDefaultDisplayBinding PlayerDefaultDisplayBindings[]={
|
|
{1,0,49u,57899u},
|
|
{1,1,50u,56658u},
|
|
{2,0,51u,51894u},
|
|
{2,1,52u,53762u},
|
|
{3,0,53u,49242u},
|
|
{3,1,54u,53768u},
|
|
{4,0,55u,54918u},
|
|
{4,1,56u,54439u},
|
|
{5,0,57u,54041u},
|
|
{5,1,58u,56327u},
|
|
{6,0,59u,55077u},
|
|
{6,1,60u,56316u},
|
|
{7,0,1563u,51877u},
|
|
{7,1,1564u,53291u},
|
|
{8,0,1478u,59071u},
|
|
{8,1,1479u,59223u},
|
|
{10,0,15476u,62127u},
|
|
{10,1,15475u,62128u},
|
|
};
|
|
struct PlayerDefaultDisplayProjection {
|
|
uint32_t display,native_display;
|
|
bool mapped;
|
|
};
|
|
inline constexpr PlayerDefaultDisplayProjection forever_player_default_displays(
|
|
uint32_t race,uint32_t sex,uint32_t display,uint32_t native_display) noexcept {
|
|
if(!display || !native_display || sex>1)return {display,native_display,false};
|
|
for(const auto& binding:PlayerDefaultDisplayBindings) {
|
|
if(binding.race!=race || binding.sex!=sex || native_display!=binding.source_default)continue;
|
|
// Preserve active shapeshifts/morphs while projecting their original
|
|
// player default. A custom native/base display is never rewritten.
|
|
return {display==binding.source_default?binding.native_default:display,
|
|
binding.native_default,true};
|
|
}
|
|
return {display,native_display,false};
|
|
}
|
|
}
|