Skip to content

Commit

Permalink
Direct fix for damage effects (#152)
Browse files Browse the repository at this point in the history
Unblocks sending missing TE's (impact effects) by disabling serverside prediction recipient culling
Replaces srccoop_addon_effects_fix.
  • Loading branch information
Alienmario authored Oct 15, 2024
1 parent a50a26a commit 2aebc23
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 177 deletions.
65 changes: 65 additions & 0 deletions gamedata/srccoop.games.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
"windows" "IEngineSoundServer003"
"linux" "IEngineSoundServer003"
}
"IServerTools"
{
"windows" "VSERVERTOOLS003"
"linux" "VSERVERTOOLS003"
}
"PlayerInfoManager"
{
"windows" "PlayerInfoManager002"
Expand Down Expand Up @@ -60,6 +65,11 @@
"windows" "44"
"linux" "44"
}
"CServerTools::GetTempEntsSystem"
{
"windows" "32"
"linux" "33"
}
}
"Signatures"
{
Expand Down Expand Up @@ -555,6 +565,39 @@
}
}
}
"CTempEntsSystem::DispatchEffect"
{
"offset" "CTempEntsSystem::DispatchEffect"
"hooktype" "raw"
"return" "void"
"this" "ignore"
"arguments"
{
"filter"
{
"type" "objectptr"
"flags" "byref"
}
"delay"
{
"type" "float"
}
"pos"
{
"type" "vectorptr"
"flags" "byref"
}
"pName"
{
"type" "charptr"
}
"data"
{
"type" "objectptr"
"flags" "byref"
}
}
}

// _____ ______ _______ ____ _ _ _____
// | __ \| ____|__ __/ __ \| | | | __ \
Expand Down Expand Up @@ -767,6 +810,13 @@
}
}
}
"CRecipientFilter::IgnorePredictionCull"
{
"signature" "CRecipientFilter::IgnorePredictionCull"
"callconv" "thiscall"
"return" "bool"
"this" "ignore"
}
}
}

Expand Down Expand Up @@ -930,6 +980,11 @@
"windows" "\x55\x8B\xEC\x83\xEC\x50\xA1\x2A\x2A\x2A\x2A\x33\xC5\x89\x45\x2A\x53\x8B\x5D\x2A\xB8\xFF\xFF\x00\x00"
"linux" "@_ZN14AI_CriteriaSet14AppendCriteriaEPKcS1_f"
}
"CRecipientFilter::IgnorePredictionCull"
{
"windows" "\x8A\x41\x1D"
"linux" "@_ZNK16CRecipientFilter20IgnorePredictionCullEv"
}
}

// ____ __ __ _____ __ __ ______ __ __ _____ _______ _____ _ _ ______ _____
Expand Down Expand Up @@ -1248,6 +1303,11 @@
"windows" "1"
"linux" "1"
}
"CTempEntsSystem::DispatchEffect" // CTempEntsSystem::DispatchEffect(IRecipientFilter&, float, Vector const&, char const*, CEffectData const&)
{
"windows" "39"
"linux" "40"
}
}
}

Expand Down Expand Up @@ -1577,6 +1637,11 @@
"windows" "1"
"linux" "1"
}
"CTempEntsSystem::DispatchEffect" // CTempEntsSystem::DispatchEffect(IRecipientFilter&, float, Vector const&, char const*, CEffectData const&)
{
"windows" "38"
"linux" "39"
}
}
}
}
1 change: 1 addition & 0 deletions scripting/include/srccoop.inc
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
#define GAMEPATCH_BLOCK_ANNOUNCER
#define GAMEPATCH_ALLOW_FLASHLIGHT
#define GAMEPATCH_TEAMSELECT_UI
#define GAMEPATCH_PREDICTED_EFFECTS

#endif // SRCCOOP_BLACKMESA

Expand Down
24 changes: 24 additions & 0 deletions scripting/include/srccoop/classdef.inc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Handle g_pGlobalEntitySetState;
Handle g_pGlobalEntitySetCounter;
Handle g_pGlobalEntityAdd;
Handle g_pGameShutdown;
Handle g_pGetTempEntsSystem;
Handle g_pSetCollisionBounds;
Handle g_pQueryHearSound;
Handle g_pGetSoundInterests;
Expand Down Expand Up @@ -216,6 +217,16 @@ stock void InitClassdef(GameData pGameConfig)
if (!(g_pGameShutdown = EndPrepSDKCall())) SetFailState("Could not prep SDK call %s", szGameShutdown);
}

char szGetTempEntsSystem[] = "CServerTools::GetTempEntsSystem";
StartPrepSDKCall(SDKCall_Raw);
if (!PrepSDKCall_SetFromConf(pGameConfig, SDKConf_Virtual, szGetTempEntsSystem))
LogMessage("Could not obtain gamedata offset %s", szGetTempEntsSystem);
else
{
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
if (!(g_pGetTempEntsSystem = EndPrepSDKCall())) SetFailState("Could not prep SDK call %s", szGetTempEntsSystem);
}

