From d17a5255ac1147588f3a880f187c1852644e7e39 Mon Sep 17 00:00:00 2001 From: Zvbhrf Date: Sat, 7 Sep 2024 02:49:05 +0500 Subject: [PATCH 1/8] Save wiremod holograms from NaN indexes --- .../gmod_wire_expression2/core/hologram.lua | 70 ++++++++++++------- 1 file changed, 43 insertions(+), 27 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/hologram.lua b/lua/entities/gmod_wire_expression2/core/hologram.lua index d855e6fc29..8aac4152e5 100644 --- a/lua/entities/gmod_wire_expression2/core/hologram.lua +++ b/lua/entities/gmod_wire_expression2/core/hologram.lua @@ -510,6 +510,19 @@ end) -- ----------------------------------------------------------------------------- +local MAX_INDEX = 2 ^ 31 +local function makeAppropriateIndex(index) + if not isnumber(index) then + return 0 + end + + if index ~= index then + return 0 + end + + return math.Clamp(math.floor(index), -MAX_INDEX, MAX_INDEX) +end + local function MakeHolo(Player, Pos, Ang, model) local prop = ents.Create( "gmod_wire_hologram" ) WireLib.setPos(prop, Pos) @@ -522,15 +535,17 @@ end -- Returns the hologram with the given index or nil if it doesn't exist. -- if shouldbenil is nil or false, assert that the hologram exists on @strict with an error. Otherwise, don't check (for holo creation, etc) local function CheckIndex(self, index, shouldbenil) - index = math.Clamp(math.floor(index), -2^31, 2^31) + index = makeAppropriateIndex(index) + local Holo - if index<0 then + if index < 0 then Holo = E2HoloRepo[self.uid][-index] else Holo = self.data.holos[index] end if (not Holo or not IsValid(Holo.ent)) and not shouldbenil then return self:throw("Holo at index " .. index .. " does not exist!", nil) end - return Holo + + return Holo, index end -- checks if a bone id is valid for a holo, throws an error for @strict if not. @@ -561,7 +576,8 @@ local function CreateHolo(self, index, pos, scale, ang, color, model) model = GetModel(self, model or "cube") or "models/holograms/cube.mdl" - local Holo = CheckIndex(self, index, true) + local Holo, index = CheckIndex(self, index, true) + if not Holo then Holo = {} SetIndex(self, index, Holo) @@ -585,7 +601,7 @@ local function CreateHolo(self, index, pos, scale, ang, color, model) Holo.e2owner = self prop:CallOnRemove( "holo_cleanup", function( ent, self, index ) --Give the player more holograms if we get removed - local Holo = CheckIndex( self, index ) + local Holo, index = CheckIndex( self, index ) if not Holo then return end PlayerAmount[self.uid] = PlayerAmount[self.uid] - 1 @@ -676,7 +692,7 @@ __e2setcost(30) -- temporary e2function entity holoCreate(index, vector position, vector scale, angle ang, vector color, string model) if not checkOwner(self) then return end if BlockList[self.player:SteamID()] == true or CheckSpawnTimer( self ) == false then return end - local Holo = CheckIndex(self, index, true) + local Holo, index = CheckIndex(self, index, true) if not Holo and checkHoloCount(self) then return end position = Vector(position[1], position[2], position[3]) @@ -688,7 +704,7 @@ end e2function entity holoCreate(index, vector position, vector scale, angle ang, vector4 color, string model) if not checkOwner(self) then return end if BlockList[self.player:SteamID()] == true or CheckSpawnTimer( self ) == false then return end - local Holo = CheckIndex(self, index, true) + local Holo, index = CheckIndex(self, index, true) if not Holo and checkHoloCount(self) then return end position = Vector(position[1], position[2], position[3]) @@ -700,7 +716,7 @@ end e2function entity holoCreate(index, vector position, vector scale, angle ang, vector color) if not checkOwner(self) then return end if BlockList[self.player:SteamID()] == true or CheckSpawnTimer( self ) == false then return end - local Holo = CheckIndex(self, index, true) + local Holo, index = CheckIndex(self, index, true) if not Holo and checkHoloCount(self) then return end position = Vector(position[1], position[2], position[3]) @@ -712,7 +728,7 @@ end e2function entity holoCreate(index, vector position, vector scale, angle ang, vector4 color) if not checkOwner(self) then return end if BlockList[self.player:SteamID()] == true or CheckSpawnTimer( self ) == false then return end - local Holo = CheckIndex(self, index, true) + local Holo, index = CheckIndex(self, index, true) if not Holo and checkHoloCount(self) then return end position = Vector(position[1], position[2], position[3]) @@ -724,7 +740,7 @@ end e2function entity holoCreate(index, vector position, vector scale, angle ang) if not checkOwner(self) then return end if BlockList[self.player:SteamID()] == true or CheckSpawnTimer( self ) == false then return end - local Holo = CheckIndex(self, index, true) + local Holo, index = CheckIndex(self, index, true) if not Holo and checkHoloCount(self) then return end position = Vector(position[1], position[2], position[3]) @@ -736,7 +752,7 @@ end e2function entity holoCreate(index, vector position, vector scale) if not checkOwner(self) then return end if BlockList[self.player:SteamID()] == true or CheckSpawnTimer( self ) == false then return end - local Holo = CheckIndex(self, index, true) + local Holo, index = CheckIndex(self, index, true) if not Holo and checkHoloCount(self) then return end position = Vector(position[1],position[2],position[3]) @@ -747,7 +763,7 @@ end e2function entity holoCreate(index, vector position) if not checkOwner(self) then return end if BlockList[self.player:SteamID()] == true or CheckSpawnTimer( self ) == false then return end - local Holo = CheckIndex(self, index, true) + local Holo, index = CheckIndex(self, index, true) if not Holo and checkHoloCount(self) then return end position = Vector(position[1],position[2],position[3]) @@ -758,7 +774,7 @@ end e2function entity holoCreate(index) if not checkOwner(self) then return end if BlockList[self.player:SteamID()] == true or CheckSpawnTimer( self ) == false then return end - local Holo = CheckIndex(self, index, true) + local Holo, index = CheckIndex(self, index, true) if not Holo and PlayerAmount[self.uid] >= wire_holograms_max:GetInt() then return end local ret = CreateHolo(self, index) @@ -767,7 +783,7 @@ end __e2setcost(20) e2function void holoDelete(index) - local Holo = CheckIndex(self, index) + local Holo, index = CheckIndex(self, index) if not Holo then return end remove_holo(Holo) @@ -788,7 +804,7 @@ end e2function void holoReset(index, string model, vector scale, vector color, string material) model = GetModel(self, model) if not model then return end - local Holo = CheckIndex(self, index) + local Holo, index = CheckIndex(self, index) if not Holo then return end Holo.ent:SetModel(model) @@ -829,21 +845,21 @@ end __e2setcost(30) -- temporary e2function void holoScale(index, vector scale) - local Holo = CheckIndex(self, index) + local Holo, index = CheckIndex(self, index) if not Holo then return end rescale(Holo, scale) end e2function vector holoScale(index) - local Holo = CheckIndex(self, index) + local Holo, index = CheckIndex(self, index) if not Holo then return end return Holo.scale or Vector(0, 0, 0) -- TODO: maybe 1,1,1? end e2function void holoScaleUnits(index, vector size) - local Holo = CheckIndex(self, index) + local Holo, index = CheckIndex(self, index) if not Holo then return end local propsize = Holo.ent:OBBMaxs()-Holo.ent:OBBMins() @@ -856,7 +872,7 @@ e2function void holoScaleUnits(index, vector size) end e2function vector holoScaleUnits(index) - local Holo = CheckIndex(self, index) + local Holo, index = CheckIndex(self, index) if not Holo then return self:throw("Holo at index " .. index .. " does not exist!", Vector(0, 0, 0)) end local scale = Holo.scale or Vector(0, 0, 0) -- TODO: maybe 1,1,1? @@ -869,7 +885,7 @@ end -- ----------------------------------------------------------------------------- e2function void holoBoneScale(index, boneindex, vector scale) - local Holo = CheckIndex(self, index) + local Holo, index = CheckIndex(self, index) if not Holo then return end if not CheckBone(self, index, boneindex, Holo) then return end @@ -877,7 +893,7 @@ e2function void holoBoneScale(index, boneindex, vector scale) end e2function void holoBoneScale(index, string bone, vector scale) - local Holo = CheckIndex(self, index) + local Holo, index = CheckIndex(self, index) if not Holo then return end local boneindex = Holo.ent:LookupBone(bone) if boneindex == nil then return self:throw("Holo at index " .. index .. " does not have a bone ['" .. bone .. "']!", nil) end @@ -886,7 +902,7 @@ e2function void holoBoneScale(index, string bone, vector scale) end e2function vector holoBoneScale(index, boneindex) - local Holo = CheckIndex(self, index) + local Holo, index = CheckIndex(self, index) if not Holo then return Vector(0, 0, 0) end if not CheckBone(self, index, boneindex, Holo) then return Vector(0, 0, 0) end @@ -894,7 +910,7 @@ e2function vector holoBoneScale(index, boneindex) end e2function vector holoBoneScale(index, string bone) - local Holo = CheckIndex(self, index) + local Holo, index = CheckIndex(self, index) if not Holo then return Vector(0, 0, 0) end local boneindex = Holo.ent:LookupBone(bone) @@ -903,7 +919,7 @@ e2function vector holoBoneScale(index, string bone) end e2function vector holoBonePos(index, boneindex) - local Holo = CheckIndex(self, index) + local Holo, index = CheckIndex(self, index) if not Holo then return Vector(0, 0, 0) end if not CheckBone(self, index, boneindex, Holo) then return Vector(0, 0, 0) end @@ -912,7 +928,7 @@ end e2function vector holoBonePos(index, string bone) - local Holo = CheckIndex(self, index) + local Holo, index = CheckIndex(self, index) if not Holo then return self:throw("Holo at index " .. index .. " does not exist!", Vector(0, 0, 0)) end local boneindex = Holo.ent:LookupBone(bone) @@ -921,7 +937,7 @@ e2function vector holoBonePos(index, string bone) end e2function angle holoBoneAng(index, boneindex) - local Holo = CheckIndex(self, index) + local Holo, index = CheckIndex(self, index) if not Holo then return Angle(0, 0, 0) end if not CheckBone(self, index, boneindex, Holo) then return Angle(0, 0, 0) end @@ -930,7 +946,7 @@ end e2function angle holoBoneAng(index, string bone) - local Holo = CheckIndex(self, index) + local Holo, index = CheckIndex(self, index) if not Holo then return self:throw("Holo at index " .. index .. " does not exist!", Angle(0, 0, 0)) end local boneindex = Holo.ent:LookupBone(bone) From 10785c5644edf7bd85d95cf8746d930f6de99655 Mon Sep 17 00:00:00 2001 From: Zvbhrf Date: Sat, 7 Sep 2024 03:03:56 +0500 Subject: [PATCH 2/8] Throw an error if NaN --- lua/entities/gmod_wire_expression2/core/hologram.lua | 6 +++--- 1 file 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 8aac4152e5..291647acae 100644 --- a/lua/entities/gmod_wire_expression2/core/hologram.lua +++ b/lua/entities/gmod_wire_expression2/core/hologram.lua @@ -511,13 +511,13 @@ end) -- ----------------------------------------------------------------------------- local MAX_INDEX = 2 ^ 31 -local function makeAppropriateIndex(index) +local function makeAppropriateIndex(self, index) if not isnumber(index) then return 0 end if index ~= index then - return 0 + return self:throw("holo index is NaN!", 0) end return math.Clamp(math.floor(index), -MAX_INDEX, MAX_INDEX) @@ -535,7 +535,7 @@ end -- Returns the hologram with the given index or nil if it doesn't exist. -- if shouldbenil is nil or false, assert that the hologram exists on @strict with an error. Otherwise, don't check (for holo creation, etc) local function CheckIndex(self, index, shouldbenil) - index = makeAppropriateIndex(index) + index = makeAppropriateIndex(self, index) local Holo if index < 0 then From c51d6021f9c61242f97a06f1ed57bcb24e35e720 Mon Sep 17 00:00:00 2001 From: Zvbhrf Date: Sat, 7 Sep 2024 03:10:56 +0500 Subject: [PATCH 3/8] Revert "Throw an error if NaN" This reverts commit 10785c5644edf7bd85d95cf8746d930f6de99655. --- lua/entities/gmod_wire_expression2/core/hologram.lua | 6 +++--- 1 file 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 291647acae..8aac4152e5 100644 --- a/lua/entities/gmod_wire_expression2/core/hologram.lua +++ b/lua/entities/gmod_wire_expression2/core/hologram.lua @@ -511,13 +511,13 @@ end) -- ----------------------------------------------------------------------------- local MAX_INDEX = 2 ^ 31 -local function makeAppropriateIndex(self, index) +local function makeAppropriateIndex(index) if not isnumber(index) then return 0 end if index ~= index then - return self:throw("holo index is NaN!", 0) + return 0 end return math.Clamp(math.floor(index), -MAX_INDEX, MAX_INDEX) @@ -535,7 +535,7 @@ end -- Returns the hologram with the given index or nil if it doesn't exist. -- if shouldbenil is nil or false, assert that the hologram exists on @strict with an error. Otherwise, don't check (for holo creation, etc) local function CheckIndex(self, index, shouldbenil) - index = makeAppropriateIndex(self, index) + index = makeAppropriateIndex(index) local Holo if index < 0 then From 6862b58971cd42de6a9e858d0b1ed0e4a054f1bc Mon Sep 17 00:00:00 2001 From: Zvbhrf Date: Sat, 7 Sep 2024 03:11:38 +0500 Subject: [PATCH 4/8] Ok, I thought setting index to 0 was a good idea. Revert "Save wiremod holograms from NaN indexes" This reverts commit d17a5255ac1147588f3a880f187c1852644e7e39. --- .../gmod_wire_expression2/core/hologram.lua | 70 +++++++------------ 1 file changed, 27 insertions(+), 43 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/hologram.lua b/lua/entities/gmod_wire_expression2/core/hologram.lua index 8aac4152e5..d855e6fc29 100644 --- a/lua/entities/gmod_wire_expression2/core/hologram.lua +++ b/lua/entities/gmod_wire_expression2/core/hologram.lua @@ -510,19 +510,6 @@ end) -- ----------------------------------------------------------------------------- -local MAX_INDEX = 2 ^ 31 -local function makeAppropriateIndex(index) - if not isnumber(index) then - return 0 - end - - if index ~= index then - return 0 - end - - return math.Clamp(math.floor(index), -MAX_INDEX, MAX_INDEX) -end - local function MakeHolo(Player, Pos, Ang, model) local prop = ents.Create( "gmod_wire_hologram" ) WireLib.setPos(prop, Pos) @@ -535,17 +522,15 @@ end -- Returns the hologram with the given index or nil if it doesn't exist. -- if shouldbenil is nil or false, assert that the hologram exists on @strict with an error. Otherwise, don't check (for holo creation, etc) local function CheckIndex(self, index, shouldbenil) - index = makeAppropriateIndex(index) - + index = math.Clamp(math.floor(index), -2^31, 2^31) local Holo - if index < 0 then + if index<0 then Holo = E2HoloRepo[self.uid][-index] else Holo = self.data.holos[index] end if (not Holo or not IsValid(Holo.ent)) and not shouldbenil then return self:throw("Holo at index " .. index .. " does not exist!", nil) end - - return Holo, index + return Holo end -- checks if a bone id is valid for a holo, throws an error for @strict if not. @@ -576,8 +561,7 @@ local function CreateHolo(self, index, pos, scale, ang, color, model) model = GetModel(self, model or "cube") or "models/holograms/cube.mdl" - local Holo, index = CheckIndex(self, index, true) - + local Holo = CheckIndex(self, index, true) if not Holo then Holo = {} SetIndex(self, index, Holo) @@ -601,7 +585,7 @@ local function CreateHolo(self, index, pos, scale, ang, color, model) Holo.e2owner = self prop:CallOnRemove( "holo_cleanup", function( ent, self, index ) --Give the player more holograms if we get removed - local Holo, index = CheckIndex( self, index ) + local Holo = CheckIndex( self, index ) if not Holo then return end PlayerAmount[self.uid] = PlayerAmount[self.uid] - 1 @@ -692,7 +676,7 @@ __e2setcost(30) -- temporary e2function entity holoCreate(index, vector position, vector scale, angle ang, vector color, string model) if not checkOwner(self) then return end if BlockList[self.player:SteamID()] == true or CheckSpawnTimer( self ) == false then return end - local Holo, index = CheckIndex(self, index, true) + local Holo = CheckIndex(self, index, true) if not Holo and checkHoloCount(self) then return end position = Vector(position[1], position[2], position[3]) @@ -704,7 +688,7 @@ end e2function entity holoCreate(index, vector position, vector scale, angle ang, vector4 color, string model) if not checkOwner(self) then return end if BlockList[self.player:SteamID()] == true or CheckSpawnTimer( self ) == false then return end - local Holo, index = CheckIndex(self, index, true) + local Holo = CheckIndex(self, index, true) if not Holo and checkHoloCount(self) then return end position = Vector(position[1], position[2], position[3]) @@ -716,7 +700,7 @@ end e2function entity holoCreate(index, vector position, vector scale, angle ang, vector color) if not checkOwner(self) then return end if BlockList[self.player:SteamID()] == true or CheckSpawnTimer( self ) == false then return end - local Holo, index = CheckIndex(self, index, true) + local Holo = CheckIndex(self, index, true) if not Holo and checkHoloCount(self) then return end position = Vector(position[1], position[2], position[3]) @@ -728,7 +712,7 @@ end e2function entity holoCreate(index, vector position, vector scale, angle ang, vector4 color) if not checkOwner(self) then return end if BlockList[self.player:SteamID()] == true or CheckSpawnTimer( self ) == false then return end - local Holo, index = CheckIndex(self, index, true) + local Holo = CheckIndex(self, index, true) if not Holo and checkHoloCount(self) then return end position = Vector(position[1], position[2], position[3]) @@ -740,7 +724,7 @@ end e2function entity holoCreate(index, vector position, vector scale, angle ang) if not checkOwner(self) then return end if BlockList[self.player:SteamID()] == true or CheckSpawnTimer( self ) == false then return end - local Holo, index = CheckIndex(self, index, true) + local Holo = CheckIndex(self, index, true) if not Holo and checkHoloCount(self) then return end position = Vector(position[1], position[2], position[3]) @@ -752,7 +736,7 @@ end e2function entity holoCreate(index, vector position, vector scale) if not checkOwner(self) then return end if BlockList[self.player:SteamID()] == true or CheckSpawnTimer( self ) == false then return end - local Holo, index = CheckIndex(self, index, true) + local Holo = CheckIndex(self, index, true) if not Holo and checkHoloCount(self) then return end position = Vector(position[1],position[2],position[3]) @@ -763,7 +747,7 @@ end e2function entity holoCreate(index, vector position) if not checkOwner(self) then return end if BlockList[self.player:SteamID()] == true or CheckSpawnTimer( self ) == false then return end - local Holo, index = CheckIndex(self, index, true) + local Holo = CheckIndex(self, index, true) if not Holo and checkHoloCount(self) then return end position = Vector(position[1],position[2],position[3]) @@ -774,7 +758,7 @@ end e2function entity holoCreate(index) if not checkOwner(self) then return end if BlockList[self.player:SteamID()] == true or CheckSpawnTimer( self ) == false then return end - local Holo, index = CheckIndex(self, index, true) + local Holo = CheckIndex(self, index, true) if not Holo and PlayerAmount[self.uid] >= wire_holograms_max:GetInt() then return end local ret = CreateHolo(self, index) @@ -783,7 +767,7 @@ end __e2setcost(20) e2function void holoDelete(index) - local Holo, index = CheckIndex(self, index) + local Holo = CheckIndex(self, index) if not Holo then return end remove_holo(Holo) @@ -804,7 +788,7 @@ end e2function void holoReset(index, string model, vector scale, vector color, string material) model = GetModel(self, model) if not model then return end - local Holo, index = CheckIndex(self, index) + local Holo = CheckIndex(self, index) if not Holo then return end Holo.ent:SetModel(model) @@ -845,21 +829,21 @@ end __e2setcost(30) -- temporary e2function void holoScale(index, vector scale) - local Holo, index = CheckIndex(self, index) + local Holo = CheckIndex(self, index) if not Holo then return end rescale(Holo, scale) end e2function vector holoScale(index) - local Holo, index = CheckIndex(self, index) + local Holo = CheckIndex(self, index) if not Holo then return end return Holo.scale or Vector(0, 0, 0) -- TODO: maybe 1,1,1? end e2function void holoScaleUnits(index, vector size) - local Holo, index = CheckIndex(self, index) + local Holo = CheckIndex(self, index) if not Holo then return end local propsize = Holo.ent:OBBMaxs()-Holo.ent:OBBMins() @@ -872,7 +856,7 @@ e2function void holoScaleUnits(index, vector size) end e2function vector holoScaleUnits(index) - local Holo, index = CheckIndex(self, index) + local Holo = CheckIndex(self, index) if not Holo then return self:throw("Holo at index " .. index .. " does not exist!", Vector(0, 0, 0)) end local scale = Holo.scale or Vector(0, 0, 0) -- TODO: maybe 1,1,1? @@ -885,7 +869,7 @@ end -- ----------------------------------------------------------------------------- e2function void holoBoneScale(index, boneindex, vector scale) - local Holo, index = CheckIndex(self, index) + local Holo = CheckIndex(self, index) if not Holo then return end if not CheckBone(self, index, boneindex, Holo) then return end @@ -893,7 +877,7 @@ e2function void holoBoneScale(index, boneindex, vector scale) end e2function void holoBoneScale(index, string bone, vector scale) - local Holo, index = CheckIndex(self, index) + local Holo = CheckIndex(self, index) if not Holo then return end local boneindex = Holo.ent:LookupBone(bone) if boneindex == nil then return self:throw("Holo at index " .. index .. " does not have a bone ['" .. bone .. "']!", nil) end @@ -902,7 +886,7 @@ e2function void holoBoneScale(index, string bone, vector scale) end e2function vector holoBoneScale(index, boneindex) - local Holo, index = CheckIndex(self, index) + local Holo = CheckIndex(self, index) if not Holo then return Vector(0, 0, 0) end if not CheckBone(self, index, boneindex, Holo) then return Vector(0, 0, 0) end @@ -910,7 +894,7 @@ e2function vector holoBoneScale(index, boneindex) end e2function vector holoBoneScale(index, string bone) - local Holo, index = CheckIndex(self, index) + local Holo = CheckIndex(self, index) if not Holo then return Vector(0, 0, 0) end local boneindex = Holo.ent:LookupBone(bone) @@ -919,7 +903,7 @@ e2function vector holoBoneScale(index, string bone) end e2function vector holoBonePos(index, boneindex) - local Holo, index = CheckIndex(self, index) + local Holo = CheckIndex(self, index) if not Holo then return Vector(0, 0, 0) end if not CheckBone(self, index, boneindex, Holo) then return Vector(0, 0, 0) end @@ -928,7 +912,7 @@ end e2function vector holoBonePos(index, string bone) - local Holo, index = CheckIndex(self, index) + local Holo = CheckIndex(self, index) if not Holo then return self:throw("Holo at index " .. index .. " does not exist!", Vector(0, 0, 0)) end local boneindex = Holo.ent:LookupBone(bone) @@ -937,7 +921,7 @@ e2function vector holoBonePos(index, string bone) end e2function angle holoBoneAng(index, boneindex) - local Holo, index = CheckIndex(self, index) + local Holo = CheckIndex(self, index) if not Holo then return Angle(0, 0, 0) end if not CheckBone(self, index, boneindex, Holo) then return Angle(0, 0, 0) end @@ -946,7 +930,7 @@ end e2function angle holoBoneAng(index, string bone) - local Holo, index = CheckIndex(self, index) + local Holo = CheckIndex(self, index) if not Holo then return self:throw("Holo at index " .. index .. " does not exist!", Angle(0, 0, 0)) end local boneindex = Holo.ent:LookupBone(bone) From 60375084981b766eee0fdd80cc5e37e7fe725d89 Mon Sep 17 00:00:00 2001 From: Zvbhrf Date: Sat, 7 Sep 2024 03:13:17 +0500 Subject: [PATCH 5/8] Just throw an error... nothing more --- lua/entities/gmod_wire_expression2/core/hologram.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lua/entities/gmod_wire_expression2/core/hologram.lua b/lua/entities/gmod_wire_expression2/core/hologram.lua index d855e6fc29..f4dbdcc1db 100644 --- a/lua/entities/gmod_wire_expression2/core/hologram.lua +++ b/lua/entities/gmod_wire_expression2/core/hologram.lua @@ -521,8 +521,10 @@ end -- Returns the hologram with the given index or nil if it doesn't exist. -- if shouldbenil is nil or false, assert that the hologram exists on @strict with an error. Otherwise, don't check (for holo creation, etc) +local MAX_INDEX = 2 ^ 31 local function CheckIndex(self, index, shouldbenil) - index = math.Clamp(math.floor(index), -2^31, 2^31) + if index ~= index then return self:throw("holo index is NaN!", 0) end + index = math.Clamp(math.floor(index), -MAX_INDEX, MAX_INDEX) local Holo if index<0 then Holo = E2HoloRepo[self.uid][-index] From be6b90a40798764ac307bea21c7d9ff61a1d4fb6 Mon Sep 17 00:00:00 2001 From: Zvbhrf Date: Mon, 9 Sep 2024 17:43:02 +0500 Subject: [PATCH 6/8] Throw nil instead of 0 --- lua/entities/gmod_wire_expression2/core/hologram.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/entities/gmod_wire_expression2/core/hologram.lua b/lua/entities/gmod_wire_expression2/core/hologram.lua index f4dbdcc1db..90f3425f4b 100644 --- a/lua/entities/gmod_wire_expression2/core/hologram.lua +++ b/lua/entities/gmod_wire_expression2/core/hologram.lua @@ -523,7 +523,7 @@ end -- if shouldbenil is nil or false, assert that the hologram exists on @strict with an error. Otherwise, don't check (for holo creation, etc) local MAX_INDEX = 2 ^ 31 local function CheckIndex(self, index, shouldbenil) - if index ~= index then return self:throw("holo index is NaN!", 0) end + if index ~= index then return self:throw("holo index is NaN!", nil) end index = math.Clamp(math.floor(index), -MAX_INDEX, MAX_INDEX) local Holo if index<0 then From 03ca614835674e355ad5497799c1652e75419456 Mon Sep 17 00:00:00 2001 From: Zvbhrf <79792873+Zvbhrf@users.noreply.github.com> Date: Tue, 10 Sep 2024 01:42:12 +0500 Subject: [PATCH 7/8] Update lua/entities/gmod_wire_expression2/core/hologram.lua The new local is unnecessary Co-authored-by: thegrb93 --- lua/entities/gmod_wire_expression2/core/hologram.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/entities/gmod_wire_expression2/core/hologram.lua b/lua/entities/gmod_wire_expression2/core/hologram.lua index 90f3425f4b..e77c2f044e 100644 --- a/lua/entities/gmod_wire_expression2/core/hologram.lua +++ b/lua/entities/gmod_wire_expression2/core/hologram.lua @@ -524,7 +524,7 @@ end local MAX_INDEX = 2 ^ 31 local function CheckIndex(self, index, shouldbenil) if index ~= index then return self:throw("holo index is NaN!", nil) end - index = math.Clamp(math.floor(index), -MAX_INDEX, MAX_INDEX) + index = math.Clamp(math.floor(index), -2^31, 2^31) local Holo if index<0 then Holo = E2HoloRepo[self.uid][-index] From bd5d35c410b1f30adad9f2a3192f4f9654a3fd55 Mon Sep 17 00:00:00 2001 From: Zvbhrf <79792873+Zvbhrf@users.noreply.github.com> Date: Tue, 10 Sep 2024 01:42:58 +0500 Subject: [PATCH 8/8] Update lua/entities/gmod_wire_expression2/core/hologram.lua Remove local Co-authored-by: thegrb93 --- lua/entities/gmod_wire_expression2/core/hologram.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/entities/gmod_wire_expression2/core/hologram.lua b/lua/entities/gmod_wire_expression2/core/hologram.lua index e77c2f044e..f703fb6e1f 100644 --- a/lua/entities/gmod_wire_expression2/core/hologram.lua +++ b/lua/entities/gmod_wire_expression2/core/hologram.lua @@ -521,7 +521,6 @@ end -- Returns the hologram with the given index or nil if it doesn't exist. -- if shouldbenil is nil or false, assert that the hologram exists on @strict with an error. Otherwise, don't check (for holo creation, etc) -local MAX_INDEX = 2 ^ 31 local function CheckIndex(self, index, shouldbenil) if index ~= index then return self:throw("holo index is NaN!", nil) end index = math.Clamp(math.floor(index), -2^31, 2^31)