Ejemplo n.º 1
0
 public void ResetCache()
 {
     worldData     = null;
     perfData      = null;
     charIdData    = null;
     actorsData    = null;
     chatLogData   = null;
     chatInputData = null;
 }
        public override object GetData(HookProcess process)
        {
            if (baseAddress.ToInt64() <= 6496)
            {
                return(null);
            }
            if (!Offsets.ContainsKey("SourceSize") || !Offsets.ContainsKey("EntityCount"))
            {
                Console.WriteLine("Couldn't find basic");
                return(null);
            }

            if (!Offsets.ContainsKey("ID") || !Offsets.ContainsKey("Type"))
            {
                Console.WriteLine("Couldn't find player basic");
                return(null);
            }

            var data = new SigActorsData();

            int sourceSize = (int)Offsets["SourceSize"];
            int limit      = (int)Offsets["EntityCount"];
            int ptrSize    = 8; // 64 bit

            byte[] characterAddressMap = process.GetByteArray(baseAddress, ptrSize * limit);
            //byte[] baseSource = process.GetByteArray(baseAddress, sourceSize);

            Dictionary <IntPtr, IntPtr> uniqueAddresses = new Dictionary <IntPtr, IntPtr>();
            IntPtr firstAddress = IntPtr.Zero;

            var firstTime = true;

            for (var i = 0; i < limit; i++)
            {
                IntPtr characterAddress = new IntPtr(BitConverter.TryToInt64(characterAddressMap, ptrSize * i));
                if (characterAddress == IntPtr.Zero)
                {
                    continue;
                }

                if (firstTime)
                {
                    firstAddress = characterAddress;
                    firstTime    = false;
                }

                uniqueAddresses[characterAddress] = characterAddress;
            }

            // Add everyone to removed
            foreach (KeyValuePair <uint, ActorData> kvp in tempActors)
            {
                data.removedActors.Add(kvp.Key, new ActorData()
                {
                    id = kvp.Value.id,
                });
            }

            foreach (KeyValuePair <IntPtr, IntPtr> kvp in uniqueAddresses)
            {
                var    characterAddress = new IntPtr(kvp.Value.ToInt64());
                byte[] playerSource     = process.GetByteArray(characterAddress, sourceSize);

                ActorData existing  = null;
                ActorData actorData = new ActorData()
                {
                    id = BitConverter.TryToUInt32(playerSource, Offsets["ID"]),
                };
                bool addActor = false;
                int  type     = playerSource[Offsets["Type"]];
                if (type == 0x01)   // Player
                {
                    if (data.removedActors.ContainsKey(actorData.id))
                    {
                        data.removedActors.Remove(actorData.id);
                        tempActors.TryGetValue(actorData.id, out existing);
                    }
                    else
                    {
                        addActor = true;
                    }

                    // Was used for TargetID
                    //var isFirstEntry = kvp.Value.ToInt64() == firstAddress.ToInt64();

                    if (true)
                    {
                        if (Offsets.TryGetValue("Name", out int nameid))
                        {
                            actorData.name = process.GetStringFromBytes(playerSource, nameid);
                        }
                        if (Offsets.TryGetValue("PerformanceID", out int perfid))
                        {
                            actorData.perfid = playerSource[perfid];
                        }
                    }

                    if (actorData.id != 0)
                    {
                        if (expiringActors.ContainsKey(actorData.id))
                        {
                            expiringActors.Remove(actorData.id);
                        }
                    }
                    else
                    {
                        // Removed
                        data.addedActors.Remove(actorData.id);
                        continue;
                    }

                    // Only getting memory, no checks?
                    //EnsureMapAndZone(entry);

                    /*
                     * if (isFirstEntry) {
                     *  if (targetAddress.ToInt64() > 0) {
                     *      byte[] targetInfoSource = MemoryHandler.Instance.GetByteArray(targetAddress, 128);
                     *      entry.TargetID = (int)BitConverter.TryToUInt32(targetInfoSource, MemoryHandler.Instance.Structures.ActorItem.ID);
                     *  }
                     * }
                     */

                    // If removed player, just continue
                    if (existing != null)
                    {
                        continue;
                    }
                    if (addActor)
                    {
                        if (!tempActors.ContainsKey(actorData.id))
                        {
                            tempActors.Add(actorData.id, actorData);
                        }
                        data.addedActors.Add(actorData.id, actorData);
                    }
                }
            }

            // Stale removal?

            DateTime now = DateTime.Now;
            TimeSpan staleActorRemovalTime = TimeSpan.FromSeconds(0.25);

            foreach (KeyValuePair <uint, ActorData> kvp2 in data.removedActors)
            {
                if (!expiringActors.ContainsKey(kvp2.Key))
                {
                    expiringActors[kvp2.Key] = now + staleActorRemovalTime;
                }
            }
            // check expiring list for stale actors
            foreach (KeyValuePair <uint, DateTime> kvp2 in expiringActors.ToList())
            {
                if (now > kvp2.Value)
                {
                    tempActors.Remove(kvp2.Key);
                    expiringActors.Remove(kvp2.Key);
                }
                else
                {
                    data.removedActors.Remove(kvp2.Key);
                }
            }

            data.currentActors = tempActors;
            return(data);
        }
