Share Pastebin
Guest
Public paste!

miceiken

By: a guest | Mar 18th, 2010 | Syntax: C# | Size: 1.56 KB | Hits: 89 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1.             public Row GetLocalizedRow(int index)
  2.             {
  3.                 if (index >= MinIndex && index <= MaxIndex)
  4.                 {
  5.                     IntPtr rowPtr = Marshal.AllocHGlobal(0x2C0);
  6.                     uint rowAddr = Memory.Read<uint>((uint)((_nativeDb.Rows) + ((index - MinIndex) * 4)));
  7.                     byte[] bufferBytes = Native.ReadBytes(rowAddr, 0x2C0);
  8.                     IntPtr bufferPtr = Marshal.AllocHGlobal(0x2C0);
  9.                     Marshal.Copy(OsMemCpy(bufferBytes, 0x2C0), 0, bufferPtr, 0x2C0);
  10.  
  11.                     Marshal.FreeHGlobal(bufferPtr);
  12.                     return new Row((uint)rowPtr);
  13.                 }
  14.                 return null;
  15.             }
  16.  
  17.             public static byte[] OsMemCpy(byte[] source, int length)
  18.             {
  19.                 byte[] outBuffer = new byte[length];
  20.                 outBuffer[0] = source[0];
  21.                 int currentIndex = 1;
  22.                 for (int i = 1; currentIndex < length; i++)
  23.                 {
  24.                     outBuffer[currentIndex++] = source[i];
  25.                     if (source[i] == source[i - 1])
  26.                     {
  27.                         for (byte j = source[i + 1]; j != 0; outBuffer[currentIndex++] = source[i])
  28.                             j--;
  29.  
  30.                         i += 2;
  31.                         if (currentIndex < length)
  32.                         {
  33.                             outBuffer[currentIndex++] = source[i];
  34.                         }
  35.                     }
  36.                 }
  37.                 return outBuffer;
  38.             }