Some works for the new resource system
Rewrite some parts of CustomEvent Expose some API as dll entry
This commit is contained in:
@ -49,9 +49,4 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="ScriptHookVDotNetCore">
|
||||
<HintPath>..\..\libs\ScriptHookVDotNetCore.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -42,6 +42,16 @@ namespace RageCoop.Client
|
||||
DiagnosticMenu.Add(
|
||||
new NativeItem(pair.Key.ToString(), pair.Value.ToString(), pair.Value.ToString()));
|
||||
};
|
||||
ShowNetworkInfoItem.CheckboxChanged += (s, e) =>
|
||||
{
|
||||
Networking.ShowNetworkInfo = ShowNetworkInfoItem.Checked;
|
||||
};
|
||||
ShowOwnerItem.CheckboxChanged += (s, e) =>
|
||||
{
|
||||
Main.Settings.ShowEntityOwnerName = ShowOwnerItem.Checked;
|
||||
Util.SaveSettings();
|
||||
};
|
||||
#if DEBUG
|
||||
SimulatedLatencyItem.Activated += (s, e) =>
|
||||
{
|
||||
try
|
||||
@ -55,16 +65,8 @@ namespace RageCoop.Client
|
||||
Main.Logger.Error(ex);
|
||||
}
|
||||
};
|
||||
ShowNetworkInfoItem.CheckboxChanged += (s, e) =>
|
||||
{
|
||||
Networking.ShowNetworkInfo = ShowNetworkInfoItem.Checked;
|
||||
};
|
||||
ShowOwnerItem.CheckboxChanged += (s, e) =>
|
||||
{
|
||||
Main.Settings.ShowEntityOwnerName = ShowOwnerItem.Checked;
|
||||
Util.SaveSettings();
|
||||
};
|
||||
Menu.Add(SimulatedLatencyItem);
|
||||
#endif
|
||||
Menu.Add(ShowNetworkInfoItem);
|
||||
Menu.Add(ShowOwnerItem);
|
||||
Menu.AddSubMenu(DiagnosticMenu);
|
||||
|
@ -31,7 +31,6 @@ namespace RageCoop.Client
|
||||
static Networking()
|
||||
{
|
||||
Security = new Security(Main.Logger);
|
||||
Packets.CustomEvent.ResolveHandle = _resolveHandle;
|
||||
}
|
||||
|
||||
public static float Latency => ServerConnection.AverageRoundtripTime / 2;
|
||||
@ -65,12 +64,14 @@ namespace RageCoop.Client
|
||||
var config = new NetPeerConfiguration("623c92c287cc392406e7aaaac1c0f3b0")
|
||||
{
|
||||
AutoFlushSendQueue = false,
|
||||
SimulatedMinimumLatency = SimulatedLatency,
|
||||
SimulatedRandomLatency = 0,
|
||||
AcceptIncomingConnections = true,
|
||||
MaximumConnections = 32,
|
||||
PingInterval = 5
|
||||
};
|
||||
#if DEBUG
|
||||
config.SimulatedMinimumLatency = SimulatedLatency;
|
||||
config.SimulatedRandomLatency = 0;
|
||||
#endif
|
||||
|
||||
config.EnableMessageType(NetIncomingMessageType.UnconnectedData);
|
||||
config.EnableMessageType(NetIncomingMessageType.NatIntroductionSuccess);
|
||||
@ -153,7 +154,7 @@ namespace RageCoop.Client
|
||||
}
|
||||
|
||||
IsConnecting = false;
|
||||
},"Connect");
|
||||
}, "Connect");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,25 +12,7 @@ namespace RageCoop.Client
|
||||
{
|
||||
internal static partial class Networking
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to reslove entity handle in a <see cref="Packets.CustomEvent" />
|
||||
/// </summary>
|
||||
private static readonly Func<byte, NetIncomingMessage, object> _resolveHandle = (t, reader) =>
|
||||
{
|
||||
switch (t)
|
||||
{
|
||||
case 50:
|
||||
return EntityPool.ServerProps[reader.ReadInt32()].MainProp?.Handle;
|
||||
case 51:
|
||||
return EntityPool.GetPedByID(reader.ReadInt32())?.MainPed?.Handle;
|
||||
case 52:
|
||||
return EntityPool.GetVehicleByID(reader.ReadInt32())?.MainVehicle?.Handle;
|
||||
case 60:
|
||||
return EntityPool.ServerBlips[reader.ReadInt32()].Handle;
|
||||
default:
|
||||
throw new ArgumentException("Cannot resolve server side argument: " + t);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
private static readonly AutoResetEvent _publicKeyReceived = new AutoResetEvent(false);
|
||||
|
||||
|
@ -1,4 +1,7 @@
|
||||
using System.Reflection;
|
||||
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Resources;
|
||||
|
||||
// General Information
|
||||
@ -13,6 +16,7 @@ using System.Resources;
|
||||
|
||||
|
||||
// Version information
|
||||
[assembly: AssemblyVersion("1.6.0.24")]
|
||||
[assembly: AssemblyFileVersion("1.6.0.24")]
|
||||
[assembly: NeutralResourcesLanguageAttribute("en-US")]
|
||||
[assembly: AssemblyVersion("1.6.0.27")]
|
||||
[assembly: AssemblyFileVersion("1.6.0.27")]
|
||||
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]
|
||||
|
||||
|
@ -33,12 +33,6 @@
|
||||
<HintPath>..\..\libs\LemonUI.SHVDNC.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\.editorconfig">
|
||||
<Link>.editorconfig</Link>
|
||||
</None>
|
||||
<None Include="Scripting\API.Exports.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="icon.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
|
97
Client/Scripts/Scripting/API.Exports.cs
Normal file
97
Client/Scripts/Scripting/API.Exports.cs
Normal file
@ -0,0 +1,97 @@
|
||||
using Lidgren.Network;
|
||||
using RageCoop.Core.Scripting;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using static RageCoop.Core.Scripting.CustomEvents;
|
||||
|
||||
namespace RageCoop.Client.Scripting
|
||||
{
|
||||
public static unsafe partial class API
|
||||
{
|
||||
[UnmanagedCallersOnly(EntryPoint = "Connect")]
|
||||
public static void Connect(char* address) => Connect(new string(address));
|
||||
|
||||
[UnmanagedCallersOnly(EntryPoint = "GetLocalPlayerID")]
|
||||
public static int GetLocalPlayerID() => LocalPlayerID;
|
||||
|
||||
/// <summary>
|
||||
/// Get configuration value
|
||||
/// </summary>
|
||||
/// <param name="szName">The name of the config</param>
|
||||
/// <param name="buf">Buffer to store retrived value</param>
|
||||
/// <param name="bufSize">Buffer size</param>
|
||||
/// <returns>The string length of returned value, not including the null terminator</returns>
|
||||
|
||||
[UnmanagedCallersOnly(EntryPoint = "GetConfigValue")]
|
||||
public static int GetConfigValue(char* szName, char* buf, int bufSize)
|
||||
{
|
||||
var name = new string(szName);
|
||||
var value = name switch
|
||||
{
|
||||
nameof(Config.EnableAutoRespawn) => Config.EnableAutoRespawn.ToString(),
|
||||
nameof(Config.Username) => Config.Username.ToString(),
|
||||
nameof(Config.BlipColor) => Config.BlipColor.ToString(),
|
||||
nameof(Config.BlipScale) => Config.BlipScale.ToString(),
|
||||
nameof(Config.BlipSprite) => Config.BlipSprite.ToString(),
|
||||
_ => null
|
||||
};
|
||||
|
||||
if (value == null)
|
||||
return 0;
|
||||
|
||||
fixed (char* p = value)
|
||||
{
|
||||
var cbRequired = (value.Length + 1) * sizeof(char);
|
||||
Buffer.MemoryCopy(p, buf, bufSize, cbRequired);
|
||||
return value.Length;
|
||||
}
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly(EntryPoint = "SetConfigValue")]
|
||||
public static void SetConfigValue(char* szName, char* szValue)
|
||||
{
|
||||
var name = new string(szName);
|
||||
var value = new string(szValue);
|
||||
switch (name)
|
||||
{
|
||||
case nameof(Config.EnableAutoRespawn): Config.EnableAutoRespawn = bool.Parse(value); break;
|
||||
case nameof(Config.Username): Config.Username = value; break;
|
||||
case nameof(Config.BlipColor): Config.BlipColor = Enum.Parse<BlipColor>(value); break;
|
||||
case nameof(Config.BlipScale): Config.BlipScale = float.Parse(value); break;
|
||||
case nameof(Config.BlipSprite): Config.BlipSprite = Enum.Parse<BlipSprite>(value); break;
|
||||
};
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly(EntryPoint = "LocalChatMessage")]
|
||||
public static void LocalChatMessage(char* from, char* msg) => LocalChatMessage(new string(from), new string(msg));
|
||||
|
||||
[UnmanagedCallersOnly(EntryPoint = "SendChatMessage")]
|
||||
public static void SendChatMessage(char* msg) => SendChatMessage(new string(msg));
|
||||
|
||||
[UnmanagedCallersOnly(EntryPoint = "GetEventHash")]
|
||||
public static CustomEventHash GetEventHash(char* name)=>new string(name);
|
||||
|
||||
public static void SendCustomEvent(int hash, CustomEventFlags flags, byte* data, int cbData)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert Entity ID to handle
|
||||
/// </summary>
|
||||
[UnmanagedCallersOnly(EntryPoint = "IdToHandle")]
|
||||
public static int IdToHandle(byte type, int id)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
T_ID_PROP => EntityPool.GetPropByID(id)?.MainProp?.Handle ?? 0,
|
||||
T_ID_PED => EntityPool.GetPedByID(id)?.MainPed?.Handle ?? 0,
|
||||
T_ID_VEH => EntityPool.GetVehicleByID(id)?.MainVehicle?.Handle ?? 0,
|
||||
T_ID_BLIP => EntityPool.GetBlipByID(id)?.Handle ?? 0,
|
||||
_ => 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using GTA;
|
||||
using Lidgren.Network;
|
||||
@ -30,7 +31,7 @@ namespace RageCoop.Client.Scripting
|
||||
/// <summary>
|
||||
/// Provides vital functionality to interact with RAGECOOP
|
||||
/// </summary>
|
||||
public static class API
|
||||
public static unsafe partial class API
|
||||
{
|
||||
#region INTERNAL
|
||||
|
||||
@ -270,6 +271,7 @@ namespace RageCoop.Client.Scripting
|
||||
/// <summary>
|
||||
/// Disconnect from current server or cancel the connection attempt.
|
||||
/// </summary>
|
||||
[UnmanagedCallersOnly(EntryPoint = "Disconnect")]
|
||||
public static void Disconnect()
|
||||
{
|
||||
if (Networking.IsOnServer || Networking.IsConnecting) Networking.ToggleConnection(null);
|
||||
@ -369,9 +371,9 @@ namespace RageCoop.Client.Scripting
|
||||
};
|
||||
DownloadManager.DownloadCompleted += handler;
|
||||
Networking.GetResponse<Packets.FileTransferResponse>(new Packets.FileTransferRequest
|
||||
{
|
||||
Name = name
|
||||
},
|
||||
{
|
||||
Name = name
|
||||
},
|
||||
p =>
|
||||
{
|
||||
if (p.Response != FileResponse.Loaded)
|
||||
|
@ -84,14 +84,10 @@ namespace RageCoop.Client
|
||||
#region PEDS
|
||||
|
||||
public static SyncedPed GetPedByID(int id)
|
||||
{
|
||||
return PedsByID.TryGetValue(id, out var p) ? p : null;
|
||||
}
|
||||
=> PedsByID.TryGetValue(id, out var p) ? p : null;
|
||||
|
||||
public static SyncedPed GetPedByHandle(int handle)
|
||||
{
|
||||
return PedsByHandle.TryGetValue(handle, out var p) ? p : null;
|
||||
}
|
||||
=> PedsByHandle.TryGetValue(handle, out var p) ? p : null;
|
||||
|
||||
public static List<int> GetPedIDs()
|
||||
{
|
||||
@ -179,14 +175,10 @@ namespace RageCoop.Client
|
||||
#region VEHICLES
|
||||
|
||||
public static SyncedVehicle GetVehicleByID(int id)
|
||||
{
|
||||
return VehiclesByID.TryGetValue(id, out var v) ? v : null;
|
||||
}
|
||||
=> VehiclesByID.TryGetValue(id, out var v) ? v : null;
|
||||
|
||||
public static SyncedVehicle GetVehicleByHandle(int handle)
|
||||
{
|
||||
return VehiclesByHandle.TryGetValue(handle, out var v) ? v : null;
|
||||
}
|
||||
=> VehiclesByHandle.TryGetValue(handle, out var v) ? v : null;
|
||||
|
||||
public static List<int> GetVehicleIDs()
|
||||
{
|
||||
@ -233,9 +225,7 @@ namespace RageCoop.Client
|
||||
#region PROJECTILES
|
||||
|
||||
public static SyncedProjectile GetProjectileByID(int id)
|
||||
{
|
||||
return ProjectilesByID.TryGetValue(id, out var p) ? p : null;
|
||||
}
|
||||
=> ProjectilesByID.TryGetValue(id, out var p) ? p : null;
|
||||
|
||||
public static void Add(SyncedProjectile p)
|
||||
{
|
||||
@ -290,6 +280,16 @@ namespace RageCoop.Client
|
||||
|
||||
#endregion
|
||||
|
||||
#region SERVER OBJECTS
|
||||
|
||||
public static SyncedProp GetPropByID(int id)
|
||||
=> ServerProps.TryGetValue(id, out var p) ? p : null;
|
||||
|
||||
public static Blip GetBlipByID(int id)
|
||||
=> ServerBlips.TryGetValue(id, out var p) ? p : null;
|
||||
|
||||
#endregion
|
||||
|
||||
private static int vehStateIndex;
|
||||
private static int pedStateIndex;
|
||||
private static int vehStatesPerFrame;
|
||||
|
Reference in New Issue
Block a user