1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.InteropServices;
  4. namespace WowMoPObjMgrTest
  5. {
  6. [StructLayout(LayoutKind.Sequential)]
  7. struct TSList // TSList<CGObject_C,TSGetExplicitLink<CGObject_C>>
  8. {
  9. public int Next;
  10. public int unk1;
  11. public IntPtr First;
  12. };
  13. [StructLayout(LayoutKind.Sequential)]
  14. struct TSHashTable // TSHashTable<CGObject_C,CHashKeyGUID>
  15. {
  16. public IntPtr vtable;
  17. public TSList Link;
  18. public int unk1;
  19. public int unk2;
  20. public int count; // count of links?
  21. public int unk4;
  22. public int unk5;
  23. public int unk6;
  24. public int unk7;
  25. }
  26. [StructLayout(LayoutKind.Sequential)]
  27. struct CurMgr
  28. {
  29. public TSHashTable VisibleObjects;
  30. public TSHashTable ToBeFreedObjects;
  31. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
  32. public TSList[] Links;
  33. public ulong ActivePlayer;
  34. public int PlayerType;
  35. public int MapId;
  36. public IntPtr ClientConnection;
  37. public IntPtr MovementGlobals;
  38. };
  39. class ObjectManager : IEnumerable<WowObject>
  40. {
  41. private IntPtr BaseAddress;
  42. private const int s_curMgr = 0x00BE1D2C;
  43. public ObjectManager()
  44. {
  45. IntPtr objMgrPtr = Memory.BaseAddress + s_curMgr;
  46. BaseAddress = Memory.Read<IntPtr>(objMgrPtr);
  47. }
  48. public ulong ActivePlayer
  49. {
  50. get { return Memory.Read<CurMgr>(BaseAddress).ActivePlayer; }
  51. }
  52. public int MapId
  53. {
  54. get { return Memory.Read<CurMgr>(BaseAddress).MapId; }
  55. }
  56. public IntPtr ClientConnection
  57. {
  58. get { return Memory.Read<CurMgr>(BaseAddress).ClientConnection; }
  59. }
  60. public IntPtr MovementGlobals
  61. {
  62. get { return Memory.Read<CurMgr>(BaseAddress).MovementGlobals; }
  63. }
  64. public IntPtr FirstObject()
  65. {
  66. CurMgr mgr = Memory.Read<CurMgr>(BaseAddress);
  67. return mgr.VisibleObjects.Link.First;
  68. }
  69. public IntPtr NextObject(IntPtr current)
  70. {
  71. CurMgr mgr = Memory.Read<CurMgr>(BaseAddress);
  72. return Memory.Read<IntPtr>(current + mgr.VisibleObjects.Link.Next + 4);
  73. }
  74. System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
  75. {
  76. return GetEnumerator();
  77. }
  78. public IEnumerator<WowObject> GetEnumerator()
  79. {
  80. IntPtr first = FirstObject();
  81. while (((first.ToInt64() & 1) == 0) && first != IntPtr.Zero)
  82. {
  83. yield return new WowObject(first);
  84. first = NextObject(first);
  85. }
  86. }
  87. }
  88. }