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
|
untyped
global function AddNorthstarModMenu
global function AddNorthstarModMenu_MainMenuFooter
global function ReloadMods
const int BUTTONS_PER_PAGE = 17
struct modStruct {
int modIndex
string modName
}
enum filterShow {
ALL = 0,
ONLY_ENABLED = 1,
ONLY_DISABLED = 2
}
struct {
int deltaX = 0
int deltaY = 0
} mouseDeltaBuffer
struct {
bool shouldReloadModsOnEnd
string currentMod
var currentButton
int scrollOffset = 0
array<modStruct> modsArrayFiltered
var menu
} file
void function AddNorthstarModMenu()
{
AddMenu( "ModListMenu", $"resource/ui/menus/modlist.menu", InitModMenu )
}
void function AddNorthstarModMenu_MainMenuFooter()
{
string controllerStr = PrependControllerPrompts( BUTTON_Y, "#MENU_TITLE_MODS" )
AddMenuFooterOption( GetMenu( "MainMenu" ), BUTTON_Y, controllerStr, "#MENU_TITLE_MODS", AdvanceToModListMenu )
}
void function AdvanceToModListMenu( var button )
{
AdvanceMenu( GetMenu( "ModListMenu" ) )
}
void function InitModMenu()
{
file.menu = GetMenu( "ModListMenu" )
AddMouseMovementCaptureHandler( file.menu, UpdateMouseDeltaBuffer )
AddMenuEventHandler( file.menu, eUIEvent.MENU_OPEN, OnModMenuOpened )
AddMenuEventHandler( file.menu, eUIEvent.MENU_CLOSE, OnModMenuClosed )
AddMenuFooterOption( file.menu, BUTTON_B, "#B_BUTTON_BACK", "#BACK" )
AddMenuFooterOption(
file.menu,
BUTTON_X,
PrependControllerPrompts( BUTTON_X, "#RELOAD_MODS" ),
"#RELOAD_MODS",
OnReloadModsButtonPressed
)
AddMenuFooterOption(
file.menu,
BUTTON_BACK,
PrependControllerPrompts( BUTTON_Y, "#AUTHENTICATION_AGREEMENT" ),
"#AUTHENTICATION_AGREEMENT",
OnAuthenticationAgreementButtonPressed
)
foreach ( var button in GetElementsByClassname( file.menu, "ModButton" ) )
{
AddButtonEventHandler( button, UIE_GET_FOCUS, OnModMenuButtonFocused )
AddButtonEventHandler( button, UIE_CLICK, OnModMenuButtonPressed )
}
AddButtonEventHandler( Hud_GetChild( file.menu, "SwtBtnShowFilter"), UIE_CHANGE, OnFiltersChange )
AddButtonEventHandler( Hud_GetChild( file.menu, "BtnModsSearch"), UIE_CHANGE, OnFiltersChange )
AddButtonEventHandler( Hud_GetChild( file.menu, "BtnModListUpArrow"), UIE_CLICK, OnUpArrowSelected )
AddButtonEventHandler( Hud_GetChild( file.menu, "BtnModListDownArrow"), UIE_CLICK, OnDownArrowSelected )
AddButtonEventHandler( Hud_GetChild( file.menu, "BtnFiltersClear"), UIE_CLICK, OnBtnFiltersClear_Activate )
// Nuke weird rui on filter switch
RuiSetString( Hud_GetRui( Hud_GetChild( file.menu, "SwtBtnShowFilter")), "buttonText", "")
}
void function OnModMenuOpened()
{
file.shouldReloadModsOnEnd = false
file.scrollOffset = 0
RegisterButtonPressedCallback(MOUSE_WHEEL_UP , OnScrollUp)
RegisterButtonPressedCallback(MOUSE_WHEEL_DOWN , OnScrollDown)
Hud_SetText( Hud_GetChild( file.menu, "Title" ), "#MENU_TITLE_MODS" )
OnFiltersChange(0)
}
void function OnModMenuClosed()
{
try
{
DeregisterButtonPressedCallback(MOUSE_WHEEL_UP , OnScrollUp)
DeregisterButtonPressedCallback(MOUSE_WHEEL_DOWN , OnScrollDown)
}
catch ( ex ) {}
if ( file.shouldReloadModsOnEnd )
ReloadMods()
}
void function OnFiltersChange( var n )
{
file.scrollOffset = 0
HideAllButtons()
RefreshModsArray()
UpdateList()
UpdateListSliderHeight()
}
void function RefreshModsArray()
{
string searchTerm = Hud_GetUTF8Text( Hud_GetChild( file.menu, "BtnModsSearch" ) ).tolower()
file.modsArrayFiltered.clear()
bool useSearch = searchTerm != ""
array<string> modNames = NSGetModNames()
int modCount = modNames.len()
foreach ( int index_, mod in modNames ) {
modStruct tempMod
tempMod.modIndex = index_
tempMod.modName = mod
int filter = GetConVarInt( "filter_mods" )
bool enabled = NSIsModEnabled( tempMod.modName )
bool containsTerm = tempMod.modName.tolower().find(searchTerm) != null
if ( filter == filterShow.ALL && (useSearch == true ? containsTerm : true ) )
{
file.modsArrayFiltered.append( tempMod )
}
else if ( filter == filterShow.ONLY_ENABLED && enabled && (useSearch == true ? containsTerm : true ))
{
file.modsArrayFiltered.append( tempMod )
}
else if ( filter == filterShow.ONLY_DISABLED && !enabled && (useSearch == true ? containsTerm : true ))
{
file.modsArrayFiltered.append( tempMod )
}
}
}
void function HideAllButtons()
{
array<var> buttons = GetElementsByClassname( file.menu, "ModButton" )
// disable all buttons, we'll enable the ones we need later
foreach ( var button in buttons )
{
Hud_SetEnabled( button, false )
Hud_SetVisible( button, false )
}
}
void function UpdateList()
{
array<var> buttons = GetElementsByClassname( file.menu, "ModButton" )
int j = file.modsArrayFiltered.len() > 17 ? 17 : file.modsArrayFiltered.len()
for ( int i = 0; i < j; i++ )
{
Hud_SetEnabled( buttons[ i ], true )
Hud_SetVisible( buttons[ i ], true )
SetModMenuNameText( buttons[ i ] )
}
}
void function SetModMenuNameText( var button )
{
modStruct mod = file.modsArrayFiltered[ int ( Hud_GetScriptID( button ) ) + file.scrollOffset ]
// should be localisation at some point
if ( NSIsModEnabled( mod.modName ) )
SetButtonRuiText( button, mod.modName + " v" + NSGetModVersionByModName( mod.modName ) )
else
SetButtonRuiText( button, mod.modName + " (DISABLED)" )
}
void function OnModMenuButtonPressed( var button )
{
string modName = file.modsArrayFiltered[ int ( Hud_GetScriptID( button ) ) + file.scrollOffset ].modName
if ( ( modName == "Northstar.Client" || modName == "Northstar.Coop" || modName == "Northstar.CustomServers") && NSIsModEnabled( modName ) )
{
file.currentMod = modName
file.currentButton = button
CoreModToggleDialog( modName )
}
else
{
NSSetModEnabled( modName, !NSIsModEnabled( modName ) )
SetModMenuNameText( button )
file.shouldReloadModsOnEnd = true
}
}
void function CoreModToggleDialog( string mod )
{
DialogData dialogData
dialogData.header = "#WARNING"
dialogData.message = "#CORE_MOD_DISABLE_WARNING"
AddDialogButton( dialogData, "#CANCEL" )
// This can't have any arguments so we use the file struct
AddDialogButton( dialogData, "#DISABLE", DisableMod )
AddDialogFooter( dialogData, "#A_BUTTON_SELECT" )
AddDialogFooter( dialogData, "#B_BUTTON_CANCEL" )
OpenDialog( dialogData )
}
void function DisableMod()
{
NSSetModEnabled( file.currentMod, false )
SetModMenuNameText( file.currentButton )
file.shouldReloadModsOnEnd = true
}
void function OnModMenuButtonFocused( var button )
{
string modName = file.modsArrayFiltered[ int ( Hud_GetScriptID( button ) ) + file.scrollOffset ].modName
var rui = Hud_GetRui( Hud_GetChild( file.menu, "LabelDetails" ) )
RuiSetGameTime( rui, "startTime", -99999.99 ) // make sure it skips the whole animation for showing this
RuiSetString( rui, "headerText", modName )
RuiSetString( rui, "messageText", FormatModDescription( modName ) )
}
string function FormatModDescription( string modName )
{
string ret
// version
ret += format( "Version %s\n", NSGetModVersionByModName( modName ) )
// download link
string modLink = NSGetModDownloadLinkByModName( modName )
if ( modLink.len() != 0 )
ret += format( "Download link: \"%s\"\n", modLink )
// load priority
ret += format( "Load Priority: %i\n", NSGetModLoadPriority( modName ) )
// todo: add ClientRequired here
// convars
array<string> modCvars = NSGetModConvarsByModName( modName )
if ( modCvars.len() != 0 )
{
ret += "ConVars: "
for ( int i = 0; i < modCvars.len(); i++ )
{
if ( i != modCvars.len() - 1 )
ret += format( "\"%s\", ", modCvars[ i ] )
else
ret += format( "\"%s\"", modCvars[ i ] )
}
ret += "\n"
}
// description
ret += format( "\n%s\n", NSGetModDescriptionByModName( modName ) )
return ret
}
void function OnReloadModsButtonPressed( var button )
{
ReloadMods()
}
void function ReloadMods()
{
NSReloadMods()
ClientCommand( "reload_localization" )
ClientCommand( "loadPlaylists" )
bool svCheatsOriginal = GetConVarBool( "sv_cheats" )
SetConVarBool( "sv_cheats", true )
ClientCommand( "weapon_reparse" ) // weapon_reparse only works if a server is running and sv_cheats is 1, gotta figure this out eventually
SetConVarBool( "sv_cheats", svCheatsOriginal )
// note: the logic for this seems really odd, unsure why it doesn't seem to update, since the same code seems to get run irregardless of whether we've read weapon data before
ClientCommand( "uiscript_reset" )
}
void function OnAuthenticationAgreementButtonPressed( var button )
{
NorthstarMasterServerAuthDialog()
}
void function OnBtnFiltersClear_Activate( var button )
{
Hud_SetText( Hud_GetChild( file.menu, "BtnModsSearch" ), "" )
SetConVarInt( "filter_mods", 0 )
OnFiltersChange(0)
}
//////////////////////////////
// Slider
//////////////////////////////
void function UpdateMouseDeltaBuffer(int x, int y)
{
mouseDeltaBuffer.deltaX += x
mouseDeltaBuffer.deltaY += y
SliderBarUpdate()
}
void function FlushMouseDeltaBuffer()
{
mouseDeltaBuffer.deltaX = 0
mouseDeltaBuffer.deltaY = 0
}
void function SliderBarUpdate()
{
if ( file.modsArrayFiltered.len() <= 15 )
{
FlushMouseDeltaBuffer()
return
}
var sliderButton = Hud_GetChild( file.menu , "BtnModListSlider" )
var sliderPanel = Hud_GetChild( file.menu , "BtnModListSliderPanel" )
var movementCapture = Hud_GetChild( file.menu , "MouseMovementCapture" )
Hud_SetFocused(sliderButton)
float minYPos = -40.0 * (GetScreenSize()[1] / 1080.0)
float maxHeight = 604.0 * (GetScreenSize()[1] / 1080.0)
float maxYPos = minYPos - (maxHeight - Hud_GetHeight( sliderPanel ))
float useableSpace = (maxHeight - Hud_GetHeight( sliderPanel ))
float jump = minYPos - (useableSpace / ( float( file.modsArrayFiltered.len())))
// got local from official respaw scripts, without untyped throws an error
local pos = Hud_GetPos(sliderButton)[1]
local newPos = pos - mouseDeltaBuffer.deltaY
FlushMouseDeltaBuffer()
if ( newPos < maxYPos ) newPos = maxYPos
if ( newPos > minYPos ) newPos = minYPos
Hud_SetPos( sliderButton , 2, newPos )
Hud_SetPos( sliderPanel , 2, newPos )
Hud_SetPos( movementCapture , 2, newPos )
file.scrollOffset = -int( ( (newPos - minYPos) / useableSpace ) * ( file.modsArrayFiltered.len() - BUTTONS_PER_PAGE) )
UpdateList()
}
void function UpdateListSliderHeight()
{
var sliderButton = Hud_GetChild( file.menu , "BtnModListSlider" )
var sliderPanel = Hud_GetChild( file.menu , "BtnModListSliderPanel" )
var movementCapture = Hud_GetChild( file.menu , "MouseMovementCapture" )
float mods = float ( file.modsArrayFiltered.len() )
float maxHeight = 604.0 * (GetScreenSize()[1] / 1080.0)
float minHeight = 80.0 * (GetScreenSize()[1] / 1080.0)
float height = maxHeight * ( float( BUTTONS_PER_PAGE ) / mods )
if ( height > maxHeight ) height = maxHeight
if ( height < minHeight ) height = minHeight
Hud_SetHeight( sliderButton , height )
Hud_SetHeight( sliderPanel , height )
Hud_SetHeight( movementCapture , height )
}
void function UpdateListSliderPosition()
{
var sliderButton = Hud_GetChild( file.menu , "BtnModListSlider" )
var sliderPanel = Hud_GetChild( file.menu , "BtnModListSliderPanel" )
var movementCapture = Hud_GetChild( file.menu , "MouseMovementCapture" )
float mods = float ( file.modsArrayFiltered.len() )
float minYPos = -40.0 * (GetScreenSize()[1] / 1080.0)
float useableSpace = (604.0 * (GetScreenSize()[1] / 1080.0) - Hud_GetHeight( sliderPanel ))
float jump = minYPos - (useableSpace / ( mods - float( BUTTONS_PER_PAGE ) ) * file.scrollOffset)
//jump = jump * (GetScreenSize()[1] / 1080.0)
if ( jump > minYPos ) jump = minYPos
Hud_SetPos( sliderButton , 2, jump )
Hud_SetPos( sliderPanel , 2, jump )
Hud_SetPos( movementCapture , 2, jump )
}
void function OnDownArrowSelected( var button )
{
if ( file.modsArrayFiltered.len() <= BUTTONS_PER_PAGE ) return
file.scrollOffset += 1
if (file.scrollOffset + BUTTONS_PER_PAGE > file.modsArrayFiltered.len()) {
file.scrollOffset = file.modsArrayFiltered.len() - BUTTONS_PER_PAGE
}
UpdateList()
UpdateListSliderPosition()
}
void function OnUpArrowSelected( var button )
{
file.scrollOffset -= 1
if (file.scrollOffset < 0) {
file.scrollOffset = 0
}
UpdateList()
UpdateListSliderPosition()
}
void function OnScrollDown( var button )
{
if ( file.modsArrayFiltered.len() <= BUTTONS_PER_PAGE ) return
file.scrollOffset += 5
if (file.scrollOffset + BUTTONS_PER_PAGE > file.modsArrayFiltered.len()) {
file.scrollOffset = file.modsArrayFiltered.len() - BUTTONS_PER_PAGE
}
UpdateList()
UpdateListSliderPosition()
}
void function OnScrollUp( var button )
{
file.scrollOffset -= 5
if (file.scrollOffset < 0) {
file.scrollOffset = 0
}
UpdateList()
UpdateListSliderPosition()
}
|