Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
Fixed bug on start of the plugin when "world" entity isn't initialized, and few other bug fixes.
  • Loading branch information
GAMMACASE authored Jan 12, 2020
1 parent f30efa6 commit 4ad12f7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
17 changes: 16 additions & 1 deletion addons/sourcemod/scripting/momsurffix/baseplayer.sp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ methodmap CBasePlayer < AddressBase
}
}

stock void InitBasePlayer(GameData gd)
stock bool InitBasePlayer(GameData gd)
{
char buff[128];

Expand All @@ -47,6 +47,21 @@ stock void InitBasePlayer(GameData gd)

offsets.cbpoffsets.m_hGroundEntity = FindSendPropInfo("CBasePlayer", "m_hGroundEntity");
ASSERT_FMT(offsets.cbpoffsets.m_hGroundEntity > 0, "Can't get \"CBasePlayer::m_hGroundEntity\" offset from FindSendPropInfo().");

if(IsValidEntity(0))
{
offsets.cbpoffsets.m_MoveType = FindDataMapInfo(0, "m_MoveType");
ASSERT_FMT(offsets.cbpoffsets.m_MoveType != -1, "Can't get \"CBasePlayer::m_MoveType\" offset from FindDataMapInfo().");
}
else
return false;

return true;
}

stock void LateInitBasePlayer(GameData gd)
{
ASSERT(IsValidEntity(0));
offsets.cbpoffsets.m_MoveType = FindDataMapInfo(0, "m_MoveType");
ASSERT_FMT(offsets.cbpoffsets.m_MoveType != -1, "Can't get \"CBasePlayer::m_MoveType\" offset from FindDataMapInfo().");
}
7 changes: 4 additions & 3 deletions addons/sourcemod/scripting/momsurffix/gametrace.sp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ methodmap Ray_t < AllocatableBase

public void Init(float start[3], float end[3], float mins[3], float maxs[3])
{
float buff[3];
float buff[3], buff2[3];
SubtractVectors(end, start, buff);
this.m_Delta.FromArray(buff);

Expand All @@ -255,8 +255,9 @@ methodmap Ray_t < AllocatableBase

AddVectors(mins, maxs, buff);
ScaleVector(buff, 0.5);
AddVectors(start, buff, buff);
ScaleVector(buff, -1.0);
AddVectors(start, buff, buff2);
this.m_Start.FromArray(buff2);
NegateVector(buff);
this.m_StartOffset.FromArray(buff);
}
}
Expand Down
30 changes: 24 additions & 6 deletions addons/sourcemod/scripting/momsurffix2.sp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
#include "dhooks"

#define SNAME "[momsurffix2] "
#define GAME_DATA_FILE "momsurffix2.games"

public Plugin myinfo = {
name = "Momentum surf fix \'2",
author = "GAMMA CASE",
description = "Ported surf fix from momentum mod.",
version = "1.0.0",
version = "1.0.1",
url = "http://steamcommunity.com/id/_GAMMACASE_/"
};

Expand All @@ -36,6 +37,7 @@ OSType gOSType;
ConVar gRampBumpCount, gBounce, gRampInitialRetraceLength;

float vec3_origin[3] = {0.0, 0.0, 0.0};
bool gLoadedTooEarly;

public void OnPluginStart()
{
Expand All @@ -49,21 +51,32 @@ public void OnPluginStart()

AutoExecConfig();

GameData gd = new GameData("momsurffix2.games");
GameData gd = new GameData(GAME_DATA_FILE);
ASSERT_FINAL(gd);

ValidateGameData(gd);

InitUtils(gd);
InitGameTrace(gd);
InitBasePlayer(gd);
gLoadedTooEarly = !InitBasePlayer(gd);
InitGameMovement(gd);

SetupDhooks(gd);

delete gd;
}

public void OnMapStart()
{
if(gLoadedTooEarly)
{
GameData gd = new GameData(GAME_DATA_FILE);
LateInitBasePlayer(gd);
gLoadedTooEarly = false;
delete gd;
}
}

public void OnPluginEnd()
{
CleanUpUtils();
Expand Down Expand Up @@ -135,6 +148,8 @@ int TryPlayerMove(CGameMovement pThis, Vector pFirstDest, CGameTrace pFirstTrace

if(stuck_on_ramp)
{
//PrintToServer(SNAME..."[%i] Stuck!!!", GetGameTickCount());

if(!has_valid_plane)
{
plane_normal = pm.plane.normal;
Expand Down Expand Up @@ -268,10 +283,12 @@ int TryPlayerMove(CGameMovement pThis, Vector pFirstDest, CGameTrace pFirstTrace
if(stuck_on_ramp && has_valid_plane)
{
alloced_vector.FromArray(fixed_origin);
//TracePlayerBBoxCustom(pThis, fixed_origin, end, MASK_PLAYERSOLID, COLLISION_GROUP_PLAYER_MOVEMENT, pm);
TracePlayerBBox(pThis, alloced_vector, vec1, MASK_PLAYERSOLID, COLLISION_GROUP_PLAYER_MOVEMENT, pm);
pm.plane.normal.FromArray(valid_plane);
}
else
//TracePlayerBBoxCustom(pThis, VectorToArray(pThis.mv.m_vecAbsOrigin), end, MASK_PLAYERSOLID, COLLISION_GROUP_PLAYER_MOVEMENT, pm);
TracePlayerBBox(pThis, pThis.mv.m_vecAbsOrigin, vec1, MASK_PLAYERSOLID, COLLISION_GROUP_PLAYER_MOVEMENT, pm);

vec1.Free();
Expand All @@ -284,19 +301,20 @@ int TryPlayerMove(CGameMovement pThis, Vector pFirstDest, CGameTrace pFirstTrace
continue;
}

if(pm.allsolid)
/*if(pm.allsolid)
{
vecVelocity.FromArray(vec3_origin);
pm.Free();
return 4;
}
}*/

if(pm.fraction > 0.0)
{
if((bumpcount == 0 || pThis.player.m_hGroundEntity != view_as<Address>(-1)) && numbumps > 0 && pm.fraction == 1.0)
{
CGameTrace stuck = CGameTrace();
//TracePlayerBBoxCustom(pThis, VectorToArray(pm.endpos), VectorToArray(pm.endpos), MASK_PLAYERSOLID, COLLISION_GROUP_PLAYER_MOVEMENT, stuck);
TracePlayerBBox(pThis, pm.endpos, pm.endpos, MASK_PLAYERSOLID, COLLISION_GROUP_PLAYER_MOVEMENT, stuck);

if((stuck.startsolid || stuck.fraction != 1.0) && bumpcount == 0)
Expand Down Expand Up @@ -528,7 +546,7 @@ stock bool IsValidMovementTrace(CGameMovement pThis, CGameTrace tr)
return true;
}

/*stock void TracePlayerBBox(CGameMovement pThis, float start[3], float end[3], int mask, int collisionGroup, CGameTrace trace)
/*stock void TracePlayerBBoxCustom(CGameMovement pThis, float start[3], float end[3], int mask, int collisionGroup, CGameTrace trace)
{
Ray_t ray = Ray_t();
Expand Down

0 comments on commit 4ad12f7

Please sign in to comment.