Skip to content

Commit 1eb00f5

Browse files
authored
fix: fixed controller controls and permissions for weapons (#613)
1 parent 814102f commit 1eb00f5

4 files changed

Lines changed: 52 additions & 3 deletions

File tree

vMenu/EventManager.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ private void SetWhiteLists()
200200
// reset addons
201201
VehicleSpawner.WhitelistVehicles = new Dictionary<string, uint>();
202202
PlayerAppearance.WhitelistedPeds = new Dictionary<string, uint>();
203+
WeaponOptions.WeaponWhitelist = new Dictionary<string, uint>();
203204

204205
var jsonData = LoadResourceFile(GetCurrentResourceName(), "config/model-whitelists.json") ?? "{}";
205206
try
@@ -238,6 +239,22 @@ private void SetWhiteLists()
238239
}
239240
}
240241
}
242+
243+
// load whitelisted weapon.
244+
if (whitelists.ContainsKey("whitelistedweapons"))
245+
{
246+
foreach (var whitelist in whitelists["whitelistedweapons"])
247+
{
248+
if (!WeaponOptions.WeaponWhitelist.ContainsKey(whitelist))
249+
{
250+
WeaponOptions.WeaponWhitelist.Add(whitelist, Game.GenerateHashASCII(whitelist));
251+
}
252+
else
253+
{
254+
Debug.WriteLine($"[vMenu] [Error] Your model-whitelists.json file contains 2 or more entries with the same ped name! ({whitelist}) Please remove duplicate lines!");
255+
}
256+
}
257+
}
241258
}
242259
catch (JsonReaderException ex)
243260
{

vMenu/FunctionsController.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public void SetupTickFunctions()
7676
Tick += MiscSettings;
7777
Tick += GeneralTasks;
7878
Tick += GcTick;
79+
Tick += ControllerTick;
7980

8081
if (GetSettingsBool(Setting.keep_player_head_props))
8182
{
@@ -214,6 +215,36 @@ private async Task GcTick()
214215
}
215216
#endregion
216217

218+
#region Controller tick and functions
219+
private async Task ControllerTick()
220+
{
221+
if (!Game.IsPaused && !IsPauseMenuRestarting() && IsScreenFadedIn() && !IsPlayerSwitchInProgress() && !Game.Player.IsDead && !MenuController.DisableMenuButtons)
222+
{
223+
if (Game.CurrentInputMode == InputMode.GamePad)
224+
{
225+
await HandleMenuToggleKeyForController();
226+
}
227+
}
228+
await Task.FromResult(0);
229+
}
230+
private async Task HandleMenuToggleKeyForController()
231+
{
232+
int tmpTimer = GetGameTimer();
233+
while ((Game.IsControlPressed(0, Control.InteractionMenu) || Game.IsDisabledControlPressed(0, Control.InteractionMenu)) && !Game.IsPaused && IsScreenFadedIn() && !Game.Player.IsDead && !IsPlayerSwitchInProgress() && !MenuController.DontOpenAnyMenu)
234+
{
235+
if (GetGameTimer() - tmpTimer > 400)
236+
{
237+
if (MainMenu.Menu != null)
238+
{
239+
MainMenu.Menu.OpenMenu();
240+
}
241+
break;
242+
}
243+
await Delay(0);
244+
}
245+
}
246+
#endregion
247+
217248
#region General Tasks
218249
/// <summary>
219250
/// All general tasks that run every 1 game ticks (and are not (sub)menu specific).

vMenu/menus/WeaponOptions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class WeaponOptions
2323
public bool UnlimitedParachutes { get; private set; } = UserDefaults.WeaponsUnlimitedParachutes;
2424

2525
public static Dictionary<string, uint> AddonWeapons = new();
26+
public static Dictionary<string, uint> WeaponWhitelist = new();
2627

2728
private Dictionary<Menu, ValidWeapon> weaponInfo;
2829
private Dictionary<Menu, ValidAddonWeapon> addonWeaponInfo;

vMenuServer/MainServer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,11 +1213,11 @@ private void SetupAddonPerms(Dictionary<string, List<string>> whitelists, Dictio
12131213
{
12141214
if (whitelists.ContainsKey("whitelistedweapons"))
12151215
{
1216-
foreach (var addon in whitelists["whitelistedweapons"])
1216+
foreach (var whitelist in whitelists["whitelistedweapons"])
12171217
{
1218-
if (!SupplementaryPermissionManager.Permission.Contains("WW" + addon.ToLower().Replace("weapon_", "")))
1218+
if (!SupplementaryPermissionManager.Permission.Contains("WW" + whitelist.ToLower().Replace("weapon_", "")))
12191219
{
1220-
SupplementaryPermissionManager.Permission.Add("WW" + addon.ToLower().Replace("weapon_", ""));
1220+
SupplementaryPermissionManager.Permission.Add("WW" + whitelist.ToLower().Replace("weapon_", ""));
12211221
}
12221222
}
12231223
}

0 commit comments

Comments
 (0)