Skip to content

Commit

Permalink
Replace getregistry with FindMetaTable
Browse files Browse the repository at this point in the history
  • Loading branch information
Derpius committed Jan 6, 2024
1 parent c4de896 commit 1b23bd0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 6 additions & 3 deletions lua/entities/gmod_wire_expression2/core/e2lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,9 @@ for funcname, _ in pairs(makeglobal) do
_G[funcname] = E2Lib[funcname]
end

local PLAYER_METATABLE = FindMetaTable("Player")
local ENTITY_METATABLE = FindMetaTable("Entity")

hook.Add("InitPostEntity", "e2lib", function()
-- If changed, put them into the global scope again.
registerCallback("e2lib_replace_function", function(funcname, func, oldfunc)
Expand All @@ -915,7 +918,7 @@ hook.Add("InitPostEntity", "e2lib", function()

-- check for a CPPI compliant plugin
if SERVER and CPPI then
if debug.getregistry().Player.CPPIGetFriends then
if PLAYER_METATABLE.CPPIGetFriends then
E2Lib.replace_function("isFriend", function(owner, player)
if owner == nil then return false end
if owner == player then return true end
Expand All @@ -934,7 +937,7 @@ hook.Add("InitPostEntity", "e2lib", function()
end)
end

if debug.getregistry().Entity.CPPIGetOwner then
if ENTITY_METATABLE.CPPIGetOwner then
local _getOwner = E2Lib.getOwner
E2Lib.replace_function("getOwner", function(self, entity)
if not IsValid(entity) then return end
Expand Down Expand Up @@ -1258,4 +1261,4 @@ function E2Lib.compileScript(code, owner)
end
end
end
end
end
4 changes: 3 additions & 1 deletion lua/entities/gmod_wire_expression2/core/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,11 @@ end

--------------------------------------------------------------------------------

local PLAYER_METATABLE = FindMetaTable("Player")

__e2setcost(2)

if CPPI and debug.getregistry().Player.CPPIGetFriends then
if CPPI and PLAYER_METATABLE.CPPIGetFriends then

local function Trusts(ply, whom)
if ply == whom then return true end
Expand Down

0 comments on commit 1b23bd0

Please sign in to comment.