fork/training-mode-ce

git clone https://git.julia.blue/fork/training-mode-ce

AitchAdd tech chase event (#317)1da5d99

master
61.7 KiB2159 linesraw
1#include "events.h"
2#include "savestate.h"
3#include <stdarg.h>
4
5/////////////////////
6// Mod Information //
7/////////////////////
8
9static char TM_VersShort[] = TM_VERSSHORT "\n";
10static char TM_VersLong[] = TM_VERSLONG "\n";
11static char TM_Compile[] = "COMPILED: " __DATE__ " " __TIME__;
12
13////////////////////////
14/// Event Defintions ///
15////////////////////////
16
17// Lab
18static EventMatchData Lab_MatchData = {
19    .timer = MATCH_TIMER_COUNTUP,
20    .matchType = MATCH_MATCHTYPE_TIME,
21    .hideGo = true,
22    .hideReady = true,
23    .isCreateHUD = true,
24    .timerRunOnPause = false,
25    .isCheckForZRetry = false,
26    .isShowScore = false,
27
28    .isRunStockLogic = false,
29    .isDisableHit = false,
30    .useKOCounter = false,
31    .timerSeconds = 0,
32};
33EventDesc Lab = {
34    // Event Name
35    .eventName = "Training Lab\n",
36    .eventDescription = "Free practice with\ncomplete control.\n",
37    .eventFile = "lab",
38    .jumpTableIndex = -1,
39    .eventCSSFile = "TM/labCSS.dat",
40    .CSSType = SLCHRKIND_TRAINING,
41    .allowed_characters = { .hmn = -1, .cpu = -1 },
42    .cpuKind = -1,
43    .stage = -1,
44    .disable_hazards = true,
45    .force_sopo = false,
46    .scoreType = SCORETYPE_KO,
47    .callbackPriority = 3,
48    .matchData = &Lab_MatchData,
49};
50
51// L-Cancel Training
52static EventMatchData LCancel_MatchData = {
53    .timer = MATCH_TIMER_HIDE,
54    .matchType = MATCH_MATCHTYPE_TIME,
55    .hideGo = true,
56    .hideReady = true,
57    .isCreateHUD = false,
58    .timerRunOnPause = false,
59    .isCheckForZRetry = false,
60    .isShowScore = false,
61
62    .isRunStockLogic = false,
63    .isDisableHit = false,
64    .useKOCounter = false,
65    .timerSeconds = 0,
66};
67EventDesc LCancel = {
68    // Event Name
69    .eventName = "L-Cancel Training\n",
70    .eventDescription = "Practice L-Cancelling on\na stationary CPU.\n",
71    .eventFile = "lcancel",
72    .jumpTableIndex = -1,
73    .CSSType = SLCHRKIND_EVENT,
74    .allowed_characters = { .hmn = -1, .cpu = -1 },
75    .cpuKind = -1,
76    .stage = -1,
77    .disable_hazards = true,
78    .force_sopo = false,
79    .scoreType = SCORETYPE_KO,
80    .callbackPriority = 15,
81    .matchData = &LCancel_MatchData,
82};
83
84// Ledgedash Training
85static EventMatchData Ledgedash_MatchData = {
86    .timer = MATCH_TIMER_HIDE,
87    .matchType = MATCH_MATCHTYPE_TIME,
88    .hideGo = true,
89    .hideReady = true,
90    .isCreateHUD = false,
91    .timerRunOnPause = false,
92    .isCheckForZRetry = false,
93    .isShowScore = false,
94
95    .isRunStockLogic = false,
96    .isDisableHit = false,
97    .useKOCounter = false,
98    .timerSeconds = 0,
99};
100EventDesc Ledgedash = {
101    .eventName = "Ledgedash Training\n",
102    .eventDescription = "Practice Ledgedashes!\nUse D-Pad to change ledge.\n",
103    .eventFile = "ledgedash",
104    .jumpTableIndex = -1,
105    .CSSType = SLCHRKIND_EVENT,
106    .allowed_characters = { .hmn = -1, .cpu = -1 },
107    .cpuKind = -1,
108    .stage = -1,
109    .disable_hazards = true,
110    .force_sopo = true,
111    .scoreType = SCORETYPE_KO,
112    .callbackPriority = 15,
113    .matchData = &Ledgedash_MatchData,
114};
115
116// Wavedash Training
117static EventMatchData Wavedash_MatchData = {
118    .timer = MATCH_TIMER_HIDE,
119    .matchType = MATCH_MATCHTYPE_TIME,
120    .hideGo = true,
121    .hideReady = true,
122    .isCreateHUD = false,
123    .timerRunOnPause = false,
124    .isCheckForZRetry = false,
125    .isShowScore = false,
126
127    .isRunStockLogic = false,
128    .isDisableHit = false,
129    .useKOCounter = false,
130    .timerSeconds = 0,
131};
132EventDesc Wavedash = {
133    .eventName = "Wavedash Training\n",
134    .eventDescription = "Practice timing your wavedash,\na fundamental movement technique.\n",
135    .eventFile = "wavedash",
136    .jumpTableIndex = -1,
137    .CSSType = SLCHRKIND_EVENT,
138    .allowed_characters = { .hmn = -1, .cpu = -1 },
139    .cpuKind = -1,
140    .stage = -1,
141    .disable_hazards = true,
142    .force_sopo = false,
143    .scoreType = SCORETYPE_KO,
144    .callbackPriority = 15,
145    .matchData = &Wavedash_MatchData,
146};
147
148// TechChase Training
149static EventMatchData TechChase_MatchData = {
150    .timer = MATCH_TIMER_HIDE,
151    .matchType = MATCH_MATCHTYPE_TIME,
152    .hideGo = true,
153    .hideReady = true,
154    .isCreateHUD = false,
155    .timerRunOnPause = false,
156    .isCheckForZRetry = false,
157    .isShowScore = false,
158
159    .isRunStockLogic = false,
160    .isDisableHit = false,
161    .useKOCounter = false,
162    .timerSeconds = 0,
163};
164EventDesc TechChase = {
165    .eventName = "Techchase Training\n",
166    .eventDescription = "Practice chasing techs! A\nuseful tool to extend combos.",
167    .eventFile = "techchase",
168    .jumpTableIndex = -1,
169    .CSSType = SLCHRKIND_TRAINING,
170    .allowed_characters = { .hmn = -1, .cpu = -1 },
171    .cpuKind = -1,
172    .stage = -1,
173    .disable_hazards = true,
174    .force_sopo = false,
175    .scoreType = SCORETYPE_KO,
176    .callbackPriority = 3,
177    .matchData = &TechChase_MatchData,
178};
179
180// Float Cancel Training
181static EventMatchData FloatCancel_MatchData = {
182    .timer = MATCH_TIMER_HIDE,
183    .matchType = MATCH_MATCHTYPE_TIME,
184    .hideGo = true,
185    .hideReady = true,
186    .isCreateHUD = false,
187    .timerRunOnPause = false,
188    .isCheckForZRetry = false,
189    .isShowScore = false,
190    .isRunStockLogic = false,
191    .isDisableHit = false,
192    .useKOCounter = false,
193    .timerSeconds = 0,
194};
195EventDesc FloatCancel = {
196    .eventName = "Float Cancel Training\n",
197    .eventDescription = "Practice Peach's most important\ntechnique!\n",
198    .eventFile = "fc",
199    .jumpTableIndex = -1,
200    .CSSType = SLCHRKIND_EVENT,
201    .allowed_characters = { .hmn = CSSID_PEACH, .cpu = -1 },
202    .cpuKind = -1,
203    .stage = GRKINDEXT_FD,
204    .disable_hazards = true,
205    .force_sopo = false,
206    .scoreType = SCORETYPE_KO,
207    .callbackPriority = 3,
208    .matchData = &FloatCancel_MatchData,
209};
210
211static EventMatchData Sweetspot_MatchData = {
212    .timer = MATCH_TIMER_HIDE,
213    .matchType = MATCH_MATCHTYPE_TIME,
214    .hideGo = true,
215    .hideReady = true,
216    .isCreateHUD = false,
217    .timerRunOnPause = false,
218    .isCheckForZRetry = true,
219    .isShowScore = false,
220
221    .isRunStockLogic = false,
222    .isDisableHit = false,
223    .useKOCounter = false,
224    .timerSeconds = 0,
225};
226EventDesc Sweetspot = {
227    .eventName = "Side-B Sweetspot\n",
228    .eventDescription = "Use a sweetspot Side-B to avoid Marth's\ndown-tilt and grab the ledge!",
229    .eventFile = "sweetspot",
230    .jumpTableIndex = -1,
231    .CSSType = SLCHRKIND_EVENT,
232    .allowed_characters = {
233        .hmn = CSSID_FALCO | CSSID_FOX,
234        .cpu = -1,
235    },
236    .playerKind = -1,
237    .cpuKind = CKIND_MARTH,
238    .stage = -1,
239    .disable_hazards = true,
240    .force_sopo = false,
241    .scoreType = SCORETYPE_KO,
242    .callbackPriority = 3,
243    .matchData = &Sweetspot_MatchData,
244};
245
246// Combo Training
247EventDesc Combo = {
248    .eventName = "Combo Training\n",
249    .eventDescription = "L+DPad adjusts percent | DPadDown moves CPU\nDPad right/left saves and loads positions.",
250    .eventFile = 0,
251    .jumpTableIndex = JUMP_COMBO,
252    .CSSType = SLCHRKIND_TRAINING,
253    .allowed_characters = { .hmn = -1, .cpu = -1 },
254    .cpuKind = -1,
255    .stage = -1,
256    .disable_hazards = true,
257    .force_sopo = false,
258    .scoreType = SCORETYPE_KO,
259    .callbackPriority = 3,
260    .matchData = 0,
261};
262
263// Attack On Shield Training
264EventDesc AttackOnShield = {
265    .eventName = "Attack on Shield\n",
266    .eventDescription = "Practice attacks on a shielding opponent\nPause to change their OoS option.\n",
267    .eventFile = 0,
268    .jumpTableIndex = JUMP_ATTACKONSHIELD,
269    .CSSType = SLCHRKIND_TRAINING,
270    .allowed_characters = { .hmn = -1, .cpu = -1 },
271    .cpuKind = -1,
272    .stage = GRKINDEXT_FD,
273    .disable_hazards = true,
274    .force_sopo = false,
275    .scoreType = SCORETYPE_KO,
276    .callbackPriority = 3,
277    .matchData = 0,
278};
279
280EventDesc Reversal = {
281    .eventName = "Reversal Training\n",
282    .eventDescription = "Practice OoS punishes! DPad left/right\nmoves characters closer and further apart.",
283    .eventFile = 0,
284    .jumpTableIndex = JUMP_REVERSAL,
285    .CSSType = SLCHRKIND_TRAINING,
286    .allowed_characters = { .hmn = -1, .cpu = -1 },
287    .cpuKind = -1,
288    .stage = -1,
289    .disable_hazards = true,
290    .force_sopo = false,
291    .scoreType = SCORETYPE_KO,
292    .callbackPriority = 3,
293    .matchData = 0,
294};
295
296EventDesc SDI = {
297    .eventName = "SDI Training\n",
298    .eventDescription = "Use Smash DI to escape\nFox's up-air!",
299    .eventFile = 0,
300    .jumpTableIndex = JUMP_SDITRAINING,
301    .CSSType = SLCHRKIND_EVENT,
302    .allowed_characters = { .hmn = -1, .cpu = -1 },
303    .cpuKind = CKIND_FOX,
304    .stage = GRKINDEXT_FD,
305    .disable_hazards = true,
306    .force_sopo = false,
307    .scoreType = SCORETYPE_KO,
308    .callbackPriority = 3,
309    .matchData = 0,
310};
311
312static EventMatchData Powershield_MatchData = {
313    .timer = MATCH_TIMER_COUNTUP,
314    .matchType = MATCH_MATCHTYPE_TIME,
315    .hideGo = true,
316    .hideReady = true,
317    .isCreateHUD = true,
318    .timerRunOnPause = false,
319    .isCheckForZRetry = true,
320    .isShowScore = false,
321    .isRunStockLogic = false,
322    .isDisableHit = false,
323    .useKOCounter = false,
324    .timerSeconds = 0,
325};
326EventDesc Powershield = {
327    .eventName = "Powershield Training\n",
328    .eventDescription = "Powershield Falco's laser!",
329    .eventFile = "powershield",
330    .jumpTableIndex = -1,
331    .CSSType = SLCHRKIND_EVENT,
332    .allowed_characters = { .hmn = -1, .cpu = -1 },
333    .cpuKind = CKIND_FALCO,
334    .stage = GRKINDEXT_FD,
335    .disable_hazards = true,
336    .force_sopo = true,
337    .scoreType = SCORETYPE_KO,
338    .callbackPriority = 3,
339    .matchData = &Powershield_MatchData,
340};
341EventDesc Ledgetech = {
342    .eventName = "Ledgetech Training\n",
343    .eventDescription = "Practice ledgeteching\nFalco's down-smash!",
344    .eventFile = 0,
345    .jumpTableIndex = JUMP_LEDGETECH,
346    .CSSType = SLCHRKIND_EVENT,
347    .allowed_characters = { .hmn = -1, .cpu = -1 },
348    .cpuKind = CKIND_FALCO,
349    .stage = -1,
350    .disable_hazards = true,
351    .force_sopo = false,
352    .scoreType = SCORETYPE_KO,
353    .callbackPriority = 3,
354    .matchData = 0,
355};
356
357EventDesc AmsahTech = {
358    .eventName = "Amsah-Tech Training\n",
359    .eventDescription = "Taunt to have Marth Up-B,\nthen ASDI down and tech!\n",
360    .eventFile = 0,
361    .jumpTableIndex = JUMP_AMSAHTECH,
362    .CSSType = SLCHRKIND_EVENT,
363    .allowed_characters = { .hmn = -1, .cpu = -1 },
364    .cpuKind = CKIND_MARTH,
365    .stage = -1,
366    .disable_hazards = true,
367    .force_sopo = false,
368    .scoreType = SCORETYPE_KO,
369    .callbackPriority = 3,
370    .matchData = 0,
371};
372
373EventDesc ShieldDrop = {
374    .eventName = "Shield Drop Training\n",
375    .eventDescription = "Counter with a shield-drop aerial!\nDPad left/right moves players apart.",
376    .eventFile = 0,
377    .jumpTableIndex = JUMP_SHIELDDROP,
378    .CSSType = SLCHRKIND_TRAINING,
379    .allowed_characters = { .hmn = -1, .cpu = -1 },
380    .cpuKind = -1,
381    .stage = -1,
382    .disable_hazards = true,
383    .force_sopo = false,
384    .scoreType = SCORETYPE_KO,
385    .callbackPriority = 3,
386    .matchData = 0,
387};
388EventDesc WaveshineSDI = {
389    .eventName = "Waveshine SDI\n",
390    .eventDescription = "Use Smash DI to get out\nof Fox's waveshine!",
391    .eventFile = 0,
392    .jumpTableIndex = JUMP_WAVESHINESDI,
393    .CSSType = SLCHRKIND_EVENT,
394    .allowed_characters = {
395        .hmn = CSSID_DOCTOR_MARIO | CSSID_MARIO | CSSID_BOWSER | CSSID_PEACH | CSSID_YOSHI
396                    | CSSID_DONKEY_KONG | CSSID_CAPTAIN_FALCON | CSSID_GANONDORF | CSSID_NESS
397                    | CSSID_SAMUS | CSSID_ZELDA | CSSID_LINK,
398        .cpu = -1,
399    },
400    .cpuKind = CKIND_FOX,
401    .stage = GRKINDEXT_FD,
402    .disable_hazards = true,
403    .force_sopo = false,
404    .scoreType = SCORETYPE_KO,
405    .callbackPriority = 3,
406    .matchData = 0,
407};
408
409EventDesc SlideOff = {
410    .eventName = "Slide-Off Training\n",
411    .eventDescription = "Use Slide-Off DI to slide off\nthe platform and counter attack!\n",
412    .eventFile = 0,
413    .jumpTableIndex = JUMP_SLIDEOFF,
414    .CSSType = SLCHRKIND_EVENT,
415    .allowed_characters = { .hmn = -1, .cpu = -1 },
416    .cpuKind = CKIND_MARTH,
417    .stage = GRKINDEXT_PSTAD,
418    .disable_hazards = true,
419    .force_sopo = false,
420    .scoreType = SCORETYPE_KO,
421    .callbackPriority = 3,
422    .matchData = 0,
423};
424
425EventDesc GrabMash = {
426    .eventName = "Grab Mash Training\n",
427    .eventDescription = "Mash buttons to escape the grab\nas quickly as possible!\n",
428    .eventFile = 0,
429    .jumpTableIndex = JUMP_GRABMASH,
430    .CSSType = SLCHRKIND_EVENT,
431    .allowed_characters = { .hmn = -1, .cpu = -1 },
432    .cpuKind = CKIND_MARTH,
433    .stage = GRKINDEXT_FD,
434    .disable_hazards = true,
435    .force_sopo = false,
436    .scoreType = SCORETYPE_KO,
437    .callbackPriority = 3,
438    .matchData = 0,
439};
440EventDesc TechCounter = {
441    .eventName = "Ledgetech Marth Counter\n",
442    .eventDescription = "Practice ledgeteching\nMarth's counter!\n",
443    .eventFile = 0,
444    .jumpTableIndex = JUMP_LEDGETECHCOUNTER,
445    .CSSType = SLCHRKIND_EVENT,
446    .allowed_characters = {
447        .hmn = CSSID_FALCO | CSSID_FOX,
448        .cpu = -1,
449    },
450    .cpuKind = CKIND_MARTH,
451    .stage = -1,
452    .disable_hazards = true,
453    .force_sopo = false,
454    .scoreType = SCORETYPE_KO,
455    .callbackPriority = 3,
456    .matchData = 0,
457};
458
459static EventMatchData Edgeguard_MatchData = {
460    .timer = MATCH_TIMER_COUNTUP,
461    .matchType = MATCH_MATCHTYPE_TIME,
462    .hideGo = true,
463    .hideReady = true,
464    .isCreateHUD = true,
465    .timerRunOnPause = false,
466    .isCheckForZRetry = true,
467    .isShowScore = false,
468    .isRunStockLogic = false,
469    .isDisableHit = false,
470    .useKOCounter = false,
471    .timerSeconds = 0,
472};
473EventDesc Edgeguard = {
474    .eventName = "Edgeguard Training\n",
475    .eventDescription = "Finish off the enemy\nafter you hit them offstage!",
476    .eventFile = "edgeguard",
477    .jumpTableIndex = -1,
478    .CSSType = SLCHRKIND_TRAINING,
479    .allowed_characters = {
480        .hmn = -1,
481        .cpu = CSSID_FOX | CSSID_FALCO | CSSID_ZELDA | CSSID_CAPTAIN_FALCON
482            | CSSID_MARTH
483    },
484    .cpuKind = -1,
485    .stage = -1,
486    .disable_hazards = true,
487    .force_sopo = false,
488    .scoreType = SCORETYPE_KO,
489    .callbackPriority = 3,
490    .matchData = &Edgeguard_MatchData,
491};
492
493EventDesc EscapeSheik = {
494    .eventName = "Escape Sheik Techchase\n",
495    .eventDescription = "Practice escaping the tech chase with a\nframe perfect shine or jab SDI!\n",
496    .eventFile = 0,
497    .jumpTableIndex = JUMP_ESCAPESHIEK,
498    .CSSType = SLCHRKIND_EVENT,
499    .allowed_characters = {
500        .hmn = CSSID_YOSHI |  CSSID_CAPTAIN_FALCON |  CSSID_FALCO |  CSSID_FOX |  CSSID_PIKACHU,
501        .cpu = -1,
502    },
503    .cpuKind = CKIND_SHEIK,
504    .stage = GRKINDEXT_FD,
505    .disable_hazards = true,
506    .force_sopo = false,
507    .scoreType = SCORETYPE_KO,
508    .callbackPriority = 3,
509    .matchData = 0,
510};
511
512static EventMatchData Eggs_MatchData = {
513    .timer = MATCH_TIMER_COUNTDOWN,
514    .matchType = MATCH_MATCHTYPE_TIME,
515    .hideGo = false,
516    .hideReady = false,
517    .isCreateHUD = true,
518    .timerRunOnPause = false,
519    .isCheckForZRetry = true,
520    .isShowScore = false,
521    .isRunStockLogic = false,
522    .isDisableHit = false,
523    .useKOCounter = false,
524    .timerSeconds = 60,
525};
526
527EventDesc Eggs = {
528    .eventName = "Eggs-ercise \n",
529    .eventDescription = "Break the eggs! Only strong hits will\nbreak them. Start = more options.",
530    .eventFile = "eggs",
531    .jumpTableIndex = -1,
532    .CSSType = SLCHRKIND_EVENT,
533    .allowed_characters = { .hmn = -1, .cpu = -1 },
534    .cpuKind = -1,
535    .stage = -1,
536    .disable_hazards = true,
537    .force_sopo = false,
538    .scoreType = SCORETYPE_KO,
539    .callbackPriority = 3,
540    .matchData = &Eggs_MatchData,
541};
542
543EventDesc Multishine = {
544    .eventName = "Shined Blind\n",
545    .eventDescription = "How many shines can you\nperform in 10 seconds?",
546    .eventFile = 0,
547    .jumpTableIndex = JUMP_MULTISHINE,
548    .CSSType = SLCHRKIND_EVENT,
549    .allowed_characters = {
550        .hmn = CSSID_FALCO | CSSID_FOX,
551        .cpu = -1,
552    },
553    .cpuKind = -1,
554    .stage = GRKINDEXT_FD,
555    .disable_hazards = true,
556    .force_sopo = false,
557    .scoreType = SCORETYPE_KO,
558    .callbackPriority = 3,
559    .matchData = 0,
560};
561
562EventDesc Reaction = {
563    .eventName = "Reaction Test\n",
564    .eventDescription = "Test your reaction time by pressing\nany button when you see/hear Fox shine!",
565    .eventFile = 0,
566    .jumpTableIndex = JUMP_REACTION,
567    .CSSType = SLCHRKIND_EVENT,
568    .allowed_characters = { .hmn = -1, .cpu = -1 },
569    .cpuKind = CKIND_FOX,
570    .stage = GRKINDEXT_FD,
571    .disable_hazards = true,
572    .force_sopo = false,
573    .scoreType = SCORETYPE_KO,
574    .callbackPriority = 3,
575    .matchData = 0,
576};
577
578EventDesc Ledgestall = {
579    .eventName = "Under Fire\n",
580    .eventDescription = "Ledgestall to remain\ninvincible while the lava rises!\n",
581    .eventFile = 0,
582    .jumpTableIndex = JUMP_LEDGESTALL,
583    .CSSType = SLCHRKIND_EVENT,
584    .allowed_characters = { .hmn = -1, .cpu = -1 },
585    .cpuKind = -1,
586    .stage = GRKINDEXT_ZEBES,
587    .disable_hazards = true,
588    .force_sopo = false,
589    .scoreType = SCORETYPE_TIME,
590    .callbackPriority = 3,
591    .matchData = 0,
592};
593
594///////////////////////
595/// Page Defintions ///
596///////////////////////
597
598// Minigames
599static EventDesc *Minigames_Events[] = {
600    &Eggs,
601    &Multishine,
602    &Reaction,
603    &Ledgestall,
604};
605static EventPage Minigames_Page = {
606    .name = "Minigames",
607    .eventNum = countof(Minigames_Events),
608    .events = Minigames_Events,
609};
610
611// Page 2 Events
612static EventDesc *General_Events[] = {
613    &Lab,
614    &LCancel,
615    &Ledgedash,
616    &Wavedash,
617    &TechChase,
618    &Combo,
619    &AttackOnShield,
620    &Reversal,
621    &SDI,
622    &Powershield,
623    &Ledgetech,
624    &AmsahTech,
625    &ShieldDrop,
626    &WaveshineSDI,
627    &SlideOff,
628    &GrabMash,
629};
630static EventPage General_Page = {
631    .name = "General Tech",
632    .eventNum = countof(General_Events),
633    .events = General_Events,
634};
635
636// Page 3 Events
637static EventDesc *CharacterSpecific_Events[] = {
638    &TechCounter,
639    &Edgeguard,
640    &Sweetspot,
641    &EscapeSheik,
642    &FloatCancel,
643};
644static EventPage CharacterSpecific_Page = {
645    .name = "Character-specific Tech",
646    .eventNum = countof(CharacterSpecific_Events),
647    .events = CharacterSpecific_Events,
648};
649
650EventPage *EventPages[] = {
651    &Minigames_Page,
652    &General_Page,
653    &CharacterSpecific_Page,
654};
655
656////////////////////////
657/// Static Variables ///
658////////////////////////
659
660RNGControl rng;
661
662EventVars stc_event_vars = {
663    .event_desc = 0,
664    .menu_assets = 0,
665    .event_gobj = 0,
666    .menu_gobj = 0,
667    .rng = &rng,
668    .game_timer = 0,
669    .Savestate_Save_v1 = Savestate_Save_v1,
670    .Savestate_Load_v1 = Savestate_Load_v1,
671    .Message_Display = Message_Display,
672    .Tip_Display = Tip_Display,
673    .Tip_Destroy = Tip_Destroy,
674    .HUD_DrawRects = HUD_DrawRects,
675    .HUD_DrawText = HUD_DrawText,
676    .HUD_DrawActionLogBar = HUD_DrawActionLogBar,
677    .HUD_DrawActionLogKey = HUD_DrawActionLogKey,
678};
679
680static GOBJ *stc_msgmgr;
681static Savestate_v1 *stc_savestate;
682static TipMgr stc_tipmgr;
683
684static Vec2 stc_msg_queue_offsets_vertical[] = {
685    {0, 5.15f},
686    {0, 5.15f},
687    {0, 5.15f},
688    {0, 5.15f},
689    {0, 5.15f},
690    {0, 5.15f},
691    {0, -5.15f}
692};
693static Vec3 stc_msg_queue_pos_sides[] = {
694    {-22.f, -13.f, 0},
695    {-7.f, -13.f, 0},
696    {7.f, -13.f, 0},
697    {22.f, -13.f, 0},
698    {0, 0, 0},
699    {0, 0, 0},
700    {0, -5.15f, 0}
701};
702
703static Vec2 stc_msg_queue_offsets_horizontal[] = {
704    {12.5f, 0},
705    {12.5f, 0},
706    {12.5f, 0},
707    {12.5f, 0},
708    {12.5f, 0},
709    {12.5f, 0},
710    {-12.5f, 0},
711};
712static Vec3 stc_msg_queue_pos_top[] = {
713    {-22.f, 20.f, 0},
714    {-22.f, 14.f, 0},
715    {-22.f, 8.f, 0},
716    {-22.f, 2.f, 0},
717    {0, 0, 0},
718    {0, 0, 0},
719    {22.f, 20.f, 0}
720};
721static GXColor stc_msg_colors[] = {
722    {255, 255, 255, 255},
723    {141, 255, 110, 255},
724    {255, 162, 186, 255},
725    {255, 240, 0, 255},
726};
727
728//////////////////
729/// Primitives ///
730//////////////////
731
732void HUD_DrawRects(Rect *rects, GXColor *colors, int count)
733{
734    HUDCamData *cam_data = stc_event_vars.hudcam_gobj->userdata;
735    if (cam_data->hide)
736        return;
737
738    COBJ *cur_cam = COBJ_GetCurrent();
739    CObj_SetCurrent(stc_event_vars.hudcam_gobj->hsd_object);
740    
741    // https://smashboards.com/threads/primitive-drawing-module.454232/
742    // params1: no culling, no point/line size, no zbuffer, triangles
743    // params2: blending, blend src = src.a, blend dst = 1-src.a, noop blend op
744    PRIM_DrawMode draw_mode = {
745        .shape = PRIM_SHAPE_TRIANGLES,
746    };
747    PRIM_BlendMode blend_mode = {
748        .blend_type = PRIM_BLEND_BLEND,
749        .blend_src = PRIM_SOURCE_SRC_ALPHA,
750        .blend_dst = PRIM_SOURCE_SRC_INV_ALPHA,
751        .blend_logic = PRIM_LOGIC_NOOP,
752    };
753    PRIM_NEW(count * 6, draw_mode, blend_mode);
754    
755    for (int i = 0; i < count; ++i) {
756        GXColor gx_color = colors[i];
757        u32 color = ((u32)gx_color.r << 24u)
758            | ((u32)gx_color.g << 16u)
759            | ((u32)gx_color.b << 8u)
760            | ((u32)gx_color.a << 0u);
761        
762        Rect *rect = &rects[i];
763        float x1 = rect->x;
764        float y1 = rect->y;
765        float x2 = x1 + rect->w;
766        float y2 = y1 + rect->h;
767        
768        PRIM_DRAW(x1, y1, 0.f, color);
769        PRIM_DRAW(x1, y2, 0.f, color);
770        PRIM_DRAW(x2, y1, 0.f, color);
771        
772        PRIM_DRAW(x1, y2, 0.f, color);
773        PRIM_DRAW(x2, y1, 0.f, color);
774        PRIM_DRAW(x2, y2, 0.f, color);
775    }
776    
777    PRIM_CLOSE();
778    CObj_SetCurrent(cur_cam);
779}
780
781void HUD_DrawText(const char *text, Rect *pos, float size)
782{
783    HUDCamData *hud = stc_event_vars.hudcam_gobj->userdata;
784    
785    // skip if already used up entire text cache
786    if (hud->text_cache_used == countof(hud->text_cache))
787        return;
788
789    // create text if it doesn't exist
790    Text **text_ptr = &hud->text_cache[hud->text_cache_used++];
791    if (*text_ptr == 0) {
792        Text *new_text = Text_CreateText(2, hud->canvas);
793        *text_ptr = new_text;
794        new_text->kerning = 1;
795        new_text->align = 1;
796        new_text->use_aspect = 1;
797        new_text->aspect.X = 165;
798        new_text->viewport_scale.X = 0.1f;
799        new_text->viewport_scale.Y = 0.1f;
800        Text_AddSubtext(new_text, 0, 0, "");
801        Text_AddSubtext(new_text, 0, 0, "");
802        Text_AddSubtext(new_text, 0, 0, "");
803        Text_AddSubtext(new_text, 0, 0, "");
804        Text_AddSubtext(new_text, 0, 0, "");
805        
806        GXColor black = {0, 0, 0, 255};
807        for (int i = 0; i < 4; ++i)
808            Text_SetColor(new_text, i, &black);
809    }
810    
811    Text *hud_text = *text_ptr;
812    hud_text->hidden = false;
813    float x = pos->x * 10.f + pos->w * 5.f;
814    float y = pos->y * -10.f + pos->h * -5.f - 25.f;
815    for (int i = 0; i < 5; ++i) {
816        Text_SetText(hud_text, i, text);
817        Text_SetScale(hud_text, i, size, size);
818    }
819    float border_offset = 1.f;
820    Text_SetPosition(hud_text, 0, x-border_offset, y-border_offset);
821    Text_SetPosition(hud_text, 1, x+border_offset, y-border_offset);
822    Text_SetPosition(hud_text, 2, x-border_offset, y+border_offset);
823    Text_SetPosition(hud_text, 3, x+border_offset, y+border_offset);
824    Text_SetPosition(hud_text, 4, x, y);
825}
826
827static float log_size = 1.f;
828static float log_padding = 0.1f;
829static float log_y_pos = 15.f;
830static GXColor log_background_color = { 20, 20, 20, 255 };
831static float action_name_size = 4.5f;
832static float action_name_padding = 1.f;
833static float action_name_y_pos = 15.f;
834
835void HUD_DrawActionLogBar(u8 *action_log, GXColor *color_lookup, int log_count) {
836    Rect rects[log_count + 1];
837    GXColor colors[log_count + 1];
838    
839    float rect_count = (float)log_count;
840    float w = rect_count * log_size + (rect_count + 1.f) * log_padding;
841    
842    Rect background = { -w/2.f, log_y_pos, w, log_size + log_padding*2.f }; 
843    rects[0] = background;
844    colors[0] = log_background_color;
845    
846    RectShrink(&background, log_padding);
847    for (int i = 0; i < log_count; ++i) {
848        RectSplitL(&rects[i+1], &background, log_size, log_padding);
849        colors[i+1] = color_lookup[action_log[i]];
850    }
851    
852    HUD_DrawRects(rects, colors, log_count + 1);
853}
854    
855void HUD_DrawActionLogKey(char **action_names, GXColor *action_colors, int action_count) {
856    Rect rects[action_count*2];
857    GXColor colors[action_count*2];
858    
859    float w = action_count * action_name_size + (action_count + 1.f) * action_name_padding;
860    Rect action_table_row = { -w/2.f, action_name_y_pos, w, action_name_size + action_name_padding*2.f };
861    RectShrink(&action_table_row, action_name_padding);
862    
863    Rect cur_rect;
864    for (int i = 0; i < action_count; ++i) {
865        RectSplitL(&cur_rect, &action_table_row, action_name_size, action_name_padding);
866        HUD_DrawText(action_names[i], &cur_rect, 0.34f);
867        
868        colors[i*2+0] = log_background_color;
869        colors[i*2+1] = action_colors[i];
870        
871        cur_rect.y += 2.f;
872        RectShrink(&cur_rect, (action_name_size - log_size) / 2.f - log_padding);
873        rects[i*2+0] = cur_rect;
874        RectShrink(&cur_rect, log_padding);
875        rects[i*2+1] = cur_rect;
876    }
877    
878    HUD_DrawRects(rects, colors, action_count * 2);
879}
880
881///////////////////////
882/// Event Functions ///
883///////////////////////
884
885void EventInit(int page, int eventID, MatchInit *matchData)
886{
887
888    /*
889    This function runs when leaving the main menu/css and handles
890    setting up the match information, such as rules, players, stage.
891    All of this data comes from the EventDesc in events.c
892    */
893
894    // get event pointer
895    EventDesc *event = GetEventDesc(page, eventID);
896    EventMatchData *eventMatchData = event->matchData;
897
898    if (event->CSSType == SLCHRKIND_VS)
899        memcpy(matchData, &(*stc_css_minorscene)->vs_data.match_init, sizeof(*matchData));
900
901    //Init default match info
902    matchData->timer_unk2 = 0;
903    matchData->unk2 = 1;
904    matchData->unk7 = 1;
905    matchData->isCheckStockSteal = 1;
906    matchData->unk1f = 3;
907    matchData->no_check_end = 1;
908    matchData->itemFreq = MATCH_ITEMFREQ_OFF;
909    matchData->onStartMelee = EventLoad;
910    matchData->isCheckForLRAStart = true;
911    matchData->isHidePauseHUD = true;
912    matchData->isDisablePause = true;
913
914    //Copy event's match info struct
915    matchData->timer = eventMatchData->timer;
916    matchData->matchType = eventMatchData->matchType;
917    matchData->hideGo = eventMatchData->hideGo;
918    matchData->hideReady = eventMatchData->hideReady;
919    matchData->isCreateHUD = eventMatchData->isCreateHUD;
920    matchData->timerRunOnPause = eventMatchData->timerRunOnPause;
921    matchData->isCheckForZRetry = eventMatchData->isCheckForZRetry;
922    matchData->isShowScore = eventMatchData->isShowScore;
923    matchData->isRunStockLogic = eventMatchData->isRunStockLogic;
924    matchData->no_hit = eventMatchData->isDisableHit;
925    matchData->timer_seconds = eventMatchData->timerSeconds;
926
927    Preload *preload = Preload_GetTable();
928
929    if (event->CSSType != SLCHRKIND_VS) {
930        // Determine player ports
931        u8 hmn_port = *stc_css_hmnport + 1;
932        u8 cpu_port = *stc_css_cpuport + 1;
933
934        // Initialize all player data
935        for (int i = 0; i < 6; i++) {
936          CSS_InitPlayerData(&matchData->playerData[i]);
937          matchData->playerData[i].stocks = 1;
938        }
939
940        // Update the player's nametag ID and rumble
941        u8 nametag = stc_memcard->EventBackup.nametag;
942        matchData->playerData[0].nametag = nametag;
943        matchData->playerData[0].isRumble = CSS_GetNametagRumble(0, nametag);
944
945        // Determine the CPU
946        s32 cpu_kind = event->cpuKind;
947        s32 cpu_costume = 0;
948        if (cpu_kind == -1 && event->CSSType == SLCHRKIND_TRAINING) {
949            cpu_kind = preload->queued.fighters[1].kind;
950            cpu_costume = preload->queued.fighters[1].costume;
951        }
952
953        if (cpu_kind == CKIND_ZELDA)
954            cpu_kind = CKIND_SHEIK;
955
956        if (cpu_kind != -1) {
957            matchData->playerData[1].costume = cpu_costume;
958            matchData->playerData[1].c_kind = cpu_kind;
959            matchData->playerData[1].p_kind = PKIND_CPU;
960            matchData->playerData[1].portNumberOverride = cpu_port;
961        }
962        
963        matchData->playerData[0].c_kind = preload->queued.fighters[0].kind;
964        matchData->playerData[0].costume = preload->queued.fighters[0].costume;
965        matchData->playerData[0].p_kind = PKIND_HMN;
966        matchData->playerData[0].portNumberOverride = hmn_port;
967
968        // Force Popo if required
969        if (event->force_sopo && matchData->playerData[0].c_kind == CKIND_ICECLIMBERS)
970            matchData->playerData[0].c_kind = CKIND_POPO;
971
972        // Determine the correct HUD position for this amount of players
973        int hudPos = 0;
974        for (int i = 0; i < 6; i++)
975        {
976            if (matchData->playerData[i].p_kind != PKIND_NONE)
977                hudPos++;
978        }
979        matchData->hudPos = hudPos;
980    }
981
982    // set to enter fall on match start
983    for (int i = 0; i < 6; i++)
984        matchData->playerData[i].isEntry = false;
985
986    // Determine the Stage
987    if (event->stage == -1) {
988        matchData->stage = preload->queued.stage;
989    } else {
990        matchData->stage = event->stage;
991    }
992};
993
994void EventLoad(void)
995{
996    // get this event
997    int page = stc_memcard->TM_EventPage;
998    int eventID = stc_memcard->EventBackup.event;
999    EventDesc *event_desc = GetEventDesc(page, eventID);
1000    evFunction *evFunction = &stc_event_vars.evFunction;
1001
1002    // clear evFunction
1003    memset(evFunction, 0, sizeof(*evFunction));
1004
1005    // append extension
1006    static char *extension = "TM/%s.dat";
1007    char buffer[20];
1008    sprintf(buffer, extension, event_desc->eventFile);
1009
1010    // load this events file
1011    HSD_Archive *archive = MEX_LoadRelArchive(buffer, evFunction, "evFunction");
1012    stc_event_vars.event_archive = archive;
1013
1014    // Create this event's gobj
1015    int pri = event_desc->callbackPriority;
1016    void *cb = evFunction->Event_Think;
1017    GOBJ *gobj = GObj_Create(0, 7, 0);
1018    void *userdata = calloc(EVENT_DATASIZE);
1019    GObj_AddUserData(gobj, 4, HSD_Free, userdata);
1020    GObj_AddProc(gobj, cb, pri);
1021
1022    // store pointer to the event's data
1023    *(EventDesc **)userdata = event_desc;
1024
1025    // Create a gobj to track match time
1026    stc_event_vars.game_timer = 0;
1027    GOBJ *timer_gobj = GObj_Create(0, 7, 0);
1028    GObj_AddProc(timer_gobj, Event_IncTimer, 0);
1029
1030    // init savestate struct
1031    stc_savestate = calloc(sizeof(Savestate_v1));
1032    stc_savestate->is_exist = 0;
1033    stc_event_vars.savestate = stc_savestate;
1034
1035    // disable hazards if enabled
1036    if (event_desc->disable_hazards == 1)
1037        Hazards_Disable();
1038
1039    // Store update function
1040    HSD_Update *update = stc_hsd_update;
1041    update->onFrame = EventUpdate;
1042    
1043    // Init static structure containing event variables
1044    stc_event_vars.event_desc = event_desc;
1045    stc_event_vars.event_gobj = gobj;
1046
1047    // init the pause menu
1048    GOBJ *menu_gobj = EventMenu_Init(*evFunction->menu_start);
1049    stc_event_vars.menu_gobj = menu_gobj;
1050    
1051    // init HUD camera
1052    GOBJ *hudcam_gobj = GObj_Create(19, 20, 0);
1053    stc_event_vars.hudcam_gobj = hudcam_gobj;
1054    COBJDesc ***dmgScnMdls = Archive_GetPublicAddress(*stc_ifall_archive, (void *)0x803f94d0);
1055    COBJDesc *cam_desc = dmgScnMdls[1][0];
1056    COBJ *hud_cobj = COBJ_LoadDesc(cam_desc);
1057    HUDCamData *cam_data = HSD_MemAlloc(sizeof(HUDCamData));
1058    *cam_data = (HUDCamData) {
1059        .hide = false,
1060        .canvas = Text_CreateCanvas(2, hudcam_gobj, 14, 15, 0, GXLINK_HUD, 81, 19),
1061    };
1062    GObj_AddUserData(hudcam_gobj, 4, HSD_Free, cam_data);
1063    GObj_AddObject(hudcam_gobj, R13_U8(-0x3E55), hud_cobj);
1064    GOBJ_InitCamera(hudcam_gobj, HUD_CObjThink, 7);
1065    hudcam_gobj->cobj_links = 1 << GXLINK_HUD;
1066    
1067    // Run this event's init function
1068    if (evFunction->Event_Init)
1069        evFunction->Event_Init(gobj);
1070};
1071
1072void UpdateDevCamera(void)
1073{
1074    MatchCamera *cam = stc_matchcam;
1075
1076    // Return if camera not in develop mode
1077    if (cam->cam_kind != 8)
1078        return;
1079
1080    int pad_index = Fighter_GetControllerPort(0);
1081    HSD_Pad *pad = PadGetMaster(pad_index);
1082    int held = pad->held;
1083    float x = pad->fsubstickX;
1084    float y = pad->fsubstickY;
1085
1086    if (fabs(x) < 0.2)
1087        x = 0;
1088    if (fabs(y) < 0.2)
1089        y = 0;
1090
1091    if (x != 0 || y != 0)
1092    {
1093        COBJ *cobj = Match_GetCObj();
1094
1095        if (held & HSD_BUTTON_A)
1096            DevCam_AdjustPan(cobj, x * -1, y * -1);
1097        else if (held & HSD_BUTTON_Y)
1098            DevCam_AdjustZoom(cobj, y);
1099        else if (held & HSD_BUTTON_B)
1100            DevCam_AdjustRotate(cobj, &cam->devcam_rot, &cam->devcam_pos, x, y);
1101    }
1102}
1103
1104void EventUpdate(void)
1105{
1106    // reset text cache for this frame
1107    HUDCamData *hudcam_data = stc_event_vars.hudcam_gobj->userdata;
1108    hudcam_data->text_cache_used = 0;
1109    for (u32 i = 0; i < countof(hudcam_data->text_cache); ++i) {
1110        Text *t = hudcam_data->text_cache[i];
1111        if (t)
1112            t->hidden = true;
1113    }
1114    
1115    // get event info
1116    GOBJ *menu_gobj = stc_event_vars.menu_gobj;
1117    if (menu_gobj)
1118        EventMenu_Update(menu_gobj);
1119
1120    evFunction *evFunction = &stc_event_vars.evFunction;
1121    if (evFunction->Event_Update)
1122        evFunction->Event_Update();
1123
1124    UpdateDevCamera();
1125
1126    // This is the vanilla callback. This code handles the vanilla develop.
1127    // mode shortcuts. We could probably delete it if we want to.
1128    Develop_UpdateMatchHotkeys();
1129}
1130
1131//////////////////////
1132/// Hook Functions ///
1133//////////////////////
1134
1135void TM_ConsoleToggle(GOBJ *gobj)
1136{
1137    DevText *text = gobj->userdata;
1138    text->show_text ^= 1;
1139    text->show_background ^= 1;
1140}
1141
1142void TM_ConsoleThink(GOBJ *gobj)
1143{
1144    // Toggle console with L/R + Z
1145    for (int i = 0; i < 4; i++)
1146    {
1147        HSD_Pad *pad = PadGetMaster(i);
1148        if (pad->held & (HSD_TRIGGER_L | HSD_TRIGGER_R) && (pad->down & HSD_TRIGGER_Z))
1149        {
1150            TM_ConsoleToggle(gobj);
1151            break;
1152        }
1153    }
1154}
1155void TM_CreateConsole(void)
1156{
1157    // init dev text
1158    DevText *text = DevelopText_CreateDataTable(13, 0, 0, 32, 32, HSD_MemAlloc(0x1000));
1159    DevelopText_Activate(0, text);
1160    text->show_cursor = 0;
1161    text->show_text = 0;
1162    text->show_background = 0;
1163
1164    GOBJ *gobj = GObj_Create(0, 0, 0);
1165    GObj_AddUserData(gobj, 4, HSD_Free, text);
1166    GObj_AddProc(gobj, TM_ConsoleThink, 0);
1167
1168    GXColor color = {21, 20, 59, 80};
1169    DevelopText_StoreBGColor(text, &color);
1170    DevelopText_StoreTextScale(text, 10, 12);
1171    stc_event_vars.db_console_text = text;
1172    TM_ConsoleToggle(gobj);
1173}
1174
1175void OnFileLoad(HSD_Archive *archive) // this function is run right after TmDt is loaded into memory on boot
1176{
1177    // init event menu assets
1178    stc_event_vars.menu_assets = Archive_GetPublicAddress(archive, "eventMenu");
1179
1180    // store pointer to static variables
1181    *event_vars_ptr_loc = &stc_event_vars;
1182}
1183
1184void OnSceneChange(void)
1185{
1186    // Hook exists at 801a4c94
1187    TM_CreateWatermark();
1188
1189#if TM_DEBUG
1190    TM_CreateConsole();
1191#endif
1192};
1193
1194void OnBoot(void)
1195{
1196    // OSReport("hi this is boot\n");
1197};
1198
1199void OnStartMelee(void)
1200{
1201    Message_Init();
1202    Tip_Init();
1203}
1204
1205///////////////////////////////
1206/// Miscellaneous Functions ///
1207///////////////////////////////
1208
1209GOBJ *GOBJToID(GOBJ *gobj)
1210{
1211    // ensure valid pointer
1212    if (gobj == 0)
1213        return (GOBJ *)-1;
1214
1215    // ensure its a fighter
1216    if (gobj->entity_class != 4)
1217        return (GOBJ *)-1;
1218
1219    // access the data
1220    FighterData *ft_data = gobj->userdata;
1221    u8 ply = ft_data->ply;
1222    u8 ms = ft_data->flags.ms;
1223
1224    return (GOBJ *)((ply << 4) | ms);
1225}
1226FighterData *FtDataToID(FighterData *fighter_data)
1227{
1228    // ensure valid pointer
1229    if (fighter_data == 0)
1230        return (FighterData *)-1;
1231
1232    // ensure its a fighter
1233    if (fighter_data->fighter == 0)
1234        return (FighterData *)-1;
1235
1236    // get ply and ms
1237    u8 ply = fighter_data->ply;
1238    u8 ms = fighter_data->flags.ms;
1239
1240    return (FighterData *)((ply << 4) | ms);
1241}
1242JOBJ *BoneToID(FighterData *fighter_data, JOBJ *bone)
1243{
1244    // ensure bone exists
1245    if (bone == 0)
1246        return (JOBJ *)-1;
1247
1248    int bone_id = -1;
1249
1250    // painstakingly look for a match
1251    for (int i = 0; i < fighter_data->bone_num; i++)
1252    {
1253        if (bone == fighter_data->bones[i].joint)
1254        {
1255            bone_id = i;
1256            break;
1257        }
1258    }
1259
1260    // no bone found
1261    if (bone_id == -1)
1262        TMLOG("no bone found %x\n", bone);
1263
1264    return (JOBJ *)bone_id;
1265}
1266GOBJ *IDToGOBJ(GOBJ *id_as_ptr)
1267{
1268    int id = (int)id_as_ptr;
1269
1270    // ensure valid pointer
1271    if (id == -1)
1272        return (GOBJ *)0;
1273
1274    // get ply and ms
1275    u8 ply = (id >> 4) & 0xF;
1276    u8 ms = id & 0xF;
1277
1278    // get the gobj for this fighter
1279    GOBJ *gobj = Fighter_GetSubcharGObj(ply, ms);
1280
1281    return gobj;
1282}
1283FighterData *IDToFtData(FighterData *id_as_ptr)
1284{
1285    int id = (int)id_as_ptr;
1286
1287    // ensure valid pointer
1288    if (id == -1)
1289        return 0;
1290
1291    // get ply and ms
1292    u8 ply = (id >> 4) & 0xF;
1293    u8 ms = id & 0xF;
1294
1295    // get the gobj for this fighter
1296    GOBJ *gobj = Fighter_GetSubcharGObj(ply, ms);
1297    FighterData *fighter_data = gobj->userdata;
1298
1299    return fighter_data;
1300}
1301JOBJ *IDToBone(FighterData *fighter_data, JOBJ *id_as_ptr)
1302{
1303    int id = (int)id_as_ptr;
1304
1305    // ensure valid pointer
1306    if (id == -1)
1307        return 0;
1308
1309    // get the bone
1310    JOBJ *bone = fighter_data->bones[id].joint;
1311
1312    return bone;
1313}
1314
1315void Event_IncTimer(GOBJ *gobj)
1316{
1317    stc_event_vars.game_timer++;
1318}
1319void TM_CreateWatermark(void)
1320{
1321    // create text canvas
1322    int canvas = Text_CreateCanvas(10, 0, 9, 13, 0, 14, 0, 19);
1323    
1324    // create text
1325    Text *text = Text_CreateText(10, canvas);
1326    // enable align and kerning
1327    text->align = 2;
1328    text->kerning = 1;
1329    // scale canvas
1330    text->viewport_scale.X = 0.4;
1331    text->viewport_scale.Y = 0.4;
1332    text->trans.X = 615;
1333    text->trans.Y = 446;
1334
1335    // print string
1336    int shadow = Text_AddSubtext(text, 2, 2, TM_VersShort);
1337    GXColor shadow_color = {0, 0, 0, 0};
1338    Text_SetColor(text, shadow, &shadow_color);
1339
1340    int shadow1 = Text_AddSubtext(text, 2, -2, TM_VersShort);
1341    Text_SetColor(text, shadow1, &shadow_color);
1342
1343    int shadow2 = Text_AddSubtext(text, -2, 2, TM_VersShort);
1344    Text_SetColor(text, shadow2, &shadow_color);
1345
1346    int shadow3 = Text_AddSubtext(text, -2, -2, TM_VersShort);
1347    Text_SetColor(text, shadow3, &shadow_color);
1348
1349    Text_AddSubtext(text, 0, 0, TM_VersShort);
1350
1351    stc_event_vars.watermark = text;
1352}
1353void Hazards_Disable(void)
1354{
1355    // get stage id
1356    int stage_internal = Stage_ExternalToInternal(Stage_GetExternalID());
1357    int is_fixwind = 0;
1358
1359    switch (stage_internal)
1360    {
1361    case (GRKIND_STORY):
1362    {
1363        // remove shyguy map gobj proc
1364        GOBJ *shyguy_gobj = Stage_GetMapGObj(3);
1365        GObj_RemoveProc(shyguy_gobj);
1366
1367        // remove randall
1368        GOBJ *randall_gobj = Stage_GetMapGObj(2);
1369        Stage_DestroyMapGObj(randall_gobj);
1370
1371        is_fixwind = 1;
1372
1373        break;
1374    }
1375    case (GRKIND_PSTAD):
1376    {
1377        // remove map gobj proc
1378        GOBJ *map_gobj = Stage_GetMapGObj(2);
1379        GObj_RemoveProc(map_gobj);
1380
1381        is_fixwind = 1;
1382
1383        break;
1384    }
1385    case (GRKIND_OLDPU):
1386    {
1387        // remove map gobj proc
1388        GOBJ *map_gobj = Stage_GetMapGObj(7);
1389        GObj_RemoveProc(map_gobj);
1390
1391        // remove map gobj proc
1392        map_gobj = Stage_GetMapGObj(6);
1393        GObj_RemoveProc(map_gobj);
1394
1395        // set wind hazard num to 0
1396        *ftchkdevice_windnum = 0;
1397
1398        break;
1399    }
1400    case (GRKIND_FD):
1401    {
1402        // set bg skip flag
1403        GOBJ *map_gobj = Stage_GetMapGObj(3);
1404        MapData *map_data = map_gobj->userdata;
1405        map_data->xc4 |= 0x40;
1406
1407        // remove on-go function that changes this flag
1408        StageOnGO *on_go = stc_stage->on_go;
1409        stc_stage->on_go = on_go->next;
1410        HSD_Free(on_go);
1411
1412        break;
1413    }
1414    }
1415
1416    // Certain stages have an essential ragdoll function
1417    // in their map_gobj think function. If the think function is removed,
1418    // the ragdoll function must be re-scheduled to function properly.
1419    if (is_fixwind == 1)
1420    {
1421        GOBJ *wind_gobj = GObj_Create(3, 5, 0);
1422        GObj_AddProc(wind_gobj, Dynamics_DecayWind, 4);
1423    }
1424}
1425
1426// Message Functions
1427void Message_Init(void)
1428{
1429    // create cobj
1430    GOBJ *cam_gobj = GObj_Create(19, 20, 0);
1431    COBJDesc *cam_desc = stc_event_vars.menu_assets->hud_cobjdesc;
1432    COBJ *cam_cobj = COBJ_LoadDescSetScissor(cam_desc);
1433    cam_cobj->scissor_bottom = 400;
1434    // init camera
1435    GObj_AddObject(cam_gobj, R13_U8(-0x3E55), cam_cobj);
1436    GOBJ_InitCamera(cam_gobj, Message_CObjThink, MSG_COBJLGXPRI);
1437    cam_gobj->cobj_links = MSG_COBJLGXLINKS;
1438
1439    // Create manager GOBJ
1440    GOBJ *mgr_gobj = GObj_Create(0, 7, 0);
1441    MsgMngrData *mgr_data = calloc(sizeof(MsgMngrData));
1442    GObj_AddUserData(mgr_gobj, 4, HSD_Free, mgr_data);
1443    GObj_AddProc(mgr_gobj, Message_Manager, 18);
1444
1445    // create text canvas
1446    int canvas = Text_CreateCanvas(2, mgr_gobj, 14, 15, 0, MSG_GXLINK, MSGTEXT_GXPRI, 19);
1447    mgr_data->canvas = canvas;
1448
1449    // store cobj
1450    mgr_data->cobj = cam_cobj;
1451
1452    // store gobj pointer
1453    stc_msgmgr = mgr_gobj;
1454}
1455GOBJ *Message_Display(int msg_kind, int queue_num, int msg_color, char *format, ...)
1456{
1457
1458    va_list args;
1459
1460    MsgMngrData *mgr_data = stc_msgmgr->userdata;
1461
1462    // Create GOBJ
1463    GOBJ *msg_gobj = GObj_Create(0, 7, 0);
1464    MsgData *msg_data = calloc(sizeof(MsgData));
1465    GObj_AddUserData(msg_gobj, 4, HSD_Free, msg_data);
1466    GObj_AddGXLink(msg_gobj, GXLink_Common, MSG_GXLINK, MSG_GXPRI);
1467    JOBJ *msg_jobj = JOBJ_LoadJoint(stc_event_vars.menu_assets->message);
1468    GObj_AddObject(msg_gobj, R13_U8(-0x3E55), msg_jobj);
1469    msg_data->lifetime = MSG_LIFETIME;
1470    msg_data->kind = msg_kind;
1471    msg_data->state = MSGSTATE_SHIFT;
1472    msg_data->anim_timer = MSGTIMER_SHIFT;
1473    msg_jobj->scale.X = MSGJOINT_SCALE;
1474    msg_jobj->scale.Y = MSGJOINT_SCALE;
1475    msg_jobj->scale.Z = MSGJOINT_SCALE;
1476    msg_jobj->trans.X = MSGJOINT_X;
1477    msg_jobj->trans.Y = MSGJOINT_Y;
1478    msg_jobj->trans.Z = MSGJOINT_Z;
1479
1480    // Create text object
1481    Text *msg_text = Text_CreateText(2, mgr_data->canvas);
1482    msg_data->text = msg_text;
1483    msg_text->kerning = 1;
1484    msg_text->align = 1;
1485    msg_text->use_aspect = 1;
1486    msg_text->color = stc_msg_colors[msg_color];
1487
1488    // adjust scale
1489    Vec3 scale = msg_jobj->scale;
1490    // background scale
1491    msg_jobj->scale = scale;
1492    // text scale
1493    msg_text->viewport_scale.X = (scale.X * 0.01) * MSGTEXT_BASESCALE;
1494    msg_text->viewport_scale.Y = (scale.Y * 0.01) * MSGTEXT_BASESCALE;
1495    msg_text->aspect.X = MSGTEXT_BASEWIDTH;
1496
1497    JOBJ_SetMtxDirtySub(msg_jobj);
1498
1499    // build string
1500    char buffer[(MSG_LINEMAX * MSG_CHARMAX) + 1];
1501    va_start(args, format);
1502    vsprintf(buffer, format, args);
1503    va_end(args);
1504    char *msg = buffer;
1505
1506    // count newlines
1507    int line_num = 1;
1508    int line_length_arr[MSG_LINEMAX];
1509    char *msg_cursor_prev, *msg_cursor_curr; // declare char pointers
1510    msg_cursor_prev = msg;
1511    msg_cursor_curr = strchr(msg_cursor_prev, '\n'); // check for occurrence
1512    while (msg_cursor_curr != 0)                     // if occurrence found, increment values
1513    {
1514        // check if exceeds max lines
1515        if (line_num >= MSG_LINEMAX)
1516            assert("MSG_LINEMAX exceeded!");
1517
1518        // Save information about this line
1519        line_length_arr[line_num - 1] = msg_cursor_curr - msg_cursor_prev; // determine length of the line
1520        line_num++;                                                        // increment number of newlines found
1521        msg_cursor_prev = msg_cursor_curr + 1;                             // update prev cursor
1522        msg_cursor_curr = strchr(msg_cursor_prev, '\n');                   // check for another occurrence
1523    }
1524
1525    // get last lines length
1526    msg_cursor_curr = strchr(msg_cursor_prev, 0);
1527    line_length_arr[line_num - 1] = msg_cursor_curr - msg_cursor_prev;
1528
1529    // copy each line to an individual char array
1530    for (int i = 0; i < line_num; i++)
1531    {
1532
1533        // check if over char max
1534        u8 line_length = line_length_arr[i];
1535        if (line_length > MSG_CHARMAX)
1536            assert("MSG_CHARMAX exceeded!");
1537
1538        // copy char array
1539        char msg_line[MSG_CHARMAX + 1];
1540        memcpy(msg_line, msg, line_length);
1541
1542        // add null terminator
1543        msg_line[line_length] = '\0';
1544
1545        // increment msg
1546        msg += (line_length + 1); // +1 to skip past newline
1547
1548        // print line
1549        int y_base = (line_num - 1) * ((-1 * MSGTEXT_YOFFSET) / 2);
1550        int y_delta = (i * MSGTEXT_YOFFSET);
1551        Text_AddSubtext(msg_text, 0, y_base + y_delta, msg_line);
1552    }
1553
1554    // Add to queue
1555    Message_Add(msg_gobj, queue_num);
1556
1557    return msg_gobj;
1558}
1559void Message_Manager(GOBJ *mngr_gobj)
1560{
1561    MsgMngrData *mgr_data = mngr_gobj->userdata;
1562
1563    // Iterate through each queue
1564    for (int i = 0; i < MSGQUEUE_NUM; i++)
1565    {
1566        GOBJ **msg_queue = mgr_data->msg_queue[i];
1567
1568        // anim update (time based logic)
1569        for (int j = (MSGQUEUE_SIZE - 2); j >= 0; j--) // iterate through backwards (because deletions)
1570        {
1571            GOBJ *this_msg_gobj = msg_queue[j];
1572
1573            // if message exists
1574            if (this_msg_gobj != 0)
1575            {
1576                MsgData *this_msg_data = this_msg_gobj->userdata;
1577
1578                // check if the message moved this frame
1579                if (this_msg_data->orig_index != j)
1580                {
1581                    this_msg_data->orig_index = j;              // moved so update this
1582                    this_msg_data->state = MSGSTATE_SHIFT;      // enter shift
1583                    this_msg_data->anim_timer = MSGTIMER_SHIFT; // shift timer
1584                }
1585
1586                // decrement state timer if above 0
1587                if (this_msg_data->anim_timer > 0)
1588                    this_msg_data->anim_timer--;
1589
1590                switch (this_msg_data->state)
1591                {
1592                case (MSGSTATE_WAIT):
1593                case (MSGSTATE_SHIFT):
1594                {
1595
1596                    // increment alive time
1597                    this_msg_data->alive_timer++;
1598
1599                    // if lifetime is ended, enter delete state
1600                    if (this_msg_data->alive_timer >= this_msg_data->lifetime)
1601                    {
1602                        // if using frame advance, instantly remove this message
1603                        if (Pause_CheckStatus(0) == 1)
1604                        {
1605                            Message_Destroy(msg_queue, j);
1606                        }
1607                        else
1608                        {
1609                            this_msg_data->state = MSGSTATE_DELETE;
1610                            this_msg_data->anim_timer = MSGTIMER_DELETE;
1611                        }
1612                    }
1613
1614                    break;
1615                }
1616
1617                case (MSGSTATE_DELETE):
1618                {
1619
1620                    // if timer is ended, remove the message
1621                    if ((this_msg_data->anim_timer <= 0))
1622                    {
1623                        Message_Destroy(msg_queue, j);
1624                    }
1625
1626                    break;
1627                }
1628                }
1629            }
1630        }
1631
1632        // position update (update messages' onscreen positions)
1633        for (int j = 0; j < MSGQUEUE_SIZE; j++)
1634        {
1635            GOBJ *this_msg_gobj = msg_queue[j];
1636
1637            // if message exists
1638            if (this_msg_gobj != 0)
1639            {
1640                MsgData *this_msg_data = this_msg_gobj->userdata;
1641                Text *this_msg_text = this_msg_data->text;
1642                JOBJ *this_msg_jobj = this_msg_gobj->hsd_object;
1643
1644                int osd_pos_type = stc_memcard->TM_OSDPosition;
1645                if (osd_pos_type > 3)
1646                    osd_pos_type = 0;
1647
1648                Vec3 base_pos;
1649                Vec2 pos_delta;
1650
1651                if (osd_pos_type == 0) {
1652                    // above hud
1653                    Vec3 *hud_pos = Match_GetPlayerHUDPos(i);
1654
1655                    base_pos.X = hud_pos->X;
1656                    base_pos.Y = hud_pos->Y + MSG_HUDYOFFSET;
1657                    base_pos.Z = hud_pos->Z;
1658                    pos_delta = stc_msg_queue_offsets_vertical[i];
1659                } else if (osd_pos_type == 1) {
1660                    // sides
1661                    base_pos = stc_msg_queue_pos_sides[i];
1662                    pos_delta = stc_msg_queue_offsets_vertical[i];
1663                } else {
1664                    // top
1665                    base_pos = stc_msg_queue_pos_top[i];
1666                    pos_delta = stc_msg_queue_offsets_horizontal[i];
1667                    if (osd_pos_type == 3) {
1668                        // top right
1669                        base_pos.X *= -1;
1670                        pos_delta.X *= -1;
1671                    }
1672                }
1673
1674                // Get the onscreen position for this queue
1675                //float pos_delta = stc_msg_queue_offsets[i];
1676
1677                Vec3 this_msg_pos = {0, 0, 0};
1678
1679                switch (this_msg_data->state)
1680                {
1681                case (MSGSTATE_WAIT):
1682                case (MSGSTATE_SHIFT):
1683                {
1684
1685                    // get time
1686                    float t = ((float)MSGTIMER_SHIFT - this_msg_data->anim_timer) / MSGTIMER_SHIFT;
1687
1688                    // get initial and final position for animation
1689                    float final_x = base_pos.X + (float)j * pos_delta.X;
1690                    float final_y = base_pos.Y + (float)j * pos_delta.Y;
1691                    float initial_x = base_pos.X + (float)this_msg_data->prev_index * pos_delta.X;
1692                    float initial_y = base_pos.Y + (float)this_msg_data->prev_index * pos_delta.Y;
1693                    if (Pause_CheckStatus(0) == 1) { // if using frame advance, do not animate
1694                        this_msg_pos.X = final_x;
1695                        this_msg_pos.Y = final_y;
1696                    } else {
1697                        this_msg_pos.X = smooth_lerp(t, initial_x, final_x);
1698                        this_msg_pos.Y = smooth_lerp(t, initial_y, final_y);
1699                    }
1700
1701                    Vec3 scale = this_msg_jobj->scale;
1702
1703                    // BG position
1704                    this_msg_jobj->trans.X = this_msg_pos.X;
1705                    this_msg_jobj->trans.Y = this_msg_pos.Y;
1706                    // text position
1707                    this_msg_text->trans.X = this_msg_pos.X + (MSGTEXT_BASEX * (scale.X / 4.0));
1708                    this_msg_text->trans.Y = (this_msg_pos.Y * -1) + (MSGTEXT_BASEY * (scale.Y / 4.0));
1709
1710                    // adjust bar
1711                    JOBJ *bar;
1712                    JOBJ_GetChild(this_msg_jobj, &bar, 4, -1);
1713                    bar->trans.X = (float)(this_msg_data->lifetime - this_msg_data->alive_timer) / (float)this_msg_data->lifetime;
1714
1715                    break;
1716                }
1717                case (MSGSTATE_DELETE):
1718                {
1719                    // get time
1720                    float t = ((this_msg_data->anim_timer) / (float)MSGTIMER_DELETE);
1721
1722                    Vec3 *scale = &this_msg_jobj->scale;
1723                    Vec3 *pos = &this_msg_jobj->trans;
1724
1725                    // BG scale
1726                    scale->Y = smooth_lerp(t,  0.0, 1.0);
1727                    // text scale
1728                    this_msg_text->viewport_scale.Y = (scale->Y * 0.01) * MSGTEXT_BASESCALE;
1729                    // text position
1730                    this_msg_text->trans.Y = (pos->Y * -1) + (MSGTEXT_BASEY * (scale->Y / 4.0));
1731
1732                    break;
1733                }
1734                }
1735
1736                JOBJ_SetMtxDirtySub(this_msg_jobj);
1737            }
1738        }
1739    }
1740}
1741void Message_Destroy(GOBJ **msg_queue, int msg_num)
1742{
1743
1744    GOBJ *msg_gobj = msg_queue[msg_num];
1745    MsgData *msg_data = msg_gobj->userdata;
1746
1747    // Destroy text
1748    Text *text = msg_data->text;
1749    if (text != 0)
1750        Text_Destroy(text);
1751
1752    // Destroy GOBJ
1753    GObj_Destroy(msg_gobj);
1754
1755    // null pointer
1756    msg_queue[msg_num] = 0;
1757
1758    // shift others
1759    for (int i = (msg_num); i < (MSGQUEUE_SIZE - 1); i++)
1760    {
1761        msg_queue[i] = msg_queue[i + 1];
1762
1763        // update its prev pos
1764        GOBJ *this_msg_gobj = msg_queue[i];
1765        if (this_msg_gobj != 0)
1766        {
1767            MsgData *this_msg_data = this_msg_gobj->userdata;
1768            if (this_msg_data != 0)
1769                this_msg_data->prev_index = i + 1; // prev position
1770        }
1771    }
1772}
1773void Message_Add(GOBJ *msg_gobj, int queue_num)
1774{
1775
1776    MsgData *msg_data = msg_gobj->userdata;
1777    MsgMngrData *mgr_data = stc_msgmgr->userdata;
1778    GOBJ **msg_queue = mgr_data->msg_queue[queue_num];
1779
1780    // ensure this queue exists
1781    if (queue_num >= MSGQUEUE_NUM)
1782        assert("queue_num over!");
1783
1784    // msg kind -1 always sticks around
1785    if (msg_data->kind != -1) {
1786        // remove any existing messages of this kind
1787        for (int i = 0; i < MSGQUEUE_SIZE; i++)
1788        {
1789            GOBJ *this_msg_gobj = msg_queue[i];
1790
1791            // if it exists
1792            if (this_msg_gobj != 0)
1793            {
1794                MsgData *this_msg_data = this_msg_gobj->userdata;
1795
1796                // Remove this message if its of the same kind
1797                if ((this_msg_data->kind == msg_data->kind))
1798                {
1799
1800                    Message_Destroy(msg_queue, i); // remove the message and shift others
1801
1802                    // if the message we're replacing is the most recent message, instantly
1803                    // remove the old one and do not animate the new one
1804                    if (i == 0)
1805                    {
1806                        msg_data->state = MSGSTATE_WAIT;
1807                        msg_data->anim_timer = 0;
1808                    }
1809                }
1810            }
1811        }
1812    }
1813
1814    // first remove last message in the queue
1815    if (msg_queue[MSGQUEUE_SIZE - 1] != 0)
1816    {
1817        Message_Destroy(msg_queue, MSGQUEUE_SIZE - 1);
1818    }
1819
1820    // shift other messages
1821    for (int i = (MSGQUEUE_SIZE - 2); i >= 0; i--)
1822    {
1823        // shift message
1824        msg_queue[i + 1] = msg_queue[i];
1825
1826        // update its prev pos
1827        GOBJ *this_msg_gobj = msg_queue[i + 1];
1828        if (this_msg_gobj != 0)
1829        {
1830            MsgData *this_msg_data = this_msg_gobj->userdata;
1831            this_msg_data->prev_index = i; // prev position
1832        }
1833    }
1834
1835    // add this new message
1836    msg_queue[0] = msg_gobj;
1837
1838    // set prev pos to -1 (slides in)
1839    msg_data->prev_index = -1;
1840    msg_data->orig_index = 0;
1841}
1842void HUD_CObjThink(GOBJ *gobj)
1843{
1844    HUDCamData *cam = gobj->userdata;
1845    if (!cam->hide && Pause_CheckStatus(1) != 2)
1846        CObjThink_Common(gobj);
1847}
1848void Message_CObjThink(GOBJ *gobj)
1849{
1850    if (Pause_CheckStatus(1) != 2)
1851        CObjThink_Common(gobj);
1852}
1853
1854// Tips Functions
1855void Tip_Init(void)
1856{
1857    // init static struct
1858    memset(&stc_tipmgr, 0, sizeof(TipMgr));
1859
1860    // create tipmgr gobj
1861    GOBJ *tipmgr_gobj = GObj_Create(0, 7, 0);
1862    GObj_AddProc(tipmgr_gobj, Tip_Think, 18);
1863}
1864void Tip_Think(GOBJ *gobj)
1865{
1866
1867    GOBJ *tip_gobj = stc_tipmgr.gobj;
1868
1869    // update tip
1870    if (tip_gobj != 0)
1871    {
1872
1873        // update anim
1874        JOBJ_AnimAll(tip_gobj->hsd_object);
1875
1876        // update text position
1877        JOBJ *tip_jobj;
1878        Vec3 tip_pos;
1879        JOBJ_GetChild(tip_gobj->hsd_object, &tip_jobj, TIP_TXTJOINT, -1);
1880        JOBJ_GetWorldPosition(tip_jobj, 0, &tip_pos);
1881        Text *tip_text = stc_tipmgr.text;
1882        tip_text->trans.X = tip_pos.X + (0 * (tip_jobj->scale.X / 4.0));
1883        tip_text->trans.Y = (tip_pos.Y * -1) + (0 * (tip_jobj->scale.Y / 4.0));
1884
1885        // state logic
1886        switch (stc_tipmgr.state)
1887        {
1888        case (0): // in
1889        {
1890            // if anim is done, enter wait
1891            if (JOBJ_CheckAObjEnd(tip_gobj->hsd_object) == 0)
1892                stc_tipmgr.state = 1; // enter wait
1893
1894            break;
1895        }
1896        case (1): // wait
1897        {
1898            // sub timer
1899            stc_tipmgr.lifetime--;
1900            if (stc_tipmgr.lifetime <= 0)
1901            {
1902                // apply exit anim
1903                JOBJ *tip_root = tip_gobj->hsd_object;
1904                JOBJ_RemoveAnimAll(tip_root);
1905                JOBJ_AddAnimAll(tip_root, stc_event_vars.menu_assets->tip_jointanim[1], 0, 0);
1906                JOBJ_ReqAnimAll(tip_root, 0);
1907
1908                stc_tipmgr.state = 2; // enter wait
1909            }
1910
1911            break;
1912        }
1913        case (2): // out
1914        {
1915            // if anim is done, destroy
1916            if (JOBJ_CheckAObjEnd(tip_gobj->hsd_object) == 0)
1917            {
1918                // remove text
1919                Text_Destroy(stc_tipmgr.text);
1920                GObj_Destroy(stc_tipmgr.gobj);
1921                stc_tipmgr.gobj = 0;
1922            }
1923            break;
1924        }
1925        }
1926    }
1927}
1928int Tip_Display(int lifetime, char *fmt, ...)
1929{
1930
1931#define TIP_TXTSIZE 4.7
1932#define TIP_TXTSIZEX TIP_TXTSIZE * 0.85
1933#define TIP_TXTSIZEY TIP_TXTSIZE
1934#define TIP_TXTASPECT 2430
1935#define TIP_LINEMAX 5
1936#define TIP_CHARMAX 48
1937
1938    va_list args;
1939
1940    // if tip exists
1941    if (stc_tipmgr.gobj != 0)
1942    {
1943        // if tip is in the process of exiting
1944        if (stc_tipmgr.state == 2)
1945        {
1946            // remove text
1947            Text_Destroy(stc_tipmgr.text);
1948            GObj_Destroy(stc_tipmgr.gobj);
1949            stc_tipmgr.gobj = 0;
1950        }
1951        // if is active onscreen do nothing
1952        else
1953            return 0;
1954    }
1955
1956    MsgMngrData *msgmngr_data = stc_msgmgr->userdata; // using message canvas cause there are so many god damn text canvases
1957
1958    // Create bg
1959    GOBJ *tip_gobj = GObj_Create(0, 0, 0);
1960    stc_tipmgr.gobj = tip_gobj;
1961    GObj_AddGXLink(tip_gobj, GXLink_Common, MSG_GXLINK, 80);
1962    JOBJ *tip_jobj = JOBJ_LoadJoint(stc_event_vars.menu_assets->tip_jobj);
1963    GObj_AddObject(tip_gobj, R13_U8(-0x3E55), tip_jobj);
1964
1965    // account for widescreen
1966    /*
1967    float aspect = (msgmngr_data->cobj->projection_param.perspective.aspect / 1.216667) - 1;
1968    tip_jobj->trans.X += (tip_jobj->trans.X * aspect);
1969    JOBJ_SetMtxDirtySub(tip_jobj);
1970    */
1971
1972    // Create text object
1973    Text *tip_text = Text_CreateText(2, msgmngr_data->canvas);
1974    stc_tipmgr.text = tip_text;
1975    stc_tipmgr.lifetime = lifetime;
1976    stc_tipmgr.state = 0;
1977    tip_text->kerning = 1;
1978    tip_text->align = 0;
1979    tip_text->use_aspect = 1;
1980
1981    // adjust text scale
1982    Vec3 scale = tip_jobj->scale;
1983    // background scale
1984    tip_jobj->scale = scale;
1985    // text scale
1986    tip_text->viewport_scale.X = (scale.X * 0.01) * TIP_TXTSIZEX;
1987    tip_text->viewport_scale.Y = (scale.Y * 0.01) * TIP_TXTSIZEY;
1988    tip_text->aspect.X = (TIP_TXTASPECT / TIP_TXTSIZEX);
1989
1990    // apply enter anim
1991    JOBJ_RemoveAnimAll(tip_jobj);
1992    JOBJ_AddAnimAll(tip_jobj, stc_event_vars.menu_assets->tip_jointanim[0], 0, 0);
1993    JOBJ_ReqAnimAll(tip_jobj, 0);
1994
1995    // build string
1996    char buffer[(TIP_LINEMAX * TIP_CHARMAX) + 1];
1997    va_start(args, fmt);
1998    vsprintf(buffer, fmt, args);
1999    va_end(args);
2000    char *msg = buffer;
2001
2002    // count newlines
2003    int line_num = 1;
2004    int line_length_arr[TIP_LINEMAX];
2005    char *msg_cursor_prev, *msg_cursor_curr; // declare char pointers
2006    msg_cursor_prev = msg;
2007    msg_cursor_curr = strchr(msg_cursor_prev, '\n'); // check for occurrence
2008    while (msg_cursor_curr != 0)                     // if occurrence found, increment values
2009    {
2010        // check if exceeds max lines
2011        if (line_num >= TIP_LINEMAX)
2012            assert("TIP_LINEMAX exceeded!");
2013
2014        // Save information about this line
2015        line_length_arr[line_num - 1] = msg_cursor_curr - msg_cursor_prev; // determine length of the line
2016        line_num++;                                                        // increment number of newlines found
2017        msg_cursor_prev = msg_cursor_curr + 1;                             // update prev cursor
2018        msg_cursor_curr = strchr(msg_cursor_prev, '\n');                   // check for another occurrence
2019    }
2020
2021    // get last lines length
2022    msg_cursor_curr = strchr(msg_cursor_prev, 0);
2023    line_length_arr[line_num - 1] = msg_cursor_curr - msg_cursor_prev;
2024
2025    // copy each line to an individual char array
2026    for (int i = 0; i < line_num; i++)
2027    {
2028
2029        // check if over char max
2030        u8 line_length = line_length_arr[i];
2031        if (line_length > TIP_CHARMAX)
2032            assert("TIP_CHARMAX exceeded!");
2033
2034        // copy char array
2035        char msg_line[TIP_CHARMAX + 1];
2036        memcpy(msg_line, msg, line_length);
2037
2038        // add null terminator
2039        msg_line[line_length] = '\0';
2040
2041        // increment msg
2042        msg += (line_length + 1); // +1 to skip past newline
2043
2044        // print line
2045        int y_delta = (i * MSGTEXT_YOFFSET);
2046        Text_AddSubtext(tip_text, 0, y_delta, msg_line);
2047    }
2048
2049    return 1; // tip created
2050}
2051void Tip_Destroy(void)
2052{
2053    // check if tip exists and isnt in exit state, enter exit
2054    if ((stc_tipmgr.gobj != 0) && (stc_tipmgr.state != 2))
2055    {
2056        // apply exit anim
2057        JOBJ *tip_root = stc_tipmgr.gobj->hsd_object;
2058        JOBJ_RemoveAnimAll(tip_root);
2059        JOBJ_AddAnimAll(tip_root, stc_event_vars.menu_assets->tip_jointanim[1], 0, 0);
2060        JOBJ_ReqAnimAll(tip_root, 0);
2061        JOBJ_ForEachAnim(tip_root, 6, 0xfb7f, AOBJ_SetRate, 1, (float)2);
2062
2063        stc_tipmgr.state = 2; // enter wait
2064    }
2065}
2066
2067///////////////////////////////
2068/// Member-Access Functions ///
2069///////////////////////////////
2070
2071EventDesc *GetEventDesc(int page, int event)
2072{
2073    return EventPages[page]->events[event];
2074}
2075char *GetEventName(int page, int event)
2076{
2077    EventDesc *desc = GetEventDesc(page, event);
2078    return desc->eventName;
2079}
2080char *GetEventDescription(int page, int event)
2081{
2082    EventDesc *desc = GetEventDesc(page, event);
2083    return desc->eventDescription;
2084}
2085char *GetPageName(int page)
2086{
2087    return EventPages[page]->name;
2088}
2089char *GetEventFile(int page, int event)
2090{
2091    EventDesc *desc = GetEventDesc(page, event);
2092    return desc->eventFile;
2093}
2094char *GetCSSFile(int page, int event)
2095{
2096    EventDesc *desc = GetEventDesc(page, event);
2097    return desc->eventCSSFile;
2098}
2099int GetPageEventNum(int page)
2100{
2101    return EventPages[page]->eventNum - 1;
2102}
2103char *GetTMVersShort(void)
2104{
2105    return TM_VersShort;
2106}
2107char *GetTMVersLong(void)
2108{
2109    return TM_VersLong;
2110}
2111char *GetTMCompile(void)
2112{
2113    return TM_Compile;
2114}
2115int GetPageNum(void)
2116{
2117    return countof(EventPages) - 1;
2118}
2119u8 GetCSSType(int page, int event)
2120{
2121    EventDesc *desc = GetEventDesc(page, event);
2122    return desc->CSSType;
2123}
2124u8 GetIsSelectStage(int page, int event)
2125{
2126    EventDesc *desc = GetEventDesc(page, event);
2127    return desc->stage == -1;
2128}
2129s8 GetCPUFighter(int page, int event)
2130{
2131    EventDesc *desc = GetEventDesc(page, event);
2132    return desc->cpuKind;
2133}
2134s16 GetStage(int page, int event)
2135{
2136    EventDesc *desc = GetEventDesc(page, event);
2137    return desc->stage;
2138}
2139u8 GetScoreType(int page, int event)
2140{
2141    EventDesc *desc = GetEventDesc(page, event);
2142    return desc->scoreType;
2143}
2144int GetPageEventOffset(int pageID) {
2145    int eventIndex = 0;
2146    // Add the number of events for each previous page
2147    for(int i = 0; i < pageID; i++) {
2148        eventIndex += EventPages[i]->eventNum;
2149    }
2150    return eventIndex;
2151}
2152int GetJumpTableOffset(int pageID, int eventID) {
2153    EventDesc *desc = GetEventDesc(pageID, eventID);
2154    return desc->jumpTableIndex;
2155}
2156AllowedCharacters *GetEventCharList(int eventID,int pageID) {
2157    EventDesc *desc = GetEventDesc(pageID, eventID);
2158    return &desc->allowed_characters;
2159}