Add latency simulation
This commit is contained in:
@ -213,17 +213,8 @@ namespace RageCoop.Client
|
||||
_lastDead=P.IsDead;
|
||||
Ticked++;
|
||||
}
|
||||
Vector3 vel =new Vector3(0,0,0.123f);
|
||||
private void OnKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if(e.KeyCode == Keys.Right)
|
||||
{
|
||||
vel.Z+=0.1f;
|
||||
}
|
||||
if (e.KeyCode == Keys.Left)
|
||||
{
|
||||
vel.Z-=0.1f;
|
||||
}
|
||||
if (MainChat.Focused)
|
||||
{
|
||||
MainChat.OnKeyDown(e.KeyCode);
|
||||
|
@ -1,6 +1,7 @@
|
||||
using GTA;
|
||||
using LemonUI.Menus;
|
||||
using System.Drawing;
|
||||
using System;
|
||||
|
||||
namespace RageCoop.Client
|
||||
{
|
||||
@ -16,13 +17,13 @@ namespace RageCoop.Client
|
||||
UseMouse = false,
|
||||
Alignment = Main.Settings.FlipMenu ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left
|
||||
};
|
||||
public static NativeItem SimulatedLatencyItem = new NativeItem("Simulated network latency", "Simulated network latency in ms (one way)", "0");
|
||||
static DebugMenu()
|
||||
{
|
||||
Menu.Banner.Color = Color.FromArgb(225, 0, 0, 0);
|
||||
Menu.Title.Color = Color.FromArgb(255, 165, 0);
|
||||
|
||||
|
||||
Menu.AddSubMenu(DiagnosticMenu);
|
||||
DiagnosticMenu.Opening+=(sender, e) =>
|
||||
{
|
||||
DiagnosticMenu.Clear();
|
||||
@ -32,6 +33,16 @@ namespace RageCoop.Client
|
||||
DiagnosticMenu.Add(new NativeItem(pair.Key.ToString(), pair.Value.ToString(), pair.Value.ToString()));
|
||||
}
|
||||
};
|
||||
SimulatedLatencyItem.Activated+=(s, e) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
SimulatedLatencyItem.AltTitle=((Networking.SimulatedLatency=int.Parse(Game.GetUserInput(SimulatedLatencyItem.AltTitle))*0.002f)*500).ToString();
|
||||
}
|
||||
catch(Exception ex) { Main.Logger.Error(ex); }
|
||||
};
|
||||
Menu.Add(SimulatedLatencyItem);
|
||||
Menu.AddSubMenu(DiagnosticMenu);
|
||||
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ namespace RageCoop.Client
|
||||
public static Security Security;
|
||||
private static readonly Dictionary<int, Action<PacketType, byte[]>> PendingResponses = new Dictionary<int, Action<PacketType, byte[]>>();
|
||||
internal static readonly Dictionary<PacketType, Func<byte[], Packet>> RequestHandlers = new Dictionary<PacketType, Func<byte[], Packet>>();
|
||||
internal static float SimulatedLatency=0;
|
||||
public static bool IsConnecting { get; private set; }
|
||||
static Networking()
|
||||
{
|
||||
@ -56,10 +57,12 @@ namespace RageCoop.Client
|
||||
IsConnecting = true;
|
||||
password = password ?? Main.Settings.Password;
|
||||
username=username ?? Main.Settings.Username;
|
||||
|
||||
// 623c92c287cc392406e7aaaac1c0f3b0 = RAGECOOP
|
||||
NetPeerConfiguration config = new NetPeerConfiguration("623c92c287cc392406e7aaaac1c0f3b0")
|
||||
{
|
||||
AutoFlushSendQueue = false,
|
||||
SimulatedMinimumLatency =SimulatedLatency,
|
||||
};
|
||||
|
||||
config.EnableMessageType(NetIncomingMessageType.UnconnectedData);
|
||||
|
@ -98,6 +98,7 @@ namespace RageCoop.Client
|
||||
BrakePower = veh.BrakePower,
|
||||
};
|
||||
var velo = veh.Velocity;
|
||||
if (v.LastVelocity==default) {v.LastVelocity=velo; }
|
||||
packet.Acceleration = (velo-v.LastVelocity)*1000/v.LastSentStopWatch.ElapsedMilliseconds;
|
||||
packet.Velocity=(v.LastVelocity = velo) + packet.Acceleration*Latency;
|
||||
v.LastSentStopWatch.Restart();
|
||||
|
@ -46,6 +46,7 @@
|
||||
<Compile Include="Scripting\API.cs" />
|
||||
<Compile Include="Scripting\BaseScript.cs" />
|
||||
<Compile Include="Scripting\ClientScript.cs" />
|
||||
<Compile Include="Scripting\ResourceDomain.cs" />
|
||||
<Compile Include="Scripting\Resources.cs" />
|
||||
<Compile Include="Security.cs" />
|
||||
<Compile Include="Settings.cs" />
|
||||
@ -242,6 +243,17 @@
|
||||
<ItemGroup>
|
||||
<Content Include="FodyWeavers.xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<COMReference Include="mscoree">
|
||||
<Guid>{5477469E-83B1-11D2-8B49-00A0C9B7C9C4}</Guid>
|
||||
<VersionMajor>2</VersionMajor>
|
||||
<VersionMinor>4</VersionMinor>
|
||||
<Lcid>0</Lcid>
|
||||
<WrapperTool>tlbimp</WrapperTool>
|
||||
<Isolated>False</Isolated>
|
||||
<EmbedInteropTypes>True</EmbedInteropTypes>
|
||||
</COMReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="..\packages\Fody.6.6.3\build\Fody.targets" Condition="Exists('..\packages\Fody.6.6.3\build\Fody.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
|
@ -24,7 +24,7 @@ namespace RageCoop.Client.Scripting
|
||||
/// <summary>
|
||||
/// Provides vital functionality to interact with RAGECOOP
|
||||
/// </summary>
|
||||
public static class API
|
||||
public class API
|
||||
{
|
||||
#region INTERNAL
|
||||
internal static Dictionary<int, List<Action<CustomEventReceivedArgs>>> CustomEventHandlers = new Dictionary<int, List<Action<CustomEventReceivedArgs>>>();
|
||||
|
92
RageCoop.Client/Scripting/ResourceDomain.cs
Normal file
92
RageCoop.Client/Scripting/ResourceDomain.cs
Normal file
@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using RageCoop.Core;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
namespace RageCoop.Client.Scripting
|
||||
{
|
||||
internal class ResourceDomain:MarshalByRefObject
|
||||
{
|
||||
public AppDomain Domain;
|
||||
public ResourceDomain()
|
||||
{
|
||||
|
||||
}
|
||||
public static void CleanUp()
|
||||
{
|
||||
foreach(var d in Util.GetAppDomains())
|
||||
{
|
||||
if (d.FriendlyName.StartsWith("RageCoop"))
|
||||
{
|
||||
AppDomain.Unload(d);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static ResourceDomain Create()
|
||||
{
|
||||
// AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(Resolve);
|
||||
|
||||
AppDomainSetup ads = new AppDomainSetup
|
||||
{
|
||||
ApplicationBase = Directory.GetParent(typeof(ResourceDomain).Assembly.Location).FullName,
|
||||
DisallowBindingRedirects = false,
|
||||
DisallowCodeDownload = true,
|
||||
ConfigurationFile =
|
||||
AppDomain.CurrentDomain.SetupInformation.ConfigurationFile,
|
||||
ShadowCopyFiles = "true",
|
||||
};
|
||||
|
||||
// Create the second AppDomain.
|
||||
AppDomain ad = AppDomain.CreateDomain("RageCoop.ResourceDomain", null, ads);
|
||||
ad.AssemblyResolve+=Resolve;
|
||||
// ad.AssemblyResolve+=Resolve;
|
||||
ResourceDomain domain=(ResourceDomain)ad.CreateInstanceAndUnwrap(
|
||||
typeof(ResourceDomain).Assembly.FullName,
|
||||
typeof(ResourceDomain).FullName
|
||||
);
|
||||
domain.Domain=ad;
|
||||
Main.Logger.Debug("Hi:"+domain.Hi());
|
||||
return domain;
|
||||
}
|
||||
|
||||
private static Assembly Resolve(object sender, ResolveEventArgs args)
|
||||
{
|
||||
var assemblyName = new AssemblyName(args.Name);
|
||||
var refed=typeof(ResourceDomain).Assembly.GetReferencedAssemblies();
|
||||
if (args.Name==typeof(SHVDN.ScriptDomain).Assembly.FullName)
|
||||
{
|
||||
return typeof(SHVDN.ScriptDomain).Assembly;
|
||||
}
|
||||
else if (args.Name==typeof(GTA.Native.Function).Assembly.FullName)
|
||||
{
|
||||
return typeof(GTA.Native.Function).Assembly;
|
||||
}
|
||||
foreach (var a in refed)
|
||||
{
|
||||
if (a.Name.Equals(assemblyName))
|
||||
{
|
||||
return Assembly.Load(a);
|
||||
}
|
||||
}
|
||||
if (assemblyName.Equals(typeof(ResourceDomain).Assembly.FullName))
|
||||
{
|
||||
return typeof(ResourceDomain).Assembly;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void Destroy(ResourceDomain d)
|
||||
{
|
||||
AppDomain.Unload(d.Domain);
|
||||
}
|
||||
public string Hi()
|
||||
{
|
||||
GTA.UI.Notification.Show("Hi");
|
||||
return AppDomain.CurrentDomain.FriendlyName;
|
||||
}
|
||||
}
|
||||
}
|
@ -11,6 +11,8 @@ using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.Xml.Serialization;
|
||||
using System.Collections.Generic;
|
||||
using mscoree;
|
||||
|
||||
namespace RageCoop.Client
|
||||
{
|
||||
@ -220,6 +222,36 @@ namespace RageCoop.Client
|
||||
Function.Call(Hash.SET_RADIO_TO_STATION_INDEX, index);
|
||||
}
|
||||
|
||||
public static IList<AppDomain> GetAppDomains()
|
||||
{
|
||||
IList<AppDomain> _IList = new List<AppDomain>();
|
||||
IntPtr enumHandle = IntPtr.Zero;
|
||||
var host = new CorRuntimeHost();
|
||||
try
|
||||
{
|
||||
host.EnumDomains(out enumHandle);
|
||||
object domain = null;
|
||||
while (true)
|
||||
{
|
||||
host.NextDomain(enumHandle, out domain);
|
||||
if (domain == null) break;
|
||||
AppDomain appDomain = (AppDomain)domain;
|
||||
_IList.Add(appDomain);
|
||||
}
|
||||
return _IList;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
host.CloseEnum(enumHandle);
|
||||
Marshal.ReleaseComObject(host);
|
||||
}
|
||||
}
|
||||
|
||||
#region WIN32
|
||||
|
||||
const UInt32 WM_KEYDOWN = 0x0100;
|
||||
|
Reference in New Issue
Block a user