Skip to content

Commit 069b408

Browse files
committed
Migrate from ProcessMovement/ProcessMovementPost to PreThink/PostThinkPost
1 parent 1d7545d commit 069b408

File tree

2 files changed

+16
-83
lines changed

2 files changed

+16
-83
lines changed

addons/sourcemod/gamedata/shavit.games.txt

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,8 @@
44

55
"#default"
66
{
7-
"Keys"
8-
{
9-
"IGameMovement" "GameMovement001"
10-
}
11-
127
"Signatures"
138
{
14-
"CreateInterface_Server"
15-
{
16-
"library" "server"
17-
"windows" "@CreateInterface"
18-
"windows64" "@CreateInterface"
19-
"linux" "@CreateInterface"
20-
"linux64" "@CreateInterface"
21-
}
22-
239
"CreateInterface_Engine"
2410
{
2511
"library" "engine"
@@ -47,14 +33,6 @@
4733
"linux" "0"
4834
"linux64" "1"
4935
}
50-
51-
"ProcessMovement"
52-
{
53-
"windows" "1"
54-
"windows64" "1"
55-
"linux" "2"
56-
"linux64" "2"
57-
}
5836
}
5937
}
6038

addons/sourcemod/scripting/shavit-core.sp

Lines changed: 16 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -484,52 +484,6 @@ void LoadDHooks()
484484
SetFailState("Failed to load shavit gamedata");
485485
}
486486

487-
StartPrepSDKCall(SDKCall_Static);
488-
if(!PrepSDKCall_SetFromConf(gamedataConf, SDKConf_Signature, "CreateInterface_Server"))
489-
{
490-
SetFailState("Failed to get CreateInterface");
491-
}
492-
PrepSDKCall_AddParameter(SDKType_String, SDKPass_Pointer);
493-
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Pointer, VDECODE_FLAG_ALLOWNULL);
494-
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
495-
Handle CreateInterface = EndPrepSDKCall();
496-
497-
if(CreateInterface == null)
498-
{
499-
SetFailState("Unable to prepare SDKCall for CreateInterface");
500-
}
501-
502-
char interfaceName[64];
503-
504-
// ProcessMovement
505-
if(!GameConfGetKeyValue(gamedataConf, "IGameMovement", interfaceName, sizeof(interfaceName)))
506-
{
507-
SetFailState("Failed to get IGameMovement interface name");
508-
}
509-
510-
Address IGameMovement = SDKCall(CreateInterface, interfaceName, 0);
511-
512-
if(!IGameMovement)
513-
{
514-
SetFailState("Failed to get IGameMovement pointer");
515-
}
516-
517-
int offset = GameConfGetOffset(gamedataConf, "ProcessMovement");
518-
if(offset == -1)
519-
{
520-
SetFailState("Failed to get ProcessMovement offset");
521-
}
522-
523-
Handle processMovement = DHookCreate(offset, HookType_Raw, ReturnType_Void, ThisPointer_Ignore, DHook_ProcessMovement);
524-
DHookAddParam(processMovement, HookParamType_CBaseEntity);
525-
DHookAddParam(processMovement, HookParamType_ObjectPtr);
526-
DHookRaw(processMovement, false, IGameMovement);
527-
528-
Handle processMovementPost = DHookCreate(offset, HookType_Raw, ReturnType_Void, ThisPointer_Ignore, DHook_ProcessMovementPost);
529-
DHookAddParam(processMovementPost, HookParamType_CBaseEntity);
530-
DHookAddParam(processMovementPost, HookParamType_ObjectPtr);
531-
DHookRaw(processMovementPost, true, IGameMovement);
532-
533487
gB_Linux = GameConfGetOffset(gamedataConf, "OS") == 2;
534488

535489
if (gEV_Type == Engine_TF2 && gB_Linux)
@@ -563,12 +517,11 @@ void LoadDHooks()
563517

564518
LoadPhysicsUntouch(gamedataConf);
565519

566-
delete CreateInterface;
567520
delete gamedataConf;
568521

569522
gamedataConf = LoadGameConfigFile("sdktools.games");
570523

