-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.lua
1819 lines (1678 loc) · 78.7 KB
/
main.lua
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.12 --\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
-- localize functions to improve performance - main.lua
local mod_storage_load,tonumber,mod_storage_save,djui_popup_create,tostring,djui_chat_message_create,is_game_paused,obj_get_first_with_behavior_id,djui_hud_is_pause_menu_created,camera_freeze,hud_hide,vec3f_copy,set_mario_action,set_mario_animation,camera_unfreeze,hud_show,type,get_id_from_behavior,obj_has_behavior_id,network_local_index_from_global,obj_has_model_extended,obj_set_model_extended,nearest_player_to_object,math_random,djui_hud_set_resolution,djui_hud_set_font,djui_hud_get_screen_width,maxf,djui_hud_set_color,djui_hud_render_rect,djui_hud_measure_text,djui_hud_print_text,min,math_min,math_ceil,math_abs,math_sin,minf,djui_hud_set_rotation,table_insert,djui_hud_print_text_interpolated,math_max,play_sound,play_character_sound,string_lower = mod_storage_load,tonumber,mod_storage_save,djui_popup_create,tostring,djui_chat_message_create,is_game_paused,obj_get_first_with_behavior_id,djui_hud_is_pause_menu_created,camera_freeze,hud_hide,vec3f_copy,set_mario_action,set_mario_animation,camera_unfreeze,hud_show,type,get_id_from_behavior,obj_has_behavior_id,network_local_index_from_global,obj_has_model_extended,obj_set_model_extended,nearest_player_to_object,math.random,djui_hud_set_resolution,djui_hud_set_font,djui_hud_get_screen_width,maxf,djui_hud_set_color,djui_hud_render_rect,djui_hud_measure_text,djui_hud_print_text,min,math.min,math.ceil,math.abs,math.sin,minf,djui_hud_set_rotation,table.insert,djui_hud_print_text_interpolated,math.max,play_sound,play_character_sound,string.lower
menu = false
menuAndTransition = false
options = false
local credits = false
local creditsAndTransition = false
currChar = 1
local currOption = 1
local creditScroll = 0
local prevCreditScroll = creditScroll
local creditScrollRange = 0
local menuCrossFade = 7
local menuCrossFadeCap = menuCrossFade
local menuCrossFadeMath = 255 / menuCrossFade
local creditsCrossFade = 7
local creditsCrossFadeCap = creditsCrossFade
local creditsCrossFadeMath = 255 / creditsCrossFade
local TEX_HEADER = get_texture_info("char-select-text")
local TEX_OVERRIDE_HEADER = nil
---@param texture TextureInfo|nil
function header_set_texture(texture)
TEX_OVERRIDE_HEADER = texture
end
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 = {
[1] = {
saveName = "Default",
currAlt = 1,
hasMoveset = false,
locked = false,
[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 / Coop Team",
color = { r = 255, g = 50, b = 50 },
model = E_MODEL_MARIO,
offset = 0,
forceChar = CT_MARIO,
lifeIcon = gTextures.mario_head,
starIcon = gTextures.star,
camScale = 1.0,
},
[2] = {
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 / Coop Team",
color = { r = 50, g = 255, b = 50 },
model = E_MODEL_LUIGI,
offset = 0,
forceChar = CT_LUIGI,
lifeIcon = gTextures.luigi_head,
starIcon = gTextures.star,
camScale = 1.0,
},
[3] = {
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 / Coop Team",
color = { r = 50, g = 50, b = 255 },
model = E_MODEL_TOAD_PLAYER,
offset = 0,
forceChar = CT_TOAD,
lifeIcon = gTextures.toad_head,
starIcon = gTextures.star,
camScale = 0.8,
},
[4] = {
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 / Coop Team",
color = { r = 130, g = 25, b = 130 },
model = E_MODEL_WALUIGI,
offset = 0,
forceChar = CT_WALUIGI,
lifeIcon = gTextures.waluigi_head,
starIcon = gTextures.star,
camScale = 1.1,
},
[5] = {
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 / Coop Team",
color = { r = 255, g = 255, b = 50 },
model = E_MODEL_WARIO,
offset = 0,
forceChar = CT_WARIO,
lifeIcon = gTextures.wario_head,
starIcon = gTextures.star,
camScale = 1.0,
},
},
}
characterCaps = {}
characterCelebrationStar = {}
characterColorPresets = {}
characterAnims = {}
characterMovesets = {[1] = {}}
characterUnlock = {}
optionTableRef = {
-- Menu
openInputs = 1,
notification = 2,
menuColor = 3,
anims = 4,
inputLatency = 5,
showLocked = 6,
-- Characters
autoPalette = 7,
localMoveset = 8,
localModels = 9,
localVoices = 10,
-- CS
credits = 11,
debugInfo = 12,
resetSaveData = 13,
}
optionTable = {
[optionTableRef.openInputs] = {
name = "Open Binds",
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",
toggle = tonumber(mod_storage_load("notifs")),
toggleSaveName = "notifs",
toggleDefault = 1,
toggleMax = 2,
toggleNames = {"Off", "On", "Pop-ups Only"},
description = {"Toggles wheather Pop-ups and", "Chat Messages display"}
},
[optionTableRef.menuColor] = {
name = "Menu Color",
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.anims] = {
name = "Menu Anims",
toggle = tonumber(mod_storage_load("Anims")),
toggleSaveName = "Anims",
toggleDefault = 1,
toggleMax = 1,
toggleNames = {"Off", "On"},
description = {"Toggles Animations In-Menu,", "Turning these off may", "Save Performance"}
},
[optionTableRef.inputLatency] = {
name = "Scroll Speed",
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.showLocked] = {
name = "Show Locked Chars",
toggle = tonumber(mod_storage_load("showLocked")),
toggleSaveName = "showLocked",
toggleDefault = 1,
toggleMax = 1,
description = {"Toggles if Locked Characters", "Display In-Menu"}
},
[optionTableRef.autoPalette] = {
name = "Auto-Apply Palette",
toggle = tonumber(mod_storage_load("autoPalette")),
toggleSaveName = "autoPalette",
toggleDefault = 1,
toggleMax = 1,
description = {"If On, Automatically", "sets your palette to the", "Character's Preset if avalible"}
},
[optionTableRef.localMoveset] = {
name = "Character Moveset",
toggle = tonumber(mod_storage_load("localMoveset")),
toggleSaveName = "localMoveset",
toggleDefault = 1,
toggleMax = 1,
description = {"Toggles if Custom Movesets", "are active on compatible", "characters"}
},
[optionTableRef.localModels] = {
name = "Locally Display Models",
toggle = tonumber(mod_storage_load("localModels")),
toggleSaveName = "localModels",
toggleDefault = 1,
toggleMax = 1,
description = {"Toggles if Custom Models display", "on your client, practically", "disables Character Select if", "Toggled Off"}
},
[optionTableRef.localVoices] = {
name = "Custom Voices",
toggle = tonumber(mod_storage_load("localVoices")),
toggleSaveName = "localVoices",
toggleDefault = 1,
toggleMax = 1,
description = {"Toggle if Custom Voicelines play", "for Characters who support it"}
},
[optionTableRef.credits] = {
name = "Credits",
toggle = 0,
toggleDefault = 0,
toggleMax = 1,
toggleNames = {"", ""},
description = {"Thank you for choosing", "Character Select!"}
},
[optionTableRef.debugInfo] = {
name = "Debugging Info",
toggle = tonumber(mod_storage_load("debuginfo")),
toggleSaveName = "debuginfo",
toggleDefault = 0,
toggleMax = 1,
description = {"Replaces the Character", "Description with Character", "Debugging Information"}
},
[optionTableRef.resetSaveData] = {
name = "Reset Save Data",
toggle = 0,
toggleDefault = 0,
toggleMax = 1,
toggleNames = {"", ""},
description = {"Resets Character Select's", "Save Data"}
},
}
creditTable = {
{
packName = "Character Select Coop",
{creditTo = "Squishy6094", creditFor = "Creator"},
{creditTo = "AngelicMiracles", creditFor = "Concepts / CoopDX"},
{creditTo = "AgentX", creditFor = "Main Contributer / CoopDX"},
{creditTo = "xLuigiGamerx", creditFor = "Main Contributer"},
{creditTo = "OneCalledRPG", creditFor = "Contributer"},
{creditTo = "SuperKirbyLover", creditFor = "Custom Health Meters"},
{creditTo = "EliteMasterEric", creditFor = "Dialog Replacement"}
}
}
local defaultOptionCount = #optionTable
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 }
}
-- Default Player Adjustments
local defaultMenuColors = {
[CT_MARIO] = menuColorTable[1],
[CT_LUIGI] = menuColorTable[4],
[CT_TOAD] = menuColorTable[5],
[CT_WALUIGI] = menuColorTable[7],
[CT_WARIO] = menuColorTable[3]
}
local defaultModels = {
[CT_MARIO] = E_MODEL_MARIO,
[CT_LUIGI] = E_MODEL_LUIGI,
[CT_TOAD] = E_MODEL_TOAD_PLAYER,
[CT_WALUIGI] = E_MODEL_WALUIGI,
[CT_WARIO] = E_MODEL_WARIO
}
local defaultForceChar = {
[CT_MARIO] = "CT_MARIO",
[CT_LUIGI] = "CT_LUIGI",
[CT_TOAD] = "CT_TOAD",
[CT_WALUIGI] = "CT_WALUIGI",
[CT_WARIO] = "CT_WARIO"
}
---@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 savedChar = mod_storage_load("PrefChar")
local savedAlt = tonumber(mod_storage_load("PrefAlt"))
if savedChar == nil or savedChar == "" then
mod_storage_save("PrefChar", "Default")
savedChar = "Default"
end
if savedAlt == nil then
mod_storage_save("PrefAlt", "1")
savedAlt = 1
end
if savedChar ~= nil and savedChar ~= "Default" then
for i = 2, #characterTable do
local char = characterTable[i]
if char.saveName == savedChar and not char.locked then
currChar = i
if savedAlt > 0 and savedAlt <= #char then
char.currAlt = savedAlt
end
if optionTable[optionTableRef.localModels].toggle == 1 then
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
end
break
end
end
end
characterTable[1].currAlt = gNetworkPlayers[0].modelIndex + 1
local savedCharColors = mod_storage_load("PrefCharColor")
if savedCharColors ~= nil and savedCharColors ~= "" then
local savedCharColorsTable = string_split(string_underscore_to_space(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 == 1 then
if optionTable[optionTableRef.notification].toggle > 0 then
djui_popup_create("Character Select:\nNo Characters were Found", 2)
end
end
TEXT_PREF_LOAD_NAME = savedChar
TEXT_PREF_LOAD_ALT = savedAlt
end
local function mod_storage_save_pref_char(charTable)
mod_storage_save("PrefChar", charTable.saveName)
mod_storage_save("PrefAlt", tostring(charTable.currAlt))
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 = charTable.saveName
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
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
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")
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
currChar = 1
for i = 1, #characterTable do
characterTable[i].currAlt = 1
end
mod_storage_save_pref_char(characterTable[1])
promptedAreYouSure = false
end
end
local function boot_note()
if #characterTable > 1 then
djui_chat_message_create("Character Select has " .. (#characterTable - 1) .. " character" .. (#characterTable > 2 and "s" or "") .." available!\nYou can use \\#ffff33\\/char-select \\#ffffff\\to open the menu!")
if #characterTable > 32 and network_is_server() then
djui_chat_message_create("\\#FFAAAA\\Warning: Having more than 32 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 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
local function get_next_unlocked_char()
for i = currChar, #characterTable do
if not characterTable[i].locked then
return i
end
end
return 1
end
local function get_last_unlocked_char()
for i = currChar, 1, -1 do
if not characterTable[i].locked then
return i
end
end
return 1
end
-------------------
-- Model Handler --
-------------------
local stallFrame = 0
local noLoop = false
local CUTSCENE_CS_MENU = 0xFA
local ignoredSurfaces = {
SURFACE_BURNING, SURFACE_QUICKSAND, SURFACE_INSTANT_QUICKSAND, SURFACE_INSTANT_MOVING_QUICKSAND, SURFACE_DEEP_MOVING_QUICKSAND, SURFACE_INSTANT_QUICKSAND, SURFACE_DEEP_QUICKSAND, SURFACE_SHALLOW_MOVING_QUICKSAND,
SURFACE_SHALLOW_QUICKSAND, SURFACE_WARP, SURFACE_LOOK_UP_WARP, SURFACE_WOBBLING_WARP, SURFACE_INSTANT_WARP_1B, SURFACE_INSTANT_WARP_1C, SURFACE_INSTANT_WARP_1D, SURFACE_INSTANT_WARP_1E
}
local TYPE_FUNCTION = "function"
local TYPE_BOOLEAN = "boolean"
local TYPE_STRING = "string"
local TYPE_INTEGER = "number"
local TYPE_TABLE = "table"
local MATH_PI = math.pi
local menuActBlacklist = {
-- Star Acts
[ACT_FALL_AFTER_STAR_GRAB] = true,
[ACT_STAR_DANCE_EXIT] = true,
[ACT_STAR_DANCE_NO_EXIT] = true,
[ACT_STAR_DANCE_WATER] = true,
-- Key Acts
[ACT_UNLOCKING_KEY_DOOR] = true,
[ACT_UNLOCKING_STAR_DOOR] = true,
-- Cutscene Acts
[ACT_INTRO_CUTSCENE] = true,
[ACT_CREDITS_CUTSCENE] = true,
[ACT_WARP_DOOR_SPAWN] = true,
[ACT_PULLING_DOOR] = true,
[ACT_PUSHING_DOOR] = true,
[ACT_UNLOCKING_KEY_DOOR] = true,
[ACT_UNLOCKING_STAR_DOOR] = true,
-- Dialog Acts
[ACT_READING_NPC_DIALOG] = true,
[ACT_WAITING_FOR_DIALOG] = true,
[ACT_EXIT_LAND_SAVE_DIALOG] = true,
[ACT_READING_AUTOMATIC_DIALOG] = true,
}
local faceAngle = 0
local function anim_generic_idle_offset(offset, animFrame)
return offset - math.max((math.sin((animFrame)/24*MATH_PI)+1.1)*2, 1.8)
end
local altOffsetAnim = {
[MARIO_ANIM_CROUCHING] = true,
[ACT_READING_AUTOMATIC_DIALOG] = true,
[MARIO_ANIM_FALL_OVER_BACKWARDS] = true,
[MARIO_ANIM_SLIDE_KICK] = false,
[MARIO_ANIM_GROUND_POUND] = false,
[MARIO_ANIM_GROUND_POUND_LANDING] = false,
[MARIO_ANIM_SLEEP_IDLE] = false,
[MARIO_ANIM_SLEEP_LYING] = false,
[MARIO_ANIM_SLEEP_START_LYING] = false,
[MARIO_ANIM_IDLE_HEAD_LEFT] = function (offset, animFrame)
return anim_generic_idle_offset(offset, animFrame)
end,
[MARIO_ANIM_IDLE_HEAD_CENTER] = function (offset, animFrame)
return anim_generic_idle_offset(offset, animFrame)
end,
[MARIO_ANIM_IDLE_HEAD_RIGHT] = function (offset, animFrame)
return anim_generic_idle_offset(offset, animFrame)
end,
}
local prevBaseCharFrame = gNetworkPlayers[0].modelIndex
local prevAnim = 0
local animTimer = 0
--- @param m MarioState
local function mario_update(m)
local np = gNetworkPlayers[m.playerIndex]
local p = gCSPlayers[m.playerIndex]
if stallFrame == 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
if stallFrame < 3 then
stallFrame = stallFrame + 1
end
if m.playerIndex == 0 and stallFrame > 1 then
if djui_hud_is_pause_menu_created() and prevBaseCharFrame ~= np.modelIndex then
characterTable[1].currAlt = np.modelIndex + 1
currChar = 1
p.presetPalette = 0
end
prevBaseCharFrame = np.modelIndex
local defaultTable = characterTable[1]
local charTable = characterTable[currChar]
p.saveName = charTable.saveName
p.currAlt = charTable.currAlt
if optionTable[optionTableRef.localModels].toggle > 0 then
p.modelId = charTable[charTable.currAlt].model
if charTable[charTable.currAlt].forceChar ~= nil then
p.forceChar = charTable[charTable.currAlt].forceChar
end
m.marioObj.hookRender = 1
else
p.modelId = nil
p.forceChar = defaultTable.forceChar
currChar = 1
end
p.offset = charTable[charTable.currAlt].offset
if menuAndTransition then
--play_secondary_music(0, 0, 0.5, 0)
camera_freeze()
hud_hide()
if _G.PersonalStarCounter then
_G.PersonalStarCounter.hide_star_counters(true)
end
if m.area.camera.cutscene == 0 then
m.area.camera.cutscene = CUTSCENE_CS_MENU
end
local camScale = charTable[charTable.currAlt].camScale
local focusPos = {
x = m.pos.x,
y = m.pos.y + 120 * camScale,
z = m.pos.z,
}
vec3f_copy(gLakituState.focus, focusPos)
gLakituState.pos.x = m.pos.x + sins(faceAngle) * 500 * camScale
gLakituState.pos.y = m.pos.y + 100 * camScale
gLakituState.pos.z = m.pos.z + coss(faceAngle) * 500 * camScale
if m.forwardVel == 0 and m.pos.y == m.floorHeight and not ignoredSurfaces[m.floor.type] and m.health > 255 and not menuActBlacklist[m.action] then
set_mario_action(m, ACT_IDLE, 0)
set_mario_animation(m, MARIO_ANIM_FIRST_PERSON)
end
noLoop = false
elseif not noLoop then
--stop_secondary_music(50)
camera_unfreeze()
hud_show()
if _G.PersonalStarCounter then
_G.PersonalStarCounter.hide_star_counters(false)
end
if m.area.camera.cutscene == CUTSCENE_CS_MENU then
m.area.camera.cutscene = CUTSCENE_STOP
end
noLoop = true
end
-- Check for Locked Chars
for i = 2, #characterTable do
local currChar = characterTable[i]
if currChar.locked then
local unlock = characterUnlock[i].check
local notif = characterUnlock[i].notif
if type(unlock) == TYPE_FUNCTION then
if unlock() then
currChar.locked = false
if stallFrame == 3 and notif then
if optionTable[optionTableRef.notification].toggle > 0 then
djui_popup_create('Character Select:\nUnlocked '..currChar.name..'\nas a Playable Character!', 3)
end
end
end
elseif type(unlock) == TYPE_BOOLEAN then
currChar.locked = not unlock
end
end
end
--Open Credits
if optionTable[optionTableRef.credits].toggle > 0 then
credits = true
optionTable[optionTableRef.credits].toggle = 0
end
--Reset Save Data Check
if optionTable[optionTableRef.resetSaveData].toggle > 0 then
reset_options(false)
optionTable[optionTableRef.resetSaveData].toggle = 0
end
charBeingSet = false
for i = 1, #optionTable do
optionTable[i].optionBeingSet = false
end
end
local marioGfx = m.marioObj.header.gfx
if prevAnim ~= marioGfx.animInfo.animID then
prevAnim = marioGfx.animInfo.animID
animTimer = 0
end
animTimer = animTimer + 1
local networkOffset = p.offset
local forceChar = p.forceChar
if networkOffset ~= 0 and networkOffset ~= nil then
if m.playerIndex == 0 then
end
local offset = altOffsetAnim[marioGfx.animInfo.animID]
if offset ~= false then
if type(offset) == TYPE_FUNCTION then
marioGfx.pos.y = marioGfx.pos.y + offset(networkOffset, marioGfx.animInfo.animFrame)
elseif type(offset) == TYPE_TABLE then
marioGfx.pos.y = marioGfx.pos.y - offset[(math.min(animTimer, #offset))]*networkOffset + networkOffset
elseif type(offset) == TYPE_INTEGER then
marioGfx.pos.y = marioGfx.pos.y + networkOffset*offset
else
marioGfx.pos.y = (altOffsetAnim[marioGfx.animInfo.animID] and m.pos.y or marioGfx.pos.y) + networkOffset
end
end
end
if forceChar ~= nil then
np.overrideModelIndex = forceChar
end
-- Character Animations
if characterAnims[p.modelId] then
local animID = characterAnims[p.modelId][m.marioObj.header.gfx.animInfo.animID]
if animID then
smlua_anim_util_set_animation(m.marioObj, animID)
end
end
end
local sCapBhvs = {
[id_bhvWingCap] = true,
[id_bhvVanishCap] = true,
[id_bhvMetalCap] = true
}
--- @param o Object
--- @param model integer
local BowserKey = false
local function on_star_or_key_grab(m, o, type)
if type == INTERACT_STAR_OR_KEY then
if get_id_from_behavior(o.behavior) == id_bhvBowserKey then
BowserKey = true
else
BowserKey = false
end
end
end
local settingModel
function set_model(o, model)
if settingModel then return end
if optionTable[optionTableRef.localModels].toggle == 0 then return end
if obj_has_behavior_id(o, id_bhvMario) ~= 0 then
local i = network_local_index_from_global(o.globalPlayerIndex)
if gCSPlayers[i].modelId ~= nil and obj_has_model_extended(o, gCSPlayers[i].modelId) == 0 then
settingModel = true
obj_set_model_extended(o, gCSPlayers[i].modelId)
settingModel = false
end
return
end
if obj_has_behavior_id(o, id_bhvCelebrationStar) ~= 0 and o.parentObj ~= nil then
local i = network_local_index_from_global(o.parentObj.globalPlayerIndex)
local starModel = characterCelebrationStar[gCSPlayers[i].modelId]
if gCSPlayers[i].modelId ~= nil and starModel ~= nil and obj_has_model_extended(o, starModel) == 0 and not BowserKey then
settingModel = true
obj_set_model_extended(o, starModel)
settingModel = false
end
return
end
if sCapBhvs[get_id_from_behavior(o.behavior)] then
o.globalPlayerIndex = nearest_player_to_object(o.parentObj).globalPlayerIndex
end
local i = network_local_index_from_global(o.globalPlayerIndex)
local c = gMarioStates[i].character
if model == c.capModelId or
model == c.capWingModelId or
model == c.capMetalModelId or
model == c.capMetalWingModelId then
local capModels = characterCaps[gCSPlayers[i].modelId]
if capModels ~= nil then
local capModel = E_MODEL_NONE
if model == c.capModelId then
capModel = capModels.normal
elseif model == c.capWingModelId then
capModel = capModels.wing
elseif model == c.capMetalModelId then
capModel = capModels.metal
elseif model == c.capMetalWingModelId then
capModel = capModels.metalWing
end
if capModel ~= E_MODEL_NONE and capModel ~= E_MODEL_ERROR_MODEL and capModel ~= nil then
settingModel = true
obj_set_model_extended(o, capModel)
settingModel = false
end
end
end
end
hook_event(HOOK_MARIO_UPDATE, mario_update)
hook_event(HOOK_ON_INTERACT, on_star_or_key_grab)
hook_event(HOOK_OBJECT_SET_MODEL, set_model)
------------------
-- Menu Handler --
------------------
local buttonAnimTimer = 0
local buttonScroll = 0
local buttonScrollCap = 30
local optionAnimTimer = -200
local optionAnimTimerCap = optionAnimTimer
local inputStallTimerButton = 0
local inputStallTimerDirectional = 0
local inputStallToDirectional = 12
local inputStallToButton = 10
--Basic Menu Text
local TEXT_OPTIONS_HEADER = "Menu Options"
local TEXT_OPTIONS_HEADER_API = "API Options"
local yearsOfCS = get_date_and_time().year - 123 -- Zero years as of 2023
local TEXT_VERSION = "Version: " .. MOD_VERSION_STRING .. " | sm64coopdx" .. (seasonalEvent == SEASON_EVENT_BIRTHDAY and (" | " .. tostring(yearsOfCS) .. " year" .. (yearsOfCS > 1 and "s" or "") .. " of Character Select!") or "")
local TEXT_RATIO_UNSUPPORTED = "Your Current Aspect-Ratio isn't Supported!"
local TEXT_DESCRIPTION = "Character Description:"
local TEXT_PREF_SAVE = "Press A to Set as Preferred Character"
local TEXT_PREF_SAVE_AND_PALETTE = "A - Set Preference | Y - Toggle Palette"
local TEXT_PAUSE_Z_OPEN = "Z Button - Character Select"
local TEXT_PAUSE_UNAVALIBLE = "Character Select is Unavalible"
local TEXT_PAUSE_CURR_CHAR = "Current Character: "
local TEXT_MOVESET_RESTRICTED = "Movesets are Restricted"
local TEXT_PALETTE_RESTRICTED = "Palettes are Restricted"
local TEXT_MOVESET_AND_PALETTE_RESTRICTED = "Moveset and Palettes are Restricted"
local TEXT_CHAR_LOCKED = "Locked"
-- Easter Egg if you get lucky loading the mod
-- Referencing the original sm64ex DynOS options by PeachyPeach >v<
if math_random(100) == 64 then
TEXT_PAUSE_Z_OPEN = "Z - DynOS"
TEXT_PAUSE_CURR_CHAR = "Model: "
end
--Debug Text
local TEXT_DEBUGGING = "Character Debug"
local TEXT_DESCRIPTION_SHORT = "Description:"
local TEXT_LIFE_ICON = "Life Icon:"
local TEXT_STAR_ICON = "Star Icon:"
local TEXT_FORCED_CHAR = "Forced: "
local TEXT_OFFSET = "Offset: "
local TEXT_TABLE_POS = "Table Position: "
local TEXT_PALETTE = "Palette: "
--Options Text
local TEXT_OPTIONS_OPEN = "Press START to open Options"
local TEXT_MENU_CLOSE = "Press B to Exit Menu"
local TEXT_OPTIONS_SELECT = "A - Select | B - Exit "
local TEXT_LOCAL_MODEL_OFF = "Locally Display Models is Off"
local TEXT_LOCAL_MODEL_OFF_OPTIONS = "You can turn it back on in the Options Menu"
--Credit Text
local TEXT_CREDITS_HEADER = "Credits"
menuColor = characterTable[1][1].color
local MATH_DIVIDE_320 = 1/320
local MATH_DIVIDE_64 = 1/64
local MATH_DIVIDE_32 = 1/32
local MATH_DIVIDE_30 = 1/30
local MATH_DIVIDE_16 = 1/16
function update_menu_color()
if optionTable[optionTableRef.menuColor].toggle > 1 then
menuColor = menuColorTable[optionTable[optionTableRef.menuColor].toggle - 1]
elseif optionTable[optionTableRef.menuColor].toggle == 1 then
optionTable[optionTableRef.menuColor].toggleNames[2] = string_underscore_to_space(TEXT_PREF_LOAD_NAME) .. ((TEXT_PREF_LOAD_ALT ~= 1 and currChar ~= 1) and " ("..TEXT_PREF_LOAD_ALT..")" or "") .. " (Pref)"
menuColor = prefCharColor
elseif characterTable[currChar] ~= nil then
local char = characterTable[currChar]
menuColor = char[char.currAlt].color
end
return menuColor
end
local TEX_TRIANGLE = get_texture_info("char-select-triangle")
local function djui_hud_render_triangle(x, y, width, height)
djui_hud_render_texture(TEX_TRIANGLE, x, y, width*MATH_DIVIDE_64, height*MATH_DIVIDE_32)
end
local buttonAltAnim = 0
local function on_hud_render()
local FONT_USER = djui_menu_get_font()
djui_hud_set_resolution(RESOLUTION_N64)
djui_hud_set_font(FONT_ALIASED)
local width = djui_hud_get_screen_width() + 1.4
local height = 240
local widthHalf = width * 0.5
local heightHalf = height * 0.5
local widthScale = maxf(width, 321.4) * MATH_DIVIDE_320
if menuAndTransition then
update_menu_color()
if optionTable[optionTableRef.localModels].toggle == 0 then
djui_hud_set_color(0, 0, 0, 200)
djui_hud_render_rect(0, 0, width, height)
djui_hud_set_color(255, 255, 255, 255)
djui_hud_print_text(TEXT_LOCAL_MODEL_OFF, widthHalf - djui_hud_measure_text(TEXT_LOCAL_MODEL_OFF) * 0.15 * widthScale, heightHalf, 0.3 * widthScale)
djui_hud_print_text(TEXT_LOCAL_MODEL_OFF_OPTIONS, widthHalf - djui_hud_measure_text(TEXT_LOCAL_MODEL_OFF_OPTIONS) * 0.1 * widthScale, heightHalf + 10 * widthScale, 0.2 * widthScale)
end
local x = 135 * widthScale * 0.8
-- Render All Black Squares Behind Below API
-- Description
djui_hud_set_color(0, 0, 0, 255)
djui_hud_render_rect(width - x + 2, 2, x - 4, height - 4)
-- Buttons
djui_hud_set_color(0, 0, 0, 255)
djui_hud_render_rect(2, 2, x - 4, height - 4)
-- Header
djui_hud_set_color(0, 0, 0, 255)
djui_hud_render_rect(2, 2, width - 4, 46)
-- API Rendering (Below Text)
if #renderInMenuTable.back > 0 then
for i = 1, #renderInMenuTable.back do
renderInMenuTable.back[i]()
end
end
--Character Description
djui_hud_set_color(menuColor.r, menuColor.g, menuColor.b, 255)
djui_hud_render_rect(width - x, 50, 2, height - 50)
djui_hud_render_rect(width - x, height - 2, x, 2)
djui_hud_render_rect(width - 2, 50, 2, height - 50)
djui_hud_set_font(FONT_ALIASED)
local character = characterTable[currChar]
local TEXT_SAVE_NAME = "Save Name: " .. character.saveName
local TEXT_MOVESET = "Has Moveset: "..(character.hasMoveset and "Yes" or "No")
local TEXT_ALT = "Alt: " .. character.currAlt .. "/" .. #character
character = characterTable[currChar][character.currAlt]
local paletteCount = characterColorPresets[gCSPlayers[0].modelId] ~= nil and #characterColorPresets[gCSPlayers[0].modelId] or 0
if optionTable[optionTableRef.debugInfo].toggle == 0 then
-- Actual Description --
local TEXT_NAME = string_underscore_to_space(character.name)
local TEXT_CREDIT = "Credit: " .. character.credit
local TEXT_DESCRIPTION_TABLE = character.description
local TEXT_PRESET = "Preset Character Palette: "..(gCSPlayers[0].presetPalette > 0 and (paletteCount > 1 and "("..gCSPlayers[0].presetPalette.."/"..paletteCount..")" or "On") or "Off")
local TEXT_PREF = "Preferred Character:"
local TEXT_PREF_LOAD_NAME = string_underscore_to_space(TEXT_PREF_LOAD_NAME)
if djui_hud_measure_text(TEXT_PREF_LOAD_NAME) / widthScale > 110 then
TEXT_PREF = "Preferred Char:"
end
if djui_hud_measure_text(TEXT_PREF_LOAD_NAME) / widthScale > 164 then
TEXT_PREF = "Pref Char:"
end
TEXT_PREF = TEXT_PREF .. ' "' .. TEXT_PREF_LOAD_NAME .. '"' .. ((TEXT_PREF_LOAD_ALT ~= 1 and TEXT_PREF_LOAD_NAME ~= "Default" and currChar ~= 1) and " ("..TEXT_PREF_LOAD_ALT..")" or "")
local textX = x * 0.5
djui_hud_print_text(TEXT_NAME, width - textX - djui_hud_measure_text(TEXT_NAME) * 0.3, 55, 0.6)
djui_hud_set_font(FONT_TINY)
local creditScale = 0.6
creditScale = math_min(creditScale, 100/djui_hud_measure_text(TEXT_CREDIT))
djui_hud_print_text(TEXT_CREDIT, width - textX - djui_hud_measure_text(TEXT_CREDIT) * creditScale *0.5, 74, creditScale)
djui_hud_set_font(FONT_ALIASED)
djui_hud_print_text(TEXT_DESCRIPTION, width - textX - djui_hud_measure_text(TEXT_DESCRIPTION) * 0.2, 85, 0.4)
if widthScale < 1.65 then
for i = 1, #TEXT_DESCRIPTION_TABLE do