Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
TomGrobbe committed May 21, 2020
2 parents 6426b2e + 3507ebc commit 1bf5247
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 39 deletions.
8 changes: 6 additions & 2 deletions vMenu/CommonFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,9 @@ public static async void SpawnVehicle(uint vehicleHash, bool spawnInside, bool r

vehicle.CanTiresBurst = !vehicleInfo.bulletProofTires;

VehicleOptions._SET_VEHICLE_HEADLIGHTS_COLOR(vehicle, vehicleInfo.headlightColor);
SetVehicleEnveffScale(vehicle.Handle, vehicleInfo.enveffScale);

VehicleOptions._SetHeadlightsColorOnVehicle(vehicle, vehicleInfo.headlightColor);
}

// Set the previous vehicle to the new vehicle.
Expand Down Expand Up @@ -1315,6 +1317,7 @@ public struct VehicleInfo
public bool xenonHeadlights;
public bool bulletProofTires;
public int headlightColor;
public float enveffScale;
};
#endregion

Expand Down Expand Up @@ -1408,7 +1411,8 @@ public static async void SaveVehicle(string updateExistingSavedVehicleName = nul
windowTint = (int)veh.Mods.WindowTint,
xenonHeadlights = IsToggleModOn(veh.Handle, 22),
bulletProofTires = !veh.CanTiresBurst,
headlightColor = VehicleOptions._GET_VEHICLE_HEADLIGHTS_COLOR(veh)
headlightColor = VehicleOptions._GetHeadlightsColorFromVehicle(veh),
enveffScale = GetVehicleEnveffScale(veh.Handle)
};

#endregion
Expand Down
21 changes: 21 additions & 0 deletions vMenu/StorageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,27 @@ public static bool SavePedInfo(string saveName, PedInfo pedData, bool overrideEx

}

public static List<MpPedDataManager.MultiplayerPedData> GetSavedMpPeds()
{
List<MpPedDataManager.MultiplayerPedData> peds = new List<MpPedDataManager.MultiplayerPedData>();
var handle = StartFindKvp("mp_ped_");
while (true)
{
string foundName = FindKvp(handle);
if (string.IsNullOrEmpty(foundName))
{
break;
}
else
{
peds.Add(GetSavedMpCharacterData(foundName));
}
}
EndFindKvp(handle);
peds.Sort((a, b) => a.SaveName.ToLower().CompareTo(b.SaveName.ToLower()));
return peds;
}

/// <summary>
/// Delete the specified saved item from local storage.
/// </summary>
Expand Down
23 changes: 22 additions & 1 deletion vMenu/menus/MiscSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ private void CreateMenu()
{
RightIcon = MenuItem.Icon.TICK
};
MenuItem exportData = new MenuItem("Export/Import Data", "Coming soon (TM): the ability to import and export your saved data.");
MenuCheckboxItem joinQuitNotifs = new MenuCheckboxItem("Join / Quit Notifications", "Receive notifications when someone joins or leaves the server.", JoinQuitNotifications);
MenuCheckboxItem deathNotifs = new MenuCheckboxItem("Death Notifications", "Receive notifications when someone dies or gets killed.", DeathNotifications);
MenuCheckboxItem nightVision = new MenuCheckboxItem("Toggle Night Vision", "Enable or disable night vision.", false);
Expand Down Expand Up @@ -575,6 +576,7 @@ private void CreateMenu()
menu.AddMenuItem(hideHud);
menu.AddMenuItem(lockCamX);
menu.AddMenuItem(lockCamY);
menu.AddMenuItem(exportData);
menu.AddMenuItem(saveSettings);

