Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metatable change critical bug #3

Open
klen-list opened this issue Mar 30, 2023 · 2 comments
Open

Metatable change critical bug #3

klen-list opened this issue Mar 30, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@klen-list
Copy link
Member

If SENT has Base = "base_entity" and has no Use method, calling Use or direct use by the player causes an overflow error on the dedicated server and crash in local hosted game. Example: 3D2DTextscreens
image

Temporary solution - 1dde1e6

@klen-list klen-list added the bug Something isn't working label Mar 30, 2023
@unknown-gd
Copy link
Member

Commentary changed: 0d071c3

@Heyter
Copy link

Heyter commented Apr 14, 2023

	do
		local _R = debug.getregistry()
		local ENTITY = _R.Entity

		local entTabs = {
			["Entity"] = { __index = ENTITY },
			["Player"] = { __index = setmetatable( table.Copy( _R.Player ), { __index = ENTITY } ) },
			["Weapon"] = { __index = setmetatable( table.Copy( _R.Weapon ), { __index = ENTITY } ) },
			["Vehicle"] = { __index = setmetatable( table.Copy( _R.Vehicle ), { __index = ENTITY } ) },
			["NPC"] = { __index = setmetatable( table.Copy( _R.NPC ), { __index = ENTITY } ) }
		}

		local ownerkey = "Owner"
		local copyKeys = {"MetaID", "MetaName", "__tostring", "__eq", "__concat"}
		local copyKeysLength = #copyKeys

		local function copyMetatable( ent, entTabName )
			if (!entTabs[entTabName]) then return end
			local tab = GetTable[ent]
			setmetatable(tab, entTabs[entTabName])

			local mt = {
				__index = function( self, key )
					if key == ownerkey then return GetOwner(self, key) end
					return tab[key]
				end,
				__newindex = tab,
				__metatable = ENTITY
			}

			local v
			for i = 1, copyKeysLength do
				v = copyKeys[i]
				mt[v] = ENTITY[v]
			end
			v = nil

			debug.setmetatable(ent, mt)
		end

		hook.Add("OnEntityCreated", "turbo.ChangeEntMeta", function(ent)
			timer.Simple(0, function()
				if (IsValid(ent)) then
					copyMetatable(ent, debug.getmetatable(ent).MetaName)
				end
			end)
		end, HOOK_MONITOR_HIGH)
	end

or

https://github.com/swampservers/contrib/blob/master/lua/swamp/sh_meta.lua

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants