mirror of
https://github.com/crskycode/GARbro.git
synced 2024-11-23 13:45:34 +08:00
(ArcView.Frame.UnsafeCopy): new private method.
This commit is contained in:
parent
882f3ec461
commit
9819218271
@ -108,9 +108,10 @@ namespace GameRes
|
||||
return ptr;
|
||||
}
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
[DllImport("kernel32.dll", SetLastError = false)]
|
||||
internal static extern void GetSystemInfo (ref SYSTEM_INFO lpSystemInfo);
|
||||
|
||||
[StructLayout (LayoutKind.Sequential)]
|
||||
internal struct SYSTEM_INFO
|
||||
{
|
||||
internal int dwOemId;
|
||||
@ -354,18 +355,19 @@ namespace GameRes
|
||||
int total = (int)Math.Min (Reserve (offset, count), count);
|
||||
if (buf.Length - buf_offset < total)
|
||||
throw new ArgumentException ("Buffer offset and length are out of bounds.");
|
||||
UnsafeCopy (offset, buf, buf_offset, total);
|
||||
return total;
|
||||
}
|
||||
|
||||
unsafe
|
||||
private unsafe void UnsafeCopy (long offset, byte[] buf, int buf_offset, int count)
|
||||
{
|
||||
byte* ptr = m_view.GetPointer (m_offset);
|
||||
try {
|
||||
Marshal.Copy ((IntPtr)(ptr+(offset-m_offset)), buf, buf_offset, total);
|
||||
Marshal.Copy ((IntPtr)(ptr+(offset-m_offset)), buf, buf_offset, count);
|
||||
} finally {
|
||||
m_view.SafeMemoryMappedViewHandle.ReleasePointer();
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read <paramref name="count"/> bytes starting from <paramref name="offset"/> into byte array and return that array.
|
||||
@ -375,7 +377,8 @@ namespace GameRes
|
||||
{
|
||||
count = Math.Min (count, Reserve (offset, count));
|
||||
var data = new byte[count];
|
||||
Read (offset, data, 0, count);
|
||||
if (count != 0)
|
||||
UnsafeCopy (offset, data, 0, data.Length);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user