Read entity position directly from memory

This commit is contained in:
Sardelka
2022-07-23 23:45:20 +08:00
parent e52135c343
commit e072c2aee8
9 changed files with 59 additions and 16 deletions

View File

@ -108,8 +108,9 @@ namespace RageCoop.Client
private void OnTick(object sender, EventArgs e)
{
P= Game.Player.Character;
PlayerPosition=P.ReadPosition();
FPS=Game.FPS;
PlayerPosition=P.Position;
PlayerPosition=P.ReadPosition();
if (Game.IsLoading)
{
return;
@ -258,7 +259,7 @@ namespace RageCoop.Client
}
else
{
var V = World.GetClosestVehicle(P.Position, 50);
var V = World.GetClosestVehicle(P.ReadPosition(), 50);
if (V!=null)
{

View File

@ -51,7 +51,7 @@ namespace RageCoop.Client
}
else
{
packet.Position = p.Position;
packet.Position = p.ReadPosition();
}
if (full)
{

View File

@ -56,6 +56,7 @@
<Compile Include="Sync\EntityPool.cs" />
<Compile Include="Sync\SyncEvents.cs" />
<Compile Include="Sync\SyncParameters.cs" />
<Compile Include="Util\Memory.cs" />
<Compile Include="Util\PedConfigFlags.cs" />
<Compile Include="Util\PedExtensions.cs" />
<Compile Include="Util\TaskType.cs" />

View File

@ -211,7 +211,7 @@ namespace RageCoop.Client
private void RenderNameTag()
{
if (!Player.DisplayNameTag || (MainPed==null) || !MainPed.IsVisible || !MainPed.IsInRange(Game.Player.Character.Position, 40f))
if (!Player.DisplayNameTag || (MainPed==null) || !MainPed.IsVisible || !MainPed.IsInRange(Main.PlayerPosition, 40f))
{
return;
}
@ -343,7 +343,7 @@ namespace RageCoop.Client
{
if (IsInParachuteFreeFall)
{
MainPed.PositionNoOffset = Vector3.Lerp(MainPed.Position, Position + Velocity, 0.5f);
MainPed.PositionNoOffset = Vector3.Lerp(MainPed.ReadPosition(), Position + Velocity, 0.5f);
MainPed.Quaternion = Rotation.ToQuaternion();
if (!Function.Call<bool>(Hash.IS_ENTITY_PLAYING_ANIM, MainPed.Handle, "skydive@base", "free_idle", 3))
@ -361,7 +361,7 @@ namespace RageCoop.Client
model.Request(1000);
if (model != null)
{
ParachuteProp = World.CreateProp(model, MainPed.Position, MainPed.Rotation, false, false);
ParachuteProp = World.CreateProp(model, MainPed.ReadPosition(), MainPed.Rotation, false, false);
model.MarkAsNoLongerNeeded();
ParachuteProp.IsPositionFrozen = true;
ParachuteProp.IsCollisionEnabled = false;
@ -372,7 +372,7 @@ namespace RageCoop.Client
MainPed.Task.ClearSecondary();
}
MainPed.PositionNoOffset = Vector3.Lerp(MainPed.Position, Position + Velocity, 0.5f);
MainPed.PositionNoOffset = Vector3.Lerp(MainPed.ReadPosition(), Position + Velocity, 0.5f);
MainPed.Quaternion = Rotation.ToQuaternion();
if (!Function.Call<bool>(Hash.IS_ENTITY_PLAYING_ANIM, MainPed.Handle, "skydive@parachute@first_person", "chute_idle_right", 3))
@ -643,8 +643,8 @@ namespace RageCoop.Client
private void WalkTo()
{
Function.Call(Hash.SET_PED_STEALTH_MOVEMENT, MainPed, IsInStealthMode, 0);
Vector3 predictPosition = Position + (Position - MainPed.Position) + Velocity * 0.5f;
float range = predictPosition.DistanceToSquared(MainPed.Position);
Vector3 predictPosition = Position + (Position - MainPed.ReadPosition()) + Velocity * 0.5f;
float range = predictPosition.DistanceToSquared(MainPed.ReadPosition());
switch (Speed)
{
@ -693,7 +693,7 @@ namespace RageCoop.Client
private void SmoothTransition()
{
var localRagdoll = MainPed.IsRagdoll;
var dist = Position.DistanceTo(MainPed.Position);
var dist = Position.DistanceTo(MainPed.ReadPosition());
if (dist>3)
{
MainPed.PositionNoOffset=Position;
@ -704,7 +704,7 @@ namespace RageCoop.Client
if (!(localRagdoll|| MainPed.IsDead))
{
MainPed.Heading=Heading;
MainPed.Velocity=Velocity+5*dist*(Position-MainPed.Position);
MainPed.Velocity=Velocity+5*dist*(Position-MainPed.ReadPosition());
}
else if (Main.Ticked-_lastRagdollTime<30)
{
@ -739,7 +739,7 @@ namespace RageCoop.Client
}
else
{
MainPed.Velocity=Velocity+5*dist*(Position-MainPed.Position);
MainPed.Velocity=Velocity+5*dist*(Position-MainPed.ReadPosition());
}
// MainPed.ApplyForce(f);
}

View File

@ -349,7 +349,7 @@ namespace RageCoop.Client
}
void DisplayVehicle()
{
var current = MainVehicle.Position;
var current = MainVehicle.ReadPosition();
var predicted = Position+Velocity*(SyncParameters.PositioinPredictionDefault+0.001f*LastSyncedStopWatch.ElapsedMilliseconds);
if (current.DistanceTo(Position)<5)
{

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GTA.Math;
using GTA;
namespace RageCoop.Client
{
internal static class Memory
{
#region OFFSET-CONST
public const int PositionOffset = 144;
#endregion
public static Vector3 ReadPosition(this Entity e)
{
return ReadVector3(e.MemoryAddress+PositionOffset);
}
public unsafe static Vector3 ReadVector3(IntPtr address)
{
float* ptr = (float*)address.ToPointer();
return new Vector3()
{
X=*ptr,
Y=ptr[1],
Z=ptr[2]
};
}
}
}

View File

@ -173,7 +173,7 @@ namespace RageCoop.Client
public static Vector3 PredictPosition(this Entity e, bool applyDefault = true)
{
return e.Position+e.Velocity*((applyDefault ? SyncParameters.PositioinPredictionDefault : 0)+Networking.Latency);
return e.ReadPosition()+e.Velocity*((applyDefault ? SyncParameters.PositioinPredictionDefault : 0)+Networking.Latency);
}
public static Vehicle CreateVehicle(Model model, Vector3 position, float heading = 0f)

View File

@ -284,7 +284,7 @@ namespace RageCoop.Core
public static class PublicExtensions
{
/// <summary>
/// Get a hex-encoded string of the input string hashed by SHA256 algorithmn, internally used to hash password at client side.
/// Get a SHA256 hashed byte array of the input string, internally used to hash password at client side.
/// </summary>
/// <param name="inputString"></param>
/// <returns></returns>
@ -293,5 +293,15 @@ namespace RageCoop.Core
using (HashAlgorithm algorithm = SHA256.Create())
return algorithm.ComputeHash(Encoding.UTF8.GetBytes(inputString));
}
/// <summary>
/// Convert a byte array to hex-encoded string, internally used to trigger handshake event
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static string ToHexString(this byte[] data)
{
return BitConverter.ToString(data).Replace("-", String.Empty);
}
}
}

View File

@ -563,7 +563,7 @@ namespace RageCoop.Server
try
{
Security.AddConnection(connection.RemoteEndPoint, packet.AesKeyCrypted,packet.AesIVCrypted);
passhash=BitConverter.ToString(Security.Decrypt(packet.PassHashEncrypted, connection.RemoteEndPoint)).Replace("-", String.Empty);
passhash=Security.Decrypt(packet.PassHashEncrypted, connection.RemoteEndPoint).ToHexString();
}
catch (Exception ex)
{