Skip to content

Commit

Permalink
Migrate from ProcessMovement/ProcessMovementPost to PreThink/PostThin…
Browse files Browse the repository at this point in the history
…kPost
  • Loading branch information
rtldg committed Feb 23, 2025
1 parent 1d7545d commit 069b408
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 83 deletions.
22 changes: 0 additions & 22 deletions addons/sourcemod/gamedata/shavit.games.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,8 @@

"#default"
{
"Keys"
{
"IGameMovement" "GameMovement001"
}

"Signatures"
{
"CreateInterface_Server"
{
"library" "server"
"windows" "@CreateInterface"
"windows64" "@CreateInterface"
"linux" "@CreateInterface"
"linux64" "@CreateInterface"
}

"CreateInterface_Engine"
{
"library" "engine"
Expand Down Expand Up @@ -47,14 +33,6 @@
"linux" "0"
"linux64" "1"
}

"ProcessMovement"
{
"windows" "1"
"windows64" "1"
"linux" "2"
"linux64" "2"
}
}
}

Expand Down
77 changes: 16 additions & 61 deletions addons/sourcemod/scripting/shavit-core.sp
Original file line number Diff line number Diff line change
Expand Up @@ -484,52 +484,6 @@ void LoadDHooks()
SetFailState("Failed to load shavit gamedata");
}

StartPrepSDKCall(SDKCall_Static);
if(!PrepSDKCall_SetFromConf(gamedataConf, SDKConf_Signature, "CreateInterface_Server"))
{
SetFailState("Failed to get CreateInterface");
}
PrepSDKCall_AddParameter(SDKType_String, SDKPass_Pointer);
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Pointer, VDECODE_FLAG_ALLOWNULL);
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
Handle CreateInterface = EndPrepSDKCall();

if(CreateInterface == null)
{
SetFailState("Unable to prepare SDKCall for CreateInterface");
}

char interfaceName[64];

// ProcessMovement
if(!GameConfGetKeyValue(gamedataConf, "IGameMovement", interfaceName, sizeof(interfaceName)))
{
SetFailState("Failed to get IGameMovement interface name");
}

Address IGameMovement = SDKCall(CreateInterface, interfaceName, 0);

if(!IGameMovement)
{
SetFailState("Failed to get IGameMovement pointer");
}

int offset = GameConfGetOffset(gamedataConf, "ProcessMovement");
if(offset == -1)
{
SetFailState("Failed to get ProcessMovement offset");
}

Handle processMovement = DHookCreate(offset, HookType_Raw, ReturnType_Void, ThisPointer_Ignore, DHook_ProcessMovement);
DHookAddParam(processMovement, HookParamType_CBaseEntity);
DHookAddParam(processMovement, HookParamType_ObjectPtr);
DHookRaw(processMovement, false, IGameMovement);

Handle processMovementPost = DHookCreate(offset, HookType_Raw, ReturnType_Void, ThisPointer_Ignore, DHook_ProcessMovementPost);
DHookAddParam(processMovementPost, HookParamType_CBaseEntity);
DHookAddParam(processMovementPost, HookParamType_ObjectPtr);
DHookRaw(processMovementPost, true, IGameMovement);

gB_Linux = GameConfGetOffset(gamedataConf, "OS") == 2;

if (gEV_Type == Engine_TF2 && gB_Linux)
Expand Down Expand Up @@ -563,12 +517,11 @@ void LoadDHooks()

LoadPhysicsUntouch(gamedataConf);

delete CreateInterface;
delete gamedataConf;

gamedataConf = LoadGameConfigFile("sdktools.games");

offset = GameConfGetOffset(gamedataConf, "AcceptInput");
int offset = GameConfGetOffset(gamedataConf, "AcceptInput");
gH_AcceptInput = new DynamicHook(offset, HookType_Entity, ReturnType_Bool, ThisPointer_CBaseEntity);
gH_AcceptInput.AddParam(HookParamType_CharPtr);
gH_AcceptInput.AddParam(HookParamType_CBaseEntity);
Expand All @@ -583,7 +536,6 @@ void LoadDHooks()
}

gH_TeleportDhook = new DynamicHook(offset, HookType_Entity, ReturnType_Void, ThisPointer_CBaseEntity);

gH_TeleportDhook.AddParam(HookParamType_VectorPtr);
gH_TeleportDhook.AddParam(HookParamType_VectorPtr);
gH_TeleportDhook.AddParam(HookParamType_VectorPtr);
Expand Down Expand Up @@ -2739,6 +2691,7 @@ public void OnClientPutInServer(int client)
CallOnStyleChanged(client, 0, gI_DefaultStyle, false);
}

SDKHook(client, SDKHook_PreThink, PreThink);
SDKHook(client, SDKHook_PreThinkPost, PreThinkPost);
SDKHook(client, SDKHook_PostThinkPost, PostThinkPost);
}
Expand Down Expand Up @@ -2923,8 +2876,15 @@ public void Shavit_OnLeaveZone(int client, int type, int track, int id, int enti
UpdateStyleSettings(client);
}

public void PreThink(int client)
{
FakeProcessMovementPre(client);
}

public void PreThinkPost(int client)
{
FakeProcessMovementPost(client);

if(IsPlayerAlive(client))
{
if (!gB_Zones || !Shavit_InsideZone(client, Zone_Airaccelerate, gA_Timers[client].iTimerTrack))
Expand Down Expand Up @@ -3088,9 +3048,8 @@ public MRESReturn DHook_PreventBunnyJumpingPre()
return MRES_Ignored;
}

public MRESReturn DHook_ProcessMovement(Handle hParams)
void FakeProcessMovementPre(int client)
{
int client = DHookGetParam(hParams, 1);
gI_ClientProcessingMovement = client;

if (gI_TF2PreventBunnyJumpingAddr != Address_Null)
Expand All @@ -3112,7 +3071,7 @@ public MRESReturn DHook_ProcessMovement(Handle hParams)
if (IsFakeClient(client) || !IsPlayerAlive(client))
{
SetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue", 1.0); // otherwise you get slow spec noclip
return MRES_Ignored;
return;
}

MoveType mt = GetEntityMoveType(client);
Expand All @@ -3124,7 +3083,7 @@ public MRESReturn DHook_ProcessMovement(Handle hParams)
SetClientEventsPaused(client, gA_Timers[client].bClientPaused);
}

return MRES_Ignored;
return;
}

// i got this code from kid-tas by kid fearless
Expand All @@ -3149,21 +3108,17 @@ public MRESReturn DHook_ProcessMovement(Handle hParams)
{
SetClientEventsPaused(client, (!Shavit_ShouldProcessFrame(client) || gA_Timers[client].bClientPaused));
}

return MRES_Ignored;
}

public MRESReturn DHook_ProcessMovementPost(Handle hParams)
void FakeProcessMovementPost(int client)
{
int client = DHookGetParam(hParams, 1);

Call_StartForward(gH_Forwards_OnProcessMovementPost);
Call_PushCell(client);
Call_Finish();

if (IsFakeClient(client) || !IsPlayerAlive(client))
{
return MRES_Ignored;
return;
}

if (gA_Timers[client].fTimescale != 1.0 && GetEntityMoveType(client) != MOVETYPE_NOCLIP)
Expand All @@ -3174,7 +3129,7 @@ public MRESReturn DHook_ProcessMovementPost(Handle hParams)

if (gA_Timers[client].bClientPaused || !gA_Timers[client].bTimerEnabled)
{
return MRES_Ignored;
return;
}

float interval = GetTickInterval();
Expand Down Expand Up @@ -3204,7 +3159,7 @@ public MRESReturn DHook_ProcessMovementPost(Handle hParams)
Call_PushCell(time);
Call_Finish();

return MRES_Ignored;
MaybeDoPhysicsUntouch(client);
}

// reference: https://github.com/momentum-mod/game/blob/5e2d1995ca7c599907980ee5b5da04d7b5474c61/mp/src/game/server/momentum/mom_timer.cpp#L388
Expand Down

0 comments on commit 069b408

Please sign in to comment.