-- Executes Ruen's actual restricted snippet against a modeled binding engine. -- This does not claim to reproduce the live secure VM or native priority rules. local frames, active, special = {}, {}, false local create, getAction = CreateFrame, GetBindingAction CreateFrame = function(kind,name,parent,template) local frame = create(kind,name,parent,template) if template == "SecureHandlerStateTemplate" then frames[#frames+1]=frame frame.profileAttributes={} function frame:SetAttribute(key,value) assert(not InCombatLockdown(),'insecure profile attribute write in combat') self.profileAttributes[key]=value end function frame:GetAttribute(key)return self.profileAttributes[key]end function frame:SetBinding(priority,key,action) assert(self.inSecureSnippet and priority==false,'must use non-priority secure binding') active[key]=action end function frame:ClearBindings() assert(self.inSecureSnippet,'clear must execute through secure snippet') active={} end function frame:Execute(body) self.inSecureSnippet=true local fn=assert(loadstring(body));setfenv(fn,{self=self});fn() self.inSecureSnippet=false end end return frame end function RegisterStateDriver(frame,key,conditions) assert(not InCombatLockdown()) assert(conditions=='[vehicleui][overridebar][possessbar] special; normal') frame.profileState=key frame.profileAttributes['state-'..key]=special and 'special' or 'normal' frame:Execute(frame.profileAttributes['_onstate-'..key]) end function UnregisterStateDriver(frame,key)frame.profileState=nil end GetBindingAction=function(key,withOverrides) if withOverrides and active[key] then return active[key] end return getAction(key,withOverrides) end return {transition=function(value) special=value for _,frame in ipairs(frames)do if frame.profileState then frame.profileAttributes['state-'..frame.profileState]=value and 'special' or 'normal' frame:Execute(frame.profileAttributes['_onstate-'..frame.profileState]) end end end, active=function()return active end}