fork/training-mode-ce

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

Alex Harrisonfix double reset when pressing up with an instant reset delayedda55f

master
44.9 KiB1378 linesraw
1#include "ledgedash.h"
2
3static GXColor tmgbar_black = {40, 40, 40, 255};
4static GXColor tmgbar_grey = {120, 120, 120, 255};
5static GXColor tmgbar_blue = {128, 128, 255, 255};
6static GXColor tmgbar_green = {128, 255, 128, 255};
7static GXColor tmgbar_cyan = {52, 202, 228, 255};
8static GXColor tmgbar_red = {255, 128, 128, 255};
9static GXColor tmgbar_magenta = {230, 22, 198, 255};
10static GXColor tmgbar_white = {255, 255, 255, 255};
11static GXColor *tmgbar_colors[] = {
12    &tmgbar_black,
13    &tmgbar_grey,
14    &tmgbar_green,
15    &tmgbar_cyan,
16    &tmgbar_magenta,
17    &tmgbar_white,
18    &tmgbar_red,
19    &tmgbar_blue,
20};
21
22enum menu_options
23{
24    OPT_POS,
25    OPT_RESET,
26    OPT_HUD,
27    OPT_TIPS,
28    OPT_CAM,
29    OPT_INV,
30    OPT_SPEED,
31    OPT_OVERLAYS,
32    OPT_RESETDELAY,
33    OPT_ABOUT,
34    OPT_EXIT,
35};
36
37enum reset_mode
38{
39    OPTRESET_NONE,
40    OPTRESET_SAME_SIDE,
41    OPTRESET_SWAP,
42    OPTRESET_SWAP_ON_SUCCESS,
43    OPTRESET_RANDOM,
44};
45
46enum reset_pos
47{
48    OPTPOS_LEDGE,
49    OPTPOS_FALLING,
50    OPTPOS_STAGE,
51    OPTPOS_RESPAWNPLAT,
52    OPTPOS_RANDOM,  // Must be last
53};
54
55// Main Menu
56static const char *LdshOptions_CamMode[] = {"Normal", "Zoom", "Fixed", "Advanced"};
57static const char *LdshOptions_Start[] = {"Ledge", "Falling", "Stage", "Respawn Platform", "Random"};
58static float LdshOptions_GameSpeeds[] = {1.f, 5.f/6.f, 2.f/3.f, 1.f/2.f, 1.f/4.f};
59static const char *LdshOptions_GameSpeedText[] = {"1", "5/6", "2/3", "1/2", "1/4"};
60static const char *LdshOptions_Reset[] = {"None", "Same Side", "Swap", "Swap on Success", "Random"};
61static const char *LdshOptions_ResetDelay[] = {"Slow", "Normal", "Fast", "Instant"};
62static int LdshOptions_ResetDelaySuccess[] = { 120, 60, 30, 1 };
63static int LdshOptions_ResetDelayFailure[] = { 60, 20, 1, 1 };
64
65static EventOption LdshOptions_Main[] = {
66    {
67        .kind = OPTKIND_STRING,
68        .value_num = sizeof(LdshOptions_Start) / 4,
69        .name = "Starting Position",
70        .desc = {"Choose where the fighter is placed ",
71                 "after resetting positions."},
72        .values = LdshOptions_Start,
73        .OnChange = Ledgedash_ToggleStartPosition,
74    },
75    {
76        .kind = OPTKIND_STRING,
77        .value_num = sizeof(LdshOptions_Reset) / 4,
78        .val = OPTRESET_SAME_SIDE,
79        .name = "Reset",
80        .desc = {"Change where the fighter gets placed",
81                 "after a ledgedash attempt."},
82        .values = LdshOptions_Reset,
83    },
84    {
85        .kind = OPTKIND_TOGGLE,
86        .name = "HUD",
87        .desc = {"Toggle visibility of the HUD."},
88        .val = 1,
89        .OnChange = Ledgedash_ChangeShowHUD,
90    },
91    {
92        .kind = OPTKIND_TOGGLE,
93        .name = "Tips",
94        .desc = {"Toggle the onscreen display of tips."},
95        .val = 1,
96        .OnChange = Tips_Toggle,
97    },
98    {
99        .kind = OPTKIND_STRING,
100        .value_num = sizeof(LdshOptions_CamMode) / 4,
101        .name = "Camera Mode",
102        .desc = {"Adjust the camera's behavior.",
103                 "In advanced mode, use C-Stick while holding",
104                 "A/B/Y to pan, rotate and zoom, respectively."},
105        .values = LdshOptions_CamMode,
106        .OnChange = Ledgedash_ChangeCamMode,
107    },
108    {
109        .kind = OPTKIND_TOGGLE,
110        .name = "Keep Ledge Invincibility",
111        .desc = {"Keep maximum invincibility while on the ledge",
112                 "to practice the ledgedash inputs."},
113    },
114    {
115        .kind = OPTKIND_STRING,
116        .value_num = sizeof(LdshOptions_GameSpeedText) /
117                     sizeof(*LdshOptions_GameSpeedText),
118        .name = "Game Speed",
119        .desc = {"Change how fast the game engine runs."},
120        .values = LdshOptions_GameSpeedText,
121    },
122    {
123        .kind = OPTKIND_TOGGLE,
124        .name = "Color Overlays",
125        .desc = {"Show which state you are in with a color overlay."},
126    },
127    {
128        .kind = OPTKIND_STRING,
129        .value_num =
130            sizeof(LdshOptions_ResetDelay) / sizeof(*LdshOptions_ResetDelay),
131        .val = 1,
132        .name = "Reset Delay",
133        .desc = {"Change how quickly you can start a new ledgedash."},
134        .values = LdshOptions_ResetDelay,
135    },
136    {
137        .kind = OPTKIND_INFO,
138        .name = "HELP",
139        .desc =
140            {"Ledgedashing is the act of wavedashing onto stage from ledge.",
141             "This is most commonly done by dropping off ledge, double jumping ",
142             "immediately, and quickly airdodging onto stage. Each input",
143             "is performed quickly after the last, making it difficult and risky."},
144    },
145    {
146        .kind = OPTKIND_FUNC,
147        .name = "Exit",
148        .desc = {"Return to the Event Selection Screen."},
149        .OnSelect = Event_Exit,
150    },
151};
152
153static EventOption Ldsh_FrameAdvance = {
154    .kind = OPTKIND_TOGGLE,
155    .name = "Frame Advance",
156    .desc = {"Enable frame advance. Press to advance one",
157             "frame. Hold to advance at normal speed."},
158};
159
160static Shortcut Ldsh_Shortcuts[] = {
161    {
162        .button_mask = HSD_BUTTON_A,
163        .option = &Ldsh_FrameAdvance,
164    }
165};
166
167static ShortcutList Ldsh_ShortcutList = {
168    .count = countof(Ldsh_Shortcuts),
169    .list = Ldsh_Shortcuts,
170};
171
172static EventMenu LdshMenu_Main = {
173    .name = "Ledgedash Training",
174    .option_num = sizeof(LdshOptions_Main) / sizeof(EventOption),
175    .options = LdshOptions_Main,
176    .shortcuts = &Ldsh_ShortcutList,
177};
178
179// Init Function
180void Event_Init(GOBJ *gobj)
181{
182    LedgedashData *event_data = gobj->userdata;
183
184    // get assets
185    event_data->assets = Archive_GetPublicAddress(event_vars->event_archive, "ledgedash");
186
187    HSD_Update *hsd_update = stc_hsd_update;
188    hsd_update->checkPause = Update_CheckPause;
189    hsd_update->checkAdvance = Update_CheckAdvance;
190
191    // standardize camera
192    float *unk_cam = (void *)0x803bcca0;
193    stc_stage->fov_r = 0; // no camera rotation
194    stc_stage->x28 = 1;   // pan value?
195    stc_stage->x2c = 1;   // pan value?
196    stc_stage->x30 = 1;   // pan value?
197    stc_stage->x34 = 130; // zoom out
198    unk_cam[0x40 / 4] = 30;
199
200    // Init hitlog
201    event_data->hitlog_gobj = Ledgedash_HitLogInit();
202
203    // Init HUD
204    Ledgedash_HUDInit(event_data);
205
206    // Init Fighter
207    Ledgedash_FtInit(event_data);
208
209    Fighter_PlaceOnLedge();
210}
211// Think Function
212void Event_Think(GOBJ *event)
213{
214    LedgedashData *event_data = event->userdata;
215
216    // get fighter data
217    GOBJ *hmn = Fighter_GetGObj(0);
218    FighterData *hmn_data = hmn->userdata;
219
220    // no ledgefall
221    FtCliffCatch *ft_state = (void *)&hmn_data->state_var;
222    if (hmn_data->state_id == ASID_CLIFFWAIT)
223        ft_state->fall_timer = 2;
224
225    if (LdshOptions_Main[OPT_INV].val == 1) {
226        if (hmn_data->state_id == ASID_CLIFFWAIT) {
227            hmn_data->hurt.intang_frames.ledge = 30;
228            hmn_data->TM.state_frame = 1;
229        }
230    }
231
232    if (hmn_data->input.down & HSD_BUTTON_DPAD_LEFT) {
233        event_data->ledge = -1;
234        Fighter_PlaceOnLedge();
235    } else if (hmn_data->input.down & HSD_BUTTON_DPAD_RIGHT) {
236        event_data->ledge = 1;
237        Fighter_PlaceOnLedge();
238    }
239
240    Ledgedash_ResetThink(event_data, hmn);
241    Ledgedash_HUDThink(event_data, hmn_data);
242    Ledgedash_HitLogThink(event_data, hmn);
243
244    if (LdshOptions_Main[OPT_OVERLAYS].val == 1) {
245        memset(&hmn_data->color[1], 0, sizeof(ColorOverlay));
246        memset(&hmn_data->color[0], 0, sizeof(ColorOverlay));
247
248        u32 curr_frame = event_data->action_state.timer - 1;
249        if (curr_frame < 30) {
250            int action = event_data->action_state.action_log[curr_frame];
251
252            GXColor color;
253            if (action == LDACT_NONE) {
254                if (hmn_data->hurt.intang_frames.ledge != 0) {
255                    color = tmgbar_blue;
256                    color.a = 180;
257                } else {
258                    color = (GXColor) {0, 0, 0, 0};
259                }
260            } else {
261                color = *tmgbar_colors[action];
262                color.a = 180;
263            }
264
265            hmn_data->color[1].hex = color;
266            hmn_data->color[1].color_enable = 1;
267        }
268    }
269}
270void Event_Exit(GOBJ *menu)
271{
272    // end game
273    stc_match->state = 3;
274
275    // cleanup
276    Match_EndVS();
277}
278
279// Ledgedash functions
280void Ledgedash_HUDInit(LedgedashData *event_data)
281{
282    GOBJ *hud_gobj = GObj_Create(0, 0, 0);
283    event_data->hud.gobj = hud_gobj;
284    // Load jobj
285    JOBJ *hud_jobj = JOBJ_LoadJoint(event_data->assets->hud);
286    GObj_AddObject(hud_gobj, 3, hud_jobj);
287    GObj_AddGXLink(hud_gobj, GXLink_Common, GXLINK_HUD, 80);
288
289    // create text canvas
290    int canvas = Text_CreateCanvas(2, hud_gobj, 14, 15, 0, GXLINK_HUD, 81, 19);
291    event_data->hud.canvas = canvas;
292
293    // init text
294    Text **text_arr = &event_data->hud.text_angle;
295    for (int i = 0; i < 3; i++)
296    {
297        // Create text object
298        Text *hud_text = Text_CreateText(2, canvas);
299        text_arr[i] = hud_text;
300        hud_text->kerning = 1;
301        hud_text->align = 1;
302        hud_text->use_aspect = 1;
303
304        // Get position
305        Vec3 text_pos;
306        JOBJ *text_jobj;
307        JOBJ_GetChild(hud_jobj, &text_jobj, 2 + i, -1);
308        JOBJ_GetWorldPosition(text_jobj, 0, &text_pos);
309
310        // adjust scale
311        Vec3 *scale = &hud_jobj->scale;
312        // text scale
313        hud_text->viewport_scale.X = (scale->X * 0.01) * LCLTEXT_SCALE;
314        hud_text->viewport_scale.Y = (scale->Y * 0.01) * LCLTEXT_SCALE;
315        hud_text->aspect.X = 165;
316
317        // text position
318        hud_text->trans.X = text_pos.X + (scale->X / 4.0);
319        hud_text->trans.Y = (text_pos.Y * -1) + (scale->Y / 4.0);
320
321        // dummy text
322        Text_AddSubtext(hud_text, 0, 0, "-");
323    }
324}
325void Ledgedash_HUDThink(LedgedashData *event_data, FighterData *hmn_data)
326{
327    // run tip logic
328    Tips_Think(event_data, hmn_data);
329
330    JOBJ *hud_jobj = event_data->hud.gobj->hsd_object;
331
332    // check to initialize timer
333    if ((hmn_data->state_id == ASID_CLIFFWAIT) && (hmn_data->TM.state_frame == 1))
334    {
335        Ledgedash_InitVariables(event_data);
336
337        event_data->tip.refresh_num++;
338    }
339
340    u32 curr_frame = event_data->action_state.timer++;
341    int hud_updating =
342        curr_frame < countof(event_data->action_state.action_log)
343        && hmn_data->hurt.intang_frames.ledge != 0;
344
345    if (hud_updating) {
346        int state_id = hmn_data->state_id;
347        int action = LDACT_GALINT;
348
349        // look for cliffwait
350        if (state_id == ASID_CLIFFWAIT)
351             action = LDACT_CLIFFWAIT;
352
353        // look for release
354        else if (state_id == ASID_FALL)
355            action = LDACT_FALL;
356
357        // look for jump
358        else if (
359            state_id == ASID_JUMPAERIALF
360            || state_id == ASID_JUMPAERIALB
361            // check for kirby and jiggs jump
362            || ((hmn_data->kind == 4 || hmn_data->kind == 15) && (state_id >= 341 && state_id <= 345)))
363            action = LDACT_JUMP;
364
365        // look for airdodge
366        else if (state_id == ASID_ESCAPEAIR)
367            action = LDACT_AIRDODGE;
368
369        // look for attack
370        else if (hmn_data->atk_kind != 1 || state_id == ASID_CATCH || state_id == ASID_CATCHDASH)
371            action = LDACT_ATTACK;
372
373        // look for landing
374        else if (
375            (state_id == ASID_LANDING && hmn_data->TM.state_frame < hmn_data->attr.normal_landing_lag)
376            || state_id == ASID_LANDINGFALLSPECIAL
377        )
378            action = LDACT_LANDING;
379
380        // look for ledge options
381        else if (ASID_CLIFFCLIMBSLOW <= state_id && state_id <= ASID_CLIFFJUMPQUICK2)
382            action = LDACT_NONE;
383
384        event_data->action_state.action_log[curr_frame] = action;
385    }
386
387    // grab airdodge angle
388    if (event_data->action_state.is_airdodge == 0)
389    {
390        if ((hmn_data->state_id == ASID_ESCAPEAIR) || (hmn_data->TM.state_prev[0] == ASID_ESCAPEAIR))
391        {
392            // determine airdodge angle
393            float angle = atan2(fabs(hmn_data->input.lstick.Y), fabs(hmn_data->input.lstick.X));
394
395            // save airdodge angle
396            event_data->hud.airdodge_angle = angle;
397            event_data->action_state.is_airdodge = 1;
398        }
399    }
400
401    if (hmn_data->state_id == ASID_CLIFFWAIT)
402        event_data->action_state.is_ledgegrab = 1;
403    if (event_data->action_state.is_ledgegrab && hmn_data->state_id == ASID_FALL)
404        event_data->action_state.is_release = 1;
405
406    int released_ledge = event_data->action_state.is_release == 1;
407    int not_finished = event_data->action_state.is_finished == 0;
408    int just_finished = false;
409    if (not_finished && released_ledge) {
410        // if actionable after normal landing
411        just_finished |= hmn_data->state_id == ASID_LANDING
412            && hmn_data->TM.state_frame >= hmn_data->attr.normal_landing_lag;
413
414        // if actionable after normal landing, but performed an action immediately after
415        just_finished |= hmn_data->TM.state_prev[0] == ASID_LANDING
416            || hmn_data->TM.state_prev[1] == ASID_LANDING;
417
418        // if actionable after airdodge landing
419        just_finished |= hmn_data->TM.state_prev[0] == ASID_LANDINGFALLSPECIAL
420            || hmn_data->TM.state_prev[1] == ASID_LANDINGFALLSPECIAL;
421
422        // if entered wait without entering landing - probably from NIL
423        just_finished |= hmn_data->state_id == ASID_WAIT;
424
425        event_data->action_state.is_finished |= just_finished;
426    }
427
428    if (just_finished) {
429        // destroy any tips
430        event_vars->Tip_Destroy();
431
432        // output remaining airdodge angle
433        if (event_data->action_state.is_airdodge == 1)
434            Text_SetText(event_data->hud.text_angle, 0, "%.2f", fabs(event_data->hud.airdodge_angle / M_1DEGREE));
435        else
436            Text_SetText(event_data->hud.text_angle, 0, "-");
437
438        // output remaining GALINT
439        void *matanim;
440        Text *text_galint = event_data->hud.text_galint;
441        if (hmn_data->hurt.intang_frames.ledge > 0)
442        {
443            event_data->hud.successful_count++;
444            event_data->was_successful = true;
445            matanim = event_data->assets->hudmatanim[0];
446            Text_SetText(text_galint, 0, "%df", hmn_data->hurt.intang_frames.ledge);
447        }
448        else if (hmn_data->TM.vuln_frames < 25)
449        {
450            event_data->was_successful = false;
451            matanim = event_data->assets->hudmatanim[1];
452            Text_SetText(text_galint, 0, "-%df", hmn_data->TM.vuln_frames);
453        }
454        else
455        {
456            event_data->was_successful = false;
457            matanim = event_data->assets->hudmatanim[1];
458            Text_SetText(text_galint, 0, "-");
459        }
460        event_data->hud.total_count++;
461        int success_count = event_data->hud.successful_count;
462        int total_count = event_data->hud.total_count;
463        float success_percent = (float)success_count/total_count;
464        Text_SetText(event_data->hud.text_count, 0, "%d/%d (%.1f%%)", success_count, total_count, success_percent*100);
465
466        // init hitbox num
467        LdshHitlogData *hitlog_data = event_data->hitlog_gobj->userdata;
468        hitlog_data->num = 0;
469
470        // apply HUD animation
471        JOBJ_RemoveAnimAll(hud_jobj);
472        JOBJ_AddAnimAll(hud_jobj, 0, matanim, 0);
473        JOBJ_ReqAnimAll(hud_jobj, 0);
474    }
475}
476
477void Ledgedash_ResetThink(LedgedashData *event_data, GOBJ *hmn)
478{
479    FighterData *hmn_data = hmn->userdata;
480
481    int reset_mode = LdshOptions_Main[OPT_RESET].val;
482
483    if (reset_mode == OPTRESET_NONE)
484        return;
485
486    if (event_data->reset_timer > 0) {
487        event_data->reset_timer--;
488        
489        if (event_data->reset_timer > 0)
490            return;
491
492        int swap = false;
493        switch (reset_mode) {
494            case OPTRESET_SAME_SIDE:
495                break;
496            case OPTRESET_SWAP:
497                swap = true;
498                break;
499            case OPTRESET_SWAP_ON_SUCCESS:
500                swap = event_data->was_successful;
501                break;
502            case OPTRESET_RANDOM:
503                swap = HSD_Randi(2);
504                break;
505        }
506
507        if (swap)
508            event_data->ledge = -event_data->ledge;
509
510        Fighter_PlaceOnLedge();
511    } else if (event_data->action_state.is_finished) {
512        
513        int reset_idx = LdshOptions_Main[OPT_RESETDELAY].val;
514        event_data->reset_timer = LdshOptions_ResetDelaySuccess[reset_idx];
515        if (event_data->was_successful)
516            SFX_Play(303);
517        else
518            SFX_PlayCommon(3);
519    } else {
520        int state = hmn_data->state_id;
521
522        bool dead = hmn_data->flags.dead;
523        bool missed_airdodge = hmn_data->state_id == ASID_ESCAPEAIR && hmn_data->TM.state_frame >= 9;
524        bool ledge_action = ASID_CLIFFCLIMBSLOW <= state && state <= ASID_CLIFFJUMPQUICK2;
525        bool non_landing_grounded = hmn_data->phys.air_state == 0
526            && event_data->action_state.is_release
527            && state != ASID_LANDING
528            && state != ASID_LANDINGFALLSPECIAL
529            && state != ASID_REBIRTHWAIT
530            && hmn_data->TM.state_frame >= 12;
531
532        if (dead || missed_airdodge || ledge_action || non_landing_grounded) {
533            int reset_idx = LdshOptions_Main[OPT_RESETDELAY].val;
534            event_data->reset_timer = LdshOptions_ResetDelayFailure[reset_idx];
535            event_data->was_successful = false;
536            SFX_PlayCommon(3);
537
538            // update counter hud
539            event_data->hud.total_count++;
540            int success_count = event_data->hud.successful_count;
541            int total_count = event_data->hud.total_count;
542            float success_percent = (float)success_count/total_count;
543            Text_SetText(event_data->hud.text_count, 0, "%d/%d (%.1f%%)", success_count, total_count, success_percent*100);
544        }
545    }
546}
547void Ledgedash_InitVariables(LedgedashData *event_data)
548{
549    event_data->action_state.timer = 0;
550    event_data->action_state.is_ledgegrab = 0;
551    event_data->action_state.is_release = 0;
552    event_data->action_state.is_airdodge = 0;
553    event_data->action_state.is_finished = 0;
554
555    // init action log
556    for (u32 i = 0; i < countof(event_data->action_state.action_log); i++)
557    {
558        event_data->action_state.action_log[i] = 0;
559    }
560}
561
562// Menu Toggle functions
563void Ledgedash_ToggleStartPosition(GOBJ *menu_gobj, int value)
564{
565    Fighter_PlaceOnLedge();
566}
567
568// Hitlog functions
569GOBJ *Ledgedash_HitLogInit(void)
570{
571
572    GOBJ *hit_gobj = GObj_Create(0, 0, 0);
573    LdshHitlogData *hit_data = calloc(sizeof(LdshHitlogData));
574    GObj_AddUserData(hit_gobj, 4, HSD_Free, hit_data);
575    GObj_AddGXLink(hit_gobj, Ledgedash_HitLogGX, 5, 0);
576
577    // init array
578    hit_data->num = 0;
579
580    return hit_gobj;
581}
582void Ledgedash_HitLogThink(LedgedashData *event_data, GOBJ *hmn)
583{
584    FighterData *hmn_data = hmn->userdata;
585    LdshHitlogData *hitlog_data = event_data->hitlog_gobj->userdata;
586
587    // log hitboxes
588    if (event_data->action_state.is_finished && hmn_data->hurt.intang_frames.ledge > 0)
589    {
590
591        // iterate through fighter hitboxes
592        for (u32 i = 0; i < countof(hmn_data->hitbox); i++)
593        {
594
595            ftHit *this_hit = &hmn_data->hitbox[i];
596
597            if ((this_hit->active != 0) &&           // if hitbox is active
598                (hitlog_data->num < LDSH_HITBOXNUM)) // if not over max
599            {
600
601                // log info
602                LdshHitboxData *this_ldsh_hit = &hitlog_data->hitlog[hitlog_data->num];
603                this_ldsh_hit->size = this_hit->size;
604                this_ldsh_hit->pos_curr = this_hit->pos;
605                this_ldsh_hit->pos_prev = this_hit->pos_prev;
606                this_ldsh_hit->kind = this_hit->attribute;
607
608                // increment hitboxes
609                hitlog_data->num++;
610            }
611        }
612
613        // iterate through items belonging to fighter
614        GOBJ *this_item = (*stc_gobj_lookup)[MATCHPLINK_ITEM];
615        while (this_item != 0)
616        {
617            ItemData *this_itemdata = this_item->userdata;
618
619            // ensure belongs to the fighter
620            if (this_itemdata->fighter_gobj == hmn)
621            {
622                // iterate through item hitboxes
623                for (u32 i = 0; i < countof(hmn_data->hitbox); i++)
624                {
625
626                    itHit *this_hit = &this_itemdata->hitbox[i];
627
628                    if ((this_hit->active != 0) &&           // if hitbox is active
629                        (hitlog_data->num < LDSH_HITBOXNUM)) // if not over max
630                    {
631
632                        // log info
633                        LdshHitboxData *this_ldsh_hit = &hitlog_data->hitlog[hitlog_data->num];
634                        this_ldsh_hit->size = this_hit->size;
635                        this_ldsh_hit->pos_curr = this_hit->pos;
636                        this_ldsh_hit->pos_prev = this_hit->pos_prev;
637                        this_ldsh_hit->kind = this_hit->attribute;
638
639                        // increment hitboxes
640                        hitlog_data->num++;
641                    }
642                }
643            }
644
645            this_item = this_item->next;
646        }
647    }
648}
649
650void Ledgedash_HitLogGX(GOBJ *gobj, int pass)
651{
652    static GXColor hitlog_ambient = {128, 0, 0, 50};
653    static GXColor hit_diffuse = {255, 99, 99, 50};
654    static GXColor grab_diffuse = {255, 0, 255, 50};
655    static GXColor detect_diffuse = {255, 255, 255, 50};
656
657    LdshHitlogData *hitlog_data = gobj->userdata;
658    
659    if (pass == 2) {
660        LedgedashData *event_data = event_vars->event_gobj->userdata;
661        static GXColor colors[] = {
662            {40, 40, 40, 180},
663            {120, 120, 120, 180},
664            {128, 255, 128, 180},
665            {52, 202, 228, 180},
666            {230, 22, 198, 180},
667            {255, 255, 255, 180},
668            {255, 128, 128, 180},
669            {128, 128, 255, 180},
670        };
671        static char *names[] = {
672            "Cliffwait",
673            "Fall",
674            "Jump",
675            "Airdodge",
676            "Attack",
677            "Landing",
678            "GALINT",
679        };
680        event_vars->HUD_DrawActionLogBar(
681            event_data->action_state.action_log,
682            colors,
683            countof(event_data->action_state.action_log)
684        );
685        event_vars->HUD_DrawActionLogKey(
686            names,
687            &colors[1],
688            countof(names)
689        );
690    }
691    
692    for (int i = 0; i < hitlog_data->num; i++)
693    {
694        LdshHitboxData *this_ldsh_hit = &hitlog_data->hitlog[i];
695
696        // determine color
697        GXColor *diffuse;
698        if (this_ldsh_hit->kind == 0)
699            diffuse = &hit_diffuse;
700        else if (this_ldsh_hit->kind == 8)
701            diffuse = &grab_diffuse;
702        else if (this_ldsh_hit->kind == 11)
703            diffuse = &detect_diffuse;
704        else
705            diffuse = &hit_diffuse;
706
707        Develop_DrawSphere(this_ldsh_hit->size, &this_ldsh_hit->pos_curr, &this_ldsh_hit->pos_prev, diffuse, &hitlog_ambient);
708    }
709}
710
711// Fighter fuctions
712void Ledgedash_FtInit(LedgedashData *event_data)
713{
714    // create camera box
715    CmSubject *cam = CameraSubject_Alloc();
716    cam->boundleft_proj = -10;
717    cam->boundright_proj = 10;
718    cam->boundtop_proj = 10;
719    cam->boundbottom_proj = -10;
720    cam->boundleft_curr = cam->boundleft_proj;
721    cam->boundright_curr = cam->boundright_proj;
722    cam->boundtop_curr = cam->boundtop_proj;
723    cam->boundbottom_curr = cam->boundbottom_proj;
724    event_data->cam = cam;
725    event_data->was_successful = false;
726    event_data->reset_timer = 0;
727    event_data->ledge = -1; // start on left ledge
728
729    //if (event_vars->ledge_l == -1 || event_vars->ledge_r == -1) {
730    //    event_data->cam->is_disable = 0;
731    //    event_vars->Tip_Display(500 * 60, "Error:\nIt appears there are no\ngood ledges on this stage...");
732    //}
733}
734
735void Ledgedash_ChangeShowHUD(GOBJ *menu_gobj, int show) {
736    HUDCamData *cam = event_vars->hudcam_gobj->userdata;
737    cam->hide = !show;
738}
739
740void Ledgedash_ChangeCamMode(GOBJ *menu_gobj, int value)
741{
742    MatchCamera *cam = stc_matchcam;
743
744    // normal cam
745    if (value == 0)
746    {
747        Match_SetNormalCamera();
748    }
749    // zoom cam
750    else if (value == 1)
751    {
752        Match_SetFreeCamera(0, 3);
753        cam->freecam_fov.X = 140;
754        cam->freecam_rotate.Y = 10;
755    }
756    // fixed
757    else if (value == 2)
758    {
759        Match_SetFixedCamera();
760    }
761    else if (value == 3)
762    {
763        Match_SetDevelopCamera();
764    }
765    Match_CorrectCamera();
766}
767
768void Event_Update(void)
769{
770    if (Pause_CheckStatus(1) != 2) {
771        float speed = LdshOptions_GameSpeeds[LdshOptions_Main[OPT_SPEED].val];
772        HSD_SetSpeedEasy(speed);
773    } else {
774        HSD_SetSpeedEasy(1.0);
775    }
776}
777
778int Ledge_Find(int search_dir, float xpos_start, float *ledge_dir)
779{
780    // get line and vert pointers
781    CollLine *collline = *stc_collline;
782
783    // get initial closest
784    float xpos_closest;
785    if (search_dir == -1) // search left
786        xpos_closest = -5000;
787    else if (search_dir == 1) // search right
788        xpos_closest = 5000;
789    else // search both
790        xpos_closest = 5000;
791
792    // look for the closest ledge
793    int index_closest = -1;
794    CollGroup *this_group = *stc_firstcollgroup;
795    while (this_group != 0) // loop through ground links
796    {
797
798        // 2 passes, one for ground and one for dynamic lines
799        int line_index, line_num;
800        for (int i = 0; i < 2; i++)
801        {
802            // first pass, use floors
803            if (i == 0)
804            {
805                line_index = this_group->desc->floor_start;          // first ground link
806                line_num = line_index + this_group->desc->floor_num; // ground link num
807            }
808            // second pass, use dynamics
809            else if (i == 1)
810            {
811                line_index = this_group->desc->dyn_start;          // first ground link
812                line_num = line_index + this_group->desc->dyn_num; // ground link num
813            }
814
815            // loop through lines
816            while (line_index < line_num)
817            {
818                // get all data for this line
819                CollLine *this_line = &collline[line_index]; // ??? i actually dont know why i cant access this directly
820                CollLineDesc *this_linedesc = this_line->desc;
821
822                // check if this link is a ledge
823                if (this_linedesc->is_ledge)
824                {
825
826                    // check both sides of this ledge
827                    Vec3 ledge_pos;
828                    for (int j = 0; j < 2; j++)
829                    {
830                        // first pass, check left
831                        if (j == 0)
832                        {
833                            GrColl_GetGroundLineEndLeft(line_index, &ledge_pos);
834                        }
835                        else if (j == 1)
836                        {
837                            GrColl_GetGroundLineEndRight(line_index, &ledge_pos);
838                        }
839
840                        // is within the camera range
841                        if ((ledge_pos.X > Stage_GetCameraLeft()) && (ledge_pos.X < Stage_GetCameraRight()) && (ledge_pos.Y > Stage_GetCameraBottom()) && (ledge_pos.Y < Stage_GetCameraTop()))
842                        {
843
844                            // check for any obstructions
845                            float dir_mult;
846                            if (j == 0) // left ledge
847                                dir_mult = -1;
848                            else if (j == 1) // right ledge
849                                dir_mult = 1;
850                            int ray_index;
851                            int ray_kind;
852                            Vec3 ray_angle;
853                            Vec3 ray_pos;
854                            float from_x = ledge_pos.X + (2 * dir_mult);
855                            float to_x = from_x;
856                            float from_y = ledge_pos.Y + 5;
857                            float to_y = from_y - 10;
858                            int is_ground = GrColl_RaycastGround(&ray_pos, &ray_index, &ray_kind, &ray_angle, -1, -1, -1, 0, from_x, from_y, to_x, to_y, 0);
859                            if (is_ground == 0)
860                            {
861                                int is_closer = 0;
862
863                                if (search_dir == -1) // check if to the left
864                                {
865                                    if ((ledge_pos.X > xpos_closest) && (ledge_pos.X < xpos_start))
866                                        is_closer = 1;
867                                }
868                                else if (search_dir == 1) // check if to the right
869                                {
870                                    if ((ledge_pos.X < xpos_closest) && (ledge_pos.X > xpos_start))
871                                        is_closer = 1;
872                                }
873                                else // check if any direction
874                                {
875                                    float dist_old = fabs(xpos_start - xpos_closest);
876                                    float dist_new = fabs(xpos_start - ledge_pos.X);
877                                    if (dist_new < dist_old)
878                                        is_closer = 1;
879                                }
880
881                                // determine direction
882                                if (is_closer)
883                                {
884
885                                    // now determine if this line is a ledge in this direction
886                                    if (j == 0) // left ledge
887                                    {
888                                        CollLine *prev_line = &collline[this_linedesc->line_prev];          // ??? i actually dont know why i cant access this directly
889                                        if ((this_linedesc->line_prev == -1) || (prev_line->is_rwall == 1)) // if prev line is a right wall / if prev line doesnt exist
890                                        {
891
892                                            // save info on this line
893                                            xpos_closest = ledge_pos.X; // save left vert's X position
894                                            index_closest = line_index;
895                                            *ledge_dir = 1;
896                                        }
897                                    }
898                                    else if (j == 1) // right ledge
899                                    {
900                                        CollLine *next_line = &collline[this_linedesc->line_next];          // ??? i actually dont know why i cant access this directly
901                                        if ((this_linedesc->line_prev == -1) || (next_line->is_lwall == 1)) // if prev line is a right wall / if prev line doesnt exist
902                                        {
903
904                                            // save info on this line
905                                            xpos_closest = ledge_pos.X; // save left vert's X position
906                                            index_closest = line_index;
907                                            *ledge_dir = -1;
908                                        }
909                                    }
910                                }
911                            }
912                        }
913                    }
914                }
915
916                line_index++;
917            }
918        }
919
920        // get next
921        this_group = this_group->next;
922    }
923
924    return index_closest;
925}
926void Fighter_PlaceOnLedge(void)
927{
928    LedgedashData *event_data = event_vars->event_gobj->userdata;
929    GOBJ *hmn = Fighter_GetGObj(0);
930    FighterData *hmn_data = hmn->userdata;
931
932    float ledge_dir;
933    int line_index = Ledge_Find(event_data->ledge, 0.f, &ledge_dir);
934
935    if (line_index == -1) {
936        event_vars->Tip_Display(500 * 60, "Error:\nIt appears there are no \nledges on this stage..");
937        return;
938    }
939
940    Ledgedash_InitVariables(event_data);
941    event_data->tip.refresh_displayed = 0;
942    event_data->tip.is_input_release = 0;
943    event_data->tip.refresh_num = 0;
944
945    // get ledge position
946    Vec3 ledge_pos;
947    if (ledge_dir > 0)
948        GrColl_GetGroundLineEndLeft(line_index, &ledge_pos);
949    else
950        GrColl_GetGroundLineEndRight(line_index, &ledge_pos);
951
952    // remove velocity
953    hmn_data->phys.self_vel.X = 0;
954    hmn_data->phys.self_vel.Y = 0;
955
956    // restore tether
957    hmn_data->flags.used_tether = 0;
958
959
960    // Sleep first
961    Fighter_EnterSleep(hmn, 0);
962    Fighter_EnterRebirth(hmn);
963
964    // face the ledge
965    hmn_data->facing_direction = ledge_dir;
966
967    // check starting position
968    int start_pos = LdshOptions_Main[OPT_POS].val;
969
970SWITCH_START_POS:
971    switch (start_pos)
972    {
973    case OPTPOS_RANDOM:
974    {
975        start_pos = HSD_Randi(OPTPOS_RANDOM);
976        goto SWITCH_START_POS;
977    }
978    case OPTPOS_LEDGE:
979    {
980        // place player on this ledge
981        event_data->tip.refresh_num = -1; // setting this to -1 because the per frame code will add 1 and make it 0
982        FtCliffCatch *ft_state = (void *)&hmn_data->state_var;
983        ft_state->ledge_index = line_index; // store line index
984        Fighter_EnterCliffWait(hmn);
985        ft_state->timer = 0; // spoof as on ledge for a frame already
986        Fighter_SetAirborne(hmn_data);
987        Fighter_EnableCollUpdate(hmn_data);
988        Coll_CheckLedge(&hmn_data->coll_data);
989        Fighter_MoveToCliff(hmn);
990        Fighter_UpdatePosition(hmn);
991        ftCommonData *ftcommon = *stc_ftcommon;
992
993        // This needs to be +1 for some reason, otherwise we get an off-by-one in galint calculations
994        Fighter_ApplyIntang(hmn, ftcommon->cliff_invuln_time+1);
995        break;
996    }
997    case OPTPOS_FALLING:
998    {
999        // place player falling above the ledge
1000        hmn_data->phys.pos.X = ledge_pos.X + -5 * ledge_dir; // slight nudge to prevent accidentally landing on stage
1001        hmn_data->phys.pos.Y = ledge_pos.Y + 20;
1002        Fighter_UpdatePosition(hmn);
1003        Fighter_EnterFall(hmn);
1004        break;
1005    }
1006    case OPTPOS_STAGE:
1007    {
1008        // place player on stage next to ledge
1009        Vec3 coll_pos, line_unk;
1010        int line_index, line_kind;
1011        float x = ledge_pos.X + 12 * ledge_dir;
1012        float from_y = ledge_pos.Y + 5;
1013        float to_y = from_y - 10;
1014        int is_ground = GrColl_RaycastGround(&coll_pos, &line_index, &line_kind, &line_unk, -1, -1, -1, 0, x, from_y, x, to_y, 0);
1015        if (is_ground == 1)
1016        {
1017            hmn_data->phys.pos = coll_pos;
1018            Fighter_UpdatePosition(hmn);
1019            Fighter_EnterWait(hmn);
1020        }
1021        break;
1022    }
1023    case OPTPOS_RESPAWNPLAT:
1024    {
1025        // place player in a random position in respawn wait
1026        float xpos_min = 40;
1027        float xpos_max = 65;
1028        float ypos_min = -30;
1029        float ypos_max = 30;
1030        hmn_data->phys.pos.X = ((ledge_dir * -1) * (xpos_min + HSD_Randi(xpos_max - xpos_min) + HSD_Randf())) + (ledge_pos.X);
1031        hmn_data->phys.pos.Y = ((ledge_dir * -1) * (ypos_min + HSD_Randi(ypos_max - ypos_min) + HSD_Randf())) + (ledge_pos.Y);
1032
1033        // enter rebirth
1034        Fighter_EnterRebirthWait(hmn);
1035        hmn_data->cb.Phys = RebirthWait_Phys;
1036        hmn_data->cb.IASA = RebirthWait_IASA;
1037
1038        Fighter_UpdateRebirthPlatformPos(hmn);
1039
1040        break;
1041    }
1042    }
1043
1044    // avoid double reset in case user manually resets
1045    event_data->reset_timer = 0;
1046
1047    // update camera box
1048    CmSubject *cam = event_data->cam;
1049    cam->cam_pos.X = ledge_pos.X + (ledge_dir * 20);
1050    cam->cam_pos.Y = ledge_pos.Y + 15;
1051
1052    Fighter_UpdateCamera(hmn);
1053    
1054    // Prevent double reset caused by normal getup -> ledge jump combo with an instant reset delay.
1055    hmn_data->input.timer_lstick_tilt_y = 10;
1056
1057    // remove all particles
1058    for (int i = 0; i < PTCL_LINKMAX; i++)
1059    {
1060        Particle **ptcls = &stc_ptcl[i];
1061        Particle *ptcl = *ptcls;
1062        while (ptcl != 0)
1063        {
1064
1065            Particle *ptcl_next = ptcl->next;
1066
1067            // begin destroying this particle
1068
1069            // subtract some value, 8039c9f0
1070            if (ptcl->gen != 0)
1071            {
1072                ptcl->gen->particle_num--;
1073            }
1074            // remove from generator? 8039ca14
1075            if (ptcl->gen != 0)
1076                psRemoveParticleAppSRT(ptcl);
1077
1078            // delete parent jobj, 8039ca48
1079            psDeletePntJObjwithParticle(ptcl);
1080
1081            // update most recent ptcl pointer
1082            *ptcls = ptcl->next;
1083
1084            // free alloc, 8039ca54
1085            HSD_ObjFree((void *)0x804d0f60, ptcl);
1086
1087            // decrement ptcl total
1088            u16 ptclnum = *stc_ptclnum;
1089            ptclnum--;
1090            *stc_ptclnum = ptclnum;
1091
1092            // get next
1093            ptcl = ptcl_next;
1094        }
1095    }
1096
1097    // remove all camera shake gobjs (p_link 18, entity_class 3)
1098    GOBJ *gobj = (*stc_gobj_lookup)[MATCHPLINK_MATCHCAM];
1099    while (gobj != 0)
1100    {
1101
1102        GOBJ *gobj_next = gobj->next;
1103
1104        // if entity class 3 (quake)
1105        if (gobj->entity_class == 3)
1106        {
1107            GObj_Destroy(gobj);
1108        }
1109
1110        gobj = gobj_next;
1111    }
1112}
1113void Fighter_UpdatePosition(GOBJ *fighter)
1114{
1115
1116    FighterData *fighter_data = fighter->userdata;
1117
1118    // Update Position (Copy Physics XYZ into all ECB XYZ)
1119    fighter_data->coll_data.topN_Curr.X = fighter_data->phys.pos.X;
1120    fighter_data->coll_data.topN_Curr.Y = fighter_data->phys.pos.Y;
1121    fighter_data->coll_data.topN_Prev.X = fighter_data->phys.pos.X;
1122    fighter_data->coll_data.topN_Prev.Y = fighter_data->phys.pos.Y;
1123    fighter_data->coll_data.topN_CurrCorrect.X = fighter_data->phys.pos.X;
1124    fighter_data->coll_data.topN_CurrCorrect.Y = fighter_data->phys.pos.Y;
1125    fighter_data->coll_data.topN_Proj.X = fighter_data->phys.pos.X;
1126    fighter_data->coll_data.topN_Proj.Y = fighter_data->phys.pos.Y;
1127
1128    // Update Collision Frame ID
1129    fighter_data->coll_data.coll_test = *stc_colltest;
1130
1131    // Adjust JObj position (code copied from 8006c324)
1132    JOBJ *fighter_jobj = fighter->hsd_object;
1133    fighter_jobj->trans.X = fighter_data->phys.pos.X;
1134    fighter_jobj->trans.Y = fighter_data->phys.pos.Y;
1135    fighter_jobj->trans.Z = fighter_data->phys.pos.Z;
1136    JOBJ_SetMtxDirtySub(fighter_jobj);
1137
1138    // Update Static Player Block Coords
1139    Fighter_SetPosition(fighter_data->ply, fighter_data->flags.ms, &fighter_data->phys.pos);
1140}
1141void Fighter_UpdateCamera(GOBJ *fighter)
1142{
1143    FighterData *fighter_data = fighter->userdata;
1144
1145    // Update camerabox pos
1146    Fighter_UpdateCameraBox(fighter);
1147
1148    // Update tween
1149    fighter_data->camera_subject->boundleft_curr = fighter_data->camera_subject->boundleft_proj;
1150    fighter_data->camera_subject->boundright_curr = fighter_data->camera_subject->boundright_proj;
1151
1152    // update camera position
1153    Match_CorrectCamera();
1154
1155    // reset onscreen bool
1156    //Fighter_UpdateOnscreenBool(fighter);
1157    fighter_data->flags.is_offscreen = 0;
1158}
1159void RebirthWait_Phys(GOBJ *fighter)
1160{
1161
1162    FighterData *fighter_data = fighter->userdata;
1163
1164    // infinite time
1165    fighter_data->state_var.state_var1 = 2;
1166}
1167int RebirthWait_IASA(GOBJ *fighter)
1168{
1169
1170    FighterData *fighter_data = fighter->userdata;
1171    if (!Fighter_IASACheck_JumpAerial(fighter))
1172    {
1173        ftCommonData *ftcommon = *stc_ftcommon;
1174
1175        // check for lstick movement
1176        float stick_x = fabs(fighter_data->input.lstick.X);
1177        float stick_y = fighter_data->input.lstick.Y;
1178        if (
1179            (stick_x > 0.2875f && fighter_data->input.timer_lstick_tilt_x < 2)
1180            || (stick_y < -ftcommon->lstick_rebirthfall && fighter_data->input.timer_lstick_tilt_y < 4)
1181        ) {
1182            Fighter_EnterFall(fighter);
1183            return 1;
1184        }
1185    }
1186
1187    return 0;
1188}
1189int Fighter_IsFallInput(FighterData *hmn_data)
1190{
1191    float thresh = (*stc_ftcommon)->ledge_drop_thresh; // 0.2875
1192    float drop_angle = (*stc_ftcommon)->lstick_tilt;  // 0.872665 (50 deg)
1193    float lx = hmn_data->input.lstick.X;
1194    float ly = hmn_data->input.lstick.Y;
1195    float angle = atan2(ly, fabs(lx));
1196    float cx = hmn_data->input.cstick.X;
1197    float cy = hmn_data->input.cstick.Y;
1198
1199    // Technically there are some false positives here that result in a ledgejump.
1200    // However, this shouldn't affect the tip displays.
1201    int lstick_drop = (fabs(lx) >= thresh || fabs(ly) >= thresh) &&
1202        !(angle > drop_angle || (angle > -drop_angle && lx * hmn_data->facing_direction >= 0));
1203    int cstick_drop = (fabs(cx) >= thresh || fabs(cy) >= thresh);
1204    return (lstick_drop || cstick_drop) && !Fighter_IsFallBlocked(hmn_data);
1205}
1206int Fighter_IsFallBlocked(FighterData *hmn_data)
1207{
1208    float thresh = (*stc_ftcommon)->ledge_drop_thresh; // 0.2875
1209    float lx = hmn_data->input.lstick_prev.X;
1210    float ly = hmn_data->input.lstick_prev.Y;
1211    float cx = hmn_data->input.cstick_prev.X;
1212    float cy = hmn_data->input.cstick_prev.Y;
1213
1214    return fabs(lx) >= thresh || fabs(ly) >= thresh ||
1215        fabs(cx) >= thresh || fabs(cy) >= thresh;
1216}
1217// Tips Functions
1218void Tips_Toggle(GOBJ *menu_gobj, int value)
1219{
1220    // destroy existing tips when disabling
1221    if (value == 1)
1222        event_vars->Tip_Destroy();
1223}
1224void Tips_Think(LedgedashData *event_data, FighterData *hmn_data)
1225{
1226    // skip if tips turned off
1227    if (LdshOptions_Main[OPT_TIPS].val == 1)
1228        return;
1229
1230    // check for early fall input in cliffcatch
1231    if (!event_data->tip.is_input_release && hmn_data->state_id == ASID_CLIFFCATCH && Fighter_IsFallInput(hmn_data))
1232    {
1233        event_data->tip.is_input_release = 1;
1234        event_vars->Tip_Destroy();
1235
1236        // determine how many frames early
1237        Figatree *anim = Fighter_GetAnimData(hmn_data, hmn_data->action_id);
1238        float frame_num = anim->frame_num;
1239        float frames_early = frame_num - hmn_data->state.frame;
1240        event_vars->Tip_Display(3 * 60, "Misinput:\nFell %d frames early.", (int)frames_early + 1);
1241    }
1242
1243    // check for early fall input on cliffwait frame 0
1244    if (!event_data->tip.is_input_release && hmn_data->state_id == ASID_CLIFFWAIT && hmn_data->TM.state_frame == 1 && Fighter_IsFallInput(hmn_data))
1245    {
1246        event_data->tip.is_input_release = 1;
1247        event_vars->Tip_Destroy();
1248        event_vars->Tip_Display(LSDH_TIPDURATION, "Misinput:\nFell 1 frame early.");
1249    }
1250
1251    if (!event_data->tip.is_input_release && hmn_data->state_id == ASID_CLIFFJUMPQUICK1)
1252    {
1253        if (Fighter_IsFallInput(hmn_data))
1254        {
1255            event_data->tip.is_input_release = 1;
1256            event_vars->Tip_Destroy();
1257
1258            // jumped before fall
1259            event_vars->Tip_Display(LSDH_TIPDURATION, "Misinput:\nJumped %d frame(s) early.", hmn_data->TM.state_frame + 1);
1260        }
1261        else if (Fighter_IsFallBlocked(hmn_data))
1262        {
1263            event_data->tip.is_input_release = 1;
1264            event_vars->Tip_Destroy();
1265
1266            // failed to release sticks to neutral
1267            event_vars->Tip_Display(LSDH_TIPDURATION, "Misinput:\nDid not reset sticks \nto neutral before dropping.", hmn_data->TM.state_frame);
1268        }
1269    }
1270
1271    // check for ledgedash without refreshing
1272    if (!event_data->tip.refresh_displayed && event_data->action_state.is_finished && event_data->tip.refresh_num == 0)
1273    {
1274
1275        event_data->tip.refresh_displayed = 1;
1276
1277        // increment condition count
1278        event_data->tip.refresh_cond_num++;
1279
1280        // after 3 conditions, display tip
1281        if (event_data->tip.refresh_cond_num >= 3)
1282        {
1283            // if tip is displayed, reset cond num
1284            if (event_vars->Tip_Display(5 * 60, "Warning:\nIt is higly recommended to\nre-grab ledge after \nbeing reset to simulate \na realistic scenario!"))
1285                event_data->tip.refresh_cond_num = 0;
1286        }
1287    }
1288}
1289
1290int Update_CheckPause(void)
1291{
1292    HSD_Update *update = stc_hsd_update;
1293    int isChange = 0;
1294
1295    // menu paused
1296    if (Ldsh_FrameAdvance.val == 1)
1297    {
1298        // check if unpaused
1299        if (update->pause_kind != PAUSEKIND_SYS)
1300            isChange = 1;
1301    }
1302    // menu unpaused
1303    else
1304    {
1305        // check if paused
1306        if (update->pause_kind == PAUSEKIND_SYS)
1307            isChange = 1;
1308    }
1309
1310    return isChange;
1311}
1312int Update_CheckAdvance(void)
1313{
1314    static int timer = 0;
1315
1316    HSD_Update *update = stc_hsd_update;
1317    int isAdvance = 0;
1318
1319    GOBJ *hmn = Fighter_GetGObj(0);
1320    FighterData *hmn_data = hmn->userdata;
1321    int controller = hmn_data->pad_index;
1322
1323    // get their pad
1324    HSD_Pad *pad = PadGetMaster(controller);
1325    HSD_Pad *engine_pad = PadGetEngine(controller);
1326
1327    // get their advance input
1328    static int stc_advance_btns[] = {HSD_TRIGGER_L, HSD_TRIGGER_Z, HSD_BUTTON_X, HSD_BUTTON_Y, HSD_TRIGGER_R};
1329    Memcard *memcard = stc_memcard;
1330    u32 btn_idx = memcard->TM_LabFrameAdvanceButton;
1331    if (btn_idx >= countof(stc_advance_btns))
1332        btn_idx = 0;
1333    int advance_btn = stc_advance_btns[btn_idx];
1334
1335    // check if holding L
1336    if (Ldsh_FrameAdvance.val == 1 && (pad->held & advance_btn))
1337    {
1338        timer++;
1339
1340        // advance if first press or holding more than 10 frames
1341        if (timer == 1 || timer > 30)
1342        {
1343            isAdvance = 1;
1344
1345            // remove button input
1346            pad->down &= ~advance_btn;
1347            pad->held &= ~advance_btn;
1348            engine_pad->down &= ~advance_btn;
1349            engine_pad->held &= ~advance_btn;
1350
1351            // if using L, remove analog press too
1352            if (advance_btn == HSD_TRIGGER_L)
1353            {
1354                pad->triggerLeft = 0;
1355                pad->ftriggerLeft = 0;
1356                engine_pad->triggerLeft = 0;
1357                engine_pad->ftriggerLeft = 0;
1358            }
1359            else if (advance_btn == HSD_TRIGGER_R)
1360            {
1361                pad->triggerRight = 0;
1362                pad->ftriggerRight = 0;
1363                engine_pad->triggerRight = 0;
1364                engine_pad->ftriggerRight = 0;
1365            }
1366        }
1367    }
1368    else
1369    {
1370        update->advance = 0;
1371        timer = 0;
1372    }
1373
1374    return isAdvance;
1375}
1376
1377// Initial Menu
1378EventMenu *Event_Menu = &LdshMenu_Main;