-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstarfall_error_viewer.txt
490 lines (373 loc) · 13.4 KB
/
starfall_error_viewer.txt
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
--@name Starfall Error Viewer
--@author legokidlogan
--@shared
--@include lkl/hud_button_diamond.txt
--@include lkl/gcolors.txt
-- CONFIG:
local diamondRadius = 20
local diamondThickness = 0.3
local diamondInnerScale = 0.4
local chipNameFontSize = 24
local chipNameFontOutline = true
local chipNameTextColor = Color( 255, 200, 200, 255 )
local returnDiamondColor = Color( 255, 255, 255, 255 )
local returnDiamondHoveredColor = Color( 255, 255, 100, 255 )
local showErrorMessages = 2 -- 0 = never, 1 = always, 2 = only when hovering over the error diamond.
local restartChipKeyCombo = { KEY.LCONTROL, KEY.R } -- Set to false to disable. Looking at an errored chip (through walls) and pressing these keys together will restart it in both realms.
local makeChipSolidKey = KEY.E -- Set to false to disable. Looking at an errored chip (through walls) that's invisible to traces (PropNotSolid or COLLISION_GROUP_IN_VEHICLE) and pressing this key will re-solidify it.
local toggleBringChipKey = KEY.G -- Set to false to disable. Loking at an errored chip (through walls) and pressing this key will bring it to you or teleport it back. The chip can be sent back even if it is no longer errored.
local clearChipReturnKey = KEY.H -- Set to false to disable. Used for clearing the return position of a chip that has been brought to you.
-- END CONFIG
if SERVER then
require( "lkl/gcolors.txt" )
local active = true
hook.add( "PlayerSay", "LKL_SEV_ToggleActive", function( ply, msg )
if ply ~= owner() then return end
local args = string.split( msg, " " )
local prefix = table.remove( args, 1 )
if prefix ~= "/sev" then return end
-- Currently only one command and no args: toggling the active state.
active = not active
print(
c_white, "[SEV] ",
c_white, "Error viewer is now ",
active and c_pale_green or c_pale_red, active and "active" or "inactive"
)
net.start( "LKL_SEV_SetActive" )
net.writeBool( active )
net.send( ply )
return ""
end )
net.receive( "LKL_SEV_MakeChipSolid", function( _, ply )
if ply ~= owner() then return end
local ent = net.readEntity()
if not isValid( ent ) then return end
ent:setCollisionGroup( COLLISION_GROUP.NONE )
ent:setSolid( true )
end )
net.receive( "LKL_SEV_SetPos", function( _, ply )
if ply ~= owner() then return end
local ent = net.readEntity()
if not isValid( ent ) then return end
ent:setPos( net.readVector() )
end )
net.receive( "LKL_SEV_RestartChip", function( _, ply )
if ply ~= owner() then return end
local ent = net.readEntity()
if not isValid( ent ) then return end
local success, err = pcall( function()
restart( ent )
end )
if not success then
if type( err ) == "table" then
err = err.msg
end
print(
c_white, "[SEV] ",
c_alert_red, "Error restarting chip on server: ",
c_pale_yellow, err
)
return
end
net.start( "LKL_SEV_RestartSucceeded" )
net.writeEntity( ent )
net.send( ply )
end )
return
end
if player() ~= owner() then return end
require( "lkl/hud_button_diamond.txt" )
require( "lkl/gcolors.txt" )
local IN_KEY_ATTACK = IN_KEY.ATTACK
local IN_KEY_RELOAD = IN_KEY.RELOAD
local active = true
local erroredChipDatas = {}
local restartChipKeyComboLookup = {}
local chipNameFont = render.createFont( "Roboto Mono", chipNameFontSize, 500, true, false, false, chipNameFontOutline, false, false )
local function splitErrorMessage( msg )
local sfInd = string.find( msg, "SF:", 1, true )
if sfInd then
msg = string.sub( msg, sfInd + 3 )
end
local msgSepInd = string.find( msg, ": ", 1, true )
if not msgSepInd then return msg end
local errLocation = string.sub( msg, 1, msgSepInd - 1 )
local errMsg = string.sub( msg, msgSepInd + 2 )
return errLocation, errMsg
end
local function removeErroredChip( ent )
local chipData = erroredChipDatas[ent]
if chipData then
if isValid( chipData.RestartButton ) then
chipData.RestartButton:destroy()
chipData.RestartButton = nil
end
if isValid( chipData.ReturnButton ) then
chipData.ReturnButton:destroy()
chipData.ReturnButton = nil
end
end
erroredChipDatas[ent] = nil
end
local function restartChip( ent )
local success, err = pcall( function()
restart( ent )
end )
if not success then
if type( err ) == "table" then
err = err.msg
end
print(
c_white, "[SEV] ",
c_alert_red, "Error restarting chip: ",
c_pale_yellow, err
)
return
end
local chipData = erroredChipDatas[ent] or {}
local returnButton = chipData.ReturnButton
if returnButton then
returnButton:splitOff()
end
if chipData.OnServer then
net.start( "LKL_SEV_RestartChip" )
net.writeEntity( ent )
net.send()
else
removeErroredChip( ent )
end
end
local function toggleBring( ent, chipData )
local returnPos = ent._sev_ReturnPos
local desPos = nil
local returnButton = chipData.ReturnButton
if returnPos then
desPos = returnPos
ent._sev_ReturnPos = nil
if ent._sev_ReturnButton == returnButton then
ent._sev_ReturnButton = nil
returnButton:destroy()
else
returnButton:setVisible( false )
end
else
desPos = eyePos() + eyeAngles():getForward() * 50
ent._sev_ReturnPos = ent:getPos()
returnButton:setPos( ent._sev_ReturnPos )
returnButton:setVisible( true )
end
net.start( "LKL_SEV_SetPos" )
net.writeEntity( ent )
net.writeVector( desPos )
net.send()
end
local function clearReturn( ent, chipData )
local returnButton = chipData.ReturnButton
ent._sev_ReturnPos = nil
if ent._sev_ReturnButton == returnButton then
ent._sev_ReturnButton = nil
returnButton:destroy()
else
returnButton:setVisible( false )
end
end
local function makeRestartButton( ent, chipData )
local hudButton = HUDButtonDiamond:new( ent:getPos(), false )
hudButton:setParent( ent )
hudButton:setRadius( diamondRadius )
hudButton:setThickness( diamondThickness )
hudButton:setFont( chipNameFont )
hudButton:setTextAnchor( TEXT_ALIGN.TOP )
hudButton:setTextAlignX( TEXT_ALIGN.CENTER )
hudButton:setTextAlignY( TEXT_ALIGN.TOP )
hudButton:setTextMargin( 3 )
hudButton:setTextSpacing( 0 )
hudButton:setColorToggleOff( Color( 0, 0, 0, 0 ) )
hudButton:setColorToggleOffHovered( Color( 255, 255, 255, 255 ) )
hudButton:setUseTopBottom( false )
hudButton:setInnerScale( diamondInnerScale )
function hudButton:canShowLinked()
return active
end
function hudButton:getInnerScale()
if not self:isHovered() then return 1 end
return self.class.getInnerScale( self )
end
function hudButton:inputClk( _ply, key, state )
if not state then return end
if restartChipKeyComboLookup[key] then
local restarting = true
for _, comboKey in ipairs( restartChipKeyCombo ) do
if not input.isKeyDown( comboKey ) then
restarting = false
break
end
end
if restarting then
restartChip( ent )
return
end
end
if key == makeChipSolidKey then
net.start( "LKL_SEV_MakeChipSolid" )
net.writeEntity( ent )
net.send()
elseif key == toggleBringChipKey then
toggleBring( ent, chipData )
elseif key == clearChipReturnKey then
clearReturn( ent, chipData )
end
end
function hudButton:updateText()
local textTbl = {
chipNameTextColor, ent:getChipName(),
}
if showErrorMessages == 1 or ( showErrorMessages == 2 and self:isHovered() ) then
if chipData.ServerMsg then
for _, msg in ipairs( chipData.ServerMsg ) do
table.insert( textTbl, c_realm_server )
table.insert( textTbl, "\n" .. msg )
end
end
if chipData.ClientMsg then
for _, msg in ipairs( chipData.ClientMsg ) do
table.insert( textTbl, c_realm_client )
table.insert( textTbl, "\n" .. msg )
end
end
end
hudButton:setText( textTbl )
end
if showErrorMessages == 2 then
function hudButton:onHoverStarted()
self:updateText()
end
function hudButton:onHoverEnded()
self:updateText()
end
end
return hudButton
end
local function makeReturnButton( ent, chipData )
if isValid( ent._sev_ReturnButton ) then
ent._sev_ReturnButton:destroy()
ent._sev_ReturnButton = nil
end
local hudButton = HUDButtonDiamond:new( ent._sev_ReturnPos or ent:getPos(), false )
hudButton:setRadius( diamondRadius * 0.5 )
hudButton:setThickness( diamondThickness )
hudButton:setColorToggleOff( returnDiamondColor )
hudButton:setColorToggleOffHovered( returnDiamondHoveredColor )
hudButton:setUseTopBottom( false )
hudButton:setInnerScale( diamondInnerScale )
hudButton:setVisible( ent._sev_ReturnPos ~= nil )
function hudButton:canShowLinked()
return active
end
function hudButton:inputClk( _ply, key, state )
if not state then return end
if key == toggleBringChipKey then
toggleBring( ent, chipData )
elseif key == clearChipReturnKey then
clearReturn( ent, chipData )
end
end
function hudButton:getColorEff()
local restartButton = chipData.RestartButton
if restartButton and restartButton:isHovered() then
return self:getColorToggleOffHovered()
end
return self.class.getColorEff( self )
end
function hudButton:draw( x, y )
self.class.draw( self, x, y )
local scrPos = ent:getPos():toScreen()
if not scrPos.visible then return end
render.setColor( self:getColorEff() )
render.drawLine( x, y, scrPos.x, scrPos.y )
end
function hudButton:splitOff()
if not ent._sev_ReturnPos then return end -- Doesn't have a returnb pos, no need to linger.
-- VERY hacky
chipData.ReturnButton = nil
chipData = { ReturnButton = self }
ent._sev_ReturnButton = self
end
return hudButton
end
local function addErroredChip( ent, isServer, msg )
local data = erroredChipDatas[ent]
if not data then
data = {
OnServer = false,
OnClient = false,
ChipName = ent:getChipName(),
}
data.RestartButton = makeRestartButton( ent, data )
data.ReturnButton = makeReturnButton( ent, data )
erroredChipDatas[ent] = data
end
local msgData
if showErrorMessages ~= 0 then
msgData = { splitErrorMessage( msg ) }
end
if isServer then
data.OnServer = true
else
data.OnClient = true
end
if msgData then
data[isServer and "ServerMsg" or "ClientMsg"] = msgData
end
local onServer = data.OnServer
local onClient = data.OnClient
local onShared = onServer and onClient
local restartButton = data.RestartButton
if onShared then
restartButton:setLeftTopColor( c_realm_server )
restartButton:setRightBottomColor( c_realm_client )
elseif onServer then
restartButton:setLeftTopColor( c_realm_server )
restartButton:setRightBottomColor( c_realm_server )
else
restartButton:setLeftTopColor( c_realm_client )
restartButton:setRightBottomColor( c_realm_client )
end
restartButton:updateText()
end
hook.add( "StarfallError", "LKL_SEV_TrackClientError", function( ent, ply, msg )
local isServer = ply == game.getWorld()
if not isServer and ply ~= owner() then return end
if not isValid( ent ) then return end
if ent:getOwner() ~= owner() then return end
addErroredChip( ent, isServer, msg )
end )
hook.add( "KeyPress", "LKL_SEV_RemoveChipsWhenRefreshed", function( ply, key )
if not isFirstTimePredicted() then return end
if key ~= IN_KEY_ATTACK and key ~= IN_KEY_RELOAD then return end
local wep = ply:getActiveWeapon()
if not isValid( wep ) or wep:getClass() ~= "gmod_tool" then return end
if wep:getToolMode() ~= "starfall_processor" then return end
local ent = ply:getEyeTrace().Entity
if not isValid( ent ) or ent:getClass() ~= "starfall_processor" then return end
if ent:getOwner() ~= ply then return end
removeErroredChip( ent )
end )
hook.add( "EntityRemoved", "LKL_SEV_RemoveDeletedChips", function( ent )
if not erroredChipDatas[ent] then return end
removeErroredChip( ent )
end )
net.receive( "LKL_SEV_SetActive", function()
active = net.readBool()
end )
net.receive( "LKL_SEV_RestartSucceeded", function()
local ent = net.readEntity()
if not isValid( ent ) then return end
removeErroredChip( ent )
end )
do
for _, key in ipairs( restartChipKeyCombo ) do
restartChipKeyComboLookup[key] = true
end
enableHud( player(), true )
end