// Handle checkbox changes.
Expand Down Expand Up @@ -690,8 +692,27 @@ private void CreateMenu()
// Handle button presses.
menu.OnItemSelect += (sender, item, index) =>
{
// export data
if (item == exportData)
{
var vehicles = GetSavedVehicles();
var normalPeds = StorageManager.GetSavedPeds();
var mpPeds = StorageManager.GetSavedMpPeds();
var weaponLoadouts = WeaponLoadouts.GetSavedWeapons();
//SetNuiFocus(true, true);
//SendNuiMessage(JsonConvert.SerializeObject(new
//var data = JsonConvert.SerializeObject(new
//{
// saved_vehicles = vehicles,
// normal_peds = normalPeds,
// mp_characters = mpPeds,
// weapon_loadouts = weaponLoadouts
//});
//Debug.WriteLine(data.Length + "\n" + data);
//TriggerServerEvent("test", data);
}
// save settings
if (item == saveSettings)
else if (item == saveSettings)
{
UserDefaults.SaveSettings();
}
Expand Down
98 changes: 66 additions & 32 deletions vMenu/menus/VehicleOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -969,9 +969,11 @@ private void CreateMenu()
MenuListItem wheelColorsList = new MenuListItem("Wheel Color", wheelColors, 0);
MenuListItem dashColorList = new MenuListItem("Dashboard Color", classic, 0);
MenuListItem intColorList = new MenuListItem("Interior / Trim Color", classic, 0);
MenuSliderItem vehicleEnveffScale = new MenuSliderItem("Vehicle Enveff Scale", "This works on certain vehicles only, like the besra for example. It 'fades' certain paint layers.", 0, 20, 10, true);

MenuItem chrome = new MenuItem("Chrome");
VehicleColorsMenu.AddMenuItem(chrome);
VehicleColorsMenu.AddMenuItem(vehicleEnveffScale);

VehicleColorsMenu.OnItemSelect += (sender, item, index) =>
{
Expand All @@ -985,7 +987,22 @@ private void CreateMenu()
}
else
{
Notify.Error("You need to be the driver of a vehicle in order to change the vehicle colors.");
Notify.Error("You need to be the driver of a driveable vehicle to change this.");
}
};
VehicleColorsMenu.OnSliderPositionChange += (m, sliderItem, oldPosition, newPosition, itemIndex) =>
{
Vehicle veh = GetVehicle();
if (veh != null && veh.Driver == Game.PlayerPed && !veh.IsDead)
{
if (sliderItem == vehicleEnveffScale)
{
SetVehicleEnveffScale(veh.Handle, newPosition / 20f);
}
}
else
{
Notify.Error("You need to be the driver of a driveable vehicle to change this slider.");
}
};

Expand Down Expand Up @@ -1733,9 +1750,12 @@ public void UpdateMods(int selectedIndex = 0)
#region more variables and setup
veh = GetVehicle();
// Create the wheel types list & listitem and add it to the menu.
List<string> wheelTypes = new List<string>() { "Sports", "Muscle", "Lowrider", "SUV", "Offroad", "Tuner", "Bike Wheels", "High End" };
MenuListItem vehicleWheelType = new MenuListItem("Wheel Type", wheelTypes, GetVehicleWheelType(veh.Handle), $"Choose a ~y~wheel type~s~ for your vehicle.");
VehicleModMenu.AddMenuItem(vehicleWheelType);
List<string> wheelTypes = new List<string>() { "Sports", "Muscle", "Lowrider", "SUV", "Offroad", "Tuner", "Bike Wheels", "High End", "Benny's (1)", "Benny's (2)" };
MenuListItem vehicleWheelType = new MenuListItem("Wheel Type", wheelTypes, MathUtil.Clamp(GetVehicleWheelType(veh.Handle), 0, 9), $"Choose a ~y~wheel type~s~ for your vehicle.");
if (!veh.Model.IsBoat && !veh.Model.IsHelicopter && !veh.Model.IsPlane && !veh.Model.IsBicycle && !veh.Model.IsTrain)
{
VehicleModMenu.AddMenuItem(vehicleWheelType);
}

// Create the checkboxes for some options.
MenuCheckboxItem toggleCustomWheels = new MenuCheckboxItem("Toggle Custom Wheels", "Press this to add or remove ~y~custom~s~ wheels.", GetVehicleModVariation(veh.Handle, 23));
Expand All @@ -1746,7 +1766,7 @@ public void UpdateMods(int selectedIndex = 0)
// Add the checkboxes to the menu.
VehicleModMenu.AddMenuItem(toggleCustomWheels);
VehicleModMenu.AddMenuItem(xenonHeadlights);
int currentHeadlightColor = _GET_VEHICLE_HEADLIGHTS_COLOR(veh);
int currentHeadlightColor = _GetHeadlightsColorFromVehicle(veh);
if (currentHeadlightColor < 0 || currentHeadlightColor > 12)
{
currentHeadlightColor = 13;
Expand Down Expand Up @@ -1926,33 +1946,46 @@ public void UpdateMods(int selectedIndex = 0)
// Wheel types
else if (item2 == vehicleWheelType)
{
// Set the wheel type.
int nindex = newIndex;
if (newIndex >= item2.ItemsCount)
// 6 should be used for bikes only.
if ((newIndex == 6 && veh.Model.IsBike) || (newIndex != 6 && !veh.Model.IsBike))
{
nindex = 0;
}
else if (newIndex < 0)
{
nindex = item2.ItemsCount - 1;
}
// Set the wheel type
SetVehicleWheelType(veh.Handle, newIndex);
// set the wheel type
SetVehicleWheelType(veh.Handle, nindex);
bool customWheels = GetVehicleModVariation(veh.Handle, 23);
bool customWheels = GetVehicleModVariation(veh.Handle, 23);
// Reset the wheel mod index for front wheels
SetVehicleMod(veh.Handle, 23, -1, customWheels);
// reset the wheel mod index for front wheels
SetVehicleMod(veh.Handle, 23, -1, customWheels);
// If the model is a bike, do the same thing for the rear wheels.
if (veh.Model.IsBike)
{
SetVehicleMod(veh.Handle, 24, -1, customWheels);
}
// if the model is a bike, do the same thing for the rear wheels.
if (veh.Model.IsBike)
// Refresh the menu with the item index so that the view doesn't change
UpdateMods(selectedIndex: itemIndex);
}
else
{
SetVehicleMod(veh.Handle, 24, -1, customWheels);
// Go past the index if it's not a bike.
if (!veh.Model.IsBike)
{
if (newIndex > oldIndex)
{
item2.ListIndex++;
}
else
{
item2.ListIndex--;
}
}
// Reset the index to 6 if it is a bike
else
{
item2.ListIndex = 6;
}
}
// Refresh the menu with the item index so that the view doesn't change
UpdateMods(selectedIndex: itemIndex);
}
// Tire smoke
else if (item2 == tireSmoke)
Expand Down Expand Up @@ -2006,11 +2039,11 @@ public void UpdateMods(int selectedIndex = 0)
{
if (newIndex == 13) // default
{
_SET_VEHICLE_HEADLIGHTS_COLOR(veh, 255);
_SetHeadlightsColorOnVehicle(veh, 255);
}
else if (newIndex > -1 && newIndex < 13)
{
_SET_VEHICLE_HEADLIGHTS_COLOR(veh, newIndex);
_SetHeadlightsColorOnVehicle(veh, newIndex);
}
}
#endregion
Expand All @@ -2033,28 +2066,29 @@ public void UpdateMods(int selectedIndex = 0)
//VehicleModMenu.CurrentIndex = selectedIndex;
}

internal static void _SET_VEHICLE_HEADLIGHTS_COLOR(Vehicle veh, int newIndex)
internal static void _SetHeadlightsColorOnVehicle(Vehicle veh, int newIndex)
{

if (veh != null && veh.Exists() && veh.Driver == Game.PlayerPed)
{
if (newIndex > -1 && newIndex < 13)
{
CitizenFX.Core.Native.Function.Call((CitizenFX.Core.Native.Hash)0xE41033B25D003A07, veh.Handle, newIndex);
SetVehicleHeadlightsColour(veh.Handle, newIndex);
}
else
{
CitizenFX.Core.Native.Function.Call((CitizenFX.Core.Native.Hash)0xE41033B25D003A07, veh.Handle, -1);
SetVehicleHeadlightsColour(veh.Handle, -1);
}
}
}

internal static int _GET_VEHICLE_HEADLIGHTS_COLOR(Vehicle vehicle)
internal static int _GetHeadlightsColorFromVehicle(Vehicle vehicle)
{
if (vehicle != null && vehicle.Exists())
{
if (IsToggleModOn(vehicle.Handle, 22))
{
int val = CitizenFX.Core.Native.Function.Call<int>((CitizenFX.Core.Native.Hash)0x3DFF319A831E0CDB, vehicle.Handle);
int val = GetVehicleHeadlightsColour(vehicle.Handle);
if (val > -1 && val < 13)
{
return val;
Expand Down
17 changes: 17 additions & 0 deletions vMenu/menus/WeaponLoadouts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ public class WeaponLoadouts

private Dictionary<string, List<ValidWeapon>> SavedWeapons = new Dictionary<string, List<ValidWeapon>>();

public static Dictionary<string, List<ValidWeapon>> GetSavedWeapons()
{
int handle = StartFindKvp("vmenu_string_saved_weapon_loadout_");
Dictionary<string, List<ValidWeapon>> saves = new Dictionary<string, List<ValidWeapon>>();
while (true)
{
string kvp = FindKvp(handle);
if (string.IsNullOrEmpty(kvp))
{
break;
}
saves.Add(kvp, JsonConvert.DeserializeObject<List<ValidWeapon>>(GetResourceKvpString(kvp)));
}
EndFindKvp(handle);
return saves;
}

private string SelectedSavedLoadoutName { get; set; } = "";
// vmenu_temp_weapons_loadout_before_respawn
// vmenu_string_saved_weapon_loadout_
Expand Down
4 changes: 2 additions & 2 deletions vMenu/vMenuClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MenuAPI.FiveM" Version="3.1.1" />
<PackageReference Include="MenuAPI.FiveM" Version="3.1.4" />

<Reference Include="Microsoft.CSharp" />

<PackageReference Include="CitizenFX.Core.Client" Version="1.0.2405">
<PackageReference Include="CitizenFX.Core.Client" Version="1.0.2457">
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>

Expand Down
4 changes: 2 additions & 2 deletions vMenuServer/vMenuServer.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net452</TargetFramework>
<DebugType>embedded</DebugType>
Expand All @@ -19,7 +19,7 @@
<ItemGroup>
<Reference Include="Microsoft.CSharp" />

<PackageReference Include="CitizenFX.Core.Server" Version="1.0.2405">
<PackageReference Include="CitizenFX.Core.Server" Version="1.0.2457">
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>

Expand Down

0 comments on commit 1bf5247

Please sign in to comment.