Garry's Mod

Garry's Mod

405 ratings
Clientside Hitreg
2
4
   
Award
Favorite
Favorited
Unfavorite
Content Type: Addon
Addon Type: Tool
Addon Tags: Fun, Realism
File Size
Posted
Updated
41.411 KB
19 May, 2023 @ 6:55am
5 Feb @ 4:45am
10 Change Notes ( view )

Subscribe to download
Clientside Hitreg

In 1 collection by wget
ESB TTT addons
13 items
Description
This is a simple implementation of client-side hit registration, which aims to eliminate instances of so-called "fake hits" (hits where you see blood impacts but deal no damage)

This also works with not only players, but also npcs, props, etc, even if they're not set to be lag-compensated
That means that this should useful for any kind of PvP or PvE gamemode (if they involve shooting guns)

This does only work with bullets though, not all kinds of traces, so this won't affect stuff like melee weapons and projectiles and such

server cvars:
clhr_shotguns 1 : allow shotguns to use clientside hitreg

clhr_tolerance 8 : hitpos tolerance for lag-compensated entities

clhr_tolerance_nolc 128 : hitpos tolerance for entities that are not lag-compensated

clhr_tolerance_ping 100 : when calculating hitpos tolerance, clamps ping to this max value

clhr_supertolerant 0 : the client is always right (not recommended for public servers)

clhr_targetbits 255 : bitfield for targets that are allowed for clientside hitreg (for if you want to exclude certain types of entities)
1 = players
2 = npcs
4 = nextbots
8 = vehicles
16 = weapons
32 = ragdolls
64 = props
128 = other

clhr_nofirebulletsincallback 0 : prevent bullets from being fired inside the callbacks of client-registered hits
(you may enable this if client-registered hits are causing some weirdness with certain implementations of bullet penetration)

clhr_subtick 0 : subtick hitreg simulation (very experimental, not recommended) <video>

clhr_printshots 0 : print attempts at client-registered hits in the console (for debug purposes)

FAQ:
How exactly does this work?
On the server's side, when you miss a shot, it will temporarily store data about that shot including possible targets that could've been hit
On the client's side, when you hit a shot, it sends a message about that shot to the server in case the server disagrees with the shot's results
Back on the server's side when it receives the client's message, it will check if you're claiming a shot that missed should've actually hit, then decides if it should take your word for it by comparing the data you sent vs the data it stored

Wouldn't cheaters be able to exploit this?
Yes, but this has pretty conservative checks to minimise that
Cheaters won't be able to hit people across the map through walls for 9999 damage with a crowbar or anything crazy like that
At most, this can mildly help cheaters with letting their aimbot be more consistent, so they kinda benefit from this in just the same way that a normal user does

