private bool AnyProblems() { if (Program.mem == null || !Program.mem.ValidateProcess() || Program.mem.GetSelfCombatant() == null || Program.mem.Process.Id != (int?)ProcessComboBox.SelectedValue) { HuntConnectionTextBlock.Text = string.Format(Properties.Resources.FormNoProcess, FFXIVProcessHelper.DX9ExeName + (Environment.Is64BitProcess ? "/" + FFXIVProcessHelper.DX11ExeName : string.Empty)); if (ProcessComboBox.SelectedValue != null && FFXIVProcessHelper.GetFFXIVProcess((int)ProcessComboBox.SelectedValue) != null) { if (Program.mem != null) { Program.mem.OnNewCommand -= ProcessChatCommand; Program.mem.Dispose(); hunts?.LeaveGroup(); } Program.mem = null; Program.mem = new FFXIVMemory(FFXIVProcessHelper.GetFFXIVProcess((int)ProcessComboBox.SelectedValue)); Program.mem.OnNewCommand += ProcessChatCommand; PersistentNamedPipeServer.Restart(); } hunts?.LeaveGroup(); HuntNotifyGroupBox.IsEnabled = false; return(true); } else { if (hunts == null && Program.mem != null && Program.mem.ValidateProcess()) { hunts = new FFXIVHunts(this); } HuntNotifyGroupBox.IsEnabled = true; } return(false); }
internal async Task LastKnownInfoForFATE(ushort id) { if (FFXIVHunts.hubConnection.Connected && FFXIVHunts.Joined) { FATEReport[] results = await FFXIVHunts.hubConnection.Connection.InvokeAsync("QueryFATE", id, default(CancellationToken)).ConfigureAwait(false); foreach (FATEReport result in results) { TimeSpan timeSinceLastReport = FFXIVHunts.ServerTimeUtc.Subtract(result.LastReported); if (timeSinceLastReport < TimeSpan.Zero) { timeSinceLastReport = TimeSpan.Zero; } ChatMessage cm = new ChatMessage(); if (timeSinceLastReport.TotalDays > 90.0) { cm.MessageString = FFXIVHunts.GetWorldPrepend(result.WorldId) + string.Format(CultureInfo.CurrentCulture, Resources.LKIHuntNotReported, result.Name(false)); } else if (timeSinceLastReport.TotalHours > 100.0) { cm.MessageString = FFXIVHunts.GetWorldPrepend(result.WorldId) + string.Format(CultureInfo.CurrentCulture, Resources.LKIFATEDays, result.Name(false), Convert.ToUInt32(timeSinceLastReport.TotalDays)); } else { cm = ChatMessage.MakePosChatMessage(FFXIVHunts.GetWorldPrepend(result.WorldId) + string.Format(CultureInfo.CurrentCulture, Resources.LKIFATE, result.Name(false), Math.Floor(timeSinceLastReport.TotalHours), timeSinceLastReport.Minutes), result.ZoneID, result.PosX, result.PosY, "", 0); } if (result.Instance > 0) { cm.PostpendToMessage(string.Format(CultureInfo.CurrentCulture, " " + Resources.InstanceSpecifier, result.Instance)); } await Program.mem.WriteChatMessage(cm).ConfigureAwait(false); } FATEReport[] array = null; } }
internal async Task QueryHunt(ushort id) { if (FFXIVHunts.hubConnection.Connected && FFXIVHunts.Joined) { IOrderedEnumerable <Hunt> results = from x in await FFXIVHunts.hubConnection.Connection.InvokeAsync("QueryHunt", id, default(CancellationToken)).ConfigureAwait(false) orderby x.LastReported select x; foreach (Hunt result in results) { TimeSpan timeSinceLastReport = FFXIVHunts.ServerTimeUtc.Subtract(result.LastReported); if (timeSinceLastReport < TimeSpan.Zero) { timeSinceLastReport = TimeSpan.Zero; } ChatMessage cm = new ChatMessage(); double TotalHours = Math.Floor(timeSinceLastReport.TotalHours); if (!result.LastAlive) { cm.MessageString = FFXIVHunts.GetWorldPrepend(result.WorldId) + string.Format(CultureInfo.CurrentCulture, Resources.LKIHuntKilled, result.Name); if (Resources.LKIHuntKilled.Contains("<time>")) { ChatMessage chatMessage = cm; chatMessage.MessageString += cm.MessageString.Replace("<time>", string.Format(CultureInfo.CurrentCulture, Resources.LKIHoursMinutes, TotalHours, timeSinceLastReport.Minutes)); } else if (timeSinceLastReport.TotalDays > 90.0) { cm.MessageString = FFXIVHunts.GetWorldPrepend(result.WorldId) + string.Format(CultureInfo.CurrentCulture, Resources.LKIHuntNotReported, result.Name); } else if (timeSinceLastReport.TotalHours > 72.0) { ChatMessage chatMessage2 = cm; chatMessage2.MessageString += string.Format(CultureInfo.CurrentCulture, Resources.LKIHours, TotalHours); } else if (timeSinceLastReport.TotalHours < 1.0) { ChatMessage chatMessage3 = cm; chatMessage3.MessageString += string.Format(CultureInfo.CurrentCulture, Resources.LKIMinutes, Math.Floor(timeSinceLastReport.TotalMinutes)); } else { ChatMessage chatMessage4 = cm; chatMessage4.MessageString += string.Format(CultureInfo.CurrentCulture, Resources.LKIHoursMinutes, TotalHours, timeSinceLastReport.Minutes); } } else { ushort zid = FFXIVHunts.GetZoneId(result.Id); cm = ChatMessage.MakePosChatMessage(FFXIVHunts.GetWorldPrepend(result.WorldId) + string.Format(CultureInfo.CurrentCulture, Resources.LKILastSeenAt, result.Name), zid, result.LastX, result.LastY, string.Format(CultureInfo.CurrentCulture, Resources.LKIHoursMinutes, TotalHours, timeSinceLastReport.Minutes), 0); } if (result.Instance > 0) { cm.PostpendToMessage(string.Format(CultureInfo.CurrentCulture, " " + Resources.InstanceSpecifier, result.Instance)); } await Program.mem.WriteChatMessage(cm).ConfigureAwait(false); } IEnumerator <Hunt> enumerator = null; } }
public override int GetHashCode() { if (this.WorldId > 1000 && this.WorldId < 2000 && (this.IsSHB || FFXIVHunts.GetZoneId(this.Id) == 156 || FFXIVHunts.GetZoneId(this.Id) == 152)) { return(this.Id.GetHashCode() ^ this.WorldId.GetHashCode() ^ this.Instance.GetHashCode()); } return(this.Id.GetHashCode() ^ this.WorldId.GetHashCode()); }
private bool PutInChat(FATEReport fate) { World world; if (!FFXIVHunts.Worlds.TryGetValue(fate.WorldId, out world)) { return(false); } int idx = world.FATEs.IndexOf(fate); if (idx == -1) { return(false); } FATEReport FATEReport = world.FATEs[idx]; FATEReport.State = fate.State; FATEReport.StartTimeEpoch = fate.StartTimeEpoch; FATEReport.Duration = fate.Duration; FATEReport.Progress = fate.Progress; bool skipAnnounce = (Settings.Default.NoAnnouncementsInContent && Program.mem.GetCurrentContentFinderCondition() > 0) || (Math.Abs(fate.TimeRemaining.TotalHours) < 3.0 && fate.TimeRemaining.TotalMinutes < (double)Settings.Default.FATEMinimumMinutesRemaining) || ((fate.State == FATEState.Preparation) ? (FATEReport.lastPutInChat > Program.mem.GetServerUtcTime().AddMinutes(-10.0)) : (Math.Abs((int)(fate.Progress - FATEReport.LastReportedProgress)) < (int)Settings.Default.FATEMinimumPercentInterval && Settings.Default.FATEMinimumPercentInterval > 0)); if (FFXIVHunts.FateNotifyCheck(FATEReport.ID) && FATEReport.lastPutInChat < Program.mem.GetServerUtcTime().AddMinutes((double)(-(double)Settings.Default.FATEInterval)) && !fate.HasEnded && !skipAnnounce) { string postpend; if (fate.State == FATEState.Preparation) { postpend = Resources.PreparationState; } else if (Math.Abs(fate.TimeRemaining.TotalHours) > 3.0) { postpend = fate.Progress.ToString() + "%"; } else { postpend = string.Format(CultureInfo.CurrentCulture, Resources.FATEPrcTimeRemaining, fate.Progress, (int)fate.TimeRemaining.TotalMinutes, fate.TimeRemaining.Seconds.ToString("D2", CultureInfo.CreateSpecificCulture(Settings.Default.LanguageCI))); } if (fate.Instance > 0) { postpend += string.Format(CultureInfo.CurrentCulture, " " + Resources.InstanceSpecifier, fate.Instance); } ChatMessage cm = ChatMessage.MakePosChatMessage(string.Format(CultureInfo.CurrentCulture, FFXIVHunts.GetWorldPrepend(fate.WorldId) + Resources.FATEMsg, FATEReport.Name(false)), fate.ZoneID, fate.PosX, fate.PosY, " " + postpend, 0); Program.mem.WriteChatMessage(cm); this.CheckAndPlaySound(HuntRank.FATE); FATEReport.lastPutInChat = Program.mem.GetServerUtcTime(); FATEReport.LastReportedProgress = fate.Progress; return(true); } return(false); }
public override bool Equals(object obj) { Hunt item = obj as Hunt; if (item == null) { return(false); } if (this.WorldId > 1000 && this.WorldId < 2000 && (this.IsSHB || FFXIVHunts.GetZoneId(this.Id) == 156 || FFXIVHunts.GetZoneId(this.Id) == 152)) { return(this.Id.Equals(item.Id) && this.WorldId.Equals(item.WorldId) && this.Instance.Equals(item.Instance)); } return(this.Id.Equals(item.Id) && this.WorldId.Equals(item.WorldId)); }
private bool AnyProblems() { if (Program.mem != null && Program.mem.ValidateProcess() && Program.mem.GetSelfCombatant() != null) { int id = Program.mem.Process.Id; int?num = (int?)this.ProcessComboBox.SelectedValue; if (id == num.GetValueOrDefault() & num != null) { if (this.hunts == null && Program.mem != null && Program.mem.ValidateProcess()) { this.hunts = new FFXIVHunts(this); } this.MainTabControl.IsEnabled = (this.HuntNotifyGroupBox.IsEnabled = true); return(false); } } this.HuntConnectionTextBlock.Text = string.Format(CultureInfo.CurrentCulture, FFXIV_GameSense.Properties.Resources.FormNoProcess, "ffxiv_dx11.exe"); if (this.ProcessComboBox.SelectedValue != null && FFXIVProcessHelper.GetFFXIVProcess((int)this.ProcessComboBox.SelectedValue) != null) { if (Program.mem != null) { Program.mem.OnNewCommand -= this.ProcessChatCommand; Program.mem.Dispose(); FFXIVHunts ffxivhunts = this.hunts; if (ffxivhunts != null) { ffxivhunts.LeaveGroup(); } } Program.mem = null; Program.mem = new FFXIVMemory(FFXIVProcessHelper.GetFFXIVProcess((int)this.ProcessComboBox.SelectedValue)); Program.mem.OnNewCommand += this.ProcessChatCommand; PersistentNamedPipeServer.Restart(); } FFXIVHunts ffxivhunts2 = this.hunts; if (ffxivhunts2 != null) { ffxivhunts2.LeaveGroup(); } this.MainTabControl.IsEnabled = (this.HuntNotifyGroupBox.IsEnabled = false); return(true); }
private void RegisterHubMethods() { FFXIVHunts.hubConnection.Connection.On("ReceiveHunt", delegate(Hunt hunt) { this.ReceiveHunt(hunt); }); FFXIVHunts.hubConnection.Connection.On("ReceiveFATE", delegate(FATEReport fate) { this.ReceiveFATE(fate); }); FFXIVHunts.hubConnection.Connection.On("DCInstanceMatch", delegate(DataCenterInstanceMatchInfo instance) { FFXIVHunts.DCInstanceMatch(instance); }); FFXIVHunts.hubConnection.Connection.On("ConnectedCount", delegate(int connectedCount) { this.w1.HuntConnectionTextBlock.Dispatcher.Invoke(delegate() { string worldName = GameResources.GetWorldName(Program.mem.GetCurrentWorldId()); IEnumerable <string> enumerable = string.Format(CultureInfo.CurrentCulture, Resources.FormConnectedToCount, worldName, connectedCount - 1).SplitAndKeep(worldName, StringComparison.Ordinal); this.w1.HuntConnectionTextBlock.Inlines.Clear(); Hyperlink worldLink = new Hyperlink(new Run(worldName)) { NavigateUri = new Uri("https://xivhunt.net/" + worldName) }; worldLink.RequestNavigate += LogInForm.Link_RequestNavigate; foreach (string s in enumerable) { if (s.Equals(worldName, StringComparison.Ordinal)) { this.w1.HuntConnectionTextBlock.Inlines.Add(worldLink); } else { this.w1.HuntConnectionTextBlock.Inlines.Add(s); } } }); }); FFXIVHunts.hubConnection.Connection.Closed += this.Connection_Closed; }
private void ProcessChatCommand(object sender, CommandEventArgs e) { LogHost.Default.Info($"[{nameof(ProcessChatCommand)}] New command: {e.Command.ToString()} {e.Parameter}"); if (e.Command == Command.Hunt) { if (GameResources.TryGetDailyHuntInfo(e.Parameter, out Tuple <ushort, ushort, float, float> hi)) { _ = Program.mem.WriteChatMessage(ChatMessage.MakePosChatMessage(string.Format(Properties.Resources.LKICanBeFoundAt, GameResources.GetEnemyName(hi.Item1, true)), hi.Item2, hi.Item3, hi.Item4)); } else if (hunts.hunts.Exists(x => x.Name.Equals(e.Parameter, StringComparison.CurrentCultureIgnoreCase))) { _ = hunts.LastKnownInfoForHunt(hunts.hunts.First(x => x.Name.Equals(e.Parameter, StringComparison.CurrentCultureIgnoreCase)).Id); } else if (GameResources.GetEnemyId(e.Parameter, out ushort bnpcid)) { _ = hunts.RandomPositionForBNpc(bnpcid); } ushort fid = GameResources.GetFateId(e.Parameter, true); if (fid > 0) { _ = hunts.LastKnownInfoForFATE(fid); if (Settings.Default.TrackFATEAfterQuery) { vm.FATEEntries.SingleOrDefault(x => x.ID == fid).Announce = true; } } else if (Enum.TryParse(e.Parameter.Split(' ').Last(), out HuntRank hr) && hr != HuntRank.FATE && GameResources.TryGetZoneID(e.Parameter.Substring(0, e.Parameter.Length - 2).Trim(), out ushort ZoneID) && FFXIVHunts.MapHunts.ContainsKey(ZoneID)) { foreach (ushort hid in FFXIVHunts.MapHunts[ZoneID].Where(x => hunts.HuntRankFor(x) == hr)) { _ = hunts.LastKnownInfoForHunt(hid); } } else { string[] pwords = e.Parameter.Split(' '); bool hqprefer = pwords.Last().Equals("HQ", StringComparison.InvariantCultureIgnoreCase); FFXIVHunts.LookupItemXIVDB(hqprefer ? string.Join(" ", pwords.Take(pwords.Count() - 1)) : e.Parameter, hqprefer).ContinueWith(t => { if (t.Result != null) { _ = Program.mem.WriteChatMessage(ChatMessage.MakeItemChatMessage(t.Result, HQ: hqprefer)); } }); } } else if (e.Command == Command.Perform) { if (!Directory.Exists(Settings.Default.PerformDirectory)) { LogHost.Default.Error(Properties.Resources.PerformDirectoryNotExists); _ = Program.mem.WriteChatMessage(new ChatMessage { MessageString = Properties.Resources.PerformDirectoryNotExists }); return; } string nametxt = e.Parameter; if (!nametxt.EndsWith(".txt")) { nametxt += ".txt"; } string namemml = e.Parameter; if (!namemml.EndsWith(".mml")) { namemml += ".mml"; } string pathnametxt = Path.Combine(Settings.Default.PerformDirectory, nametxt); string pathnamemml = Path.Combine(Settings.Default.PerformDirectory, namemml); if (File.Exists(pathnametxt)) { StopPerformance(); var p = new Performance(string.Join(",", File.ReadAllLines(pathnametxt))); if (p.Sheet.Count > 0) { _ = Program.mem.PlayPerformance(p, cts.Token); } else { TryMML(pathnametxt); } } else if (File.Exists(pathnamemml)) { StopPerformance(); TryMML(pathnamemml); } else { LogHost.Default.Error("Neither of these files were found:" + Environment.NewLine + pathnametxt + Environment.NewLine + pathnamemml); } } else if (e.Command == Command.PerformStop && cts != null) { cts.Cancel(); } else if (e.Command == Command.Flag) { string[] coords = e.Parameter.Split(','); if (coords.Length > 1 && float.TryParse(coords[0], out float xR) && float.TryParse(coords[1], out float yR)) { ushort zid = Program.mem.GetZoneId(); float x = Combatant.GetCoordFromReadable(xR, zid); float y = Combatant.GetCoordFromReadable(yR, zid); var cm = ChatMessage.MakePosChatMessage(string.Empty, zid, x, y); _ = Program.mem.WriteChatMessage(cm); } } }
private static void CreateWorldsOnDC(IEnumerable <World> worldsOnCurrentDC) { foreach (World worldNotYetCreated in from x in worldsOnCurrentDC where !FFXIVHunts.Worlds.ContainsKey(x.ID) select x) { FFXIVHunts.Worlds.Add(worldNotYetCreated.ID, new World(worldNotYetCreated.ID)); foreach (KeyValuePair <ushort, HuntRank> kvp in Hunt.RankMap) { if (worldNotYetCreated.ID > 100 && worldNotYetCreated.ID < 2000 && (kvp.Key > 8000 || FFXIVHunts.GetZoneId(kvp.Key) == 156 || FFXIVHunts.GetZoneId(kvp.Key) == 152)) { for (byte i = 1; i <= 3; i += 1) { FFXIVHunts.Worlds[worldNotYetCreated.ID].Hunts.Add(new Hunt(kvp.Key, worldNotYetCreated.ID) { Instance = i }); } } else { FFXIVHunts.Worlds[worldNotYetCreated.ID].Hunts.Add(new Hunt(kvp.Key, worldNotYetCreated.ID)); } } } }
internal FFXIVHunts(Window1 pw1) { this.w1 = pw1; FFXIVHunts.CreateWorldsOnDC(GameResources.GetWorld(Program.mem.GetHomeWorldId()).GetWorldsOnSameDataCenter()); this.CreateConnection(); }
internal async void Check(FFXIVMemory mem) { FFXIVHunts.< > c__DisplayClass44_0 CS$ < > 8__locals1 = new FFXIVHunts.< > c__DisplayClass44_0(); if (!FFXIVHunts.hubConnection.Connected) { await this.Connect(); } if (FFXIVHunts.hubConnection.Connected) { ushort currentWorldID = mem.GetCurrentWorldId(); if ((FFXIVHunts.LastJoinedWorldID != currentWorldID && FFXIVHunts.Joined && !FFXIVHunts.Joining) || !FFXIVHunts.Joined) { await this.LeaveGroup(); await this.JoinServerGroup(); } FFXIVHunts.ServerTimeUtc = mem.GetServerUtcTime(); CS$ < > 8__locals1.thisZone = mem.GetZoneId(); if (CS$ < > 8__locals1.thisZone != FFXIVHunts.lastZone && Settings.Default.OncePerHunt && Settings.Default.ForgetOnZoneChange) { FFXIVHunts.HuntsPutInChat.Clear(); } if (Array.IndexOf <uint>(FFXIVHunts.DCZones, (uint)CS$ < > 8__locals1.thisZone) > -1 && Array.IndexOf <uint>(FFXIVHunts.DCZones, (uint)FFXIVHunts.lastZone) == -1 && FFXIVHunts.Joined) { TaskAwaiter <DateTime> taskAwaiter = this.JoinDCZone(CS$ < > 8__locals1.thisZone).GetAwaiter(); if (!taskAwaiter.IsCompleted) { await taskAwaiter; TaskAwaiter <DateTime> taskAwaiter2; taskAwaiter = taskAwaiter2; taskAwaiter2 = default(TaskAwaiter <DateTime>); } FFXIVHunts.LastShoutChatSync = taskAwaiter.GetResult(); } else if (Array.IndexOf <uint>(FFXIVHunts.DCZones, (uint)FFXIVHunts.lastZone) > -1 && Array.IndexOf <uint>(FFXIVHunts.DCZones, (uint)CS$ < > 8__locals1.thisZone) == -1) { await this.LeaveDCZone(); } FFXIVHunts.lastZone = CS$ < > 8__locals1.thisZone; IEnumerable <Monster> source = mem.Combatants.OfType <Monster>(); Func <Monster, bool> predicate; if ((predicate = CS$ < > 8__locals1.< > 9__3) == null) { FFXIVHunts.< > c__DisplayClass44_0 CS$ < > 8__locals2 = CS$ < > 8__locals1; Func <Monster, bool> func = (Monster c) => FFXIVHunts.CurrentWorld.Hunts.Exists((Hunt h) => h.Id == c.BNpcNameID && FFXIVHunts.GetZoneId(c.BNpcNameID) == CS$ < > 8__locals1.thisZone); CS$ < > 8__locals2.< > 9__3 = func; predicate = func; } foreach (Monster c2 in source.Where(predicate)) { this.ReportHunt(c2); } if (Array.IndexOf <uint>(FFXIVHunts.DCZones, (uint)CS$ < > 8__locals1.thisZone) > -1) { DateTime lastShoutChatSync = FFXIVHunts.LastShoutChatSync; await this.ReportDCShoutChat((from x in mem.ReadChatLogBackwards(1000, (ChatMessage x) => x.Channel == ChatChannel.Shout && !string.IsNullOrWhiteSpace(x.Sender.Name), (ChatMessage x) => x.Timestamp <= FFXIVHunts.LastShoutChatSync) orderby x.Timestamp descending select x).Take(10)); } IEnumerable <FATE> fateList = mem.GetFateList(); Func <FATE, bool> predicate2; if ((predicate2 = CS$ < > 8__locals1.< > 9__5) == null) { FFXIVHunts.< > c__DisplayClass44_0 CS$ < > 8__locals3 = CS$ < > 8__locals1; Func <FATE, bool> func2 = (FATE f) => f.ZoneID == CS$ < > 8__locals1.thisZone; CS$ < > 8__locals3.< > 9__5 = func2; predicate2 = func2; } foreach (FATE f2 in fateList.Where(predicate2)) { this.ReportFate(f2); if (f2.IsDataCenterShared() && this.PutInChat(new FATEReport(f2) { WorldId = mem.GetHomeWorldId() }) && Settings.Default.FlashTaskbarIconOnHuntAndFATEs) { NativeMethods.FlashTaskbarIcon(mem.Process); } } }