@@ -10,17 +10,8 @@ global function AddNorthstarModMenu_MainMenuFooter
10
10
global function ReloadMods
11
11
12
12
13
- struct modData {
14
- string name = " "
15
- string version = " "
16
- string link = " "
17
- int loadPriority = 0
18
- bool enabled = false
19
- array< string> conVars = []
20
- }
21
-
22
13
struct panelContent {
23
- modData & mod
14
+ ModInfo & mod
24
15
bool isHeader = false
25
16
}
26
17
@@ -42,10 +33,10 @@ struct {
42
33
var menu
43
34
array< var> panels
44
35
int scrollOffset = 0
45
- array< string > enabledMods
36
+ array< ModInfo > enabledMods
46
37
var currentButton
47
38
string searchTerm
48
- modData & lastMod
39
+ ModInfo & lastMod
49
40
} file
50
41
51
42
const int PANELS_LEN = 15
@@ -155,11 +146,20 @@ void function OnModMenuClosed()
155
146
}
156
147
catch ( ex ) {}
157
148
158
- array< string > current = GetEnabledModsArray ()
149
+ array< ModInfo > current = GetEnabledModsArray ()
159
150
bool reload
160
- foreach ( string mod in current )
151
+ foreach ( ModInfo mod in current )
161
152
{
162
- if ( file. enabledMods . find (mod) == - 1 )
153
+ bool notFound = true
154
+ foreach ( ModInfo enMod in file. enabledMods )
155
+ {
156
+ if ( mod. name == enMod. name )
157
+ {
158
+ notFound = false
159
+ break
160
+ }
161
+ }
162
+ if ( notFound )
163
163
{
164
164
reload = true
165
165
break
@@ -181,10 +181,10 @@ void function OnModButtonFocused( var button )
181
181
182
182
RuiSetGameTime ( rui, " startTime" , - 99999.99 ) // make sure it skips the whole animation for showing this
183
183
RuiSetString ( rui, " headerText" , modName )
184
- RuiSetString ( rui, " messageText" , FormatModDescription ( modName ) )
184
+ RuiSetString ( rui, " messageText" , FormatModDescription () )
185
185
186
186
// Add a button to open the link with if required
187
- string link = NSGetModDownloadLinkByModName ( modName )
187
+ string link = file . lastMod . downloadLink
188
188
var linkButton = Hud_GetChild ( file. menu , " ModPageButton" )
189
189
if ( link. len () )
190
190
{
@@ -198,28 +198,41 @@ void function OnModButtonFocused( var button )
198
198
Hud_SetVisible ( linkButton, false )
199
199
}
200
200
201
- SetControlBarColor ( modName )
201
+ SetControlBarColor ( file . lastMod )
202
202
203
- bool required = NSIsModRequiredOnClient ( modName )
203
+ bool required = file . lastMod . requiredOnClient
204
204
Hud_SetVisible ( Hud_GetChild ( file. menu , " WarningLegendLabel" ), required )
205
205
Hud_SetVisible ( Hud_GetChild ( file. menu , " WarningLegendImage" ), required )
206
206
}
207
207
208
208
void function OnModButtonPressed ( var button )
209
209
{
210
- string modName = file. mods [ int ( Hud_GetScriptID ( Hud_GetParent ( button ) ) ) + file. scrollOffset - 1 ]. mod . name
211
- if ( StaticFind ( modName ) && NSIsModEnabled ( modName ) )
210
+ ModInfo mod = file. mods [ int ( Hud_GetScriptID ( Hud_GetParent ( button ) ) ) + file. scrollOffset - 1 ]. mod
211
+ string modName = mod. name
212
+ if ( StaticFind ( modName ) && mod. enabled )
212
213
CoreModToggleDialog ( modName )
213
214
else
214
215
{
215
- NSSetModEnabled ( modName, ! NSIsModEnabled ( modName ) )
216
- var panel = file. panels [ int ( Hud_GetScriptID ( Hud_GetParent ( button ) ) ) - 1 ]
217
- SetControlBoxColor ( Hud_GetChild ( panel, " ControlBox" ), modName )
218
- SetControlBarColor ( modName )
219
- SetModEnabledHelperImageAsset ( Hud_GetChild ( panel, " EnabledImage" ), modName )
220
- // RefreshMods()
221
- UpdateListSliderPosition ()
222
- UpdateListSliderHeight ()
216
+ NSSetModEnabled ( modName, ! mod. enabled )
217
+ // retrieve state of the mod that just got toggled
218
+ array< ModInfo> infos = NSGetModInformation ( mod. name )
219
+ foreach ( ModInfo modInfo in infos )
220
+ {
221
+ if ( modInfo. name != modName || modInfo. version != mod. version )
222
+ {
223
+ continue
224
+ }
225
+ // Update UI mod state
226
+ file. mods [ int ( Hud_GetScriptID ( Hud_GetParent ( button ) ) ) + file. scrollOffset - 1 ]. mod = modInfo
227
+ var panel = file. panels [ int ( Hud_GetScriptID ( Hud_GetParent ( button ) ) ) - 1 ]
228
+ SetControlBoxColor ( Hud_GetChild ( panel, " ControlBox" ), modInfo )
229
+ SetControlBarColor ( modInfo )
230
+ SetModEnabledHelperImageAsset ( Hud_GetChild ( panel, " EnabledImage" ), modInfo )
231
+ // RefreshMods()
232
+ UpdateListSliderPosition ()
233
+ UpdateListSliderHeight ()
234
+ break
235
+ }
223
236
}
224
237
}
225
238
@@ -235,8 +248,8 @@ void function OnAuthenticationAgreementButtonPressed( var button )
235
248
236
249
void function OnModLinkButtonPressed ( var button )
237
250
{
238
- string modName = file. mods [ int ( Hud_GetScriptID ( Hud_GetParent ( file. currentButton ) ) ) + file. scrollOffset - 1 ]. mod . name
239
- string link = NSGetModDownloadLinkByModName ( modName )
251
+ ModInfo mod = file. mods [ int ( Hud_GetScriptID ( Hud_GetParent ( file. currentButton ) ) ) + file. scrollOffset - 1 ]. mod
252
+ string link = mod . downloadLink
240
253
if ( link. find (" http://" ) != 0 && link. find (" https://" ) != 0 )
241
254
link = " http://" + link // links without the http or https protocol get opened in the internal browser
242
255
LaunchExternalWebBrowser ( link, WEBBROWSER_FLAG_FORCEEXTERNAL )
@@ -266,7 +279,7 @@ void function OnHideConVarsChange( var n )
266
279
if ( modName == " " )
267
280
return
268
281
var rui = Hud_GetRui ( Hud_GetChild ( file. menu , " LabelDetails" ) )
269
- RuiSetString ( rui, " messageText" , FormatModDescription ( modName ) )
282
+ RuiSetString ( rui, " messageText" , FormatModDescription () )
270
283
}
271
284
272
285
// LIST LOGIC
@@ -289,23 +302,34 @@ void function CoreModToggleDialog( string mod )
289
302
290
303
void function DisableMod ()
291
304
{
292
- string modName = file. mods [ int ( Hud_GetScriptID ( Hud_GetParent ( file. currentButton ) ) ) + file. scrollOffset - 1 ]. mod . name
305
+ ModInfo mod = file. mods [ int ( Hud_GetScriptID ( Hud_GetParent ( file. currentButton ) ) ) + file. scrollOffset - 1 ]. mod
306
+ string modName = mod. name
293
307
NSSetModEnabled ( modName, false )
294
308
295
- var panel = file. panels [ int ( Hud_GetScriptID ( Hud_GetParent ( file. currentButton ) ) ) - 1 ]
296
- SetControlBoxColor ( Hud_GetChild ( panel, " ControlBox" ), modName )
297
- SetControlBarColor ( modName )
298
- SetModEnabledHelperImageAsset ( Hud_GetChild ( panel, " EnabledImage" ), modName )
309
+ // retrieve state of the mod that just got toggled
310
+ array< ModInfo> infos = NSGetModInformation ( mod. name )
311
+ foreach ( modInfo in infos )
312
+ {
313
+ if ( modInfo. name != modName || modInfo. version != mod. version )
314
+ {
315
+ continue
316
+ }
317
+ var panel = file. panels [ int ( Hud_GetScriptID ( Hud_GetParent ( file. currentButton ) ) ) - 1 ]
318
+ SetControlBoxColor ( Hud_GetChild ( panel, " ControlBox" ), modInfo )
319
+ SetControlBarColor ( modInfo )
320
+ SetModEnabledHelperImageAsset ( Hud_GetChild ( panel, " EnabledImage" ), modInfo )
299
321
300
- RefreshMods ()
322
+ RefreshMods ()
323
+ break
324
+ }
301
325
}
302
326
303
- array< string > function GetEnabledModsArray ()
327
+ array< ModInfo > function GetEnabledModsArray ()
304
328
{
305
- array< string > enabledMods
306
- foreach ( string mod in NSGetModNames () )
329
+ array< ModInfo > enabledMods
330
+ foreach ( ModInfo mod in NSGetModsInformation () )
307
331
{
308
- if ( NSIsModEnabled ( mod ) )
332
+ if ( mod. enabled )
309
333
enabledMods. append ( mod )
310
334
}
311
335
return enabledMods
@@ -329,25 +353,26 @@ void function UpdateList()
329
353
330
354
void function RefreshMods ()
331
355
{
332
- array< string > modNames = NSGetModNames ()
356
+ array< ModInfo > mods = NSGetModsInformation ()
333
357
file. mods . clear ()
334
358
335
359
bool reverse = GetConVarBool ( " modlist_reverse" )
336
360
337
- int lastLoadPriority = reverse ? NSGetModLoadPriority ( modNames[ modNames . len () - 1 ] ) + 1 : - 1
361
+ int lastLoadPriority = reverse ? mods . top () . loadPriority + 1 : - 1
338
362
string searchTerm = Hud_GetUTF8Text ( Hud_GetChild ( file. menu , " BtnModsSearch" ) ). tolower ()
339
363
340
- for ( int i = reverse ? modNames . len () - 1 : 0 ;
341
- reverse ? ( i >= 0 ) : ( i < modNames . len () );
364
+ for ( int i = reverse ? mods . len () - 1 : 0 ;
365
+ reverse ? ( i >= 0 ) : ( i < mods . len () );
342
366
i += ( reverse ? - 1 : 1 ) )
343
367
{
344
- string mod = modNames[i]
368
+ ModInfo mod = mods[i]
369
+ string modName = mod. name
345
370
346
- if ( searchTerm. len () && mod . tolower (). find ( searchTerm ) == null )
371
+ if ( searchTerm. len () && modName . tolower (). find ( searchTerm ) == null )
347
372
continue
348
373
349
- bool enabled = NSIsModEnabled ( mod )
350
- bool required = NSIsModRequiredOnClient ( mod )
374
+ bool enabled = mod. enabled
375
+ bool required = mod. requiredOnClient
351
376
switch ( GetConVarInt ( " filter_mods" ) )
352
377
{
353
378
case filterShow. ONLY_ENABLED :
@@ -368,11 +393,11 @@ void function RefreshMods()
368
393
break
369
394
}
370
395
371
- int pr = NSGetModLoadPriority ( mod )
396
+ int pr = mod. loadPriority
372
397
373
398
if ( reverse ? pr < lastLoadPriority : pr > lastLoadPriority )
374
399
{
375
- modData m
400
+ ModInfo m
376
401
m. name = pr. tostring ()
377
402
378
403
panelContent c
@@ -382,16 +407,9 @@ void function RefreshMods()
382
407
lastLoadPriority = pr
383
408
}
384
409
385
- modData m
386
- m. name = mod
387
- m. version = NSGetModVersionByModName ( mod )
388
- m. link = NSGetModDownloadLinkByModName ( mod )
389
- m. loadPriority = NSGetModLoadPriority ( mod )
390
- m. enabled = enabled
391
- m. conVars = NSGetModConvarsByModName ( mod )
392
410
393
411
panelContent c
394
- c. mod = m
412
+ c. mod = mod
395
413
396
414
file. mods . append ( c )
397
415
}
@@ -405,7 +423,7 @@ void function DisplayModPanels()
405
423
break
406
424
407
425
panelContent c = file. mods [ file. scrollOffset + i ]
408
- modData mod = c. mod
426
+ ModInfo mod = c. mod
409
427
var btn = Hud_GetChild ( panel, " BtnMod" )
410
428
var headerLabel = Hud_GetChild ( panel, " Header" )
411
429
var box = Hud_GetChild ( panel, " ControlBox" )
@@ -435,53 +453,45 @@ void function DisplayModPanels()
435
453
436
454
Hud_SetVisible ( headerLabel, false )
437
455
438
- SetControlBoxColor ( box, mod. name )
456
+ SetControlBoxColor ( box, mod )
439
457
Hud_SetVisible ( box, true )
440
458
Hud_SetVisible ( line, false )
441
459
442
- Hud_SetVisible ( warning, NSIsModRequiredOnClient ( c . mod . name ) )
460
+ Hud_SetVisible ( warning, mod. requiredOnClient )
443
461
444
- SetModEnabledHelperImageAsset ( enabledImage, c. mod . name )
462
+ SetModEnabledHelperImageAsset ( enabledImage, c. mod )
445
463
}
446
464
Hud_SetVisible ( panel, true )
447
465
}
448
466
}
449
467
450
- void function SetModEnabledHelperImageAsset ( var panel, string modName )
468
+ void function SetModEnabledHelperImageAsset ( var panel, ModInfo mod )
451
469
{
452
- if ( NSIsModEnabled ( modName ) )
470
+ if ( mod . enabled )
453
471
RuiSetImage ( Hud_GetRui ( panel ), " basicImage" , $" rui/menu/common/merit_state_success" )
454
472
else
455
473
RuiSetImage ( Hud_GetRui ( panel ), " basicImage" , $" rui/menu/common/merit_state_failure" )
456
- RuiSetFloat3 (Hud_GetRui ( panel ), " basicImageColor" , GetControlColorForMod ( modName ) )
474
+ RuiSetFloat3 (Hud_GetRui ( panel ), " basicImageColor" , GetControlColorForMod ( mod ) )
457
475
Hud_SetVisible ( panel, true )
458
476
}
459
477
460
- void function SetControlBoxColor ( var box, string modName )
478
+ void function SetControlBoxColor ( var box, ModInfo mod )
461
479
{
462
480
var rui = Hud_GetRui ( box )
463
- // if ( NSIsModEnabled( modName ) )
464
- // RuiSetFloat3(rui, "basicImageColor", <0,1,0>)
465
- // else
466
- // RuiSetFloat3(rui, "basicImageColor", <1,0,0>)
467
- RuiSetFloat3 (rui, " basicImageColor" , GetControlColorForMod ( modName ) )
481
+ RuiSetFloat3 (rui, " basicImageColor" , GetControlColorForMod ( mod ) )
468
482
}
469
483
470
- void function SetControlBarColor ( string modName )
484
+ void function SetControlBarColor ( ModInfo mod )
471
485
{
472
486
var bar_element = Hud_GetChild ( file. menu , " ModEnabledBar" )
473
487
var bar = Hud_GetRui ( bar_element )
474
- // if ( NSIsModEnabled( modName ) )
475
- // RuiSetFloat3(bar, "basicImageColor", <0,1,0>)
476
- // else
477
- // RuiSetFloat3(bar, "basicImageColor", <1,0,0>)
478
- RuiSetFloat3 (bar, " basicImageColor" , GetControlColorForMod ( modName ) )
488
+ RuiSetFloat3 (bar, " basicImageColor" , GetControlColorForMod ( mod ) )
479
489
Hud_SetVisible ( bar_element, true )
480
490
}
481
491
482
- vector function GetControlColorForMod ( string modName )
492
+ vector function GetControlColorForMod ( ModInfo mod )
483
493
{
484
- if ( NSIsModEnabled ( modName ) )
494
+ if ( mod . enabled )
485
495
switch ( GetConVarInt ( " colorblind_mode" ) )
486
496
{
487
497
case 1 :
@@ -503,17 +513,19 @@ vector function GetControlColorForMod( string modName )
503
513
unreachable
504
514
}
505
515
506
- string function FormatModDescription ( string modName )
516
+ string function FormatModDescription ()
507
517
{
518
+ ModInfo mod = file. lastMod
519
+ string modName = mod. name
508
520
string ret
509
521
// version
510
- ret += format ( " Version %s\n " , NSGetModVersionByModName ( modName ) )
522
+ ret += format ( " Version %s\n " , mod . version )
511
523
512
524
// load priority
513
- ret += format ( " Load Priority: %i\n " , NSGetModLoadPriority ( modName ) )
525
+ ret += format ( " Load Priority: %i\n " , mod . loadPriority )
514
526
515
527
// convars
516
- array< string> modCvars = NSGetModConvarsByModName ( modName )
528
+ array< string> modCvars = mod . conVars
517
529
if ( modCvars. len () != 0 && GetConVarBool ( " modlist_show_convars" ) )
518
530
{
519
531
ret += " ConVars: "
@@ -530,7 +542,7 @@ string function FormatModDescription( string modName )
530
542
}
531
543
532
544
// description
533
- ret += format ( " \n %s\n " , NSGetModDescriptionByModName ( modName ) )
545
+ ret += format ( " \n %s\n " , mod . description )
534
546
535
547
return ret
536
548
}
0 commit comments