Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Runtime.InteropServices;
- namespace cleanCore
- {
- public class WoWSpell
- {
- public WoWSpell(int id)
- {
- this.Id = id;
- }
- public static void Initialize()
- {
- PlayerSpells = new Dictionary<int, WoWSpell>();
- castSpell = Helper.Magic.RegisterDelegate<CastSpellDelegate>(Offsets.CastSpell);
- getSpellCooldown = Helper.Magic.RegisterDelegate<GetSpellCooldownDelegate>(Offsets.GetSpellCooldown);
- }
- public static bool Pulse()
- {
- for (int index = 0; index < Helper.Magic.Read<int>(Helper.Rebase(0x9ECD84)); index++)
- {
- var id = Helper.Magic.Read<int>((uint)(Helper.Rebase(0x9ECD88) + index));
- if (!PlayerSpells.ContainsKey(id))
- PlayerSpells.Add(id, new WoWSpell(id));
- }
- return false;
- }
- private static Dictionary<int, WoWSpell> PlayerSpells;
- public static WoWSpell GetSpell(int id)
- {
- WoWSpell spell = null;
- PlayerSpells.TryGetValue(id, out spell);
- return spell;
- }
- public Dictionary<int, WoWSpell> Spells
- {
- get { return PlayerSpells; }
- }
- public int Id
- {
- get;
- private set;
- }
- public string Name
- {
- get { return WoWScript.Execute<string>("GetSpellBookItemName(" + Id + ", \"spell\")", 0); }
- }
- public void Cast()
- {
- Cast(null);
- }
- public void Cast(WoWUnit target)
- {
- if (target != null && !target.IsValid)
- throw new InvalidOperationException("Can't cast on invalid target");
- if (target == null)
- target = Manager.LocalPlayer;
- castSpell(Id, guid: target.Guid);
- }
- public float Cooldown
- {
- get
- {
- int start = 0;
- int duration = 0;
- bool isReady = false;
- getSpellCooldown(Id, false, ref duration, ref start, ref isReady);
- int result = start + duration - (int)Helper.PerformanceCount;
- return isReady ? (result > 0 ? result / 1000f : 0f) : float.MaxValue;
- }
- }
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- private delegate int CastSpellDelegate(int spellId, int itemId = 0, ulong guid = 0L, bool isTrade = false);
- private static CastSpellDelegate castSpell;
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- private delegate bool GetSpellCooldownDelegate(int spellId, bool isPet, ref int duration, ref int start, ref bool isEnabled);
- private static GetSpellCooldownDelegate getSpellCooldown;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement