/// <summary> /// </summary> /// <param name="sender"> </param> /// <param name="e"> </param> private void ScanTimerElapsed(object sender, ElapsedEventArgs e) { if (this._isScanning) { return; } this._isScanning = true; double refresh = 1000; if (double.TryParse(Settings.Default.PlayerInfoWorkerRefresh.ToString(CultureInfo.InvariantCulture), out refresh)) { this._scanTimer.Interval = refresh; } Func <bool> scanner = delegate { CurrentPlayerResult readResult = Reader.GetCurrentPlayer(); AppContextHelper.Instance.RaiseCurrentPlayerUpdated(readResult.CurrentPlayer); this._isScanning = false; return(true); }; scanner.BeginInvoke(delegate { }, scanner); }
public static CurrentPlayerResult GetCurrentPlayer() { var result = new CurrentPlayerResult(); if (!CanGetPlayerInfo() || !MemoryHandler.Instance.IsAttached) { return(result); } var PlayerInfoMap = (IntPtr)Scanner.Instance.Locations[Signatures.PlayerInformationKey]; if (PlayerInfoMap.ToInt64() <= 6496) { return(result); } try { byte[] source = MemoryHandler.Instance.GetByteArray(PlayerInfoMap, MemoryHandler.Instance.Structures.CurrentPlayer.SourceSize); try { result.CurrentPlayer = CurrentPlayerResolver.ResolvePlayerFromBytes(source); } catch (Exception ex) { MemoryHandler.Instance.RaiseException(Logger, ex, true); } if (CanGetAgroEntities()) { var agroCount = MemoryHandler.Instance.GetInt16(Scanner.Instance.Locations[Signatures.AgroCountKey]); var agroStructure = (IntPtr)Scanner.Instance.Locations[Signatures.AgroMapKey]; if (agroCount > 0 && agroCount < 32 && agroStructure.ToInt64() > 0) { var agroSourceSize = MemoryHandler.Instance.Structures.EnmityItem.SourceSize; for (uint i = 0; i < agroCount; i++) { var address = new IntPtr(agroStructure.ToInt64() + i * agroSourceSize); var agroEntry = new EnmityItem { ID = (uint)MemoryHandler.Instance.GetPlatformInt(address, MemoryHandler.Instance.Structures.EnmityItem.ID), Name = MemoryHandler.Instance.GetString(address + MemoryHandler.Instance.Structures.EnmityItem.Name), Enmity = MemoryHandler.Instance.GetUInt32(address + MemoryHandler.Instance.Structures.EnmityItem.Enmity) }; if (agroEntry.ID > 0) { result.CurrentPlayer.EnmityItems.Add(agroEntry); } } } } } catch (Exception ex) { MemoryHandler.Instance.RaiseException(Logger, ex, true); Console.WriteLine(ex.StackTrace); } return(result); }
public CurrentPlayerResult GetCurrentPlayer() { CurrentPlayerResult result = new CurrentPlayerResult(); result.Entity = this.GetCurrentPlayerEntity(); result.PlayerInfo = this.GetPlayerInfo(); return(result); }
// Memory funcs public bool IsPlayerJobReady() { if (Properties.Settings.Default.ForcedOpen) { return(true); } if (Reader.CanGetPlayerInfo()) { CurrentPlayerResult res = Reader.GetCurrentPlayer(); return(res.CurrentPlayer.Job == Sharlayan.Core.Enums.Actor.Job.BRD); } return(false); }
private void Reset() { hasScanned = false; isLoggedIn = false; logItems.Clear(); completeLog.Clear(); _previousArrayIndex = 0; _previousOffset = 0; currentPlayer = new CurrentPlayerResult(); party = new PartyResult(); actors = new ActorResult(); performance = new PerformanceResult(); }
private void ScanTimerElapsed(object sender, ElapsedEventArgs e) { if (this._isScanning) { return; } this._scanTimer.Interval = Settings.Default.CurrentPlayerWorkerTiming; this._isScanning = true; CurrentPlayerResult result = this._memoryHandler.Reader.GetCurrentPlayer(); EventHost.Instance.RaiseNewCurrentUserEvent(this._memoryHandler, result.Entity); EventHost.Instance.RaiseNewPlayerInfoEvent(this._memoryHandler, result.PlayerInfo); this._isScanning = false; }
public Func <bool> GetChatCommand(ChatLogItem item) { if (GetCommand(item.Line, out Command command)) { command.code = item.Code; if (!string.IsNullOrEmpty(command.target)) { if (Reader.CanGetPlayerInfo()) { CurrentPlayerResult res = Reader.GetCurrentPlayer(); if (!command.target.Equals(res.CurrentPlayer.Name)) { return(null); } } } return(new Func <bool>(() => FindChatCommand(command.command).Invoke(command))); } return(null); }
public PlayerStruct(CurrentPlayerResult currentPlayer, ActorItem playerActor) { if (playerActor != null) { WeaponUnsheathed = (playerActor.CombatFlags & 4U) > 0U; InCombat = playerActor.InCombat; CastingPercentage = playerActor.CastingPercentage; HPCurrent = playerActor.HPCurrent; HPMax = playerActor.HPMax; MPCurrent = playerActor.MPCurrent; MPMax = playerActor.MPMax; CPCurrent = playerActor.CPCurrent; CPMax = playerActor.CPMax; GPCurrent = playerActor.GPCurrent; GPMax = playerActor.GPMax; } else { InCombat = WeaponUnsheathed = false; CastingPercentage = HPCurrent = HPMax = MPCurrent = MPMax = CPCurrent = CPMax = GPCurrent = GPMax = 0; } getLevelProgression(currentPlayer); Status = 0; }
private void Memory_OnCurrentPlayerJobChange(CurrentPlayerResult res) { this.Invoke(t => t.UpdatePerformance()); }
public bool Refresh() { if (ffxivProcess != null) { ffxivProcess.Refresh(); if (ffxivProcess.HasExited) { OnProcessLost?.Invoke(this, EventArgs.Empty); ffxivProcess = null; hasLost = true; Reset(); Console.WriteLine("Exited game"); } if (IsScanning() && !hasScanned) { Console.WriteLine("Scanning..."); while (IsScanning()) { Thread.Sleep(100); } Console.WriteLine("Finished scanning"); OnProcessReady?.Invoke(this, ffxivProcess); hasScanned = true; } } if ((ffxivProcess == null) && hasLost) { OnProcessSeek?.Invoke(this, EventArgs.Empty); hasLost = false; return(false); } if (Reader.CanGetCharacterId()) { string id = Reader.GetCharacterId(); if (!string.IsNullOrEmpty(id)) { if (string.IsNullOrEmpty(CharacterID) || (!string.IsNullOrEmpty(CharacterID) && !CharacterID.Equals(id))) { CharacterID = id; } } } if (Reader.CanGetPlayerInfo()) { CurrentPlayerResult res = Reader.GetCurrentPlayer(); if (res.CurrentPlayer.Job != currentPlayer.CurrentPlayer.Job) { if (currentPlayer.CurrentPlayer.Job == Sharlayan.Core.Enums.Actor.Job.Unknown) { // Logged in OnCurrentPlayerLogin?.Invoke(this, res); isLoggedIn = true; } else if (res.CurrentPlayer.Job == Sharlayan.Core.Enums.Actor.Job.Unknown) { // Logged out OnCurrentPlayerLogout?.Invoke(this, currentPlayer); isLoggedIn = false; Reset(); } else { OnCurrentPlayerJobChange?.Invoke(this, currentPlayer); } } currentPlayer = res; } if (!isLoggedIn) { return(false); } if (Reader.CanGetPartyMembers()) { PartyResult party2 = Reader.GetPartyMembers(); if (party2.NewPartyMembers.Count > 0 || party2.RemovedPartyMembers.Count > 0) { // Something changed party = party2; OnPartyChanged?.Invoke(this, party2); } int pcount = party.PartyMembers.Count; int pcount2 = party2.PartyMembers.Count; if (!(party is PartyResult) || (party is PartyResult && (pcount != pcount2))) { party = party2; OnPartyChanged?.Invoke(this, party2); } } if (Reader.CanGetPerformance()) { List <uint> changedIds = new List <uint>(); PerformanceResult perf = Reader.GetPerformance(); if (!perf.Performances.IsEmpty && !performance.Performances.IsEmpty) { foreach (KeyValuePair <uint, PerformanceItem> pp in perf.Performances) { if (pp.Value.Status != performance.Performances[pp.Key].Status) { changedIds.Add(pp.Key); } } } if (changedIds.Count > 0) { List <uint> actorIds = new List <uint>(); if (Reader.CanGetActors()) { foreach (ActorItem actor in Reader.GetActors().CurrentPCs.Values) { if (changedIds.Contains(actor.PerformanceID / 2)) { actorIds.Add(actor.ID); } } } if (actorIds.Count > 0) { OnPerformanceChanged?.Invoke(this, actorIds); } } //Update performance = perf; bool r = perf.Performances[0].IsReady(); if (r != performanceReady) { performanceReady = r; OnPerformanceReadyChanged?.Invoke(this, performanceReady); } } logItems.Clear(); if (Reader.CanGetChatLog()) { ChatLogResult readResult = Reader.GetChatLog(_previousArrayIndex, _previousOffset); _previousArrayIndex = readResult.PreviousArrayIndex; _previousOffset = readResult.PreviousOffset; foreach (ChatLogItem item in readResult.ChatLogItems) { logItems.Push(item); completeLog.Add(item); OnChatReceived?.Invoke(this, item); } } if (Reader.CanGetActors()) { int jobsum0 = 0; if (actors != null) { jobsum0 = actors.CurrentPCs.Sum(e => (int)e.Value.Job); } ActorResult actorRes = Reader.GetActors(); if (actors != null) { if (actorRes.CurrentPCs.Count != actors.CurrentPCs.Count) { actors = actorRes; OnPcChanged?.Invoke(this, actorRes.CurrentPCs.ToDictionary(k => k.Key, k => k.Value as ActorItemBase)); } int jobsum1 = actorRes.CurrentPCs.Sum(e => (int)e.Value.Job); if (jobsum0 != jobsum1) { actors = actorRes; OnPcChanged?.Invoke(this, actorRes.CurrentPCs.ToDictionary(k => k.Key, k => k.Value as ActorItemBase)); } } else { actors = actorRes; OnPcChanged?.Invoke(this, actorRes.CurrentPCs.ToDictionary(k => k.Key, k => k.Value as ActorItemBase)); } } return(true); }
private void UpdateRPC(Object source, ElapsedEventArgs e) { if (Attach()) { if (!discord.IsInitialized) { //start discord if not running and game is running discord = new DiscordRpcClient(DISCORD_CLIENT_ID); discordStartTime = Timestamps.Now; discord.Initialize(); } string smallImageText = null; string smallImageKey = null; string details; string status; Reader.GetActors(); CurrentPlayerResult cpr = Reader.GetCurrentPlayer(); var player = ActorItem.CurrentUser; if (cpr.CurrentPlayer.Name != null && cpr.CurrentPlayer.Name != "" && player != null) { details = String.Format("{0} ({1} Lv{2})", cpr.CurrentPlayer.Name, UIStrings.JobAbbreviations[cpr.CurrentPlayer.Job], player.Level); smallImageKey = UIStrings.JobAbbreviations[cpr.CurrentPlayer.Job].ToLower(); smallImageText = String.Format("Level {0} {1}", player.Level, UIStrings.JobNames[cpr.CurrentPlayer.Job]); string zone = ActGlobals.oFormActMain.CurrentZone; pluginStatusText.Text = String.Format("Character Found: {0}", details); switch (player.IconID) { case 15: status = String.Format("Watching a cutscene"); break; case 17: status = String.Format("AFK in {0}", zone); break; case 18: status = String.Format("Taking screenshots"); break; case 22: status = String.Format("RP'ing in {0}", zone); break; case 25: status = String.Format("Waiting for Duty Finder"); break; case 26: status = String.Format("Recruiting Party Members"); break; default: status = zone; break; } } else { details = "Main Menu"; status = null; } if (discord.IsInitialized) { discord.SetPresence(new RichPresence() { Details = details, State = status, Assets = new Assets() { LargeImageKey = "logo", SmallImageKey = smallImageKey, SmallImageText = smallImageText }, Timestamps = discordStartTime }); } } else { if (!discord.IsDisposed) { //dispose discord if game is not running discord.Dispose(); } } }