Files
WoW-Hybrid-gateway/tests/native_ground_cast_request_test.cpp

118 lines
5.0 KiB
C++

#include "world_translation.hpp"
#include <bit>
#include <iostream>
#include <optional>
using namespace gateway;
namespace {
using Point = std::array<float, 3>;
constexpr Point origin{22.5f, -35.25f, 2.f};
constexpr Point focus{-125.75f, 83.5f, 14.25f};
constexpr uint32_t far_sight = 6196;
void xyz(Bytes& bytes, const Point& position) {
for (float value : position) le(bytes, std::bit_cast<uint32_t>(value), 4);
}
Bytes cast(uint32_t flags, const Guid128& unit, std::optional<Point> source,
std::optional<Point> destination, std::optional<int32_t> map = {},
const Guid128& transport = {}, uint32_t spell = far_sight) {
Guid128 id{};
id[0] = 7;
Bytes bytes = pack_guid(id);
le(bytes, 1, 1); // Representative SendCastFlags.
for (int i = 0; i < 3; ++i) le(bytes, 0, 4);
le(bytes, spell, 4); le(bytes, 0, 4); le(bytes, 0, 4);
le(bytes, flags, 4);
append(bytes, pack_guid(unit));
append(bytes, pack_guid(Guid128{})); // Item and housing.
append(bytes, pack_guid(Guid128{}));
uint8_t presence = (source ? 0x40 : 0) | (destination ? 0x20 : 0);
if (map) presence |= 0x18; // Include orientation and map.
le(bytes, presence, 1); le(bytes, 0, 1);
for (const auto& point : {source, destination}) {
if (!point) continue;
append(bytes, pack_guid(transport));
xyz(bytes, *point);
}
if (map) {
le(bytes, std::bit_cast<uint32_t>(0.25f), 4);
le(bytes, uint32_t(*map), 4);
}
le(bytes, 0, 4); le(bytes, 0, 4); // Trajectory.
append(bytes, pack_guid(Guid128{}));
for (int i = 0; i < 3; ++i) le(bytes, 0, 4);
le(bytes, 0, 2); // Craft flags and optional tail.
return bytes;
}
void check(bool value, const char* message) {
if (!value) throw Error(message);
}
void refused(NativeWorldTranslation& world, const Bytes& body, const char* message) {
try { world.gameplay(0x3e0176, body); }
catch (const Error&) { return; }
throw Error(message);
}
}
int main() {
try {
NativeWorldTranslation world;
world.realm = 70;
world.selected.guid = 4509;
world.selected.race = 2;
world.selected.cls = 7;
world.selected.level = 60;
world.self_created = true;
world.location = WorldLocation{1, {0, 0, 0, 0}};
world.spells.insert(far_sight);
const auto cursor = cast(0x40, {}, {}, focus);
Bytes expected;
le(expected, far_sight, 4); le(expected, 0x40, 2); xyz(expected, focus);
const auto legacy = world.gameplay(0x3e0176, cursor);
check(legacy.opcode == 0x12e && legacy.body == expected,
"Far Sight destination differs from the Turtle cursor position");
world.gameplay_sent(0x3e0176, cursor);
check(world.pending_cast && world.pending_cast->spell.spell == far_sight &&
world.pending_cast->spell.target_flags == 0x40 &&
turtle_spell_request(world.pending_cast->spell, {}) == expected,
"Far Sight was not queued with its real destination mask");
// Octo Word of Recall Other declares SOURCE_LOCATION (0x20).
world.spells.insert(4);
Bytes source_only;
le(source_only, 4, 4); le(source_only, 0x20, 2); xyz(source_only, origin);
check(world.gameplay(0x3e0176, cast(0x20, {}, origin, {}, {}, {}, 4)).body == source_only,
"absolute source was not forwarded");
// Exercise the common SpellCastTargets field order independently of
// which subset a particular spell asks the client to send.
const auto self = forever_player_guid(world.selected.guid, world.realm);
Bytes combined;
le(combined, far_sight, 4); le(combined, 0x62, 2);
Bytes raw; le(raw, world.selected.guid, 8); append(combined, pack_guid(raw));
xyz(combined, origin); xyz(combined, focus);
check(world.gameplay(0x3e0176, cast(0x62, self, origin, focus, 1)).body == combined,
"unit, source and destination were not serialized in Turtle order");
check(world.gameplay(0x3e0176, cast(0x40, {}, {}, focus, -1)).body == expected,
"unspecified native map did not use the active world");
refused(world, cast(0x40, {}, {}, focus, 0), "cross-map destination accepted");
refused(world, cast(0x40, {}, {}, focus, {}, self), "transport offset sent as world coordinates");
refused(world, cast(0x40, {}, {}, {}), "missing destination treated as the origin");
refused(world, cast(0, {}, {}, focus), "unflagged destination accepted");
refused(world, cast(0x40, {}, {}, Point{18000, 0, 12}), "off-map XY position accepted");
refused(world, cast(0x42, forever_player_guid(4514, world.realm), {}, focus),
"ground target bypassed existing unit binding");
world.spells.erase(far_sight);
refused(world, cursor, "unlearned Far Sight forwarded");
std::cout << "Far Sight and absolute ground cast target translation PASS\n";
} catch (const std::exception& e) {
std::cerr << e.what() << '\n';
return 1;
}
}