feat: a player's construction can leave out its position and world transition

For the one construction a client gets of its own player after a seamless instance move. The client applies a
construction's frame to its player at once (LWOBasePhysComponent::Deserialize, 0x00bf5a10), and world transition
state 0 makes it fade the screen in from white (LWOCharacterComponent::PostCharacterLoaded, 0x00c71660). State 3 is
read but nothing acts on it. Nothing sets either flag yet.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-11-10 15:15:16 -06:00
parent 7695445c4c
commit f081dafb94
5 changed files with 124 additions and 8 deletions

View File

@@ -225,12 +225,20 @@ void CharacterComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInit
outBitStream.Write(m_RacesFinished);
outBitStream.Write(m_FirstPlaceRaceFinishes);
outBitStream.Write0();
outBitStream.Write(m_IsLanding);
if (m_IsLanding) {
outBitStream.Write<uint16_t>(m_LastRocketConfig.size());
for (uint16_t character : m_LastRocketConfig) {
outBitStream.Write(character);
// The world transition state, two bits: 0 none, 1 arriving by rocket, 2 leaving. The client's
// LWOCharacterComponent::PostCharacterLoaded (0x00c71660) fades the screen in from white and pushes its
// gameplay state again when it reads 0. A client that kept its scene gets 3, which nothing acts on.
if (m_KeepClientScene) {
outBitStream.Write1();
outBitStream.Write1();
} else {
outBitStream.Write0();
outBitStream.Write(m_IsLanding);
if (m_IsLanding) {
outBitStream.Write<uint16_t>(m_LastRocketConfig.size());
for (uint16_t character : m_LastRocketConfig) {
outBitStream.Write(character);
}
}
}
}

View File

@@ -71,6 +71,13 @@ public:
void SetLastCustomBuild(const std::u16string& tokenizedLOTList) { m_LastRocketConfig = tokenizedLOTList; }
bool GetIsLanding() const { return m_IsLanding; }
/**
* Constructions written while this is set tell the client there is no world transition to show (state 3 instead
* of 0 or the rocket landing). For the one construction a client gets of its own player after a seamless instance
* move (docs/SeamlessTransfer.md).
*/
void SetKeepClientScene(const bool value) { m_KeepClientScene = value; }
/**
* Find a player's rocket
* @param player the entity that triggered the event
@@ -418,6 +425,11 @@ private:
*/
bool m_IsLanding;
/**
* Whether constructions say there is no world transition to show (SetKeepClientScene)
*/
bool m_KeepClientScene = false;
/**
* The configuration of the last used rocket, essentially a string of LOTs separated by commas
*/

View File

@@ -141,8 +141,11 @@ void ControllablePhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bo
if (!bIsInitialUpdate) m_DirtyBubble = false;
}
outBitStream.Write(m_DirtyPosition || bIsInitialUpdate);
if (m_DirtyPosition || bIsInitialUpdate) {
// A client that kept its player across a seamless instance move knows where it stands better than the save does:
// its construction leaves the frame out, and LWOBasePhysComponent::Deserialize (0x00bf5a10) then sets nothing
const bool writePosition = bIsInitialUpdate ? !m_KeepClientPosition : m_DirtyPosition;
outBitStream.Write(writePosition);
if (writePosition) {
outBitStream.Write(m_Position.x);
outBitStream.Write(m_Position.y);
outBitStream.Write(m_Position.z);

View File

@@ -210,6 +210,13 @@ public:
*/
bool GetIsTeleporting() const { return m_IsTeleporting; }
/**
* Constructions written while this is set carry no position, rotation or velocity. For the one construction a
* client gets of its own player after a seamless instance move (docs/SeamlessTransfer.md): the client applies a
* construction's frame to its player at once, which would pull it back to where it was saved.
*/
void SetKeepClientPosition(const bool value) { m_KeepClientPosition = value; }
/**
* Returns the Physics entity for the component
* @return Physics entity for the component
@@ -389,6 +396,11 @@ private:
*/
bool m_IsTeleporting;
/**
* Whether constructions leave the position out (SetKeepClientPosition)
*/
bool m_KeepClientPosition = false;
/**
* The list of speed boosts for this entity
*/

View File

@@ -199,6 +199,87 @@ TEST_F(ReplicaConstructionTest, ControllablePhysicsConstructionWritesCheatsOnlyW
EXPECT_FLOAT_EQ(cheats.second, 1.05f);
}
// A client that kept its player across a seamless instance move (docs/SeamlessTransfer.md): its own player's
// construction carries no frame, because LWOBasePhysComponent::Deserialize (0x00bf5a10) applies a construction's
// position, rotation and velocities to the object at once. Everyone else's construction still has it.
TEST_F(ReplicaConstructionTest, ControllablePhysicsConstructionCanLeaveThePositionOut) {
Entity entity(15, info);
auto* const physics = entity.AddComponent<ControllablePhysicsComponent>(-1);
physics->SetPosition(NiPoint3(1.0f, 2.0f, 3.0f));
// no jetpack, stun immunities, no cheats, equipped item info (flag, pickup radius, in jetpack), bubble (flag, off)
constexpr uint32_t beforePosition = 1 + 1 + 7 * 32 + 1 + (1 + 32 + 1) + (1 + 1);
const auto positionBit = [physics, beforePosition](uint32_t& bitsAfter) {
RakNet::BitStream stream;
physics->Serialize(stream, true);
stream.IgnoreBits(beforePosition);
bool hasPosition{};
EXPECT_TRUE(stream.Read(hasPosition));
bitsAfter = stream.GetNumberOfUnreadBits();
return hasPosition;
};
uint32_t bitsAfter{};
EXPECT_TRUE(positionBit(bitsAfter));
EXPECT_GT(bitsAfter, 7u * 32u);
physics->SetKeepClientPosition(true);
EXPECT_FALSE(positionBit(bitsAfter));
EXPECT_EQ(bitsAfter, 0u);
// Serializations are untouched: a moved player is still sent
RakNet::BitStream flushed;
physics->Serialize(flushed, false);
RakNet::BitStream serialization;
physics->SetPosition(NiPoint3(4.0f, 5.0f, 6.0f));
physics->Serialize(serialization, false);
serialization.IgnoreBits(3); // no cheats, equipped item info or bubble change
bool hasPosition{};
EXPECT_TRUE(serialization.Read(hasPosition));
EXPECT_TRUE(hasPosition);
physics->SetKeepClientPosition(false);
EXPECT_TRUE(positionBit(bitsAfter));
}
// The same client's character construction: world transition state 3. With 0 the client's
// LWOCharacterComponent::PostCharacterLoaded (0x00c71660) fades the whole screen in from white and pushes its gameplay
// state a second time; 1 is the rocket landing and 2 hides the character. The blocks after it stay where they were.
TEST_F(ReplicaConstructionTest, CharacterConstructionCanSkipTheWorldTransition) {
User user(UNASSIGNED_SYSTEM_ADDRESS, "tester", "key");
Character character(1, &user);
info.lot = 1;
Entity player(1152921506064087003, info);
player.SetCharacter(&character);
character.SetEntity(&player);
auto* const component = player.AddComponent<CharacterComponent>(-1, &character, UNASSIGNED_SYSTEM_ADDRESS);
// 4 absent claim codes, 10 u32 appearance fields, 4 u64s, the free-trial bit and 27 u64 statistics
constexpr uint32_t beforeTransition = 4 + 10 * 32 + 4 * 64 + 1 + 27 * 64;
const auto transition = [component, beforeTransition](uint32_t& bitsAfter) {
RakNet::BitStream construction;
component->Serialize(construction, true);
construction.IgnoreBits(beforeTransition);
uint8_t state{};
EXPECT_TRUE(construction.ReadBits(&state, 2));
bitsAfter = construction.GetNumberOfUnreadBits();
return state;
};
uint32_t normalBits{};
EXPECT_EQ(transition(normalBits), 0);
component->SetKeepClientScene(true);
uint32_t keptBits{};
EXPECT_EQ(transition(keptBits), 3);
EXPECT_EQ(keptBits, normalBits);
component->SetKeepClientScene(false);
EXPECT_EQ(transition(keptBits), 0);
player.SetCharacter(nullptr);
}
// Simple physics: live sent motion type Fixed for objects without a motionType (never the invalid 0 DLU sent when the
// level gave none) and no velocity for fixed objects (38,970 Fixed constructions, all without velocity); moving
// platforms were Keyframed with a velocity (1,059 of 1,059).