From 781c2224c6a5d8ce9db2ebaa1dd268fb3095c735 Mon Sep 17 00:00:00 2001 From: Ricky Merc Date: Fri, 3 Nov 2023 04:33:45 -0400 Subject: [PATCH 1/7] added feature requested in fivem discussion on discord https://discord.com/channels/285424882534187008/648513027683123213/1169114705080635422 --- SharedClasses/ConfigManager.cs | 3 +++ vMenu/menus/VoiceChat.cs | 4 +++- vMenuServer/config/permissions.cfg | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/SharedClasses/ConfigManager.cs b/SharedClasses/ConfigManager.cs index 07e1b0bf..627ebc44 100644 --- a/SharedClasses/ConfigManager.cs +++ b/SharedClasses/ConfigManager.cs @@ -61,6 +61,9 @@ public enum Setting vmenu_current_hour, vmenu_current_minute, vmenu_sync_to_machine_time, + + // Voice Chat Settings + vmenu_override_voicechat_default_range, } /// diff --git a/vMenu/menus/VoiceChat.cs b/vMenu/menus/VoiceChat.cs index d97b2447..60012360 100644 --- a/vMenu/menus/VoiceChat.cs +++ b/vMenu/menus/VoiceChat.cs @@ -6,6 +6,8 @@ using static vMenuShared.PermissionsManager; +using static vMenuShared.ConfigManager; + namespace vMenuClient.menus { public class VoiceChat @@ -15,7 +17,7 @@ public class VoiceChat public bool EnableVoicechat = UserDefaults.VoiceChatEnabled; public bool ShowCurrentSpeaker = UserDefaults.ShowCurrentSpeaker; public bool ShowVoiceStatus = UserDefaults.ShowVoiceStatus; - public float currentProximity = UserDefaults.VoiceChatProximity; + public float currentProximity = (GetSettingsFloat(Setting.vmenu_override_voicechat_default_range) != 0.0) ? GetSettingsFloat(Setting.vmenu_override_voicechat_default_range) : UserDefaults.VoiceChatProximity; public List channels = new() { "Channel 1 (Default)", diff --git a/vMenuServer/config/permissions.cfg b/vMenuServer/config/permissions.cfg index 5612b65a..1d0e46b8 100644 --- a/vMenuServer/config/permissions.cfg +++ b/vMenuServer/config/permissions.cfg @@ -535,6 +535,8 @@ add_ace builtin.everyone "vMenu.VoiceChat.Menu" allow #add_ace builtin.everyone "vMenu.VoiceChat.All" allow add_ace builtin.everyone "vMenu.VoiceChat.Enable" allow add_ace builtin.everyone "vMenu.VoiceChat.ShowSpeaker" allow +setr vmenu_override_voicechat_default_range 0.0 # options 5.0 5m, 10.0 10m, 15.0 15m, 20.0 20m, 100.0 100m, 300.0 300m, 1000.0 1000m ,2000.0 2000m, 0.0 userdefault + # Staff voice channel is restricted to moderators/admins by default. add_ace group.moderator "vMenu.VoiceChat.StaffChannel" allow From 70002dacb6b53a4c02a4d42958ab69b12d0a9ef3 Mon Sep 17 00:00:00 2001 From: Ricky Merc Date: Fri, 3 Nov 2023 04:44:20 -0400 Subject: [PATCH 2/7] Fixed typo in original source code --- vMenu/menus/VoiceChat.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vMenu/menus/VoiceChat.cs b/vMenu/menus/VoiceChat.cs index 60012360..309d1caf 100644 --- a/vMenu/menus/VoiceChat.cs +++ b/vMenu/menus/VoiceChat.cs @@ -34,8 +34,8 @@ public class VoiceChat 20f, // 20m 100f, // 100m 300f, // 300m - 1000f, // 1.000m - 2000f, // 2.000m + 1000f, // 1.000km + 2000f, // 2.000km 0f, // global }; From d9aa568cf669503a842d8f9ad6475c49b14163f9 Mon Sep 17 00:00:00 2001 From: Ricky Merc Date: Fri, 3 Nov 2023 06:56:17 -0400 Subject: [PATCH 3/7] RegisterKeyMapping setup --- SharedClasses/ConfigManager.cs | 3 + vMenu/FunctionsController.cs | 2 +- vMenu/MainMenu.cs | 129 ++++++++++++++++++++--------- vMenu/Noclip.cs | 34 +++++++- vMenuServer/config/permissions.cfg | 7 +- 5 files changed, 133 insertions(+), 42 deletions(-) diff --git a/SharedClasses/ConfigManager.cs b/SharedClasses/ConfigManager.cs index 627ebc44..01f5c612 100644 --- a/SharedClasses/ConfigManager.cs +++ b/SharedClasses/ConfigManager.cs @@ -64,6 +64,9 @@ public enum Setting // Voice Chat Settings vmenu_override_voicechat_default_range, + + // Key Mapping + vmenu_keymapping_id, } /// diff --git a/vMenu/FunctionsController.cs b/vMenu/FunctionsController.cs index c76ec5d1..5a220e6c 100644 --- a/vMenu/FunctionsController.cs +++ b/vMenu/FunctionsController.cs @@ -1063,7 +1063,7 @@ private async Task MiscRecordingKeybinds() { if (Game.CurrentInputMode == InputMode.MouseAndKeyboard) { - var recordKey = MainMenu.MenuToggleKey == Control.ReplayStartStopRecording ? Control.SaveReplayClip : Control.ReplayStartStopRecording; + var recordKey = 0 == Control.ReplayStartStopRecording ? Control.SaveReplayClip : Control.ReplayStartStopRecording; if (!IsRecording()) { if (Game.IsControlJustReleased(0, recordKey)) diff --git a/vMenu/MainMenu.cs b/vMenu/MainMenu.cs index 4f4217ac..caee46ca 100644 --- a/vMenu/MainMenu.cs +++ b/vMenu/MainMenu.cs @@ -24,8 +24,9 @@ public class MainMenu : BaseScript public static bool PermissionsSetupComplete => ArePermissionsSetup; public static bool ConfigOptionsSetupComplete = false; - public static Control MenuToggleKey { get { return MenuController.MenuToggleKey; } private set { MenuController.MenuToggleKey = value; } } // M by default (InteractionMenu) - public static int NoClipKey { get; private set; } = 289; // F2 by default (ReplayStartStopRecordingSecondary) + //public static Control MenuToggleKey { get { return MenuController.MenuToggleKey; } private set { MenuController.MenuToggleKey = value; } } // M by default (InteractionMenu) + public static string MenuToggleKey { get; private set; } = "M"; // M by default + public static string NoClipKey { get; private set; } = "F2"; // F2 by default public static Menu Menu { get; private set; } public static Menu PlayerSubmenu { get; private set; } public static Menu VehicleSubmenu { get; private set; } @@ -58,6 +59,8 @@ public class MainMenu : BaseScript public static bool DontOpenMenus { get { return MenuController.DontOpenAnyMenu; } set { MenuController.DontOpenAnyMenu = value; } } public static bool DisableControls { get { return MenuController.DisableMenuButtons; } set { MenuController.DisableMenuButtons = value; } } + public static bool MenuEnabled { get; private set; } = true; + private const int currentCleanupVersion = 2; #endregion @@ -117,7 +120,67 @@ public MainMenu() Debug.WriteLine("[vMenu] Cleanup of old unused KVP items completed."); } #endregion + #region keymapping + string KeyMappingID = String.IsNullOrWhiteSpace(GetSettingsString(Setting.vmenu_keymapping_id)) ? "Default" : GetSettingsString(Setting.vmenu_keymapping_id); + RegisterCommand($"vMenu:{KeyMappingID}:NoClip", new Action, string>((dynamic source, List args, string rawCommand) => + { + if ( IsAllowed(Permission.NoClip) ) + { + if (Game.PlayerPed.IsInVehicle()) + { + var veh = GetVehicle(); + if (veh != null && veh.Exists() && veh.Driver == Game.PlayerPed) + { + NoClipEnabled = !NoClipEnabled; + } + else + { + NoClipEnabled = false; + Notify.Error("This vehicle does not exist (somehow) or you need to be the driver of this vehicle to enable noclip!"); + } + } + else + { + NoClipEnabled = !NoClipEnabled; + } + } + }), false); + RegisterCommand($"vMenu:{KeyMappingID}:MenuToggle", new Action, string>((dynamic source, List args, string rawCommand) => + { + if (MenuEnabled) + { + if (!MenuController.IsAnyMenuOpen()) + { + Menu.OpenMenu(); + } + else + { + MenuController.CloseAllMenus(); + } + } + }), false); + if (!(GetSettingsString(Setting.vmenu_noclip_toggle_key) == null)) + { + NoClipKey = GetSettingsString(Setting.vmenu_noclip_toggle_key); + } + else + { + NoClipKey = "F2"; + } + + if (!(GetSettingsString(Setting.vmenu_menu_toggle_key) == null)) + { + MenuToggleKey = GetSettingsString(Setting.vmenu_menu_toggle_key); + } + else + { + MenuToggleKey = "M"; + } + + RegisterKeyMapping($"vMenu:{KeyMappingID}:NoClip", "vMenu NoClip Toggle Button", "keyboard", NoClipKey); + RegisterKeyMapping($"vMenu:{KeyMappingID}:MenuToggle", "vMenu Toggle Button", "keyboard", MenuToggleKey); + #endregion if (EnableExperimentalFeatures) { RegisterCommand("testped", new Action, string>((dynamic source, List args, string rawCommand) => @@ -282,6 +345,8 @@ public MainMenu() // Request server state from the server. TriggerServerEvent("vMenu:RequestServerState"); + + MenuController.MenuToggleKey = (Control)(-1); // disables the menu toggle keyMenuController.MenuToggleKey = (Control)(-1); // disables the menu toggle key } #region Infinity bits @@ -415,20 +480,10 @@ static bool canUseMenu() MenuController.MainMenu = null; MenuController.DisableMenuButtons = true; MenuController.DontOpenAnyMenu = true; + MenuEnabled = false; MenuController.MenuToggleKey = (Control)(-1); // disables the menu toggle key return; } - - if (GetSettingsInt(Setting.vmenu_menu_toggle_key) != -1) - { - MenuToggleKey = (Control)GetSettingsInt(Setting.vmenu_menu_toggle_key); - //MenuToggleKey = GetSettingsInt(Setting.vmenu_menu_toggle_key); - } - if (GetSettingsInt(Setting.vmenu_noclip_toggle_key) != -1) - { - NoClipKey = GetSettingsInt(Setting.vmenu_noclip_toggle_key); - } - // Create the main menu. Menu = new Menu(Game.Player.Name, "Main Menu"); PlayerSubmenu = new Menu(Game.Player.Name, "Player Related Options"); @@ -521,34 +576,34 @@ static bool IsOpen() Notify.Alert("You must save your ped first before exiting, or click the ~r~Exit Without Saving~s~ button."); } - if (Game.CurrentInputMode == InputMode.MouseAndKeyboard) - { - if (Game.IsControlJustPressed(0, (Control)NoClipKey) && IsAllowed(Permission.NoClip) && UpdateOnscreenKeyboard() != 0) - { - if (Game.PlayerPed.IsInVehicle()) - { - var veh = GetVehicle(); - if (veh != null && veh.Exists() && veh.Driver == Game.PlayerPed) - { - NoClipEnabled = !NoClipEnabled; - } - else - { - NoClipEnabled = false; - Notify.Error("This vehicle does not exist (somehow) or you need to be the driver of this vehicle to enable noclip!"); - } - } - else - { - NoClipEnabled = !NoClipEnabled; - } - } - } + //if (Game.CurrentInputMode == InputMode.MouseAndKeyboard) + //{ + // if (Game.IsControlJustPressed(0, (Control)NoClipKey) && IsAllowed(Permission.NoClip) && UpdateOnscreenKeyboard() != 0) + // { + // if (Game.PlayerPed.IsInVehicle()) + // { + // var veh = GetVehicle(); + // if (veh != null && veh.Exists() && veh.Driver == Game.PlayerPed) + // { + // NoClipEnabled = !NoClipEnabled; + // } + // else + // { + // NoClipEnabled = false; + // Notify.Error("This vehicle does not exist (somehow) or you need to be the driver of this vehicle to enable noclip!"); + // } + // } + // else + // { + // NoClipEnabled = !NoClipEnabled; + // } + // } + //} #endregion // Menu toggle button. - Game.DisableControlThisFrame(0, MenuToggleKey); + //Game.DisableControlThisFrame(0, MenuToggleKey); } } diff --git a/vMenu/Noclip.cs b/vMenu/Noclip.cs index 8c631561..6e78460e 100644 --- a/vMenu/Noclip.cs +++ b/vMenu/Noclip.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Threading.Tasks; @@ -5,6 +6,8 @@ using static CitizenFX.Core.Native.API; +using static vMenuShared.ConfigManager; + namespace vMenuClient { public class NoClip : BaseScript @@ -41,7 +44,35 @@ internal static bool IsNoclipActive() { return NoclipActive; } + static string JOAAT(string command) + { + uint hash = 0; + string str = command.ToLower(); + for (int i = 0; i < str.Length; i++) + { + uint letter = (uint)str[i]; + hash += letter; + hash += (hash << 10); + hash ^= (hash >> 6); + } + + hash += (hash << 3); + if (hash < 0) + { + hash = (uint)((int)hash); + } + + hash ^= (hash >> 11); + hash += (hash << 15); + + if (hash < 0) + { + hash = (uint)((int)hash); + } + + return hash.ToString("X"); + } private async Task NoClipHandler() { if (NoclipActive) @@ -99,7 +130,8 @@ private async Task NoClipHandler() BeginScaleformMovieMethod(Scale, "SET_DATA_SLOT"); ScaleformMovieMethodAddParamInt(6); - PushScaleformMovieMethodParameterString(GetControlInstructionalButton(0, MainMenu.NoClipKey, 1)); + string KeyMappingID = String.IsNullOrWhiteSpace(GetSettingsString(Setting.vmenu_keymapping_id)) ? "Default" : GetSettingsString(Setting.vmenu_keymapping_id); + PushScaleformMovieMethodParameterString($"~INPUT_{JOAAT($"vMenu:{KeyMappingID}:NoClip")}~"); PushScaleformMovieMethodParameterString($"Toggle NoClip"); EndScaleformMovieMethod(); diff --git a/vMenuServer/config/permissions.cfg b/vMenuServer/config/permissions.cfg index 1d0e46b8..184588e5 100644 --- a/vMenuServer/config/permissions.cfg +++ b/vMenuServer/config/permissions.cfg @@ -15,9 +15,10 @@ setr vmenu_menu_staff_only false # Disable setting stats like stamina, lung capacity, driving skills etc. setr vmenu_disable_player_stats_setup false -# Any valid control ID can be used here. -setr vmenu_menu_toggle_key 244 -setr vmenu_noclip_toggle_key 289 +# Key Mapping Stuff. +setr vmenu_menu_toggle_key "M" # https://docs.fivem.net/docs/game-references/input-mapper-parameter-ids/keyboard/ +setr vmenu_noclip_toggle_key "F2" # https://docs.fivem.net/docs/game-references/input-mapper-parameter-ids/keyboard/ +setr vmenu_keymapping_id "Default" # needs to be one word no spaces # Keeps spawned vehicles from de-spawning if 'replace previous vehicle' is disabled. setr vmenu_keep_spawned_vehicles_persistent false From c3eb35f2c07a7ebab94f9fc5362568d3aa532d7f Mon Sep 17 00:00:00 2001 From: Ricky Merc Date: Fri, 3 Nov 2023 07:13:50 -0400 Subject: [PATCH 4/7] removed useless code that was breaking mapping --- vMenu/MainMenu.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/vMenu/MainMenu.cs b/vMenu/MainMenu.cs index caee46ca..05dd5259 100644 --- a/vMenu/MainMenu.cs +++ b/vMenu/MainMenu.cs @@ -24,7 +24,6 @@ public class MainMenu : BaseScript public static bool PermissionsSetupComplete => ArePermissionsSetup; public static bool ConfigOptionsSetupComplete = false; - //public static Control MenuToggleKey { get { return MenuController.MenuToggleKey; } private set { MenuController.MenuToggleKey = value; } } // M by default (InteractionMenu) public static string MenuToggleKey { get; private set; } = "M"; // M by default public static string NoClipKey { get; private set; } = "F2"; // F2 by default public static Menu Menu { get; private set; } @@ -346,7 +345,6 @@ public MainMenu() // Request server state from the server. TriggerServerEvent("vMenu:RequestServerState"); - MenuController.MenuToggleKey = (Control)(-1); // disables the menu toggle keyMenuController.MenuToggleKey = (Control)(-1); // disables the menu toggle key } #region Infinity bits @@ -481,7 +479,6 @@ static bool canUseMenu() MenuController.DisableMenuButtons = true; MenuController.DontOpenAnyMenu = true; MenuEnabled = false; - MenuController.MenuToggleKey = (Control)(-1); // disables the menu toggle key return; } // Create the main menu. From 789ef81130f4d0e532c2210216bde8fc411d6b8b Mon Sep 17 00:00:00 2001 From: Ricky Merc Date: Sun, 5 Nov 2023 08:32:53 -0500 Subject: [PATCH 5/7] Voice chat modifications --- vMenu/menus/VoiceChat.cs | 52 +++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/vMenu/menus/VoiceChat.cs b/vMenu/menus/VoiceChat.cs index 309d1caf..7c1537c2 100644 --- a/vMenu/menus/VoiceChat.cs +++ b/vMenu/menus/VoiceChat.cs @@ -4,6 +4,8 @@ using MenuAPI; +using static vMenuClient.CommonFunctions; + using static vMenuShared.PermissionsManager; using static vMenuShared.ConfigManager; @@ -67,7 +69,8 @@ private void CreateMenu() "2 km", "Global", }; - var voiceChatProximity = new MenuListItem("Voice Chat Proximity", proximity, proximityRange.IndexOf(currentProximity), "Set the voice chat receiving proximity in meters."); + //var voiceChatProximity = new MenuListItem("Voice Chat Proximity", proximity, proximityRange.IndexOf(currentProximity), "Set the voice chat receiving proximity in meters."); + var voiceChatProximity = new MenuItem("Voice Chat Proximity (" + ConvertToMetric(currentProximity) + ")" , "Set the voice chat receiving proximity in meters. Set to 0 for global."); var voiceChatChannel = new MenuListItem("Voice Chat Channel", channels, channels.IndexOf(currentChannel), "Set the voice chat channel."); if (IsAllowed(Permission.VCEnable)) @@ -81,6 +84,7 @@ private void CreateMenu() } menu.AddMenuItem(voiceChatProximity); + //menu.AddMenuItem(voiceChatProximity2); menu.AddMenuItem(voiceChatChannel); menu.AddMenuItem(showVoiceStatus); } @@ -103,20 +107,52 @@ private void CreateMenu() menu.OnListIndexChange += (sender, item, oldIndex, newIndex, itemIndex) => { - if (item == voiceChatProximity) - { - currentProximity = proximityRange[newIndex]; - Subtitle.Custom($"New voice chat proximity set to: ~b~{proximity[newIndex]}~s~."); - } - else if (item == voiceChatChannel) + if (item == voiceChatChannel) { currentChannel = channels[newIndex]; Subtitle.Custom($"New voice chat channel set to: ~b~{channels[newIndex]}~s~."); } }; + menu.OnItemSelect += async (sender, item, index) => + { + if (item == voiceChatProximity) + { + var result = await GetUserInput(windowTitle: $"Enter Proximity In Meters. Current: ({ConvertToMetric(currentProximity)})", maxInputLength: 6); + + if (float.TryParse(result, out var resultfloat)) + { + currentProximity = resultfloat; + Subtitle.Custom($"New voice chat proximity set to: ~b~{ConvertToMetric(currentProximity)}~s~."); + voiceChatProximity.Text = ("Voice Chat Proximity (" + ConvertToMetric(currentProximity) + ")" ); + } + } + }; } - + static string ConvertToMetric(float input) + { + string val = "0m"; + if (input < 1.0) + { + val = (input * 100) + "cm"; + } + else if (input >= 1.0) + { + if (input < 1000) + { + val = input + "m"; + } + else + { + val = input / 1000 + "km"; + } + } + if (input==0) + { + val = "global"; + } + return val; + } /// /// Create the menu if it doesn't exist, and then returns it. /// From daf6790652ff9a86f9234210c06945c94ec97f3f Mon Sep 17 00:00:00 2001 From: Ricky Merc Date: Sun, 5 Nov 2023 18:51:56 -0500 Subject: [PATCH 6/7] should be happy now --- vMenu/MainMenu.cs | 1 - vMenu/menus/VoiceChat.cs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/vMenu/MainMenu.cs b/vMenu/MainMenu.cs index 05dd5259..aae0c470 100644 --- a/vMenu/MainMenu.cs +++ b/vMenu/MainMenu.cs @@ -344,7 +344,6 @@ public MainMenu() // Request server state from the server. TriggerServerEvent("vMenu:RequestServerState"); - } #region Infinity bits diff --git a/vMenu/menus/VoiceChat.cs b/vMenu/menus/VoiceChat.cs index 7c1537c2..e183d97a 100644 --- a/vMenu/menus/VoiceChat.cs +++ b/vMenu/menus/VoiceChat.cs @@ -144,7 +144,7 @@ static string ConvertToMetric(float input) } else { - val = input / 1000 + "km"; + val = (input / 1000) + "km"; } } if (input==0) From ee0a1d7dc3b3dd7a607682f60d71486f92ed75b5 Mon Sep 17 00:00:00 2001 From: Ricky Merc Date: Sun, 5 Nov 2023 18:56:09 -0500 Subject: [PATCH 7/7] Clean up --- vMenu/menus/VoiceChat.cs | 2 -- vMenuServer/config/permissions.cfg | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/vMenu/menus/VoiceChat.cs b/vMenu/menus/VoiceChat.cs index e183d97a..dcf4e0eb 100644 --- a/vMenu/menus/VoiceChat.cs +++ b/vMenu/menus/VoiceChat.cs @@ -69,7 +69,6 @@ private void CreateMenu() "2 km", "Global", }; - //var voiceChatProximity = new MenuListItem("Voice Chat Proximity", proximity, proximityRange.IndexOf(currentProximity), "Set the voice chat receiving proximity in meters."); var voiceChatProximity = new MenuItem("Voice Chat Proximity (" + ConvertToMetric(currentProximity) + ")" , "Set the voice chat receiving proximity in meters. Set to 0 for global."); var voiceChatChannel = new MenuListItem("Voice Chat Channel", channels, channels.IndexOf(currentChannel), "Set the voice chat channel."); @@ -84,7 +83,6 @@ private void CreateMenu() } menu.AddMenuItem(voiceChatProximity); - //menu.AddMenuItem(voiceChatProximity2); menu.AddMenuItem(voiceChatChannel); menu.AddMenuItem(showVoiceStatus); } diff --git a/vMenuServer/config/permissions.cfg b/vMenuServer/config/permissions.cfg index 184588e5..82a1da73 100644 --- a/vMenuServer/config/permissions.cfg +++ b/vMenuServer/config/permissions.cfg @@ -536,7 +536,7 @@ add_ace builtin.everyone "vMenu.VoiceChat.Menu" allow #add_ace builtin.everyone "vMenu.VoiceChat.All" allow add_ace builtin.everyone "vMenu.VoiceChat.Enable" allow add_ace builtin.everyone "vMenu.VoiceChat.ShowSpeaker" allow -setr vmenu_override_voicechat_default_range 0.0 # options 5.0 5m, 10.0 10m, 15.0 15m, 20.0 20m, 100.0 100m, 300.0 300m, 1000.0 1000m ,2000.0 2000m, 0.0 userdefault +setr vmenu_override_voicechat_default_range 0.0 # range in meters, 0.0 is user default # Staff voice channel is restricted to moderators/admins by default.