RafaelDeJongh / cap

Carter Addons Pack Code
Other
102 stars 94 forks source link

Faulty math.randomseed usage #96

Open DBotThePony opened 4 years ago

DBotThePony commented 4 years ago

Cause complete desync between client and server With CAP installed: gmod_Zafo5UdvOX

Without CAP installed: gmod_28B9glqhhw

browser_JRT0iwMm7f https://wiki.facepunch.com/gmod/math.randomseed

Please use util.SharedRandom: https://wiki.facepunch.com/gmod/util.SharedRandom

DBotThePony commented 4 years ago

Also this should be removed https://github.com/RafaelDeJongh/cap/blob/master/lua/autorun/swep_fix.lua

Client calls :PrimaryAttack() until it works out all prediction issues. It is called once or two times with low ping, and multiple times with high ping. Such "fix" applied by file above almost completely ruin prediction.

AlexALX commented 4 years ago

Isn't this issue only with CAP SWEP's? Or affect others? Anyway it is pretty old code and maybe someone can review it, removing is bad idea because we might got much more issues.

DBotThePony commented 4 years ago

it affects ALL SWEPs installed on server.

AlexALX commented 4 years ago

I think if we will remove that then it will break most of cap weapons, unless this bug was fixed in gmod. So i'm not sure what to do.

DBotThePony commented 4 years ago

This is not a bug, this is how things are supposed to be (server call predicted hooks once, client call them as much as needed to close gap between server and client state).

From my own testing i found out that only some weapons are lacking proper prediction, most notably wraith hands.

If you want your logic to be executed only once on clientside realm on primary/secondary fire, use IsFirstTimePredicted() global function.

AlexALX commented 3 years ago

Can you please say me if its caused by exactly math.randomseed usages in cap or sbep_fix.lua file? How you are checking this?

DBotThePony commented 3 years ago

https://wiki.facepunch.com/gmod/Prediction#commonquestions ???

AlexALX commented 3 years ago

I mean which command you used to display those cubes like on screen, because i tried some from this page, but didn't got anything like this.

DBotThePony commented 3 years ago

local sv_showimpacts = CreateConVar("sv_showimpacts", 0, FCVAR_REPLICATED, "Shows client (red) and server (blue) bullet impact point", 0, 3)
local sv_showimpacts_time = CreateConVar("sv_showimpacts_time", 4, FCVAR_REPLICATED, "How long to show bullet impact points for.", 1, 10)

local colorServer = Color(0, 0, 255, 127)
local colorClient = Color(255, 0, 0, 127)
local mins, maxs = Vector(-2, -2, -2), Vector(2, 2, 2)

if CLIENT then
    net.Receive("sv_showimpacts", function()
        debugoverlay.Box(Vector(net.ReadDouble(), net.ReadDouble(), net.ReadDouble()), mins, maxs, sv_showimpacts_time:GetFloat(), colorServer, true)
    end)
else
    util.AddNetworkString("sv_showimpacts")
end

hook.Add("EntityFireBullets", "showimpacts", function(pEntity, bulletInfo)
    if !IsFirstTimePredicted() then
        return
    end

    if sv_showimpacts:GetBool() then
        local originalCallback = bulletInfo.Callback

        bulletInfo.Callback = function(entity, trace, dmgInfo)
            if originalCallback then
                originalCallback(entity, trace, dmgInfo)
            end

            local impacts = sv_showimpacts:GetInt()

            if SERVER and (impacts == 1 or impacts == 3) then
                if game.SinglePlayer() then
                    debugoverlay.Box(trace.HitPos, mins, maxs, sv_showimpacts_time:GetFloat(), colorServer, true)
                else
                    net.Start("sv_showimpacts", true)
                    net.WriteDouble(trace.HitPos.x)
                    net.WriteDouble(trace.HitPos.y)
                    net.WriteDouble(trace.HitPos.z)
                    net.Broadcast()
                end
            elseif CLIENT and (impacts == 1 or impacts == 2) then
                debugoverlay.Box(trace.HitPos, mins, maxs, sv_showimpacts_time:GetFloat(), colorClient)
            end

        end

        return true
    end
end)

in autorun

Grocel commented 11 months ago

I think if we will remove that then it will break most of cap weapons, unless this bug was fixed in gmod. So i'm not sure what to do.

IsFirstTimePredicted()?