From ea5046827d0772ff43327ec400f607a2eb1cbec1 Mon Sep 17 00:00:00 2001 From: ampreeT <61920833+ampreeT@users.noreply.github.com> Date: Wed, 27 Nov 2024 15:39:33 -0800 Subject: [PATCH 1/3] Hit Registration Fix --- gamedata/srccoop.games.txt | 17 ++++++++++++ scripting/include/srccoop.inc | 2 ++ scripting/include/srccoop/classdef.inc | 33 +++++++++++++++++++++++ scripting/include/srccoop/globals.inc | 4 +++ scripting/include/srccoop/playerpatch.inc | 24 +++++++++++++++-- scripting/srccoop.sp | 7 +++++ 6 files changed, 85 insertions(+), 2 deletions(-) diff --git a/gamedata/srccoop.games.txt b/gamedata/srccoop.games.txt index a0d0235d..7f01ad82 100644 --- a/gamedata/srccoop.games.txt +++ b/gamedata/srccoop.games.txt @@ -600,6 +600,13 @@ "return" "void" "this" "entity" } + "CBasePlayer::Weapon_ShootPosition" + { + "offset" "CBasePlayer::Weapon_ShootPosition" + "hooktype" "entity" + "return" "vector" + "this" "entity" + } // _____ ______ _______ ____ _ _ _____ // | __ \| ____|__ __/ __ \| | | | __ \ @@ -1449,6 +1456,11 @@ "windows" "239" "linux" "289" } + "CBasePlayer::Weapon_ShootPosition" // CBasePlayer::Weapon_ShootPosition() + { + "windows" "285" + "linux" "286" + } } } @@ -1808,6 +1820,11 @@ "windows" "13" "linux" "13" } + "CBasePlayer::Weapon_ShootPosition" // CBasePlayer::Weapon_ShootPosition() + { + "windows" "265" + "linux" "266" + } } } } \ No newline at end of file diff --git a/scripting/include/srccoop.inc b/scripting/include/srccoop.inc index bbaeea5e..3366c712 100644 --- a/scripting/include/srccoop.inc +++ b/scripting/include/srccoop.inc @@ -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 @@ -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 diff --git a/scripting/include/srccoop/classdef.inc b/scripting/include/srccoop/classdef.inc index 59e4f6cf..4ffbe58d 100644 --- a/scripting/include/srccoop/classdef.inc +++ b/scripting/include/srccoop/classdef.inc @@ -1267,6 +1267,31 @@ methodmap CBaseTrigger < CBaseToggle } } +methodmap CTriggerPush < CBaseTrigger +{ + public CTriggerPush(const int iEntIndex = -1) + { + return view_as(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) @@ -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 diff --git a/scripting/include/srccoop/globals.inc b/scripting/include/srccoop/globals.inc index 8767e040..f365186b 100644 --- a/scripting/include/srccoop/globals.inc +++ b/scripting/include/srccoop/globals.inc @@ -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; diff --git a/scripting/include/srccoop/playerpatch.inc b/scripting/include/srccoop/playerpatch.inc index a9bf3b27..f066b946 100644 --- a/scripting/include/srccoop/playerpatch.inc +++ b/scripting/include/srccoop/playerpatch.inc @@ -6,6 +6,8 @@ #pragma newdecls required #pragma semicolon 1 +static float g_pvec3PlayerShootPosition[MAXPLAYERS][3]; + //------------------------------------------------------ // Allow flashlight //------------------------------------------------------ @@ -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_pvec3PlayerShootPosition[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(GetEntProp(iClient, Prop_Send, "m_iObserverMode")); @@ -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 hParams) +{ + 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(hParams, g_pvec3PlayerShootPosition[iClient]); + return MRES_Supercede; + } + else + { + return MRES_Ignored; + } +} + //------------------------------------------------------ // Player team change hooks // - Force everyone to single team in TDM diff --git a/scripting/srccoop.sp b/scripting/srccoop.sp index 85831c84..b54f06b6 100644 --- a/scripting/srccoop.sp +++ b/scripting/srccoop.sp @@ -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"); @@ -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); From 6d418b7682865f13765e052f8f8d7f9b81f5fb92 Mon Sep 17 00:00:00 2001 From: ampreeT <61920833+ampreeT@users.noreply.github.com> Date: Wed, 27 Nov 2024 18:15:37 -0800 Subject: [PATCH 2/3] Fixed HL2DM `Weapon_ShootPosition` offset --- gamedata/srccoop.games.txt | 4 ++-- scripting/include/srccoop/playerpatch.inc | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gamedata/srccoop.games.txt b/gamedata/srccoop.games.txt index 7f01ad82..7ae80df2 100644 --- a/gamedata/srccoop.games.txt +++ b/gamedata/srccoop.games.txt @@ -1822,8 +1822,8 @@ } "CBasePlayer::Weapon_ShootPosition" // CBasePlayer::Weapon_ShootPosition() { - "windows" "265" - "linux" "266" + "windows" "271" + "linux" "272" } } } diff --git a/scripting/include/srccoop/playerpatch.inc b/scripting/include/srccoop/playerpatch.inc index f066b946..f2b429c0 100644 --- a/scripting/include/srccoop/playerpatch.inc +++ b/scripting/include/srccoop/playerpatch.inc @@ -6,7 +6,7 @@ #pragma newdecls required #pragma semicolon 1 -static float g_pvec3PlayerShootPosition[MAXPLAYERS][3]; +static float g_vec3PlayerShootPosition[MAXPLAYERS + 1][3]; //------------------------------------------------------ // Allow flashlight @@ -154,7 +154,7 @@ 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_pvec3PlayerShootPosition[iClient]); + pClient.GetEyePosition(g_vec3PlayerShootPosition[iClient]); if (IsFakeClient(iClient) || !CoopManager.IsCoopModeEnabled()) return Plugin_Continue; @@ -617,13 +617,13 @@ public Action Hook_PlayerTakeDamage(int victim, int &attacker, int &inflictor, f // 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 hParams) +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(hParams, g_pvec3PlayerShootPosition[iClient]); + DHookSetReturnVector(hParams, g_vec3PlayerShootPosition[iClient]); return MRES_Supercede; } else From 562c8e8cf663cacfd4c78580e1ed54b14c9144fb Mon Sep 17 00:00:00 2001 From: ampreeT <61920833+ampreeT@users.noreply.github.com> Date: Wed, 27 Nov 2024 18:23:18 -0800 Subject: [PATCH 3/3] Fixed variable error --- scripting/include/srccoop/playerpatch.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripting/include/srccoop/playerpatch.inc b/scripting/include/srccoop/playerpatch.inc index f2b429c0..37e82876 100644 --- a/scripting/include/srccoop/playerpatch.inc +++ b/scripting/include/srccoop/playerpatch.inc @@ -623,7 +623,7 @@ public MRESReturn Hook_PlayerWeaponShootPosition_Post(int iClient, Handle hRetur // Objects that are carried will call this hook and lag further behind the desired position. if (pPlayer.GetCarriedObject() == NULL_CBASEENTITY) { - DHookSetReturnVector(hParams, g_vec3PlayerShootPosition[iClient]); + DHookSetReturnVector(hReturn, g_vec3PlayerShootPosition[iClient]); return MRES_Supercede; } else