Skip to content

Commit 49a38cc

Browse files
committed
Fixed crucial issues
Plane normal was nulling itself when trying to resolve stuck plane normal. That "bug" was added on 1.0.4 update, probably left over from my testings and wasn't removed untill now. Also fixed incorrect logic for Ray_t::Init() arguments.
1 parent 1a81c2c commit 49a38cc

1 file changed

Lines changed: 21 additions & 26 deletions

File tree

addons/sourcemod/scripting/momsurffix2.sp

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,12 @@ int TryPlayerMove(CGameMovement pThis, Vector pFirstDest, CGameTrace pFirstTrace
334334
alloced_vector.ToArray(valid_plane);
335335
}
336336
//TODO: should be replaced with normal solution!! Currently hack to fix issue #1.
337-
else if(!gNoclipWorkAround.BoolValue || (vecVelocity.z < -6.25 && vecVelocity.z > 0.0))
337+
else if(!gNoclipWorkAround.BoolValue || (vecVelocity.z < -6.25 || vecVelocity.z > 0.0))
338338
{
339339
//Quite heavy part of the code, should not be triggered much or else it'll impact performance by a lot!!!
340340
float offsets[3];
341-
offsets[0] = (bumpcount * 2.0) * -gRampInitialRetraceLength.FloatValue;
342-
offsets[2] = (bumpcount * 2.0) * gRampInitialRetraceLength.FloatValue;
341+
offsets[0] = (float(bumpcount) * 2.0) * -gRampInitialRetraceLength.FloatValue;
342+
offsets[2] = (float(bumpcount) * 2.0) * gRampInitialRetraceLength.FloatValue;
343343
int valid_planes = 0;
344344

345345
VectorCopy(view_as<float>({0.0, 0.0, 0.0}), valid_plane);
@@ -378,22 +378,26 @@ int TryPlayerMove(CGameMovement pThis, Vector pFirstDest, CGameTrace pFirstTrace
378378
PROF_STOP(0);
379379

380380
PROF_START();
381+
AddVectors(fixed_origin, offset, buff);
382+
SubtractVectors(end, offset, offset);
381383
if(gEngineVersion == Engine_CSGO)
382-
ray.Init((AddVectors(fixed_origin, offset, buff), buff), (SubtractVectors(end, offset, offset), offset),
383-
(SubtractVectors(VectorToArray(GetPlayerMins(pThis)), offset_mins, offset_mins), offset_mins),
384-
(AddVectors(VectorToArray(GetPlayerMaxs(pThis)), offset_maxs, offset_maxs), offset_maxs));
384+
{
385+
SubtractVectors(VectorToArray(GetPlayerMins(pThis)), offset_mins, offset_mins);
386+
AddVectors(VectorToArray(GetPlayerMaxs(pThis)), offset_maxs, offset_maxs);
387+
}
385388
else
386-
ray.Init((AddVectors(fixed_origin, offset, buff), buff), (SubtractVectors(end, offset, offset), offset),
387-
(SubtractVectors(VectorToArray(GetPlayerMinsCSS(pThis, alloced_vector)), offset_mins, offset_mins), offset_mins),
388-
(AddVectors(VectorToArray(GetPlayerMaxsCSS(pThis, alloced_vector2)), offset_maxs, offset_maxs), offset_maxs));
389+
{
390+
SubtractVectors(VectorToArray(GetPlayerMinsCSS(pThis, alloced_vector)), offset_mins, offset_mins);
391+
AddVectors(VectorToArray(GetPlayerMaxsCSS(pThis, alloced_vector2)), offset_maxs, offset_maxs);
392+
}
389393
PROF_STOP(1);
390394

391395
PROF_START();
392-
UTIL_TraceRay(ray, MASK_PLAYERSOLID, pThis, COLLISION_GROUP_PLAYER_MOVEMENT, pm);
396+
ray.Init(buff, offset, offset_mins, offset_maxs);
393397
PROF_STOP(2);
394398

395399
PROF_START();
396-
pm.plane.normal.FromArray(vec3_origin);
400+
UTIL_TraceRay(ray, MASK_PLAYERSOLID, pThis, COLLISION_GROUP_PLAYER_MOVEMENT, pm);
397401
PROF_STOP(3);
398402

399403
PROF_START();
@@ -403,18 +407,18 @@ int TryPlayerMove(CGameMovement pThis, Vector pFirstDest, CGameTrace pFirstTrace
403407
FloatAbs(plane_normal.z) <= 1.0 && pm.fraction > 0.0 && pm.fraction < 1.0 && !pm.startsolid)
404408
{
405409
valid_planes++;
406-
plane_normal.ToArray(valid_plane);
410+
AddVectors(valid_plane, VectorToArray(plane_normal), valid_plane);
407411
}
408412
PROF_STOP(4);
409413
}
410414
}
411415
}
412416
ray.Free();
413417

414-
if(valid_planes > 0 && !CloseEnough(valid_plane, view_as<float>({0.0, 0.0, 0.0})))
418+
if(valid_planes != 0 && !CloseEnough(valid_plane, view_as<float>({0.0, 0.0, 0.0})))
415419
{
416420
has_valid_plane = true;
417-
VectorNormalize(valid_plane);
421+
NormalizeVector(valid_plane, valid_plane);
418422
continue;
419423
}
420424
}
@@ -448,7 +452,9 @@ int TryPlayerMove(CGameMovement pThis, Vector pFirstDest, CGameTrace pFirstTrace
448452
pm.plane.normal.FromArray(valid_plane);
449453
}
450454
else
455+
{
451456
TracePlayerBBox(pThis, vecAbsOrigin, alloced_vector2, MASK_PLAYERSOLID, COLLISION_GROUP_PLAYER_MOVEMENT, pm);
457+
}
452458
}
453459

454460
if(bumpcount > 0 && pThis.player.m_hGroundEntity == view_as<Address>(-1) && !IsValidMovementTrace(pThis, pm))
@@ -584,7 +590,7 @@ int TryPlayerMove(CGameMovement pThis, Vector pFirstDest, CGameTrace pFirstTrace
584590
}
585591

586592
GetVectorCrossProduct(planes[0], planes[1], dir);
587-
VectorNormalize(dir);
593+
NormalizeVector(dir, dir);
588594

589595
d = vecVelocity.Dot(dir);
590596

@@ -615,17 +621,6 @@ stock void VectorMA(float start[3], float scale, float dir[3], float dest[3])
615621
dest[2] = start[2] + dir[2] * scale;
616622
}
617623

618-
stock float VectorNormalize(float vec[3])
619-
{
620-
float iradius = 1.0 / ( SquareRoot(vec[0]*vec[0] + vec[1]*vec[1] + vec[2]*vec[2]) + FLT_EPSILON);
621-
622-
vec[0] *= iradius;
623-
vec[1] *= iradius;
624-
vec[2] *= iradius;
625-
626-
return iradius;
627-
}
628-
629624
stock void VectorCopy(float from[3], float to[3])
630625
{
631626
to[0] = from[0];

0 commit comments

Comments
 (0)