Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
CS2-Essentials/obj
CS2-Essentials/bin
*.user
/.vs/CS2-Essentials
31 changes: 30 additions & 1 deletion CS2-Essentials/Features/RapidFireFix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static void UnregisterCustomVotes(Plugin plugin)

public HookResult OnWeaponFire(EventWeaponFire eventWeaponFire, GameEventInfo info)
{
if (!eventWeaponFire.Userid.IsPlayer())
if (!eventWeaponFire.Userid.IsPlayer() || hvh_restrict_rapidfire.Value == (int)FixMethod.Ignore)
return HookResult.Continue;

var firedWeapon = eventWeaponFire.Userid!.Pawn.Value?.WeaponServices?.ActiveWeapon.Value;
Expand Down Expand Up @@ -125,6 +125,9 @@ public HookResult OnWeaponFire(EventWeaponFire eventWeaponFire, GameEventInfo in

public HookResult OnTakeDamage(DynamicHook h)
{
if(hvh_restrict_rapidfire.Value == (int)FixMethod.Ignore)
return HookResult.Continue;

var damageInfo = h.GetParam<CTakeDamageInfo>(1);

// attacker is invalid
Expand Down Expand Up @@ -156,4 +159,30 @@ public HookResult OnTakeDamage(DynamicHook h)

return HookResult.Changed;
}

public HookResult OnBulletImpact(EventBulletImpact eventBulletImpact, GameEventInfo info)
{
if (hvh_restrict_rapidfire.Value != (int)FixMethod.Ignore)
return HookResult.Continue;

var firedWeapon = eventBulletImpact.Userid!.Pawn.Value!.WeaponServices!.ActiveWeapon.Value;

if (firedWeapon == null || firedWeapon.DesignerName == "weapon_revolver")
return HookResult.Continue;

var weaponData = firedWeapon.GetVData<CCSWeaponBaseVData>();

if (weaponData == null)
return HookResult.Continue;

int tickBase = (int)eventBulletImpact.Userid.TickBase;
int fixedPrimaryTick = (int)Math.Round(weaponData.CycleTime.Values[0] * 64) - 3;

firedWeapon.NextPrimaryAttackTick = Math.Max(firedWeapon.NextPrimaryAttackTick, tickBase + fixedPrimaryTick);

// maybe deprecated as CSSharp auto setting state changes
Utilities.SetStateChanged(firedWeapon, "CBasePlayerWeapon", "m_nNextPrimaryAttackTick");

return HookResult.Continue;
}
}
3 changes: 2 additions & 1 deletion CS2-Essentials/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace hvhgg_essentials;
public class Plugin : BasePlugin, IPluginConfig<Cs2EssentialsConfig>
{
public override string ModuleName => "HvH.gg - Essentials";
public override string ModuleVersion => "1.4.0";
public override string ModuleVersion => "1.5.0";
public override string ModuleAuthor => "imi-tat0r";
public override string ModuleDescription => "Essential features for CS2 HvH servers";
public Cs2EssentialsConfig Config { get; set; } = new();
Expand Down Expand Up @@ -157,6 +157,7 @@ private void UseRapidFireRestrict()
Console.WriteLine("[HvH.gg] Register rapid fire listeners");

var rapidFire = _serviceProvider!.GetRequiredService<RapidFire>();
RegisterEventHandler<EventBulletImpact>(rapidFire.OnBulletImpact, HookMode.Pre);
RegisterEventHandler<EventWeaponFire>(rapidFire.OnWeaponFire);
VirtualFunctions.CBaseEntity_TakeDamageOldFunc.Hook(rapidFire.OnTakeDamage, HookMode.Pre);

Expand Down