diff --git a/Dalamud/Memory/MemoryHelper.cs b/Dalamud/Memory/MemoryHelper.cs index e8a32d2c3..a2fddd5fc 100644 --- a/Dalamud/Memory/MemoryHelper.cs +++ b/Dalamud/Memory/MemoryHelper.cs @@ -730,5 +730,28 @@ namespace Dalamud.Memory } #endregion + + #region Utility + + /// + /// Null-terminate a byte array. + /// + /// The byte array to terminate. + /// The terminated byte array. + public static byte[] NullTerminate(this byte[] bytes) + { + if (bytes.Length == 0 || bytes[^1] != 0) + { + var newBytes = new byte[bytes.Length + 1]; + Array.Copy(bytes, newBytes, bytes.Length); + newBytes[^1] = 0; + + return newBytes; + } + + return bytes; + } + + #endregion } }