Skip to content

Commit b5f14f1

Browse files
authored
Fix #2178: testLineAgainstWater works incorrectly outside of game boundaries (#2192)
1 parent 9f01206 commit b5f14f1

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

Client/game_sa/CWaterManagerSA.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -838,11 +838,19 @@ bool CWaterManagerSA::TestLineAgainstWater(const CVector& vecStart, const CVecto
838838
CVector rayDir = vecEnd - vecStart;
839839

840840
// Check if we're outside of map area.
841-
CVector zeroPoint;
842-
if (vecStart.IntersectsSegmentPlane(rayDir, CVector(0, 0, 1), CVector(0, 0, 0), &zeroPoint) && IsPointOutsideOfGameArea(zeroPoint))
841+
// Check for intersection with ocean outside the game area (takes water level into account)
842+
// If a hit is detected, and it is outside, we early out, as custom water can't be created outside game boundaries
843843
{
844-
*vecCollision = zeroPoint;
845-
return true;
844+
CVector intersection{};
845+
const float waterHeight = *reinterpret_cast<float*>(0x6E873F);
846+
if (vecStart.IntersectsSegmentPlane(rayDir, CVector(0, 0, 1), CVector(0, 0, waterHeight), &intersection))
847+
{
848+
if (IsPointOutsideOfGameArea(intersection))
849+
{
850+
*vecCollision = intersection;
851+
return true;
852+
}
853+
}
846854
}
847855

848856
// Early out in case of both points being out of map
@@ -858,7 +866,7 @@ bool CWaterManagerSA::TestLineAgainstWater(const CVector& vecStart, const CVecto
858866
return false;
859867
}
860868
}
861-
869+
862870
std::vector<CWaterZoneSA*> vecZones;
863871
GetZonesIntersecting(vecStart, vecEnd, vecZones);
864872

Shared/sdk/CVector.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,18 @@ class CVector
118118

119119
if (fabs(fDenom) > 1e-4f)
120120
{
121-
*fOutDist = (vecPosition.Length() - vecNormal.DotProduct(this)) / fDenom;
121+
*fOutDist = (vecNormal.DotProduct(&vecPosition) - vecNormal.DotProduct(this)) / fDenom;
122122
return true;
123123
}
124124

125125
if (fDenom != 0.0f)
126126
{
127-
*fOutDist = (vecPosition.Length() - vecNormal.DotProduct(this)) / fDenom;
127+
*fOutDist = (vecNormal.DotProduct(&vecPosition) - vecNormal.DotProduct(this)) / fDenom;
128128
return fabs(*fOutDist) < 1e-4f;
129129
}
130130

131131
*fOutDist = 0.0f;
132-
return fabs(vecNormal.DotProduct(this) - vecPosition.Length()) < 1e-3f;;
132+
return fabs(vecNormal.DotProduct(this) - vecNormal.DotProduct(&vecPosition)) < 1e-3f;;
133133
}
134134

135135
bool IntersectsSegmentPlane(const CVector& vecSegment, const CVector& vecNormal, const CVector& vecPosition, CVector* outVec) const noexcept

0 commit comments

Comments
 (0)