Skip to content

Commit

Permalink
merge dev into rc
Browse files Browse the repository at this point in the history
  • Loading branch information
Doxoh committed Jan 2, 2024
2 parents c4d2123 + a8de0d5 commit 891b38c
Show file tree
Hide file tree
Showing 29 changed files with 400 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ on:
push:
tags:
- '*.*.*'
- '*.*.*-*'
- '*.*.*-*.*'
jobs:
fetch-nethost-linux:
runs-on: ubuntu-22.04
Expand Down
6 changes: 3 additions & 3 deletions api/AltV.Net.Async/AsyncCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -869,14 +869,14 @@ public override void OnGivePedScriptedTaskEvent(IntPtr eventPointer, IPlayer sou
}

public override void OnPlayerConnectDeniedEvent(PlayerConnectDeniedReason reason, string name, string ip, ulong passwordHash,
bool isDebug, string branch, uint majorVersion, string cdnUrl, long discordId)
bool isDebug, string branch, ushort versionMajor, ushort versionMinor, string cdnUrl, long discordId)
{
base.OnPlayerConnectDeniedEvent(reason, name, ip, passwordHash, isDebug, branch, majorVersion, cdnUrl, discordId);
base.OnPlayerConnectDeniedEvent(reason, name, ip, passwordHash, isDebug, branch, versionMajor, versionMinor, cdnUrl, discordId);

if (!PlayerConnectDeniedAsyncEventHandler.HasEvents()) return;
Task.Run(async () =>
{
await PlayerConnectDeniedAsyncEventHandler.CallAsync(@delegate => @delegate(reason, name, ip, passwordHash, isDebug, branch, majorVersion, cdnUrl, discordId));
await PlayerConnectDeniedAsyncEventHandler.CallAsync(@delegate => @delegate(reason, name, ip, passwordHash, isDebug, branch, versionMajor, versionMinor, cdnUrl, discordId));
});
}

Expand Down
18 changes: 16 additions & 2 deletions api/AltV.Net.Async/Elements/Entities/AsyncConnectionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,31 @@ public string Branch
}
}
}
public uint Build

public ushort VersionMajor
{
get
{
lock (ConnectionInfo)
{
if (!AsyncContext.CheckIfExistsOrCachedNullable(ConnectionInfo)) return default;
return ConnectionInfo.VersionMajor;
}
}
}

public ushort VersionMinor
{
get
{
lock (ConnectionInfo)
{
if (!AsyncContext.CheckIfExistsOrCachedNullable(ConnectionInfo)) return default;
return ConnectionInfo.Build;
return ConnectionInfo.VersionMinor;
}
}
}

public string CdnUrl
{
get
Expand Down
19 changes: 19 additions & 0 deletions api/AltV.Net.Async/Elements/Entities/AsyncVehicle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using AltV.Net.CApi.Data;
using AltV.Net.Data;
using AltV.Net.Elements.Entities;
using AltV.Net.Enums;
Expand Down Expand Up @@ -1993,6 +1994,24 @@ public List<PlayerSeat> Passengers
}
}

public void SetBage(string textureDictionary, string texture, VehicleBadgePosition[] vehicleBadgePosition)
{
lock (Vehicle)
{
if (!AsyncContext.CheckIfExistsOrCachedNullable(Vehicle)) return;
Vehicle.SetBage(textureDictionary, texture, vehicleBadgePosition);
}
}

public void SetBage(uint textureDictionary, uint texture, VehicleBadgePosition[] vehicleBadgePosition)
{
lock (Vehicle)
{
if (!AsyncContext.CheckIfExistsOrCachedNullable(Vehicle)) return;
Vehicle.SetBage(textureDictionary, texture, vehicleBadgePosition);
}
}

[Obsolete("Use new async API instead")]
public IVehicle ToAsync(IAsyncContext asyncContext)
{
Expand Down
2 changes: 1 addition & 1 deletion api/AltV.Net.Async/Events/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace AltV.Net.Async.Events
public delegate Task PlayerConnectAsyncDelegate(IPlayer player, string reason);

public delegate Task PlayerConnectDeniedAsyncDelegate(PlayerConnectDeniedReason reason, string name, string ip,
ulong passwordHash, bool isDebug, string branch, uint majorVersion, string cdnUrl, long discordId);
ulong passwordHash, bool isDebug, string branch, ushort versionMajor, ushort versionMinor, string cdnUrl, long discordId);

public delegate Task ResourceEventAsyncDelegate(INativeResource resource);

Expand Down
33 changes: 17 additions & 16 deletions api/AltV.Net.CApi.Generator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ private static string GetCMethodDelegateType(CMethod method)
var args = string.Join("", method.Params.Select(p => p.Type + ", "));
return $"delegate* unmanaged[Cdecl{noGc}]<{args}{method.ReturnType}>";
}

private static string GetCMethodArgs(CMethod method)
{
return string.Join(", ", method.Params.Select(p => p.Type + " " + p.Name));
}

public static void Generate()
{
var libOutputPath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location)!, "../../../../AltV.Net.CApi/Libraries");
var libOutputPath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location)!, "../../../../AltV.Net.CApi/Libraries");
var tableOutputPath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location)!, "../../../../../runtime/c-api/func_table.cpp");

var tableHashes = new StringBuilder();
Expand All @@ -40,31 +40,32 @@ public static void Generate()
collisionFound = true;
Console.WriteLine("Colliding methods: " + string.Join(",", collision.Select(e => e.Name)));
}

