- using System;
- using System.Collections.Generic;
- using System.Runtime.InteropServices;
- namespace WowMoPObjMgrTest
- {
- [StructLayout(LayoutKind.Sequential)]
- struct TSList // TSList<CGObject_C,TSGetExplicitLink<CGObject_C>>
- {
- public int Next;
- public int unk1;
- public IntPtr First;
- };
- [StructLayout(LayoutKind.Sequential)]
- struct TSHashTable // TSHashTable<CGObject_C,CHashKeyGUID>
- {
- public IntPtr vtable;
- public TSList Link;
- public int unk1;
- public int unk2;
- public int count; // count of links?
- public int unk4;
- public int unk5;
- public int unk6;
- public int unk7;
- }
- [StructLayout(LayoutKind.Sequential)]
- struct CurMgr
- {
- public TSHashTable VisibleObjects;
- public TSHashTable ToBeFreedObjects;
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
- public TSList[] Links;
- public ulong ActivePlayer;
- public int PlayerType;
- public int MapId;
- public IntPtr ClientConnection;
- public IntPtr MovementGlobals;
- };
- class ObjectManager : IEnumerable<WowObject>
- {
- private IntPtr BaseAddress;
- private const int s_curMgr = 0x00BE1D2C;
- public ObjectManager()
- {
- IntPtr objMgrPtr = Memory.BaseAddress + s_curMgr;
- BaseAddress = Memory.Read<IntPtr>(objMgrPtr);
- }
- public ulong ActivePlayer
- {
- get { return Memory.Read<CurMgr>(BaseAddress).ActivePlayer; }
- }
- public int MapId
- {
- get { return Memory.Read<CurMgr>(BaseAddress).MapId; }
- }
- public IntPtr ClientConnection
- {
- get { return Memory.Read<CurMgr>(BaseAddress).ClientConnection; }
- }
- public IntPtr MovementGlobals
- {
- get { return Memory.Read<CurMgr>(BaseAddress).MovementGlobals; }
- }
- public IntPtr FirstObject()
- {
- CurMgr mgr = Memory.Read<CurMgr>(BaseAddress);
- return mgr.VisibleObjects.Link.First;
- }
- public IntPtr NextObject(IntPtr current)
- {
- CurMgr mgr = Memory.Read<CurMgr>(BaseAddress);
- return Memory.Read<IntPtr>(current + mgr.VisibleObjects.Link.Next + 4);
- }
- System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
- public IEnumerator<WowObject> GetEnumerator()
- {
- IntPtr first = FirstObject();
- while (((first.ToInt64() & 1) == 0) && first != IntPtr.Zero)
- {
- yield return new WowObject(first);
- first = NextObject(first);
- }
- }
- }
- }