Skip to content

Commit

Permalink
merge rc
Browse files Browse the repository at this point in the history
  • Loading branch information
Doxoh committed Jan 14, 2025
2 parents aa56b3f + 7b5f0e0 commit 19e4ce8
Show file tree
Hide file tree
Showing 26 changed files with 340 additions and 87 deletions.
64 changes: 64 additions & 0 deletions CONTRIBUTE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# How to Contribute

## Implementing [cpp-sdk](https://github.com/altmp/cpp-sdk) Changes

To implement a new `cpp-sdk` change or add a missing implementation, follow these steps:

1. **Create a New Branch**
- Start by creating a new branch based on the [dev](https://github.com/altmp/coreclr-module/tree/dev) branch.
- In the submodule `runtime`, create another branch also based on the [dev](https://github.com/altmp/coreclr-module-runtime/tree/dev) branch.

2. **Update the cpp-sdk Version**
- If required, update the `cpp-sdk` version in the `runtime` branch.

3. **Add the cpp-sdk Method**
- Add the new `cpp-sdk` method to the appropriate classes.
For example, to implement [IPlayer.GetSocialClubId()](https://github.com/altmp/cpp-sdk/blob/30b5e35ab7081f7e8ff7ac2bc0568aa7cf38e6be/objects/IPlayer.h#L90C20-L90C31), update the following runtime classes:
- [player.h](https://github.com/altmp/coreclr-module-runtime/blob/dev/c-api/entities/player.h)
- [player.cpp](https://github.com/altmp/coreclr-module-runtime/blob/dev/c-api/entities/player.cpp)

4. **Run the CApi Generator**
- Run the [CApi Generator](https://github.com/altmp/coreclr-module/blob/dev/api/AltV.Net.CApi.Generator/Program.cs) with the `runtime/c-api` folder as the working directory.

5. **Push Changes**
- Push all changes to the `runtime` branch.

6. **Implement the Method in the C# Module**
- Use the `runtime` branch to implement the method within the C# module.
For the example above, add the `SocialClubId` as a getter to the `IPlayer` interface.

7. **Add the Getter Implementation**
- Implement the getter in the `Player` class to invoke the unsafe runtime call `Core.Library.*`.

8. **Extend the AsyncPlayer Class**
- Add the method to the `AsyncPlayer` class, ensuring it calls the parent method from the `Player` class.

9. **Push Changes**
- Push all changes to the `module` branch.

10. **Testing**
- Open powershell window, change directory to root module folder. Run `gen_local_win_env.ps1` and wait everything downloaded.
- To test the changes, use the `windows-build.bat` file in the `runtime/server` folder to generate a `coreclr-module.dll`.
- Place the generated DLL in the server's `modules` folder.
- Build the module project and copy the new module DLLs to the C# resource folder and the project directory of the resource.
```
<ItemGroup>
<Reference Include="AltV.Net">
<HintPath>lib\AltV.Net.dll</HintPath>
</Reference>
<Reference Include="AltV.Net.Async">
<HintPath>lib\AltV.Net.Async.dll</HintPath>
</Reference>
<Reference Include="AltV.Net.Interactions">
<HintPath>lib\AltV.Net.Interactions.dll</HintPath>
</Reference>
<None Update="lib\*.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
```
- Test your changes thoroughly.
- **Clientside cannot be tested yet**
11. **Submit Pull Requests**
- Create separate pull requests for both the `module` branch and the `runtime` branch.
5 changes: 3 additions & 2 deletions api/AltV.Net.Async/AltAsync.RegisterEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,11 @@ public static void RegisterEvents(object target)
new[]
{
typeof(IPlayer), typeof(IEntity), typeof(uint), typeof(ushort),
typeof(Position), typeof(BodyPart)
typeof(Position), typeof(BodyPart), typeof(IEntity)
}, isAsync: true);
if (scriptFunction == null) return;
OnWeaponDamage +=
(player, targetEntity, weapon, damage, shotOffset, damageOffset) =>
(player, targetEntity, weapon, damage, shotOffset, damageOffset, sourceEntity) =>
{
var currScriptFunction = scriptFunction.Clone();
currScriptFunction.Set(player);
Expand All @@ -368,6 +368,7 @@ public static void RegisterEvents(object target)
currScriptFunction.Set(damage);
currScriptFunction.Set(shotOffset);
currScriptFunction.Set(damageOffset);
currScriptFunction.Set(sourceEntity);
return currScriptFunction.CallAsync();
};
break;
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 @@ -295,14 +295,14 @@ await ExplosionAsyncEventHandler.CallAsync(@delegate =>

public override void OnWeaponDamageEvent(IntPtr eventPointer, IPlayer sourcePlayer, IEntity targetEntity,
uint weapon, ushort damage,
Position shotOffset, BodyPart bodyPart)
Position shotOffset, BodyPart bodyPart, IEntity sourceEntity)
{
base.OnWeaponDamageEvent(eventPointer, sourcePlayer, targetEntity, weapon, damage, shotOffset, bodyPart);
base.OnWeaponDamageEvent(eventPointer, sourcePlayer, targetEntity, weapon, damage, shotOffset, bodyPart, sourceEntity);
if (!WeaponDamageAsyncEventHandler.HasEvents()) return;
Task.Run(async () =>
{
await WeaponDamageAsyncEventHandler.CallAsync(@delegate =>
@delegate(sourcePlayer, targetEntity, weapon, damage, shotOffset, bodyPart));
@delegate(sourcePlayer, targetEntity, weapon, damage, shotOffset, bodyPart, sourceEntity));
});
}

Expand Down
14 changes: 14 additions & 0 deletions api/AltV.Net.Async/Elements/Entities/AsyncConnectionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ public ulong HardwareIdExHash
}
}
}

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

public string AuthToken
{
get
Expand All @@ -74,6 +87,7 @@ public string AuthToken
}
}
}

