Skip to content

Commit b22d462

Browse files
committed
RedM: Replace more slow native calls
1 parent 3d7c280 commit b22d462

File tree

1 file changed

+66
-61
lines changed

1 file changed

+66
-61
lines changed

MenuAPI/MenuController.cs

+66-61
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ private async Task HandleMainNavigationButtons(Menu currentMenu)
318318
Game.IsDisabledControlJustReleased(0, Control.PhoneCancel)
319319
#endif
320320
#if REDM
321-
Call<bool>(IS_DISABLED_CONTROL_JUST_RELEASED, 0, Control.CellphoneCancel)
321+
IsDisabledControlJustReleased(0, (uint)Control.CellphoneCancel)
322322
#endif
323323
)
324324
{
@@ -533,30 +533,33 @@ private async Task ProcessDirectionalButtons()
533533

534534
// Check if the Go Left controls are pressed.
535535
else if (
536+
AreMenuButtonsEnabled && (
536537
#if FIVEM
537-
Game.IsDisabledControlJustPressed(0, Control.PhoneLeft) ||
538-
Game.IsControlJustPressed(0, Control.PhoneLeft)
538+
Game.IsDisabledControlJustPressed(0, Control.PhoneLeft) ||
539+
Game.IsControlJustPressed(0, Control.PhoneLeft)
539540
#endif
540541
#if REDM
541-
IsDisabledControlJustPressed(0, (uint)Control.FrontendLeft) ||
542-
IsControlJustPressed(0, (uint)Control.FrontendLeft)
542+
IsDisabledControlJustPressed(0, (uint)Control.FrontendLeft) ||
543+
IsControlJustPressed(0, (uint)Control.FrontendLeft)
543544
#endif
545+
)
544546
)
545547
{
546548
await HandleLeftNavigation(currentMenu);
547549
}
548550

549551
// Check if the Go Right controls are pressed.
550552
else if (
553+
AreMenuButtonsEnabled && (
551554
#if FIVEM
552-
Game.IsDisabledControlJustPressed(0, Control.PhoneRight) ||
553-
Game.IsControlJustPressed(0, Control.PhoneRight)
555+
Game.IsDisabledControlJustPressed(0, Control.PhoneRight) ||
556+
Game.IsControlJustPressed(0, Control.PhoneRight)
554557
#endif
555558
#if REDM
556-
AreMenuButtonsEnabled &&
557-
Call<bool>(IS_DISABLED_CONTROL_JUST_PRESSED, 0, Control.FrontendRight) ||
558-
Call<bool>(IS_CONTROL_JUST_PRESSED, 0, Control.FrontendRight)
559+
IsDisabledControlJustPressed(0, (uint)Control.FrontendRight) ||
560+
IsControlJustPressed(0, (uint)Control.FrontendRight)
559561
#endif
562+
)
560563
)
561564
{
562565
await HandleRightNavigation(currentMenu);
@@ -576,7 +579,13 @@ private async Task HandleRightNavigation(Menu currentMenu)
576579
while ((Game.IsDisabledControlPressed(0, Control.PhoneRight) || Game.IsControlPressed(0, Control.PhoneRight)) && GetCurrentMenu() != null && AreMenuButtonsEnabled)
577580
#endif
578581
#if REDM
579-
while ((Call<bool>(IS_DISABLED_CONTROL_PRESSED, 0, Control.FrontendRight) || Call<bool>(IS_CONTROL_PRESSED, 0, Control.FrontendRight)) && GetCurrentMenu() != null && AreMenuButtonsEnabled)
582+
while (
583+
GetCurrentMenu() != null &&
584+
AreMenuButtonsEnabled && (
585+
IsDisabledControlPressed(0, (uint)Control.FrontendRight) ||
586+
IsControlPressed(0, (uint)Control.FrontendRight)
587+
)
588+
)
580589
#endif
581590
{
582591
currentMenu = GetCurrentMenu();
@@ -616,16 +625,17 @@ private async Task HandleLeftNavigation(Menu currentMenu)
616625
var times = 0;
617626
var delay = 200;
618627
while (
619-
#if FIVEM
620-
(Game.IsDisabledControlPressed(0, Control.PhoneLeft) || Game.IsControlPressed(0, Control.PhoneLeft)) &&
621628
GetCurrentMenu() != null &&
622-
AreMenuButtonsEnabled
629+
AreMenuButtonsEnabled && (
630+
#if FIVEM
631+
Game.IsDisabledControlPressed(0, Control.PhoneLeft) ||
632+
Game.IsControlPressed(0, Control.PhoneLeft)
623633
#endif
624634
#if REDM
625-
(Call<bool>(IS_DISABLED_CONTROL_PRESSED, 0, Control.FrontendLeft) || Call<bool>(IS_CONTROL_PRESSED, 0, Control.FrontendLeft)) &&
626-
GetCurrentMenu() != null &&
627-
AreMenuButtonsEnabled
635+
IsDisabledControlPressed(0, (uint)Control.FrontendLeft) ||
636+
IsControlPressed(0, (uint)Control.FrontendLeft)
628637
#endif
638+
)
629639
)
630640
{
631641
currentMenu = GetCurrentMenu();
@@ -856,10 +866,10 @@ private static void DisableControls()
856866
return;
857867
if (
858868
#if FIVEM
859-
Game.PlayerPed.IsDead
869+
Game.PlayerPed.IsDead
860870
#endif
861871
#if REDM
862-
Call<bool>(IS_ENTITY_DEAD, PlayerPedId())
872+
IsEntityDead(PlayerPedId())
863873
#endif
864874
)
865875
{
@@ -888,38 +898,38 @@ private static void DisableControls()
888898
#if REDM
889899
private static void DisableControlsRedM()
890900
{
891-
Call(DISABLE_CONTROL_ACTION, 0, Control.Attack, true);
892-
Call(DISABLE_CONTROL_ACTION, 0, Control.Attack2, true);
893-
Call(DISABLE_CONTROL_ACTION, 0, Control.HorseAim, true);
894-
Call(DISABLE_CONTROL_ACTION, 0, Control.HorseAttack, true);
895-
Call(DISABLE_CONTROL_ACTION, 0, Control.HorseAttack2, true);
896-
Call(DISABLE_CONTROL_ACTION, 0, Control.HorseMelee, true);
897-
Call(DISABLE_CONTROL_ACTION, 0, Control.MeleeAttack, true);
898-
Call(DISABLE_CONTROL_ACTION, 0, Control.MeleeBlock, true);
899-
Call(DISABLE_CONTROL_ACTION, 0, Control.MeleeGrapple, true);
900-
Call(DISABLE_CONTROL_ACTION, 0, Control.MeleeGrappleAttack, true);
901-
Call(DISABLE_CONTROL_ACTION, 0, Control.MeleeGrappleBreakout, true);
902-
Call(DISABLE_CONTROL_ACTION, 0, Control.MeleeGrappleChoke, true);
903-
Call(DISABLE_CONTROL_ACTION, 0, Control.MeleeGrappleMountSwitch, true);
904-
Call(DISABLE_CONTROL_ACTION, 0, Control.MeleeGrappleReversal, true);
905-
Call(DISABLE_CONTROL_ACTION, 0, Control.MeleeGrappleStandSwitch, true);
906-
Call(DISABLE_CONTROL_ACTION, 0, Control.MeleeHorseAttackPrimary, true);
907-
Call(DISABLE_CONTROL_ACTION, 0, Control.MeleeHorseAttackSecondary, true);
908-
Call(DISABLE_CONTROL_ACTION, 0, Control.MeleeModifier, true);
909-
Call(DISABLE_CONTROL_ACTION, 0, Control.VehAttack, true);
910-
Call(DISABLE_CONTROL_ACTION, 0, Control.VehAttack2, true);
911-
Call(DISABLE_CONTROL_ACTION, 0, Control.VehBoatAttack, true);
912-
Call(DISABLE_CONTROL_ACTION, 0, Control.VehBoatAttack2, true);
913-
Call(DISABLE_CONTROL_ACTION, 0, Control.VehCarAttack, true);
914-
Call(DISABLE_CONTROL_ACTION, 0, Control.VehCarAttack2, true);
915-
Call(DISABLE_CONTROL_ACTION, 0, Control.VehDraftAttack, true);
916-
Call(DISABLE_CONTROL_ACTION, 0, Control.VehDraftAttack2, true);
917-
Call(DISABLE_CONTROL_ACTION, 0, Control.VehFlyAttack, true);
918-
Call(DISABLE_CONTROL_ACTION, 0, Control.VehFlyAttack2, true);
919-
Call(DISABLE_CONTROL_ACTION, 0, Control.VehPassengerAttack, true);
920-
if (Call<bool>(_IS_INPUT_DISABLED, 2))
901+
DisableControlAction(0, (uint)Control.Attack, true);
902+
DisableControlAction(0, (uint)Control.Attack2, true);
903+
DisableControlAction(0, (uint)Control.HorseAim, true);
904+
DisableControlAction(0, (uint)Control.HorseAttack, true);
905+
DisableControlAction(0, (uint)Control.HorseAttack2, true);
906+
DisableControlAction(0, (uint)Control.HorseMelee, true);
907+
DisableControlAction(0, (uint)Control.MeleeAttack, true);
908+
DisableControlAction(0, (uint)Control.MeleeBlock, true);
909+
DisableControlAction(0, (uint)Control.MeleeGrapple, true);
910+
DisableControlAction(0, (uint)Control.MeleeGrappleAttack, true);
911+
DisableControlAction(0, (uint)Control.MeleeGrappleBreakout, true);
912+
DisableControlAction(0, (uint)Control.MeleeGrappleChoke, true);
913+
DisableControlAction(0, (uint)Control.MeleeGrappleMountSwitch, true);
914+
DisableControlAction(0, (uint)Control.MeleeGrappleReversal, true);
915+
DisableControlAction(0, (uint)Control.MeleeGrappleStandSwitch, true);
916+
DisableControlAction(0, (uint)Control.MeleeHorseAttackPrimary, true);
917+
DisableControlAction(0, (uint)Control.MeleeHorseAttackSecondary, true);
918+
DisableControlAction(0, (uint)Control.MeleeModifier, true);
919+
DisableControlAction(0, (uint)Control.VehAttack, true);
920+
DisableControlAction(0, (uint)Control.VehAttack2, true);
921+
DisableControlAction(0, (uint)Control.VehBoatAttack, true);
922+
DisableControlAction(0, (uint)Control.VehBoatAttack2, true);
923+
DisableControlAction(0, (uint)Control.VehCarAttack, true);
924+
DisableControlAction(0, (uint)Control.VehCarAttack2, true);
925+
DisableControlAction(0, (uint)Control.VehDraftAttack, true);
926+
DisableControlAction(0, (uint)Control.VehDraftAttack2, true);
927+
DisableControlAction(0, (uint)Control.VehFlyAttack, true);
928+
DisableControlAction(0, (uint)Control.VehFlyAttack2, true);
929+
DisableControlAction(0, (uint)Control.VehPassengerAttack, true);
930+
if (IsInputDisabled(2))
921931
{
922-
Call(DISABLE_CONTROL_ACTION, 0, Control.FrontendPauseAlternate, true);
932+
DisableControlAction(0, (uint)Control.FrontendPauseAlternate, true);
923933
}
924934
}
925935
#endif
@@ -1024,20 +1034,15 @@ private static async Task ProcessMenus()
10241034
if (!(
10251035
Menus.Any() &&
10261036
IsAnyMenuOpen() &&
1027-
#if FIVEM
10281037
IsScreenFadedIn() &&
1029-
!Game.IsPaused &&
1030-
!Game.Player.IsDead &&
1031-
!IsPlayerSwitchInProgress()
1032-
#endif
1033-
#if REDM
1034-
Call<bool>(IS_SCREEN_FADED_IN) &&
1035-
!Call<bool>(IS_PAUSE_MENU_ACTIVE) &&
1036-
!Call<bool>(IS_ENTITY_DEAD, PlayerPedId())
1038+
!IsPauseMenuActive() &&
1039+
!IsEntityDead(PlayerPedId())
1040+
#if FIVEM
1041+
&& !IsPlayerSwitchInProgress()
10371042
#endif
1038-
))
1043+
)
1044+
)
10391045
{
1040-
10411046
UnloadAssets();
10421047
return;
10431048
}

0 commit comments

Comments
 (0)