mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-13 12:14:16 +01:00
doc: SafeMemory.PtrToStructure
This commit is contained in:
parent
a3b217b3a0
commit
9d781518d6
1 changed files with 12 additions and 0 deletions
|
|
@ -190,8 +190,20 @@ namespace Dalamud
|
||||||
return WriteBytes(address, encoding.GetBytes(str + "\0"));
|
return WriteBytes(address, encoding.GetBytes(str + "\0"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Marshals data from an unmanaged block of memory to a managed object.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The type to create.</typeparam>
|
||||||
|
/// <param name="addr">The address to read from.</param>
|
||||||
|
/// <returns>The read object, or null, if it could not be read.</returns>
|
||||||
public static T? PtrToStructure<T>(IntPtr addr) where T : struct => (T?)PtrToStructure(addr, typeof(T));
|
public static T? PtrToStructure<T>(IntPtr addr) where T : struct => (T?)PtrToStructure(addr, typeof(T));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Marshals data from an unmanaged block of memory to a managed object.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="addr">The address to read from.</param>
|
||||||
|
/// <param name="type">The type to create.</param>
|
||||||
|
/// <returns>The read object, or null, if it could not be read.</returns>
|
||||||
public static object? PtrToStructure(IntPtr addr, Type type)
|
public static object? PtrToStructure(IntPtr addr, Type type)
|
||||||
{
|
{
|
||||||
var size = Marshal.SizeOf(type);
|
var size = Marshal.SizeOf(type);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue