Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pause CServerGameDLL::GameFrame #208

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions gamedata/srccoop.games.txt
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,20 @@
}
}
}
"CServerGameDLL::GameFrame"
{
"offset" "CServerGameDLL::GameFrame"
"hooktype" "raw"
"return" "void"
"this" "ignore"
"arguments"
{
"simulating"
{
"type" "bool"
}
}
}
"CEngineSoundServer::SetPlayerDSP"
{
"offset" "CEngineSoundServer::SetPlayerDSP"
Expand Down Expand Up @@ -690,19 +704,6 @@
}
}
}
"Physics_RunThinkFunctions"
{
"signature" "Physics_RunThinkFunctions"
"callconv" "cdecl"
"return" "void"
"arguments"
{
"simulating"
{
"type" "bool"
}
}
}
"CBoneSetup::AccumulatePose"
{
"signature" "CBoneSetup::AccumulatePose"
Expand Down Expand Up @@ -872,6 +873,7 @@
"signature" "UTIL_FindClientInPVSGuts"
"callconv" "cdecl"
"return" "edict"
"this" "ignore"
"arguments"
{
"pEdict"
Expand Down Expand Up @@ -1062,12 +1064,6 @@
"windows" "\x55\x8B\xEC\x83\xEC\x5C\x56\x57\x8B\xF9\x2A\x2A\x2A\x2A\x2A\x8B\xF0\x85\xF6\x2A\x2A\x2A\x2A\x2A\x2A"
"linux" "@_ZN11CWeapon_Tau8FireBeamERKfb"
}
"Physics_RunThinkFunctions"
{
// str: "sv_teststepsimulation" (referenced convar)
"windows" "\x55\x8B\xEC\x83\xEC\x08\xA1\x2A\x2A\x2A\x2A\x33\xC5\x89\x45\xFC\xA1\x2A\x2A\x2A\x2A"
"linux" "@_Z25Physics_RunThinkFunctionsb"
}
"CAI_ExpresserHost_NPC_DoModifyOrAppendCriteria"
{
"windows" "\x55\x8B\xEC\x83\xEC\x0C\x53\x56\x8B\x75\x08\x57\xFF\xB6\xA0\x09\x00\x00\x2A\x2A\x2A\x2A\x2A\x8B\x7D\x0C\x83\xC4"
Expand Down Expand Up @@ -1206,6 +1202,11 @@
"windows" "8"
"linux" "8"
}
"CServerGameDLL::GameFrame" // CServerGameDLL::GameFrame(bool)
{
"windows" "5"
"linux" "5"
}
"CMultiplayRules::FAllowFlashlight" // CMultiplayRules::FAllowFlashlight()
{
"windows" "56"
Expand Down Expand Up @@ -1609,12 +1610,6 @@
"windows" "\x55\x8B\xEC\x83\xEC\x0C\x53\x56\x57\xFF\x75\x08"
"linux" "@_Z16GlobalEntity_AddPKcS0_12GLOBALESTATE"
}
"Physics_RunThinkFunctions"
{
// str: "Trace: %d, contents %d, enumerate %d" (in caller)
"windows" "\x55\x8B\xEC\x51\xA1\x2A\x2A\x2A\x2A\xB9\x2A\x2A\x2A\x2A\x53\x56\x57\x83\x78\x30\x00\xA1"
"linux" "@_Z25Physics_RunThinkFunctionsb"
}
"CAI_ExpresserHost_NPC_DoModifyOrAppendCriteria"
{
"windows" "\x55\x8B\xEC\x83\xEC\x0C\x53\x56\x8B\x75\x08\x57\xFF\xB6\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\x8B\x2A\x2A\x83\xC4\x04" // str: "timesincecombat"
Expand Down Expand Up @@ -1707,6 +1702,11 @@
"windows" "8"
"linux" "8"
}
"CServerGameDLL::GameFrame" // CServerGameDLL::GameFrame(bool)
{
"windows" "5"
"linux" "5"
}
"CMultiplayRules::IsMultiplayer" // CMultiplayRules::IsMultiplayer()
{
"windows" "34"
Expand Down
4 changes: 2 additions & 2 deletions scripting/include/srccoop/entitypatch.inc
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,11 @@ public MRESReturn Hook_BaseNPCThinkPost(int _this)
}

//------------------------------------------------------
// Physics_RunThinkFunctions - The main physics simulation loop against all entities
// CServerGameDLL::GameFrame
// This hook is only active when there are no real players on the server!
// Its main purpose is to ensure NPCs can always find a valid player pointer when thinking.
//------------------------------------------------------
public MRESReturn Hook_Physics_RunThinkFunctions(DHookParam hParams)
public MRESReturn Hook_GameFrame(DHookParam hParams)
{
return MRES_Supercede;
}
Expand Down
3 changes: 2 additions & 1 deletion scripting/include/srccoop/globals.inc
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ DynamicDetour hkBaseNpcUpdateSleepState;
#endif

#if defined ENTPATCH_NPC_THINK_LOCALPLAYER
DynamicDetour hkPhysics_RunThinkFunctions;
int g_iGameFrameHookId = INVALID_HOOK_ID;
DynamicHook hkGameFrame;
#endif

#if defined ENTPATCH_BM_DISSOLVE
Expand Down
19 changes: 11 additions & 8 deletions scripting/srccoop.sp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ void LoadGameData()
if (hkLevelInit.HookRaw(Hook_Pre, IServerGameDLL.Get().GetAddress(), Hook_OnLevelInit) == INVALID_HOOK_ID)
SetFailState("Could not hook CServerGameDLL::LevelInit");

#if defined ENTPATCH_NPC_THINK_LOCALPLAYER
LoadDHookVirtual(pGameConfig, hkGameFrame, "CServerGameDLL::GameFrame");
if ((g_iGameFrameHookId = hkGameFrame.HookRaw(Hook_Pre, IServerGameDLL.Get().GetAddress(), Hook_GameFrame)) == INVALID_HOOK_ID)
SetFailState("Could not hook CServerGameDLL::GameFrame");
#endif

LoadDHookVirtual(pGameConfig, hkChangeTeam, "CBasePlayer::ChangeTeam");
LoadDHookVirtual(pGameConfig, hkShouldCollide, "CBaseEntity::ShouldCollide");
LoadDHookVirtual(pGameConfig, hkPlayerSpawn, "CBasePlayer::Spawn");
Expand Down Expand Up @@ -164,10 +170,6 @@ void LoadGameData()
LoadDHookDetour(pGameConfig, hkPickup_ForcePlayerToDropThisObject, "Pickup_ForcePlayerToDropThisObject", Hook_ForcePlayerToDropThisObject);
#endif

#if defined ENTPATCH_NPC_THINK_LOCALPLAYER
LoadDHookDetour(pGameConfig, hkPhysics_RunThinkFunctions, "Physics_RunThinkFunctions", Hook_Physics_RunThinkFunctions);
#endif

#if defined ENTPATCH_BM_DISSOLVE
LoadDHookDetour(pGameConfig, hkDissolve, "CBaseAnimating::Dissolve", Hook_Dissolve);
#endif
Expand Down Expand Up @@ -467,8 +469,9 @@ public void OnClientPutInServer(int client)
if (!g_iPlayerCount++)
{
#if defined ENTPATCH_NPC_THINK_LOCALPLAYER
// resume entity thinking
hkPhysics_RunThinkFunctions.Disable(Hook_Pre, Hook_Physics_RunThinkFunctions);
// resume running frames
DynamicHook.RemoveHook(g_iGameFrameHookId);
g_iGameFrameHookId = INVALID_HOOK_ID;
#endif
}

Expand Down Expand Up @@ -538,8 +541,8 @@ public void OnClientDisconnect_Post(int client)
#if defined ENTPATCH_NPC_THINK_LOCALPLAYER
if (!g_iPlayerCount)
{
// pause entity thinking
hkPhysics_RunThinkFunctions.Enable(Hook_Pre, Hook_Physics_RunThinkFunctions);
// pause running frames
g_iGameFrameHookId = hkGameFrame.HookRaw(Hook_Pre, IServerGameDLL.Get().GetAddress(), Hook_GameFrame);
}
#endif
}
Expand Down
Loading