153 lines
6.9 KiB
C++
153 lines
6.9 KiB
C++
#include "optional_test_codec.hpp"
|
|
#include "world_translation.hpp"
|
|
#include "gateway/spell_visual_kit_profile.hpp"
|
|
#include <dlfcn.h>
|
|
#include <iostream>
|
|
#include <source_location>
|
|
|
|
using namespace gateway;
|
|
|
|
namespace {
|
|
void check(bool ok, std::source_location at = std::source_location::current()) {
|
|
if (!ok) throw Error("spell feedback fixture line " + std::to_string(at.line()));
|
|
}
|
|
|
|
Bytes guid_value(uint64_t source, uint32_t value) {
|
|
Bytes bytes;
|
|
le(bytes, source, 8);
|
|
le(bytes, value, 4);
|
|
return bytes;
|
|
}
|
|
|
|
Bytes cooldown(uint32_t spell, uint64_t source) {
|
|
Bytes bytes;
|
|
le(bytes, spell, 4);
|
|
le(bytes, source, 8);
|
|
return bytes;
|
|
}
|
|
|
|
void run(decltype(&gw_codec_serialize) codec) {
|
|
constexpr uint16_t realm = 57;
|
|
constexpr uint64_t self = 42, peer = 41, creature = 0xf13000000a000001ULL;
|
|
constexpr uint64_t item = 0x400000000000001cULL, pet = 0xf14000000b000002ULL;
|
|
NativeWorldTranslation world{};
|
|
world.selected.guid = self; world.selected.race = 1; world.selected.cls = 8;
|
|
world.realm = realm; world.location = WorldLocation{1, {}}; world.self_created = true;
|
|
world.entities.set_action_scope(self, realm, 1);
|
|
world.entities.self_presentation_ready = true;
|
|
const auto owner = forever_player_guid(self, realm);
|
|
const auto other = forever_player_guid(peer, realm);
|
|
const auto npc = forever_creature_guid(creature, 10, realm, 1);
|
|
auto bind = [&](uint64_t id, uint8_t kind, const Guid128& guid) {
|
|
auto& actor = world.entities.actors[id];
|
|
actor.kind = kind; actor.sent = true; actor.eligible = true;
|
|
actor.modern = guid; actor.presentation_map = 1; actor.presentation_realm = realm;
|
|
};
|
|
bind(creature, 3, npc);
|
|
bind(peer, 4, other);
|
|
world.inventory.items[item].type = 1;
|
|
auto dispatch = [&](uint32_t opcode, const Bytes& body) {
|
|
return world.translate({opcode, body}, 0x39010039, 1, codec);
|
|
};
|
|
auto expect = [&](uint32_t opcode, const Bytes& body, uint32_t normalized, const Bytes& expected) {
|
|
Bytes output; le(output, 1, 4); le(output, normalized, 4); le(output, expected.size(), 4);
|
|
append(output, expected);
|
|
check(dispatch(opcode, body) == output);
|
|
};
|
|
auto omitted = [&](uint32_t opcode, const Bytes& body) { check(dispatch(opcode, body) == Bytes(4)); };
|
|
auto rejects = [&](uint32_t opcode, const Bytes& body) {
|
|
bool threw = false;
|
|
try { dispatch(opcode, body); } catch (const Error&) { threw = true; }
|
|
check(threw);
|
|
};
|
|
auto unit_packet = [](const Guid128& guid, std::initializer_list<uint32_t> words) {
|
|
Bytes bytes = pack_guid(guid);
|
|
for (uint32_t value : words) le(bytes, value, 4);
|
|
return bytes;
|
|
};
|
|
auto kit_packet = [&](const Guid128& guid, uint32_t kit, uint32_t type) {
|
|
Bytes bytes = unit_packet(guid, {kit, type, 0});
|
|
bytes.push_back(0); // MountedVisual bit and padding.
|
|
return bytes;
|
|
};
|
|
|
|
// 0xB0 from Player::ApplyEquipCooldown. Known item low 28, HighGuid::Item.
|
|
Bytes equipped = unhex("01801c0c");
|
|
le(equipped, 406, 4); le(equipped, 30000, 4);
|
|
expect(0xb0, guid_value(item, 406), 0x470273, equipped);
|
|
check(world.item_cooldown_until.contains(406));
|
|
world.item_cooldown_until[406] = UINT64_MAX;
|
|
expect(0xb0, guid_value(item, 406), 0x470273, equipped);
|
|
check(world.item_cooldown_until.at(406) == UINT64_MAX);
|
|
omitted(0xb0, guid_value(item + 1, 404));
|
|
check(!world.item_cooldown_until.contains(404));
|
|
rejects(0xb0, guid_value(item, 0));
|
|
|
|
expect(0x135, cooldown(5143, self), 0x470166, unhex("1714000000"));
|
|
expect(0x135, cooldown(5143, pet), 0x470166, unhex("1714000080"));
|
|
expect(0x135, cooldown(5143, creature), 0x470166, unhex("1714000080"));
|
|
rejects(0x135, cooldown(1, item));
|
|
rejects(0x135, cooldown(1, 0));
|
|
rejects(0x135, cooldown(0xffffffff, self));
|
|
|
|
expect(0x13c, guid_value(creature, 2), 0x470162, unit_packet(npc, {2}));
|
|
expect(0x13c, guid_value(creature, 0), 0x470162, unit_packet(npc, {0}));
|
|
omitted(0x13c, guid_value(peer, 2));
|
|
rejects(0x13c, guid_value(creature, 5));
|
|
check(spell_visual_kit_profile::resolve(406) == 406);
|
|
check(spell_visual_kit_profile::resolve(6811) == 410002);
|
|
check(spell_visual_kit_profile::resolve(6746) == 0);
|
|
expect(0x1f3, guid_value(self, 406), 0x69003c, kit_packet(owner, 406, 0));
|
|
expect(0x1f3, guid_value(creature, 6811), 0x69003c, kit_packet(npc, 410002, 0));
|
|
expect(0x1f3, guid_value(peer, 2810), 0x69003c, kit_packet(other, 2810, 0));
|
|
// Turtle-added kits with reused Blizzard IDs. Only component-backed imports are playable.
|
|
constexpr std::pair<uint32_t, uint32_t> collisions[] = {
|
|
{5609, 0}, {5849, 410000}, {5891, 0}, {5893, 410001}, {6380, 0}, {6386, 0},
|
|
{6540, 0}, {6542, 0}, {6745, 0}, {6816, 0}, {6817, 0}, {6818, 0}, {6823, 0},
|
|
{6898, 0}, {6899, 0}, {6915, 0}, {6947, 410038}, {6949, 0}, {6959, 410046},
|
|
{6963, 0}, {6964, 410049}, {6965, 410050}, {6966, 410051}, {6967, 410052},
|
|
{6968, 410053}, {6973, 0}, {7004, 410084},
|
|
};
|
|
for (auto [source, target] : collisions) {
|
|
check(spell_visual_kit_profile::resolve(source) == target);
|
|
if (target) expect(0x1f3, guid_value(self, source), 0x69003c, kit_packet(owner, target, 0));
|
|
else omitted(0x1f3, guid_value(self, source));
|
|
}
|
|
omitted(0x1f3, guid_value(self, 6746)); // Source-only kit without imported assets.
|
|
omitted(0x1f3, guid_value(self, UINT32_MAX)); // Unknown in both tables.
|
|
omitted(0x1f3, guid_value(self, 0));
|
|
expect(0x1f7, guid_value(self, 362), 0x69003c, kit_packet(owner, 362, 1));
|
|
omitted(0x1f7, guid_value(self, 406));
|
|
|
|
for (uint32_t op : {0xb0, 0x135, 0x13c, 0x1f3, 0x1f7}) {
|
|
rejects(op, Bytes(11));
|
|
rejects(op, Bytes(13));
|
|
}
|
|
auto& actor = world.entities.actors.at(creature);
|
|
actor.sent = false; omitted(0x13c, guid_value(creature, 0));
|
|
actor.sent = true; actor.eligible = false; omitted(0x1f3, guid_value(creature, 406));
|
|
actor.eligible = true; ++actor.presentation_map; omitted(0x1f3, guid_value(creature, 406));
|
|
--actor.presentation_map; ++actor.presentation_realm; omitted(0x13c, guid_value(creature, 0));
|
|
world.self_created = false;
|
|
omitted(0x1f3, guid_value(self, 406));
|
|
omitted(0xb0, guid_value(item, 406));
|
|
}
|
|
}
|
|
|
|
int main(int argc, char** argv) {
|
|
try {
|
|
check(argc == 2);
|
|
if (test_fixture::optional_codec_missing(argv[1])) return 77;
|
|
auto lib = dlopen(argv[1], RTLD_NOW | RTLD_LOCAL);
|
|
if (!lib) throw Error(dlerror());
|
|
const auto codec = reinterpret_cast<decltype(&gw_codec_serialize)>(dlsym(lib, "gw_codec_serialize"));
|
|
check(codec != nullptr);
|
|
run(codec);
|
|
dlclose(lib);
|
|
std::cout << "source item cooldown, owner/pet cooldown, AI reaction, direct kit playback and qualified impact passed\n";
|
|
} catch (const std::exception& e) {
|
|
std::cerr << e.what() << '\n';
|
|
return 1;
|
|
}
|
|
}
|