forked from Squishy6094/character-select-coop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
2470 lines (2251 loc) · 108 KB
/
Copy pathmain.lua
File metadata and controls
2470 lines (2251 loc) · 108 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
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
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- name: Character Select
-- description:\\#ffff33\\-- Character Select Coop v1.16.2 --\n\n\\#dcdcdc\\A Library / API made to make adding and using Custom Characters as simple as possible!\nUse\\#ffff33\\ /char-select\\#dcdcdc\\ to get started!\n\nCreated by:\\#008800\\ Squishy6094\n\n\\#AAAAFF\\Updates can be found on\nCharacter Select's Github:\n\\#6666FF\\Squishy6094/character-select-coop
-- pausable: false
-- category: cs
if incompatibleClient then return 0 end
---@param hookEventType LuaHookedEventType
local function create_hook_wrapper(hookEventType)
local callbacks = {}
hook_event(hookEventType, function(...)
for _, func in pairs(callbacks) do
func(...)
end
end)
return function(func)
table.insert(callbacks, func)
end
end
cs_hook_mario_update = create_hook_wrapper(HOOK_MARIO_UPDATE)
menu = false
menuAndTransition = false
gridMenu = mod_storage_load_bool("PrefGridView")
options = nil; OPTIONS_MAIN = 0; OPTIONS_CREDITS = 1
prevOptions = nil; optionsTimer = 0
bootChar = CT_MARIO
if gMarioStates[0].character ~= nil then
bootChar = gMarioStates[0].character.type
end
currChar = bootChar
local prevChar = bootChar
currCharRender = bootChar
currCategory = 1
local currOption = 1
local currCredits = 1
local currCreditScroll = 0
local creditScrollMin = 8
local totalPlaytime = 0
local menuCrossFade = 7
local menuCrossFadeCap = menuCrossFade
local menuCrossFadeMath = 255 / menuCrossFade
local TYPE_FUNCTION = "function"
local TYPE_BOOLEAN = "boolean"
local TYPE_STRING = "string"
local TYPE_INTEGER = "number"
local TYPE_TABLE = "table"
local MENU_BINDS_DEFAULT = 1
local MENU_BINDS_GRID = 2
local MENU_BINDS_OPTIONS = 3
local MENU_BINDS_CREDITS = 4
local TEXT_TABLE_MENU_BINDS = {
[MENU_BINDS_DEFAULT] = {
{bind = "Up / Down", desc = "Change Character"},
{bind = "Left / Right", desc = "Change Costume"},
{bind = "A Button", desc = "Set Preferred Character"},
{bind = "B Button", desc = "Exit Menu"},
{bind = "X Button", desc = "Toggle Grid View"},
{bind = "Y Button", desc = "Toggle Palette"},
{bind = "L/R Triggers", desc = "Change Categories"},
{bind = "Start Button", desc = "Options Menu"},
},
[MENU_BINDS_GRID] = {
{bind = "Up / Down / Left / Right", desc = "Change Character"},
{bind = "A Button", desc = "Set Preferred Character"},
{bind = "B Button", desc = "Exit Menu"},
{bind = "X Button", desc = "Toggle List View"},
{bind = "Y Button", desc = "Toggle Palette"},
{bind = "L/R Triggers", desc = "Change Categories"},
{bind = "Start Button", desc = "Options Menu"},
},
[MENU_BINDS_OPTIONS] = {
{bind = "Up / Down", desc = "Scroll Options"},
{bind = "Left / Right", desc = "Toggle Option"},
{bind = "Start / B Button", desc = "Exit Options Menu"},
},
[MENU_BINDS_CREDITS] = {
{bind = "Up / Down", desc = "Scroll Credits"},
{bind = "Left / Right", desc = "Switch Page"},
{bind = "Start / B Button", desc = "Exit Credits Menu"},
},
}
local TEX_LOGO = get_texture_info("char_select_logo")
local TEX_WALL_LEFT = get_texture_info("char_select_wall_left")
local TEX_WALL_RIGHT = get_texture_info("char_select_wall_right")
TEX_GRAFFITI_DEFAULT = get_texture_info("char_select_graffiti_default")
local TEX_NAMEPLATE = get_texture_info("char_select_list_button")
local TEX_ALBUM_LAYER1 = get_texture_info("char_select_album_back")
local TEX_ALBUM_LAYER2 = get_texture_info("char_select_album_front")
local TEX_ALBUM_LAYER3 = get_texture_info("char_select_album_overlay")
local TEX_CD_LAYER1 = get_texture_info("char_select_cd_layer1")
local TEX_CD_LAYER2 = get_texture_info("char_select_cd_layer2")
local TEX_CD_LAYER3 = get_texture_info("char_select_cd_layer3")
local TEX_CD_LAYER4 = get_texture_info("char_select_cd_layer4")
local TEX_RECORD = get_texture_info("char_select_record")
local TEX_PALETTE_BUCKET = get_texture_info("char_select_palette_bucket")
local TEX_OPTIONS_TV = get_texture_info("char_select_options_tv")
local TEX_GEAR = get_texture_info("char_select_gear")
LOCKED_NEVER = 0
LOCKED_TRUE = 1
LOCKED_FALSE = 2
local SOUND_CHAR_SELECT_THEME = audio_stream_load("char_select_menu_theme.ogg")
local SOUND_CHAR_SELECT_DIAL = audio_stream_load("char_select_dial_wind.ogg")
local SOUND_CHAR_SELECT_TV_ON = audio_sample_load("char_select_tv_on.ogg")
local menuThemeTargetVolume = 0
local menuThemeVolume = menuThemeTargetVolume
audio_stream_set_looping(SOUND_CHAR_SELECT_THEME, true)
audio_stream_set_loop_points(SOUND_CHAR_SELECT_THEME, 0, 93.659*22050)
CS_ANIM_MENU = CHAR_ANIM_MAX + 1
local TEXT_PREF_LOAD_NAME = "Default"
local TEXT_PREF_LOAD_ALT = 1
--[[
Note: Do NOT add characters via the characterTable below,
We highly recommend you create your own mod and use the
API to add characters, this ensures your pack is easy
to use for anyone and low on file space!
]]
characterTable = {
[CT_MARIO] = {
saveName = "Mario_CoopDX",
nickname = "Mario",
category = "All_CoopDX",
ogNum = CT_MARIO,
currAlt = 1,
hasMoveset = false,
locked = LOCKED_NEVER,
playtime = 0,
autoDialog = true,
replaceModels = {},
replaceTextures = {},
[1] = {
name = "Mario",
description = "The iconic Italian plumber himself! He's quite confident and brave, always prepared to jump into action to save the Mushroom Kingdom!",
credit = "Nintendo/CoopDX",
color = { r = 255, g = 50, b = 50 },
model = E_MODEL_MARIO,
ogModel = E_MODEL_MARIO,
baseChar = CT_MARIO,
lifeIcon = gTextures.mario_head,
starIcon = gTextures.star,
camScale = 1.0,
healthMeter = {
label = {
left = get_texture_info("texture_power_meter_left_side"),
right = get_texture_info("texture_power_meter_right_side"),
},
pie = {
[1] = get_texture_info("texture_power_meter_one_segments"),
[2] = get_texture_info("texture_power_meter_two_segments"),
[3] = get_texture_info("texture_power_meter_three_segments"),
[4] = get_texture_info("texture_power_meter_four_segments"),
[5] = get_texture_info("texture_power_meter_five_segments"),
[6] = get_texture_info("texture_power_meter_six_segments"),
[7] = get_texture_info("texture_power_meter_seven_segments"),
[8] = get_texture_info("texture_power_meter_full"),
}
}
},
},
[CT_LUIGI] = {
saveName = "Luigi_CoopDX",
nickname = "Luigi",
category = "All_CoopDX",
ogNum = CT_LUIGI,
currAlt = 1,
hasMoveset = false,
locked = LOCKED_NEVER,
playtime = 0,
autoDialog = true,
replaceModels = {},
replaceTextures = {},
[1] = {
name = "Luigi",
description = "The other iconic Italian plumber! He's a bit shy and scares easily, but he's willing to follow his brother Mario through any battle that may come their way!",
credit = "Nintendo/CoopDX",
color = { r = 50, g = 255, b = 50 },
model = E_MODEL_LUIGI,
ogModel = E_MODEL_LUIGI,
baseChar = CT_LUIGI,
lifeIcon = gTextures.luigi_head,
starIcon = gTextures.star,
camScale = 1.0,
healthMeter = {
label = {
left = get_texture_info("char_select_luigi_meter_left"),
right = get_texture_info("char_select_luigi_meter_right"),
},
pie = defaultMeterInfo.pie
}
},
},
[CT_TOAD] = {
saveName = "Toad_CoopDX",
nickname = "Toad",
category = "All_CoopDX",
ogNum = CT_TOAD,
currAlt = 1,
hasMoveset = false,
locked = LOCKED_NEVER,
playtime = 0,
autoDialog = true,
replaceModels = {},
replaceTextures = {},
[1] = {
name = "Toad",
description = "Princess Peach's little attendant! He's an energetic little mushroom that's never afraid to follow Mario and Luigi on their adventures!",
credit = "Nintendo/CoopDX",
color = { r = 50, g = 50, b = 255 },
model = E_MODEL_TOAD_PLAYER,
ogModel = E_MODEL_TOAD_PLAYER,
baseChar = CT_TOAD,
lifeIcon = gTextures.toad_head,
starIcon = gTextures.star,
camScale = 0.8,
healthMeter = {
label = {
left = get_texture_info("char_select_toad_meter_left"),
right = get_texture_info("char_select_toad_meter_right"),
},
pie = defaultMeterInfo.pie
}
},
},
[CT_WALUIGI] = {
saveName = "Waluigi_CoopDX",
nickname = "Waluigi",
category = "All_CoopDX",
ogNum = CT_WALUIGI,
currAlt = 1,
hasMoveset = false,
locked = LOCKED_NEVER,
playtime = 0,
autoDialog = true,
replaceModels = {},
replaceTextures = {},
[1] = {
name = "Waluigi",
description = "The mischievous rival of Luigi! He's a narcissistic competitor that takes great taste in others getting pummeled from his success!",
credit = "Nintendo/CoopDX",
color = { r = 130, g = 25, b = 130 },
model = E_MODEL_WALUIGI,
ogModel = E_MODEL_WALUIGI,
baseChar = CT_WALUIGI,
lifeIcon = gTextures.waluigi_head,
starIcon = gTextures.star,
camScale = 1.1,
healthMeter = {
label = {
left = get_texture_info("char_select_waluigi_meter_left"),
right = get_texture_info("char_select_waluigi_meter_right"),
},
pie = defaultMeterInfo.pie
}
},
},
[CT_WARIO] = {
saveName = "Wario_CoopDX",
nickname = "Wario",
category = "All_CoopDX",
ogNum = CT_WARIO,
currAlt = 1,
hasMoveset = false,
locked = LOCKED_NEVER,
playtime = 0,
autoDialog = true,
replaceModels = {},
replaceTextures = {},
[1] = {
name = "Wario",
description = "The mischievous rival of Mario! He's a greed-filled treasure hunter obsessed with money and gold coins. He's always ready for a brawl if his money is on the line!",
credit = "Nintendo/CoopDX",
color = { r = 255, g = 255, b = 50 },
model = E_MODEL_WARIO,
ogModel = E_MODEL_WARIO,
baseChar = CT_WARIO,
lifeIcon = gTextures.wario_head,
starIcon = gTextures.star,
camScale = 1.1,
healthMeter = {
label = {
left = get_texture_info("char_select_wario_meter_left"),
right = get_texture_info("char_select_wario_meter_right"),
},
pie = defaultMeterInfo.pie
}
},
},
}
function character_is_vanilla(charNum)
if charNum == nil then charNum = currChar end
return charNum < CT_MAX
end
characterCategories = {
{name = "All", icon1 = CT_MARIO, icon2 = CT_LUIGI},
{name = "CoopDX", icon1 = CT_WARIO, icon2 = CT_WALUIGI},
}
local characterTableRender = {}
characterCaps = {}
characterColorPresets = {}
characterAnims = {
[E_MODEL_MARIO] = {
anims = {[CS_ANIM_MENU] = MARIO_ANIM_CS_MENU},
eyes = {[CS_ANIM_MENU] = MARIO_EYES_LOOK_RIGHT},
},
[E_MODEL_LUIGI] = {
anims = {[CS_ANIM_MENU] = LUIGI_ANIM_CS_MENU},
eyes = {[CS_ANIM_MENU] = MARIO_EYES_LOOK_RIGHT},
hands = {[CS_ANIM_MENU] = MARIO_HAND_OPEN}
},
[E_MODEL_TOAD_PLAYER] = {
anims = {[CS_ANIM_MENU] = TOAD_PLAYER_ANIM_CS_MENU},
hands = {[CS_ANIM_MENU] = MARIO_HAND_OPEN}
},
[E_MODEL_WALUIGI] = {
anims = {[CS_ANIM_MENU] = WALUIGI_ANIM_CS_MENU},
eyes = {[CS_ANIM_MENU] = MARIO_EYES_LOOK_RIGHT},
},
[E_MODEL_WARIO] = {
anims = {[CS_ANIM_MENU] = WARIO_ANIM_CS_MENU},
eyes = {[CS_ANIM_MENU] = MARIO_EYES_LOOK_LEFT},
},
}
characterMovesets = {
[CT_MARIO] = {},
[CT_LUIGI] = {},
[CT_TOAD] = {},
[CT_WALUIGI] = {},
[CT_WARIO] = {},
}
characterUnlock = {}
characterInstrumentals = {}
characterGraffiti = {
[CT_MARIO] = get_texture_info("char_select_graffiti_mario"),
[CT_LUIGI] = get_texture_info("char_select_graffiti_luigi"),
[CT_TOAD] = get_texture_info("char_select_graffiti_toad"),
[CT_WALUIGI] = get_texture_info("char_select_graffiti_waluigi"),
[CT_WARIO] = get_texture_info("char_select_graffiti_wario"),
}
characterDialog = {}
texturesModified = {}
tableRefNum = 0
local function make_table_ref_num()
tableRefNum = tableRefNum + 1
return tableRefNum
end
OPTION_MENU = "Menu"
OPTION_CHAR = "Character"
OPTION_MISC = "Misc"
OPTION_MOD = "Host"
OPTION_API = "Packs"
optionTableRef = {
-- Menu
openInputs = make_table_ref_num(),
notification = make_table_ref_num(),
menuColor = make_table_ref_num(),
music = make_table_ref_num(),
inputLatency = make_table_ref_num(),
-- Characters
localMoveset = make_table_ref_num(),
localVoices = make_table_ref_num(),
localVisuals = make_table_ref_num(),
-- Moderation
--restrictPalettes = make_table_ref_num(),
restrictMovesets = make_table_ref_num(),
-- Misc
resetSaveData = make_table_ref_num(),
credits = make_table_ref_num(),
}
optionTable = {
[optionTableRef.openInputs] = {
name = "Menu Bind",
category = OPTION_MENU,
toggle = tonumber(mod_storage_load("MenuInput")),
toggleSaveName = "MenuInput",
toggleDefault = 1,
toggleMax = 2,
toggleNames = {"None", "Z (Pause Menu)", ommActive and "D-pad Down + R" or "D-pad Down"},
description = {"Sets a Bind to Open the Menu", "rather than using the command."}
},
[optionTableRef.notification] = {
name = "Notifications",
category = OPTION_MENU,
toggle = tonumber(mod_storage_load("notifs")),
toggleSaveName = "notifs",
toggleDefault = 1,
toggleMax = 2,
toggleNames = {"Off", "On", "Pop-ups Only"},
description = {"Toggles whether Pop-ups and", "Chat Messages display."}
},
[optionTableRef.menuColor] = {
name = "Menu Color",
category = OPTION_MENU,
toggle = tonumber(mod_storage_load("MenuColor")),
toggleSaveName = "MenuColor",
toggleDefault = 0,
toggleMax = 10,
toggleNames = {"Auto", "Saved", "Red", "Orange", "Yellow", "Green", "Blue", "Pink", "Purple", "White", "Black"},
description = {"Toggles the Menu Color"}
},
[optionTableRef.music] = {
name = "Menu Music",
category = OPTION_MENU,
toggle = tonumber(mod_storage_load("Music")),
toggleSaveName = "Music",
toggleDefault = 1,
toggleMax = 3,
toggleNames = {"Off", "On", "Breakroom Only", "Character Only"},
description = {"Toggles which music plays", "in the menu."}
},
[optionTableRef.inputLatency] = {
name = "Menu Scroll Speed",
category = OPTION_MENU,
toggle = tonumber(mod_storage_load("Latency")),
toggleSaveName = "Latency",
toggleDefault = 1,
toggleMax = 2,
toggleNames = {"Slow", "Normal", "Fast"},
description = {"Sets how fast you scroll", "throughout the Menu"}
},
[optionTableRef.localVoices] = {
name = "Character Voices",
category = OPTION_CHAR,
toggle = tonumber(mod_storage_load("localVoices")),
toggleSaveName = "localVoices",
toggleDefault = 1,
toggleMax = 2,
toggleNames = {"Off", "On", "Local Only"},
description = {"Toggle if Custom Voicelines play", "for Characters who support it"}
},
[optionTableRef.localVisuals] = {
name = "Character Visuals",
category = OPTION_CHAR,
toggle = tonumber(mod_storage_load("localVisuals")),
toggleSaveName = "localVisuals",
toggleDefault = 1,
toggleMax = 1,
description = {"Toggle if Characters can", "change the apperence of", "Objects and Textures"}
},
[optionTableRef.localMoveset] = {
name = "Character Moveset",
category = OPTION_CHAR,
toggle = tonumber(mod_storage_load("localMoveset")),
toggleSaveName = "localMoveset",
toggleDefault = 1,
toggleMax = 1,
description = {"Toggles if Custom Movesets", "are active on compatible", "characters"},
lock = function ()
if gGlobalSyncTable.charSelectRestrictMovesets ~= 0 then
return "Forced Off"
end
end,
},
[optionTableRef.restrictMovesets] = {
name = "Restrict Movesets",
category = OPTION_MOD,
toggle = 0,
toggleDefault = 0,
toggleMax = 1,
description = {"Restricts turning on movesets", "(Host Only)"},
lock = function ()
if gGlobalSyncTable.charSelectRestrictMovesets < 2 then
if not network_is_server() then
return "Host Only"
end
else
return "API Only"
end
end,
},
[optionTableRef.resetSaveData] = {
name = "Reset Save Data",
category = OPTION_MISC,
toggle = 0,
toggleDefault = 0,
toggleMax = 1,
toggleNames = {"Reset Save Data", "Reset Save Data"},
description = {"Resets Character Select's", "Save Data"}
},
[optionTableRef.credits] = {
name = "Credits",
category = OPTION_MISC,
toggle = 0,
toggleDefault = 0,
toggleMax = 1,
toggleNames = {"Open Credits", "Open Credits"},
description = {"Thank you for choosing", "Character Select!"}
},
}
local gridYOffset = 0
local function update_character_render_table()
gridYOffset = -100
local ogNum = currChar
local insertNum = 0
currChar = 0
currCharRender = 0
local category = characterCategories[currCategory]
if category == nil then return false end
characterTableRender = {}
for i = 0, #characterTable do
local charCategories = string_split(characterTable[i].category, "_")
if characterTable[i].locked ~= LOCKED_TRUE then
for c = 1, #charCategories do
if category.name == charCategories[c] then
characterTableRender[insertNum] = characterTable[i]
characterTableRender[insertNum].UIOffset = 0
if ogNum == i then
currChar = ogNum
currCharRender = math.clamp(insertNum, 0, #characterTableRender)
end
insertNum = insertNum + 1
end
end
end
end
if #characterTableRender > 0 then
-- Get icons for category based on name similarity
if category.icon1 == nil or category.icon2 == nil then
local sorted = {}
for i = 0, #characterTableRender do
local char = characterTableRender[i]
table.insert(sorted, {ogNum = char.ogNum, sim = string_sim(char.saveName, category.name)})
end
table.sort(sorted, function(a, b)
log_to_console_once(tostring(a.ogNum) .. " - " .. tostring(a.sim), CONSOLE_MESSAGE_INFO)
log_to_console_once(tostring(b.ogNum) .. " - " .. tostring(b.sim), CONSOLE_MESSAGE_INFO)
return a.sim < b.sim
end)
category.icon1 = category.icon1 or sorted[1].ogNum
category.icon2 = category.icon2 or sorted[2].ogNum
end
-- Set Character if they are in the category
currChar = (characterTableRender[currCharRender] and characterTableRender[currCharRender].ogNum or characterTableRender[0].ogNum)
return true
else
return false
end
end
hookTableOnCharacterChange = {
[1] = function (prevChar, currChar)
local m = gMarioStates[0]
-- Switch all models to either Vanilla or the Character's
set_all_visuals(currChar)
-- Reset anim to ensure Custom Anims don't leak
m.marioObj.header.gfx.animInfo.animID = -1
-- Check for Non-Vanilla Actions when switching Characters
if is_mario_in_vanilla_action(m) or m.health < 256 then return end
if m.action & ACT_FLAG_RIDING_SHELL ~= 0 then
set_mario_action(m, ACT_RIDING_SHELL_FALL, 0)
elseif m.action & ACT_FLAG_ALLOW_FIRST_PERSON ~= 0 then
set_mario_action(m, ACT_IDLE, 0)
elseif m.action & ACT_GROUP_MOVING ~= 0 or m.action & ACT_FLAG_MOVING ~= 0 then
set_mario_action(m, ACT_WALKING, 0)
elseif m.action & ACT_GROUP_SUBMERGED ~= 0 or m.action & ACT_FLAG_SWIMMING ~= 0 then
-- Need to fix upwarping
set_mario_action(m, ACT_WATER_IDLE, 0)
else
set_mario_action(m, ACT_FREEFALL, 0)
end
end
}
local function on_character_change(prevChar, currChar)
for i = 1, #hookTableOnCharacterChange do
hookTableOnCharacterChange[i](prevChar, currChar)
end
end
function force_set_character(charNum, charAlt)
if not charNum then charNum = gNetworkPlayers[0].modelIndex end
if not charAlt then charAlt = 1 end
currCategory = 1
prevChar = currChar
currChar = charNum
characterTable[currChar].currAlt = charAlt
currCharRender = charNum
charBeingSet = true
update_character_render_table()
end
---@description A function that gets an option's status from the Character Select Options Menu
---@param tableNum integer The table position of the option
---@return number?
function get_options_status(tableNum)
if type(tableNum) ~= TYPE_INTEGER then return 1 end
return (optionTable[tableNum] and optionTable[tableNum].toggle or 1)
end
---@class Credits
---@field packName string
---@class Credit
---@field creditee string
---@field credit string
---@type Credits[]
creditTable = {
[1] = {
packName = "Character Select Coop",
{ creditee = "Squishy6094", credit = "Creator" },
{ creditee = "Trashcam", credit = "Menu Music" },
{ creditee = "Charity", credit = "Sound Design" },
{ creditee = "JerThePear", credit = "Menu Assets/Anims" },
{ creditee = "Shell_x33", credit = "Menu Assets" },
{ creditee = "WinbowBreaker", credit = "Rendered Menu Assets" },
{ creditee = "xLuigiGamerx", credit = "HUD Accuracy" },
{ creditee = "Wibblus", credit = "Menu Anims Code" },
}
}
if CREDIT_SUPPORTERS ~= nil then
creditTable[0] = {
packName = "Character Select Supporters",
}
for i = 1, #CREDIT_SUPPORTERS do
table.insert(creditTable[0], { creditee = CREDIT_SUPPORTERS[i]})
end
end
local latencyValueTable = {12, 6, 3}
local menuColorTable = {
{ r = 255, g = 50, b = 50 },
{ r = 255, g = 100, b = 50 },
{ r = 255, g = 255, b = 50 },
{ r = 50, g = 255, b = 50 },
{ r = 50, g = 50, b = 255 },
{ r = 251, g = 148, b = 220 },
{ r = 130, g = 25, b = 130 },
{ r = 255, g = 255, b = 255 },
{ r = 50, g = 50, b = 50 }
}
---@param m MarioState
local function nullify_inputs(m)
local c = m.controller
_G.charSelect.controller = {
buttonDown = c.buttonDown,
buttonPressed = c.buttonPressed & ~_G.charSelect.controller.buttonDown,
extStickX = c.extStickX,
extStickY = c.extStickY,
rawStickX = c.rawStickX,
rawStickY = c.rawStickY,
stickMag = c.stickMag,
stickX = c.stickX,
stickY = c.stickY
}
c.buttonDown = 0
c.buttonPressed = 0
c.extStickX = 0
c.extStickY = 0
c.rawStickX = 0
c.rawStickY = 0
c.stickMag = 0
c.stickX = 0
c.stickY = 0
end
local prefCharColor = {r = 255, g = 50, b = 50}
local function load_preferred_char()
local m = gMarioStates[0]
local savedChar = mod_storage_load("PrefChar")
local savedNick = mod_storage_load("PrefNick")
local savedAlt = tonumber(mod_storage_load("PrefAlt"))
local savedPalette = tonumber(mod_storage_load("PrefPalette"))
if savedChar == nil or savedChar == "" then
mod_storage_save("PrefChar", characterTable[bootChar].saveName)
savedChar = characterTable[bootChar].saveName
end
if savedAlt == nil then
mod_storage_save("PrefAlt", "1")
savedAlt = 1
end
if savedPalette == nil then
local paletteSave = 0
mod_storage_save("PrefAlt", tostring(paletteSave))
savedPalette = paletteSave
end
-- Find Saved Character
local charFound = false
for i = 0, #characterTable do
local char = characterTable[i]
if char.saveName == savedChar and char.locked ~= LOCKED_TRUE then
currChar = i
currCharRender = i
charFound = true
if optionTable[optionTableRef.notification].toggle > 0 then
djui_popup_create('Character Select:\nYour Preferred Character\n"' .. string_underscore_to_space(char[char.currAlt].name) .. '"\nwas applied successfully!', 4)
end
break
end
end
-- Set Alt
savedAlt = math.clamp(savedAlt, 1, #characterTable[currChar])
characterTable[currChar].currAlt = savedAlt
-- Set Palette
local model = characterTable[currChar][savedAlt].model
if characterColorPresets[model] ~= nil then
gCSPlayers[0].presetPalette = charFound and savedPalette or 0
characterColorPresets[model].currPalette = gCSPlayers[0].presetPalette
end
local savedCharColors = mod_storage_load("PrefCharColor")
if savedCharColors ~= nil and savedCharColors ~= "" then
local savedCharColorsTable = string_split(savedCharColors, "_")
prefCharColor = {
r = tonumber(savedCharColorsTable[1]),
g = tonumber(savedCharColorsTable[2]),
b = tonumber(savedCharColorsTable[3])
}
else
mod_storage_save("PrefCharColor", "255_50_50")
end
if #characterTable < CT_MAX then
if optionTable[optionTableRef.notification].toggle > 0 then
djui_popup_create("Character Select:\nNo Characters were Found", 2)
end
else
if not charFound then
if savedNick ~= nil then
djui_popup_create('Character Select:\nYour Preferred Character\n"' .. string_underscore_to_space(savedNick) .. '"\nwas not found.', 4)
else
djui_popup_create('Character Select:\nYour Preferred Character\nwas not found.', 3)
end
end
end
TEXT_PREF_LOAD_NAME = string_space_to_underscore(savedNick or savedChar)
TEXT_PREF_LOAD_ALT = savedAlt
update_character_render_table()
end
local function mod_storage_save_pref_char(charTable)
charTable = charTable or characterTable[bootChar]
mod_storage_save("PrefChar", charTable.saveName)
mod_storage_save("PrefNick", string_space_to_underscore(charTable.nickname))
mod_storage_save("PrefAlt", tostring(charTable.currAlt))
mod_storage_save("PrefPalette", tostring(gCSPlayers[0].presetPalette))
mod_storage_save("PrefCharColor", tostring(charTable[charTable.currAlt].color.r) .. "_" .. tostring(charTable[charTable.currAlt].color.g) .. "_" .. tostring(charTable[charTable.currAlt].color.b))
TEXT_PREF_LOAD_NAME = string_space_to_underscore(charTable.nickname)
TEXT_PREF_LOAD_ALT = charTable.currAlt
prefCharColor = charTable[charTable.currAlt].color
end
function failsafe_options()
for i = 1, #optionTable do
if optionTable[i].toggle == nil or optionTable[i].toggle == "" then
local load = optionTable[i].toggleSaveName and mod_storage_load(optionTable[i].toggleSaveName) or nil
if load == "" then
load = nil
end
optionTable[i].toggle = load and tonumber(load) or optionTable[i].toggleDefault
end
if optionTable[i].toggleNames == nil then
optionTable[i].toggleNames = {"Off", "On"}
end
end
if optionTable[optionTableRef.openInputs].toggle == 2 and ommActive then
djui_popup_create('Character Select:\nYour Open bind has changed to:\nD-pad Down + R\nDue to OMM Rebirth being active!', 4)
end
end
hookTableOnReset = {}
local promptedAreYouSure = false
local function reset_options(wasChatTriggered)
if not promptedAreYouSure then
djui_chat_message_create("\\#ffdcdc\\Are you sure you want to reset your Save Data for Character Select, including your Preferred Character\nand Settings?\n" .. (wasChatTriggered and "Type \\#ff3333\\/char-select reset\\#ffdcdc\\ to confirm." or "Press the \\#ff3333\\" .. optionTable[optionTableRef.resetSaveData].name .. "\\#ffdcdc\\ Option again to confirm." ))
promptedAreYouSure = true
else
for i = 1, #optionTable do
optionTable[i].toggle = optionTable[i].toggleDefault
if optionTable[i].toggleSaveName ~= nil then
mod_storage_save(optionTable[i].toggleSaveName, tostring(optionTable[i].toggle))
end
if optionTable[i].toggleNames == nil then
optionTable[i].toggleNames = { "Off", "On" }
end
end
for i = 0, #characterTable do
characterTable[i].currAlt = 1
characterTable[i].locked = characterTable[i].locked == LOCKED_NEVER and LOCKED_NEVER or LOCKED_TRUE
end
mod_storage_save_pref_char()
if #hookTableOnReset > 0 then
for i = 1, #hookTableOnReset do
hookTableOnReset[i]()
end
end
force_set_character()
djui_chat_message_create("\\#ff3333\\Character Select Save Data Reset!")
djui_chat_message_create("Note: If your issue has not been resolved, you may need to manually delete your save data via the directory below:\n\\#dcdcFF\\%appdata%/sm64coopdx/sav/character-select-coop.sav")
promptedAreYouSure = false
end
end
local function boot_note()
local charCount = (#characterTable + 1) - CT_MAX
if charCount > 0 then
djui_chat_message_create("Character Select has " .. charCount .. " character" .. (charCount > 1 and "s" or "") .." available!\nYou can use \\#ffff33\\/char-select \\#ffffff\\to open the menu!")
if charCount > 32 and network_is_server() then
djui_chat_message_create("\\#FFAAAA\\Warning: Having a lot of characters\nmay be unstable, For a better experience please\ndisable a few packs!")
end
else
djui_chat_message_create("Character Select is active!\nYou can use \\#ffff33\\/char-select \\#ffffff\\to open the menu!")
end
end
local function menu_is_allowed(m)
if m == nil then m = gMarioStates[0] end
-- API Check
for _, func in pairs(allowMenu) do
if not func() then
return false
end
end
-- C-up Failsafe (Camera Softlocks)
if m.action == ACT_FIRST_PERSON or (m.prevAction == ACT_FIRST_PERSON and is_game_paused()) then
return false
elseif m.prevAction == ACT_FIRST_PERSON and not is_game_paused() then
m.prevAction = ACT_WALKING
end
-- Cutscene Check
if m.action & ACT_GROUP_CUTSCENE ~= 0 then return false end
if gNetworkPlayers[0].currActNum == 99 then return false end
if m.action == ACT_INTRO_CUTSCENE then return false end
if obj_get_first_with_behavior_id(id_bhvActSelector) ~= nil then return false end
return true
end
-------------------
-- Model Handler --
-------------------
-- Port of SM64's idle action without transistion bs
local ACT_CS_MENU_IDLE = allocate_mario_action(ACT_FLAG_STATIONARY | ACT_FLAG_IDLE | ACT_FLAG_ALLOW_FIRST_PERSON | ACT_FLAG_PAUSE_EXIT)
---@param m MarioState
local function act_cs_menu_idle(m)
if not m then return 0 end
local p = gCSPlayers[m.playerIndex]
if (m.quicksandDepth > 30.0) then
return set_mario_action(m, ACT_IN_QUICKSAND, 0);
end
if (check_common_idle_cancels(m) ~= 0) then
return 1;
end
m.actionState = 0
m.actionTimer = 0
local customIdleExists = (characterAnims[p.modelId] and characterAnims[p.modelId].anims and characterAnims[p.modelId].anims[CS_ANIM_MENU])
set_character_animation(m, customIdleExists and CS_ANIM_MENU or CHAR_ANIM_FIRST_PERSON)
stationary_ground_step(m);
return 0
end
hook_mario_action(ACT_CS_MENU_IDLE, act_cs_menu_idle)
CUTSCENE_CS_MENU = 0xFA
local prevBaseCharFrame = gNetworkPlayers[0].modelIndex
local prevBasePalette = {
[PANTS] = network_player_get_palette_color(gNetworkPlayers[0], PANTS),
[SHIRT] = network_player_get_palette_color(gNetworkPlayers[0], SHIRT),
[GLOVES] = network_player_get_palette_color(gNetworkPlayers[0], GLOVES),
[SHOES] = network_player_get_palette_color(gNetworkPlayers[0], SHOES),
[HAIR] = network_player_get_palette_color(gNetworkPlayers[0], HAIR),
[SKIN] = network_player_get_palette_color(gNetworkPlayers[0], SKIN),
[CAP] = network_player_get_palette_color(gNetworkPlayers[0], CAP),
[EMBLEM] = network_player_get_palette_color(gNetworkPlayers[0], EMBLEM),
}
local worldColor = {
lighting = {r = 255, g = 255, b = 255},
skybox = {r = 255, g = 255, b = 255},
fog = {r = 255, g = 255, b = 255},
vertex = {r = 255, g = 255, b = 255},
ambient = {r = 255, g = 255, b = 255}
}
local menuOffsetX = 0
local menuOffsetY = 0
local camScale = 1
local prevMusicToggle = 1
local prevVisualToggle = 1
---@param m MarioState
local function mario_update(m)
if m.playerIndex == 0 and (startup_init_stall(1) or queueStorageFailsafe) then
failsafe_options()
if not queueStorageFailsafe then
load_preferred_char()
if optionTable[optionTableRef.notification].toggle == 1 then
boot_note()
end
end
queueStorageFailsafe = false
end
local np = gNetworkPlayers[m.playerIndex]
local p = gCSPlayers[m.playerIndex]
if m.playerIndex == 0 then
-- Used for Viewport stuffs
m.marioObj.header.gfx.sharedChild.hookProcess = 1
-- Check for Locked Chars
for i = CT_MAX, #characterTable do
local char = characterTable[i]
if char.locked ~= LOCKED_NEVER then
local unlock = characterUnlock[i].check
local notif = characterUnlock[i].notif
local prevLockState = char.locked
if type(unlock) == TYPE_FUNCTION then
char.locked = (unlock() ~= false) and LOCKED_FALSE or LOCKED_TRUE
elseif type(unlock) == TYPE_BOOLEAN then
char.locked = (unlock ~= false) and LOCKED_FALSE or LOCKED_TRUE
end
if char.locked ~= prevLockState then
update_character_render_table()
if prevLockState == LOCKED_TRUE then -- Character was unlocked
if startup_init_stall() and notif then
if optionTable[optionTableRef.notification].toggle > 0 then
djui_popup_create('Character Select:\nUnlocked '..tostring(char[1].name)..'\nas a Playable Character!', 3)
end
end
end
end
end
end
if djui_hud_is_pause_menu_created() then
if prevBaseCharFrame ~= np.modelIndex then
force_set_character(np.modelIndex)
p.presetPalette = 0
end
if gCSPlayers[0].presetPalette ~= 0 then
for i = PANTS, EMBLEM do
local prevColor = prevBasePalette[i]
local currColor = network_player_get_palette_color(np, i)
if prevColor.r ~= currColor.r or prevColor.g ~= currColor.g or prevColor.b ~= currColor.b then
local model = characterTable[currChar][characterTable[currChar].currAlt].model
gCSPlayers[0].presetPalette = 0
characterColorPresets[model].currPalette = 0
prevColor.r = currColor.r
prevColor.g = currColor.g
prevColor.b = currColor.b
end
end
end
end
prevBaseCharFrame = np.modelIndex
local charTable = characterTable[currChar]
p.saveName = charTable.saveName
p.currAlt = charTable.currAlt
p.modelId = charTable[charTable.currAlt].model
if charTable[charTable.currAlt].baseChar ~= nil then
p.baseChar = charTable[charTable.currAlt].baseChar
end
p.modelEditOffset = charTable[charTable.currAlt].model - charTable[charTable.currAlt].ogModel
m.marioObj.hookRender = 1
if menu and m.action == ACT_SLEEPING then