From d05d0b7f07678233b6a8300fcf3d2695714f539f Mon Sep 17 00:00:00 2001 From: Redox Date: Sat, 7 Dec 2024 18:17:04 +0100 Subject: [PATCH 1/6] Use MAX_EDICT_BITS --- .../gmod_wire_expression2/core/hologram.lua | 22 +++++++++---------- lua/entities/gmod_wire_hologram.lua | 21 +++++++++--------- lua/wire/wireshared.lua | 2 ++ 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/hologram.lua b/lua/entities/gmod_wire_expression2/core/hologram.lua index ec984d4610..69c3c9e2c3 100644 --- a/lua/entities/gmod_wire_expression2/core/hologram.lua +++ b/lua/entities/gmod_wire_expression2/core/hologram.lua @@ -239,13 +239,13 @@ local function flush_scale_queue(queue, recipient) net.Start("wire_holograms_set_scale") for _, plyqueue in pairs(queue) do for Holo, scale in pairs(plyqueue) do - net.WriteUInt(Holo.ent:EntIndex(), 16) + net.WriteUInt(Holo.ent:EntIndex(), WireLib.MAX_EDICT_BITS) net.WriteFloat(scale.x) net.WriteFloat(scale.y) net.WriteFloat(scale.z) end end - net.WriteUInt(0, 16) + net.WriteUInt(0, WireLib.MAX_EDICT_BITS) if recipient then net.Send(recipient) else net.Broadcast() end end @@ -257,7 +257,7 @@ local function flush_bone_scale_queue(queue, recipient) for _, plyqueue in pairs(queue) do for Holo, holoqueue in pairs(plyqueue) do for bone, scale in pairs(holoqueue) do - net.WriteUInt(Holo.ent:EntIndex(), 16) + net.WriteUInt(Holo.ent:EntIndex(), WireLib.MAX_EDICT_BITS) net.WriteUInt(bone + 1, 16) -- using +1 to be able reset holo bones scale with -1 and not use signed int net.WriteFloat(scale.x) net.WriteFloat(scale.y) @@ -265,7 +265,7 @@ local function flush_bone_scale_queue(queue, recipient) end end end - net.WriteUInt(0, 16) + net.WriteUInt(0, WireLib.MAX_EDICT_BITS) net.WriteUInt(0, 16) if recipient then net.Send(recipient) else net.Broadcast() end end @@ -279,7 +279,7 @@ local function flush_clip_queue(queue, recipient) for Holo,holoqueue in pairs(plyqueue) do for _, clip in pairs(holoqueue) do if clip and clip.index then - net.WriteUInt(Holo.ent:EntIndex(), 16) + net.WriteUInt(Holo.ent:EntIndex(), WireLib.MAX_EDICT_BITS) net.WriteUInt(clip.index, 4) -- 4: absolute highest wire_holograms_max_clips is thus 16 if clip.enabled ~= nil then net.WriteBool(true) @@ -288,13 +288,13 @@ local function flush_clip_queue(queue, recipient) net.WriteBool(false) net.WriteVector(clip.origin) net.WriteVector(clip.normal) - net.WriteUInt(clip.localentid, 16) + net.WriteUInt(clip.localentid, WireLib.MAX_EDICT_BITS) end end end end end - net.WriteUInt(0, 16) + net.WriteUInt(0, WireLib.MAX_EDICT_BITS) if recipient then net.Send(recipient) else net.Broadcast() end end @@ -305,10 +305,10 @@ local function flush_vis_queue() if IsValid( ply ) and next(plyqueue) ~= nil then net.Start("wire_holograms_set_visible") for Holo,visible in pairs(plyqueue) do - net.WriteUInt(Holo.ent:EntIndex(), 16) + net.WriteUInt(Holo.ent:EntIndex(), WireLib.MAX_EDICT_BITS) net.WriteBit(visible) end - net.WriteUInt(0, 16) + net.WriteUInt(0, WireLib.MAX_EDICT_BITS) net.Send(ply) end end @@ -320,11 +320,11 @@ local function flush_player_color_queue() net.Start("wire_holograms_set_player_color") for _, plyqueue in pairs(player_color_queue) do for Holo,color in pairs(plyqueue) do - net.WriteUInt(Holo.ent:EntIndex(), 16) + net.WriteUInt(Holo.ent:EntIndex(), WireLib.MAX_EDICT_BITS) net.WriteVector(color) end end - net.WriteUInt(0, 16) + net.WriteUInt(0, WireLib.MAX_EDICT_BITS) net.Broadcast() end diff --git a/lua/entities/gmod_wire_hologram.lua b/lua/entities/gmod_wire_hologram.lua index c789e4ce31..602f95d9b2 100644 --- a/lua/entities/gmod_wire_hologram.lua +++ b/lua/entities/gmod_wire_hologram.lua @@ -181,8 +181,9 @@ if CLIENT then end net.Receive("wire_holograms_clip", function(netlen) + print("wire_holograms_clip", netlen) while true do - local entid = net.ReadUInt(16) + local entid = net.ReadUInt(WireLib.MAX_EDICT_BITS) if entid == 0 then return end -- stupid hack to not include amount of entities in the message. feel free to rework this. local clipid = net.ReadUInt(4) @@ -190,7 +191,7 @@ if CLIENT then if net.ReadBool() then SetClipEnabled(entid, clipid, net.ReadBool()) else - SetClip(entid, clipid, net.ReadVector(), net.ReadVector(), net.ReadUInt(16)) + SetClip(entid, clipid, net.ReadVector(), net.ReadVector(), net.ReadUInt(WireLib.MAX_EDICT_BITS)) end local ent = Entity(entid) @@ -270,21 +271,21 @@ if CLIENT then end net.Receive("wire_holograms_set_scale", function(netlen) - local index = net.ReadUInt(16) + local index = net.ReadUInt(WireLib.MAX_EDICT_BITS) while index ~= 0 do SetScale(index, Vector(net.ReadFloat(), net.ReadFloat(), net.ReadFloat())) - index = net.ReadUInt(16) + index = net.ReadUInt(WireLib.MAX_EDICT_BITS) end end) net.Receive("wire_holograms_set_bone_scale", function(netlen) - local index = net.ReadUInt(16) + local index = net.ReadUInt(WireLib.MAX_EDICT_BITS) local bindex = net.ReadUInt(16) - 1 -- using -1 to get negative -1 for reset while index ~= 0 do SetBoneScale(index, bindex, Vector(net.ReadFloat(), net.ReadFloat(), net.ReadFloat())) - index = net.ReadUInt(16) + index = net.ReadUInt(WireLib.MAX_EDICT_BITS) bindex = net.ReadUInt(16) - 1 end end) @@ -301,7 +302,7 @@ if CLIENT then end net.Receive("wire_holograms_set_visible", function(netlen) - local index = net.ReadUInt(16) + local index = net.ReadUInt(WireLib.MAX_EDICT_BITS) while index ~= 0 do @@ -312,7 +313,7 @@ if CLIENT then vis_buffer[index] = net.ReadBit() == 0 end - index = net.ReadUInt(16) + index = net.ReadUInt(WireLib.MAX_EDICT_BITS) end end) @@ -338,7 +339,7 @@ if CLIENT then end net.Receive("wire_holograms_set_player_color", function(netlen) - local index = net.ReadUInt(16) + local index = net.ReadUInt(WireLib.MAX_EDICT_BITS) while index ~= 0 do local ent = Entity(index) @@ -348,7 +349,7 @@ if CLIENT then player_color_buffer[index] = net.ReadVector() end - index = net.ReadUInt(16) + index = net.ReadUInt(WireLib.MAX_EDICT_BITS) end end) diff --git a/lua/wire/wireshared.lua b/lua/wire/wireshared.lua index 106989c7aa..73ae0ea14d 100644 --- a/lua/wire/wireshared.lua +++ b/lua/wire/wireshared.lua @@ -16,6 +16,8 @@ local string_sub = string.sub local utf8_char = utf8.char local hook = hook +WireLib.MAX_EDICT_BITS = net.MAX_EDICT_BITS or 13 + -- extra table functions -- Returns a noniterable version of tbl. So indexing still works, but pairs(tbl) won't find anything From cba3919ea30b1e02e61346d3547688742ca05204 Mon Sep 17 00:00:00 2001 From: Redox Date: Sat, 7 Dec 2024 18:22:05 +0100 Subject: [PATCH 2/6] Cleanup --- lua/entities/gmod_wire_hologram.lua | 3 --- 1 file changed, 3 deletions(-) diff --git a/lua/entities/gmod_wire_hologram.lua b/lua/entities/gmod_wire_hologram.lua index 602f95d9b2..7863fe728b 100644 --- a/lua/entities/gmod_wire_hologram.lua +++ b/lua/entities/gmod_wire_hologram.lua @@ -181,7 +181,6 @@ if CLIENT then end net.Receive("wire_holograms_clip", function(netlen) - print("wire_holograms_clip", netlen) while true do local entid = net.ReadUInt(WireLib.MAX_EDICT_BITS) if entid == 0 then return end -- stupid hack to not include amount of entities in the message. feel free to rework this. @@ -334,8 +333,6 @@ if CLIENT then SetPlayerColor(eidx, player_color_buffer[eidx]) player_color_buffer[eidx] = nil end - - end net.Receive("wire_holograms_set_player_color", function(netlen) From 92ba9ab7f2746eea987ca7d4e5f7ceae0d094ca8 Mon Sep 17 00:00:00 2001 From: Redox Date: Sat, 7 Dec 2024 18:30:26 +0100 Subject: [PATCH 3/6] Use right bit amount for bones --- lua/entities/gmod_wire_expression2/core/hologram.lua | 2 +- lua/entities/gmod_wire_hologram.lua | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/hologram.lua b/lua/entities/gmod_wire_expression2/core/hologram.lua index 69c3c9e2c3..798517f759 100644 --- a/lua/entities/gmod_wire_expression2/core/hologram.lua +++ b/lua/entities/gmod_wire_expression2/core/hologram.lua @@ -258,7 +258,7 @@ local function flush_bone_scale_queue(queue, recipient) for Holo, holoqueue in pairs(plyqueue) do for bone, scale in pairs(holoqueue) do net.WriteUInt(Holo.ent:EntIndex(), WireLib.MAX_EDICT_BITS) - net.WriteUInt(bone + 1, 16) -- using +1 to be able reset holo bones scale with -1 and not use signed int + net.WriteUInt(bone + 1, 9) -- using +1 to be able reset holo bones scale with -1 and not use signed int net.WriteFloat(scale.x) net.WriteFloat(scale.y) net.WriteFloat(scale.z) diff --git a/lua/entities/gmod_wire_hologram.lua b/lua/entities/gmod_wire_hologram.lua index 7863fe728b..7a9e7946db 100644 --- a/lua/entities/gmod_wire_hologram.lua +++ b/lua/entities/gmod_wire_hologram.lua @@ -280,12 +280,12 @@ if CLIENT then net.Receive("wire_holograms_set_bone_scale", function(netlen) local index = net.ReadUInt(WireLib.MAX_EDICT_BITS) - local bindex = net.ReadUInt(16) - 1 -- using -1 to get negative -1 for reset + local bindex = net.ReadUInt(9) - 1 -- using -1 to get negative -1 for reset while index ~= 0 do SetBoneScale(index, bindex, Vector(net.ReadFloat(), net.ReadFloat(), net.ReadFloat())) index = net.ReadUInt(WireLib.MAX_EDICT_BITS) - bindex = net.ReadUInt(16) - 1 + bindex = net.ReadUInt(9) - 1 end end) From 96b25f81a2a737d8e247312aa20caa1987a918ef Mon Sep 17 00:00:00 2001 From: Redox Date: Wed, 11 Dec 2024 19:27:46 +0100 Subject: [PATCH 4/6] Use new gmod global --- lua/wire/wireshared.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/wire/wireshared.lua b/lua/wire/wireshared.lua index 73ae0ea14d..1ff41a22be 100644 --- a/lua/wire/wireshared.lua +++ b/lua/wire/wireshared.lua @@ -16,7 +16,7 @@ local string_sub = string.sub local utf8_char = utf8.char local hook = hook -WireLib.MAX_EDICT_BITS = net.MAX_EDICT_BITS or 13 +WireLib.MAX_EDICT_BITS = MAX_EDICT_BITS or 13 -- extra table functions From 12133214952d9f1acb9bb64a14fd9b4c715b2292 Mon Sep 17 00:00:00 2001 From: Redox Date: Wed, 11 Dec 2024 22:03:28 +0100 Subject: [PATCH 5/6] Use MAX_EDICT_BITS global --- .../gmod_wire_expression2/core/hologram.lua | 22 +++++++++---------- lua/entities/gmod_wire_hologram.lua | 20 ++++++++--------- lua/wire/wireshared.lua | 2 +- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/hologram.lua b/lua/entities/gmod_wire_expression2/core/hologram.lua index 798517f759..49b08b797b 100644 --- a/lua/entities/gmod_wire_expression2/core/hologram.lua +++ b/lua/entities/gmod_wire_expression2/core/hologram.lua @@ -239,13 +239,13 @@ local function flush_scale_queue(queue, recipient) net.Start("wire_holograms_set_scale") for _, plyqueue in pairs(queue) do for Holo, scale in pairs(plyqueue) do - net.WriteUInt(Holo.ent:EntIndex(), WireLib.MAX_EDICT_BITS) + net.WriteUInt(Holo.ent:EntIndex(), MAX_EDICT_BITS) net.WriteFloat(scale.x) net.WriteFloat(scale.y) net.WriteFloat(scale.z) end end - net.WriteUInt(0, WireLib.MAX_EDICT_BITS) + net.WriteUInt(0, MAX_EDICT_BITS) if recipient then net.Send(recipient) else net.Broadcast() end end @@ -257,7 +257,7 @@ local function flush_bone_scale_queue(queue, recipient) for _, plyqueue in pairs(queue) do for Holo, holoqueue in pairs(plyqueue) do for bone, scale in pairs(holoqueue) do - net.WriteUInt(Holo.ent:EntIndex(), WireLib.MAX_EDICT_BITS) + net.WriteUInt(Holo.ent:EntIndex(), MAX_EDICT_BITS) net.WriteUInt(bone + 1, 9) -- using +1 to be able reset holo bones scale with -1 and not use signed int net.WriteFloat(scale.x) net.WriteFloat(scale.y) @@ -265,7 +265,7 @@ local function flush_bone_scale_queue(queue, recipient) end end end - net.WriteUInt(0, WireLib.MAX_EDICT_BITS) + net.WriteUInt(0, MAX_EDICT_BITS) net.WriteUInt(0, 16) if recipient then net.Send(recipient) else net.Broadcast() end end @@ -279,7 +279,7 @@ local function flush_clip_queue(queue, recipient) for Holo,holoqueue in pairs(plyqueue) do for _, clip in pairs(holoqueue) do if clip and clip.index then - net.WriteUInt(Holo.ent:EntIndex(), WireLib.MAX_EDICT_BITS) + net.WriteUInt(Holo.ent:EntIndex(), MAX_EDICT_BITS) net.WriteUInt(clip.index, 4) -- 4: absolute highest wire_holograms_max_clips is thus 16 if clip.enabled ~= nil then net.WriteBool(true) @@ -288,13 +288,13 @@ local function flush_clip_queue(queue, recipient) net.WriteBool(false) net.WriteVector(clip.origin) net.WriteVector(clip.normal) - net.WriteUInt(clip.localentid, WireLib.MAX_EDICT_BITS) + net.WriteUInt(clip.localentid, MAX_EDICT_BITS) end end end end end - net.WriteUInt(0, WireLib.MAX_EDICT_BITS) + net.WriteUInt(0, MAX_EDICT_BITS) if recipient then net.Send(recipient) else net.Broadcast() end end @@ -305,10 +305,10 @@ local function flush_vis_queue() if IsValid( ply ) and next(plyqueue) ~= nil then net.Start("wire_holograms_set_visible") for Holo,visible in pairs(plyqueue) do - net.WriteUInt(Holo.ent:EntIndex(), WireLib.MAX_EDICT_BITS) + net.WriteUInt(Holo.ent:EntIndex(), MAX_EDICT_BITS) net.WriteBit(visible) end - net.WriteUInt(0, WireLib.MAX_EDICT_BITS) + net.WriteUInt(0, MAX_EDICT_BITS) net.Send(ply) end end @@ -320,11 +320,11 @@ local function flush_player_color_queue() net.Start("wire_holograms_set_player_color") for _, plyqueue in pairs(player_color_queue) do for Holo,color in pairs(plyqueue) do - net.WriteUInt(Holo.ent:EntIndex(), WireLib.MAX_EDICT_BITS) + net.WriteUInt(Holo.ent:EntIndex(), MAX_EDICT_BITS) net.WriteVector(color) end end - net.WriteUInt(0, WireLib.MAX_EDICT_BITS) + net.WriteUInt(0, MAX_EDICT_BITS) net.Broadcast() end diff --git a/lua/entities/gmod_wire_hologram.lua b/lua/entities/gmod_wire_hologram.lua index 7a9e7946db..c176b5861b 100644 --- a/lua/entities/gmod_wire_hologram.lua +++ b/lua/entities/gmod_wire_hologram.lua @@ -182,7 +182,7 @@ if CLIENT then net.Receive("wire_holograms_clip", function(netlen) while true do - local entid = net.ReadUInt(WireLib.MAX_EDICT_BITS) + local entid = net.ReadUInt(MAX_EDICT_BITS) if entid == 0 then return end -- stupid hack to not include amount of entities in the message. feel free to rework this. local clipid = net.ReadUInt(4) @@ -190,7 +190,7 @@ if CLIENT then if net.ReadBool() then SetClipEnabled(entid, clipid, net.ReadBool()) else - SetClip(entid, clipid, net.ReadVector(), net.ReadVector(), net.ReadUInt(WireLib.MAX_EDICT_BITS)) + SetClip(entid, clipid, net.ReadVector(), net.ReadVector(), net.ReadUInt(MAX_EDICT_BITS)) end local ent = Entity(entid) @@ -270,21 +270,21 @@ if CLIENT then end net.Receive("wire_holograms_set_scale", function(netlen) - local index = net.ReadUInt(WireLib.MAX_EDICT_BITS) + local index = net.ReadUInt(MAX_EDICT_BITS) while index ~= 0 do SetScale(index, Vector(net.ReadFloat(), net.ReadFloat(), net.ReadFloat())) - index = net.ReadUInt(WireLib.MAX_EDICT_BITS) + index = net.ReadUInt(MAX_EDICT_BITS) end end) net.Receive("wire_holograms_set_bone_scale", function(netlen) - local index = net.ReadUInt(WireLib.MAX_EDICT_BITS) + local index = net.ReadUInt(MAX_EDICT_BITS) local bindex = net.ReadUInt(9) - 1 -- using -1 to get negative -1 for reset while index ~= 0 do SetBoneScale(index, bindex, Vector(net.ReadFloat(), net.ReadFloat(), net.ReadFloat())) - index = net.ReadUInt(WireLib.MAX_EDICT_BITS) + index = net.ReadUInt(MAX_EDICT_BITS) bindex = net.ReadUInt(9) - 1 end end) @@ -301,7 +301,7 @@ if CLIENT then end net.Receive("wire_holograms_set_visible", function(netlen) - local index = net.ReadUInt(WireLib.MAX_EDICT_BITS) + local index = net.ReadUInt(MAX_EDICT_BITS) while index ~= 0 do @@ -312,7 +312,7 @@ if CLIENT then vis_buffer[index] = net.ReadBit() == 0 end - index = net.ReadUInt(WireLib.MAX_EDICT_BITS) + index = net.ReadUInt(MAX_EDICT_BITS) end end) @@ -336,7 +336,7 @@ if CLIENT then end net.Receive("wire_holograms_set_player_color", function(netlen) - local index = net.ReadUInt(WireLib.MAX_EDICT_BITS) + local index = net.ReadUInt(MAX_EDICT_BITS) while index ~= 0 do local ent = Entity(index) @@ -346,7 +346,7 @@ if CLIENT then player_color_buffer[index] = net.ReadVector() end - index = net.ReadUInt(WireLib.MAX_EDICT_BITS) + index = net.ReadUInt(MAX_EDICT_BITS) end end) diff --git a/lua/wire/wireshared.lua b/lua/wire/wireshared.lua index 1ff41a22be..8f6deb7930 100644 --- a/lua/wire/wireshared.lua +++ b/lua/wire/wireshared.lua @@ -16,7 +16,7 @@ local string_sub = string.sub local utf8_char = utf8.char local hook = hook -WireLib.MAX_EDICT_BITS = MAX_EDICT_BITS or 13 +MAX_EDICT_BITS = MAX_EDICT_BITS or 13 -- Delete once MAX_EDICT_BITS is fully out in base GMod -- extra table functions From 0b67d86acd57812a6a4d2a01dc7f1cac42cb8e8a Mon Sep 17 00:00:00 2001 From: Redox Date: Sun, 15 Dec 2024 16:03:54 +0100 Subject: [PATCH 6/6] Use MAX_EDICT_BITS in wires networking --- lua/wire/wireshared.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/wire/wireshared.lua b/lua/wire/wireshared.lua index 8f6deb7930..08689d365b 100644 --- a/lua/wire/wireshared.lua +++ b/lua/wire/wireshared.lua @@ -480,7 +480,7 @@ if SERVER then if not DontSend then net.Start("wire_ports") net.WriteInt(-3, 8) -- set eid - net.WriteUInt(eid, 16) -- entity id + net.WriteUInt(eid, MAX_EDICT_BITS) -- entity id if hasinputs then net.WriteInt(-1, 8) end -- delete inputs if hasoutputs then net.WriteInt(-2, 8) end -- delete outputs net.WriteInt(0, 8) -- break @@ -561,7 +561,7 @@ if SERVER then eid = msg[1] writeCurrentStrings() -- We're switching to talking about a different entity, lets send port information net.WriteInt(-3,8) - net.WriteUInt(eid,16) + net.WriteUInt(eid,MAX_EDICT_BITS) end local msgtype = msg[2] @@ -637,7 +637,7 @@ elseif CLIENT then elseif cmd == -2 then ents_with_outputs[eid] = nil elseif cmd == -3 then - eid = net.ReadUInt(16) + eid = net.ReadUInt(MAX_EDICT_BITS) elseif cmd == -4 then connections[#connections+1] = {eid, net.ReadUInt(8), net.ReadBit() ~= 0} -- Delay this process till after the loop elseif cmd > 0 then