Ejemplo n.º 3
0
 public void MemoryLoop()
 {
     //Console.Clear();
     if (GetSignature("WORLD", out var worldSig))
     {
         SigWorldData data = (SigWorldData)worldSig.GetData(ffxivProcess);
         if (worldData == null || !data.Equals(worldData))
         {
             dataPipe.PushMessage(CreatePipeData(data));
             Console.WriteLine("World: " + data.world);
             worldData = data;
         }
     }
     if (GetSignature("PERFSTATUS", out var perfSig))
     {
         SigPerfData data = (SigPerfData)perfSig.GetData(ffxivProcess);
         if (data != null)
         {
             if (perfData == null || !data.Equals(perfData))
             {
                 dataPipe.PushMessage(CreatePipeData(data));
                 Console.WriteLine("Performance change " + data.IsUp());
                 perfData = data;
             }
         }
     }
     if (GetSignature("CHARID", out var charidSig))
     {
         SigCharIdData data = (SigCharIdData)charidSig.GetData(ffxivProcess);
         if (data != null)
         {
             if (charIdData == null || !data.Equals(charIdData))
             {
                 dataPipe.PushMessage(CreatePipeData(data));
                 Console.WriteLine("New charid: " + data.id);
                 charIdData = data;
             }
         }
     }
     if (GetSignature("CHARMAP", out var charSig))
     {
         SigActorsData data = (SigActorsData)charSig.GetData(ffxivProcess);
         if (data != null)
         {
             if (data.currentActors.Values.Count > 0)
             {
                 ActorData me = data.currentActors.First().Value;
                 //Console.WriteLine(string.Format("YOU: {0} {1}", me.name, me.id));
             }
             if (data.addedActors.Count > 0 || data.removedActors.Count > 0)
             {
                 dataPipe.PushMessage(CreatePipeData(data));
                 string added = String.Join("+", data.addedActors.Select(t => t.Value.name).ToArray());
                 Console.WriteLine(string.Format("Players: {0} new, {1} removed: {2}", data.addedActors.Count, data.removedActors.Count, added));
             }
             if (false)
             {
                 string added   = String.Join(",", data.addedActors.Select(t => t.Value.name).ToArray());
                 string current = String.Join(",", data.currentActors.Select(t => t.Value.name).ToArray());
                 string removed = String.Join(",", data.removedActors.Select(t => t.Value.name).ToArray());
                 Console.WriteLine(string.Format("--- {0} players", data.currentActors.Count()));
                 Console.WriteLine(string.Format("ADDED: {0}", added));
                 Console.WriteLine(string.Format("REMOVED: {0}", removed));
                 Console.WriteLine(string.Format("CURRENT: {0}", current));
             }
         }
     }
     if (GetSignature("CHATLOG", out var chatlogSig))
     {
         SigChatLogData data = (SigChatLogData)chatlogSig.GetData(ffxivProcess);
         if (data != null)
         {
             foreach (ChatLogItem msg in data.chatMessages)
             {
                 Console.WriteLine(msg.Line);
             }
             if (data.chatMessages.Count > 0)
             {
                 dataPipe.PushMessage(CreatePipeData(data));
                 Console.WriteLine(string.Format("Chatlog: {0} new", data.chatMessages.Count));
             }
         }
     }
 }