Files
praxisandClaude Fable 5.2 c2194c59d4 Protocol core: packet translation between source and native
127 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:47 +02:00

53 lines
2.8 KiB
C++

#pragma once
#include "gateway/object_updates.hpp"
#include <bit>
#include <cmath>
namespace gateway {
// Source DynamicObject is a map-local 32-bit counter, with no entry bits.
// Only genuine area-aura type1 is qualified. Flare's 0x10 diameter convention,
// portal0 and farsight2 remain separate contracts.
struct PersistentGround {
uint64_t source=0,caster=0;
uint32_t spell=0,type=0,cast_time=0;
float radius=0,scale=0;
std::array<float,4> position{};
std::map<uint16_t,uint32_t> fields;
bool observe(const LegacyObjectUpdate& update,bool create) {
if(create) {
if((update.kind!=2&&update.kind!=3)||update.type!=6||!update.movement||
(update.guid>>32)!=0xf1000000u||!uint32_t(update.guid))return false;
source=update.guid;fields.clear();position=update.movement->position;
}else if(update.kind!=0||update.guid!=source)return false;
for(auto [index,value]:update.fields)if(index<16)fields[index]=value;
if(!create)for(unsigned i=0;i<4;++i)if(auto it=update.fields.find(11+i);it!=update.fields.end())
position[i]=std::bit_cast<float>(it->second);
auto word=[&](uint16_t i){auto it=fields.find(i);return it==fields.end()?0u:it->second;};
caster=uint64_t(word(6))|(uint64_t(word(7))<<32);
type=word(8);spell=word(9);radius=std::bit_cast<float>(word(10));
scale=std::bit_cast<float>(word(4));
if(!caster||type!=1||!spell||spell>0x7fffff||!std::isfinite(radius)||radius<=0||radius>1000||
!std::isfinite(scale)||scale<=0||scale>100)return false;
for(auto v:position)if(!std::isfinite(v)||std::abs(v)>100000)return false;
return true;
}
};
inline Guid128 forever_persistent_ground_guid(uint64_t source,uint32_t spell,uint16_t realm,uint32_t map) {
if((source>>32)!=0xf1000000u||!uint32_t(source)||!spell||spell>0x7fffff||realm>8191||map>8191)
throw Error("persistent ground GUID context bound");
Bytes raw;le(raw,uint32_t(source),8);
le(raw,(uint64_t(12)<<58)|(uint64_t(realm)<<42)|(uint64_t(map)<<29)|(uint64_t(spell)<<6),8);
Guid128 id{};std::copy(raw.begin(),raw.end(),id.begin());return id;
}
// A pure codec context: both native identities are already bound by the tracker.
// kind0=create, kind1=typed values. No lifetime timer is encoded or fabricated.
inline Bytes persistent_ground_input(uint8_t kind,uint16_t map,const Guid128& id,
const Guid128& caster,const PersistentGround& ground,uint32_t visual) {
Bytes out{kind};le(out,map,2);append(out,id);append(out,caster);
le(out,ground.spell,4);le(out,visual,4);le(out,ground.type,1);
le(out,std::bit_cast<uint32_t>(ground.radius),4);le(out,ground.cast_time,4);
le(out,std::bit_cast<uint32_t>(ground.scale),4);
for(auto p:ground.position)le(out,std::bit_cast<uint32_t>(p),4);
return out;
}
}