Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added feature requested in fivem discussion on discord #317

Merged
merged 7 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions SharedClasses/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ public enum Setting
vmenu_current_hour,
vmenu_current_minute,
vmenu_sync_to_machine_time,

// Voice Chat Settings
vmenu_override_voicechat_default_range,

// Key Mapping
vmenu_keymapping_id,
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion vMenu/FunctionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
127 changes: 89 additions & 38 deletions vMenu/MainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ 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 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; }
Expand Down Expand Up @@ -58,6 +58,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

Expand Down Expand Up @@ -117,7 +119,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<dynamic, List<dynamic>, string>((dynamic source, List<dynamic> 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<dynamic, List<dynamic>, string>((dynamic source, List<dynamic> 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<dynamic, List<dynamic>, string>((dynamic source, List<dynamic> args, string rawCommand) =>
Expand Down Expand Up @@ -415,20 +477,9 @@ static bool canUseMenu()
MenuController.MainMenu = null;
MenuController.DisableMenuButtons = true;
MenuController.DontOpenAnyMenu = true;
MenuController.MenuToggleKey = (Control)(-1); // disables the menu toggle key
MenuEnabled = false;
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");
Expand Down Expand Up @@ -521,34 +572,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);
}
}

Expand Down
34 changes: 33 additions & 1 deletion vMenu/Noclip.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

using CitizenFX.Core;

using static CitizenFX.Core.Native.API;

using static vMenuShared.ConfigManager;

namespace vMenuClient
{
public class NoClip : BaseScript
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();

Expand Down
58 changes: 47 additions & 11 deletions vMenu/menus/VoiceChat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

using MenuAPI;

using static vMenuClient.CommonFunctions;

using static vMenuShared.PermissionsManager;

using static vMenuShared.ConfigManager;

namespace vMenuClient.menus
{
public class VoiceChat
Expand All @@ -15,7 +19,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<string> channels = new()
{
"Channel 1 (Default)",
Expand All @@ -32,8 +36,8 @@ public class VoiceChat
20f, // 20m
100f, // 100m
300f, // 300m
1000f, // 1.000m
2000f, // 2.000m
1000f, // 1.000km
2000f, // 2.000km
0f, // global
};

Expand Down Expand Up @@ -65,7 +69,7 @@ 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.");

if (IsAllowed(Permission.VCEnable))
Expand Down Expand Up @@ -101,20 +105,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;
}
/// <summary>
/// Create the menu if it doesn't exist, and then returns it.
/// </summary>
Expand Down
9 changes: 6 additions & 3 deletions vMenuServer/config/permissions.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -535,6 +536,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 # range in meters, 0.0 is user default


# Staff voice channel is restricted to moderators/admins by default.
add_ace group.moderator "vMenu.VoiceChat.StaffChannel" allow