132 lines
7.2 KiB
C++
132 lines
7.2 KiB
C++
#pragma once
|
|
#include "gateway/protocol.hpp"
|
|
#include <bit>
|
|
#include <climits>
|
|
#include <map>
|
|
#include <optional>
|
|
|
|
namespace gateway {
|
|
// Source writers: Tortoise Object.cpp/Spell.cpp/SpellEffects.cpp/Unit.cpp.
|
|
// ObjectGuid operator<< writes FULL64; only explicit GetPackGUID is packed.
|
|
// These neutral parsers do not imply a native representation for every event.
|
|
namespace turtle_combat_detail {
|
|
inline uint64_t packed(Reader& r) { auto b=unpack_guid(r,8);Reader g(b);return g.le(8); }
|
|
inline bool spell(uint32_t id) { return id && id<=INT_MAX; }
|
|
inline Bytes bound(uint64_t id,const std::map<uint64_t,Guid128>& known) {
|
|
auto it=known.find(id);
|
|
if(!id || it==known.end())throw Error("combat log actor outside live visible bindings");
|
|
return pack_guid(it->second);
|
|
}
|
|
}
|
|
struct TurtleSpellHealLog {
|
|
uint64_t target=0,caster=0;uint32_t spell=0,amount=0;bool critical=false;
|
|
};
|
|
inline std::optional<TurtleSpellHealLog> turtle_spell_heal_log(std::span<const uint8_t> body) {
|
|
Reader r(body);TurtleSpellHealLog d;
|
|
d.target=turtle_combat_detail::packed(r);d.caster=turtle_combat_detail::packed(r);
|
|
d.spell=uint32_t(r.le(4));d.amount=uint32_t(r.le(4));auto crit=r.le(1);r.end();
|
|
if(!d.target || !d.caster || !turtle_combat_detail::spell(d.spell) || crit>1)return {};
|
|
d.critical=bool(crit);return d;
|
|
}
|
|
struct TurtleSpellEnergizeLog {
|
|
uint64_t target=0,caster=0;uint32_t spell=0,amount=0;int32_t power_type=0;
|
|
};
|
|
inline std::optional<TurtleSpellEnergizeLog> turtle_spell_energize_log(std::span<const uint8_t> body) {
|
|
Reader r(body);TurtleSpellEnergizeLog d;
|
|
d.target=turtle_combat_detail::packed(r);d.caster=turtle_combat_detail::packed(r);
|
|
d.spell=uint32_t(r.le(4));d.power_type=std::bit_cast<int32_t>(uint32_t(r.le(4)));
|
|
d.amount=uint32_t(r.le(4));r.end();
|
|
// Actual Source enum: mana/rage/focus/energy/happiness and health(-2).
|
|
if(!d.target || !d.caster || !turtle_combat_detail::spell(d.spell) ||
|
|
(d.power_type!=-2 && (d.power_type<0 || d.power_type>4)))return {};
|
|
return d;
|
|
}
|
|
struct TurtleSpellMissTarget {uint64_t target=0;uint8_t miss_info=0;};
|
|
struct TurtleSpellMissLog {uint32_t spell=0;uint64_t caster=0;std::vector<TurtleSpellMissTarget> targets;};
|
|
inline std::optional<TurtleSpellMissLog> turtle_spell_miss_log(std::span<const uint8_t> body) {
|
|
Reader r(body);TurtleSpellMissLog d;
|
|
d.spell=uint32_t(r.le(4));d.caster=r.le(8);auto debug=r.le(1),count=r.le(4);
|
|
if(!turtle_combat_detail::spell(d.spell) || !d.caster || debug || !count || count>r.left()/9)return {};
|
|
d.targets.reserve(size_t(count));
|
|
for(uint64_t i=0;i<count;++i) {
|
|
TurtleSpellMissTarget t;t.target=r.le(8);t.miss_info=uint8_t(r.le(1));
|
|
// IMMUNE2=8, DEFLECT=9, ABSORB=10, REFLECT=11 are real Source values.
|
|
if(!t.target || t.miss_info>11)return {};
|
|
d.targets.push_back(t);
|
|
}
|
|
r.end();return d;
|
|
}
|
|
struct TurtleEnvironmentalDamageLog {
|
|
uint64_t victim=0;uint8_t type=0;uint32_t damage=0,absorbed=0;int32_t resisted=0;
|
|
};
|
|
inline std::optional<TurtleEnvironmentalDamageLog> turtle_environmental_damage_log(std::span<const uint8_t> body) {
|
|
Reader r(body);TurtleEnvironmentalDamageLog d;
|
|
d.victim=r.le(8);d.type=uint8_t(r.le(1));d.damage=uint32_t(r.le(4));
|
|
d.absorbed=uint32_t(r.le(4));d.resisted=std::bit_cast<int32_t>(uint32_t(r.le(4)));r.end();
|
|
// Unit::SendEnvironmentalDamageLog rewrites custom FALL_TO_VOID6 to FALL2.
|
|
if(!d.victim || d.type>5)return {};
|
|
return d;
|
|
}
|
|
struct TurtlePartyKillLog {uint64_t killer=0,victim=0;};
|
|
inline std::optional<TurtlePartyKillLog> turtle_party_kill_log(std::span<const uint8_t> body) {
|
|
Reader r(body);TurtlePartyKillLog d;d.killer=r.le(8);d.victim=r.le(8);r.end();
|
|
if(!d.killer || !d.victim)return {};
|
|
return d;
|
|
}
|
|
struct TurtleSpellDispelLog {uint64_t target=0,caster=0;std::vector<uint32_t> removed_spells;};
|
|
inline std::optional<TurtleSpellDispelLog> turtle_spell_dispel_log(std::span<const uint8_t> body) {
|
|
Reader r(body);TurtleSpellDispelLog d;
|
|
d.target=turtle_combat_detail::packed(r);d.caster=turtle_combat_detail::packed(r);auto count=r.le(4);
|
|
// Source has no DispelledBySpellID, IsSteal, IsBreak or rolled/needed fields.
|
|
if(!d.target || !d.caster || !count || count>r.left()/4)return {};
|
|
d.removed_spells.reserve(size_t(count));
|
|
for(uint64_t i=0;i<count;++i) {auto id=uint32_t(r.le(4));if(!turtle_combat_detail::spell(id))return {};d.removed_spells.push_back(id);}
|
|
r.end();return d;
|
|
}
|
|
struct TurtleSpellImmuneLog {uint64_t caster=0,target=0;uint32_t spell=0;};
|
|
inline std::optional<TurtleSpellImmuneLog> turtle_spell_immune_log(std::span<const uint8_t> body) {
|
|
Reader r(body);TurtleSpellImmuneLog d;
|
|
d.caster=r.le(8);d.target=r.le(8);d.spell=uint32_t(r.le(4));auto debug=r.le(1);r.end();
|
|
if(!d.caster || !d.target || !turtle_combat_detail::spell(d.spell) || debug)return {};
|
|
return d;
|
|
}
|
|
|
|
// Qualified ORIGINAL70334 getter + dispatch/readers, not the 0x6700xx source
|
|
// reference enum. Exact byte contracts/provenance are in combat-log-batch receipt.
|
|
inline constexpr uint32_t NativeSpellHealLogOpcode=0x69000a;
|
|
inline constexpr uint32_t NativeEnvironmentalDamageLogOpcode=0x69000e;
|
|
inline constexpr uint32_t NativeSpellImmuneLogOpcode=0x69001d;
|
|
// Source DealHeal supplies the post-hook raw heal, before health clamping; it
|
|
// implements no heal-absorption stage. ORIGINAL70334 callback1424e97a0 reads
|
|
// OverHeal at+4c and explicitly preserves -1 (unknown) at1424e99a9..99c7.
|
|
inline Bytes forever_spell_heal_log(const TurtleSpellHealLog& d,
|
|
const std::map<uint64_t,Guid128>& known) {
|
|
if(!turtle_combat_detail::spell(d.spell) || d.amount>INT_MAX)
|
|
throw Error("heal outside native signed32 representation");
|
|
auto out=turtle_combat_detail::bound(d.target,known);append(out,turtle_combat_detail::bound(d.caster,known));
|
|
le(out,d.spell,4);le(out,d.amount,4);le(out,d.amount,4);
|
|
le(out,0xffffffffu,4); // Original consumer's explicit unknown-overheal sentinel.
|
|
le(out,0,4);le(out,0,4); // No Source heal absorption or supporter records.
|
|
le(out,d.critical?0x80:0,1); // No roll debug, advanced log or content tuning.
|
|
return out;
|
|
}
|
|
inline Bytes forever_environmental_damage_log(const TurtleEnvironmentalDamageLog& d,
|
|
const std::map<uint64_t,Guid128>& known) {
|
|
if(!d.victim || d.type>5 || d.damage>INT_MAX || d.absorbed>INT_MAX)
|
|
throw Error("environmental damage outside native signed32 representation");
|
|
auto out=turtle_combat_detail::bound(d.victim,known);
|
|
le(out,d.type,1);le(out,d.damage,4);le(out,uint32_t(d.resisted),4);le(out,d.absorbed,4);
|
|
le(out,0,1); // Original reader's optional advanced-log presence bit is false.
|
|
return out;
|
|
}
|
|
inline Bytes forever_spell_immune_log(const TurtleSpellImmuneLog& d,
|
|
const std::map<uint64_t,Guid128>& known) {
|
|
if(!turtle_combat_detail::spell(d.spell))throw Error("invalid immune spell");
|
|
auto out=turtle_combat_detail::bound(d.caster,known);append(out,turtle_combat_detail::bound(d.target,known));
|
|
le(out,d.spell,4);
|
|
le(out,0,1); // ORIGINAL reads bits7 AND6; Source supplies neither optional flag.
|
|
return out;
|
|
}
|
|
// Additional source-qualified combat event writers live in source_combat_events.hpp.
|
|
}
|