Facepunch / garrysmod-issues

Garry's Mod issue tracker
141 stars 56 forks source link

Entity:GetAttachment ignores SWEP world model, server always returns bad data #4979

Open TiberiumFusion opened 3 years ago

TiberiumFusion commented 3 years ago

Details

When GetAttachment is called serverside on a SWEP, the server ignores the SWEP's actual worldmodel and substitutes in some mysterious unknown worldmodel for the attachment calculations. Naturally, this makes the attachments calculations completely wrong, and so GetAttachment is completely useless for things like firing hitscan/entity bullets, particle effects like muzzle flashes, etc. You know, stuff that's kind of sort of maybe important to SWEPs.

On the client, GetAttachment works correctly.

Demo

Use this addon to visualize the problem: broken_getattachment_demo.zip

Here are some screenshots of what the addon demonstrates:

Composite

Steps to reproduce

  1. Install addon provided above.
  2. -noworkshop
  3. Start a multiplayer game
  4. Spawnmenu > Weapons > Other > Broken GetAttachment Demo
  5. Use a camera to look at yourself. Observe the red and green cubes and text.
  6. Change the .WorldModel in the swep code, kill yourself, and spawn a new swep. Observe how the server is always wrong in the exact same way, regardless of the world model.

Environment

Vanilla 2021.06.09 x64-86 2021.06.09

TiberiumFusion commented 3 years ago

Additional notes

I am somewhat confident in my guess that the server replaces every SWEP's worldmodel with some invalid stand-in. I tried to create to create a workaround with Entity:GetBoneMatrix, but it was returning nil when it shouldn't have. This only makes sense if the bone index I am trying to access does not actually exist... except it does. And the only way the bone could not exist is if the server was completely ignoring my SWEP's worldmodel and substituting its own garbage one instead.

robotboy655 commented 3 years ago

It's using the view model on server and in some frames on client, and we are at the point again that there is probably code that relies on this behavior and fixing this would cause shit to break..

robotboy655 commented 3 years ago

In fact the engine itself relies on this shit for animations for some reason. The only way I can see out of this mess is to add manual hacks to the Lua functions like GetModel() already does.

TiberiumFusion commented 3 years ago

I would be fine with a new GetWorldModelAttachment on SWEPs only that fixes the behavior while leaving the original GetAttachment unmodified. It is ugly, but that is nothing new for gmod.