Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 3rd, 2012  |  syntax: None  |  size: 2.85 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using MemoryIO;
  6.  
  7. namespace BlackRain.Common
  8. {
  9.     class StringStore
  10.     {
  11.  
  12.         // Player names
  13.         public static StringStore NameStore = new StringStore(
  14.             (IntPtr)Offsets.WowPlayer.NameStore, (uint)Offsets.WowPlayer.NameBase,
  15.             (uint)Offsets.WowPlayer.NameMask, (uint)Offsets.WowPlayer.NameString
  16.             );
  17.  
  18.         // Guild names
  19.         public static StringStore GuildNameStore = new StringStore(
  20.             (IntPtr)Offsets.WowPlayer.GuildNameStore, (uint)Offsets.WowPlayer.GuildNameBase,
  21.             (uint)Offsets.WowPlayer.GuildNameMask, (uint)Offsets.WowPlayer.GuildNameString
  22.             );
  23.  
  24.         private IntPtr store;
  25.         private uint baseOffset;
  26.         private uint maskOffset;
  27.         private uint nameOffset;
  28.  
  29.         public StringStore(IntPtr store, uint baseOffset, uint maskOffset, uint nameOffset)
  30.         {
  31.             this.store = store;
  32.             this.baseOffset = baseOffset;
  33.             this.maskOffset = maskOffset;
  34.             this.nameOffset = nameOffset;
  35.         }
  36.  
  37.         public string getString(uint guid)
  38.         {
  39.             try
  40.             {
  41.                 // We're only looking at the first part of the guid
  42.                 guid &= 0xFFFFFFFF;
  43.  
  44.                 // Get the mask value
  45.                 uint mask = Memory.ReadRelative<uint>((IntPtr)((uint)store + maskOffset));
  46.                 IntPtr basePointer = Memory.ReadRelative<IntPtr>((IntPtr)((uint)store + baseOffset));
  47.  
  48.                 // Calculate the hash index from the guid
  49.                 uint hashKey = guid & mask;
  50.  
  51.                 // Calculate the bin offset
  52.                 uint binOffset = 0xC * hashKey;
  53.  
  54.                 // Get the pointer to the first object in the bin
  55.                 IntPtr obj = Memory.ReadAtOffset<IntPtr>(basePointer, binOffset + 0x08);
  56.  
  57.                 // Get the offset of the 'next' pointer in each of the stored objects
  58.                 uint nextOffset = Memory.ReadAtOffset<uint>(basePointer, binOffset) + 0x4;
  59.  
  60.                 // Iterate over the list until we find the object we need
  61.                 while (((uint)obj != 0) && (((uint)obj & 0x1) != 0x1))
  62.                 {
  63.                     // Check if the guid of the current object equals the object we're looking for and return
  64.                     // the string if they match
  65.                     if (Memory.Read<uint>(obj) == guid)
  66.                         return Memory.ReadAtOffset<string>(obj, nameOffset);
  67.  
  68.                     // Next item in the linked list.
  69.                     obj = Memory.ReadAtOffset<IntPtr>(obj, nextOffset);
  70.                 }
  71.  
  72.                 return string.Empty;
  73.  
  74.             }
  75.             catch (Exception)
  76.             {
  77.                 return "Error";
  78.             }
  79.  
  80.         }
  81.  
  82.     }
  83. }