View Single Post
Forgetest
Member
Join Date: Aug 2020
Old 09-21-2021 , 01:23   Re: [L4D1/2] Don't switch weapon to secondary slot when pick up pistols
Reply With Quote #3

Quote:
Originally Posted by Marttt View Post
Try the following codes:

Method 1 (may be a bit glitch)

Spoiler


Method 2 (didn't have much time to work on this one, need some rework)

Spoiler
As far as I know, WeaponEquip doesn't fire when picking up the second pistol for both games. Internally uses EquipSecondWeapon.

I've been trying to make memory patches on this, only to get crashes on both games on Windows, but it seems to work on Linux L4D2.

Partial pseudocode from EquipSecondWeapon:
PHP Code:
    if ( v4 // = (CBaseCombatCharacter *)CTerrorWeapon::GetPlayerOwner(this);
    
{
      if ( 
this == (CTerrorGun *)CBaseCombatCharacter::GetActiveWeapon(v4) )
      {
        if ( *((
_BYTE *)this 6114) ) // m_inInitialPickup
          
(*(void (__cdecl **)(CTerrorGun *))(*(_DWORD *)this 1128))(this); // CTerrorGun::Reload()
      
}
      else
      {
        if ( 
CBaseCombatCharacter::GetActiveWeapon(v4) )
        {
          
v9 CBaseCombatCharacter::GetActiveWeapon(v4);
          (*(
void (__cdecl **)(int_DWORD))(*(_DWORD *)v9 1064))(v90); // CTerrorGun::Holster(CBaseCombatWeapon*)
        
}
        
CBaseCombatCharacter::SetActiveWeapon(v4this);
        (*(
void (__cdecl **)(CTerrorGun *))(*(_DWORD *)this 1060))(this); // CTerrorGun::Deploy()
      

So I aimed to patch those calls of Holster, SetActiveWeapon and Deploy to NOPs. However as mentioned above, it's crashing on Windows.

My detour setup: (There should be another detour on CWeaponSpawn::Use, otherwise it only functions when picking up dropped pistols)
PHP Code:
    Handle hDetour null;
    if (!
g_bLeft4Dead2)
    {
        if (
os == 1// Linux
        
{
            
hDetour DHookCreateDetour(Address_NullCallConv_CDECLReturnType_VoidThisPointer_Ignore);
            
DHookAddParam(hDetourHookParamType_CBaseEntity);
            
DHookAddParam(hDetourHookParamType_CBaseEntity);
        } else {
            
hDetour DHookCreateDetour(Address_NullCallConv_THISCALLReturnType_VoidThisPointer_CBaseEntity);
            
DHookAddParam(hDetourHookParamType_Int);
            
DHookAddParam(hDetourHookParamType_CBaseEntity);
            
DHookAddParam(hDetourHookParamType_Int);
            
DHookAddParam(hDetourHookParamType_Int);            
        }
    }
    else
    {
        if (
os == 1// Linux
        
{
            
hDetour DHookCreateDetour(Address_NullCallConv_CDECLReturnType_VoidThisPointer_Ignore);
            
DHookAddParam(hDetourHookParamType_CBaseEntity);
            
DHookAddParam(hDetourHookParamType_CBaseEntity);
            
DHookAddParam(hDetourHookParamType_Int);
        } else {
            
hDetour DHookCreateDetour(Address_NullCallConv_THISCALLReturnType_VoidThisPointer_CBaseEntity);
            
DHookAddParam(hDetourHookParamType_CBaseEntity);
            
DHookAddParam(hDetourHookParamType_Int);
            
DHookAddParam(hDetourHookParamType_Int);
            
DHookAddParam(hDetourHookParamType_Int);
        }
    }
    
    if (!
hDetour)
        
SetFailState("detour");
    
    if (!
DHookSetFromConf(hDetourconfSDKConf_Signature"CTerrorGun_Use"))
        
SetFailState("DHookSetFromConf");
    
    if (
os == 1// Linux
    
{
        if (!
DHookEnableDetour(hDetourfalseCTerrorGun_OnUse) || !DHookEnableDetour(hDetourtrueCTerrorGun_OnUsePost))
            
SetFailState("DHookEnableDetour");
    } else {
        if (!
DHookEnableDetour(hDetourfalseWindows_CTerrorGun_OnUse) || !DHookEnableDetour(hDetourtrueWindows_CTerrorGun_OnUsePost))
            
SetFailState("DHookEnableDetour");
    } 
Attached Files
File Type: txt secondary.txt (3.6 KB, 36 views)

Last edited by Forgetest; 09-21-2021 at 01:36.
Forgetest is offline