Skip to content

Commit

Permalink
Add CRagdollProp - CreateServerRagdoll
Browse files Browse the repository at this point in the history
  • Loading branch information
Alienmario committed Jan 13, 2025
1 parent 2fb3c35 commit c052fdf
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 27 deletions.
3 changes: 0 additions & 3 deletions scripting/include/srccoop/globals.inc
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ ConVar sv_long_jump_manacost;
// ----------------------------
// SDK Calls
// ----------------------------
#if defined PLAYERPATCH_SERVERSIDE_RAGDOLLS
Handle g_pCreateServerRagdoll;
#endif

// ----------------------------
// DHooks
Expand Down
12 changes: 5 additions & 7 deletions scripting/include/srccoop/playerpatch.inc
Original file line number Diff line number Diff line change
Expand Up @@ -563,27 +563,25 @@ void PlayerPatch_ApplyServerRagdoll(const CBasePlayer pPlayer, const CTakeDamage
return;
}

CBaseAnimating pSourceEntity = pPlayer;

#if defined SRCCOOP_BLACKMESA
int iRagdollInheritIndex;
if (g_pIdle[pPlayer.entindex].m_pModel.IsValid())
{
// Player is currently using model for idle animations.
// The nodraw is required for hiding the player the tick he dies.
// The model that was parented is cleared since `CreateServerRagdoll` will not work otherwise.
pPlayer.m_fEffects |= EF_NODRAW;
g_pIdle[pPlayer.entindex].m_pModel.ClearParent();
iRagdollInheritIndex = g_pIdle[pPlayer.entindex].m_pModel.entindex;
pSourceEntity = g_pIdle[pPlayer.entindex].m_pModel;
}
else
{
pPlayer.m_fEffects &= ~EF_NODRAW;
iRagdollInheritIndex = pPlayer.entindex;
pSourceEntity.m_fEffects &= ~EF_NODRAW;
}
#else
int iRagdollInheritIndex = pPlayer.entindex;
#endif

pRagdoll = CRagdollProp(SDKCall(g_pCreateServerRagdoll, iRagdollInheritIndex, pPlayer.GetForceBone(), pTakeDamageInfo, COLLISION_GROUP_DEBRIS_TRIGGER, false));
pRagdoll = CreateServerRagdoll(pSourceEntity, pPlayer.GetForceBone(), pTakeDamageInfo, COLLISION_GROUP_DEBRIS_TRIGGER, false);
if (pRagdoll != NULL_CBASEENTITY)
{
SDKHook(pRagdoll.entindex, SDKHook_OnTakeDamage, Hook_NoDmg);
Expand Down
1 change: 1 addition & 0 deletions scripting/include/srccoop_api/classdef.inc
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ stock void InitClassdef(const GameData hGameConfig)
CBaseCombatWeapon.InitClassdef(hGameConfig);
CBaseCombatCharacter.InitClassdef(hGameConfig);
CBaseViewModel.InitClassdef(hGameConfig);
CRagdollProp.InitClassdef(hGameConfig);
CPlayerInfoManager.InitClassdef(hGameConfig);
AI_CriteriaSet.InitClassdef(hGameConfig);
IServerGameClients.InitClassdef(hGameConfig);
Expand Down
25 changes: 25 additions & 0 deletions scripting/include/srccoop_api/classdef/common/CRagdollProp.inc
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
#pragma newdecls required
#pragma semicolon 1

static Handle g_pCreateServerRagdoll;

methodmap CRagdollProp < CBaseAnimating
{
public static void InitClassdef(const GameData hGameConfig)
{
char szCreateServerRagdoll[] = "CreateServerRagdoll";
StartPrepSDKCall(SDKCall_Static);
if (!PrepSDKCall_SetFromConf(hGameConfig, SDKConf_Signature, szCreateServerRagdoll))
LogMessage("Could not obtain gamedata signature %s", szCreateServerRagdoll);
PrepSDKCall_SetReturnInfo(SDKType_CBaseEntity, SDKPass_Pointer);
PrepSDKCall_AddParameter(SDKType_CBaseEntity, SDKPass_Pointer); // CBaseAnimating *pAnimating
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain); // int forceBone
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain); // const CTakeDamageInfo &info
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain); // int collisionGroup
PrepSDKCall_AddParameter(SDKType_Bool, SDKPass_Plain); // bool bUseLRURetirement
if (!(g_pCreateServerRagdoll = EndPrepSDKCall()))
SetFailState("Could not prep SDK call %s", szCreateServerRagdoll);
}
public CRagdollProp(const int iEntIndex = -1)
{
return view_as<CRagdollProp>(CBaseAnimating(iEntIndex));
}
}

stock CRagdollProp CreateServerRagdoll(const CBaseAnimating pAnimating, const int iForceBone, const CTakeDamageInfo pInfo, const Collision_Group_t eCollisionGroup, const bool bUseLRURetirement = false)
{
return CRagdollProp
(
SDKCall(g_pCreateServerRagdoll, pAnimating.entindex, iForceBone, pInfo, eCollisionGroup, bUseLRURetirement)
);
}
17 changes: 0 additions & 17 deletions scripting/srccoop.sp
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,6 @@ void LoadGameData()

// Init SDKCalls for classdef
InitClassdef(pGameConfig);

// Calls

#if defined PLAYERPATCH_SERVERSIDE_RAGDOLLS
char szCreateServerRagdoll[] = "CreateServerRagdoll";
StartPrepSDKCall(SDKCall_Static);
if (!PrepSDKCall_SetFromConf(pGameConfig, SDKConf_Signature, szCreateServerRagdoll))
SetFailState("Could not obtain gamedata signature %s", szCreateServerRagdoll);
PrepSDKCall_SetReturnInfo(SDKType_CBaseEntity, SDKPass_Pointer);
PrepSDKCall_AddParameter(SDKType_CBaseEntity, SDKPass_Pointer); // CBaseAnimating *pAnimating
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain); // int forceBone
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain); // const CTakeDamageInfo &info
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain); // int collisionGroup
PrepSDKCall_AddParameter(SDKType_Bool, SDKPass_Plain); // bool bUseLRURetirement
if (!(g_pCreateServerRagdoll = EndPrepSDKCall()))
SetFailState("Could not prep SDK call %s", szCreateServerRagdoll);
#endif

LoadDHookVirtual(pGameConfig, hkLevelInit, "CServerGameDLL::LevelInit");
if (hkLevelInit.HookRaw(Hook_Pre, IServerGameDLL.Get().GetAddress(), Hook_OnLevelInit) == INVALID_HOOK_ID)
Expand Down

0 comments on commit c052fdf

Please sign in to comment.