Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.02 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Runtime.InteropServices;
  7.  
  8. namespace cleanCore
  9. {
  10.     public class WoWSpell
  11.     {
  12.         public WoWSpell(int id)
  13.         {
  14.             this.Id = id;            
  15.         }
  16.  
  17.         public static void Initialize()
  18.         {
  19.             PlayerSpells = new Dictionary<int, WoWSpell>();
  20.             castSpell = Helper.Magic.RegisterDelegate<CastSpellDelegate>(Offsets.CastSpell);
  21.             getSpellCooldown = Helper.Magic.RegisterDelegate<GetSpellCooldownDelegate>(Offsets.GetSpellCooldown);            
  22.         }
  23.  
  24.         public static bool Pulse()
  25.         {
  26.             for (int index = 0; index < Helper.Magic.Read<int>(Helper.Rebase(0x9ECD84)); index++)
  27.             {
  28.                 var id = Helper.Magic.Read<int>((uint)(Helper.Rebase(0x9ECD88) + index));
  29.                 if (!PlayerSpells.ContainsKey(id))
  30.                     PlayerSpells.Add(id, new WoWSpell(id));
  31.             }
  32.             return false;
  33.         }
  34.  
  35.         private static Dictionary<int, WoWSpell> PlayerSpells;
  36.  
  37.         public static WoWSpell GetSpell(int id)
  38.         {
  39.             WoWSpell spell = null;
  40.             PlayerSpells.TryGetValue(id, out spell);
  41.             return spell;
  42.         }
  43.  
  44.         public Dictionary<int, WoWSpell> Spells
  45.         {
  46.             get { return PlayerSpells; }
  47.         }        
  48.  
  49.         public int Id
  50.         {
  51.             get;
  52.             private set;
  53.         }
  54.  
  55.         public string Name
  56.         {
  57.             get { return WoWScript.Execute<string>("GetSpellBookItemName(" + Id + ", \"spell\")", 0); }
  58.         }
  59.  
  60.         public void Cast()
  61.         {
  62.             Cast(null);
  63.         }
  64.  
  65.         public void Cast(WoWUnit target)
  66.         {
  67.             if (target != null && !target.IsValid)
  68.                 throw new InvalidOperationException("Can't cast on invalid target");
  69.  
  70.             if (target == null)
  71.                 target = Manager.LocalPlayer;
  72.  
  73.             castSpell(Id, guid: target.Guid);
  74.         }
  75.  
  76.         public float Cooldown
  77.         {
  78.             get
  79.             {
  80.                 int start = 0;
  81.                 int duration = 0;
  82.                 bool isReady = false;
  83.  
  84.                 getSpellCooldown(Id, false, ref duration, ref start, ref isReady);
  85.  
  86.                 int result = start + duration - (int)Helper.PerformanceCount;
  87.                 return isReady ? (result > 0 ? result / 1000f : 0f) : float.MaxValue;
  88.             }
  89.         }
  90.  
  91.         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  92.         private delegate int CastSpellDelegate(int spellId, int itemId = 0, ulong guid = 0L, bool isTrade = false);
  93.         private static CastSpellDelegate castSpell;        
  94.  
  95.         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  96.         private delegate bool GetSpellCooldownDelegate(int spellId, bool isPet, ref int duration, ref int start, ref bool isEnabled);
  97.         private static GetSpellCooldownDelegate getSpellCooldown;
  98.  
  99.  
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement