883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
123 lines
7.3 KiB
C++
123 lines
7.3 KiB
C++
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
#include "gateway/quest_log.hpp"
|
|
#include <cassert>
|
|
#include <functional>
|
|
#include <iostream>
|
|
|
|
using namespace gateway;
|
|
static uint16_t field(unsigned slot, unsigned word) { return uint16_t(198 + slot * 3 + word); }
|
|
static uint32_t packed(unsigned a, unsigned b, unsigned c, unsigned d, unsigned state) {
|
|
return a | (b << 6) | (c << 12) | (d << 18) | (state << 24);
|
|
}
|
|
static void rejects(const std::function<void()>& f) {
|
|
bool failed = false;
|
|
try { f(); } catch (const Error&) { failed = true; }
|
|
assert(failed);
|
|
}
|
|
int main() {
|
|
static_assert(SourceQuestLogSlots == 20 && NativeQuestLogSlots == 175);
|
|
assert(!source_quest_log_field(197) && source_quest_log_field(198));
|
|
assert(source_quest_log_field(257) && !source_quest_log_field(258));
|
|
std::map<uint16_t, uint32_t> snapshot{
|
|
{field(0,0),101}, {field(0,1),packed(1,2,3,63,3)}, {field(0,2),0xFFFFFFFFu},
|
|
{field(19,0),202}, {field(19,1),packed(0,0,0,0,2)}, {field(19,2),1700000000}};
|
|
SourceQuestLogState state;
|
|
auto created = state.observe(snapshot, true);
|
|
assert(state.initialized() && created.source_create && created.slots.size() == 20);
|
|
assert(created.indices == std::vector<QuestLogIndex>({{101,0},{202,19}}));
|
|
assert(created.slots[0] == QuestLogSlot({0,101,3,0xFFFFFFFFu,{1,2,3,63}}));
|
|
assert(created.slots[1] == QuestLogSlot({1,0,0,0,{0,0,0,0}}));
|
|
assert(created.slots[19] == QuestLogSlot({19,202,2,1700000000,{0,0,0,0}}));
|
|
|
|
auto counters = state.observe({{field(0,1),packed(4,5,6,7,1)}}, false);
|
|
assert(counters.slots == std::vector<QuestLogSlot>({{0,101,1,0xFFFFFFFFu,{4,5,6,7}}}));
|
|
assert(counters.indices.empty() && counters.erased_indices.empty());
|
|
auto timer = state.observe({{field(19,2),1800000000}}, false);
|
|
assert(timer.slots == std::vector<QuestLogSlot>({{19,202,2,1800000000,{0,0,0,0}}}));
|
|
assert(state.observe({{600,123}}, false).empty());
|
|
auto cleared = state.observe({{field(0,0),0}}, false);
|
|
assert(cleared.slots == std::vector<QuestLogSlot>({{0,0,0,0,{0,0,0,0}}}));
|
|
assert(cleared.erased_indices == std::vector<QuestLogIndex>({{101,0}}));
|
|
assert(cleared.indices.empty());
|
|
|
|
auto replaced = state.observe({{field(19,0),303},{field(19,1),0},{field(19,2),888}},false);
|
|
assert(replaced.erased_indices == std::vector<QuestLogIndex>({{202,19}}));
|
|
assert(replaced.indices == std::vector<QuestLogIndex>({{303,19}}));
|
|
assert(replaced.slots == std::vector<QuestLogSlot>({{19,303,0,888,{0,0,0,0}}}));
|
|
rejects([&] { state.observe({{field(19,0),0xFFFFFFFFu}},false); });
|
|
auto after_error = state.observe({{field(19,2),999}},false);
|
|
assert(after_error.slots[0].quest_id == 303 && after_error.slots[0].end_time == 999);
|
|
|
|
auto unknown_flags = state.observe({{field(19,1),0xFD000000u}},false);
|
|
assert(unknown_flags.slots[0].state_flags == 1 && unknown_flags.unmapped_state_bits == 0xFC000000u);
|
|
auto fresh = state.observe({{field(2,0),404}},true);
|
|
assert(fresh.slots.size() == 20 && fresh.slots[19].quest_id == 0);
|
|
assert(fresh.indices == std::vector<QuestLogIndex>({{404,2}}) && fresh.erased_indices.empty());
|
|
|
|
SourceQuestLogState waiting;
|
|
assert(waiting.observe({{field(0,1),packed(1,2,3,4,1)}},false).waiting_for_create);
|
|
assert(!waiting.initialized());
|
|
auto first_create = waiting.observe({{field(0,0),505}},true);
|
|
assert(first_create.slots[0].counters == std::array<uint8_t,4>({0,0,0,0}));
|
|
waiting.clear(); assert(!waiting.initialized());
|
|
|
|
SourceQuestLogState swapped;
|
|
swapped.observe({{field(0,0),101},{field(1,0),202}},true);
|
|
auto swap = swapped.observe({{field(0,0),202},{field(1,0),101}},false);
|
|
assert(swap.slots.size() == 2 && swap.erased_indices.empty());
|
|
assert(swap.indices == std::vector<QuestLogIndex>({{101,1},{202,0}}));
|
|
SourceQuestLogState duplicate;
|
|
auto duplicate_create = duplicate.observe({{field(0,0),101},{field(1,0),101}},true);
|
|
assert(duplicate_create.indices == std::vector<QuestLogIndex>({{101,0}}));
|
|
auto first_removed = duplicate.observe({{field(0,0),0}},false);
|
|
assert(first_removed.erased_indices.empty() && first_removed.indices == std::vector<QuestLogIndex>({{101,1}}));
|
|
|
|
auto encoded = quest_log_update_input(70,1,4526,counters);
|
|
auto decoded = parse_quest_log_update_input(encoded);
|
|
assert(decoded.realm == 70 && decoded.map == 1 && decoded.self == 4526);
|
|
assert(decoded.projection.slots == counters.slots && decoded.projection.indices.empty());
|
|
for (size_t i = 0; i < encoded.size(); ++i)
|
|
rejects([&] { parse_quest_log_update_input(std::span(encoded.data(),i)); });
|
|
auto trailing = encoded; trailing.push_back(0);
|
|
rejects([&] { parse_quest_log_update_input(trailing); });
|
|
rejects([&] { quest_log_update_input(0,1,4526,counters); });
|
|
rejects([&] { quest_log_update_input(70,65536,4526,counters); });
|
|
rejects([&] { quest_log_update_input(70,1,0,counters); });
|
|
rejects([&] { quest_log_update_input(70,1,1ULL<<32,counters); });
|
|
auto bad = counters; bad.slots.push_back(bad.slots[0]);
|
|
rejects([&] { quest_log_update_input(70,1,4526,bad); });
|
|
bad = counters; bad.slots[0].slot = 20;
|
|
rejects([&] { quest_log_update_input(70,1,4526,bad); });
|
|
bad = counters; bad.slots[0].counters[0] = 64;
|
|
rejects([&] { quest_log_update_input(70,1,4526,bad); });
|
|
bad = counters; bad.indices={{101,0}}; bad.erased_indices={{101,0}};
|
|
rejects([&] { quest_log_update_input(70,1,4526,bad); });
|
|
// Actual recovered-Praxis shape: quest41015 is Source slot16. Native
|
|
// item slots4..7 carry genuine inventory-derived counts independently of
|
|
// Source creature counters and retain them through sparse word updates.
|
|
SourceQuestLogState items;
|
|
items.observe({{field(16,0),41015}},true);
|
|
assert(items.active_quests()==std::vector<uint32_t>{41015});
|
|
auto progress=items.set_item_counts({{41015,{1,2,0,32767}}});
|
|
assert(progress.slots.size()==1 && progress.slots[0].slot==16);
|
|
assert(progress.slots[0].item_counters==(std::array<uint16_t,4>{1,2,0,32767}));
|
|
auto with_items=quest_log_update_input(70,1,4526,progress);
|
|
assert(parse_quest_log_update_input(with_items).projection.slots==progress.slots);
|
|
for(size_t n=with_items.size()-9;n<with_items.size();++n)
|
|
rejects([&]{parse_quest_log_update_input(std::span(with_items.data(),n));});
|
|
assert(items.set_item_counts({{41015,{1,2,0,32767}}}).empty());
|
|
auto creature=items.observe({{field(16,1),packed(3,4,5,6,1)}},false);
|
|
assert(creature.slots[0].counters==(std::array<uint8_t,4>{3,4,5,6}));
|
|
assert(creature.slots[0].item_counters==progress.slots[0].item_counters);
|
|
auto gone=items.set_item_counts({});assert(gone.slots.size()==1);
|
|
assert(gone.slots[0].item_counters==(std::array<uint16_t,4>{}));
|
|
assert(gone.slots[0].counters==creature.slots[0].counters);
|
|
rejects([&]{items.set_item_counts({{41015,{32768,0,0,0}}});});
|
|
items.set_item_counts({{41015,{1,0,0,0}}});
|
|
auto removed=items.observe({{field(16,0),0}},false);
|
|
assert(removed.slots[0].item_counters==(std::array<uint16_t,4>{}));
|
|
items.observe({{field(16,0),41015}},true);
|
|
assert(items.observe({{field(16,1),1}},false).slots[0].item_counters==(std::array<uint16_t,4>{}));
|
|
std::cout << "Quest log: twenty-slot create, sparse cached words, counters/state/timer, clear/swap/index lifecycle, generation reset and DTO bounds PASS\n";
|
|
}
|