Advertisement
C0BRA

Walls

Sep 28th, 2011
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.80 KB | None | 0 0
  1. local qq = eqq -- eqq = externel qq, it exists only a few cycles
  2.  
  3. local PlyMeta = qq.Meta.Ply
  4. local EntMeta = qq.Meta.Ent
  5.  
  6. local Plugin = {
  7.     Name = "Wallhack",
  8.     Alias = "wallhack"
  9. }
  10.  
  11. Plugin.Init = function()
  12.     qq.CreateSetting(qq.MENU_VISUALS, Plugin, "enabled", "Wallhack", true, {Save = true})
  13.     qq.CreateSetting(qq.MENU_VISUALS, Plugin, "weapons", "Weapons", true, {Save = true})
  14.    
  15.     qq.CreateSetting(qq.MENU_VISUALS, Plugin, "weapons_maxdmg", "Max Damage", 43, {Save = true, Min = 0, Max = 100})
  16.     qq.CreateSetting(qq.MENU_VISUALS, Plugin, "weapons_starthue", "Start Damage Hue", 160, {Save = true, Min = 0, Max = 360})
  17.     qq.CreateSetting(qq.MENU_VISUALS, Plugin, "weapons_endhue", "End Damage Hue", 30, {Save = true, Min = 0, Max = 360})
  18.    
  19.     qq.CreateSetting(qq.MENU_VISUALS, Plugin, "blursize", "Blur Size", 2, {Min = 0, Max = 10, Places = 1})
  20. end
  21.  
  22. local MaterialBlurX = Material( "pp/blurx" )
  23. local MaterialBlurY = Material( "pp/blury" )
  24. local MaterialWhite = CreateMaterial( "WhiteMaterial", "VertexLitGeneric", {
  25.      ["$basetexture"] = "color/white",
  26.      ["$vertexalpha"] = "1",
  27.      ["$model"] = "1",
  28. } )
  29. local MaterialComposite = CreateMaterial( "CompositeMaterial", "UnlitGeneric", {
  30.      ["$basetexture"] = "_rt_FullFrameFB",
  31.      ["$additive"] = "1",
  32. } )
  33.  
  34. local RT1 = GetRenderTarget( "L4D1" )
  35. local RT2 = GetRenderTarget( "L4D2" )
  36.  
  37.  
  38. Plugin.RenderToStencil = function(entity)
  39.     -- tell the stencil buffer we're going to write a value of one wherever the model
  40.     -- is rendered
  41.     render.SetStencilEnable( true )
  42.     render.SetStencilFailOperation( STENCILOPERATION_KEEP )
  43.     render.SetStencilZFailOperation( STENCILOPERATION_KEEP )
  44.     --STENCILOPERATION_INVERT
  45.     render.SetStencilPassOperation( STENCILOPERATION_REPLACE )
  46.     render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_ALWAYS )
  47.     render.SetStencilWriteMask( 1 )
  48.     render.SetStencilReferenceValue( 1 )
  49.      
  50.     -- this uses a small hack to render ignoring depth while not drawing color
  51.     -- i couldn't find a function in the engine to disable writing to the color channels
  52.     -- i did find one for shaders though, but I don't feel like writing a shader for this.
  53.     cam.IgnoreZ( true )
  54.       render.SetBlend( 0 )
  55.         local weap = nil
  56.             if type(entity) == "Player" then
  57.                 if PlyMeta.GetActiveWeapon(entity) != nil then
  58.                     weap = PlyMeta.GetActiveWeapon(entity)
  59.                 end
  60.             end
  61.             SetMaterialOverride( MaterialWhite )
  62.                 EntMeta.DrawModel(entity)
  63.                 if weap != nil and ValidEntity(weap) then
  64.                     EntMeta.DrawModel(weap)
  65.                 end
  66.             SetMaterialOverride()
  67.              
  68.       render.SetBlend( 1 )
  69.       render.SetBlend( 1 )
  70.     cam.IgnoreZ( false )
  71.      
  72.     -- don't need this for the next pass
  73.     render.SetStencilEnable( false )
  74. end
  75.  
  76. Plugin.RenderToGlowTexture = function(entity)
  77.     if not qq.Setting(Plugin, "enabled") then return end
  78.     local w, h = ScrW(), ScrH()
  79.     local fogmode = render.GetFogMode()
  80.     render.FogMode(MATERIAL_FOG_NONE)
  81.     -- draw into the white texture
  82.     local oldRT = render.GetRenderTarget()
  83.     render.SetRenderTarget( RT1 )
  84.         render.SetViewPort( 0, 0, 512, 512 )
  85.                
  86.         cam.IgnoreZ( false )
  87.             local weap = nil
  88.             render.SuppressEngineLighting( true )
  89.             if type(entity) == "Player" then
  90.                 local col = team.GetColor(PlyMeta.Team(entity))
  91.                 if entity.StencilColor != nil then
  92.                     col = entity.StencilColor
  93.                 end
  94.                 render.SetColorModulation( col.r/255, col.g/255, col.b/255)
  95.                 if PlyMeta.GetActiveWeapon(entity) != nil then
  96.                     weap = PlyMeta.GetActiveWeapon(entity)
  97.                 end
  98.             else
  99.                 local col = Color(255,255,255)
  100.                 if entity.StencilColor != nil then
  101.                     col = entity.StencilColor
  102.                 end
  103.                 render.SetColorModulation( col.r/255, col.g/255, col.b/255)
  104.             end
  105.            
  106.             SetMaterialOverride( MaterialWhite )
  107.                 EntMeta.DrawModel(entity)
  108.                 if weap != nil and ValidEntity(weap) then
  109.                     EntMeta.DrawModel(weap)
  110.                 end
  111.             SetMaterialOverride()
  112.                
  113.             render.SetColorModulation( 1, 1, 1 )
  114.             render.SuppressEngineLighting( false )
  115.            
  116.         cam.IgnoreZ( false )
  117.        
  118.         render.SetViewPort( 0, 0, w, h )
  119.     render.SetRenderTarget( oldRT )
  120.     render.FogMode(fogmode)
  121. end
  122.  
  123. Plugin.RenderScene = function( Origin, Angles )
  124.     if not qq.Setting(Plugin, "enabled") then return end
  125.     local oldRT = render.GetRenderTarget()
  126.     render.SetRenderTarget( RT1 )
  127.     render.Clear( 0, 0, 0, 255, true )
  128.     render.SetRenderTarget( oldRT )
  129.    
  130. end
  131.  
  132. Plugin.Disabled = function()
  133.     if Plugin.FakeModel and ValidEntity(Plugin.FakeModel) then
  134.         Plugin.FakeModel:Remove()
  135.     end
  136. end
  137. Plugin.Enabled = function()
  138.     Plugin.FakeModel = ClientsideModel("models/props_c17/canister02a.mdl", RENDERGROUP_OPAQUE)
  139.     Plugin.FakeModel:SetPos(Vector(0,0,-1000))
  140. end
  141.  
  142. Plugin.SetupFakeModel = function(ent)
  143.     EntMeta.SetModel(Plugin.FakeModel, "models/props_c17/canister02a.mdl")
  144.     local mdl = EntMeta.GetModel(ent)
  145.     if mdl == nil then return end
  146.     EntMeta.SetModel(Plugin.FakeModel, mdl)
  147.  
  148.     EntMeta.SetPos(Plugin.FakeModel, EntMeta.GetPos(ent))
  149.     EntMeta.SetAngles(Plugin.FakeModel, EntMeta.GetAngles(ent))
  150.    
  151.     Plugin.FakeModel.StencilColor = ent.StencilColor
  152. end
  153.  
  154. Plugin.MoveFakeModel = function()
  155.     EntMeta.SetPos(Plugin.FakeModel, Vector(0,0,-1000))
  156.     Plugin.FakeModel.StencilColor = nil
  157. end
  158.  
  159. Plugin.DrawOtherStuff = function()
  160.     if not qq.Setting(Plugin, "enabled") then return end
  161.        
  162.     local entslist = ents.GetAll()
  163.     local count = #entslist
  164.    
  165.     for i = 1, count do
  166.         local ent = entslist[i]
  167.         if not ValidEntity(ent) then continue end
  168.         if type(ent) == "Player" then continue end
  169.         if EntMeta.GetModel(ent) == "" then continue end
  170.        
  171.         local t = type(ent)
  172.         local Draw = qq.CallInternalHook("QQShouldWallhack", ent, t)
  173.         //print(EntMeta.GetModel(ent))
  174.         if Draw and Draw > 0 then
  175.             if Draw > 1 then
  176.                 Plugin.SetupFakeModel(ent)
  177.                 Plugin.OUTLINING = true
  178.                
  179.                 Plugin.RenderToStencil( Plugin.FakeModel )
  180.                 Plugin.RenderToGlowTexture( Plugin.FakeModel )
  181.                
  182.                 Plugin.OUTLINING = false
  183.                 Plugin.MoveFakeModel()
  184.             else
  185.                 Plugin.OUTLINING = true
  186.                
  187.                 Plugin.RenderToStencil( ent )
  188.                 Plugin.RenderToGlowTexture( ent )
  189.                
  190.                 Plugin.OUTLINING = false
  191.             end
  192.         end
  193.        
  194.     end
  195. end
  196.  
  197. Plugin.ShouldWallhackEnt = function(ent,typ)
  198.    
  199.     if typ == "NPC" then
  200.         ent.StencilColor = Color(255,0,0)
  201.         return 1
  202.     elseif typ == "Weapon" and qq.Setting(Plugin, "weapons") then
  203.         if not ValidEntity(ent.Owner) or ent.Owner == nil then
  204.             local col = Color(255,255,255)
  205.             if ent.Primary then
  206.                 local maxdmg = qq.Setting(Plugin, "weapons_maxdmg")
  207.                 local starthue = qq.Setting(Plugin, "weapons_starthue")
  208.                 local endhue = qq.Setting(Plugin, "weapons_endhue")
  209.                
  210.                 local dmg = ent.Primary.Damage or 0
  211.                 dmg = math.max(0, 1 - (dmg / maxdmg))
  212.                 dmg = dmg * (starthue - endhue) + endhue
  213.                
  214.                 //print(dmg, ent.Primary.Damage)
  215.                 col = HSVToColor(dmg, 1, 1)
  216.             end
  217.             ent.StencilColor = col
  218.             return 2
  219.         end
  220.     end
  221. end
  222.  
  223. Plugin.RenderScreenspaceEffects = function( )
  224.     if not qq.Setting(Plugin, "enabled") then return end
  225.    
  226.     MaterialBlurX:SetMaterialTexture( "$basetexture", RT1 )
  227.     MaterialBlurY:SetMaterialTexture( "$basetexture", RT2 )
  228.    
  229.     local BlurSize = qq.Setting(Plugin, "blursize") or 2
  230.    
  231.     MaterialBlurX:SetMaterialFloat( "$size", BlurSize ) // 2
  232.     MaterialBlurY:SetMaterialFloat( "$size", BlurSize )
  233.    
  234.     local oldRT = render.GetRenderTarget()
  235.    
  236.     -- blur horizontally
  237.     render.SetRenderTarget( RT2 )
  238.     render.SetMaterial( MaterialBlurX )
  239.     render.DrawScreenQuad()
  240.  
  241.     -- blur vertically
  242.     render.SetRenderTarget( RT1 )
  243.     render.SetMaterial( MaterialBlurY )
  244.     render.DrawScreenQuad()
  245.  
  246.     render.SetRenderTarget( oldRT )
  247.    
  248.     -- tell the stencil buffer we're only going to draw
  249.      -- where the player models are not.
  250.     render.SetStencilEnable( true )
  251.     render.SetStencilReferenceValue( 0 )
  252.     render.SetStencilTestMask( 1 )
  253.     render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_EQUAL )
  254.     render.SetStencilPassOperation( STENCILOPERATION_ZERO )
  255.      
  256.     -- composite the scene
  257.     MaterialComposite:SetMaterialTexture( "$basetexture", RT1 )
  258.     render.SetMaterial( MaterialComposite )
  259.     render.DrawScreenQuad()
  260.  
  261.      -- don't need this anymore
  262.     render.SetStencilEnable( false )
  263. end
  264.  
  265.  
  266. Plugin.PostPlayerDraw = function( pl )
  267.     if not qq.Setting(Plugin, "enabled") then return end
  268.     -- prevent recursion
  269.     if( Plugin.OUTLINING ) then return end
  270.     Plugin.OUTLINING = true
  271.     Plugin.RenderToStencil( pl )
  272.     Plugin.RenderToGlowTexture( pl )
  273.     -- prevents recursion time
  274.     Plugin.OUTLINING = false
  275.     if( ScrW() == ScrH() ) then return end
  276.     return false // Prevent gay GMs doing shit to players too (like hats)
  277. end --PostDrawOpaqueRenderables
  278.  
  279.  
  280. Plugin.Hooks = {
  281.     RenderScene = Plugin.RenderScene,
  282.     RenderScreenspaceEffects = Plugin.RenderScreenspaceEffects,
  283.     PostPlayerDraw = Plugin.PostPlayerDraw,
  284.     PostDrawTranslucentRenderables = Plugin.DrawOtherStuff,
  285.     QQShouldWallhack = Plugin.ShouldWallhackEnt
  286.     //PostDrawTranslucentRenderables = Plugin.DrawOtherStuff
  287. }
  288.  
  289. qq.RegisterPlugin(Plugin)
  290.  
  291.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement