-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZScript.zsc
403 lines (293 loc) · 14.9 KB
/
ZScript.zsc
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
version "3.3.0"
// ZChecker, an universal debugger for *ZDoom-family ports written on ZScript.
//
// Main repository:
// https://github.com/LLDM-Doom-Modding/ZChecker
//
// (c) Morthimer McMare a.k.a. JSO_x, 2018-2024.
// (c) LLDM Doom Modding team, 2022-2024.
// For all code files:
// Tab size - 4 spaces.
// Indentation style - in general a "one true brace".
// Spaces style - generous/rife.
//
// If you want to change something in the project core, please try to use this
//style (of course, gist of the code has higher priority). Modules like
//infopanels and console commands are formally free from this rule...
// General, base, utility and miscellaneous code; constants are in "ZCUtils.zsc":
#include "ZScript/ZCUtils.zsc"
#include "ZScript/Core/ZCBranchSpecific.zsc"
#include "ZScript/Core/ZCDataStructures.zsc"
#include "ZScript/ZCBaseClasses.zsc"
#include "ZScript/Core/ZCMenus.zsc"
#include "ZScript/Core/ZCMapScripts.zsc"
#include "ZScript/Core/ZCCommandMenuItems.zsc"
#include "ZScript/Core/ZCInitializationCore.zsc"
#include "ZScript/Core/ZCRendererCore.zsc"
// Console classes and CCMDs:
#include "ZScript/ZCCommandsGeneral.zsc"
#include "ZScript/ZCCommandsActorAlter.zsc"
#include "ZScript/ZCCommandsMap.zsc"
#include "ZScript/ZCCommandsThinkers.zsc"
#include "ZScript/ZCCommandsMiscControl.zsc"
#include "ZScript/ZCTooltipClasses.zsc"
// Informational panels classes:
#include "ZScript/ZCInfopanelsGeneral.zsc"
#include "ZScript/ZCInfopanelsSubsystems.zsc"
#include "ZScript/ZCInfopanelsPointers.zsc"
#include "ZScript/ZCInfopanelsGeometry.zsc"
#include "ZScript/ZCInfopanelsOther.zsc"
const ZCheckerVersionNumber = "0.87b";
const ZCheckerVersion = ZCheckerVersionNumber .. ", branch \"" .. ZCheckerVersionBranch .. "\"";
const MaxTestee = 3; // [McM] A legacy constant from 2018, will rename someday.
//Right now the whole project is ready to accept changing
//constant to variable (it remains only to replace the
//identifier name and call method everywhere).
// === Internal core of the project.
class ZCheckerHandler: StaticEventHandler {
ZCGlobal globalclass;
ZCPanelsStorage panels;
ZCheckerHandlerDatascopeVariables datascoped;
Array<ZCConsoleClass> zcConsoleHandleClasses;
Array<ZCInternalActorNameCell> allActorNames;
// In current structure it's impossible to avoid unloading pointers to
//actors from memory on level reloading. Found this too late for a
//simple fix.
ZCheckerField Testee[ MaxTestee ];
ZCheckerCCMDInfo zcCCMDInfo;
void UpdateInternalClassnameByField( uint fieldnum ) {
if ( fieldnum >= MaxTestee )
return;
String newClassname = "";
if ( Testee[ fieldnum ].mo )
newClassname = Testee[ fieldnum ].mo.GetClassName();
globalclass.SetClassnameVariable( "$" .. ( fieldnum + 1 ), newClassname );
} // of void UpdateInternalClassnameByField( uint fieldnum ) {}
clearscope bool CheckForResetLocalization( void ) const {
// Double call of the "StringTable.Localize()" is for optimization.
if ( datascoped.lastLocalizationTestGameTic != gametic && StringTable.Localize( "$ZCHECKER_CURLANGUAGE" ) != datascoped.lastLocalizedTestString ) {
datascoped.lastLocalizedTestString = StringTable.Localize( "$ZCHECKER_CURLANGUAGE" );
datascoped.lastLocalizationTestGameTic = gametic;
return true;
}
return false;
} // of clearscope bool CheckForResetLocalization( void ) {}
void ResetPlayLocalization( void ) {
if ( CheckForResetLocalization() ) {
ZCGlobal.Log( LL_Debug, GetClassName() .. "::ResetPlayLocalization(). Updating all console classes. New language is " .. datascoped.lastLocalizedTestString );
for ( int i = 0; i < zcConsoleHandleClasses.Size(); i++ )
zcConsoleHandleClasses[ i ].ResetCachedHelpString();
}
} // of void ResetPlayLocalization( void ) {}
private String neteventArgColored( int value ) {
return ( value == 0? TEXTCOLOR_DARKBROWN : TEXTCOLOR_CREAM ) .. value;
}
override void NetworkProcess( ConsoleEvent e ) {
bool isDebugLoggingLevel = ( ZCGlobal.GetLoglevel() >= LL_Debug );
// ZChecker CCMDs parsing:
String ccmdName = zcCCMDInfo.InitFromEvent( e );
if ( ccmdName ~== "zc_update_panels_order" ) {
if ( zcCCMDInfo.args.Size() == 1 ) {
panels.panelsstr = zcCCMDInfo.args[ 0 ];
panels.UpdatePanels();
panels.InitSetPanelsorderCVars( zcCCMDInfo.args[ 0 ] );
} else {
ZCGlobal.Log( LL_Emergency, GetClassName() .. "::NetworkProcess(). Updating panels order netevent has wrong amount of arguments (must be 1, got " .. zcCCMDInfo.args.Size() .. ")." );
ZCGlobal.Log( LL_Main, GetClassName() .. "::NetworkProcess(). Name: \"" .. TEXTCOLOR_TAN .. e.Name .. "\c-\"." );
}
Super.NetworkProcess( e );
return;
} // of if ( ccmdName ~== "zc_update_panels_order" ) {}
if ( multiplayer && ccmdName ~== "zc_multiplayer_synctest" ) {
if ( e.args[ 1 ] != consoleplayer ) {
if ( zcCCMDInfo.args.Size() == 1 ) {
uint testeePos = uint( e.args[ 0 ] );
uint srcPlayer = uint( e.args[ 1 ] );
bool argerror = false;
if ( testeePos >= MaxTestee ) {
argerror = true;
ZCGlobal.Log( LL_Emergency, GetClassName() .. "::NetworkProcess(). Multiplayer sync netevent: wrong position " .. testeePos .. " to compare." );
}
if ( srcPlayer >= MAXPLAYERS ) {
argerror = true;
ZCGlobal.Log( LL_Emergency, GetClassName() .. "::NetworkProcess(). Multiplayer sync netevent: wrong source player #" .. srcPlayer .. "." );
}
if ( !argerror )
Testee[ testeePos ].asyncwith = ( ( Testee[ testeePos ].hashsync[ srcPlayer ] == zcCCMDInfo.args[ 0 ] )? 0 : srcPlayer + 1 );
} else {
ZCGlobal.Log( LL_Emergency, GetClassName() .. "::NetworkProcess(). Multiplayer sync netevent has wrong amount of arguments (must be 1, got " .. zcCCMDInfo.args.Size() .. ")." );
ZCGlobal.Log( LL_Main, GetClassName() .. "::NetworkProcess(). Name: \"" .. TEXTCOLOR_TAN .. e.Name .. "\c-\"." );
}
}
Super.NetworkProcess( e );
return;
} // of if ( multiplayer && ccmdName ~== "zc_multiplayer_synctest" ) {}
// Just a debug NetworkProcess() output:
if ( isDebugLoggingLevel ) {
String debugstr = GetClassName() .. "::NetworkProcess(). CCMD: \"" .. ccmdName .. "\"";
if ( zcCCMDInfo.args.Size() != 0 ) {
for ( int i = 0; i < zcCCMDInfo.args.Size(); i++ )
debugstr.AppendFormat( " [" .. TEXTCOLOR_DARKGREEN .. "#%i: \"%s\"" .. LLCOLOR_DEBUG .. "]", i + 1, zcCCMDInfo.args[ i ] );
} else {
debugstr = debugstr .. ", no arguments.";
}
ZCGlobal.ClearscopeLog( LL_Debug, debugstr );
}
int interceptNeteventsMode = clamp( CVar.GetCVar( "lldm_zc_specinfo_netevents", players[ e.Player ] ).GetInt(), 0, 3 );
int nonblockingCommandsAmount = 0;
// Polling ZChecker CCMD handlers by stored netevent name:
for ( int i = 0; i < zcConsoleHandleClasses.Size(); i++ ) {
if ( !( zcConsoleHandleClasses[ i ] is 'ZCConsoleCommand' ) )
continue; // Skipping tooltips and other plaintext classes.
ZCConsoleCommand curCCMD = ZCConsoleCommand( zcConsoleHandleClasses[ i ] );
String curCCMDNeteventName = curCCMD.ccmdInterfaceData.neteventName;
if ( curCCMDNeteventName != "" && ccmdName ~== curCCMDNeteventName ) {
curCCMD.ccmd = zcCCMDInfo;
if ( nonblockingCommandsAmount == 0 )
ZCGlobal.Log( LL_APIMessage, LLCOLOR_DARK .. GetClassName() .. "::NetworkProcess(). " .. LLCOLOR_MAIN .. "Maximal amount of arguments (excluding name): " .. zcCCMDInfo.maxArgsAmount );
if ( zcCCMDInfo.paramCallHelp && !( curCCMD.zcFlags & curCCMD.CCF_HelpArgOverride ) ) {
// Converts a "zc<ccmd> help" to a "zchelp <ccmd>".
//Too subtly realisation, actually.
if ( curCCMD.ccmdInterfaceData.helpInternalAliases.Size() == 0 ) {
ZCGlobal.Log( LL_Emergency, GetClassName() .. "::NetworkProcess(). No internal help aliases for the \"" .. curCCMD.GetClassName() .. "\"." );
break;
}
zcCCMDInfo.paramCallHelp = false;
zcCCMDInfo.args.Clear();
zcCCMDInfo.args.Push( curCCMD.ccmdInterfaceData.helpInternalAliases[ 0 ] );
ccmdName = "zc_help";
ZCGlobal.Log( LL_APIMessage, String.Format(
"%s::NetworkProcess(). Command was changed to the \"" .. TEXTCOLOR_ORANGE .. "%s %s" .. LLCOLOR_MAIN .. "\".",
GetClassName(), "zchelp", zcCCMDInfo.args[ 0 ]
) );
i = -1;
continue;
} else if ( curCCMD.zcFlags & ( curCCMD.CCF_NonblockingSuccess | curCCMD.CCF_NonblockingFailure ) ) {
// Requires a non-blocking execution.
if ( nonblockingCommandsAmount != 0 )
ZCGlobal.Log( LL_APIMessage, LLCOLOR_DEBUG .. GetClassName() .. "::NetworkProcess(). " .. TEXTCOLOR_OLIVE .. "Requested a non-blocking execution" .. LLCOLOR_DEBUG .. "." );
zcCCMDInfo.nonblockingCommands.Push( curCCMD );
nonblockingCommandsAmount++;
} else {
// Default execution.
// Saving original log level:
int realLogLevel = ZCGlobal.GetLoglevel();
ZCGlobal.ForceSetLogLevel( zcCCMDInfo.paramLogLevelOverride );
ResetPlayLocalization();
// Command call:
if ( curCCMD.HandleArguments() )
curCCMD.DoCommand();
else if ( !zcCCMDInfo.paramNoUsage )
ZCGlobal.Log( LL_Normal | LL_NoPrefix, TEXTCOLOR_YELLOW .. ZCGlobal.Locz( "CCMDSHELP_USAGE" ) .. LLCOLOR_MAIN .. ":\n" .. curCCMD.GetHelpString() );
// Restoring log level:
ZCGlobal.ForceSetLogLevel( realLogLevel );
interceptNeteventsMode = 0;
break;
}
}
} // of for ( int i = 0; i < zcConsoleHandleClasses.Size(); i++ ) {}
if ( nonblockingCommandsAmount != zcCCMDInfo.nonblockingCommands.Size() && isDebugLoggingLevel )
ZCGlobal.Log( LL_Debug, GetClassName() .. "::NetworkProcess(). " .. TEXTCOLOR_BRICK .. "Non-blocking commands array size changed" .. LLCOLOR_DEBUG .. ": was " .. nonblockingCommandsAmount .. ", new " .. zcCCMDInfo.nonblockingCommands.Size() );
nonblockingCommandsAmount = zcCCMDInfo.nonblockingCommands.Size();
if ( nonblockingCommandsAmount != 0 ) {
if ( isDebugLoggingLevel ) {
String debugstr = GetClassName() .. "::NetworkProcess(). Non-blocking handling of ";
for ( int i = 0; i < nonblockingCommandsAmount; i++ )
debugstr.AppendFormat( "\"" .. TEXTCOLOR_BLUE .. zcCCMDInfo.nonblockingCommands[ i ].GetClassName() .. LLCOLOR_DEBUG .. "\"; " );
ZCGlobal.ClearscopeLog( LL_Debug, debugstr .. "with total amount of " .. nonblockingCommandsAmount .. " commands." );
} // of if ( isDebugLoggingLevel ) {}
bool printUsage = true;
int curCCMDIndex = 0;
zcCCMDInfo.SetUsageMessageNonblockingCCMD( zcCCMDInfo.nonblockingCommands[ 0 ] );
for ( ; curCCMDIndex < nonblockingCommandsAmount; curCCMDIndex++ ) {
ZCConsoleCommand curCCMD = zcCCMDInfo.nonblockingCommands[ curCCMDIndex ];
if ( curCCMD.HandleArguments() ) {
int realLogLevel = ZCGlobal.GetLoglevel();
ZCGlobal.ForceSetLogLevel( zcCCMDInfo.paramLogLevelOverride );
curCCMD.DoCommand();
printUsage = false;
ZCGlobal.ForceSetLogLevel( realLogLevel );
if ( !( curCCMD.zcFlags & curCCMD.CCF_NonblockingSuccess ) )
break;
} else {
if ( !( curCCMD.zcFlags & curCCMD.CCF_NonblockingFailure ) )
break;
}
}
if ( printUsage && zcCCMDInfo.usageNonblockingCommand && !zcCCMDInfo.paramNoUsage )
ZCGlobal.Log( LL_Normal | LL_NoPrefix, TEXTCOLOR_YELLOW .. ZCGlobal.Locz( "CCMDSHELP_USAGE" ) .. LLCOLOR_MAIN .. ":\n" .. zcCCMDInfo.usageNonblockingCommand.GetHelpString() );
interceptNeteventsMode = 0;
zcCCMDInfo.nonblockingCommands.Clear();
} // of if ( nonblockingCommandsAmount != 0 ) {}
if ( e.name == "zc_evmap_recreate" || e.name == "zc_evmap_reloadsectors" /*|| e.name == "zc_evmap_pause_level_part"*/ )
interceptNeteventsMode = 0;
if ( interceptNeteventsMode ) {
String outStr = "";
if ( interceptNeteventsMode == 3 ) {
outStr = String.Format( TEXTCOLOR_GRAY .. "%s" .. TEXTCOLOR_DARKGRAY .. " %s ",
ZCGlobal.Locz( "NETEVENTINTC_" .. ( e.IsManual? "MANUAL" : "SYSTEM" ) ),
ZCGlobal.Locz( "NETEVENTINTC_NETEVENT" ) );
} else {
outStr = TEXTCOLOR_DARKGRAY .. ZCGlobal.Locz( "NETEVENTINTC_NETEVENT" ) .. " ";
}
// Compatibility between all *ZDoom versions:
int compatTicRate = max( Thinker.Tics2Seconds( 350000 ), 1 );
compatTicRate = int( 350000 / compatTicRate );
if ( interceptNeteventsMode >= 2 ) {
outStr.AppendFormat( "%s %s.%02i ",
ZCGlobal.Locz( "NETEVENTINTC_TIMEAT" ),
level.TimeFormatted(),
int( floor( ( level.time % compatTicRate ) / double( compatTicRate ) * 100.0 ) ) );
}
String ARGSSEP = TEXTCOLOR_DARKGRAY .. "/" .. TEXTCOLOR_CREAM;
outStr.AppendFormat( "\"" .. TEXTCOLOR_LIGHTBLUE .. e.Name .. " " .. TEXTCOLOR_CREAM .. "%s%s%s%s%s" .. TEXTCOLOR_DARKGRAY .. "\"",
neteventArgColored( e.args[ 0 ] ), ARGSSEP, neteventArgColored( e.args[ 1 ] ), ARGSSEP, neteventArgColored( e.args[ 2 ] ) );
if ( interceptNeteventsMode == 3 )
outStr.AppendFormat( " %s" .. TEXTCOLOR_WHITE .. "%i", ZCGlobal.Locz( "NETEVENTINTC_FROMPLAYER" ), e.Player );
ZCGlobal.Log( LL_Normal, outStr );
} // of if ( interceptNeteventsMode ) {}
Super.NetworkProcess( e );
} // of override void NetworkProcess( ConsoleEvent e ) {}
override void WorldTick() {
if ( ( gamestate == GS_LEVEL || gamestate == GS_DEMOSCREEN ) && !( level.maptime % 17 ) )
globalclass.UpdateLogLevel();
// ACS works only in the play scope.
panels.TickSetPanelsorderCVars();
for ( int i = 0; i < panels.curPanels.PlayscopedSize(); i++ ) {
ZCBaseInfoPanelPart_PlayScope playpanel = ZCBaseInfoPanelPart_PlayScope( panels.curPanels.playnodes[ i ].panel );
for ( int j = 0; j < MaxTestee; j++ ) {
Actor curTestee = UpdateTesteeField( j );
if ( curTestee )
playpanel.playscopedInfo[ j ] = playpanel.GetInfo_play( curTestee, Testee[ j ] );
}
}
Super.WorldTick();
// Test for asynchronous actors:
int playernum = ( level.maptime % MAXPLAYERS );
if ( multiplayer && playeringame[ playernum ] ) {
if ( playernum == consoleplayer ) {
for ( int i = 0; i < MaxTestee; i++ ) {
// Warning! Hash may generate a format specifier ("%s" etc). Do not use any "printf()" output!
String hash = Testee[ i ].GetHash();
EventHandler.SendNetworkEvent( "zc_multiplayer_synctest" .. ZCHECKER_ARGS_SEPARATOR .. hash, i, consoleplayer );
}
} else {
for ( int i = 0; i < MaxTestee; i++ )
Testee[ i ].UpdateHash( playernum );
}
//for ( int i = 0; i < MaxTestee; i++ )
// console.printf( GetClassName() .. "::WorldTick(). ZCheckerField[ " .. i .. " ]: \"" .. Testee[ i ].GetHash() .. "\"" );
}
} // of override void WorldTick() {}
override void WorldLoaded( WorldEvent e ) {
globalclass = ZCGlobal.Get();
globalclass.SaveHandler( self );
globalclass.SetClassnameVariable( "$1", "" );
globalclass.SetClassnameVariable( "$2", "" );
globalclass.SetClassnameVariable( "$3", "" );
globalclass.SetClassnameVariable( "$last", "" );
if ( panels.panelsorderChanged )
panels.UpdatePanels( true );
Super.WorldLoaded( e );
}
} // of class ZCheckerHandler: StaticEventHandler {}