mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-20 02:35:28 +00:00
Merge exp/component-audit-2: component audit rounds 2-4
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -4,7 +4,11 @@ set(DCOMPONENTS_TESTS
|
||||
"InventorySaveTests.cpp"
|
||||
"EquipMessagesTests.cpp"
|
||||
"DestroyableLevelConfigTests.cpp"
|
||||
"ProximityMonitorComponentTests.cpp"
|
||||
"RailActivatorComponentTests.cpp"
|
||||
"MountControlComponentTests.cpp"
|
||||
"ConstructionOnlyComponentTests.cpp"
|
||||
"PropertyVendorComponentTests.cpp"
|
||||
"VendorBuybackTests.cpp"
|
||||
"RacingWrongWayTests.cpp"
|
||||
"DestroyableComponentTests.cpp"
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
#include "tinyxml2.h"
|
||||
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
@@ -115,6 +116,196 @@ TEST_F(CharacterSaveFieldsTests, TooltipFlagsMissingInOldSave) {
|
||||
EXPECT_STREQ(doc.FirstChildElement("obj")->FirstChildElement("char")->Attribute("ttip"), "0");
|
||||
}
|
||||
|
||||
// The <char> attributes live wrote on every character and the client reads: cm, edit, mldt, gid, gn, v, vd and the
|
||||
// last respawn point. A save that has them keeps what the server does not own, and nothing touches the coins.
|
||||
TEST_F(CharacterSaveFieldsTests, LiveCharacterAttributesRoundTrip) {
|
||||
tinyxml2::XMLDocument doc;
|
||||
Parse(doc, R"(<obj v="1"><mf/><char cc="22609" cm="5000" ls="0" mldt="1301715419" v="1" vd="1" lrx="1" lry="2" lrz="3" lrrx="0" lrry="0.5" lrrz="0" lrrw="0.5" stime="349" lzcs="2233038349"/></obj>)");
|
||||
|
||||
Character character(1, nullptr);
|
||||
Entity player(40, info);
|
||||
auto* const characterComponent = player.AddComponent<CharacterComponent>(-1, &character, UNASSIGNED_SYSTEM_ADDRESS);
|
||||
characterComponent->LoadFromSaveData(doc);
|
||||
EXPECT_EQ(characterComponent->GetVotesLeft(), 1);
|
||||
EXPECT_EQ(characterComponent->GetVoteDay(), 1u);
|
||||
|
||||
characterComponent->WriteSaveData(doc);
|
||||
const auto* const saved = doc.FirstChildElement("obj")->FirstChildElement("char");
|
||||
EXPECT_STREQ(saved->Attribute("cc"), "22609");
|
||||
EXPECT_STREQ(saved->Attribute("cm"), "5000"); // kept, not replaced and not applied
|
||||
EXPECT_STREQ(saved->Attribute("mldt"), "1301715419");
|
||||
EXPECT_STREQ(saved->Attribute("edit"), "0");
|
||||
EXPECT_STREQ(saved->Attribute("gid"), "0");
|
||||
EXPECT_STREQ(saved->Attribute("gn"), "");
|
||||
// A new day: the votes are filled up
|
||||
const uint64_t today = static_cast<uint64_t>(std::time(nullptr)) / 86400;
|
||||
EXPECT_LE(saved->Unsigned64Attribute("vd") - today, 1u); // (the day may turn during the test)
|
||||
EXPECT_STREQ(saved->Attribute("v"), "3");
|
||||
// No respawn point was reached in this world: the saved one stays
|
||||
EXPECT_STREQ(saved->Attribute("lrx"), "1");
|
||||
EXPECT_STREQ(saved->Attribute("lrrw"), "0.5");
|
||||
// The session goes on (no other login is known): its seconds are kept
|
||||
EXPECT_GE(saved->Unsigned64Attribute("stime"), 349u);
|
||||
EXPECT_LE(saved->Unsigned64Attribute("stime"), 351u);
|
||||
// Not written by the server: left alone
|
||||
EXPECT_STREQ(saved->Attribute("lzcs"), "2233038349");
|
||||
|
||||
// The same day: the votes left are kept
|
||||
Entity reloaded(41, info);
|
||||
auto* const reloadedComponent = reloaded.AddComponent<CharacterComponent>(-1, &character, UNASSIGNED_SYSTEM_ADDRESS);
|
||||
doc.FirstChildElement("obj")->FirstChildElement("char")->SetAttribute("v", 2);
|
||||
reloadedComponent->LoadFromSaveData(doc);
|
||||
EXPECT_EQ(reloadedComponent->GetVotesLeft(), 2);
|
||||
reloadedComponent->SetGuild(77, u"Builders");
|
||||
reloadedComponent->WriteSaveData(doc);
|
||||
EXPECT_STREQ(saved->Attribute("v"), "2");
|
||||
EXPECT_STREQ(saved->Attribute("gid"), "77");
|
||||
EXPECT_STREQ(saved->Attribute("gn"), "Builders");
|
||||
}
|
||||
|
||||
// Saves from before they were written load as before and gain them with the values live had: the coins are not
|
||||
// touched and cm is the client's own "no limit".
|
||||
TEST_F(CharacterSaveFieldsTests, LiveCharacterAttributesMissingInOldSave) {
|
||||
tinyxml2::XMLDocument doc;
|
||||
Parse(doc, R"(<obj v="1"><mf/><char acct="1" cc="123456789012" gm="0" ls="15700" ttip="4" time="54390"/></obj>)");
|
||||
|
||||
Character character(1, nullptr);
|
||||
Entity player(42, info);
|
||||
auto* const characterComponent = player.AddComponent<CharacterComponent>(-1, &character, UNASSIGNED_SYSTEM_ADDRESS);
|
||||
characterComponent->LoadFromSaveData(doc);
|
||||
EXPECT_EQ(characterComponent->GetVotesLeft(), 3);
|
||||
EXPECT_EQ(characterComponent->GetTooltipFlags(), 4u);
|
||||
EXPECT_EQ(characterComponent->GetUScore(), 15700);
|
||||
|
||||
characterComponent->WriteSaveData(doc);
|
||||
const auto* const saved = doc.FirstChildElement("obj")->FirstChildElement("char");
|
||||
EXPECT_STREQ(saved->Attribute("cc"), "123456789012");
|
||||
EXPECT_STREQ(saved->Attribute("acct"), "1");
|
||||
EXPECT_STREQ(saved->Attribute("ls"), "15700");
|
||||
EXPECT_STREQ(saved->Attribute("cm"), "9223372036854775807");
|
||||
EXPECT_STREQ(saved->Attribute("edit"), "0");
|
||||
EXPECT_STREQ(saved->Attribute("mldt"), "0");
|
||||
EXPECT_STREQ(saved->Attribute("gid"), "0");
|
||||
EXPECT_STREQ(saved->Attribute("gn"), "");
|
||||
EXPECT_STREQ(saved->Attribute("v"), "3");
|
||||
EXPECT_NE(saved->Attribute("vd"), nullptr);
|
||||
EXPECT_EQ(saved->Attribute("lrx"), nullptr); // no respawn point reached yet
|
||||
EXPECT_NE(saved->Attribute("stime"), nullptr);
|
||||
}
|
||||
|
||||
namespace {
|
||||
// Loads <char> with the given attributes for a character whose login (charinfo.last_login) is sessionLogin, lets
|
||||
// seconds pass and saves. Returns the saved <char>.
|
||||
const tinyxml2::XMLElement* LoadPlayAndSave(tinyxml2::XMLDocument& doc, Character& character, CharacterComponent& component,
|
||||
const std::string& attributes, const uint64_t sessionLogin, const int64_t seconds) {
|
||||
const auto xml = R"(<obj v="1"><mf/><char acct="1" cc="5" )" + attributes + "/></obj>";
|
||||
EXPECT_EQ(doc.Parse(xml.c_str()), tinyxml2::XML_SUCCESS);
|
||||
character.SetSessionLogin(sessionLogin);
|
||||
component.LoadFromSaveData(doc);
|
||||
component.SetLastUpdateTimestamp(std::time(nullptr) - seconds);
|
||||
component.WriteSaveData(doc);
|
||||
return doc.FirstChildElement("obj")->FirstChildElement("char");
|
||||
}
|
||||
|
||||
// The seconds asked for, or one more when the clock ticked during the test
|
||||
void ExpectAbout(const uint64_t value, const uint64_t expected) {
|
||||
EXPECT_GE(value, expected);
|
||||
EXPECT_LE(value, expected + 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Play time as live saved it: time is the total before the session, stime the session's seconds, and the client
|
||||
// shows time + stime (LWOCharacterComponent::LoadFromSaveData 0x00ca4910, SendMessage 0x00d34330 GetTimePlayed).
|
||||
// A save from before stime was written has every past session in time: the total stays what it was.
|
||||
TEST_F(CharacterSaveFieldsTests, OldSavePlayTimeKeepsItsTotal) {
|
||||
tinyxml2::XMLDocument doc;
|
||||
Character character(1, nullptr);
|
||||
Entity player(60, info);
|
||||
auto* const component = player.AddComponent<CharacterComponent>(-1, &character, UNASSIGNED_SYSTEM_ADDRESS);
|
||||
const auto* const saved = LoadPlayAndSave(doc, character, *component, R"(llog="1700000000" time="54390")", 1700090000, 0);
|
||||
EXPECT_EQ(component->GetTotalTimePlayed() - component->GetSessionTimePlayed(), 54390u);
|
||||
ExpectAbout(component->GetTotalTimePlayed(), 54390);
|
||||
EXPECT_STREQ(saved->Attribute("time"), "54390");
|
||||
ExpectAbout(saved->Unsigned64Attribute("stime"), 0);
|
||||
EXPECT_STREQ(saved->Attribute("llog"), "1700090000");
|
||||
EXPECT_EQ(saved->Unsigned64Attribute("time") + saved->Unsigned64Attribute("stime"), component->GetTotalTimePlayed());
|
||||
|
||||
// The same without a known login (no charinfo row): nothing is lost and llog is left alone
|
||||
tinyxml2::XMLDocument unknownDoc;
|
||||
Character unknown(2, nullptr);
|
||||
Entity other(61, info);
|
||||
auto* const otherComponent = other.AddComponent<CharacterComponent>(-1, &unknown, UNASSIGNED_SYSTEM_ADDRESS);
|
||||
const auto* const otherSaved = LoadPlayAndSave(unknownDoc, unknown, *otherComponent, R"(llog="1700000000" time="54390")", 0, 0);
|
||||
EXPECT_STREQ(otherSaved->Attribute("time"), "54390");
|
||||
EXPECT_STREQ(otherSaved->Attribute("llog"), "1700000000");
|
||||
ExpectAbout(otherComponent->GetTotalTimePlayed(), 54390);
|
||||
}
|
||||
|
||||
// A session in progress: the seconds since the last save go to stime, time stays, and a world transfer in the same
|
||||
// session (the same login) goes on counting in stime. Live: time=262486 with stime=6795, then 7259 in the next world.
|
||||
TEST_F(CharacterSaveFieldsTests, SessionPlayTimeGrowsInStime) {
|
||||
tinyxml2::XMLDocument doc;
|
||||
Character character(1, nullptr);
|
||||
Entity player(62, info);
|
||||
auto* const component = player.AddComponent<CharacterComponent>(-1, &character, UNASSIGNED_SYSTEM_ADDRESS);
|
||||
const auto* saved = LoadPlayAndSave(doc, character, *component, R"(llog="1327837739" time="262486" stime="6795")", 1327837739, 464);
|
||||
EXPECT_STREQ(saved->Attribute("time"), "262486");
|
||||
ExpectAbout(saved->Unsigned64Attribute("stime"), 7259);
|
||||
EXPECT_STREQ(saved->Attribute("llog"), "1327837739");
|
||||
ExpectAbout(component->GetTotalTimePlayed(), 262486 + 7259);
|
||||
ExpectAbout(component->GetSessionTimePlayed(), 7259);
|
||||
|
||||
// A second save in the same world adds only what passed since the first
|
||||
component->SetLastUpdateTimestamp(std::time(nullptr) - 10);
|
||||
component->WriteSaveData(doc);
|
||||
EXPECT_STREQ(saved->Attribute("time"), "262486");
|
||||
EXPECT_GE(saved->Unsigned64Attribute("stime"), 7269u);
|
||||
EXPECT_LE(saved->Unsigned64Attribute("stime"), 7271u);
|
||||
|
||||
// The next world of the session loads what this one saved and goes on
|
||||
tinyxml2::XMLPrinter printer(nullptr, true);
|
||||
doc.Print(&printer);
|
||||
const std::string written = printer.CStr();
|
||||
tinyxml2::XMLDocument next;
|
||||
ASSERT_EQ(next.Parse(written.c_str()), tinyxml2::XML_SUCCESS);
|
||||
Entity inNextWorld(63, info);
|
||||
auto* const nextComponent = inNextWorld.AddComponent<CharacterComponent>(-1, &character, UNASSIGNED_SYSTEM_ADDRESS);
|
||||
nextComponent->LoadFromSaveData(next);
|
||||
EXPECT_EQ(nextComponent->GetTotalTimePlayed(), component->GetTotalTimePlayed());
|
||||
EXPECT_EQ(nextComponent->GetSessionTimePlayed(), component->GetSessionTimePlayed());
|
||||
nextComponent->SetLastUpdateTimestamp(std::time(nullptr) - 30);
|
||||
nextComponent->WriteSaveData(next);
|
||||
const auto* const nextSaved = next.FirstChildElement("obj")->FirstChildElement("char");
|
||||
EXPECT_STREQ(nextSaved->Attribute("time"), "262486");
|
||||
EXPECT_GE(nextSaved->Unsigned64Attribute("stime"), 7299u);
|
||||
EXPECT_LE(nextSaved->Unsigned64Attribute("stime"), 7302u);
|
||||
}
|
||||
|
||||
// The next login: the last session's seconds join time and stime starts over. Live: time=262486 stime=7344 at the
|
||||
// end of one session, time=269830 in the next. The total is the same before and after.
|
||||
TEST_F(CharacterSaveFieldsTests, ANewSessionMovesStimeIntoTime) {
|
||||
tinyxml2::XMLDocument doc;
|
||||
Character character(1, nullptr);
|
||||
Entity player(64, info);
|
||||
auto* const component = player.AddComponent<CharacterComponent>(-1, &character, UNASSIGNED_SYSTEM_ADDRESS);
|
||||
const auto* const saved = LoadPlayAndSave(doc, character, *component, R"(llog="1327837739" time="262486" stime="7344")", 1327848273, 74);
|
||||
EXPECT_STREQ(saved->Attribute("time"), "269830");
|
||||
ExpectAbout(saved->Unsigned64Attribute("stime"), 74);
|
||||
EXPECT_STREQ(saved->Attribute("llog"), "1327848273");
|
||||
ExpectAbout(component->GetTotalTimePlayed(), 269830 + 74);
|
||||
}
|
||||
|
||||
// The client reads stime as a float; a fraction written by something else is read, not refused
|
||||
TEST_F(CharacterSaveFieldsTests, FractionalStimeIsRead) {
|
||||
tinyxml2::XMLDocument doc;
|
||||
Character character(1, nullptr);
|
||||
Entity player(65, info);
|
||||
auto* const component = player.AddComponent<CharacterComponent>(-1, &character, UNASSIGNED_SYSTEM_ADDRESS);
|
||||
const auto* const saved = LoadPlayAndSave(doc, character, *component, R"(time="100" stime="15.6958")", 0, 0);
|
||||
EXPECT_STREQ(saved->Attribute("time"), "100");
|
||||
ExpectAbout(saved->Unsigned64Attribute("stime"), 15);
|
||||
}
|
||||
|
||||
// <skil sc>: the cooldown groups still running and the seconds left, as live wrote them (sc="17:15.6958;") and the
|
||||
// client reads them (split on ';' and ':').
|
||||
TEST_F(CharacterSaveFieldsTests, SkillCooldownsRoundTrip) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// the player has that mission.
|
||||
#include "GameDependencies.h"
|
||||
|
||||
#include "BitStream.h"
|
||||
#include "GameMessages.h"
|
||||
#include "CDClientDatabase.h"
|
||||
#include "CDClientManager.h"
|
||||
@@ -60,6 +61,24 @@ TEST_F(CollectibleComponentTests, RequirementMissionIsRead) {
|
||||
EXPECT_EQ(other.AddComponent<CollectibleComponent>(999, 5)->GetRequirementMission(), -1); // no row
|
||||
}
|
||||
|
||||
// LWOCollectibleComponent::Deserialize reads the 16-bit id on construction and nothing on an update. DLU wrote the id
|
||||
// on updates too, which the client read as the next components' flag bits.
|
||||
TEST_F(CollectibleComponentTests, TheIdIsWrittenOnConstructionOnly) {
|
||||
Entity object(22, info);
|
||||
auto* const collectible = object.AddComponent<CollectibleComponent>(78, 5);
|
||||
|
||||
RakNet::BitStream construction;
|
||||
collectible->Serialize(construction, true);
|
||||
ASSERT_EQ(construction.GetNumberOfBitsUsed(), 16u);
|
||||
int16_t id{};
|
||||
construction.Read(id);
|
||||
EXPECT_EQ(id, 5);
|
||||
|
||||
RakNet::BitStream update;
|
||||
collectible->Serialize(update, false);
|
||||
EXPECT_EQ(update.GetNumberOfBitsUsed(), 0u);
|
||||
}
|
||||
|
||||
TEST_F(CollectibleComponentTests, AchievementsAndMissingMissionsAlwaysCount) {
|
||||
Entity player(42, info);
|
||||
player.AddComponent<MissionComponent>(-1);
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
// What the client reads for a chest, a choice build and a roller: LWOChestComponent::Deserialize (0x00c22010),
|
||||
// LWOChoiceBuildComponent::Deserialize (0x00bf26d0) and LWORollerComponent::Deserialize (0x00c15920). Where they are
|
||||
// read among an object's components is in ReplicaComponentOrderTests.
|
||||
#include "GameDependencies.h"
|
||||
|
||||
#include "BitStream.h"
|
||||
#include "ChestComponent.h"
|
||||
#include "ChoiceBuildComponent.h"
|
||||
#include "Entity.h"
|
||||
#include "RollerComponent.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <vector>
|
||||
|
||||
class ConstructionOnlyComponentTests : public GameDependenciesTest {
|
||||
protected:
|
||||
void SetUp() override { SetUpDependencies(); }
|
||||
void TearDown() override { TearDownDependencies(); }
|
||||
|
||||
template <typename Component>
|
||||
static std::vector<uint8_t> Bytes(Component& component, const bool construction, uint32_t* const bits = nullptr) {
|
||||
RakNet::BitStream stream;
|
||||
component.Serialize(stream, construction);
|
||||
if (bits) *bits = stream.GetNumberOfBitsUsed();
|
||||
return { stream.GetData(), stream.GetData() + stream.GetNumberOfBytesUsed() };
|
||||
}
|
||||
};
|
||||
|
||||
// Construction: the player (u64) and the loot offer count (u32); nothing in an update
|
||||
TEST_F(ConstructionOnlyComponentTests, Chest) {
|
||||
Entity entity(15, info);
|
||||
auto* const chest = entity.AddComponent<ChestComponent>(0);
|
||||
uint32_t bits{};
|
||||
EXPECT_EQ(Bytes(*chest, true, &bits), (std::vector<uint8_t>{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }));
|
||||
EXPECT_EQ(bits, 96u);
|
||||
|
||||
chest->SetPlayerID(0x1000000000000001LL);
|
||||
chest->SetLootOfferCount(3);
|
||||
EXPECT_EQ(Bytes(*chest, true, &bits), (std::vector<uint8_t>{ 0x01, 0, 0, 0, 0, 0, 0, 0x10, 0x03, 0, 0, 0 }));
|
||||
EXPECT_EQ(bits, 96u);
|
||||
|
||||
EXPECT_TRUE(Bytes(*chest, false, &bits).empty());
|
||||
EXPECT_EQ(bits, 0u);
|
||||
}
|
||||
|
||||
// A flag, then the state (u32), the built object (u64) and the user (u64): always in a construction, in an update
|
||||
// after a change only
|
||||
TEST_F(ConstructionOnlyComponentTests, ChoiceBuild) {
|
||||
Entity entity(15, info);
|
||||
auto* const choiceBuild = entity.AddComponent<ChoiceBuildComponent>(1);
|
||||
uint32_t bits{};
|
||||
// 1 flag bit, then 160 zero bits: waiting, nothing built, nobody using it (the client's own start values)
|
||||
std::vector<uint8_t> waiting(21, 0);
|
||||
waiting[0] = 0x80;
|
||||
EXPECT_EQ(Bytes(*choiceBuild, true, &bits), waiting);
|
||||
EXPECT_EQ(bits, 161u);
|
||||
|
||||
EXPECT_EQ(Bytes(*choiceBuild, false, &bits), (std::vector<uint8_t>{ 0x00 }));
|
||||
EXPECT_EQ(bits, 1u);
|
||||
|
||||
choiceBuild->SetState(ChoiceBuildComponent::eState::Building, 0x0000400000000002LL, 0x1000000000000001LL);
|
||||
// The same fields shifted by the flag bit: state 1, object 0x0000400000000002, user 0x1000000000000001
|
||||
RakNet::BitStream expected;
|
||||
expected.Write1();
|
||||
expected.Write<uint32_t>(1);
|
||||
expected.Write<LWOOBJID>(0x0000400000000002LL);
|
||||
expected.Write<LWOOBJID>(0x1000000000000001LL);
|
||||
const std::vector<uint8_t> building{ expected.GetData(), expected.GetData() + expected.GetNumberOfBytesUsed() };
|
||||
EXPECT_EQ(building[0], 0x80); // the flag, then the low byte of the state (1) one bit on
|
||||
EXPECT_EQ(building[1], 0x80);
|
||||
EXPECT_EQ(Bytes(*choiceBuild, false, &bits), building);
|
||||
EXPECT_EQ(bits, 161u);
|
||||
// Sent once
|
||||
EXPECT_EQ(Bytes(*choiceBuild, false, &bits), (std::vector<uint8_t>{ 0x00 }));
|
||||
// A later construction carries the state as it is
|
||||
EXPECT_EQ(Bytes(*choiceBuild, true, &bits), building);
|
||||
}
|
||||
|
||||
// Construction: camera position and look-at (3 floats each), the projectile skill (u32, the client starts at 1348),
|
||||
// then the flag of the user block, which is never set. An update is that flag alone.
|
||||
TEST_F(ConstructionOnlyComponentTests, Roller) {
|
||||
Entity entity(15, info);
|
||||
auto* const roller = entity.AddComponent<RollerComponent>(13951);
|
||||
uint32_t bits{};
|
||||
std::vector<uint8_t> expected(29, 0);
|
||||
expected[24] = 0x44; // 1348 = 0x544
|
||||
expected[25] = 0x05;
|
||||
EXPECT_EQ(Bytes(*roller, true, &bits), expected);
|
||||
EXPECT_EQ(bits, 225u);
|
||||
|
||||
EXPECT_EQ(Bytes(*roller, false, &bits), (std::vector<uint8_t>{ 0x00 }));
|
||||
EXPECT_EQ(bits, 1u);
|
||||
}
|
||||
|
||||
// The level's activity_camera_pos / activity_camera_lookat_pos: three numbers with character 31 between them
|
||||
TEST_F(ConstructionOnlyComponentTests, RollerCameraComesFromTheLevel) {
|
||||
Entity entity(15, info);
|
||||
entity.SetVar<std::u16string>(u"activity_camera_pos", u"-327.861\x1f" u"256.91\x1f" u".64822");
|
||||
entity.SetVar<std::u16string>(u"activity_camera_lookat_pos", u"1\x1f" u"2\x1f" u"-0.5");
|
||||
auto* const roller = entity.AddComponent<RollerComponent>(13951); // loads the level's keys
|
||||
EXPECT_EQ(roller->GetCameraPosition(), NiPoint3(-327.861f, 256.91f, 0.64822f));
|
||||
EXPECT_EQ(roller->GetCameraLookAt(), NiPoint3(1.0f, 2.0f, -0.5f));
|
||||
|
||||
RakNet::BitStream expected;
|
||||
for (const float value : { -327.861f, 256.91f, 0.64822f, 1.0f, 2.0f, -0.5f }) expected.Write(value);
|
||||
expected.Write<uint32_t>(1348);
|
||||
expected.Write0();
|
||||
uint32_t bits{};
|
||||
EXPECT_EQ(Bytes(*roller, true, &bits), (std::vector<uint8_t>{ expected.GetData(), expected.GetData() + expected.GetNumberOfBytesUsed() }));
|
||||
EXPECT_EQ(bits, 225u);
|
||||
// 1.0f little endian, the first look-at number
|
||||
EXPECT_EQ(Bytes(*roller, true)[12 + 3], 0x3f);
|
||||
}
|
||||
@@ -622,6 +622,63 @@ TEST_F(DestroyableTest, PlayerDieDoesNotClaimAClientDeath) {
|
||||
player.SetCharacter(nullptr);
|
||||
}
|
||||
|
||||
// A construction goes to the one client the object came into range of; it must not use up the health change the
|
||||
// players already watching are waiting for (LWODestroyableComponent::Deserialize reads it behind a flag bit).
|
||||
TEST_F(DestroyableTest, AConstructionKeepsThePendingHealthChange) {
|
||||
destroyableComponent->SetHealth(3);
|
||||
RakNet::BitStream construction;
|
||||
destroyableComponent->Serialize(construction, true);
|
||||
|
||||
RakNet::BitStream update;
|
||||
destroyableComponent->Serialize(update, false);
|
||||
bool hasHealth{};
|
||||
uint32_t health{};
|
||||
ASSERT_TRUE(update.Read(hasHealth));
|
||||
ASSERT_TRUE(hasHealth);
|
||||
ASSERT_TRUE(update.Read(health));
|
||||
EXPECT_EQ(health, 3u);
|
||||
|
||||
// Written once
|
||||
RakNet::BitStream again;
|
||||
destroyableComponent->Serialize(again, false);
|
||||
EXPECT_EQ(again.GetNumberOfBitsUsed(), 2u);
|
||||
}
|
||||
|
||||
// LWOCharacterComponent::SendMessage, IsValidPVPTarget: two players with PVP on are enemies, a player is never its own
|
||||
TEST_F(DestroyableTest, APlayerWithPvpIsNotItsOwnEnemy) {
|
||||
auto playerInfo = info;
|
||||
playerInfo.lot = 1;
|
||||
SystemAddress address;
|
||||
address.binaryAddress = 0x0100007f;
|
||||
address.port = 2003;
|
||||
|
||||
Entity player(0x1000000000000001LL, playerInfo);
|
||||
Character character(1, nullptr);
|
||||
player.SetCharacter(&character);
|
||||
character.SetEntity(&player);
|
||||
auto* playerCharacter = player.AddComponent<CharacterComponent>(-1, &character, address);
|
||||
auto* destroyable = player.AddComponent<DestroyableComponent>(-1);
|
||||
|
||||
Entity other(0x1000000000000002LL, playerInfo);
|
||||
Character otherCharacter(2, nullptr);
|
||||
other.SetCharacter(&otherCharacter);
|
||||
otherCharacter.SetEntity(&other);
|
||||
auto* otherCharacterComponent = other.AddComponent<CharacterComponent>(-1, &otherCharacter, address);
|
||||
other.AddComponent<DestroyableComponent>(-1);
|
||||
ASSERT_TRUE(player.IsPlayer());
|
||||
ASSERT_TRUE(other.IsPlayer());
|
||||
|
||||
EXPECT_FALSE(destroyable->IsEnemy(&other));
|
||||
playerCharacter->SetPvpEnabled(true);
|
||||
EXPECT_FALSE(destroyable->IsEnemy(&other));
|
||||
otherCharacterComponent->SetPvpEnabled(true);
|
||||
EXPECT_TRUE(destroyable->IsEnemy(&other));
|
||||
EXPECT_FALSE(destroyable->IsEnemy(&player));
|
||||
|
||||
player.SetCharacter(nullptr);
|
||||
other.SetCharacter(nullptr);
|
||||
}
|
||||
|
||||
// BasicAttack's dir_angle_* are degrees; live's Die carries them as these exact floats.
|
||||
TEST_F(DestroyableTest, DeathDirectionDegreesMatchLiveBits) {
|
||||
const auto bits = [](float value) { uint32_t out; std::memcpy(&out, &value, sizeof(out)); return out; };
|
||||
|
||||
@@ -6,7 +6,10 @@
|
||||
#include "CDClientDatabase.h"
|
||||
#include "CDComponentsRegistryTable.h"
|
||||
#include "CDItemComponentTable.h"
|
||||
#include "CDBehaviorTemplateTable.h"
|
||||
#include "CDObjectSkillsTable.h"
|
||||
#include "CDSkillBehaviorTable.h"
|
||||
#include "BehaviorTemplate.h"
|
||||
#include "Character.h"
|
||||
#include "CharacterComponent.h"
|
||||
#include "EffectsMessages.h"
|
||||
@@ -210,3 +213,41 @@ TEST_F(EquipMessagesTests, UnequippingAndSlotsWithoutAnEffect) {
|
||||
sent = Messages(Capture([&] { rocket->Equip(true); }));
|
||||
EXPECT_EQ(sent, (std::vector<Sent>{ { CHANGE_OBJECT_WORLD_STATE, rocket->GetId(), true, "ATTACHED" } }));
|
||||
}
|
||||
|
||||
// A worn jetpack is found again after a world load, so jetpack mode can be sent again: live sent SetJetPackMode (use,
|
||||
// bypass checks, effect 167) about 100 packets after the player's own construction in 12 of 28 world loads of a player
|
||||
// with a jetpack, and constructed the player in jetpack mode in the other 16.
|
||||
TEST_F(EquipMessagesTests, AWornJetPackIsFoundAfterAWorldLoad) {
|
||||
constexpr LOT JETPACK = 1727; // skill 306, behavior 3569 on equip
|
||||
RegisterLot(JETPACK, "back");
|
||||
CDClientManager::GetEntriesMutable<CDObjectSkillsTable>().push_back({ JETPACK, 306, 1, 0 });
|
||||
CDClientManager::GetEntriesMutable<CDObjectSkillsTable>().push_back({ SWORD, 400, 0, 0 }); // a use skill, not an equip one
|
||||
auto& skills = CDClientManager::GetEntriesMutable<CDSkillBehaviorTable>();
|
||||
CDSkillBehavior jetPackSkill{};
|
||||
jetPackSkill.skillID = 306;
|
||||
jetPackSkill.behaviorID = 3569;
|
||||
skills.insert_or_assign(306, jetPackSkill);
|
||||
CDSkillBehavior hoodSkill{};
|
||||
hoodSkill.skillID = 362;
|
||||
hoodSkill.behaviorID = 4000;
|
||||
skills.insert_or_assign(362, hoodSkill);
|
||||
auto& templates = CDClientManager::GetEntriesMutable<CDBehaviorTemplateTable>();
|
||||
CDBehaviorTemplate jetPackTemplate{};
|
||||
jetPackTemplate.behaviorID = 3569;
|
||||
jetPackTemplate.templateID = static_cast<uint32_t>(BehaviorTemplate::JETPACK);
|
||||
templates.insert_or_assign(3569, jetPackTemplate);
|
||||
CDBehaviorTemplate buffTemplate{};
|
||||
buffTemplate.behaviorID = 4000;
|
||||
buffTemplate.templateID = static_cast<uint32_t>(BehaviorTemplate::BUFF);
|
||||
templates.insert_or_assign(4000, buffTemplate);
|
||||
|
||||
EXPECT_TRUE(inventory->FindEquippedJetPacks().empty());
|
||||
// What a save puts back: the equipped items, without their equip skills cast
|
||||
auto* const hood = Give(HOOD);
|
||||
auto* const jetPack = Give(JETPACK);
|
||||
Give(SWORD);
|
||||
inventory->UpdateSlot("hair", { hood->GetId(), HOOD, 1, 0 });
|
||||
EXPECT_TRUE(inventory->FindEquippedJetPacks().empty());
|
||||
inventory->UpdateSlot("back", { jetPack->GetId(), JETPACK, 1, 1 });
|
||||
EXPECT_EQ(inventory->FindEquippedJetPacks(), std::vector<uint32_t>{ 3569 });
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
// The mount element of a character's save: LWOMountControlComponent::LoadFromSaveData (0x00bf99c0) reads <mnt a>, and
|
||||
// every live save had the element, always as <mnt a="0"/> (450 looked at).
|
||||
#include "GameDependencies.h"
|
||||
|
||||
#include "Entity.h"
|
||||
#include "MountControlComponent.h"
|
||||
#include "PossessorComponent.h"
|
||||
|
||||
#include "tinyxml2.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <string>
|
||||
|
||||
class MountControlComponentTests : public GameDependenciesTest {
|
||||
protected:
|
||||
void SetUp() override { SetUpDependencies(); }
|
||||
void TearDown() override { TearDownDependencies(); }
|
||||
|
||||
static std::string Print(const tinyxml2::XMLDocument& doc) {
|
||||
tinyxml2::XMLPrinter printer(nullptr, true);
|
||||
doc.Print(&printer);
|
||||
return printer.CStr();
|
||||
}
|
||||
};
|
||||
|
||||
// A save from before the element was written gains it, and nothing else changes
|
||||
TEST_F(MountControlComponentTests, OldSaveGainsTheElement) {
|
||||
tinyxml2::XMLDocument doc;
|
||||
ASSERT_EQ(doc.Parse(R"(<obj v="1"><mf hc="1"/><char cc="5"/><dest hm="4"/></obj>)"), tinyxml2::XML_SUCCESS);
|
||||
Entity player(70, info);
|
||||
auto* const mountControl = player.AddComponent<MountControlComponent>(-1);
|
||||
mountControl->LoadFromSaveData(doc);
|
||||
EXPECT_EQ(mountControl->GetSavedMountItemID(), LWOOBJID_EMPTY);
|
||||
mountControl->WriteSaveData(doc);
|
||||
EXPECT_EQ(Print(doc), R"(<obj v="1"><mf hc="1"/><char cc="5"/><dest hm="4"/><mnt a="0"/></obj>)");
|
||||
// Saving again changes nothing
|
||||
mountControl->WriteSaveData(doc);
|
||||
EXPECT_EQ(Print(doc), R"(<obj v="1"><mf hc="1"/><char cc="5"/><dest hm="4"/><mnt a="0"/></obj>)");
|
||||
}
|
||||
|
||||
// Live wrote 0 in every save, so 0 is written while a mount is ridden as well. A save that holds another value is
|
||||
// read without failing and gets 0 at the next save.
|
||||
TEST_F(MountControlComponentTests, ZeroIsWrittenAlsoWhileRiding) {
|
||||
tinyxml2::XMLDocument doc;
|
||||
ASSERT_EQ(doc.Parse(R"(<obj v="1"><mis/><mnt a="1152921510436607007"/><dest hm="4"/></obj>)"), tinyxml2::XML_SUCCESS);
|
||||
Entity player(71, info);
|
||||
auto* const possessor = player.AddComponent<PossessorComponent>(-1);
|
||||
auto* const mountControl = player.AddComponent<MountControlComponent>(-1);
|
||||
mountControl->LoadFromSaveData(doc);
|
||||
EXPECT_EQ(mountControl->GetSavedMountItemID(), 1152921510436607007LL);
|
||||
|
||||
mountControl->WriteSaveData(doc);
|
||||
EXPECT_EQ(Print(doc), R"(<obj v="1"><mis/><mnt a="0"/><dest hm="4"/></obj>)");
|
||||
|
||||
possessor->SetMountItemID(1152921510436607123LL);
|
||||
mountControl->WriteSaveData(doc);
|
||||
EXPECT_EQ(Print(doc), R"(<obj v="1"><mis/><mnt a="0"/><dest hm="4"/></obj>)");
|
||||
}
|
||||
|
||||
// An a that is not a number is not an error: nothing is read and 0 is written
|
||||
TEST_F(MountControlComponentTests, AnUnreadableValueDoesNotFail) {
|
||||
tinyxml2::XMLDocument doc;
|
||||
ASSERT_EQ(doc.Parse(R"(<obj v="1"><mnt a="x"/></obj>)"), tinyxml2::XML_SUCCESS);
|
||||
Entity player(72, info);
|
||||
auto* const mountControl = player.AddComponent<MountControlComponent>(-1);
|
||||
mountControl->LoadFromSaveData(doc);
|
||||
EXPECT_EQ(mountControl->GetSavedMountItemID(), LWOOBJID_EMPTY);
|
||||
mountControl->WriteSaveData(doc);
|
||||
EXPECT_EQ(Print(doc), R"(<obj v="1"><mnt a="0"/></obj>)");
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
// The property guard's mission: LWOPropertyVendorComponent::onCheckUseRequirements (0x00c2e210) lets a player use the
|
||||
// guard only with the level's property_required_mission finished.
|
||||
#include "GameDependencies.h"
|
||||
#include "dGameMessagesTests/GameMessageTestUtils.h"
|
||||
|
||||
#include "CDClientDatabase.h"
|
||||
#include "CDClientManager.h"
|
||||
#include "CDMissionsTable.h"
|
||||
#include "Entity.h"
|
||||
#include "MissionComponent.h"
|
||||
#include "PropertyMessages.h"
|
||||
#include "PropertyVendorComponent.h"
|
||||
|
||||
#include "tinyxml2.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using namespace GameMessageTestUtils;
|
||||
|
||||
namespace {
|
||||
// Mission IDs only these tests use
|
||||
constexpr uint32_t REQUIRED = 993001;
|
||||
constexpr uint32_t REPEATED = 993002;
|
||||
}
|
||||
|
||||
class PropertyVendorComponentTests : public GameDependenciesTest {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
SetUpDependencies();
|
||||
CDClientDatabase::Connect(":memory:"); // MissionComponent counts the achievements
|
||||
CDClientDatabase::ExecuteDML("CREATE TABLE Missions (id INTEGER, isMission INTEGER);");
|
||||
auto& missions = CDClientManager::GetEntriesMutable<CDMissionsTable>();
|
||||
for (const auto id : { REQUIRED, REPEATED }) {
|
||||
CDMissions row{};
|
||||
row.id = id;
|
||||
row.isMission = true;
|
||||
row.repeatable = id == REPEATED;
|
||||
missions.push_back(row);
|
||||
}
|
||||
guard = std::make_unique<Entity>(GUARD, info);
|
||||
vendor = guard->AddComponent<PropertyVendorComponent>(-1);
|
||||
player = std::make_unique<Entity>(PLAYER, info);
|
||||
missions_ = player->AddComponent<MissionComponent>(-1);
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
player.reset();
|
||||
guard.reset();
|
||||
CDClientManager::GetEntriesMutable<CDMissionsTable>().clear();
|
||||
TearDownDependencies();
|
||||
}
|
||||
|
||||
void Load(const std::string& done, const std::string& cur) {
|
||||
tinyxml2::XMLDocument doc;
|
||||
const auto xml = R"(<obj v="1"><mis><done>)" + done + "</done><cur>" + cur + "</cur></mis></obj>";
|
||||
ASSERT_EQ(doc.Parse(xml.c_str()), tinyxml2::XML_SUCCESS);
|
||||
missions_->LoadFromSaveData(doc);
|
||||
}
|
||||
|
||||
static constexpr LWOOBJID GUARD = 0x0000400000112233LL;
|
||||
static constexpr LWOOBJID PLAYER = 0x1000000000000001LL;
|
||||
std::unique_ptr<Entity> guard;
|
||||
std::unique_ptr<Entity> player;
|
||||
PropertyVendorComponent* vendor = nullptr;
|
||||
MissionComponent* missions_ = nullptr;
|
||||
};
|
||||
|
||||
TEST_F(PropertyVendorComponentTests, AGuardWithoutAMissionAsksForNone) {
|
||||
EXPECT_EQ(vendor->GetRequiredMission(), 0u);
|
||||
EXPECT_TRUE(vendor->MayRent(*player));
|
||||
}
|
||||
|
||||
TEST_F(PropertyVendorComponentTests, TheMissionMustBeFinished) {
|
||||
guard->SetVar<uint32_t>(u"property_required_mission", REQUIRED);
|
||||
EXPECT_EQ(vendor->GetRequiredMission(), REQUIRED);
|
||||
EXPECT_FALSE(vendor->MayRent(*player)); // never taken
|
||||
|
||||
Load("", R"(<m id="993001" state="2"/>)");
|
||||
EXPECT_FALSE(vendor->MayRent(*player)); // in progress
|
||||
}
|
||||
|
||||
TEST_F(PropertyVendorComponentTests, AFinishedMissionRents) {
|
||||
guard->SetVar<uint32_t>(u"property_required_mission", REQUIRED);
|
||||
Load(R"(<m id="993001" cct="1" cts="1000"/>)", "");
|
||||
EXPECT_TRUE(vendor->MayRent(*player));
|
||||
}
|
||||
|
||||
// The client's list of finished missions keeps a mission that is being repeated
|
||||
TEST_F(PropertyVendorComponentTests, AFinishedMissionThatIsRepeatedRents) {
|
||||
guard->SetVar<uint32_t>(u"property_required_mission", REPEATED);
|
||||
Load(R"(<m id="993002" cct="1" cts="1000"/>)", R"(<m id="993002" state="10"/>)");
|
||||
EXPECT_TRUE(vendor->MayRent(*player));
|
||||
}
|
||||
|
||||
// A rent request without the mission is answered with code 9, which the client shows as "you failed to rent" and
|
||||
// UGG_PROPRENT_Dont_have_achievement (LWOPropertyVendorComponent::onPropertyRentalResponse 0x00c56d70):
|
||||
// clone u32 0, code u32 9, property u64 0, rent due i64 0
|
||||
TEST_F(PropertyVendorComponentTests, RentingWithoutTheMissionIsRefused) {
|
||||
guard->SetVar<uint32_t>(u"property_required_mission", REQUIRED);
|
||||
const auto packets = Capture([&] { vendor->OnBuyFromVendor(player.get(), true, 0, 1); });
|
||||
ASSERT_EQ(packets.size(), 1u);
|
||||
EXPECT_PACKET_EQ(FromHex(
|
||||
"53 05 00 0c 00 00 00 00 33 22 11 00 00 40 00 00 ee 02 "
|
||||
"00 00 00 00 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00", 336), FromCapture(packets[0]));
|
||||
}
|
||||
|
||||
// With the mission, the request goes on to the property (none in this test: nothing is sent, nothing refused)
|
||||
TEST_F(PropertyVendorComponentTests, RentingWithTheMissionIsNotRefused) {
|
||||
guard->SetVar<uint32_t>(u"property_required_mission", REQUIRED);
|
||||
Load(R"(<m id="993001" cct="1" cts="1000"/>)", "");
|
||||
const auto packets = Capture([&] { vendor->OnBuyFromVendor(player.get(), true, 0, 1); });
|
||||
EXPECT_TRUE(packets.empty());
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
#include "GameDependencies.h"
|
||||
|
||||
#include "CDClientDatabase.h"
|
||||
#include "CDClientManager.h"
|
||||
#include "CDProximityMonitorComponentTable.h"
|
||||
#include "Entity.h"
|
||||
#include "GameMessages.h"
|
||||
#include "ProximityMonitorComponent.h"
|
||||
#include "dpEntity.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
// A ProximityMonitorComponent row lists ProximityTypes ids, as LWOProximityMonitorComponent::LoadDataFromTemplate
|
||||
// (0x00c2dfb0) reads it; the types say their name, radius and where they are loaded.
|
||||
class ProximityMonitorComponentTests : public GameDependenciesTest {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
SetUpDependencies();
|
||||
CDClientDatabase::Connect(":memory:");
|
||||
CDClientDatabase::ExecuteDML("CREATE TABLE ProximityTypes (id INTEGER, Name TEXT, Radius INTEGER, CollisionGroup INTEGER, PassiveChecks INTEGER, IconID INTEGER, LoadOnClient INTEGER, LoadOnServer INTEGER);");
|
||||
CDClientDatabase::ExecuteDML("INSERT INTO ProximityTypes VALUES (2, 'Test Proximity', 10, 1, 1, 1, 1, 0);");
|
||||
CDClientDatabase::ExecuteDML("INSERT INTO ProximityTypes VALUES (3, 'Test Prox Large', 20, 1, 1, 3, 1, 1);");
|
||||
CDClientDatabase::ExecuteDML("INSERT INTO ProximityTypes VALUES (7, 'RocketSign', 30, 1, 1, -1, 1, 0);");
|
||||
CDClientDatabase::ExecuteDML("INSERT INTO ProximityTypes VALUES (8, 'WorldLauncher', 80, 1, 1, 74, 1, 0);");
|
||||
CDClientDatabase::ExecuteDML("INSERT INTO ProximityTypes VALUES (11, 'NoRadius', 0, 1, 1, 0, 1, 1);");
|
||||
auto& rows = CDClientManager::GetEntriesMutable<CDProximityMonitorComponentTable>();
|
||||
rows.push_back({ 3, "2,3", true, true });
|
||||
rows.push_back({ 6, "7,8", true, false });
|
||||
rows.push_back({ 50, "3,11,99", true, true });
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
TearDownDependencies();
|
||||
}
|
||||
};
|
||||
|
||||
// A rocket launch pad's "7,8" are the client's sign and launch proximities, not radii of 7 and 8: nothing for the server
|
||||
TEST_F(ProximityMonitorComponentTests, ClientOnlyProximitiesAreNotMadeOnTheServer) {
|
||||
Entity launchpad(1, info);
|
||||
auto* const proximity = launchpad.AddComponent<ProximityMonitorComponent>(6);
|
||||
proximity->LoadDataFromTemplate();
|
||||
EXPECT_TRUE(proximity->GetProximitiesData().empty());
|
||||
}
|
||||
|
||||
TEST_F(ProximityMonitorComponentTests, ServerProximitiesTakeTheTypesNameAndRadius) {
|
||||
Entity object(2, info);
|
||||
auto* const proximity = object.AddComponent<ProximityMonitorComponent>(3);
|
||||
proximity->LoadDataFromTemplate();
|
||||
const auto& made = proximity->GetProximitiesData();
|
||||
ASSERT_EQ(made.size(), 1u);
|
||||
ASSERT_TRUE(made.contains("Test Prox Large"));
|
||||
|
||||
// A radius of 0 is 30, and a type that does not exist is skipped
|
||||
Entity other(3, info);
|
||||
auto* const otherProximity = other.AddComponent<ProximityMonitorComponent>(50);
|
||||
otherProximity->LoadDataFromTemplate();
|
||||
EXPECT_EQ(otherProximity->GetProximitiesData().size(), 2u);
|
||||
EXPECT_TRUE(otherProximity->GetProximitiesData().contains("NoRadius"));
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "CDRailActivatorComponent.h"
|
||||
#include "Entity.h"
|
||||
#include "MovementMessages.h"
|
||||
#include "ObjectMessages.h"
|
||||
#include "dGameMessagesTests/GameMessageTestUtils.h"
|
||||
#include "RailActivatorComponent.h"
|
||||
|
||||
@@ -82,3 +83,24 @@ TEST_F(RailActivatorComponentTests, InactiveRailIsReportedInactive) {
|
||||
notify.bActive = false;
|
||||
EXPECT_FALSE(RoundTrip(notify).bActive);
|
||||
}
|
||||
|
||||
// A rail that is off is not ridden: LWORailActivatorComponent::msgCheckUseRequirements (0x00c2c5b0) refuses the use, so a
|
||||
// client never asks for it
|
||||
TEST_F(RailActivatorComponentTests, ARailThatIsOffIsNotUsed) {
|
||||
entity->SetVar<bool>(u"rail_activator_active", false);
|
||||
auto* const rail = entity->AddComponent<RailActivatorComponent>(COMPONENT_ID);
|
||||
Entity user(77, info);
|
||||
GameMessages::RequestUse use;
|
||||
GameMessages::RequestUseEvent event(use, user);
|
||||
EXPECT_TRUE(rail->OnRequestUse(event));
|
||||
EXPECT_TRUE(rail->GetEntitiesOnRail().empty());
|
||||
}
|
||||
|
||||
TEST_F(RailActivatorComponentTests, ARailThatIsOnIsUsed) {
|
||||
auto* const rail = entity->AddComponent<RailActivatorComponent>(COMPONENT_ID);
|
||||
Entity user(78, info);
|
||||
GameMessages::RequestUse use;
|
||||
GameMessages::RequestUseEvent event(use, user);
|
||||
EXPECT_TRUE(rail->OnRequestUse(event));
|
||||
EXPECT_EQ(rail->GetEntitiesOnRail(), std::vector<LWOOBJID>{ 78 });
|
||||
}
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
#include "BouncerComponent.h"
|
||||
#include "BuffComponent.h"
|
||||
#include "CharacterComponent.h"
|
||||
#include "ChestComponent.h"
|
||||
#include "ChoiceBuildComponent.h"
|
||||
#include "RollerComponent.h"
|
||||
#include "CollectibleComponent.h"
|
||||
#include "ControllablePhysicsComponent.h"
|
||||
#include "DestroyableComponent.h"
|
||||
@@ -561,3 +564,102 @@ TEST_F(ReplicaComponentOrderTest, EveryListedComponent) {
|
||||
entity.AddComponent<MiniGameControlComponent>(-1);
|
||||
});
|
||||
}
|
||||
|
||||
namespace {
|
||||
// The bits of `expected` are the first bits of `actual`
|
||||
void ExpectStartsWith(RakNet::BitStream& actual, RakNet::BitStream& expected) {
|
||||
ASSERT_GE(actual.GetNumberOfBitsUsed(), expected.GetNumberOfBitsUsed());
|
||||
actual.ResetReadPointer();
|
||||
expected.ResetReadPointer();
|
||||
for (uint32_t i = 0; i < expected.GetNumberOfBitsUsed(); i++) {
|
||||
ASSERT_EQ(actual.ReadBit(), expected.ReadBit()) << "bit " << i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// LWOGameObject::Deserialize (0x00f99690) reads the components in the order ObjectLoader2::FillComponentOrder
|
||||
// (0x0101f8e0) lists them: a chest (22) after its phantom physics (40) and before its render component (2).
|
||||
// LOT 2196: phantom physics, chest, render.
|
||||
TEST_F(ReplicaComponentOrderTest, ChestIsWrittenBeforeRender) {
|
||||
Entity entity(15, info);
|
||||
auto* const physics = entity.AddComponent<PhantomPhysicsComponent>(-1);
|
||||
auto* const chest = entity.AddComponent<ChestComponent>(0);
|
||||
chest->SetPlayerID(0x1000000000000001LL);
|
||||
chest->SetLootOfferCount(3);
|
||||
auto* const render = entity.AddComponent<RenderComponent>(-1);
|
||||
|
||||
RakNet::BitStream actual;
|
||||
entity.WriteComponents(actual, eReplicaPacketType::CONSTRUCTION);
|
||||
|
||||
Entity copy(15, info);
|
||||
RakNet::BitStream expected;
|
||||
copy.AddComponent<PhantomPhysicsComponent>(-1)->Serialize(expected, true);
|
||||
expected.Write<LWOOBJID>(0x1000000000000001LL);
|
||||
expected.Write<uint32_t>(3);
|
||||
copy.AddComponent<RenderComponent>(-1)->Serialize(expected, true);
|
||||
ExpectStartsWith(actual, expected);
|
||||
static_cast<void>(physics);
|
||||
static_cast<void>(render);
|
||||
}
|
||||
|
||||
// A choice build (52) is read after physics, destroyable and script and before render. LOT 6414: simple physics,
|
||||
// destroyable, choice build, render; LOT 5668 has a script in place of the destroyable.
|
||||
TEST_F(ReplicaComponentOrderTest, ChoiceBuildIsWrittenAfterScriptAndBeforeRender) {
|
||||
const auto build = [](Entity& entity) {
|
||||
entity.AddComponent<SimplePhysicsComponent>(-1);
|
||||
entity.AddComponent<BuffComponent>(-1);
|
||||
entity.AddComponent<DestroyableComponent>(-1)->SetMaxHealth(1.0f);
|
||||
entity.AddComponent<ScriptComponent>(-1, "", true);
|
||||
entity.AddComponent<ChoiceBuildComponent>(1);
|
||||
entity.AddComponent<RenderComponent>(-1);
|
||||
};
|
||||
Entity entity(15, info);
|
||||
build(entity);
|
||||
RakNet::BitStream actual;
|
||||
entity.WriteComponents(actual, eReplicaPacketType::CONSTRUCTION);
|
||||
|
||||
Entity copy(15, info);
|
||||
build(copy);
|
||||
RakNet::BitStream expected;
|
||||
copy.GetComponent<SimplePhysicsComponent>()->Serialize(expected, true);
|
||||
copy.GetComponent<BuffComponent>()->Serialize(expected, true);
|
||||
copy.GetComponent<DestroyableComponent>()->Serialize(expected, true);
|
||||
copy.GetComponent<ScriptComponent>()->Serialize(expected, true);
|
||||
expected.Write1();
|
||||
expected.Write<uint32_t>(0); // waiting
|
||||
expected.Write<LWOOBJID>(0); // nothing built
|
||||
expected.Write<LWOOBJID>(0); // nobody using it
|
||||
copy.GetComponent<RenderComponent>()->Serialize(expected, true);
|
||||
ExpectStartsWith(actual, expected);
|
||||
}
|
||||
|
||||
// A roller (105) is read after script, skill and inventory and before the moving platform (25) and render.
|
||||
// LOT 2714: simple physics, roller, moving platform, render; LOT 13951 adds script, skill and inventory.
|
||||
TEST_F(ReplicaComponentOrderTest, RollerIsWrittenBeforeTheMovingPlatform) {
|
||||
const auto build = [](Entity& entity) {
|
||||
entity.AddComponent<SimplePhysicsComponent>(-1);
|
||||
entity.AddComponent<ScriptComponent>(-1, "", true);
|
||||
entity.AddComponent<SkillComponent>(-1);
|
||||
entity.AddComponent<RollerComponent>(13951);
|
||||
entity.AddComponent<MovingPlatformComponent>(-1, "");
|
||||
entity.AddComponent<RenderComponent>(-1);
|
||||
};
|
||||
for (const auto packetType : { eReplicaPacketType::CONSTRUCTION, eReplicaPacketType::SERIALIZATION }) {
|
||||
const bool construction = packetType == eReplicaPacketType::CONSTRUCTION;
|
||||
Entity entity(15, info);
|
||||
build(entity);
|
||||
RakNet::BitStream actual;
|
||||
entity.WriteComponents(actual, packetType);
|
||||
|
||||
Entity copy(15, info);
|
||||
build(copy);
|
||||
RakNet::BitStream expected;
|
||||
copy.GetComponent<SimplePhysicsComponent>()->Serialize(expected, construction);
|
||||
copy.GetComponent<ScriptComponent>()->Serialize(expected, construction);
|
||||
copy.GetComponent<SkillComponent>()->Serialize(expected, construction);
|
||||
copy.GetComponent<RollerComponent>()->Serialize(expected, construction);
|
||||
copy.GetComponent<MovingPlatformComponent>()->Serialize(expected, construction);
|
||||
copy.GetComponent<RenderComponent>()->Serialize(expected, construction);
|
||||
ExpectStartsWith(actual, expected);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,11 +18,17 @@
|
||||
#include "Entity.h"
|
||||
#include "InventoryComponent.h"
|
||||
#include "ItemComponent.h"
|
||||
#include "LevelProgressionComponent.h"
|
||||
#include "LUPExhibitComponent.h"
|
||||
#include "PlayerForcedMovementComponent.h"
|
||||
#include "ScriptedActivityComponent.h"
|
||||
#include "Item.h"
|
||||
#include "ModelComponent.h"
|
||||
#include "MovingPlatformComponent.h"
|
||||
#include "PhantomPhysicsComponent.h"
|
||||
#include "SimplePhysicsComponent.h"
|
||||
#include "User.h"
|
||||
#include "eGameActivity.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
#include "eReplicaPacketType.h"
|
||||
|
||||
@@ -130,6 +136,270 @@ TEST_F(ReplicaConstructionTest, CharacterConstructionAlwaysWritesGmActivityAndSo
|
||||
player.SetCharacter(nullptr);
|
||||
}
|
||||
|
||||
// A current-activity or PVP change is written once, as a guild change is: LWOCharacterComponent::Deserialize reads each
|
||||
// block behind its own flag bit.
|
||||
TEST_F(ReplicaConstructionTest, CharacterActivityAndPvpChangesAreWrittenOnce) {
|
||||
User user(UNASSIGNED_SYSTEM_ADDRESS, "tester", "key");
|
||||
Character character(1, &user);
|
||||
info.lot = 1;
|
||||
Entity player(1152921506064087005, info);
|
||||
player.SetCharacter(&character);
|
||||
character.SetEntity(&player);
|
||||
auto* const component = player.AddComponent<CharacterComponent>(-1, &character, UNASSIGNED_SYSTEM_ADDRESS);
|
||||
|
||||
component->SetCurrentActivity(eGameActivity::QUICKBUILDING);
|
||||
component->SetPvpEnabled(true);
|
||||
RakNet::BitStream serialization;
|
||||
component->Serialize(serialization, false);
|
||||
RakNet::BitStream expected;
|
||||
expected.Write1(); // gm_pvp_info
|
||||
expected.Write1(); // pvp_enabled
|
||||
expected.Write0(); // is_gm
|
||||
expected.Write<uint8_t>(0); // gm_level
|
||||
expected.Write0(); // editor_enabled
|
||||
expected.Write<uint8_t>(0); // editor_level
|
||||
expected.Write1(); // current_activity
|
||||
expected.Write(eGameActivity::QUICKBUILDING);
|
||||
expected.Write0(); // social_info
|
||||
ExpectSameBits(serialization, expected);
|
||||
|
||||
RakNet::BitStream again;
|
||||
component->Serialize(again, false);
|
||||
EXPECT_EQ(again.GetNumberOfBitsUsed(), 3u);
|
||||
|
||||
// A construction in between (another player coming into range) doesn't swallow a pending change
|
||||
component->SetCurrentActivity(eGameActivity::NONE);
|
||||
RakNet::BitStream construction;
|
||||
component->Serialize(construction, true);
|
||||
RakNet::BitStream after;
|
||||
component->Serialize(after, false);
|
||||
EXPECT_EQ(after.GetNumberOfBitsUsed(), 3u + 32u);
|
||||
|
||||
player.SetCharacter(nullptr);
|
||||
}
|
||||
|
||||
// A player in jetpack mode is constructed in it: live player constructions carried the jetpack block (effect 167,
|
||||
// flying 0, bypass checks 1) and a 0 after the pickup radius. LWOControllablePhysComponent::Deserialize reads both.
|
||||
TEST_F(ReplicaConstructionTest, ControllablePhysicsConstructionCarriesJetPackMode) {
|
||||
Entity player(1152921506064087006, info);
|
||||
auto* const physics = player.AddComponent<ControllablePhysicsComponent>(-1);
|
||||
|
||||
const auto construct = [physics]() {
|
||||
RakNet::BitStream construction;
|
||||
physics->Serialize(construction, true);
|
||||
return Bits(construction);
|
||||
};
|
||||
const auto bits = [](const RakNet::BitStream& stream) { return Bits(stream); };
|
||||
|
||||
// No jetpack: one 0 bit, then the stun immunities
|
||||
const auto plain = construct();
|
||||
EXPECT_EQ(plain.substr(0, 2), "01");
|
||||
|
||||
physics->SetJetPackMode(true, 167, true);
|
||||
RakNet::BitStream head;
|
||||
head.Write1(); // jetpack
|
||||
head.Write<int32_t>(167); // effect
|
||||
head.Write0(); // flying
|
||||
head.Write1(); // bypass checks
|
||||
head.Write1(); // stun immunities
|
||||
const auto jetpack = construct();
|
||||
EXPECT_EQ(jetpack.substr(0, head.GetNumberOfBitsUsed()), bits(head));
|
||||
// After the 7 immunity counts: no cheats, then the pickup radius and a 0 (not the jetpack flag)
|
||||
const size_t afterImmunities = head.GetNumberOfBitsUsed() + 7 * 32;
|
||||
EXPECT_EQ(jetpack.substr(afterImmunities, 2), "01");
|
||||
EXPECT_EQ(jetpack[afterImmunities + 2 + 32], '0');
|
||||
// The rest is what a player without a jetpack gets
|
||||
EXPECT_EQ(jetpack.substr(head.GetNumberOfBitsUsed()), plain.substr(2));
|
||||
|
||||
physics->SetJetPackMode(false, -1, false);
|
||||
EXPECT_EQ(construct(), plain);
|
||||
}
|
||||
|
||||
namespace {
|
||||
struct VolumeEffect {
|
||||
uint32_t type{};
|
||||
float amount{};
|
||||
bool hasDistance{};
|
||||
float min{};
|
||||
float max{};
|
||||
bool isDirectional{};
|
||||
NiPoint3 direction{};
|
||||
};
|
||||
|
||||
// A phantom volume looks its LOT up in the registry when it is made
|
||||
void ConnectRegistry() {
|
||||
if (CDClientDatabase::isConnected) return;
|
||||
CDClientDatabase::Connect(":memory:");
|
||||
CDClientDatabase::ExecuteDML("CREATE TABLE ComponentsRegistry (id INTEGER, component_type INTEGER, component_id INTEGER);");
|
||||
}
|
||||
|
||||
// The effect block of a phantom physics update made from a trigger's SetPhysicsVolumeEffect arguments
|
||||
VolumeEffect ReadVolumeEffect(Entity& volume, const std::vector<std::string>& args) {
|
||||
auto* const phantom = volume.AddComponent<PhantomPhysicsComponent>(-1);
|
||||
phantom->SetVolumeEffect(args);
|
||||
RakNet::BitStream stream;
|
||||
phantom->Serialize(stream, false);
|
||||
|
||||
VolumeEffect effect;
|
||||
bool flag{};
|
||||
stream.Read(flag);
|
||||
if (flag) stream.IgnoreBits(7 * 32); // position and rotation
|
||||
stream.Read(flag);
|
||||
EXPECT_TRUE(flag); // the effect block
|
||||
stream.Read(flag);
|
||||
EXPECT_TRUE(flag); // active
|
||||
stream.Read(effect.type);
|
||||
stream.Read(effect.amount);
|
||||
stream.Read(effect.hasDistance);
|
||||
if (effect.hasDistance) {
|
||||
stream.Read(effect.min);
|
||||
stream.Read(effect.max);
|
||||
}
|
||||
stream.Read(effect.isDirectional);
|
||||
if (effect.isDirectional) {
|
||||
stream.Read(effect.direction.x);
|
||||
stream.Read(effect.direction.y);
|
||||
stream.Read(effect.direction.z);
|
||||
}
|
||||
EXPECT_EQ(stream.GetNumberOfUnreadBits(), 0u);
|
||||
return effect;
|
||||
}
|
||||
}
|
||||
|
||||
// Trigger volume effects as live sent them (phantom physics constructions in the live captures; the client reads
|
||||
// them in LWOPhantomPhysicsComponent::Deserialize): the direction has the amount as its length, the distances go out
|
||||
// for "true" only and as 1 and the max, and a zero direction is no direction.
|
||||
TEST_F(ReplicaConstructionTest, PhantomPhysicsVolumeEffectsAsLive) {
|
||||
ConnectRegistry();
|
||||
Entity pushWithDistance(1001, info);
|
||||
auto effect = ReadVolumeEffect(pushWithDistance, { "Push", "50", "0.91", "-0.34", "-0.22", "true", "20", "50" });
|
||||
EXPECT_EQ(effect.type, 0u);
|
||||
EXPECT_EQ(effect.amount, 50.0f);
|
||||
EXPECT_TRUE(effect.hasDistance);
|
||||
EXPECT_EQ(effect.min, 1.0f);
|
||||
EXPECT_EQ(effect.max, 50.0f);
|
||||
EXPECT_TRUE(effect.isDirectional);
|
||||
EXPECT_NEAR(effect.direction.x, 45.68f, 0.01f);
|
||||
EXPECT_NEAR(effect.direction.y, -17.07f, 0.01f);
|
||||
EXPECT_NEAR(effect.direction.z, -11.04f, 0.01f);
|
||||
|
||||
Entity pushFar(1002, info);
|
||||
effect = ReadVolumeEffect(pushFar, { "Push", "200", "1", "0", "0", "true", "150", "175" });
|
||||
EXPECT_TRUE(effect.hasDistance);
|
||||
EXPECT_EQ(effect.min, 1.0f);
|
||||
EXPECT_EQ(effect.max, 175.0f);
|
||||
EXPECT_EQ(effect.direction, NiPoint3(200.0f, 0.0f, 0.0f));
|
||||
|
||||
// "1" is not "true": no distances
|
||||
Entity updraft(1003, info);
|
||||
effect = ReadVolumeEffect(updraft, { "Push", "40.0", "0", "1", "0", "1", "20", "50" });
|
||||
EXPECT_EQ(effect.amount, 40.0f);
|
||||
EXPECT_FALSE(effect.hasDistance);
|
||||
EXPECT_TRUE(effect.isDirectional);
|
||||
EXPECT_EQ(effect.direction, NiPoint3(0.0f, 40.0f, 0.0f));
|
||||
|
||||
Entity repulse(1004, info);
|
||||
effect = ReadVolumeEffect(repulse, { "Repulse", "150", "0", "0", "0", "true", "25", "100" });
|
||||
EXPECT_EQ(effect.type, 2u);
|
||||
EXPECT_EQ(effect.amount, 150.0f);
|
||||
EXPECT_TRUE(effect.hasDistance);
|
||||
EXPECT_EQ(effect.min, 1.0f);
|
||||
EXPECT_EQ(effect.max, 100.0f);
|
||||
EXPECT_FALSE(effect.isDirectional);
|
||||
|
||||
Entity slanted(1005, info);
|
||||
effect = ReadVolumeEffect(slanted, { "Push", " 35", " .79", " 0", " .61" });
|
||||
EXPECT_FALSE(effect.hasDistance);
|
||||
EXPECT_NEAR(effect.direction.x, 27.70f, 0.01f);
|
||||
EXPECT_NEAR(effect.direction.z, 21.39f, 0.01f);
|
||||
|
||||
Entity friction(1006, info);
|
||||
effect = ReadVolumeEffect(friction, { "Friction", "0" });
|
||||
EXPECT_EQ(effect.type, 4u);
|
||||
EXPECT_FALSE(effect.hasDistance);
|
||||
EXPECT_FALSE(effect.isDirectional);
|
||||
|
||||
// The amount is a float all the way: LWOPhantomPhysicsComponent::Deserialize (0x00c34db0) reads 32 bits into a
|
||||
// float, and trigger commands are run by the server only, so a fraction is kept as the zone file has it
|
||||
Entity lowFriction(1007, info);
|
||||
effect = ReadVolumeEffect(lowFriction, { "Friction", "0.1" });
|
||||
EXPECT_EQ(effect.type, 4u);
|
||||
EXPECT_EQ(effect.amount, 0.1f);
|
||||
}
|
||||
|
||||
// A construction (the volume coming into one player's range) doesn't use up an effect change the players already
|
||||
// watching it still have to get.
|
||||
TEST_F(ReplicaConstructionTest, PhantomPhysicsConstructionKeepsThePendingEffect) {
|
||||
ConnectRegistry();
|
||||
Entity volume(1007, info);
|
||||
auto* const phantom = volume.AddComponent<PhantomPhysicsComponent>(-1);
|
||||
RakNet::BitStream first;
|
||||
phantom->Serialize(first, false);
|
||||
const auto idle = first.GetNumberOfBitsUsed();
|
||||
|
||||
phantom->SetVolumeEffect({ "Friction", "0" });
|
||||
RakNet::BitStream construction;
|
||||
phantom->Serialize(construction, true);
|
||||
RakNet::BitStream update;
|
||||
phantom->Serialize(update, false);
|
||||
EXPECT_EQ(update.GetNumberOfBitsUsed(), 2u + 1 + 32 + 32 + 1 + 1);
|
||||
RakNet::BitStream again;
|
||||
phantom->Serialize(again, false);
|
||||
EXPECT_EQ(again.GetNumberOfBitsUsed(), 2u);
|
||||
EXPECT_LE(again.GetNumberOfBitsUsed(), idle);
|
||||
}
|
||||
|
||||
// A construction goes to the one client the object came into range of. It must not use up a change the clients
|
||||
// already watching are still waiting for (the level, rail and billboard flags are each read behind a flag bit).
|
||||
TEST_F(ReplicaConstructionTest, AConstructionKeepsPendingLevelAndForcedMovementChanges) {
|
||||
Entity player(1152921506064087008, info);
|
||||
auto* const level = player.AddComponent<LevelProgressionComponent>(-1);
|
||||
auto* const forcedMovement = player.AddComponent<PlayerForcedMovementComponent>(-1);
|
||||
|
||||
level->SetLevel(7);
|
||||
forcedMovement->SetPlayerOnRail(true);
|
||||
RakNet::BitStream construction;
|
||||
level->Serialize(construction, true);
|
||||
forcedMovement->Serialize(construction, true);
|
||||
|
||||
RakNet::BitStream update;
|
||||
level->Serialize(update, false);
|
||||
forcedMovement->Serialize(update, false);
|
||||
RakNet::BitStream expected;
|
||||
expected.Write1();
|
||||
expected.Write<uint32_t>(7);
|
||||
expected.Write1();
|
||||
expected.Write1(); // on rail
|
||||
expected.Write0(); // show billboard
|
||||
ExpectSameBits(update, expected);
|
||||
|
||||
RakNet::BitStream again;
|
||||
level->Serialize(again, false);
|
||||
forcedMovement->Serialize(again, false);
|
||||
EXPECT_EQ(again.GetNumberOfBitsUsed(), 2u);
|
||||
}
|
||||
|
||||
// The client learns the exhibit's LOT only from the component's block (LWOLUPExhibitComponent::Deserialize: a flag
|
||||
// and the LOT). DLU wrote it on a construction only while it was dirty, so a player who came into range after the
|
||||
// first update saw no exhibit until the next one was picked.
|
||||
TEST_F(ReplicaConstructionTest, LupExhibitConstructionAlwaysCarriesTheExhibit) {
|
||||
Entity exhibit(1009, info);
|
||||
auto* const component = exhibit.AddComponent<LUPExhibitComponent>(-1);
|
||||
|
||||
RakNet::BitStream update;
|
||||
component->Serialize(update, false);
|
||||
RakNet::BitStream idle;
|
||||
component->Serialize(idle, false);
|
||||
EXPECT_EQ(idle.GetNumberOfBitsUsed(), 1u);
|
||||
|
||||
RakNet::BitStream construction;
|
||||
component->Serialize(construction, true);
|
||||
RakNet::BitStream expected;
|
||||
expected.Write1();
|
||||
expected.Write<LOT>(11121);
|
||||
ExpectSameBits(construction, expected);
|
||||
}
|
||||
|
||||
// A guild change (docs/Guilds.md) is written once: the client reads guild id, a u8 length and 16-bit characters, and
|
||||
// redraws the name billboard every time it reads a name.
|
||||
TEST_F(ReplicaConstructionTest, CharacterGuildChangeIsWrittenOnce) {
|
||||
@@ -170,6 +440,81 @@ TEST_F(ReplicaConstructionTest, CharacterGuildChangeIsWrittenOnce) {
|
||||
player.SetCharacter(nullptr);
|
||||
}
|
||||
|
||||
// A client that comes into range of an activity is told its players, whether or not they changed since the last
|
||||
// update. Live finish line constructions (LOT 4967): flag 1 and the count in 40 of 40, one of them with a player.
|
||||
TEST_F(ReplicaConstructionTest, AnActivityConstructionAlwaysCarriesItsPlayers) {
|
||||
ConnectRegistry();
|
||||
Entity activity(1010, info);
|
||||
auto* const component = activity.AddComponent<ScriptedActivityComponent>(-1);
|
||||
const LWOOBJID player = 1152921506064087006;
|
||||
component->SetActivityValue(player, 1, 42.0f);
|
||||
|
||||
RakNet::BitStream update;
|
||||
component->Serialize(update, false);
|
||||
RakNet::BitStream idle;
|
||||
component->Serialize(idle, false);
|
||||
EXPECT_EQ(Bits(idle), "0"); // nothing changed since
|
||||
|
||||
RakNet::BitStream construction;
|
||||
component->Serialize(construction, true);
|
||||
EXPECT_EQ(Bits(construction), Bits(update));
|
||||
EXPECT_TRUE(construction.ReadBit());
|
||||
uint32_t count{};
|
||||
ASSERT_TRUE(construction.Read(count));
|
||||
EXPECT_EQ(count, 1u);
|
||||
LWOOBJID id{};
|
||||
ASSERT_TRUE(construction.Read(id));
|
||||
EXPECT_EQ(id, player);
|
||||
for (uint32_t i = 0; i < 10; i++) {
|
||||
float value{};
|
||||
ASSERT_TRUE(construction.Read(value));
|
||||
EXPECT_EQ(value, i == 1 ? 42.0f : 0.0f);
|
||||
}
|
||||
EXPECT_EQ(construction.GetNumberOfUnreadBits(), 0u);
|
||||
|
||||
// Without players: the flag and a count of 0
|
||||
component->RemoveActivityPlayerData(player);
|
||||
RakNet::BitStream cleared;
|
||||
component->Serialize(cleared, false);
|
||||
RakNet::BitStream empty;
|
||||
component->Serialize(empty, true);
|
||||
EXPECT_EQ(Bits(empty), "1" + std::string(32, '0'));
|
||||
}
|
||||
|
||||
// Run speed modifiers stack as in LWOControllablePhysComponent::msgAddRunspeedModifier (0x00be0af0) and
|
||||
// msgRemoveRunSpeedModifier (0x00be0720): the lowest slow wins, otherwise the highest boost; 500 and anything over 1000
|
||||
// count for nothing
|
||||
TEST_F(ReplicaConstructionTest, RunSpeedModifiersStackAsTheClientDoes) {
|
||||
Entity entity(15, info);
|
||||
auto* const physics = entity.AddComponent<ControllablePhysicsComponent>(-1);
|
||||
EXPECT_FLOAT_EQ(physics->GetSpeedMultiplier(), 1.0f);
|
||||
|
||||
physics->AddSpeedboost(750.0f);
|
||||
EXPECT_FLOAT_EQ(physics->GetSpeedMultiplier(), 1.5f);
|
||||
physics->AddSpeedboost(550.0f); // a smaller boost applied later does not replace the bigger one
|
||||
EXPECT_FLOAT_EQ(physics->GetSpeedMultiplier(), 1.5f);
|
||||
physics->AddSpeedboost(250.0f); // any slow beats every boost
|
||||
EXPECT_FLOAT_EQ(physics->GetSpeedMultiplier(), 0.5f);
|
||||
physics->AddSpeedboost(133.0f);
|
||||
EXPECT_FLOAT_EQ(physics->GetSpeedMultiplier(), 133.0f / 500.0f);
|
||||
physics->AddSpeedboost(350.0f);
|
||||
EXPECT_FLOAT_EQ(physics->GetSpeedMultiplier(), 133.0f / 500.0f);
|
||||
physics->AddSpeedboost(1500.0f);
|
||||
physics->AddSpeedboost(500.0f);
|
||||
EXPECT_FLOAT_EQ(physics->GetSpeedMultiplier(), 133.0f / 500.0f);
|
||||
|
||||
physics->RemoveSpeedboost(133.0f);
|
||||
EXPECT_FLOAT_EQ(physics->GetSpeedMultiplier(), 0.5f);
|
||||
physics->RemoveSpeedboost(250.0f);
|
||||
EXPECT_FLOAT_EQ(physics->GetSpeedMultiplier(), 0.7f);
|
||||
physics->RemoveSpeedboost(350.0f);
|
||||
EXPECT_FLOAT_EQ(physics->GetSpeedMultiplier(), 1.5f);
|
||||
physics->RemoveSpeedboost(750.0f);
|
||||
EXPECT_FLOAT_EQ(physics->GetSpeedMultiplier(), 1.1f);
|
||||
physics->RemoveSpeedboost(550.0f);
|
||||
EXPECT_FLOAT_EQ(physics->GetSpeedMultiplier(), 1.0f); // 1500 and 500 are left and count for nothing
|
||||
}
|
||||
|
||||
// Live wrote the cheat block (gravity scale, speed multiplier) on construction only when one of them was changed: 216
|
||||
// of 20,617 controllable-physics constructions had it (players at run speed 1.05, enemies with gravity 0), never 1/1.
|
||||
TEST_F(ReplicaConstructionTest, ControllablePhysicsConstructionWritesCheatsOnlyWhenChanged) {
|
||||
@@ -438,6 +783,11 @@ TEST_F(InventoryConstructionTest, NpcItemsLikeLive) {
|
||||
coleExpected.Write<uint32_t>(0);
|
||||
ExpectSameBits(coleConstruction, coleExpected);
|
||||
|
||||
// The equipment put on before the construction still goes to the clients already watching, once
|
||||
RakNet::BitStream pending;
|
||||
coleInventory->Serialize(pending, false);
|
||||
EXPECT_GT(pending.GetNumberOfBitsUsed(), 2u);
|
||||
|
||||
// A serialization with nothing changed writes neither list
|
||||
RakNet::BitStream serialization;
|
||||
coleInventory->Serialize(serialization, false);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "GameDependencies.h"
|
||||
#include "dGameMessagesTests/GameMessageTestUtils.h"
|
||||
|
||||
#include "CDClientDatabase.h"
|
||||
#include "Entity.h"
|
||||
#include "ObjectMessages.h"
|
||||
#include "RocketLaunchpadControlComponent.h"
|
||||
|
||||
@@ -49,3 +51,107 @@ TEST_F(RocketLaunchTests, RocketEquippedIsBroadcast) {
|
||||
ASSERT_EQ(sent.size(), 1u);
|
||||
EXPECT_TRUE(sent[0].broadcast);
|
||||
}
|
||||
|
||||
// A pad's row can ask for a GM level (the AG test pad: 9); LWORocketLaunchComponentCommon::msgFireEventClientSide
|
||||
// (0x00cb78b0) does not launch a player under it
|
||||
TEST_F(RocketLaunchTests, APadWithAGmLevelLaunchesOnlyThoseAtIt) {
|
||||
CDClientDatabase::Connect(":memory:");
|
||||
CDClientDatabase::ExecuteDML("CREATE TABLE RocketLaunchpadControlComponent (id INTEGER, targetZone INTEGER, defaultZoneID INTEGER, targetScene TEXT, gmLevel INTEGER, useLaunchPrecondition INTEGER, launchPrecondition TEXT, useAltLandingPrecondition INTEGER, altLandingPrecondition TEXT, altLandingSpawnPointName TEXT);");
|
||||
CDClientDatabase::ExecuteDML("INSERT INTO RocketLaunchpadControlComponent VALUES (1, 1100, 0, 'AGLaunch', 9, 0, '', 0, '', '');");
|
||||
CDClientDatabase::ExecuteDML("INSERT INTO RocketLaunchpadControlComponent VALUES (2, 1200, 0, 'NS_NT', 0, 0, '47', 0, '', '');");
|
||||
|
||||
Entity gmPad(PAD, info);
|
||||
auto* const gmOnly = gmPad.AddComponent<RocketLaunchpadControlComponent>(1);
|
||||
gmOnly->LoadDataFromTemplate();
|
||||
Entity openPad(PAD + 1, info);
|
||||
auto* const open = openPad.AddComponent<RocketLaunchpadControlComponent>(2);
|
||||
open->LoadDataFromTemplate();
|
||||
|
||||
Entity player(PLAYER, info);
|
||||
EXPECT_FALSE(gmOnly->MayLaunch(player));
|
||||
EXPECT_TRUE(open->MayLaunch(player)); // its precondition is not in use
|
||||
player.SetGMLevel(eGameMasterLevel::OPERATOR);
|
||||
EXPECT_TRUE(gmOnly->MayLaunch(player));
|
||||
}
|
||||
|
||||
namespace {
|
||||
void MakePadTables() {
|
||||
CDClientDatabase::Connect(":memory:");
|
||||
CDClientDatabase::ExecuteDML("CREATE TABLE RocketLaunchpadControlComponent (id INTEGER, targetZone INTEGER, defaultZoneID INTEGER, targetScene TEXT, gmLevel INTEGER, useLaunchPrecondition INTEGER, launchPrecondition TEXT, useAltLandingPrecondition INTEGER, altLandingPrecondition TEXT, altLandingSpawnPointName TEXT);");
|
||||
// Row 3 is the Venture Explorer pad's (LOT 14214): no precondition in the table
|
||||
// No precondition is known: one that is asked for fails for a player without components
|
||||
CDClientDatabase::ExecuteDML("CREATE TABLE Preconditions (id INTEGER, type INTEGER, targetLOT TEXT, targetGroup TEXT, targetCount INTEGER, iconID INTEGER, localize INTEGER, validContexts INTEGER);");
|
||||
CDClientDatabase::ExecuteDML("INSERT INTO RocketLaunchpadControlComponent VALUES (3, 1100, 0, 'AGLanding', 0, 0, NULL, 0, NULL, NULL);");
|
||||
// Row 16: a Nimbus Station pad with the precondition in the table
|
||||
CDClientDatabase::ExecuteDML("INSERT INTO RocketLaunchpadControlComponent VALUES (16, 1300, 0, 'GFLanding', 0, 1, '0', 0, '', '');");
|
||||
}
|
||||
}
|
||||
|
||||
// A pad whose level sets rocketLaunchUseDBDefaults to false is ruled by the level's keys, not its row:
|
||||
// LWORocketLaunchComponentCommon::LoadConfigData (0x00c55150) reads them and the row is only loaded while the key is
|
||||
// true (0x00c12ea0). The Venture Explorer's pads: the row has no precondition, the level has
|
||||
// "237;8;127|128;6|55;107;282" with rocketUseLaunchPrecondition.
|
||||
TEST_F(RocketLaunchTests, APadThatDoesNotUseTheTableIsRuledByItsLevel) {
|
||||
MakePadTables();
|
||||
Entity pad(PAD, info);
|
||||
pad.SetVar<bool>(u"rocketLaunchUseDBDefaults", false);
|
||||
pad.SetVar<int32_t>(u"targetZone", 1100);
|
||||
pad.SetVar<std::u16string>(u"targetScene", u"AGLanding");
|
||||
pad.SetVar<int32_t>(u"GMLevel", 0);
|
||||
pad.SetVar<bool>(u"rocketUseLaunchPrecondition", true);
|
||||
pad.SetVar<std::u16string>(u"rocketLaunchPreCondition", u"0"); // an empty precondition table: nobody passes "0"
|
||||
// AddComponent loads the row, then the level's keys
|
||||
auto* const component = pad.AddComponent<RocketLaunchpadControlComponent>(3);
|
||||
|
||||
Entity player(PLAYER, info);
|
||||
// The row alone asks for nothing
|
||||
Entity rowPad(PAD + 2, info);
|
||||
EXPECT_TRUE(rowPad.AddComponent<RocketLaunchpadControlComponent>(3)->MayLaunch(player));
|
||||
EXPECT_EQ(component->GetTargetZone(), 1100);
|
||||
EXPECT_EQ(component->GetTargetScene(), "AGLanding");
|
||||
EXPECT_FALSE(component->MayLaunch(player));
|
||||
|
||||
// The level's GM level counts as well (the test pads to the Gnarled Forest and Forbidden Valley properties: 9)
|
||||
Entity gmPad(PAD + 1, info);
|
||||
gmPad.SetVar<bool>(u"rocketLaunchUseDBDefaults", false);
|
||||
gmPad.SetVar<int32_t>(u"targetZone", 1100);
|
||||
gmPad.SetVar<int32_t>(u"GMLevel", 9);
|
||||
auto* const gmOnly = gmPad.AddComponent<RocketLaunchpadControlComponent>(3);
|
||||
EXPECT_FALSE(gmOnly->MayLaunch(player));
|
||||
player.SetGMLevel(eGameMasterLevel::OPERATOR);
|
||||
EXPECT_TRUE(gmOnly->MayLaunch(player));
|
||||
}
|
||||
|
||||
// The level's precondition is only used with the level's rocketUseLaunchPrecondition (Nimbus Station's pad to
|
||||
// Forbidden Valley's property has "115" without it)
|
||||
TEST_F(RocketLaunchTests, ALevelPreconditionThatIsNotInUseIsNotChecked) {
|
||||
MakePadTables();
|
||||
Entity pad(PAD, info);
|
||||
pad.SetVar<bool>(u"rocketLaunchUseDBDefaults", false);
|
||||
pad.SetVar<int32_t>(u"targetZone", 1450);
|
||||
pad.SetVar<bool>(u"rocketUseLaunchPrecondition", false);
|
||||
pad.SetVar<std::u16string>(u"rocketLaunchPreCondition", u"0");
|
||||
auto* const component = pad.AddComponent<RocketLaunchpadControlComponent>(3);
|
||||
Entity player(PLAYER, info);
|
||||
EXPECT_TRUE(component->MayLaunch(player));
|
||||
EXPECT_EQ(component->GetTargetZone(), 1450);
|
||||
}
|
||||
|
||||
// With rocketLaunchUseDBDefaults true (the client's default, and 12 pads in the maps say so) the row rules and the
|
||||
// level's keys are not looked at
|
||||
TEST_F(RocketLaunchTests, APadThatUsesTheTableIgnoresItsLevelKeys) {
|
||||
MakePadTables();
|
||||
for (const bool withKey : { true, false }) {
|
||||
Entity pad(PAD, info);
|
||||
if (withKey) pad.SetVar<bool>(u"rocketLaunchUseDBDefaults", true);
|
||||
pad.SetVar<int32_t>(u"targetZone", 1400);
|
||||
pad.SetVar<std::u16string>(u"targetScene", u"FVGate");
|
||||
pad.SetVar<int32_t>(u"GMLevel", 9);
|
||||
pad.SetVar<bool>(u"rocketUseLaunchPrecondition", false);
|
||||
auto* const component = pad.AddComponent<RocketLaunchpadControlComponent>(16);
|
||||
EXPECT_EQ(component->GetTargetZone(), 1300);
|
||||
EXPECT_EQ(component->GetTargetScene(), "GFLanding");
|
||||
Entity player(PLAYER, info);
|
||||
EXPECT_FALSE(component->MayLaunch(player)); // the row's precondition, not the level's "none"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,6 +131,35 @@ TEST_F(SimplePhysicsTest, SimplePhysicsConstructionTest) {
|
||||
ASSERT_EQ(rotation, NiQuaternion(1.0f, 2.0f, 3.0f, 4.0f));
|
||||
}
|
||||
|
||||
// A construction (the object coming into one player's range) doesn't use up a velocity or motion state change the
|
||||
// players already watching it still have to get. LWOSimplePhysicsComponent::Deserialize (0x00be4b00) reads each
|
||||
// behind its own flag bit.
|
||||
TEST_F(SimplePhysicsTest, AConstructionKeepsPendingChangesForTheNextUpdate) {
|
||||
RakNet::BitStream construction;
|
||||
simplePhysicsComponent->Serialize(construction, true);
|
||||
|
||||
simplePhysicsComponent->Serialize(bitStream, false);
|
||||
bool hasVelocity{};
|
||||
bitStream.Read(hasVelocity);
|
||||
ASSERT_TRUE(hasVelocity);
|
||||
NiPoint3 velocity;
|
||||
NiPoint3 angularVelocity;
|
||||
bitStream.Read(velocity);
|
||||
bitStream.Read(angularVelocity);
|
||||
EXPECT_EQ(velocity, NiPoint3(5.0f, 6.0f, 7.0f));
|
||||
bool hasMotionState{};
|
||||
bitStream.Read(hasMotionState);
|
||||
ASSERT_TRUE(hasMotionState);
|
||||
uint32_t motionState{};
|
||||
bitStream.Read(motionState);
|
||||
EXPECT_EQ(motionState, 2u);
|
||||
|
||||
// Written once
|
||||
RakNet::BitStream again;
|
||||
simplePhysicsComponent->Serialize(again, false);
|
||||
EXPECT_EQ(again.GetNumberOfBitsUsed(), 3u);
|
||||
}
|
||||
|
||||
TEST_F(SimplePhysicsTest, SimplePhysicsGettersAndSettersTest) {
|
||||
ASSERT_EQ(simplePhysicsComponent->GetClimabbleType(), eClimbableType::CLIMBABLE_TYPE_WALL);
|
||||
ASSERT_EQ(simplePhysicsComponent->GetPosition(), NiPoint3(1.0f, 2.0f, 3.0f));
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#include "ZCompression.h"
|
||||
#include "LDFFormat.h"
|
||||
#include "ChatPackets.h"
|
||||
#include "ClientPackets.h"
|
||||
#include "GameDependencies.h"
|
||||
@@ -310,6 +312,7 @@ TEST_F(WorldPacketsTests, CreateCharacterMatchesLegacy) {
|
||||
packet.reputation = reputation;
|
||||
packet.propertyCloneID = cloneID;
|
||||
packet.txfring = false; // the legacy sender never wrote it
|
||||
packet.sendWorldKeys = false; // nor the world keys
|
||||
ExpectSameSend([&](const SystemAddress& a) { LegacyWorldPackets::SendCreateCharacter(a, reputation, objectID, xml, name, gm, cloneID); }, packet);
|
||||
|
||||
const auto copy = RoundTrip(packet);
|
||||
@@ -340,6 +343,90 @@ TEST_F(WorldPacketsTests, CreateCharacterSendsTxfring) {
|
||||
EXPECT_FALSE(RoundTrip(packet).txfring);
|
||||
}
|
||||
|
||||
// Live sent legoclub=1, freetrial=0, requiresrename=0, levelid and position / rotation in 451 of 451 character data packets
|
||||
TEST_F(WorldPacketsTests, CreateCharacterSendsTheWorldKeys) {
|
||||
ClientPackets::CreateCharacter packet;
|
||||
packet.xmlData = "<obj/>";
|
||||
packet.requiresRename = true;
|
||||
packet.levelID = 1200ULL | 7ULL << 16 | 99ULL << 32;
|
||||
packet.position = NiPoint3(1.5f, -2.0f, 3.25f);
|
||||
packet.rotation = NiQuaternion(0.5f, 0.1f, 0.2f, 0.3f);
|
||||
const auto copy = RoundTrip(packet);
|
||||
EXPECT_TRUE(copy.sendWorldKeys);
|
||||
EXPECT_TRUE(copy.legoClub);
|
||||
EXPECT_FALSE(copy.freeTrial);
|
||||
EXPECT_TRUE(copy.requiresRename);
|
||||
EXPECT_EQ(copy.levelID, packet.levelID);
|
||||
EXPECT_EQ(copy.position, packet.position);
|
||||
EXPECT_EQ(copy.rotation, packet.rotation);
|
||||
|
||||
packet.sendWorldKeys = false;
|
||||
const auto without = RoundTrip(packet);
|
||||
EXPECT_FALSE(without.sendWorldKeys);
|
||||
EXPECT_FALSE(without.legoClub); // the client's value without the key
|
||||
EXPECT_FALSE(without.requiresRename);
|
||||
}
|
||||
|
||||
// Live sent reputation as LDF type 8 (a 64-bit number), not as an object ID (type 9), in every character data packet.
|
||||
// The entries are sorted by key: reputation follows propertycloneid.
|
||||
TEST_F(WorldPacketsTests, CreateCharacterSendsReputationAsLdfType8) {
|
||||
const auto reputationType = [](const ClientPackets::CreateCharacter& packet) {
|
||||
RakNet::BitStream bitStream;
|
||||
packet.Serialize(bitStream);
|
||||
// The LDF is compressed: size + 9, the compressed flag, the size, the compressed size, the data
|
||||
uint32_t sizePlusHeader{};
|
||||
uint8_t compressed{};
|
||||
uint32_t uncompressedSize{};
|
||||
uint32_t compressedSize{};
|
||||
EXPECT_TRUE(bitStream.Read(sizePlusHeader));
|
||||
EXPECT_TRUE(bitStream.Read(compressed));
|
||||
EXPECT_TRUE(bitStream.Read(uncompressedSize));
|
||||
EXPECT_TRUE(bitStream.Read(compressedSize));
|
||||
std::vector<uint8_t> compressedData(compressedSize);
|
||||
EXPECT_TRUE(bitStream.ReadAlignedBytes(compressedData.data(), compressedSize));
|
||||
std::vector<uint8_t> uncompressed(uncompressedSize);
|
||||
int32_t error{};
|
||||
EXPECT_EQ(ZCompression::Decompress(compressedData.data(), compressedSize, uncompressed.data(), uncompressedSize, error), static_cast<int32_t>(uncompressedSize));
|
||||
RakNet::BitStream data(uncompressed.data(), uncompressed.size(), false);
|
||||
uint32_t count{};
|
||||
EXPECT_TRUE(data.Read(count));
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
uint8_t keyBytes{};
|
||||
EXPECT_TRUE(data.Read(keyBytes));
|
||||
std::u16string key(keyBytes / 2, u'\0');
|
||||
for (auto& character : key) EXPECT_TRUE(data.Read(character));
|
||||
uint8_t type{};
|
||||
EXPECT_TRUE(data.Read(type));
|
||||
if (key == u"reputation") {
|
||||
int64_t value{};
|
||||
EXPECT_TRUE(data.Read(value));
|
||||
EXPECT_EQ(value, 300);
|
||||
return static_cast<int32_t>(type);
|
||||
}
|
||||
switch (type) {
|
||||
case LDF_TYPE_S32: case LDF_TYPE_U32: case LDF_TYPE_FLOAT: data.IgnoreBytes(4); break;
|
||||
case LDF_TYPE_BOOLEAN: data.IgnoreBytes(1); break;
|
||||
case LDF_TYPE_U64: case LDF_TYPE_OBJID: data.IgnoreBytes(8); break;
|
||||
case LDF_TYPE_UTF_16: { uint32_t length{}; EXPECT_TRUE(data.Read(length)); data.IgnoreBytes(length * 2); break; }
|
||||
case LDF_TYPE_UTF_8: { uint32_t length{}; EXPECT_TRUE(data.Read(length)); data.IgnoreBytes(length); break; }
|
||||
default: ADD_FAILURE() << "LDF type " << static_cast<int32_t>(type); return -1;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
|
||||
ClientPackets::CreateCharacter packet;
|
||||
packet.xmlData = "<obj/>";
|
||||
packet.reputation = 300;
|
||||
EXPECT_EQ(reputationType(packet), 8);
|
||||
EXPECT_EQ(RoundTrip(packet).reputation, 300);
|
||||
|
||||
// The packet from before the world keys keeps its type
|
||||
packet.sendWorldKeys = false;
|
||||
EXPECT_EQ(reputationType(packet), 9);
|
||||
EXPECT_EQ(RoundTrip(packet).reputation, 300);
|
||||
}
|
||||
|
||||
TEST_F(WorldPacketsTests, CharacterListMatchesLegacy) {
|
||||
FakeCharacter first;
|
||||
FakeCharacter second;
|
||||
|
||||
Reference in New Issue
Block a user