-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutil.lua
More file actions
332 lines (248 loc) · 6.72 KB
/
Copy pathutil.lua
File metadata and controls
332 lines (248 loc) · 6.72 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
do
local developer = GetConVar("developer")
_G.DEVELOPER = developer:GetBool()
function IsDeveloper(n)
return developer:GetInt() >= (n or 1)
end
end
if IsDeveloper() then
local function lua_run_menu(_,_,_,code)
local func = CompileString(code,"",false)
if isstring(func) then
Msg"Invalid syntax> "print(func)
return
end
MsgN("> ",code)
xpcall(func,function(err)
print(debug.traceback(err))
end)
end
concommand.Add("lua_run_menu",lua_run_menu)
end
function gamemenucommand(str)
RunGameUICommand(str)
end
local function FindInTable( tab, find, parents, depth )
depth = depth or 0
parents = parents or ""
if ( !istable( tab ) ) then return end
if ( depth > 3 ) then return end
depth = depth + 1
for k, v in pairs ( tab ) do
if ( type(k) == "string" ) then
if ( k && k:lower():find( find:lower() ) ) then
Msg("\t", parents, k, " - (", type(v), " - ", v, ")\n")
end
-- Recurse
if ( istable(v) &&
k != "_R" &&
k != "_E" &&
k != "_G" &&
k != "_M" &&
k != "_LOADED" &&
k != "__index" ) then
local NewParents = parents .. k .. ".";
FindInTable( v, find, NewParents, depth )
end
end
end
end
--[[---------------------------------------------------------
Name: Find
-----------------------------------------------------------]]
local function Find( ply, command, arguments )
if ( IsValid(ply) && ply:IsPlayer() && !ply:IsAdmin() ) then return end
if ( !arguments[1] ) then return end
Msg("Finding '", arguments[1], "':\n\n")
FindInTable( _G, arguments[1] )
FindInTable( debug.getregistry(), arguments[1] )
Msg("\n\n")
end
concommand.Add( "lua_find_menu", Find, nil, "", { FCVAR_DONTRECORD } )
local iter iter=function(t,cb)
for k,v in next,t do
if istable(v) then
iter(v,cb)
else
cb(v,k)
end
end
end
--iter(util.KeyValuesToTable(file.Read("resource/SourceScheme.res",'MOD')),
-- function(val,key)
-- if not isstring(val) then return end
--
-- local r,g,b,a = val:match("(%d+) (%d+) (%d+) (%d+)")
-- if not a then
-- a=255
-- r,g,b = val:match("(%d+) (%d+) (%d+)")
-- end
-- if g then
-- MsgC(Color(r,g,b,a),"█████ ",Color(255,255,255,255),key,"\n")
-- end
-- end)
hook.Add( "MenuStart", "Menu2", function()
print"MenuStart"
end )
hook.Add( "ConsoleVisible", "Menu2", function(is)
print(is
and '<console on>'
or '<console off>'
)
end )
hook.Add( "InGame", "Menu2", function(is)
print(is and "InGame" or "Out of game")
end )
hook.Add( "LoadingStatus", "Menu2", function(status)
print("LoadingStatus",status)
end )
local isingame = IsInGame()
local wasingame = false
local status = GetLoadStatus()
local console
local alt
hook.Add( "Think", "Menu2", function()
-- every other Think is enough
alt = not alt if alt then return end
local is=IsInGame()
if is~=isingame then
isingame=is
wasingame = wasingame or isingame
hook.Call("InGame",nil,isingame)
end
local s=GetLoadStatus()
if s~=status then
status=s
hook.Call("LoadingStatus",nil,status)
end
local s=gui.IsConsoleVisible()
if s~=console then
console=s
hook.Call("ConsoleVisible",nil,console)
end
end )
function WasInGame()
return wasingame
end
local games = engine.GetGames()
local addons = engine.GetAddons()
hook.Add( "GameContentChanged", "Menu2", function()
local games_new = engine.GetGames()
local _ = games
games = games_new
local games = _
local addons_new = engine.GetAddons()
local _ = addons
addons = addons_new
local addons = _
local wasmount = false
local wasaddon = false
for k,new in next,games_new do
local old = games[k]
assert(old.depot==new.depot)
if old.mounted ~= new.mounted then
print("MOUNT",new.title,new.mounted and "MOUNTED" or "UNMOUNTED")
wasmount=true
end
end
for k,new in next,addons_new do
local old
for k,v in next,addons do
if v.file == new.file then
old = v
break
end
end
if not old then
print("Added ",new.mounted and "(M)" or " ",'\t',new.title)
wasaddon=true
continue
end
assert(old.depot==new.depot)
if old.mounted ~= new.mounted then
print("MOUNT",new.title,"\t",new.mounted and "MOUNTED" or "UNMOUNTED")
wasaddon=true
end
end
for k,old in next,addons do
local new
for k,v in next,addons_new do
if v.file == old.file then
new = v
break
end
end
if not new then
MsgN("Removed ",old.title)
nothing=false
continue
end
end
--if not wasmount and not wasaddon then
if IsDeveloper(2) then print("MENU: Unhandled GameContentChanged") end
--else
hook.Call("GameContentsChanged",nil,wasmount,wasaddon)
--end
end )
function UpdateSteamName( id, time )
error"todo"
if ( !id ) then return end
if ( !time ) then time = 0.2 end
local name = steamworks.GetPlayerName( id )
if ( name != "" && name != "[unknown]" ) then
return;
end
steamworks.RequestPlayerInfo( id )
timer.Simple( time, function() UpdateSteamName( id, time + 0.2 ) end )
end
function UpdateLanguages()
local f = file.Find( "resource/localization/*.png", "MOD" )
end
--
-- Called from the engine any time the language changes
--
function LanguageChanged( lang )
print("LanguageChanged",lang)
end
hook.Add( "GameContentChanged", "RefreshMainMenu", function()
--print("GameContentChanged")
end )
--pnlMainMenu = vgui.Create( "MainMenuPanel" )
--"UpdateVersion( '"..VERSIONSTR.."', '"..BRANCH.."' )" )
local language = GetConVarString( "gmod_language" )
--LanguageChanged( language )
--hook.Run( "GameContentChanged" )
--[[ serverlist.PlayerList( serverip, function( tbl )
local json = util.TableToJSON( tbl );
pnlMainMenu:Call( "SetPlayerList( '"..serverip.."', "..json..")" );
end )
--]]
SelectGamemode = function ( g )
RunConsoleCommand( "gamemode", g )
end
function SetMounted(game,yesno)
engine.SetMounted(game.depot,yesno==nil or yesno)
end
SelectLanguage = function ( lang )
RunConsoleCommand( "gmod_language", lang )
end
function SearchWorkshop(str)
str = string.JavascriptSafe(str)
str = "http://steamcommunity.com/workshop/browse?searchtext="..str.."&childpublishedfileid=0§ion=items&appid=4000&browsesort=trend&requiredtags[]=-1"
gui.OpenURL(str)
end
function CompileFile(path)
local f = file.Open(path,'rb','LuaMenu')
if not f then
ErrorNoHalt("Could not open: "..path..'\n')
return
end
local str = f:Read(f:Size())
f:Close()
local func = CompileString(str,'@'..path,false)
if isstring(func) then
error(func)
else
return func
end
end