110 lines
3.1 KiB
Lua
110 lines
3.1 KiB
Lua
|
|
netCodes = netCodes or {
|
|
["SendToServer"] = net.SendToServer,
|
|
["Start"] = net.Start,
|
|
["WriteAngle"] = net.WriteAngle,
|
|
["WriteBit"] = net.WriteBit,
|
|
["WriteBool"] = net.WriteBool,
|
|
["WriteColor"] = net.WriteColor,
|
|
["WriteData"] = net.WriteData,
|
|
["WriteDouble"] = net.WriteDouble,
|
|
["WriteEntity"] = net.WriteEntity,
|
|
["WriteFloat"] = net.WriteFloat,
|
|
["WriteInt"] = net.WriteInt,
|
|
["WriteMatrix"] = net.WriteMatrix,
|
|
["WriteNormal"] = net.WriteNormal,
|
|
["WriteString"] = net.WriteString,
|
|
["WriteTable"] = net.WriteTable,
|
|
["WriteUInt"] = net.WriteUInt,
|
|
["WriteVector"] = net.WriteVector
|
|
}
|
|
|
|
function tableToString(t)
|
|
if type(o) == 'table' then
|
|
local s = '{ '
|
|
for k,v in pairs(o) do
|
|
if type(k) ~= 'number' then k = '"'..k..'"' end
|
|
s = s .. '['..k..'] = ' .. dump(v) .. ','
|
|
end
|
|
return s .. '} '
|
|
else
|
|
return tostring(o)
|
|
end
|
|
end
|
|
|
|
|
|
local buffer = ""
|
|
|
|
local function construct_net_block(t, netName)
|
|
makeString = "net." ..netName .. "("
|
|
for i=1, #t do
|
|
indexValue = t[i]
|
|
if (type(indexValue) == "number") then
|
|
if (i == #t) then makeString = makeString .. indexValue else makeString = makeString .. indexValue .. ", " end
|
|
elseif (type(indexValue) == "boolean") then
|
|
makeString = makeString .. tostring(indexValue)
|
|
elseif (type(indexValue) == "string") then
|
|
if (i == #t) then makeString = makeString .. "\"" .. indexValue .. "\"" else makeString = makeString .. "\"" .. indexValue .. "\", " end
|
|
elseif (type(indexValue) == "Player" || type(indexValue) == "Entity" || type(indexValue) == "NPC") then
|
|
makeString = makeString .. "Entity(" .. tostring(indexValue:EntIndex()) .. ")"
|
|
elseif (type(indexValue) == "Vector") then
|
|
makeString = makeString .. "Vector(" .. string.gsub(tostring(indexValue), "%s+", ", ") .. ")"
|
|
elseif (type(indexValue) == "table") then
|
|
print("INDEXVALUE IS TABLE")
|
|
print("indevalue", table.ToString(indexValue))
|
|
makeString = makeString .. table.ToString(indexValue)
|
|
else
|
|
ErrorNoHalt("[netlogthing] !!! UNHANDLED !!! " .. "type(index): " .. "[" .. type(indexValue) .. "]" .. " index: " .. "[" .. tostring(indexValue) .. "]")
|
|
end
|
|
end
|
|
|
|
buffer = buffer .. makeString .. ")" .. "\n"
|
|
if (string.match(buffer, "SendToServer")) then
|
|
hook.Run( "RecvNetMsg", buffer )
|
|
buffer = ""
|
|
end
|
|
end
|
|
|
|
|
|
|
|
-- net request sent
|
|
-- net requests go through our
|
|
|
|
|
|
|
|
function handle_net_message(netName)
|
|
return function (...) -- just doing this so I can give access to netName in construct_net_block function
|
|
construct_net_block({...}, netName)
|
|
hook.Add( "RecvNetMsg", "netlogger", function(netmsg)
|
|
detour_net_functions(false)
|
|
RunString(netmsg)
|
|
detour_net_functions(true)
|
|
end)
|
|
|
|
-- netCodes[netName](...)
|
|
end
|
|
end
|
|
|
|
|
|
function detour_net_functions(bool) -- WriteTable calls a bunch of other net functions internally, so got to turn it off
|
|
if (bool) then
|
|
for k, v in pairs(netCodes) do
|
|
net[k] = handle_net_message(k)
|
|
end
|
|
else
|
|
for k, v in pairs(netCodes) do
|
|
net[k] = v
|
|
end
|
|
end
|
|
|
|
end
|
|
|
|
|
|
if (!detoured_net_functions) then
|
|
detoured_net_functions = true
|
|
detour_net_functions(true)
|
|
else
|
|
print("\n\n\nAlready detoured net functions\n\n\n")
|
|
end
|
|
|