if (collisionFound) throw new Exception("Collision found!");

var capiHash = FnvHash.Generate(string.Join(";", parsedMethods.Select(e => e.Hash)));

foreach (var group in parsedMethods.OrderBy(e => e.Name).GroupBy(e => e.Target))
{
#region C# bindings
var target = group.Key.ForceCapitalize();

var methods = string.Join("\n", group.Where(e => !e.OnlyManual)
.Select(e => $" public {GetCMethodDelegateType(e)} {e.Name} {{ get; }}"));

// todo add docs link to the exception
var fallbacks = string.Join("\n", group.Where(e => !e.OnlyManual)
.Select(e => $" [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate {e.ReturnType} {e.Name}Delegate({GetCMethodArgs(e)});\n"
+ $" private static {e.ReturnType} {e.Name}Fallback({GetCMethodArgs(e)}) => throw new Exceptions.OutdatedSdkException(\"{e.Name}\", \"{e.Name} SDK method is outdated. Please update your module nuget\");"));

var loads = string.Join("\n", group.Where(e => !e.OnlyManual)
.Select(e => $" {e.Name} = ({GetCMethodDelegateType(e)}) GetUnmanagedPtr<{e.Name}Delegate>(funcTable, {e.Hash}UL, {e.Name}Fallback);"));

var output = new StringBuilder();

output.Append("// ReSharper disable InconsistentNaming\n");
output.Append("using AltV.Net.Data;\n");
output.Append("using AltV.Net.CApi.Data;\n");
output.Append("using System.Numerics;\n");
output.Append("using System.Runtime.InteropServices;\n");
output.Append("using AltV.Net.Elements.Args;\n");
Expand Down Expand Up @@ -100,21 +101,21 @@ public static void Generate()

File.WriteAllText(Path.Combine(libOutputPath, $"{target}Library.cs"), output.ToString());
#endregion

#region Func table

if (group.Key != "SHARED")
{
tableHashes.Append($" #ifdef ALT_{group.Key}_API\n");
tablePointers.Append($" #ifdef ALT_{group.Key}_API\n");
}

foreach (var e in group)
{
tableHashes.Append($" {e.Hash}UL,\n");
tablePointers.Append($" (void*) {e.Name},\n");
}

if (group.Key != "SHARED")
{
tableHashes.Append($" #endif\n");
Expand All @@ -125,13 +126,13 @@ public static void Generate()

var table = new StringBuilder();
table.Append("#include \"func_table.h\"\n\n");

table.Append($"inline uint64_t capiHash = {capiHash}UL;\n");
table.Append("inline uint64_t capiHashes[] = {\n");
table.Append(" 0,\n");
table.Append(tableHashes);
table.Append("};\n\n");

table.Append("inline void* capiPointers[] = {\n");
table.Append(" (void*) &capiHash,\n");
table.Append(tablePointers);
Expand All @@ -145,10 +146,10 @@ public static void Generate()
table.Append(" };\n");
table.Append(" return &data;\n");
table.Append("}");

File.WriteAllText(tableOutputPath, table.ToString());
}
}

public static void Main()
{
Generate();
Expand Down
2 changes: 2 additions & 0 deletions api/AltV.Net.CApi.Generator/TypeRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public static class TypeRegistry
{ "rotation_t", "Rotation" },
{ "alt::Rotation", "Rotation" },

{ "vehicleBadgePosition_t[]", "VehicleBadgePosition[]" },

{ "cloth_t&", "Cloth*" },
{ "cloth_t", "Cloth" },
{ "dlccloth_t&", "DlcCloth*" },
Expand Down
39 changes: 39 additions & 0 deletions api/AltV.Net.CApi/Data/VehicleBadgePosition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Numerics;
using System.Runtime.InteropServices;

namespace AltV.Net.CApi.Data;

[StructLayout(LayoutKind.Sequential)]
public struct VehicleBadgePosition : IEquatable<VehicleBadgePosition>
{
public VehicleBadgePosition(bool active, byte alpha, float size, short boneIndex, Vector3 offset, Vector3 direction, Vector3 side)
{
Active = active ? (byte)1 : (byte)0;
Alpha = alpha;
Size = size;
BoneIndex = boneIndex;
Offset = offset;
Direction = direction;
Side = side;
}

public byte Active { get; set; } = 0;
public byte Alpha { get; set; } = 255;
public float Size { get; set; } = 1f;
public short BoneIndex { get; set; } = 0;
public Vector3 Offset { get; set; } = new(0, 0, 0);
public Vector3 Direction { get; set; } = new(0, 0, 0);
public Vector3 Side { get; set; } = new(0, 0, 0);

public bool Equals(VehicleBadgePosition other)
{
return Active == other.Active && Alpha == other.Alpha && Size.Equals(other.Size) && BoneIndex == other.BoneIndex && Offset.Equals(other.Offset) && Direction.Equals(other.Direction) && Side.Equals(other.Side);
}

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

public override int GetHashCode() => HashCode.Combine(Active.GetHashCode(), Alpha.GetHashCode(), Size.GetHashCode(), BoneIndex.GetHashCode(), Offset.GetHashCode(), Direction.GetHashCode(), Side.GetHashCode());
}
Loading

0 comments on commit 891b38c

Please sign in to comment.