miceiken
By: a guest | Mar 18th, 2010 | Syntax:
C# | Size: 1.56 KB | Hits: 89 | Expires: Never
public Row GetLocalizedRow(int index)
{
if (index >= MinIndex && index <= MaxIndex)
{
IntPtr rowPtr = Marshal.AllocHGlobal(0x2C0);
uint rowAddr = Memory.Read<uint>((uint)((_nativeDb.Rows) + ((index - MinIndex) * 4)));
byte[] bufferBytes = Native.ReadBytes(rowAddr, 0x2C0);
IntPtr bufferPtr = Marshal.AllocHGlobal(0x2C0);
Marshal.Copy(OsMemCpy(bufferBytes, 0x2C0), 0, bufferPtr, 0x2C0);
Marshal.FreeHGlobal(bufferPtr);
return new Row((uint)rowPtr);
}
return null;
}
public static byte[] OsMemCpy(byte[] source, int length)
{
byte[] outBuffer = new byte[length];
outBuffer[0] = source[0];
int currentIndex = 1;
for (int i = 1; currentIndex < length; i++)
{
outBuffer[currentIndex++] = source[i];
if (source[i] == source[i - 1])
{
for (byte j = source[i + 1]; j != 0; outBuffer[currentIndex++] = source[i])
j--;
i += 2;
if (currentIndex < length)
{
outBuffer[currentIndex++] = source[i];
}
}
}
return outBuffer;
}