Doesn't explaining how this works and having the server-side code be public make this less secure?
No, security through obscurity is silly
Feel free to scrutinise the code and pick it apart, since I did just hastily make this in a couple of days (at least that's my excuse for the many questionable decisions in the source code)
Still, I'm pretty confident that this shouldn't be buggy and should be compatible with pretty much anything, but PLEASE report to me any bugs or errors you encounter with this addon

Can I use this along with LeyHitreg?
No, that's like using 2 adblockers at the same time, they will conflict with each other and break stuff
Only use one or the other, depending on which one is more compatible with whatever set of addons that you have

How is this different from LeyHitreg?
I haven't looked into how exactly LeyHitreg performs its clientside hitreg, but I've done some tests with it when I was fixing some random-spread-related issues it was causing with one of my addons
From my tests, LeyHitreg seems very overzealous and lets you land up to like 50% more shots than you should, I think it's way too generous
To prove this, I've fired a thousand shots with an average chance to hit of 26.4%, and 338 of those shots landed with LeyHitreg
Using the binomial distribution formula, this has an odds to occur of like 1 in 8 million
It always kinda felt like I only needed to aim in someone's general direction to land shots in a server that has LeyHitreg installed, it appears to perform some sort of aim-assist or bullet-magnetism

Also this addon works with shotguns and on npcs while LeyHitreg doesn't

Why do fake hits still occasionally happen with this?
This addon is quite strict with how it validates hits sent by the client, since it makes sure that a shot is actually possible from where you fired it to where you claim it hits
The value of the clhr_tolerance convar is used to tell how far away the claimed hit position can be from the line of the shot (basically a cylinder check)
If you find that the default value of 8 units is too strict, you may increase it to like 16 or higher
You can scroll up to the "server cvars" section to see more console variables that you can adjust

I did a quick test where I tried to get a lot of "fake hits" with 200 ms ping and 50 ms jitter while aiming for the head of a player bot that's wildly swinging its crowbar and chasing me in a circle
I fired a thousand shots with an average chance to hit of 72.9%:
- 534 shots hit without clientside hitreg (30.65% fake hits)
- 756 shots hit at 8 units of tolerance (1.82% fake hits)
- 768 shots hit at 16 units of tolerance (0.26% fake hits)

(whenever I say "average chance to hit", it's calculated clientside using the bullet's cone of spread and the hitboxes within it)

more info:
for addon coders, here's some compatibility features:
https://gtm.steamproxy.vip/workshop/filedetails/discussion/2977785840/3824163953450188003/

thanks to figardo for some early testing

anyone is free to edit and share edited versions of this addon's code (just make it clear what you changed)

github page: https://github.com/wgetJane/gmod-clientside-hitreg

my addons:
my maps:
Popular Discussions View All (1)
0
19 May, 2023 @ 6:52pm
PINNED: Here's some compatibility features for addon coders
wget
70 Comments
wget  [author] 7 Feb @ 2:52am 
IMPORTANT!!!

now that leyhitreg was just recently made free and open source and available on the workshop ( https://gtm.steamproxy.vip/sharedfiles/filedetails/?id=3421440369 ), please do NOT use both leyhitreg and this addon at the same time

having both leyhitreg and this addon active at the same time will NOT somehow result in better hitreg if that's what you're thinking, it will actually just break a ton of things that nobody's gonna help you with, because they are not meant to be used together

you must install only either this addon or leyhitreg, so just use whichever one's most compatible with your server's set of addons
wget  [author] 6 Feb @ 3:26am 
btw code should be up on github now, which i should've done like 2 years ago
https://github.com/wgetJane/gmod-clientside-hitreg
Winn 5 Feb @ 1:55pm 
it was really weird, it happened once and then never again. thank you for your efforts though
wget  [author] 5 Feb @ 4:40am 
@Winn
i could not replicate this at all in any branch, can you be specific about the circumstances of the crash?
wget  [author] 30 Jan @ 9:39pm 
@Winn
very odd, this is a crash on the C-side of the game

what branch of gmod is the server on, main or 64-bit or dev?

also can you be more specific on how the crash happened? is it a vanilla hl2 gun shooting a strider?
Winn 30 Jan @ 6:43pm 
crashed while shooting a strider

Client
*Not in Lua call OR Lua has panicked*

Server
0. DispatchTraceAttack - [C]:-1
1. func - lua/marghitreg/sv_marghitreg.lua:1087
2. internal_call - lua/includes/modules/hook.lua:409
3. (null) - lua/includes/modules/hook.lua:428

MenuSystem
*Not in Lua call OR Lua has panicked*
wget  [author] 4 Dec, 2024 @ 5:44pm 
@Loewenstern
yes, the addon only ever disables itself in single-player mode
Loewenstern 4 Dec, 2024 @ 1:36pm 
does this work when hosting peer to peer?
wget  [author] 20 Oct, 2024 @ 4:59am 
@Dr. House M.D.
can you paste in the error you're getting
Silly Driver 19 Oct, 2024 @ 12:32pm 
I'm having issues where the add-on either partially loads and errors or simply refuses to load at all.

sv_allowcslua 1 fixes the add-on not loading at all problem, but it still randomly decides to show only three or four convars instead of all the ones listed in the description, as well as erroring when shooting things (indicating something is missing).

Add-on works fantastic for my needs, but I cannot for the life of me get it to reliably load without restarting the server several times. (tested without other add-ons enabled)