571-
offset = GameConfGetOffset(gamedataConf, "AcceptInput");
524+
int offset = GameConfGetOffset(gamedataConf, "AcceptInput");
572525
gH_AcceptInput = new DynamicHook(offset, HookType_Entity, ReturnType_Bool, ThisPointer_CBaseEntity);
573526
gH_AcceptInput.AddParam(HookParamType_CharPtr);
574527
gH_AcceptInput.AddParam(HookParamType_CBaseEntity);
@@ -583,7 +536,6 @@ void LoadDHooks()
583536
}
584537

585538
gH_TeleportDhook = new DynamicHook(offset, HookType_Entity, ReturnType_Void, ThisPointer_CBaseEntity);
586-
587539
gH_TeleportDhook.AddParam(HookParamType_VectorPtr);
588540
gH_TeleportDhook.AddParam(HookParamType_VectorPtr);
589541
gH_TeleportDhook.AddParam(HookParamType_VectorPtr);
@@ -2739,6 +2691,7 @@ public void OnClientPutInServer(int client)
27392691
CallOnStyleChanged(client, 0, gI_DefaultStyle, false);
27402692
}
27412693

2694+
SDKHook(client, SDKHook_PreThink, PreThink);
27422695
SDKHook(client, SDKHook_PreThinkPost, PreThinkPost);
27432696
SDKHook(client, SDKHook_PostThinkPost, PostThinkPost);
27442697
}
@@ -2923,8 +2876,15 @@ public void Shavit_OnLeaveZone(int client, int type, int track, int id, int enti
29232876
UpdateStyleSettings(client);
29242877
}
29252878

2879+
public void PreThink(int client)
2880+
{
2881+
FakeProcessMovementPre(client);
2882+
}
2883+
29262884
public void PreThinkPost(int client)
29272885
{
2886+
FakeProcessMovementPost(client);
2887+
29282888
if(IsPlayerAlive(client))
29292889
{
29302890
if (!gB_Zones || !Shavit_InsideZone(client, Zone_Airaccelerate, gA_Timers[client].iTimerTrack))
@@ -3088,9 +3048,8 @@ public MRESReturn DHook_PreventBunnyJumpingPre()
30883048
return MRES_Ignored;
30893049
}
30903050

3091-
public MRESReturn DHook_ProcessMovement(Handle hParams)
3051+
void FakeProcessMovementPre(int client)
30923052
{
3093-
int client = DHookGetParam(hParams, 1);
30943053
gI_ClientProcessingMovement = client;
30953054

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

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

3127-
return MRES_Ignored;
3086+
return;
31283087
}
31293088

31303089
// i got this code from kid-tas by kid fearless
@@ -3149,21 +3108,17 @@ public MRESReturn DHook_ProcessMovement(Handle hParams)
31493108
{
31503109
SetClientEventsPaused(client, (!Shavit_ShouldProcessFrame(client) || gA_Timers[client].bClientPaused));
31513110
}
3152-
3153-
return MRES_Ignored;
31543111
}
31553112

3156-
public MRESReturn DHook_ProcessMovementPost(Handle hParams)
3113+
void FakeProcessMovementPost(int client)
31573114
{
3158-
int client = DHookGetParam(hParams, 1);
3159-
31603115
Call_StartForward(gH_Forwards_OnProcessMovementPost);
31613116
Call_PushCell(client);
31623117
Call_Finish();
31633118

31643119
if (IsFakeClient(client) || !IsPlayerAlive(client))
31653120
{
3166-
return MRES_Ignored;
3121+
return;
31673122
}
31683123

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

31753130
if (gA_Timers[client].bClientPaused || !gA_Timers[client].bTimerEnabled)
31763131
{
3177-
return MRES_Ignored;
3132+
return;
31783133
}
31793134

31803135
float interval = GetTickInterval();
@@ -3204,7 +3159,7 @@ public MRESReturn DHook_ProcessMovementPost(Handle hParams)
32043159
Call_PushCell(time);
32053160
Call_Finish();
32063161

3207-
return MRES_Ignored;
3162+
MaybeDoPhysicsUntouch(client);
32083163
}
32093164

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

0 commit comments

Comments
 (0)