diff --git a/Dalamud/Memory/MemoryHelper.cs b/Dalamud/Memory/MemoryHelper.cs index d663f2245..cf483b65b 100644 --- a/Dalamud/Memory/MemoryHelper.cs +++ b/Dalamud/Memory/MemoryHelper.cs @@ -48,11 +48,11 @@ namespace Dalamud.Memory } /// - /// Reads a generic type from a specified memory address. + /// Reads a byte array from a specified memory address. /// /// The memory address to read from. /// The amount of bytes to read starting from the memoryAddress. - /// The read in struct. + /// The read in byte array. public static byte[] ReadRaw(IntPtr memoryAddress, int length) { var value = new byte[length]; @@ -93,6 +93,22 @@ namespace Dalamud.Memory return value; } + /// + /// Reads a null-terminated byte array from a specified memory address. + /// + /// The memory address to read from. + /// The read in byte array. + public static unsafe byte[] ReadRawNullTerminated(IntPtr memoryAddress) + { + var byteCount = 0; + while (*(byte*)(memoryAddress + byteCount) != 0x00) + { + byteCount++; + } + + return ReadRaw(memoryAddress, byteCount); + } + #endregion #region Read(out) @@ -207,13 +223,24 @@ namespace Dalamud.Memory return eosPos >= 0 ? data.Substring(0, eosPos) : data; } + /// + /// Read a null-terminated SeString from a specified memory address. + /// + /// The memory address to read from. + /// The read in string. + public static SeString ReadSeStringNullTerminated(IntPtr memoryAddress) + { + var buffer = ReadRawNullTerminated(memoryAddress); + return seStringManager.Parse(buffer); + } + /// /// Read an SeString from a specified memory address. /// /// The memory address to read from. /// The maximum length of the string. /// The read in string. - public static SeString ReadSeString(IntPtr memoryAddress, int maxLength = 256) + public static SeString ReadSeString(IntPtr memoryAddress, int maxLength) { ReadRaw(memoryAddress, maxLength, out var buffer); @@ -302,12 +329,12 @@ namespace Dalamud.Memory => value = ReadString(memoryAddress, encoding, maxLength); /// - /// Read an SeString from a specified memory address. + /// Read a null-terminated SeString from a specified memory address. /// /// The memory address to read from. /// The read in SeString. - public static void ReadSeString(IntPtr memoryAddress, out SeString value) - => value = ReadSeString(memoryAddress); + public static void ReadSeStringNullTerminated(IntPtr memoryAddress, out SeString value) + => value = ReadSeStringNullTerminated(memoryAddress); /// /// Read an SeString from a specified memory address.