Skip to content

Commit

Permalink
Merge pull request #371 from Arochka/dev
Browse files Browse the repository at this point in the history
Add new player setters/getters
  • Loading branch information
FabianTerhorst committed Oct 30, 2021
2 parents 70b2684 + 00c6e14 commit 4b8167e
Show file tree
Hide file tree
Showing 13 changed files with 757 additions and 27 deletions.
15 changes: 7 additions & 8 deletions api/AltV.Net.Async/AltAsync.Player.cs
@@ -1,7 +1,6 @@
using System;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using AltV.Net.Async.Elements.Entities;
using AltV.Net.Data;
using AltV.Net.Elements.Entities;
using AltV.Net.Elements.Args;
Expand Down Expand Up @@ -119,7 +118,7 @@ public static async Task<IVehicle> GetVehicleAsync(this IPlayer player)

public static Task RemoveAllWeaponsAsync(this IPlayer player) =>
AltVAsync.Schedule(player.RemoveAllWeapons);

public static Task SetMaxHealthAsync(this IPlayer player, ushort maxhealth) =>
AltVAsync.Schedule(() => player.MaxHealth = maxhealth);

Expand Down Expand Up @@ -166,7 +165,7 @@ public static async Task EmitAsync(this IPlayer player, string eventName, params

public static Task SetVisibleAsync(this IPlayer player, bool visibility) =>
AltVAsync.Schedule(() => player.Visible = visibility);

public static Task<bool> GetStreamedAsync(this IPlayer player) =>
AltVAsync.Schedule(() => player.Streamed);

Expand All @@ -175,7 +174,7 @@ public static async Task EmitAsync(this IPlayer player, string eventName, params

public static Task<string> GetAuthTokenAsync(this IPlayer player) =>
AltVAsync.Schedule(() => player.AuthToken);

public static Task<uint> GetCurrentWeaponAsync(this IPlayer player) =>
AltVAsync.Schedule(() => player.CurrentWeapon);

Expand All @@ -199,7 +198,7 @@ public static async Task EmitAsync(this IPlayer player, string eventName, params

public static Task<ushort> GetMaxArmorAsync(this IPlayer player) =>
AltVAsync.Schedule(() => player.MaxArmor);

public static Task<ushort> GetMaxHealthAsync(this IPlayer player) =>
AltVAsync.Schedule(() => player.MaxHealth);

Expand Down Expand Up @@ -260,14 +259,14 @@ public static async Task EmitAsync(this IPlayer player, string eventName, params

public static Task SetPropsAsync(this IPlayer player, byte component, ushort drawable, byte texture) =>
AltVAsync.Schedule(() => player.SetProps(component, drawable, texture));

public static Task SetDlcPropsAsync(this IPlayer player, byte component, ushort drawable, byte texture,
uint dlc) =>
AltVAsync.Schedule(() => player.SetDlcProps(component, drawable, texture, dlc));

public static Task SetWeaponTintIndexAsync(this IPlayer player, uint weapon, byte tintIndex) =>
AltVAsync.Schedule(() => player.SetWeaponTintIndex(weapon, tintIndex));

public static Task SetWeaponTintIndexAsync(this IPlayer player, WeaponModel weaponModel, byte tintIndex) =>
AltVAsync.Schedule(() => player.SetWeaponTintIndex(weaponModel, tintIndex));

Expand All @@ -277,7 +276,7 @@ public static async Task EmitAsync(this IPlayer player, string eventName, params
public static Task SetInvincibleAsync(this IPlayer player, bool isInvincible) =>
AltVAsync.Schedule(() => player.Invincible = isInvincible);

public static Task SetIntoVehicleAsync(this IPlayer player, IVehicle vehicle, byte seat) =>
public static Task SetIntoVehicleAsync(this IPlayer player, IVehicle vehicle, byte seat) =>
AltVAsync.Schedule(() => player.SetIntoVehicle(vehicle, seat));

public static Task<bool> IsSuperJumpEnabledAsync(this IPlayer player) =>
Expand Down
158 changes: 158 additions & 0 deletions api/AltV.Net.Async/Elements/Entities/AsyncPlayer.cs
Expand Up @@ -690,5 +690,163 @@ public void PlayAmbientSpeech(string speechName, string speechParam, uint speech
{
AsyncContext.Enqueue(() => BaseObject.PlayAmbientSpeech(speechName, speechParam, speechHash));
}

public HeadBlendData HeadBlendData
{
get
{
lock(BaseObject)
{
if (!AsyncContext.CheckIfExists(BaseObject)) return default;
return BaseObject.HeadBlendData;
}
}
}

public ushort EyeColor
{
get
{
lock (BaseObject)
{
if (!AsyncContext.CheckIfExists(BaseObject)) return default;
return BaseObject.EyeColor;
}
}
}

public byte HairColor
{
get
{
AsyncContext.RunAll();
lock (BaseObject)
{
if (!AsyncContext.CheckIfExists(BaseObject)) return default;
return BaseObject.HairColor;
}
}
set { AsyncContext.Enqueue(() => BaseObject.HairColor = value); }
}

public byte HairHighlightColor
{
get
{
AsyncContext.RunAll();
lock (BaseObject)
{
if (!AsyncContext.CheckIfExists(BaseObject)) return default;
return BaseObject.HairHighlightColor;
}
}
set { AsyncContext.Enqueue(() => BaseObject.HairHighlightColor = value); }
}

public bool SetHeadOverlay(byte overlayId, byte index, float opacity)
{
AsyncContext.RunAll();
lock (BaseObject)
{
if (!AsyncContext.CheckIfExists(BaseObject)) return default;
return BaseObject.SetHeadOverlay(overlayId, index, opacity);
}
}

public bool RemoveHeadOverlay(byte overlayId)
{
AsyncContext.RunAll();
lock (BaseObject)
{
if (!AsyncContext.CheckIfExists(BaseObject)) return default;
return BaseObject.RemoveHeadOverlay(overlayId);
}
}


public bool SetHeadOverlayColor(byte overlayId, byte colorType, byte colorIndex, byte secondColorIndex)
{
AsyncContext.RunAll();
lock (BaseObject)
{
if (!AsyncContext.CheckIfExists(BaseObject)) return default;
return BaseObject.SetHeadOverlayColor(overlayId, colorType, colorIndex, secondColorIndex);
}
}

public HeadOverlay GetHeadOverlay(byte overlayID)
{
AsyncContext.RunAll();
lock (BaseObject)
{
if (!AsyncContext.CheckIfExists(BaseObject)) return default;
return BaseObject.GetHeadOverlay(overlayID);
}
}

public bool SetFaceFeature(byte index, float scale)
{
AsyncContext.RunAll();
lock (BaseObject)
{
if (!AsyncContext.CheckIfExists(BaseObject)) return default;
return BaseObject.SetFaceFeature(index, scale);
}
}

public float GetFaceFeatureScale(byte index)
{
AsyncContext.RunAll();
lock (BaseObject)
{
if (!AsyncContext.CheckIfExists(BaseObject)) return default;
return BaseObject.GetFaceFeatureScale(index);
}
}

public bool RemoveFaceFeature(byte index)
{
AsyncContext.RunAll();
lock (BaseObject)
{
if (!AsyncContext.CheckIfExists(BaseObject)) return default;
return BaseObject.RemoveFaceFeature(index);
}
}

public bool SetHeadBlendPaletteColor(byte id, Rgba rgba)
{
AsyncContext.RunAll();
lock (BaseObject)
{
if (!AsyncContext.CheckIfExists(BaseObject)) return default;
return BaseObject.SetHeadBlendPaletteColor(id, rgba);
}
}

public Rgba GetHeadBlendPaletteColor(byte id)
{
AsyncContext.RunAll();
lock (BaseObject)
{
if (!AsyncContext.CheckIfExists(BaseObject)) return default;
return BaseObject.GetHeadBlendPaletteColor(id);
}
}

public void SetHeadBlendData(uint shapeFirstID, uint shapeSecondID, uint shapeThirdID, uint skinFirstID, uint skinSecondID, uint skinThirdID, float shapeMix, float skinMix, float thirdMix)
{
AsyncContext.Enqueue(() => BaseObject.SetHeadBlendData(shapeFirstID, shapeSecondID, shapeThirdID, skinFirstID, skinSecondID, skinThirdID, shapeMix, skinMix, thirdMix));
}

public bool SetEyeColor(ushort eyeColor)
{
AsyncContext.RunAll();
lock (BaseObject)
{
if (!AsyncContext.CheckIfExists(BaseObject)) return default;
return BaseObject.SetEyeColor(eyeColor);
}
}
}
}
8 changes: 6 additions & 2 deletions api/AltV.Net.CodeGen/WriteLibrary.cs
Expand Up @@ -8,7 +8,7 @@ namespace AltV.Net.CodeGen
public static class WriteLibrary
{
private const string Quote = "\"";

private static readonly IDictionary<string, string> CToCSharpTypes = new Dictionary<string, string>
{
["alt::IPlayer*"] = "nint",
Expand Down Expand Up @@ -105,6 +105,10 @@ public static class WriteLibrary
["uint8_t&"] = "byte*",
["uint8_t*"] = "byte*",
["rgba_t"] = "Rgba",
["head_blend_data_t"] = "HeadBlendData",
["head_blend_data_t&"] = "HeadBlendData*",
["head_overlay_t"] = "HeadOverlay",
["head_overlay_t&"] = "HeadOverlay*",
["void*"] = "nint",
["const void*"] = "nint"
};
Expand Down Expand Up @@ -159,7 +163,7 @@ public static string Write(ParseExports.CMethod[] methods)
imports.Append(Environment.NewLine);

fullFile.Append(imports);

foreach (var method in methods)
{
var template = $@" public delegate* unmanaged[Cdecl]<{string.Join(", ", method.Params.Select(param => TypeToCSharp(param.Type, param.Name)).ToArray())}, {TypeToCSharp(method.ReturnType)}> {method.Name} {{ get; }}";
Expand Down
51 changes: 51 additions & 0 deletions api/AltV.Net/Data/HeadBlendData.cs
@@ -0,0 +1,51 @@
using System;
using System.Runtime.InteropServices;

namespace AltV.Net.Data
{
[StructLayout(LayoutKind.Sequential)]
public struct HeadBlendData : IEquatable<HeadBlendData>
{
public static HeadBlendData Zero = new(0, 0, 0, 0, 0, 0, 0, 0, 0);

public uint ShapeFirstID;
public uint ShapeSecondID;
public uint ShapeThirdID;
public uint SkinFirstID;
public uint SkinSecondID;
public uint SkinThirdID;
public float ShapeMix;
public float SkinMix;
public float ThirdMix;

public HeadBlendData(uint shapeFirstID, uint shapeSecondID, uint shapeThirdID, uint skinFirstID, uint skinSecondID, uint skinThirdID, float shapeMix, float skinMix, float thirdMix)
{
ShapeFirstID = shapeFirstID;
ShapeSecondID = shapeSecondID;
ShapeThirdID = shapeThirdID;
SkinFirstID = skinFirstID;
SkinSecondID = skinSecondID;
SkinThirdID = skinThirdID;
ShapeMix = shapeMix;
SkinMix = skinMix;
ThirdMix = thirdMix;
}
public override string ToString()
{
return $"HeadBlendData(shapeFirstID: {ShapeFirstID}, shapeSecondID: {ShapeSecondID}, shapeThirdID: {ShapeThirdID}, skinFirstID: {SkinFirstID}, skinSecondID: {SkinSecondID}, skinThirdID: {SkinThirdID}, shapeMix: {ShapeMix}, skinMix: {SkinMix}, thirdMix: {ThirdMix})";
}

public override bool Equals(object obj)
{
return obj is HeadBlendData other && Equals(other);
}

public bool Equals(HeadBlendData other)
{
return ShapeFirstID.Equals(other.ShapeFirstID) && ShapeSecondID.Equals(other.ShapeSecondID) && ShapeThirdID.Equals(other.ShapeThirdID) && SkinFirstID.Equals(other.SkinFirstID)
&& SkinSecondID.Equals(other.SkinSecondID) && SkinThirdID.Equals(other.SkinThirdID) && ShapeMix.Equals(other.ShapeMix) && SkinMix.Equals(other.SkinMix) && ThirdMix.Equals(other.ThirdMix);
}

public override int GetHashCode() => HashCode.Combine(HashCode.Combine(ShapeFirstID.GetHashCode(), ShapeSecondID.GetHashCode(), ShapeThirdID.GetHashCode(), SkinFirstID.GetHashCode(), SkinSecondID.GetHashCode(), SkinThirdID.GetHashCode(), ShapeMix.GetHashCode(), SkinMix.GetHashCode()), ThirdMix.GetHashCode());
}
}
43 changes: 43 additions & 0 deletions api/AltV.Net/Data/HeadOverlay.cs
@@ -0,0 +1,43 @@
using System;
using System.Runtime.InteropServices;

namespace AltV.Net.Data
{
[StructLayout(LayoutKind.Sequential)]
public struct HeadOverlay : IEquatable<HeadOverlay>
{
public static HeadOverlay Zero = new(0, 0, 0, 0, 0);

public byte Index;
public float Opacity;
public byte ColorType;
public byte ColorIndex;
public byte SecondColorIndex;

public HeadOverlay(byte index, float opacity, byte colorType, byte colorIndex, byte secondColorIndex)
{
Index = index;
Opacity = opacity;
ColorType = colorType;
ColorIndex = colorIndex;
SecondColorIndex = secondColorIndex;
}

public override string ToString()
{
return $"HeadOverlay(index: {Index}, opacity: {Opacity}, colorType: {ColorType}, colorIndex: {ColorIndex}, secondColorIndex: {SecondColorIndex})";
}

public override bool Equals(object obj)
{
return obj is HeadOverlay other && Equals(other);
}

public bool Equals(HeadOverlay other)
{
return Index.Equals(other.Index) && Opacity.Equals(other.Opacity) && ColorType.Equals(other.ColorType) && ColorIndex.Equals(other.ColorIndex) && SecondColorIndex.Equals(other.SecondColorIndex);
}

public override int GetHashCode() => HashCode.Combine(Index.GetHashCode(), Opacity.GetHashCode(), ColorType.GetHashCode(), ColorIndex.GetHashCode(), SecondColorIndex.GetHashCode());
}
}

0 comments on commit 4b8167e

Please sign in to comment.