private void ScanTimerElapsed(object sender, ElapsedEventArgs e) { if (this._isScanning) { return; } this._scanTimer.Interval = Settings.Default.PartyWorkerTiming; this._isScanning = true; PartyResult result = this._memoryHandler.Reader.GetPartyMembers(); if (!this._partyReferencesSet) { this._partyReferencesSet = true; EventHost.Instance.RaiseNewPartyMembersEvent(this._memoryHandler, result.PartyMembers); } if (result.NewPartyMembers.Any()) { EventHost.Instance.RaisePartyMembersAddedEvent(this._memoryHandler, result.NewPartyMembers); } if (result.RemovedPartyMembers.Any()) { EventHost.Instance.RaisePartyMembersRemovedEvent(this._memoryHandler, result.RemovedPartyMembers); } this._isScanning = false; }
public bool IsInParty() { PartyResult party = Reader.GetPartyMembers(); partySize = party.PartyMembers.Count; return(partySize > 1); }
/// <summary> /// Gets part results for a constituency result from a row. /// </summary> /// <param name="csv">The csv row.</param> /// <param name="partyNames">The party names.</param> /// <param name="totalVotesCast">The total votes cast in the constituency.</param> /// <returns>The parsed constituency result.</returns> public static List <PartyResult> GetPartyConstituencyResults( CsvReader csv, string[] partyNames, int totalVotesCast) { int partiesOffset = 9; float percentageMultiplier = 100f / totalVotesCast; List <PartyResult> partyResults = new List <PartyResult>(); for (int i = 0; i < partyNames.Length; i++) { PartyResult partyResult = new PartyResult { PartyAbbreviation = partyNames[i], Votes = ConvertInt(csv.GetField <string>(partiesOffset + i)), PercentageOfVotes = ConvertFloat(csv.GetField <string>(partiesOffset + i)) * percentageMultiplier }; partyResults.Add(partyResult); } return(partyResults); }
private OpinionPoll GetOpinionPollFromRecord(CsvReader csv, string pollingCompany) { // if here on a line with data after the start tag has been found so get the abbreviation string link = csv.GetField <string>(2); if ( csv.TryGetField <DateTime>(1, out DateTime publicationDate) && !string.IsNullOrWhiteSpace(link)) { // Get the constituency party support predictions. List <PartyResult> constituencyPartyPredictions = new List <PartyResult>(); for (int i = 0; i < ConstituencyPartyNames.Length; i++) { PartyResult partyResult = new PartyResult { PartyAbbreviation = ConstituencyPartyNames[i], Votes = 0, PercentageOfVotes = ConvertFloat(csv.GetField <string>(ConstituencyPartyNamesOffset + i)) }; constituencyPartyPredictions.Add(partyResult); } // Get the list party support predictions. List <PartyResult> listPartyPredictions = new List <PartyResult>(); for (int i = 0; i < ListPartyNames.Length; i++) { PartyResult partyResult = new PartyResult { PartyAbbreviation = ListPartyNames[i], Votes = 0, PercentageOfVotes = ConvertFloat(csv.GetField <string>(ListPartyNamesOffset + i)) }; listPartyPredictions.Add(partyResult); } // Make up the poll. return(new OpinionPoll { PollingCompany = pollingCompany, Link = link, PublicationDate = publicationDate, ConstituencyPredictions = constituencyPartyPredictions, ListPredictions = listPartyPredictions }); } return(null); }
public void SendPartyResult(PartyOperation operation, string member, PartyResult res, uint val = 0) { PartyCommandResult packet = new(); packet.Name = member; packet.Command = (byte)operation; packet.Result = (byte)res; packet.ResultData = val; packet.ResultGUID = ObjectGuid.Empty; SendPacket(packet); }
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(); }
/// <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.PartyInfoWorkerRefresh.ToString(CultureInfo.InvariantCulture), out refresh)) { this._scanTimer.Interval = refresh; } Func <bool> scanner = delegate { PartyResult readResult = Reader.GetPartyMembers(); if (!this.ReferencesSet) { this.ReferencesSet = true; AppContextHelper.Instance.RaisePartyMembersUpdated(readResult.PartyMembers); } if (readResult.NewPartyMembers.Any()) { AppContextHelper.Instance.RaisePartyMembersAdded(readResult.NewPartyMembers); } if (readResult.RemovedPartyMembers.Any()) { AppContextHelper.Instance.RaisePartyMembersRemoved(readResult.RemovedPartyMembers); } this._isScanning = false; return(true); }; scanner.BeginInvoke(delegate { }, scanner); }
void HandlePartyUninvite(PartyUninvite packet) { //can't uninvite yourself if (packet.TargetGUID == GetPlayer().GetGUID()) { Log.outError(LogFilter.Network, "HandleGroupUninviteGuidOpcode: leader {0}({1}) tried to uninvite himself from the group.", GetPlayer().GetName(), GetPlayer().GetGUID().ToString()); return; } PartyResult res = GetPlayer().CanUninviteFromGroup(packet.TargetGUID); if (res != PartyResult.Ok) { SendPartyResult(PartyOperation.UnInvite, "", res); return; } Group grp = GetPlayer().GetGroup(); // grp is checked already above in CanUninviteFromGroup() Cypher.Assert(grp); if (grp.IsMember(packet.TargetGUID)) { Player.RemoveFromGroup(grp, packet.TargetGUID, RemoveMethod.Kick, GetPlayer().GetGUID(), packet.Reason); return; } Player player = grp.GetInvited(packet.TargetGUID); if (player) { player.UninviteFromGroup(); return; } SendPartyResult(PartyOperation.UnInvite, "", PartyResult.TargetNotInGroupS); }
public static PartyResult GetPartyMembers() { var result = new PartyResult(); if (!CanGetPartyMembers() || !MemoryHandler.Instance.IsAttached) { return(result); } var PartyInfoMap = (IntPtr)Scanner.Instance.Locations[Signatures.PartyMapKey]; Signature PartyCountMap = Scanner.Instance.Locations[Signatures.PartyCountKey]; foreach (KeyValuePair <uint, PartyMember> kvp in PartyWorkerDelegate.PartyMembers) { result.RemovedPartyMembers.TryAdd(kvp.Key, kvp.Value.Clone()); } try { var partyCount = MemoryHandler.Instance.GetByte(PartyCountMap); var sourceSize = MemoryHandler.Instance.Structures.PartyMember.SourceSize; if (partyCount > 1 && partyCount < 9) { for (uint i = 0; i < partyCount; i++) { var address = PartyInfoMap.ToInt64() + i * (uint)sourceSize; byte[] source = MemoryHandler.Instance.GetByteArray(new IntPtr(address), sourceSize); var ID = BitConverter.TryToUInt32(source, MemoryHandler.Instance.Structures.PartyMember.ID); ActorItem existing = null; var newEntry = false; if (result.RemovedPartyMembers.ContainsKey(ID)) { result.RemovedPartyMembers.TryRemove(ID, out PartyMember removedPartyMember); if (MonsterWorkerDelegate.ActorItems.ContainsKey(ID)) { existing = MonsterWorkerDelegate.GetActorItem(ID); } if (PCWorkerDelegate.ActorItems.ContainsKey(ID)) { existing = PCWorkerDelegate.GetActorItem(ID); } } else { newEntry = true; } PartyMember entry = PartyMemberResolver.ResolvePartyMemberFromBytes(source, existing); if (!entry.IsValid) { continue; } if (existing != null) { continue; } if (newEntry) { PartyWorkerDelegate.EnsurePartyMember(entry.ID, entry); result.NewPartyMembers.TryAdd(entry.ID, entry.Clone()); } } } if (partyCount <= 1) { PartyMember entry = PartyMemberResolver.ResolvePartyMemberFromBytes(Array.Empty <byte>(), PCWorkerDelegate.CurrentUser); if (result.RemovedPartyMembers.ContainsKey(entry.ID)) { result.RemovedPartyMembers.TryRemove(entry.ID, out PartyMember removedPartyMember); } PartyWorkerDelegate.EnsurePartyMember(entry.ID, entry); } } catch (Exception ex) { MemoryHandler.Instance.RaiseException(Logger, ex, true); } try { // REMOVE OLD PARTY MEMBERS FROM LIVE CURRENT DICTIONARY foreach (KeyValuePair <uint, PartyMember> kvp in result.RemovedPartyMembers) { PartyWorkerDelegate.RemovePartyMember(kvp.Key); } } catch (Exception ex) { MemoryHandler.Instance.RaiseException(Logger, ex, true); } return(result); }
public PartyResult GetPartyMembers() { PartyResult result = new PartyResult(); if (!this.CanGetPartyMembers() || !this._memoryHandler.IsAttached) { return(result); } IntPtr partInfoAddress = (IntPtr)this._memoryHandler.Scanner.Locations[Signatures.PARTYMAP_KEY]; IntPtr partyCountyAddress = this._memoryHandler.Scanner.Locations[Signatures.PARTYCOUNT_KEY]; foreach (KeyValuePair <uint, PartyMember> kvp in this._partyWorkerDelegate.PartyMembers) { result.RemovedPartyMembers.TryAdd(kvp.Key, kvp.Value.Clone()); } try { byte partyCount = this._memoryHandler.GetByte(partyCountyAddress); int sourceSize = this._memoryHandler.Structures.PartyMember.SourceSize; byte[] partyMemberMap = this._memoryHandler.BufferPool.Rent(sourceSize); try { if (partyCount > 1 && partyCount < 9) { for (uint i = 0; i < partyCount; i++) { long address = partInfoAddress.ToInt64() + i * (uint)sourceSize; this._memoryHandler.GetByteArray(new IntPtr(address), partyMemberMap); uint ID = SharlayanBitConverter.TryToUInt32(partyMemberMap, this._memoryHandler.Structures.PartyMember.ID); ActorItem existing = null; bool newEntry = false; if (result.RemovedPartyMembers.ContainsKey(ID)) { result.RemovedPartyMembers.TryRemove(ID, out PartyMember removedPartyMember); if (this._monsterWorkerDelegate.ActorItems.ContainsKey(ID)) { existing = this._monsterWorkerDelegate.GetActorItem(ID); } if (this._pcWorkerDelegate.ActorItems.ContainsKey(ID)) { existing = this._pcWorkerDelegate.GetActorItem(ID); } } else { newEntry = true; } PartyMember entry = this._partyMemberResolver.ResolvePartyMemberFromBytes(partyMemberMap, existing); if (!entry.IsValid) { continue; } if (existing != null) { continue; } if (newEntry) { this._partyWorkerDelegate.EnsurePartyMember(entry.ID, entry); result.NewPartyMembers.TryAdd(entry.ID, entry.Clone()); } } } if (partyCount <= 1 && this._pcWorkerDelegate.CurrentUser != null) { PartyMember entry = this._partyMemberResolver.ResolvePartyMemberFromBytes(Array.Empty <byte>(), this._pcWorkerDelegate.CurrentUser); if (result.RemovedPartyMembers.ContainsKey(entry.ID)) { result.RemovedPartyMembers.TryRemove(entry.ID, out PartyMember removedPartyMember); } this._partyWorkerDelegate.EnsurePartyMember(entry.ID, entry); } } catch (Exception ex) { this._memoryHandler.RaiseException(Logger, ex); } finally { this._memoryHandler.BufferPool.Return(partyMemberMap); } } catch (Exception ex) { this._memoryHandler.RaiseException(Logger, ex); } try { // REMOVE OLD PARTY MEMBERS FROM LIVE CURRENT DICTIONARY foreach (KeyValuePair <uint, PartyMember> kvp in result.RemovedPartyMembers) { this._partyWorkerDelegate.RemovePartyMember(kvp.Key); } } catch (Exception ex) { this._memoryHandler.RaiseException(Logger, ex); } result.PartyMembers = this._partyWorkerDelegate.PartyMembers; return(result); }
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); }
public PartyResult(PartyResult src) { PartyAbbreviation = src.PartyAbbreviation; Votes = src.Votes; PercentageOfVotes = src.PercentageOfVotes; }