SolvedNet.Start/Receive List

Posts 1–8 of 8 · Page 1 of 1
Net.Start/Receive List
While I was learning some Lua code, I wondered to myself if there is a way to monitor any net.Start and net.Receive clientside, IE. if I join a server is there a way for me to see every net.Send and net.Receive that is on my client that goes to the server? Thanks in advance
local oldnetStart = net.Start;
net.Start = function( msg, ... )
print( msg );
oldnetStart( msg );
end
It would look something like that, in order to log anything going out through "net.Start".
Quote Originally Posted by Chief Gooby View Post
It would look something like that, in order to log anything going out through "net.Start".
you use the varargs but then do nothing with them?
Quote Originally Posted by dustin1525 View Post
While I was learning some Lua code, I wondered to myself if there is a way to monitor any net.Start and net.Receive clientside, IE. if I join a server is there a way for me to see every net.Send and net.Receive that is on my client that goes to the server? Thanks in advance
probably impossible tbh
Code:
netlog = netlog || {};
netlog.receivers = netlog.receivers || {};
netlog.originals = netlog.originals || {};
netlog.curmsg = "";
netlog.types = {
	["Angle"] = true,
	["Bit"] = true,
	["Bool"] = true,
	["Color"] = true,
	["Data"] = true,
	["Double"] = true,
	["Entity"] = true,
	["Float"] = true,
	["Int"] = true,
	["Normal"] = true,
	["String"] = true,
	["Table"] = true,
	["Type"] = true,
	["UInt"] = true,
	["Vector"] = true,
};

function netlog.log(msg)
	//local txtcol = string.sub(msg, 1, 3) == "---" && Color(255, 255, 255) || Color(255, 0, 0);
	//MsgC(Color(255, 0, 0), "net", Color(255, 255, 255), "Log] ", txtcol, msg .. " \n");

	MsgN("netLog] " .. msg)
end

function netlog.detour(name, func, newfunc)
	netlog.log("detoured net function " .. name);
	
	local ofunc = func;
	netlog.originals[name] = netlog.originals[name] || ofunc;
	return newfunc;
end

function netlog.setcurnet(netname)
	if (!netname || !isstring(netname)) then
		return;
	end

	if (netlog.curmsg && netlog.curmsg != "") then
		netlog.log("---end net msg " .. netlog.curmsg .. "---");
	end

	netlog.log("---begin net msg " .. netname .. "---");
	netlog.curmsg = netname;
	netlog.originals["net.Start"](netname);
end

function netlog.endcurnet()
	netlog.log("---end net msg " .. netlog.curmsg .. "---");
	netlog.curmsg = "";
	netlog.originals["net.SendToServer"]();
end

function netlog.think()
	local same = true;

	for name, func in next, net.Receivers do
		if (!netlog.receivers[name]) then
			same = false;
			netlog.receivers[name] = func;
		end
	end

	if (!same) then
		for name, func in next, net.Receivers do
			netlog.log("detouring net receiver function for " .. name);

			net.Receivers[name] = function(len)
				if (netlog.curmsg && netlog.curmsg != "") then
					netlog.log("---end net msg " .. netlog.curmsg .. "---");
				end

				netlog.log("---begin net msg " .. name .. "---");
				netlog.curmsg = name;
				netlog.receivers[name](len);
			end
		end
	end
end

net.Start = netlog.detour("net.Start", net.Start, netlog.setcurnet);
net.SendToServer = netlog.detour("net.SendToServer", net.SendToServer, netlog.endcurnet);
netlog.log("added think hook");
hook.Add("Think", "netlog.think", netlog.think);

for name, valid in next, netlog.types do
	if (!valid) then
		continue;
	end

	if (net["Read" .. name]) then
		netlog.log("detouring net read function " .. string.lower(name));
		netlog.originals["net.Read" .. name] = netlog.originals["net.Read" .. name] || net["Read" .. name];
		local ofunc = netlog.originals["net.Read" .. name];

		net["Read" .. name] = function(read)
			local ret = ofunc(read);
			netlog.log("read " .. string.lower(name) .. ": " .. tostring(ret));
			return ret;
		end
	end

	if (net["Write" .. name]) then
		netlog.log("detouring net write function " .. string.lower(name));
		netlog.originals["net.Write" .. name] = netlog.originals["net.Write" .. name] || net["Write" .. name];
		local ofunc = netlog.originals["net.Write" .. name];

		net["Write" .. name] = function(write, ...)
			netlog.log("wrote " .. string.lower(name) .. ": " .. tostring(write));
			ofunc(write, ...);
		end
	end
end
Quote Originally Posted by SmokeIsGay View Post
probably impossible tbh
Code:
netlog = netlog || {};
netlog.receivers = netlog.receivers || {};
netlog.originals = netlog.originals || {};
netlog.curmsg = "";
netlog.types = {
	["Angle"] = true,
	["Bit"] = true,
	["Bool"] = true,
	["Color"] = true,
	["Data"] = true,
	["Double"] = true,
	["Entity"] = true,
	["Float"] = true,
	["Int"] = true,
	["Normal"] = true,
	["String"] = true,
	["Table"] = true,
	["Type"] = true,
	["UInt"] = true,
	["Vector"] = true,
};

function netlog.log(msg)
	//local txtcol = string.sub(msg, 1, 3) == "---" && Color(255, 255, 255) || Color(255, 0, 0);
	//MsgC(Color(255, 0, 0), "net", Color(255, 255, 255), "Log] ", txtcol, msg .. " \n");

	MsgN("netLog] " .. msg)
end

function netlog.detour(name, func, newfunc)
	netlog.log("detoured net function " .. name);
	
	local ofunc = func;
	netlog.originals[name] = netlog.originals[name] || ofunc;
	return newfunc;
end

function netlog.setcurnet(netname)
	if (!netname || !isstring(netname)) then
		return;
	end

	if (netlog.curmsg && netlog.curmsg != "") then
		netlog.log("---end net msg " .. netlog.curmsg .. "---");
	end

	netlog.log("---begin net msg " .. netname .. "---");
	netlog.curmsg = netname;
	netlog.originals["net.Start"](netname);
end

function netlog.endcurnet()
	netlog.log("---end net msg " .. netlog.curmsg .. "---");
	netlog.curmsg = "";
	netlog.originals["net.SendToServer"]();
end

function netlog.think()
	local same = true;

	for name, func in next, net.Receivers do
		if (!netlog.receivers[name]) then
			same = false;
			netlog.receivers[name] = func;
		end
	end

	if (!same) then
		for name, func in next, net.Receivers do
			netlog.log("detouring net receiver function for " .. name);

			net.Receivers[name] = function(len)
				if (netlog.curmsg && netlog.curmsg != "") then
					netlog.log("---end net msg " .. netlog.curmsg .. "---");
				end

				netlog.log("---begin net msg " .. name .. "---");
				netlog.curmsg = name;
				netlog.receivers[name](len);
			end
		end
	end
end

net.Start = netlog.detour("net.Start", net.Start, netlog.setcurnet);
net.SendToServer = netlog.detour("net.SendToServer", net.SendToServer, netlog.endcurnet);
netlog.log("added think hook");
hook.Add("Think", "netlog.think", netlog.think);

for name, valid in next, netlog.types do
	if (!valid) then
		continue;
	end

	if (net["Read" .. name]) then
		netlog.log("detouring net read function " .. string.lower(name));
		netlog.originals["net.Read" .. name] = netlog.originals["net.Read" .. name] || net["Read" .. name];
		local ofunc = netlog.originals["net.Read" .. name];

		net["Read" .. name] = function(read)
			local ret = ofunc(read);
			netlog.log("read " .. string.lower(name) .. ": " .. tostring(ret));
			return ret;
		end
	end

	if (net["Write" .. name]) then
		netlog.log("detouring net write function " .. string.lower(name));
		netlog.originals["net.Write" .. name] = netlog.originals["net.Write" .. name] || net["Write" .. name];
		local ofunc = netlog.originals["net.Write" .. name];

		net["Write" .. name] = function(write, ...)
			netlog.log("wrote " .. string.lower(name) .. ": " .. tostring(write));
			ofunc(write, ...);
		end
	end
end

That did work, however it lagged my game to crap.. Thanks anyway! +rep

If there was a way to save that to a text document that would be 11/10
Thank you VERY much, this helped quite a lot.
Seems this has been solved.

/Closed.
Posts 1–8 of 8 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us