fix: trigger volume effects go out as live sent them

A trigger's SetPhysicsVolumeEffect is "type,amount,x,y,z,use distance,
min,max". In live phantom physics constructions:
- the direction has the amount as its length: "Push,50,0.91,-0.34,-0.22"
  went out as 45.68, -17.07, -11.04. DLU multiplied the arguments as
  they were, so a direction that isn't a unit vector pushed harder;
- a zero direction ("Repulse,150,0,0,0,true,25,100") is no direction;
- the distances go out when use distance is "true" ("true,150,175" as 1
  and 175, "true,20,50" as 1 and 50) and not when it is "1"
  ("Push,40.0,0,1,0,1,20,50"). DLU never wrote them.
LWOPhantomPhysicsComponent::Deserialize (0x00c34db0) reads the two
distances as floats and keeps the least of the min and 1, and a max of at
least that.

Seven arguments no longer read an eighth.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-11-10 13:19:28 -06:00
parent a269ce0cc7
commit 5832567bc4
4 changed files with 159 additions and 45 deletions

View File

@@ -3,6 +3,7 @@
* Copyright 2018
*/
#include <algorithm>
#include <sstream>
#include <iostream>
@@ -136,13 +137,13 @@ void PhantomPhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bool bI
outBitStream.Write(m_EffectType);
outBitStream.Write(m_DirectionalMultiplier);
// forgive me father for i have sinned
outBitStream.Write0();
//outBitStream.Write(m_MinMax);
//if (m_MinMax) {
//outBitStream.Write(m_Min);
//outBitStream.Write(m_Max);
//}
// Live wrote the distances as the client keeps them: "true,150,175" went out as 1 and 175
outBitStream.Write(m_MinMax);
if (m_MinMax) {
const float min = std::min(m_Min, 1.0f);
outBitStream.Write(min);
outBitStream.Write(std::max(m_Max, min));
}
outBitStream.Write(m_IsDirectional);
if (m_IsDirectional) {
@@ -244,18 +245,50 @@ void PhantomPhysicsComponent::SetEffectType(ePhysicsEffectType type) {
m_EffectInfoDirty = true;
}
void PhantomPhysicsComponent::SetMin(uint32_t min) {
void PhantomPhysicsComponent::SetMin(const float min) {
m_Min = min;
m_MinMax = true;
m_EffectInfoDirty = true;
}
void PhantomPhysicsComponent::SetMax(uint32_t max) {
void PhantomPhysicsComponent::SetMax(const float max) {
m_Max = max;
m_MinMax = true;
m_EffectInfoDirty = true;
}
void PhantomPhysicsComponent::SetVolumeEffect(std::vector<std::string> args) {
for (auto& arg : args) {
arg.erase(0, arg.find_first_not_of(' '));
arg.erase(arg.find_last_not_of(' ') + 1);
}
SetPhysicsEffectActive(true);
ePhysicsEffectType effectType = ePhysicsEffectType::PUSH;
if (!args.empty()) {
std::transform(args.at(0).begin(), args.at(0).end(), args.at(0).begin(), ::tolower);
if (args.at(0) == "push") effectType = ePhysicsEffectType::PUSH;
else if (args.at(0) == "attract") effectType = ePhysicsEffectType::ATTRACT;
else if (args.at(0) == "repulse") effectType = ePhysicsEffectType::REPULSE;
else if (args.at(0) == "gravity") effectType = ePhysicsEffectType::GRAVITY_SCALE;
else if (args.at(0) == "friction") effectType = ePhysicsEffectType::FRICTION;
}
SetEffectType(effectType);
if (args.size() > 1) SetDirectionalMultiplier(GeneralUtils::TryParse(args.at(1), 0.0f));
if (args.size() > 4) {
// Live sent the direction with the amount as its length ("Push,50,0.91,-0.34,-0.22" as 45.68, -17.07, -11.04)
// and none when it was zero ("Repulse,150,0,0,0,true,25,100")
const NiPoint3 direction = GeneralUtils::TryParse(args.at(2), args.at(3), args.at(4), NiPoint3Constant::ZERO);
if (direction != NiPoint3Constant::ZERO) SetDirection(direction.Unitize());
}
// Live sent the distances for "true" only: volumes with "1,20,50" went out without them
if (args.size() > 7 && args.at(5) == "true") {
SetMin(GeneralUtils::TryParse(args.at(6), 0.0f));
SetMax(GeneralUtils::TryParse(args.at(7), 0.0f));
}
}
void PhantomPhysicsComponent::SetPosition(const NiPoint3& pos) {
PhysicsComponent::SetPosition(pos);
if (m_dpEntity) m_dpEntity->SetPosition(pos);
@@ -281,8 +314,8 @@ bool PhantomPhysicsComponent::OnGetObjectReportInfo(GameMessages::GetObjectRepor
if (m_MinMax) {
auto& minMaxInfo = info.PushDebug("Min Max Info");
minMaxInfo.PushDebug<AMFIntValue>("Min") = m_Min;
minMaxInfo.PushDebug<AMFIntValue>("Max") = m_Max;
minMaxInfo.PushDebug<AMFDoubleValue>("Min") = m_Min;
minMaxInfo.PushDebug<AMFDoubleValue>("Max") = m_Max;
}
if (m_IsRespawnVolume) {