Skip to content

Instantly share code, notes, and snippets.

@CaptainPRICE
Created July 26, 2019 09:10
Show Gist options
  • Save CaptainPRICE/6d74b463b7a125535e52bb8ff311eaf2 to your computer and use it in GitHub Desktop.
Save CaptainPRICE/6d74b463b7a125535e52bb8ff311eaf2 to your computer and use it in GitHub Desktop.
Reconstruction of AddFlags/RemoveFlags/IsFlagSet on Garry's Mod Lua...
local ENTITY = FindMetaTable("Entity")
local Entity_GetInternalVariable = ENTITY.GetInternalVariable
local Entity_AddFlags, Entity_RemoveFlags = ENTITY.AddFlags, ENTITY.RemoveFlags
local bit_bor, bit_bnot, bit_band = bit.bor, bit.bnot, bit.band
function ENTITY.AddFlags(this, flagMask)
assert(IsValid(this), "attempt to AddFlags on NULL entity")
local m_fFlags = Entity_GetInternalVariable(this, "m_fFlags")
Entity_AddFlags(this, bit_bor(m_fFlags, flagMask))
end
function ENTITY.RemoveFlags(this, flagMask)
assert(IsValid(this), "attempt to RemoveFlags on NULL entity")
local m_fFlags = Entity_GetInternalVariable(this, "m_fFlags")
Entity_RemoveFlags(this, bit_band(m_fFlags, bit_bnot(flagMask)))
end
function ENTITY.IsFlagSet(this, flagMask)
if IsValid(this) then
local m_fFlags = Entity_GetInternalVariable(this, "m_fFlags")
return bit_band(m_fFlags, flagMask) ~= 0
end
return false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment