- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using MemoryIO;
- namespace BlackRain.Common
- {
- class StringStore
- {
- // Player names
- public static StringStore NameStore = new StringStore(
- (IntPtr)Offsets.WowPlayer.NameStore, (uint)Offsets.WowPlayer.NameBase,
- (uint)Offsets.WowPlayer.NameMask, (uint)Offsets.WowPlayer.NameString
- );
- // Guild names
- public static StringStore GuildNameStore = new StringStore(
- (IntPtr)Offsets.WowPlayer.GuildNameStore, (uint)Offsets.WowPlayer.GuildNameBase,
- (uint)Offsets.WowPlayer.GuildNameMask, (uint)Offsets.WowPlayer.GuildNameString
- );
- private IntPtr store;
- private uint baseOffset;
- private uint maskOffset;
- private uint nameOffset;
- public StringStore(IntPtr store, uint baseOffset, uint maskOffset, uint nameOffset)
- {
- this.store = store;
- this.baseOffset = baseOffset;
- this.maskOffset = maskOffset;
- this.nameOffset = nameOffset;
- }
- public string getString(uint guid)
- {
- try
- {
- // We're only looking at the first part of the guid
- guid &= 0xFFFFFFFF;
- // Get the mask value
- uint mask = Memory.ReadRelative<uint>((IntPtr)((uint)store + maskOffset));
- IntPtr basePointer = Memory.ReadRelative<IntPtr>((IntPtr)((uint)store + baseOffset));
- // Calculate the hash index from the guid
- uint hashKey = guid & mask;
- // Calculate the bin offset
- uint binOffset = 0xC * hashKey;
- // Get the pointer to the first object in the bin
- IntPtr obj = Memory.ReadAtOffset<IntPtr>(basePointer, binOffset + 0x08);
- // Get the offset of the 'next' pointer in each of the stored objects
- uint nextOffset = Memory.ReadAtOffset<uint>(basePointer, binOffset) + 0x4;
- // Iterate over the list until we find the object we need
- while (((uint)obj != 0) && (((uint)obj & 0x1) != 0x1))
- {
- // Check if the guid of the current object equals the object we're looking for and return
- // the string if they match
- if (Memory.Read<uint>(obj) == guid)
- return Memory.ReadAtOffset<string>(obj, nameOffset);
- // Next item in the linked list.
- obj = Memory.ReadAtOffset<IntPtr>(obj, nextOffset);
- }
- return string.Empty;
- }
- catch (Exception)
- {
- return "Error";
- }
- }
- }
- }