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
19 changes: 0 additions & 19 deletions gamedata/srccoop.games.txt
Original file line number Diff line number Diff line change
Expand Up @@ -545,20 +545,6 @@
"return" "int"
"this" "entity"
}
"CWeapon_Crossbow::FireBolt"
{
"offset" "CWeapon_Crossbow::FireBolt"
"hooktype" "entity"
"return" "bool"
"this" "entity"
"arguments"
{
"bUnknown"
{
"type" "bool"
}
}
}
"CTempEntsSystem::DispatchEffect"
{
"offset" "CTempEntsSystem::DispatchEffect"
Expand Down Expand Up @@ -1450,11 +1436,6 @@
"windows" "299"
"linux" "300"
}
"CWeapon_Crossbow::FireBolt" // CWeapon_Crossbow::FireBolt(bool)
{
"windows" "423"
"linux" "424"
}
"CBaseViewModel::SendViewModelMatchingSequence" // CBaseViewModel::SendViewModelMatchingSequence(int)
{
"windows" "235"
Expand Down
159 changes: 65 additions & 94 deletions scripting/include/srccoop/bms/entitypatch.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// Patches for Black Mesa

static bool g_pPlayerIronsightClassic[MAXPLAYERS + 1];
static bool g_bDisableCrossbowExplosion = false;

//------------------------------------------------------
// CNPC_PlayerCompanion - npc_human_scientist*, npc_human_security
Expand Down Expand Up @@ -826,10 +827,12 @@ public MRESReturn Hook_ToggleIronsights(int _this, DHookParam hParams)
if (pWeapon.IsReloading())
return MRES_Supercede;

CBlackMesaPlayer pPlayer = view_as<CBlackMesaPlayer>(pWeapon.GetOwner());
if (!pPlayer.IsValid())
CBaseCombatCharacter pOwner = pWeapon.GetOwner();
if (pOwner == NULL_CBASEENTITY || !pOwner.IsPlayer())
return MRES_Supercede;

CBlackMesaPlayer pPlayer = view_as<CBlackMesaPlayer>(pOwner);

char szClassname[MAX_CLASSNAME];
bool bIsCrossbow = pWeapon.GetClassname(szClassname, sizeof(szClassname)) && strcmp(szClassname, "weapon_crossbow") == 0;
bool bWillBeUsingIronsights = !pWeapon.IsInIronsights();
Expand All @@ -848,7 +851,7 @@ public MRESReturn Hook_ToggleIronsights(int _this, DHookParam hParams)
if (!g_pPlayerIronsightClassic[pPlayer.entindex])
{
CPredictedViewModel pViewModel = pPlayer.GetViewModel();
if (pViewModel.IsValid())
if (pViewModel != NULL_CBASEENTITY)
{
if (bWillBeUsingIronsights || !bIsRearming)
{
Expand Down Expand Up @@ -899,24 +902,6 @@ public MRESReturn Hook_IronsightGetPrimaryAttackActivity(int _this, DHookReturn
return MRES_Ignored;
}

//------------------------------------------------------
// weapon_crossbow
// Fixes the shooting animation played while using ironsights.
//------------------------------------------------------
public MRESReturn Hook_CrossbowGetPrimaryAttackActivity(int _this, DHookReturn hReturn)
{
if (CoopManager.IsFeatureEnabled(FT_SP_WEAPONS))
{
CBlackMesaBaseCombatWeaponIronsights pWeapon = CBlackMesaBaseCombatWeaponIronsights(_this);
if (pWeapon.IsInIronsights())
{
DHookSetReturn(hReturn, ACT_VM_PRIMARYATTACK);
return MRES_Supercede;
}
}
return MRES_Ignored;
}

//------------------------------------------------------
// Caches the player ConVar `cl_ironsight_classic`.
//------------------------------------------------------
Expand Down Expand Up @@ -955,7 +940,7 @@ public MRESReturn Hook_IronsightDeployPost_SaveSettings(int _this, DHookReturn h
//------------------------------------------------------
public MRESReturn Hook_GrenadeBoltAcceptInput(int _this, DHookReturn hReturn, DHookParam hParams)
{
if (CoopManager.IsFeatureEnabled(FT_SP_WEAPONS))
if (g_bDisableCrossbowExplosion)
{
char szInputType[MAX_FORMAT];
DHookGetParamString(hParams, 1, szInputType, sizeof(szInputType));
Expand All @@ -968,6 +953,20 @@ public MRESReturn Hook_GrenadeBoltAcceptInput(int _this, DHookReturn hReturn, DH
return MRES_Ignored;
}

//------------------------------------------------------
// weapon_crossbow
// Fixes the shooting animation played while using ironsights.
//------------------------------------------------------
public MRESReturn Hook_CrossbowGetPrimaryAttackActivity(int _this, DHookReturn hReturn)
{
if (CoopManager.IsFeatureEnabled(FT_SP_WEAPONS))
{
DHookSetReturn(hReturn, ACT_VM_PRIMARYATTACK);
return MRES_Supercede;
}
return MRES_Ignored;
}

//------------------------------------------------------
// weapon_crossbow
// Sets the skin of the crossbow.
Expand All @@ -993,129 +992,101 @@ public MRESReturn Hook_CrossbowDeployPost(int _this, DHookReturn hReturn)

//------------------------------------------------------
// weapon_crossbow
// Sets the rearming animation (not the state!) after firing.
// This hook manages the rearm state.
// In the original implementation, the rearm state is never called in multiplayer
// Also fixes the scope in animation covering the screen by setting it to idle.
//
// TODO: Hooking ItemPostFrame with IsMultiplayer = false causes prediction issues.
// Fix this by not calling IsMultiplayer = false.
//------------------------------------------------------
public MRESReturn Hook_CrossbowItemPostFrame(int _this, DHookReturn hReturn)
public MRESReturn Hook_CrossbowItemPostFramePost(int _this, DHookReturn hReturn)
{
if (CoopManager.IsFeatureEnabled(FT_SP_WEAPONS))
{
g_bIsMultiplayerOverride = false;

CBaseCombatWeapon pWeapon = CBaseCombatWeapon(_this);
CWeapon_Crossbow pWeapon = CWeapon_Crossbow(_this);
CBaseCombatCharacter pOwner = pWeapon.GetOwner();
if (pOwner != NULL_CBASEENTITY && pOwner.IsPlayer())
{
CBasePlayer pPlayer = view_as<CBasePlayer>(pOwner);
CBlackMesaPlayer pPlayer = view_as<CBlackMesaPlayer>(pOwner);
CPredictedViewModel pViewModel = pPlayer.GetViewModel();
if (pViewModel != NULL_CBASEENTITY)
{
// Switch to idle animation so the scope does not block the view.
if (pViewModel.GetSequence() == pViewModel.SelectWeightedSequence(ACT_VM_IDLE_TO_IS) && pViewModel.GetCycle() >= 0.55)
Activity eActivity = pWeapon.GetActivity();
if (pWeapon.IsRearming())
{
if (pViewModel != NULL_CBASEENTITY)
{
if (pWeapon.GetActivity() == ACT_CROSSBOW_BOLT_BACK)
{
if (pViewModel.IsSequenceFinished())
{
pWeapon.SetRearming(false);
}
}
else
{
pWeapon.SendWeaponAnim(ACT_CROSSBOW_BOLT_BACK);
}
}
}
else if (eActivity == ACT_VM_IDLE_TO_IS && pViewModel.GetCycle() >= 0.55)
{
// Switch to idle animation so the scope does not block the view.
pWeapon.SendWeaponAnim(ACT_VM_IDLE);
}
}
}
}
return MRES_Ignored;
}

//------------------------------------------------------
// weapon_crossbow
// See `Hook_CrossbowItemPostFrame` for details.
//------------------------------------------------------
public MRESReturn Hook_CrossbowItemPostFramePost(int _this, DHookReturn hReturn)
{
if (CoopManager.IsFeatureEnabled(FT_SP_WEAPONS))
{
g_bIsMultiplayerOverride = true;
}
return MRES_Ignored;
}

//------------------------------------------------------
// weapon_crossbow
// This does the following:
//
// - Causes `CWeapon_Crossbow::FireBolt` to get called instead of `CWeapon_Crossbow::FireHitscanBolt` on secondary attacks
// - Sets the rearm bool
// - Sets animations
// Prevents the input `SetToExplode` from being called.
//------------------------------------------------------
public MRESReturn Hook_CrossbowPrimaryAttack(int _this, DHookReturn hReturn, DHookParam hParams)
{
if (CoopManager.IsFeatureEnabled(FT_SP_WEAPONS))
{
g_bIsMultiplayerOverride = false;
g_bDisableCrossbowExplosion = true;
}
return MRES_Ignored;
}

//------------------------------------------------------
// weapon_crossbow
// See `Hook_CrossbowPrimaryAttack` for details.
// Sets the rearm state and fixes the time to attack.
//------------------------------------------------------
public MRESReturn Hook_CrossbowPrimaryAttackPost(int _this, DHookReturn hReturn, DHookParam hParams)
{
if (CoopManager.IsFeatureEnabled(FT_SP_WEAPONS))
{
g_bIsMultiplayerOverride = true;
}
return MRES_Ignored;
}
g_bDisableCrossbowExplosion = true;

//------------------------------------------------------
// weapon_crossbow
// Fixes the rearm animation when pulling out the crossbow.
//------------------------------------------------------
public MRESReturn Hook_CrossbowGetDrawActivity(int _this, DHookReturn hReturn)
{
if (CoopManager.IsFeatureEnabled(FT_SP_WEAPONS))
{
g_bIsMultiplayerOverride = false;
}
return MRES_Ignored;
}
CWeapon_Crossbow pWeapon = CWeapon_Crossbow(_this);

//------------------------------------------------------
// weapon_crossbow
// See `Hook_CrossbowGetDrawActivity` for details.
//------------------------------------------------------
public MRESReturn Hook_CrossbowGetDrawActivityPost(int _this, DHookReturn hReturn)
{
if (CoopManager.IsFeatureEnabled(FT_SP_WEAPONS))
{
g_bIsMultiplayerOverride = true;
}
return MRES_Ignored;
}

//------------------------------------------------------
// weapon_crossbow
// `CWeapon_Crossbow::FireBolt` is only called by `CWeapon_Crossbow::PrimaryAttack` which is hooked.
// If this gets called with singleplayer being set, this will crash the server.
//------------------------------------------------------
public MRESReturn Hook_CrossbowFireBolt(int _this, DHookReturn hReturn, DHookParam hParams)
{
if (CoopManager.IsFeatureEnabled(FT_SP_WEAPONS))
{
g_bIsMultiplayerOverride = true;
bool bShouldRearm = pWeapon.GetPrimaryAmmo() > 0;
if (bShouldRearm)
{
pWeapon.DelayNextAttack(2.0);
}
pWeapon.SetRearming(bShouldRearm);
}
return MRES_Ignored;
}

//------------------------------------------------------
// weapon_crossbow
// See `Hook_CrossbowFireBolt` for details.
// Fixes the rearm animation when pulling out the crossbow.
//------------------------------------------------------
public MRESReturn Hook_CrossbowFireBoltPost(int _this, DHookReturn hReturn, DHookParam hParams)
public MRESReturn Hook_CrossbowGetDrawActivity(int _this, DHookReturn hReturn)
{
if (CoopManager.IsFeatureEnabled(FT_SP_WEAPONS))
{
g_bIsMultiplayerOverride = false;
CWeapon_Crossbow pWeapon = CWeapon_Crossbow(_this);
if (pWeapon.IsRearming())
{
DHookSetReturn(hReturn, ACT_CROSSBOW_BOLT_BACK);
return MRES_Supercede;
}
}
return MRES_Ignored;
}
Expand Down
1 change: 0 additions & 1 deletion scripting/include/srccoop/globals.inc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ DynamicHook hkBaseCombatWeaponDeploy;
DynamicHook hkBaseCombatWeaponPrimaryAttack;
DynamicHook hkBaseCombatWeaponGetPrimaryAttackActivity;
DynamicHook hkBaseCombatWeaponGetDrawActivity;
DynamicHook hkCrossbowFireBolt;
DynamicDetour hkToggleIronsights;
DynamicDetour hkTauFireBeam;
DynamicDetour hkParamsManagerInitInstances;
Expand Down
12 changes: 0 additions & 12 deletions scripting/include/srccoop/manager.inc
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,6 @@ methodmap CoopManager
}
}

public static void OnPlayerRunCmd(CBasePlayer pPlayer)
{
if (!data.m_bStarted)
{
CBaseCombatWeapon pWeapon = pPlayer.GetActiveWeapon();
if (pWeapon != NULL_CBASEENTITY)
{
pWeapon.DelayNextAttack(0.25);
}
}
}

public static void OnPlayerSpawned(CBasePlayer pPlayer)
{
bool bDefaultTeleport = g_pSpawnOptions.bUseSpawnSystem;
Expand Down
Loading