public bool IsDebug
{
get
Expand Down
12 changes: 12 additions & 0 deletions api/AltV.Net.Async/Elements/Entities/AsyncPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ public ulong HardwareIdExHash
}
}

public string HardwareId3
{
get
{
lock (Player)
{
if (!AsyncContext.CheckIfExistsOrCachedNullable(Player)) return default;
return Player.HardwareId3;
}
}
}

public string AuthToken
{
get
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 @@ -59,7 +59,7 @@ public delegate Task ExplosionAsyncDelegate(IPlayer player, ExplosionType explos
uint explosionFx, IEntity target);

public delegate Task WeaponDamageAsyncDelegate(IPlayer player, IEntity target, uint weapon, ushort damage,
Position shotOffset, BodyPart bodyPart);
Position shotOffset, BodyPart bodyPart, IEntity sourceEntity);

public delegate Task VehicleDestroyAsyncDelegate(IVehicle vehicle);

Expand Down
4 changes: 2 additions & 2 deletions api/AltV.Net.CApi/Libraries/ClientLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ public unsafe interface IClientLibrary

public unsafe class ClientLibrary : IClientLibrary
{
public readonly uint Methods = 1810;
public readonly uint Methods = 1812;
public delegate* unmanaged[Cdecl]<nint, nint, void> Audio_AddOutput { get; }
public delegate* unmanaged[Cdecl]<nint, nint> Audio_GetBaseObject { get; }
public delegate* unmanaged[Cdecl]<nint, double> Audio_GetCurrentTime { get; }
Expand Down Expand Up @@ -3721,7 +3721,7 @@ private IntPtr GetUnmanagedPtr<T>(IDictionary<ulong, IntPtr> funcTable, ulong ha
public ClientLibrary(Dictionary<ulong, IntPtr> funcTable)
{
if (!funcTable.TryGetValue(0, out var capiHash)) Outdated = true;
else if (capiHash == IntPtr.Zero || *(ulong*)capiHash != 7720423717087039049UL) Outdated = true;
else if (capiHash == IntPtr.Zero || *(ulong*)capiHash != 992064889353150126UL) Outdated = true;
Audio_AddOutput = (delegate* unmanaged[Cdecl]<nint, nint, void>) GetUnmanagedPtr<Audio_AddOutputDelegate>(funcTable, 9914412815391408844UL, Audio_AddOutputFallback);
Audio_GetBaseObject = (delegate* unmanaged[Cdecl]<nint, nint>) GetUnmanagedPtr<Audio_GetBaseObjectDelegate>(funcTable, 6330360502401226894UL, Audio_GetBaseObjectFallback);
Audio_GetCurrentTime = (delegate* unmanaged[Cdecl]<nint, double>) GetUnmanagedPtr<Audio_GetCurrentTimeDelegate>(funcTable, 2944324482134975819UL, Audio_GetCurrentTimeFallback);
Expand Down
14 changes: 12 additions & 2 deletions api/AltV.Net.CApi/Libraries/ServerLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public unsafe interface IServerLibrary
public delegate* unmanaged[Cdecl]<IntPtr, byte> ConnectionInfo_GetCloudAuthResult { get; }
public delegate* unmanaged[Cdecl]<IntPtr, int*, nint> ConnectionInfo_GetCloudID { get; }
public delegate* unmanaged[Cdecl]<IntPtr, long> ConnectionInfo_GetDiscordUserID { get; }
public delegate* unmanaged[Cdecl]<IntPtr, int*, nint> ConnectionInfo_GetHwid3 { get; }
public delegate* unmanaged[Cdecl]<IntPtr, ulong> ConnectionInfo_GetHwIdExHash { get; }
public delegate* unmanaged[Cdecl]<IntPtr, ulong> ConnectionInfo_GetHwIdHash { get; }
public delegate* unmanaged[Cdecl]<IntPtr, uint> ConnectionInfo_GetID { get; }
Expand Down Expand Up @@ -194,6 +195,7 @@ public unsafe interface IServerLibrary
public delegate* unmanaged[Cdecl]<nint, HeadBlendData*, void> Player_GetHeadBlendData { get; }
public delegate* unmanaged[Cdecl]<nint, byte, Rgba*, void> Player_GetHeadBlendPaletteColor { get; }
public delegate* unmanaged[Cdecl]<nint, byte, HeadOverlay*, void> Player_GetHeadOverlay { get; }
public delegate* unmanaged[Cdecl]<nint, int*, nint> Player_GetHwid3 { get; }
public delegate* unmanaged[Cdecl]<nint, ulong> Player_GetHwidExHash { get; }
public delegate* unmanaged[Cdecl]<nint, ulong> Player_GetHwidHash { get; }
public delegate* unmanaged[Cdecl]<nint, uint> Player_GetInteriorLocation { get; }
Expand Down Expand Up @@ -488,7 +490,7 @@ public unsafe interface IServerLibrary

public unsafe class ServerLibrary : IServerLibrary
{
public readonly uint Methods = 1810;
public readonly uint Methods = 1812;
public delegate* unmanaged[Cdecl]<nint, nint, void> BaseObject_DeleteSyncedMetaData { get; }
public delegate* unmanaged[Cdecl]<nint, nint[], nint[], ulong, void> BaseObject_SetMultipleSyncedMetaData { get; }
public delegate* unmanaged[Cdecl]<nint, nint, nint, void> BaseObject_SetSyncedMetaData { get; }
Expand All @@ -513,6 +515,7 @@ public unsafe class ServerLibrary : IServerLibrary
public delegate* unmanaged[Cdecl]<IntPtr, byte> ConnectionInfo_GetCloudAuthResult { get; }
public delegate* unmanaged[Cdecl]<IntPtr, int*, nint> ConnectionInfo_GetCloudID { get; }
public delegate* unmanaged[Cdecl]<IntPtr, long> ConnectionInfo_GetDiscordUserID { get; }
public delegate* unmanaged[Cdecl]<IntPtr, int*, nint> ConnectionInfo_GetHwid3 { get; }
public delegate* unmanaged[Cdecl]<IntPtr, ulong> ConnectionInfo_GetHwIdExHash { get; }
public delegate* unmanaged[Cdecl]<IntPtr, ulong> ConnectionInfo_GetHwIdHash { get; }
public delegate* unmanaged[Cdecl]<IntPtr, uint> ConnectionInfo_GetID { get; }
Expand Down Expand Up @@ -672,6 +675,7 @@ public unsafe class ServerLibrary : IServerLibrary
public delegate* unmanaged[Cdecl]<nint, HeadBlendData*, void> Player_GetHeadBlendData { get; }
public delegate* unmanaged[Cdecl]<nint, byte, Rgba*, void> Player_GetHeadBlendPaletteColor { get; }
public delegate* unmanaged[Cdecl]<nint, byte, HeadOverlay*, void> Player_GetHeadOverlay { get; }
public delegate* unmanaged[Cdecl]<nint, int*, nint> Player_GetHwid3 { get; }
public delegate* unmanaged[Cdecl]<nint, ulong> Player_GetHwidExHash { get; }
public delegate* unmanaged[Cdecl]<nint, ulong> Player_GetHwidHash { get; }
public delegate* unmanaged[Cdecl]<nint, uint> Player_GetInteriorLocation { get; }
Expand Down Expand Up @@ -1010,6 +1014,8 @@ public unsafe class ServerLibrary : IServerLibrary
private static nint ConnectionInfo_GetCloudIDFallback(IntPtr _connectionInfo, int* _size) => throw new Exceptions.OutdatedSdkException("ConnectionInfo_GetCloudID", "ConnectionInfo_GetCloudID SDK method is outdated. Please update your module nuget");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate long ConnectionInfo_GetDiscordUserIDDelegate(IntPtr _connectionInfo);
private static long ConnectionInfo_GetDiscordUserIDFallback(IntPtr _connectionInfo) => throw new Exceptions.OutdatedSdkException("ConnectionInfo_GetDiscordUserID", "ConnectionInfo_GetDiscordUserID SDK method is outdated. Please update your module nuget");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate nint ConnectionInfo_GetHwid3Delegate(IntPtr _connectionInfo, int* _size);
private static nint ConnectionInfo_GetHwid3Fallback(IntPtr _connectionInfo, int* _size) => throw new Exceptions.OutdatedSdkException("ConnectionInfo_GetHwid3", "ConnectionInfo_GetHwid3 SDK method is outdated. Please update your module nuget");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate ulong ConnectionInfo_GetHwIdExHashDelegate(IntPtr _connectionInfo);
private static ulong ConnectionInfo_GetHwIdExHashFallback(IntPtr _connectionInfo) => throw new Exceptions.OutdatedSdkException("ConnectionInfo_GetHwIdExHash", "ConnectionInfo_GetHwIdExHash SDK method is outdated. Please update your module nuget");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate ulong ConnectionInfo_GetHwIdHashDelegate(IntPtr _connectionInfo);
Expand Down Expand Up @@ -1328,6 +1334,8 @@ public unsafe class ServerLibrary : IServerLibrary
private static void Player_GetHeadBlendPaletteColorFallback(nint _player, byte _id, Rgba* _headBlendPaletteColor) => throw new Exceptions.OutdatedSdkException("Player_GetHeadBlendPaletteColor", "Player_GetHeadBlendPaletteColor SDK method is outdated. Please update your module nuget");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void Player_GetHeadOverlayDelegate(nint _player, byte _overlayID, HeadOverlay* _headOverlay);
private static void Player_GetHeadOverlayFallback(nint _player, byte _overlayID, HeadOverlay* _headOverlay) => throw new Exceptions.OutdatedSdkException("Player_GetHeadOverlay", "Player_GetHeadOverlay SDK method is outdated. Please update your module nuget");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate nint Player_GetHwid3Delegate(nint _player, int* _size);
private static nint Player_GetHwid3Fallback(nint _player, int* _size) => throw new Exceptions.OutdatedSdkException("Player_GetHwid3", "Player_GetHwid3 SDK method is outdated. Please update your module nuget");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate ulong Player_GetHwidExHashDelegate(nint _player);
private static ulong Player_GetHwidExHashFallback(nint _player) => throw new Exceptions.OutdatedSdkException("Player_GetHwidExHash", "Player_GetHwidExHash SDK method is outdated. Please update your module nuget");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate ulong Player_GetHwidHashDelegate(nint _player);
Expand Down Expand Up @@ -1917,7 +1925,7 @@ private IntPtr GetUnmanagedPtr<T>(IDictionary<ulong, IntPtr> funcTable, ulong ha
public ServerLibrary(Dictionary<ulong, IntPtr> funcTable)
{
if (!funcTable.TryGetValue(0, out var capiHash)) Outdated = true;
else if (capiHash == IntPtr.Zero || *(ulong*)capiHash != 7720423717087039049UL) Outdated = true;
else if (capiHash == IntPtr.Zero || *(ulong*)capiHash != 992064889353150126UL) Outdated = true;
BaseObject_DeleteSyncedMetaData = (delegate* unmanaged[Cdecl]<nint, nint, void>) GetUnmanagedPtr<BaseObject_DeleteSyncedMetaDataDelegate>(funcTable, 8228424877092269355UL, BaseObject_DeleteSyncedMetaDataFallback);
BaseObject_SetMultipleSyncedMetaData = (delegate* unmanaged[Cdecl]<nint, nint[], nint[], ulong, void>) GetUnmanagedPtr<BaseObject_SetMultipleSyncedMetaDataDelegate>(funcTable, 1390762125822890831UL, BaseObject_SetMultipleSyncedMetaDataFallback);
BaseObject_SetSyncedMetaData = (delegate* unmanaged[Cdecl]<nint, nint, nint, void>) GetUnmanagedPtr<BaseObject_SetSyncedMetaDataDelegate>(funcTable, 8002999088966424231UL, BaseObject_SetSyncedMetaDataFallback);
Expand All @@ -1942,6 +1950,7 @@ public ServerLibrary(Dictionary<ulong, IntPtr> funcTable)
ConnectionInfo_GetCloudAuthResult = (delegate* unmanaged[Cdecl]<IntPtr, byte>) GetUnmanagedPtr<ConnectionInfo_GetCloudAuthResultDelegate>(funcTable, 7415605567391116903UL, ConnectionInfo_GetCloudAuthResultFallback);
ConnectionInfo_GetCloudID = (delegate* unmanaged[Cdecl]<IntPtr, int*, nint>) GetUnmanagedPtr<ConnectionInfo_GetCloudIDDelegate>(funcTable, 7998061229071288348UL, ConnectionInfo_GetCloudIDFallback);
ConnectionInfo_GetDiscordUserID = (delegate* unmanaged[Cdecl]<IntPtr, long>) GetUnmanagedPtr<ConnectionInfo_GetDiscordUserIDDelegate>(funcTable, 4175744399917476392UL, ConnectionInfo_GetDiscordUserIDFallback);
ConnectionInfo_GetHwid3 = (delegate* unmanaged[Cdecl]<IntPtr, int*, nint>) GetUnmanagedPtr<ConnectionInfo_GetHwid3Delegate>(funcTable, 3230557606089997547UL, ConnectionInfo_GetHwid3Fallback);
ConnectionInfo_GetHwIdExHash = (delegate* unmanaged[Cdecl]<IntPtr, ulong>) GetUnmanagedPtr<ConnectionInfo_GetHwIdExHashDelegate>(funcTable, 3151831504154255688UL, ConnectionInfo_GetHwIdExHashFallback);
ConnectionInfo_GetHwIdHash = (delegate* unmanaged[Cdecl]<IntPtr, ulong>) GetUnmanagedPtr<ConnectionInfo_GetHwIdHashDelegate>(funcTable, 11409383581668438027UL, ConnectionInfo_GetHwIdHashFallback);
ConnectionInfo_GetID = (delegate* unmanaged[Cdecl]<IntPtr, uint>) GetUnmanagedPtr<ConnectionInfo_GetIDDelegate>(funcTable, 8080268107975854795UL, ConnectionInfo_GetIDFallback);
Expand Down Expand Up @@ -2101,6 +2110,7 @@ public ServerLibrary(Dictionary<ulong, IntPtr> funcTable)
Player_GetHeadBlendData = (delegate* unmanaged[Cdecl]<nint, HeadBlendData*, void>) GetUnmanagedPtr<Player_GetHeadBlendDataDelegate>(funcTable, 12996031514192232278UL, Player_GetHeadBlendDataFallback);
Player_GetHeadBlendPaletteColor = (delegate* unmanaged[Cdecl]<nint, byte, Rgba*, void>) GetUnmanagedPtr<Player_GetHeadBlendPaletteColorDelegate>(funcTable, 6875264309357036667UL, Player_GetHeadBlendPaletteColorFallback);
Player_GetHeadOverlay = (delegate* unmanaged[Cdecl]<nint, byte, HeadOverlay*, void>) GetUnmanagedPtr<Player_GetHeadOverlayDelegate>(funcTable, 18242810182906526031UL, Player_GetHeadOverlayFallback);
Player_GetHwid3 = (delegate* unmanaged[Cdecl]<nint, int*, nint>) GetUnmanagedPtr<Player_GetHwid3Delegate>(funcTable, 13686597780873033455UL, Player_GetHwid3Fallback);
Player_GetHwidExHash = (delegate* unmanaged[Cdecl]<nint, ulong>) GetUnmanagedPtr<Player_GetHwidExHashDelegate>(funcTable, 424368865670330442UL, Player_GetHwidExHashFallback);
Player_GetHwidHash = (delegate* unmanaged[Cdecl]<nint, ulong>) GetUnmanagedPtr<Player_GetHwidHashDelegate>(funcTable, 9546723288515311389UL, Player_GetHwidHashFallback);
Player_GetInteriorLocation = (delegate* unmanaged[Cdecl]<nint, uint>) GetUnmanagedPtr<Player_GetInteriorLocationDelegate>(funcTable, 16961931856292652951UL, Player_GetInteriorLocationFallback);
Expand Down
Loading

0 comments on commit 19e4ce8

Please sign in to comment.