code_junkie

C# - Collections and casting

Nov 13th, 2011
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.19 KB | None | 0 0
  1. // declaring and initializing the idictionary
  2. public IDictionary<ulong, BaseObject> ObjectList = new Dictionary<ulong, BaseObject>();
  3. // how i add derived objects to the collection
  4. ObjectList.Add(TempObject.Guid, new DerivedObject1(this, TempObject.BaseAddress));
  5. ObjectList.Add(TempObject2.Guid, new DerivedObject2(this, TempObject2.BaseAddress));
  6.  
  7. // in the class
  8. public DerivedObject3 LocalPlayer;
  9. // in a method inside a class
  10. LocalPlayer = (DerivedObject3)ObjectList[TempObject.Guid];
  11.  
  12. static void Main()
  13. {
  14. ObjectManager OM = new ObjectManager();
  15. OM.LoadAddresses();
  16. OM.PopulateList();
  17. Console.WriteLine(OM.LocalPlayer.Type);
  18. Console.ReadLine();
  19. }
  20.  
  21. class WowObject
  22. {
  23. protected const uint GuidOffset = 0x30,
  24. NextObjectOffset = 0x3C,
  25. TypeOffset = 0x14,
  26. XPositionOffset = 0x7D0,
  27. YPositionOffset = 0x7D4,
  28. ZPositionOffset = 0x7D8,
  29. RotationOffset = 0x7DC,
  30. DescriptorFieldsOffset = 0x8;
  31.  
  32. protected uint baseAddress;
  33. protected ObjectManager OM;
  34.  
  35. public WowObject(ObjectManager OM, uint baseAddress)
  36. {
  37. this.baseAddress = baseAddress;
  38. this.OM = OM;
  39. }
  40.  
  41. public uint BaseAddress
  42. {
  43. get { return baseAddress; }
  44. set { baseAddress = value; }
  45. }
  46.  
  47. public uint DescriptorFields
  48. {
  49. get { return OM.ReadUInt32((IntPtr)(BaseAddress + DescriptorFieldsOffset)); }
  50. }
  51.  
  52. public int Type
  53. {
  54. get { return OM.ReadInt32((IntPtr)(BaseAddress + TypeOffset)); }
  55. }
  56.  
  57. public virtual ulong Guid
  58. {
  59. get { return OM.ReadULong((IntPtr)(BaseAddress + GuidOffset)); }
  60. set { return; }
  61. }
  62.  
  63. public virtual float XPos
  64. {
  65. get { return OM.ReadFloat((IntPtr)(BaseAddress + XPositionOffset)); }
  66. }
  67.  
  68. public virtual float YPos
  69. {
  70. get { return OM.ReadFloat((IntPtr)(BaseAddress + YPositionOffset)); }
  71. }
  72.  
  73. public virtual float ZPos
  74. {
  75. get { return OM.ReadFloat((IntPtr)(BaseAddress + ZPositionOffset)); }
  76. }
  77.  
  78. public float Rotation
  79. {
  80. get { return OM.ReadFloat((IntPtr)(BaseAddress + RotationOffset)); }
  81. }
  82. }
  83.  
  84. class CreatureObject : WowObject
  85. {
  86. protected const uint LevelOffset = 0x35 * 4,
  87. CurrentHealthOffset = 0x17 * 4,
  88. MaxHealthOffset = 0x1F * 4,
  89. CurrentManaOffset = 0x18 * 4,
  90. MaxManaOffset = 0x20 * 4,
  91. TargetGuidOffset = 0x12*4;
  92. private CreatureObject targetObject;
  93.  
  94. public CreatureObject(ObjectManager OM, uint BaseAddress)
  95. : base(OM, BaseAddress)
  96. { }
  97.  
  98. public CreatureObject TargetObject
  99. {
  100. get { return targetObject; }
  101. set { targetObject = value; }
  102. }
  103.  
  104. public ulong TargetGuid
  105. {
  106. get { return OM.ReadULong((IntPtr)(BaseAddress + TargetGuid)); }
  107. }
  108.  
  109. public int Level
  110. {
  111. get { return OM.ReadInt32((IntPtr)(DescriptorFields + LevelOffset)); }
  112. }
  113.  
  114. public int CurrentHealth
  115. {
  116. get { return OM.ReadInt32((IntPtr)(DescriptorFields + CurrentHealthOffset)); }
  117. }
  118.  
  119. public int MaxHealth
  120. {
  121. get { return OM.ReadInt32((IntPtr)(DescriptorFields + MaxHealthOffset)); }
  122. }
  123.  
  124. public int CurrentMana
  125. {
  126. get { return OM.ReadInt32((IntPtr)(DescriptorFields + CurrentMana)); }
  127. }
  128.  
  129. public int MaxMana
  130. {
  131. get { return OM.ReadInt32((IntPtr)(DescriptorFields + MaxManaOffset)); }
  132. }
  133.  
  134. public int HealthPercent
  135. {
  136. get
  137. {
  138. double percentage = CurrentHealth / MaxHealth;
  139. percentage = percentage * 100;
  140. return (int)Math.Round(percentage);
  141. }
  142. }
  143. }
  144.  
  145. class NpcObject : CreatureObject
  146. {
  147. protected const uint SummonedByOffset = 0xE * 4,
  148. AttackingGuidOffset = 0x0A38;
  149.  
  150. public NpcObject(ObjectManager OM, uint BaseAddress)
  151. : base(OM, BaseAddress)
  152. { }
  153.  
  154. public ulong AttackingGuid
  155. {
  156. get { return OM.ReadULong((IntPtr)(BaseAddress + AttackingGuidOffset)); }
  157. }
  158.  
  159. public ulong SummonedBy
  160. {
  161. get { return OM.ReadULong((IntPtr)(DescriptorFields + SummonedByOffset)); }
  162. }
  163. }
  164.  
  165. class PlayerObject : CreatureObject
  166. {
  167. protected const uint CurrentRageOffset = 0x19 * 4,
  168. CurrentEnergyOffset = 0x1B * 4,
  169. MaxEnergyOffset = 0x23 * 4;
  170.  
  171. public PlayerObject(ObjectManager OM, uint BaseAddress)
  172. : base(OM, BaseAddress)
  173. { }
  174.  
  175. public int CurrentRage
  176. {
  177. get
  178. {
  179. int RageTemp = OM.ReadInt32((IntPtr)(DescriptorFields + CurrentRageOffset));
  180. return (int)(Math.Floor((double)(RageTemp / 10)));
  181. }
  182. }
  183.  
  184. public int MaxRage
  185. {
  186. get { return 100; }
  187. }
  188.  
  189. public int CurrentEnergy
  190. {
  191. get { return OM.ReadInt32((IntPtr)(DescriptorFields + CurrentEnergyOffset)); }
  192. }
  193.  
  194. public int MaxEnergy
  195. {
  196. get { return OM.ReadInt32((IntPtr)(DescriptorFields + MaxEnergyOffset)); }
  197. }
  198. }
  199.  
  200. class LocalCharacter : PlayerObject
  201. {
  202. private ulong guid = 0;
  203.  
  204. public LocalCharacter(ObjectManager OM, uint BaseAddress)
  205. : base(OM, BaseAddress)
  206. { }
  207.  
  208. public override ulong Guid
  209. {
  210. get { return guid; }
  211. set { guid = value; }
  212. }
  213. }
  214.  
  215. class GameObject : WowObject
  216. {
  217. protected const uint gameObject_XPos = 0x10 * 4,
  218. gameObject_YPos = 0x11 * 4,
  219. gameObject_ZPos = 0x12 * 4;
  220.  
  221. public GameObject(ObjectManager OM, uint BaseAddress)
  222. : base(OM, BaseAddress)
  223. { }
  224.  
  225. public override float XPos
  226. {
  227. get { return OM.ReadFloat((IntPtr)(DescriptorFields + gameObject_XPos)); }
  228. }
  229.  
  230. public override float YPos
  231. {
  232. get { return OM.ReadFloat((IntPtr)(DescriptorFields + gameObject_YPos)); }
  233. }
  234.  
  235. public override float ZPos
  236. {
  237. get { return OM.ReadFloat((IntPtr)(DescriptorFields + gameObject_ZPos)); }
  238. }
  239. }
  240.  
  241. class DynamicObject : WowObject
  242. {
  243. protected const uint dynamicObject_XPos = 0xB * 4,
  244. dynamicObject_YPos = 0xC * 4,
  245. dynamicObject_ZPos = 0xD * 4;
  246.  
  247. public DynamicObject(ObjectManager OM, uint BaseAddress)
  248. : base(OM, BaseAddress)
  249. { }
  250.  
  251. public override float XPos
  252. {
  253. get { return OM.ReadFloat((IntPtr)(DescriptorFields + dynamicObject_XPos)); }
  254. }
  255.  
  256. public override float YPos
  257. {
  258. get { return OM.ReadFloat((IntPtr)(DescriptorFields + dynamicObject_YPos)); }
  259. }
  260.  
  261. public override float ZPos
  262. {
  263. get { return OM.ReadFloat((IntPtr)(DescriptorFields + dynamicObject_ZPos)); }
  264. }
  265. }
  266.  
  267. class CorpseObject : WowObject
  268. {
  269. protected const uint corpseObject_XPos = 0xB * 4,
  270. corpseObject_YPos = 0xC * 4,
  271. corpseObject_ZPos = 0xD * 4;
  272.  
  273. public CorpseObject(ObjectManager OM, uint BaseAddress)
  274. : base(OM, BaseAddress)
  275. { }
  276.  
  277. public override float XPos
  278. {
  279. get { return OM.ReadFloat((IntPtr)(DescriptorFields + corpseObject_XPos)); }
  280. }
  281.  
  282. public override float YPos
  283. {
  284. get { return OM.ReadFloat((IntPtr)(DescriptorFields + corpseObject_YPos)); }
  285. }
  286.  
  287. public override float ZPos
  288. {
  289. get { return OM.ReadFloat((IntPtr)(DescriptorFields + corpseObject_ZPos)); }
  290. }
  291. }
  292.  
  293. class ObjectManager : Memory
  294. {
  295. public IDictionary<ulong, WowObject> ObjectList = new Dictionary<ulong, WowObject>();
  296.  
  297. public LocalCharacter LocalPlayer;
  298.  
  299. private const uint staticClientConnection = 0x011CA310, // static client connection, same address every boot
  300. objectManagerOffset = 0x28A4, // offset from the ClientConnection to the object manager
  301. localGuidOffset = 0xC0, // offset from the object manager to the local guid
  302. firstObjectOffset = 0xAC, // offset from the object manager to the first object
  303. nextObjectOffset = 0x3C; // offset from
  304. private uint objectManagerBase; // the address off the object manager
  305.  
  306. public void LoadAddresses()
  307. {
  308. objectManagerBase = ReadUInt32((IntPtr)(ReadUInt32((IntPtr)(staticClientConnection)) + objectManagerOffset));
  309. LocalPlayer = new LocalCharacter(this, ReadUInt32((IntPtr)(objectManagerBase + localGuidOffset)));
  310. }
  311.  
  312. public void PopulateList()
  313. {
  314. WowObject TempObject = new WowObject(this, ReadUInt32((IntPtr)(objectManagerBase + firstObjectOffset)));
  315.  
  316. while (TempObject.BaseAddress != 0 && TempObject.BaseAddress % 2 == 0)
  317. {
  318. if (TempObject.Type == 3)
  319. ObjectList.Add(TempObject.Guid, new NpcObject(this, TempObject.BaseAddress));
  320. if (TempObject.Type == 4)
  321. {
  322. if (TempObject.Guid != LocalPlayer.Guid)
  323. ObjectList.Add(TempObject.Guid, new PlayerObject(this, TempObject.BaseAddress));
  324. else
  325. {
  326. ObjectList.Add(TempObject.Guid, new PlayerObject(this, TempObject.BaseAddress));
  327. LocalPlayer = (LocalCharacter)ObjectList[TempObject.Guid];
  328. }
  329. }
  330.  
  331. TempObject.BaseAddress = ReadUInt32((IntPtr)(TempObject.BaseAddress + nextObjectOffset));
  332. }
  333. }
  334. }
  335.  
  336. static void Main()
  337. {
  338. ObjectManager OM = new ObjectManager();
  339. OM.SetProcess("Wow", "Read");
  340. OM.LoadAddresses();
  341. OM.PopulateList();
  342. Console.WriteLine(OM.LocalPlayer.Type);
  343. Console.ReadLine();
  344. }
Add Comment
Please, Sign In to add comment