Skip to content
Merged
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
17 changes: 17 additions & 0 deletions gamedata/srccoop.games.txt
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,13 @@
"return" "void"
"this" "entity"
}
"CBasePlayer::Weapon_ShootPosition"
{
"offset" "CBasePlayer::Weapon_ShootPosition"
"hooktype" "entity"
"return" "vector"
"this" "entity"
}

// _____ ______ _______ ____ _ _ _____
// | __ \| ____|__ __/ __ \| | | | __ \
Expand Down Expand Up @@ -1449,6 +1456,11 @@
"windows" "239"
"linux" "289"
}
"CBasePlayer::Weapon_ShootPosition" // CBasePlayer::Weapon_ShootPosition()
{
"windows" "285"
"linux" "286"
}
}
}

Expand Down Expand Up @@ -1808,6 +1820,11 @@
"windows" "13"
"linux" "13"
}
"CBasePlayer::Weapon_ShootPosition" // CBasePlayer::Weapon_ShootPosition()
{
"windows" "271"
"linux" "272"
}
}
}
}
2 changes: 2 additions & 0 deletions scripting/include/srccoop.inc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#define PLAYERPATCH_SUIT_SOUNDS
#define PLAYERPATCH_PICKUP_FORCEPLAYERTODROPTHISOBJECT
#define PLAYERPATCH_SERVERSIDE_RAGDOLLS
#define PLAYERPATCH_HITREG

#define GAMEPATCH_UTIL_GETLOCALPLAYER
#define GAMEPATCH_IS_MULTIPLAYER
Expand Down Expand Up @@ -115,6 +116,7 @@
#define PLAYERPATCH_RESTORE_MP_FORCERESPAWN
#define PLAYERPATCH_OVERRIDE_DEATH_OBSMODE
#define PLAYERPATCH_FINDLADDER
#define PLAYERPATCH_HITREG

#define GAMEPATCH_UTIL_GETLOCALPLAYER
#define GAMEPATCH_IS_MULTIPLAYER
Expand Down
33 changes: 33 additions & 0 deletions scripting/include/srccoop/classdef.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,31 @@ methodmap CBaseTrigger < CBaseToggle
}
}

methodmap CTriggerPush < CBaseTrigger
{
public CTriggerPush(const int iEntIndex = -1)
{
return view_as<CTriggerPush>(CBaseTrigger(iEntIndex));
}

public float GetPushSpeed()
{
return GetEntPropFloat(this.GetEntIndex(), Prop_Data, "m_flSpeed");
}
public void SetPushSpeed(const float flSpeed)
{
SetEntPropFloat(this.GetEntIndex(), Prop_Data, "m_flSpeed", flSpeed);
}
public void GetPushDirection(float vecBuffer[3])
{
GetEntPropVector(this.GetEntIndex(), Prop_Data, "m_vecPushDir", vecBuffer);
}
public void SetPushDirection(const float vec3Direction[3])
{
SetEntPropVector(this.GetEntIndex(), Prop_Data, "m_vecPushDir", vec3Direction);
}
}

methodmap CChangelevel < CBaseTrigger
{
public CChangelevel(const int iEntIndex = -1)
Expand Down Expand Up @@ -2650,6 +2675,14 @@ methodmap CBasePlayer < CBaseCombatCharacter
}
#endif
}
public float GetLaggedMovement()
{
return GetEntPropFloat(this.GetEntIndex(), Prop_Data, "m_flLaggedMovementValue");
}
public void SetLaggedMovement(const float flValue)
{
SetEntPropFloat(this.GetEntIndex(), Prop_Data, "m_flLaggedMovementValue", flValue);
}
}

methodmap CBeam < CBaseEntity
Expand Down
4 changes: 4 additions & 0 deletions scripting/include/srccoop/globals.inc
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ DynamicHook hkForceRespawn;
DynamicHook hkStartObserverMode;
#endif

#if defined PLAYERPATCH_HITREG
DynamicHook hkPlayerWeaponShootPosition;
#endif

