Share Pastebin
Guest
Public paste!

miceiken

By: a guest | Mar 18th, 2010 | Syntax: C# | Size: 3.26 KB | Hits: 140 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1.         #region DbcUtils
  2.         internal static class DbcUtils
  3.         {
  4.             private const uint WOW_USE_SPELL_UNPACK = 0xC775D0;
  5.             public static void GetLocalizedRow(uint clientDb, int recordId, out IntPtr buffer)
  6.             {
  7.                 clientDb = (uint)(clientDb - 0x18);
  8.                 var header = Memory.ReadStruct<DBC.WoWClientDb>(clientDb);
  9.                 buffer = IntPtr.Zero;
  10.                 if (recordId >= header.MinIndex && recordId <= header.MaxIndex)
  11.                 {
  12.                     IntPtr lpRow = Memory.Read<IntPtr>((uint)(header.Rows + (4 * (recordId - header.MinIndex))));
  13.  
  14.                     if (Memory.Read<byte>((uint)WOW_USE_SPELL_UNPACK) == 1)
  15.                     {
  16.                         UnpackSpellDb(lpRow, 0x2C0u, out buffer);
  17.                     }
  18.                     else
  19.                     {
  20.                         byte[] data = Native.ReadBytes((uint)lpRow, 0x2C0);
  21.                         buffer = Marshal.AllocHGlobal(0x2C0);
  22.                         Marshal.Copy(data, 0, buffer, 0x2C0);
  23.                     }
  24.                 }
  25.             }
  26.  
  27.             private static void UnpackSpellDb(IntPtr source, uint size, out IntPtr buffer)
  28.             {
  29.                 // This function is taken directly from WoW. It includes lots of Marshal usage, and some other stuff.
  30.                 // So if you don't understand it, tough shit. :D
  31.  
  32.                 // Way too much allocated; but oh well.
  33.                 byte[] byteBuffer = new byte[0x5000];
  34.  
  35.                 // *outBuffer = *source;
  36.                 byteBuffer[0] = Memory.Read<byte>((uint)source);
  37.  
  38.                 // currentAddress = outBuffer + 1;
  39.                 int currentAddress = 1;
  40.  
  41.                 uint i;
  42.  
  43.                 // for ( i = (char *)source + 1;         currentAddress < endAddress;                     ++i )
  44.                 for (i = (uint)(source.ToInt32() + 1); currentAddress < size; ++i)
  45.                 {
  46.                     // *currentAddress++ = *i;
  47.                     byteBuffer[currentAddress++] = Memory.Read<byte>((uint)i);
  48.                     //currentAddress++;
  49.  
  50.                     // if (*i == *(i -1))
  51.                     byte atI = Memory.Read<byte>((uint)i);
  52.                     byte prevI = Memory.Read<byte>((uint)(i - 1));
  53.                     if (atI == prevI)
  54.                     {
  55.                         // for ( j = *(i + 1); j; *currentAddress++ = *i )
  56.                         for (byte j = Memory.Read<byte>((uint)(i + 1)); j != 0; byteBuffer[currentAddress++] = Memory.Read<byte>((uint)i))
  57.                         {
  58.                             j--;
  59.                         }
  60.  
  61.                         // i += 2;
  62.                         i += 2;
  63.  
  64.                         // if ( currentAddres < endAddress )
  65.                         if (currentAddress < size)
  66.                         {
  67.                             // *currentAddress++ = *i;
  68.                             byteBuffer[currentAddress++] = Memory.Read<byte>((uint)i);
  69.                             //currentAddress++;
  70.                         }
  71.                     }
  72.                 }
  73.  
  74.                 buffer = Marshal.AllocHGlobal(0x2C0);
  75.                 Marshal.Copy(byteBuffer, 0, buffer, 0x2C0);
  76.             }
  77.         }
  78.         #endregion