wiremod / advdupe2

Advanced Duplicator 2
http://wiremod.com
Apache License 2.0
90 stars 60 forks source link

Fix AreaCopy when used with the CopyOutside param #466

Closed brandonsturgeon closed 6 months ago

brandonsturgeon commented 6 months ago

Problem Summary

The Copy function takes a ply so it can determine which entities to copy: https://github.com/wiremod/advdupe2/blob/master/lua/advdupe2/sv_clipboard.lua#L376

But when the CopyOutside param is enabled in AreaCopy, it doesn't pass a ply in: https://github.com/wiremod/advdupe2/blob/master/lua/advdupe2/sv_clipboard.lua#L495

So when using the CopyOutside param with AreaCopy, an error is produced:

[advdupe2] addons/advdupe2/lua/advdupe2/sv_clipboard.lua:379: attempt to call method 'EntIndex' (a nil value)
  1. RecursiveCopy - addons/advdupe2/lua/advdupe2/sv_clipboard.lua:379
   2. Copy - addons/advdupe2/lua/advdupe2/sv_clipboard.lua:440
    3. AreaCopy - addons/advdupe2/lua/advdupe2/sv_clipboard.lua:495
     4. RightClick - addons/advdupe2/lua/weapons/gmod_tool/stools/advdupe2.lua:292
      5. unknown - gamemodes/sandbox/entities/weapons/gmod_tool/shared.lua:257

The Fix

I've updated the AreaCopy function to take ply as the last parameter, which is then passed through to the Copy function correctly.

I also updated all of the instances of AreaCopy to provide a ply.

I'm not 100% sure this is the best way, but it does address the issue.

Reproduce

thegrb93 commented 6 months ago

Could you put ply as the first arg so its consistent with Copy

brandonsturgeon commented 6 months ago

Sure, but note that because the function is exposed it'll be a breaking change for anything that uses AreaCopy directly

thegrb93 commented 6 months ago

Yeah. Also you need to update the functions calling it.

brandonsturgeon commented 6 months ago

D'oh, thanks. I did it very mindlessly

thegrb93 commented 6 months ago

Can you fix them?