cap icon indicating copy to clipboard operation
cap copied to clipboard

Faulty math.randomseed usage

Open DBotThePony opened this issue 5 years ago • 10 comments

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 avatar Aug 15 '20 14:08 DBotThePony

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.

DBotThePony avatar Aug 17 '20 02:08 DBotThePony

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.

AlexALX avatar Aug 17 '20 12:08 AlexALX

it affects ALL SWEPs installed on server.

DBotThePony avatar Aug 18 '20 17:08 DBotThePony

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.

AlexALX avatar Aug 18 '20 20:08 AlexALX

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.

DBotThePony avatar Aug 19 '20 17:08 DBotThePony

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?

AlexALX avatar Nov 28 '20 16:11 AlexALX

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

DBotThePony avatar Nov 30 '20 04:11 DBotThePony

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.

AlexALX avatar Nov 30 '20 11:11 AlexALX


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

DBotThePony avatar Nov 30 '20 11:11 DBotThePony

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()?

Grocel avatar Nov 05 '23 22:11 Grocel