mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 10:53:44 +00:00
feat(character): keep and save the tooltip flags (SetTooltipFlag, char@ttip)
The client sends SetTooltipFlag (469: bFlag, then the tooltip, 2 live packets, both tooltip 24) when a tooltip has been shown, and follows it with SetFlag for the same ID. DLU dropped it and never wrote char@ttip, so the client's tooltip bits reset on every load. - SetTooltipFlag message struct and handler: the bit is set or cleared on the CharacterComponent exactly as the client does it (LWOCharacterComponent::SendMessage 0x00d34330): tooltips above 127 are ignored, set = 1 << tooltip, clear = mask ~1 << tooltip (which also clears the lower bits), shifts of 64 or more give 0. - Saved as char@ttip, a 64-bit value (the client reads it with GetLongLongValue in LoadFromSaveData 0x00ca4910). Live wrote it on every character (226 live charxmls: "0" or "16777216" = tooltip 24). Old saves without it load with 0. Check in game: on a new character, trigger a first-time tooltip (e.g. the one about an item or a new area), change zones and log out and back in: the character loads normally and the same tooltip does not come back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
#include "GameDependencies.h"
|
||||
|
||||
#include "CDClientDatabase.h"
|
||||
#include "Character.h"
|
||||
#include "CharacterComponent.h"
|
||||
#include "Entity.h"
|
||||
#include "GameMessages.h"
|
||||
#include "MissionComponent.h"
|
||||
@@ -72,3 +74,38 @@ TEST_F(CharacterSaveFieldsTests, MissionTypeStatesMissingInOldSave) {
|
||||
missions->UpdateXml(doc);
|
||||
EXPECT_EQ(Print(doc), R"(<obj v="1"><mis><done/><cur/><ts/></mis></obj>)");
|
||||
}
|
||||
|
||||
// char@ttip: the tooltip bits (the client reads it with GetLongLongValue). Live wrote it on every character.
|
||||
TEST_F(CharacterSaveFieldsTests, TooltipFlagsRoundTrip) {
|
||||
tinyxml2::XMLDocument doc;
|
||||
Parse(doc, R"(<obj v="1"><mf/><char ls="0" ttip="16777216"/></obj>)");
|
||||
|
||||
Character character(1, nullptr);
|
||||
Entity player(23, info);
|
||||
auto* const characterComponent = player.AddComponent<CharacterComponent>(-1, &character, UNASSIGNED_SYSTEM_ADDRESS);
|
||||
characterComponent->LoadFromXml(doc);
|
||||
EXPECT_EQ(characterComponent->GetTooltipFlags(), 16777216u);
|
||||
|
||||
characterComponent->SetTooltipFlag(2, true);
|
||||
characterComponent->UpdateXml(doc);
|
||||
EXPECT_STREQ(doc.FirstChildElement("obj")->FirstChildElement("char")->Attribute("ttip"), "16777220");
|
||||
|
||||
Entity reloaded(24, info);
|
||||
auto* const reloadedComponent = reloaded.AddComponent<CharacterComponent>(-1, &character, UNASSIGNED_SYSTEM_ADDRESS);
|
||||
reloadedComponent->LoadFromXml(doc);
|
||||
EXPECT_EQ(reloadedComponent->GetTooltipFlags(), 16777220u);
|
||||
}
|
||||
|
||||
// Saves from before ttip was written load with no tooltips flagged and gain ttip="0".
|
||||
TEST_F(CharacterSaveFieldsTests, TooltipFlagsMissingInOldSave) {
|
||||
tinyxml2::XMLDocument doc;
|
||||
Parse(doc, R"(<obj v="1"><mf/><char ls="0"/></obj>)");
|
||||
|
||||
Character character(1, nullptr);
|
||||
Entity player(25, info);
|
||||
auto* const characterComponent = player.AddComponent<CharacterComponent>(-1, &character, UNASSIGNED_SYSTEM_ADDRESS);
|
||||
characterComponent->LoadFromXml(doc);
|
||||
EXPECT_EQ(characterComponent->GetTooltipFlags(), 0u);
|
||||
characterComponent->UpdateXml(doc);
|
||||
EXPECT_STREQ(doc.FirstChildElement("obj")->FirstChildElement("char")->Attribute("ttip"), "0");
|
||||
}
|
||||
|
||||
@@ -16,7 +16,8 @@ SET(DGAMEMESSAGES_TESTS
|
||||
"VendorMessagesTests.cpp"
|
||||
"LegacyGameMessageTests.cpp"
|
||||
"GameMessageDecoderTests.cpp"
|
||||
"HotPropertyMessageTests.cpp")
|
||||
"HotPropertyMessageTests.cpp"
|
||||
"ClientMessagesTests.cpp")
|
||||
|
||||
# Get the folder name and prepend it to the files above
|
||||
get_filename_component(thisFolderName ${CMAKE_CURRENT_SOURCE_DIR} NAME)
|
||||
|
||||
69
tests/dGameTests/dGameMessagesTests/ClientMessagesTests.cpp
Normal file
69
tests/dGameTests/dGameMessagesTests/ClientMessagesTests.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
// Client -> server game messages DLU used to drop (docs/CaptureUnknowns.md section 4). Packets are from 2011/2012
|
||||
// live captures with the object ID replaced.
|
||||
#include "GameDependencies.h"
|
||||
#include "GameMessageTestUtils.h"
|
||||
|
||||
#include "CharacterComponent.h"
|
||||
#include "Entity.h"
|
||||
#include "PlayerMessages.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using namespace GameMessageTestUtils;
|
||||
|
||||
namespace {
|
||||
// A synthetic player object ID, as the object ID of the live packets below
|
||||
constexpr const char* PLAYER_HEADER = "53040005000000000100000000000010";
|
||||
}
|
||||
|
||||
class ClientMessagesTests : public GameDependenciesTest {
|
||||
protected:
|
||||
std::unique_ptr<Entity> player;
|
||||
std::unique_ptr<Character> character;
|
||||
|
||||
void SetUp() override {
|
||||
SetUpDependencies();
|
||||
player = std::make_unique<Entity>(0x1000000000000001LL, info);
|
||||
character = std::make_unique<Character>(1, nullptr);
|
||||
player->AddComponent<CharacterComponent>(-1, character.get(), UNASSIGNED_SYSTEM_ADDRESS);
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
player.reset();
|
||||
character.reset();
|
||||
TearDownDependencies();
|
||||
}
|
||||
};
|
||||
|
||||
// SetTooltipFlag (469): bFlag, then the tooltip. Both live samples flagged tooltip 24; live saved ttip="16777216".
|
||||
TEST_F(ClientMessagesTests, SetTooltipFlagMatchesLiveCapture) {
|
||||
auto msg = FromLiveClientCapture<GameMessages::SetTooltipFlag>(std::string(PLAYER_HEADER) + "d501" + "8c00000000");
|
||||
EXPECT_TRUE(msg.bFlag);
|
||||
EXPECT_EQ(msg.iToolTip, 24);
|
||||
EXPECT_EQ(RoundTrip(msg).iToolTip, 24);
|
||||
ExpectTruncatedFails(msg);
|
||||
|
||||
auto* const characterComponent = player->GetComponent<CharacterComponent>();
|
||||
msg.Handle(*player, UNASSIGNED_SYSTEM_ADDRESS);
|
||||
EXPECT_EQ(characterComponent->GetTooltipFlags(), 16777216u);
|
||||
}
|
||||
|
||||
// The client's bit operations: set shifts 1 by the tooltip; clear masks with ~1 shifted by the tooltip (clearing
|
||||
// every lower bit too); shifts of 64 or more give 0; tooltips above 127 are ignored.
|
||||
TEST_F(ClientMessagesTests, SetTooltipFlagFollowsTheClient) {
|
||||
auto* const characterComponent = player->GetComponent<CharacterComponent>();
|
||||
characterComponent->SetTooltipFlag(0, true);
|
||||
characterComponent->SetTooltipFlag(3, true);
|
||||
characterComponent->SetTooltipFlag(63, true);
|
||||
EXPECT_EQ(characterComponent->GetTooltipFlags(), 0x8000000000000009ULL);
|
||||
characterComponent->SetTooltipFlag(64, true);
|
||||
EXPECT_EQ(characterComponent->GetTooltipFlags(), 0x8000000000000009ULL);
|
||||
characterComponent->SetTooltipFlag(128, false);
|
||||
EXPECT_EQ(characterComponent->GetTooltipFlags(), 0x8000000000000009ULL);
|
||||
characterComponent->SetTooltipFlag(3, false);
|
||||
EXPECT_EQ(characterComponent->GetTooltipFlags(), 0x8000000000000000ULL);
|
||||
characterComponent->SetTooltipFlag(100, false);
|
||||
EXPECT_EQ(characterComponent->GetTooltipFlags(), 0u);
|
||||
}
|
||||
Reference in New Issue
Block a user