update dev

This commit is contained in:
cake
2026-01-22 02:30:22 +01:00
5 changed files with 38 additions and 48 deletions

View File

@@ -3,7 +3,7 @@
<PropertyGroup>
<Authors></Authors>
<Company></Company>
<Version>2.0.2.88</Version>
<Version>2.1.1</Version>
<Description></Description>
<Copyright></Copyright>
<PackageProjectUrl>https://github.com/Light-Public-Syncshells/LightlessClient</PackageProjectUrl>

View File

@@ -127,7 +127,7 @@ public class PlayerDataFactory
{
nint basePtr = playerPointer;
if (!PtrGuard.LooksLikePtr(basePtr))
if (!PtrGuard.LooksLikePtr(basePtr, _dalamudUtil.IsWine))
return true;
nint drawObjAddr = basePtr + _drawObjectOffset;
@@ -135,10 +135,10 @@ public class PlayerDataFactory
if (!PtrGuard.IsReadable(drawObjAddr, (nuint)IntPtr.Size))
return true;
if (!PtrGuard.TryReadIntPtr(drawObjAddr, out var drawObj))
if (!PtrGuard.TryReadIntPtr(drawObjAddr, _dalamudUtil.IsWine, out var drawObj))
return true;
if (drawObj != 0 && !PtrGuard.LooksLikePtr(drawObj))
if (drawObj != 0 && !PtrGuard.LooksLikePtr(drawObj, _dalamudUtil.IsWine))
return true;
return drawObj == 0;

View File

@@ -180,7 +180,7 @@ public sealed class GameObjectHandler : DisposableMediatorSubscriberBase, IHighP
var nextAddr = _getAddress();
if (nextAddr != IntPtr.Zero && !PtrGuard.LooksLikePtr(nextAddr))
if (nextAddr != IntPtr.Zero && !PtrGuard.LooksLikePtr(nextAddr, _dalamudUtil.IsWine))
{
nextAddr = IntPtr.Zero;
}
@@ -196,13 +196,8 @@ public sealed class GameObjectHandler : DisposableMediatorSubscriberBase, IHighP
if (Address != IntPtr.Zero)
{
var gameObject = (FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)Address;
var draw = (nint)gameObject->DrawObject;
if (!PtrGuard.LooksLikePtr(draw) || !PtrGuard.IsReadable(draw, (nuint)sizeof(DrawObject)))
draw = 0;
DrawObjectAddress = draw;
var drawObjAddr = (IntPtr)gameObject->DrawObject;
DrawObjectAddress = drawObjAddr;
EntityId = gameObject->EntityId;
if (PtrGuard.IsReadable(Address, (nuint)sizeof(Character)))
@@ -360,10 +355,7 @@ public sealed class GameObjectHandler : DisposableMediatorSubscriberBase, IHighP
private unsafe bool CompareAndUpdateMainHand(Weapon* weapon)
{
var p = (nint)weapon;
if (!PtrGuard.LooksLikePtr(p) || !PtrGuard.IsReadable(p, (nuint)sizeof(Weapon)))
return false;
if ((nint)weapon == nint.Zero) return false;
bool hasChanges = false;
hasChanges |= weapon->ModelSetId != MainHandData[0];
MainHandData[0] = weapon->ModelSetId;
@@ -376,10 +368,7 @@ public sealed class GameObjectHandler : DisposableMediatorSubscriberBase, IHighP
private unsafe bool CompareAndUpdateOffHand(Weapon* weapon)
{
var p = (nint)weapon;
if (!PtrGuard.LooksLikePtr(p) || !PtrGuard.IsReadable(p, (nuint)sizeof(Weapon)))
return false;
if ((nint)weapon == nint.Zero) return false;
bool hasChanges = false;
hasChanges |= weapon->ModelSetId != OffHandData[0];
OffHandData[0] = weapon->ModelSetId;

View File

@@ -5,40 +5,41 @@ namespace LightlessSync.Utils
{
public static partial class PtrGuard
{
private const ulong _aligmentPtr = 0x7UL;
private static readonly nuint _minAppAddr = (nuint)GetMinAppAddr();
private static readonly nuint _maxAppAddr = (nuint)GetMaxAppAddr();
private static readonly nuint _hardMinWindows =
(nuint)(IntPtr.Size == 8 ? 0x0000000100000000UL : 0x0000000000010000UL);
private static readonly nuint _hardMaxWindows =
(nuint)(IntPtr.Size == 8 ? 0x00007FFFFFFFFFFFUL : 0x7FFFFFFFUL);
private const nuint _alignmentPtr = 0x7;
private static nint GetMinAppAddr()
private static readonly (nuint min, nuint max) _sysRange = GetSysRange();
private static (nuint min, nuint max) GetSysRange()
{
GetSystemInfo(out var si);
return si.lpMinimumApplicationAddress;
return ((nuint)si.lpMinimumApplicationAddress, (nuint)si.lpMaximumApplicationAddress);
}
private static nint GetMaxAppAddr()
private static nuint GetMinAppAddr(bool isWine) => isWine ? _sysRange.min : _hardMinWindows;
private static nuint GetMaxAppAddr(bool isWine) => isWine ? _sysRange.max : _hardMaxWindows;
public static bool LooksLikePtr(nint p, bool isWine = false)
{
GetSystemInfo(out var si);
return si.lpMaximumApplicationAddress;
if (p == 0) return false;
nuint u = (nuint)p;
if (u < GetMinAppAddr(isWine)) return false;
if (u > GetMaxAppAddr(isWine)) return false;
if ((u & _alignmentPtr) != 0) return false;
if ((uint)u == 0x12345679u) return false;
return true;
}
public static bool LooksLikePtr(nint p)
{
if (p == 0) return false;
nuint u = (nuint)p;
if (u < _minAppAddr) return false;
if (u > _maxAppAddr) return false;
if ((u & _aligmentPtr) != 0) return false;
if ((uint)u == 0x12345679u) return false;
return true;
}
public static bool TryReadIntPtr(nint addr, out nint value)
public static bool TryReadIntPtr(nint addr, bool isWine, out nint value)
{
value = 0;
if (!LooksLikePtr(addr))
if (!LooksLikePtr(addr, isWine))
return false;
return ReadProcessMemory(GetCurrentProcess(), addr, out value, (nuint)IntPtr.Size, out nuint bytesRead)

View File

@@ -5,7 +5,7 @@ namespace LightlessSync.Utils
internal static class PtrGuardMemory
{
[StructLayout(LayoutKind.Sequential)]
internal struct MEMORY_BASIC_INFORMATION
internal struct MemoryBasicInformation
{
public nint BaseAddress;
public nint AllocationBase;
@@ -19,7 +19,7 @@ namespace LightlessSync.Utils
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern nuint VirtualQuery(
nint lpAddress,
out MEMORY_BASIC_INFORMATION lpBuffer,
out MemoryBasicInformation lpBuffer,
nuint dwLength);
[DllImport("kernel32.dll", SetLastError = true)]
@@ -34,10 +34,10 @@ namespace LightlessSync.Utils
internal static extern nint GetCurrentProcess();
[DllImport("kernel32.dll")]
internal static extern void GetSystemInfo(out SYSTEM_INFO lpSystemInfo);
internal static extern void GetSystemInfo(out SystemInfo lpSystemInfo);
[StructLayout(LayoutKind.Sequential)]
internal struct SYSTEM_INFO
internal struct SystemInfo
{
public ushort wProcessorArchitecture;
public ushort wReserved;