Created
July 26, 2019 09:10
-
-
Save CaptainPRICE/6d74b463b7a125535e52bb8ff311eaf2 to your computer and use it in GitHub Desktop.
Reconstruction of AddFlags/RemoveFlags/IsFlagSet on Garry's Mod Lua...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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