forked from solsticegamestudios/GModCEFCodecFix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
detection_example.lua
72 lines (58 loc) · 2.27 KB
/
detection_example.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
--[[
GModCEFCodecFix detection code example
Copyright 2024, Solstice Game Studios (www.solsticegamestudios.com)
LICENSE: GNU General Public License v3.0
Purpose: Detects if CEFCodecFix has been applied successfully on a GMod client.
Contact:
Discord: https://www.solsticegamestudios.com/discord/
Email: [email protected]
]]
-- CEF is only on the Client
if not CLIENT then return end
-- Use these global variables for detection elsewhere in your Lua code
CEFCodecFixChecked = false
CEFCodecFixAvailable = false
-- We hook PreRender for reliability
hook.Add("PreRender", "CEFCodecFixCheck", function()
hook.Remove("PreRender", "CEFCodecFixCheck")
print("Querying CEF Codec Support...")
-- If the client isn't on the x86-64 beta, it's impossible for them to have CEFCodecFix
if BRANCH ~= "x86-64" then
CEFCodecFixAvailable = false
CEFCodecFixChecked = true
print("CEF does not have CEFCodecFix")
return
end
local cefTestPanel = vgui.Create("DHTML", nil, "CEFCodecFixCheck")
cefTestPanel:SetSize(32, 32)
cefTestPanel:SetKeyboardInputEnabled(false)
cefTestPanel:SetMouseInputEnabled(false)
function cefTestPanel:Paint()
return true -- We don't want this to draw normally
end
function cefTestPanel:RemoveWhileHidden()
-- HACK: The panel apparently draws for a frame once Remove() is called, so we're disabling visibility beforehand
-- NOTE: Don't use SetVisible(false) to replace the Paint override! Panel Think/Javascript won't run without panel "visibility"
self:SetVisible(false)
self:Remove()
end
cefTestPanel:SetHTML("")
function cefTestPanel:OnDocumentReady()
if not CEFCodecFixChecked then
self:AddFunction("gmod", "getCodecStatus", function(codecStatus)
CEFCodecFixAvailable = codecStatus
CEFCodecFixChecked = true
if CEFCodecFixAvailable then
print("CEF has CEFCodecFix")
else
print("CEF does not have CEFCodecFix")
end
self:RemoveWhileHidden()
end)
-- This is what actually does the detection, by seeing if the web framework is capable of playing H.264 (a proprietary video codec)
self:QueueJavascript([[gmod.getCodecStatus(document.createElement("video").canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"') == "probably")]])
elseif IsValid(self) then
self:RemoveWhileHidden()
end
end
end)