#if defined ENTPATCH_BM_SP_WEAPONS
DynamicHook hkBaseCombatWeaponItemPostFrame;
DynamicHook hkBaseCombatWeaponDeploy;
Expand Down
24 changes: 22 additions & 2 deletions scripting/include/srccoop/playerpatch.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#pragma newdecls required
#pragma semicolon 1

static float g_vec3PlayerShootPosition[MAXPLAYERS + 1][3];

//------------------------------------------------------
// Allow flashlight
//------------------------------------------------------
Expand Down Expand Up @@ -151,13 +153,14 @@ public MRESReturn Hook_PlayerStartObserverMode(int iClient, DHookReturn hReturn,
//------------------------------------------------------
public Action OnPlayerRunCmd(int iClient, int &iButtons, int &iImpulse, float fVel[3], float fAngles[3], int &iWeapon, int& subtype, int& cmdnum, int& tickcount, int& seed, int mouse[2])
{
CBasePlayer pClient = CBasePlayer(iClient);
pClient.GetEyePosition(g_vec3PlayerShootPosition[iClient]);

if (IsFakeClient(iClient) || !CoopManager.IsCoopModeEnabled())
return Plugin_Continue;

if (mouse[0] || mouse[1])
g_bPostTeamSelect[iClient] = true;

CBasePlayer pClient = CBasePlayer(iClient);

// Spectator fixes; Credits: harper
Obs_Mode iObsMode = view_as<Obs_Mode>(GetEntProp(iClient, Prop_Send, "m_iObserverMode"));
Expand Down Expand Up @@ -612,6 +615,23 @@ public Action Hook_PlayerTakeDamage(int victim, int &attacker, int &inflictor, f
return Plugin_Continue;
}

// Fixes hit registration being off by 1 tick.
// Credits to Xutax_Kamay (https://forums.alliedmods.net/showthread.php?t=315405)
public MRESReturn Hook_PlayerWeaponShootPosition_Post(int iClient, Handle hReturn)
{
CBasePlayer pPlayer = CBasePlayer(iClient);
// Objects that are carried will call this hook and lag further behind the desired position.
if (pPlayer.GetCarriedObject() == NULL_CBASEENTITY)
{
DHookSetReturnVector(hReturn, g_vec3PlayerShootPosition[iClient]);
return MRES_Supercede;
}
else
{
return MRES_Ignored;
}
}

//------------------------------------------------------
// Player team change hooks
// - Force everyone to single team in TDM
Expand Down
7 changes: 7 additions & 0 deletions scripting/srccoop.sp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ void LoadGameData()
#if defined PLAYERPATCH_OVERRIDE_DEATH_OBSMODE
LoadDHookVirtual(pGameConfig, hkStartObserverMode, "CBasePlayer::StartObserverMode");
#endif

#if defined PLAYERPATCH_HITREG
LoadDHookVirtual(pGameConfig, hkPlayerWeaponShootPosition, "CBasePlayer::Weapon_ShootPosition");
#endif

#if defined ENTPATCH_BM_SP_WEAPONS
LoadDHookVirtual(pGameConfig, hkBaseCombatWeaponDeploy, "CBaseCombatWeapon::Deploy");
Expand Down Expand Up @@ -473,6 +477,9 @@ public void OnClientPutInServer(int client)
SDKHook(client, SDKHook_TraceAttack, Hook_PlayerTraceAttack);
SDKHook(client, SDKHook_OnTakeDamage, Hook_PlayerTakeDamage);
SDKHook(client, SDKHook_WeaponEquipPost, Hook_PlayerWeaponEquipPost);
#if defined PLAYERPATCH_HITREG
DHookEntity(hkPlayerWeaponShootPosition, true, client, _, Hook_PlayerWeaponShootPosition_Post);
#endif
DHookEntity(hkChangeTeam, false, client, _, Hook_PlayerChangeTeam);
DHookEntity(hkChangeTeam, true, client, _, Hook_PlayerChangeTeamPost);
DHookEntity(hkShouldCollide, false, client, _, Hook_PlayerShouldCollide);
Expand Down