char szQueryHearSound[] = "CAI_BaseNPC::QueryHearSound";
StartPrepSDKCall(SDKCall_Entity);
if (!PrepSDKCall_SetFromConf(pGameConfig, SDKConf_Virtual, szQueryHearSound))
Expand Down Expand Up @@ -2990,6 +3001,19 @@ methodmap IServerGameDLL
}
}

methodmap IServerTools
{
public IServerTools(Address pAddress)
{
return view_as<IServerTools>(pAddress);
}

public Address GetTempEntsSystem()
{
return SDKCall(g_pGetTempEntsSystem, this);
}
}

/**
* The player state is an embedded class inside of player that is shared with the engine.
* The Engine uses some of this data for responding to external server queries.
Expand Down
28 changes: 27 additions & 1 deletion scripting/include/srccoop/entitypatch.inc
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public MRESReturn Hook_FindNamedEntity(int _this, Handle hReturn, Handle hParams
if (pActor.IsValid())
{
CBasePlayer pBestPlayer = GetNearestPlayer(pActor);
if (pBestPlayer.IsValid())
if (pBestPlayer != NULL_CBASEENTITY)
{
DHookSetReturn(hReturn, pBestPlayer.GetEntIndex());
return MRES_Supercede;
Expand Down Expand Up @@ -1355,3 +1355,29 @@ public MRESReturn Hook_TrackTrainBlocked(int _this, Handle hReturn, Handle hPara

return MRES_Ignored;
}

//------------------------------------------------------
// Unblocks sending missing TE's (impact effects)
// by disabling serverside prediction recipient culling
//------------------------------------------------------
bool g_bIgnorePredictionCull = true;

public MRESReturn Hook_IgnorePredictionCull(DHookReturn hReturn)
{
hReturn.Value = g_bIgnorePredictionCull;
g_bIgnorePredictionCull = true; // reset for next call
return MRES_Supercede;
}

public MRESReturn Hook_DispatchEffect(DHookParam hParams)
{
// World impacts are correctly predicted by client.
// Filter them out out of the server dispatched ones.
char szName[16];
hParams.GetString(4, szName, sizeof(szName));
if (StrEqual(szName, "Impact"))
{
g_bIgnorePredictionCull = false;
}
return MRES_Ignored;
}
6 changes: 6 additions & 0 deletions scripting/include/srccoop/globals.inc
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ DynamicDetour hkBaseNpcUpdateSleepState;
DynamicDetour hkPhysics_RunThinkFunctions;
#endif

#if defined GAMEPATCH_PREDICTED_EFFECTS
DynamicDetour hkIgnorePredictionCull;
DynamicHook hkDispatchEffect;
#endif

#if defined SRCCOOP_HL2DM && defined PLAYERPATCH_SERVERSIDE_RAGDOLLS
DynamicHook hkCreateRagdollEntity;
#endif
Expand All @@ -160,6 +165,7 @@ DynamicDetour hkTestGroundMove;
// Adresses, Interfaces
// ----------------------------
IServerGameDLL g_ServerGameDLL;
IServerTools g_ServerTools;

// ----------------------------
// Plugin variables
Expand Down
16 changes: 13 additions & 3 deletions scripting/srccoop.sp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ void LoadGameData()

g_serverOS = view_as<OperatingSystem>(pGameConfig.GetOffset("_OS_Detector_"));

// Init SDKCalls for classdef
InitClassdef(pGameConfig);

if (!(g_ServerGameDLL = IServerGameDLL(GetInterface(pGameConfig, "server", "IServerGameDLL"))))
SetFailState("Could not get interface for %s", "IServerGameDLL");

if (!(g_ServerTools = IServerTools(GetInterface(pGameConfig, "server", "IServerTools"))))
SetFailState("Could not get interface for %s", "IServerTools");

// Calls

Expand Down Expand Up @@ -159,6 +165,13 @@ void LoadGameData()
LoadDHookDetour(pGameConfig, hkPhysics_RunThinkFunctions, "Physics_RunThinkFunctions", Hook_Physics_RunThinkFunctions);
#endif

#if defined GAMEPATCH_PREDICTED_EFFECTS
LoadDHookDetour(pGameConfig, hkIgnorePredictionCull, "CRecipientFilter::IgnorePredictionCull", Hook_IgnorePredictionCull);
LoadDHookVirtual(pGameConfig, hkDispatchEffect, "CTempEntsSystem::DispatchEffect");
if (hkDispatchEffect.HookRaw(Hook_Pre, g_ServerTools.GetTempEntsSystem(), Hook_DispatchEffect) == INVALID_HOOK_ID)
SetFailState("Could not hook CTempEntsSystem::DispatchEffect");
#endif

#if defined SRCCOOP_BLACKMESA
if (g_serverOS == OS_Linux)
{
Expand All @@ -177,9 +190,6 @@ void LoadGameData()
LoadMemPatch(pGameConfig, "CLagCompensationManager::RestoreEntityFromRecords::SetPoseParameter", true, false);
LoadMemPatch(pGameConfig, "CLagCompensationManager::BacktrackEntity::SetPoseParameter", true, false);
#endif

// Init SDKCalls for classdef
InitClassdef(pGameConfig);

pGameConfig.Close();
}
Expand Down
Loading

0 comments on commit 2aebc23

Please sign in to comment.