mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-31 21:03:43 +01:00
feat(MemoryHelper): add helpers for game allocators
This commit is contained in:
parent
a4ce3d0688
commit
173804cbe1
1 changed files with 77 additions and 0 deletions
|
|
@ -5,6 +5,7 @@ using System.Text;
|
||||||
|
|
||||||
using Dalamud.Game.Text.SeStringHandling;
|
using Dalamud.Game.Text.SeStringHandling;
|
||||||
using Dalamud.Memory.Exceptions;
|
using Dalamud.Memory.Exceptions;
|
||||||
|
using FFXIVClientStructs.FFXIV.Client.System.Memory;
|
||||||
using FFXIVClientStructs.FFXIV.Client.System.String;
|
using FFXIVClientStructs.FFXIV.Client.System.String;
|
||||||
|
|
||||||
using static Dalamud.NativeFunctions;
|
using static Dalamud.NativeFunctions;
|
||||||
|
|
@ -653,5 +654,81 @@ namespace Dalamud.Memory
|
||||||
=> SizeOf<T>(marshal) * elementCount;
|
=> SizeOf<T>(marshal) * elementCount;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Game
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Allocate memory in the game's UI memory space.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="size">Amount of bytes to allocate.</param>
|
||||||
|
/// <param name="alignment">The alignment of the allocation.</param>
|
||||||
|
/// <returns>Pointer to the allocated region.</returns>
|
||||||
|
public static IntPtr GameAllocateUi(ulong size, ulong alignment = 0)
|
||||||
|
{
|
||||||
|
return new IntPtr(IMemorySpace.GetUISpace()->Malloc(size, alignment));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Allocate memory in the game's default memory space.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="size">Amount of bytes to allocate.</param>
|
||||||
|
/// <param name="alignment">The alignment of the allocation.</param>
|
||||||
|
/// <returns>Pointer to the allocated region.</returns>
|
||||||
|
public static IntPtr GameAllocateDefault(ulong size, ulong alignment = 0)
|
||||||
|
{
|
||||||
|
return new IntPtr(IMemorySpace.GetDefaultSpace()->Malloc(size, alignment));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Allocate memory in the game's animation memory space.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="size">Amount of bytes to allocate.</param>
|
||||||
|
/// <param name="alignment">The alignment of the allocation.</param>
|
||||||
|
/// <returns>Pointer to the allocated region.</returns>
|
||||||
|
public static IntPtr GameAllocateAnimation(ulong size, ulong alignment = 0)
|
||||||
|
{
|
||||||
|
return new IntPtr(IMemorySpace.GetAnimationSpace()->Malloc(size, alignment));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Allocate memory in the game's apricot memory space.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="size">Amount of bytes to allocate.</param>
|
||||||
|
/// <param name="alignment">The alignment of the allocation.</param>
|
||||||
|
/// <returns>Pointer to the allocated region.</returns>
|
||||||
|
public static IntPtr GameAllocateApricot(ulong size, ulong alignment = 0)
|
||||||
|
{
|
||||||
|
return new IntPtr(IMemorySpace.GetApricotSpace()->Malloc(size, alignment));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Allocate memory in the game's sound memory space.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="size">Amount of bytes to allocate.</param>
|
||||||
|
/// <param name="alignment">The alignment of the allocation.</param>
|
||||||
|
/// <returns>Pointer to the allocated region.</returns>
|
||||||
|
public static IntPtr GameAllocateSound(ulong size, ulong alignment = 0)
|
||||||
|
{
|
||||||
|
return new IntPtr(IMemorySpace.GetSoundSpace()->Malloc(size, alignment));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Free memory in the game's memory space.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>The memory you are freeing must be allocated with game allocators.</remarks>
|
||||||
|
/// <param name="ptr">Position at which the memory to be freed is located.</param>
|
||||||
|
/// <param name="size">Amount of bytes to free.</param>
|
||||||
|
public static void GameFree(ref IntPtr ptr, ulong size)
|
||||||
|
{
|
||||||
|
if (ptr == IntPtr.Zero)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
IMemorySpace.Free((void*)ptr, size);
|
||||||
|
ptr = IntPtr.Zero;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue