Added seperate collections for other states, moved clean up of penumbra collection out of config. Safe read of ptr on process, fixed notfications on popup and notifications with flags.
This commit is contained in:
41
LightlessSync/Utils/MemoryProcessProbe.cs
Normal file
41
LightlessSync/Utils/MemoryProcessProbe.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace LightlessSync.Utils;
|
||||
|
||||
internal static class MemoryProcessProbe
|
||||
{
|
||||
[DllImport("kernel32.dll")]
|
||||
private static extern nint GetCurrentProcess();
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
private static extern bool ReadProcessMemory(
|
||||
nint hProcess,
|
||||
nint lpBaseAddress,
|
||||
byte[] lpBuffer,
|
||||
int dwSize,
|
||||
out nint lpNumberOfBytesRead);
|
||||
|
||||
private static readonly nint _proc = GetCurrentProcess();
|
||||
|
||||
public static bool TryReadIntPtr(nint address, out nint value)
|
||||
{
|
||||
value = nint.Zero;
|
||||
|
||||
if (address == nint.Zero)
|
||||
return false;
|
||||
|
||||
if ((ulong)address < 0x10000UL)
|
||||
return false;
|
||||
|
||||
var buf = new byte[IntPtr.Size];
|
||||
if (!ReadProcessMemory(_proc, address, buf, buf.Length, out var read) || read != (nint)buf.Length)
|
||||
return false;
|
||||
|
||||
value = IntPtr.Size == 8
|
||||
? (nint)BitConverter.ToInt64(buf, 0)
|
||||
: (nint)BitConverter.ToInt32(buf, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user