Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public void PipeMessage(NamedPipeConnection <PipeData, PipeData> conn, PipeData message)
        {
            Type type = Type.GetType(message.id + ",FFMemoryParser");

            if (type == null)
            {
                return;
            }

            Object obj = message.data.ToObject();

            if (obj != null)
            {
                if (type.Name == "SignatureList")
                {
                    Memory.SignatureList data = (obj as Memory.SignatureList);
                    if (data != null)
                    {
                        foreach (Signature item in data)
                        {
                            Console.WriteLine(string.Format("Signature {0} Not found!", item.Key));
                        }
                    }
                }

                if (type.Name == "SigWorldData")
                {
                    SigWorldData data = (obj as SigWorldData);
                    if (data != null)
                    {
                        World = data.world;
                    }
                }
                if (type.Name == "SigCharIdData")
                {
                    SigCharIdData data = (obj as SigCharIdData);
                    if (data != null)
                    {
                        CharacterID = data.id;
                        OnCharacterId?.Invoke(this, CharacterID);
                    }
                }
                // ...
                if (type.Name == "SigPerfData")
                {
                    SigPerfData data = (obj as SigPerfData);
                    if (data != null)
                    {
                        performanceData = data;

                        OnPerformanceChanged?.Invoke(this, performanceData);
                    }
                }
                if (type.Name == "SigActorsData")
                {
                    SigActorsData data = (obj as SigActorsData);
                    if (data != null)
                    {
                        actorData = data;

                        ActorData local = null;
                        if (actorData.currentActors.Count > 0)
                        {
                            local = actorData.currentActors.First().Value;
                        }
                        if (localPlayer == null || local.name != localPlayer.name)
                        {
                            localPlayer = local;
                            if (localPlayer != null)
                            {
                                OnLocalPlayerLogin?.Invoke(this, localPlayer);
                            }
                            else
                            {
                                OnLocalPlayerLogout?.Invoke(this, localPlayer);
                            }
                        }
                    }
                }
                if (type.Name == "SigChatLogData")
                {
                    SigChatLogData data = (obj as SigChatLogData);
                    if (data != null)
                    {
                        foreach (ChatLogItem item in data.chatMessages)
                        {
                            OnChatReceived?.Invoke(this, item);
                        }
                    }
                }
                if (type.Name == "SigChatInputData")
                {
                    SigChatInputData data = (obj as SigChatInputData);
                    if (data != null)
                    {
                        ChatInputOpen = data.open;
                        if (data.open)
                        {
                            Console.WriteLine(data.text);
                        }
                    }
                }
            }
        }