public MacroState(Player client) { if (client == null) throw new ArgumentNullException("client"); this.client = client; }
public PlayerMacroState GetMacroState(Player player) { if (isLockedDown) throw new InvalidOperationException("Macro virtual machine is currently locked down."); if (clientMacros.ContainsKey(player.Process.ProcessId)) return clientMacros[player.Process.ProcessId]; var state = new PlayerMacroState(player); clientMacros[player.Process.ProcessId] = state; return state; }
public void AddNewClient(ClientProcess process, ClientVersion version = null) { var player = new Player(process) { Version = version }; player.PropertyChanged += Player_PropertyChanged; if (player.Version == null) { player.Version = ClientVersionManager.Instance.Versions.First(v => v.Key != "Auto-Detect"); } AddPlayer(player); player.Update(); }
public void AddPlayer(Player player) { if (player == null) throw new ArgumentNullException("player"); var alreadyExists = players.ContainsKey(player.Process.ProcessId); players[player.Process.ProcessId] = player; if (alreadyExists) OnPlayerUpdated(player); else OnPlayerAdded(player); }
public MapLocation(Player owner) { this.owner = owner; }
void OnPlayerLoggedOut(Player player) { if (player == null || string.IsNullOrWhiteSpace(player.Name)) return; var shouldSaveMacroStates = UserSettingsManager.Instance.Settings.SaveMacroStates; var macro = MacroManager.Instance.GetMacroState(player); try { if (shouldSaveMacroStates && macro != null) SaveMacroState(macro); } catch (Exception ex) { this.Dispatcher.Invoke((Action)delegate { this.ShowMessageBox("Save State Error", string.Format("There was an error saving the macro state:\n{0}", ex.Message), string.Format("{0}'s macro state may not be preserved upon next login.", player.Name), MessageBoxButton.OK, 460, 260); }, DispatcherPriority.Normal, null); } finally { this.Dispatcher.InvokeIfRequired(() => { if (player.HasHotkey) HotkeyManager.Instance.UnregisterHotkey(windowSource.Handle, player.Hotkey); player.Hotkey = null; }); } if (macro != null) { macro.ClearSpellQueue(); macro.ClearFlowerQueue(); } }
void OnPlayerLoggedIn(Player player) { if (player == null || string.IsNullOrWhiteSpace(player.Name)) return; var shouldSaveMacroStates = UserSettingsManager.Instance.Settings.SaveMacroStates; var macro = MacroManager.Instance.GetMacroState(player); try { if (shouldSaveMacroStates && macro != null) { LoadMacroState(player); } } catch (Exception ex) { this.Dispatcher.Invoke((Action)delegate { this.ShowMessageBox("Load State Error", string.Format("There was an error loading the macro state:\n{0}", ex.Message), string.Format("{0}'s macro state was not preserved.", player.Name), MessageBoxButton.OK, 460, 260); }, DispatcherPriority.Normal, null); } }
void LoadMacroState(Player player) { if (player == null) throw new ArgumentNullException("player"); if (!Directory.Exists("saves")) return; var filename = Path.Combine("saves", string.Format("{0}.xml", player.Name)); if (!File.Exists(filename)) return; var macroState = SavedMacroState.LoadFromFile(filename); if (macroState == null) return; MacroManager.Instance.ImportMacroState(player, macroState); if (File.Exists(filename)) File.Delete(filename); }
public PlayerModifiers(Player owner) { this.owner = owner; }
public PlayerEventArgs(Player player) { this.player = player; }
public ClientState(Player owner) { this.owner = owner; }
public void ImportMacroState(Player player, SavedMacroState state) { if (player == null) throw new ArgumentNullException("player"); if (state == null) throw new ArgumentNullException("state"); var macro = GetMacroState(player); if (macro == null) return; macro.Stop(); var process = Process.GetCurrentProcess(); if (player.HasHotkey) { HotkeyManager.Instance.UnregisterHotkey(process.MainWindowHandle, player.Hotkey); player.Hotkey = null; } player.Skillbook.ClearActiveSkills(); macro.ClearSpellQueue(); macro.ClearFlowerQueue(); player.Update(PlayerFieldFlags.Spellbook); macro.UseLyliacVineyard = player.HasLyliacVineyard && state.UseLyliacVineyard; macro.FlowerAlternateCharacters = player.HasLyliacPlant && state.FlowerAlternateCharacters; player.Update(PlayerFieldFlags.Skillbook); foreach (var skill in state.Skills) { if (!player.Skillbook.ContainSkill(skill.SkillName)) continue; player.Skillbook.ToggleActive(skill.SkillName, true); } foreach (var spell in state.Spells) { if (!player.Spellbook.ContainSpell(spell.SpellName)) continue; var spellInfo = player.Spellbook.GetSpell(spell.SpellName); if (spellInfo == null) continue; var queueItem = new SpellQueueItem(spellInfo, spell); macro.AddToSpellQueue(queueItem); } if (player.HasLyliacPlant) foreach (var flower in state.Flowers) { if (flower.TargetMode == TargetCoordinateUnits.None) continue; var queueItem = new FlowerQueueItem(flower); macro.AddToFlowerQueue(queueItem); } var windowHandle = Process.GetCurrentProcess().MainWindowHandle; if (state.HotkeyKey != Key.None && (state.HotkeyModifiers != ModifierKeys.None || Hotkey.IsFunctionKey(state.HotkeyKey))) { var hotkey = new Hotkey(state.HotkeyModifiers, state.HotkeyKey); if (HotkeyManager.Instance.RegisterHotkey(windowHandle, hotkey)) player.Hotkey = hotkey; } }
void OnPlayerUpdated(Player player) { player.PropertyChanged += Player_PropertyChanged; var handler = this.PlayerUpdated; if (handler != null) handler(this, new PlayerEventArgs(player)); }
void OnPlayerPropertyChanged(Player player, string propertyName) { var handler = this.PlayerPropertyChanged; if (handler != null) handler(player, new PropertyChangedEventArgs(propertyName)); }
public PlayerStats(Player owner) { this.owner = owner; }