Skip to content

Replace shotgun spread ASM patch with a SharedRandomFloat hook - #1025

Open
A1mDev wants to merge 6 commits into
SirPlease:masterfrom
A1mDev:l4d2_sharedrandom_overrides
Open

A1mDev wants to merge 6 commits into
SirPlease:masterfrom
A1mDev:l4d2_sharedrandom_overrides

Conversation

@A1mDev

@A1mDev A1mDev commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Description:

Replace the legacy ASM-based static shotgun spread patch with a detour hook for SharedRandomFloat, providing a configurable and extensible shotgun pellet pattern system.

The plugin preserves the existing static spread logic while allowing further customization of pellet distribution.

Changes:

1. Configurable pellet patterns — support for custom rings and radius factors.

2. Corrected spread direction calculation — use the full 0°–<180° range instead of the restricted ranges produced by the legacy ASM patch.

3. Disabled unnecessary spread offsets — remove shot-relative up/down and left/right offsets to ensure accurate static patterns.

4. Detour-based implementation — replace the legacy ASM patch with a function hook, making the implementation easier to understand, maintain, and extend.

5. Preserved legacy behavior — retain compatibility with the existing static spread logic.

Technical details:

The implementation is based on reverse engineering and analysis of CTerrorPlayer::FireBullets, CTerrorGun::FireBullet, FireTerrorBullets, and their calls to SharedRandomFloat.

The legacy ASM patch was analyzed and compared against the behavior of the l4d2_static_shotgun_spread plugin. The new implementation was also tested using a C++ test.

Credits:

Jahze — original ASM patch, l4d2_static_shotgun_spread, and related spread manipulation and testing plugins.

ProdigySim — proposed the SharedRandomFloat hook approach and provided the initial plugin implementation.

ProdigySim, Visor, Rena — maintenance of the legacy plugin and ASM patch.

Alan — testing, feedback, and verification of the initial implementation.

Future improvements:

  1. Add Gaussian distribution support.

  2. Support individual patterns for each shotgun without dynamically patching the central pellet.

  3. Fix prediction seed precision issues for large values (Cvar issue).

  4. Investigate cases where the saved seed reaches INT_MAX.

  5. Explore Left 4 Dead 1 support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant