Ejemplo n.º 1
0
 private void RemoveUnvantedCombatants(Combatant self, List <Combatant> clist)
 {
     clist.RemoveAll(c => c.BNpcNameID == 5042 || c.BNpcNameID == 7395);
     if (!Properties.Settings.Default.displaySelf)
     {
         clist.RemoveAll(c => c.ID == self.ID);
     }
     if (!Properties.Settings.Default.displayMonsters)
     {
         clist.RemoveAll(c => c.Type == ObjectType.Monster);
     }
     if (!Properties.Settings.Default.displayTreasureCoffers)
     {
         clist.RemoveAll(c => c.Type == ObjectType.Treasure);
     }
     if (!Properties.Settings.Default.displayCairns)
     {
         clist.RemoveAll(c => c.Type == ObjectType.EObject && c.EventType != EObjType.Silver && c.EventType != EObjType.Gold);
     }
     if (!Properties.Settings.Default.displayOtherPCs)
     {
         clist.RemoveAll(c => c.Type == ObjectType.PC && c.ID != self.ID);
     }
     if (!Properties.Settings.Default.displaySilverTreasureCoffers)
     {
         clist.RemoveAll(c => c.Type == ObjectType.EObject && c.EventType == EObjType.Silver);
     }
     if (!Properties.Settings.Default.displayGoldTreasureCoffers)
     {
         clist.RemoveAll(c => c.Type == ObjectType.EObject && c.EventType == EObjType.Gold);
     }
     if (clist.Any(c => c.Type == ObjectType.EObject && c.EventType == EObjType.Hoard && hoardsDiscovered.Contains(c.ID)))
     {
         clist.RemoveAll(c => c.ID == hoardsDiscovered.Last());
     }
 }
Ejemplo n.º 2
0
        internal unsafe Combatant GetCombatantFromByteArray(byte[] source)
        {
            int       offset    = 0;
            Combatant combatant = new Combatant();

            fixed(byte *p = source)
            {
                combatant.Name    = GetStringFromBytes(source, combatantOffsets.Name);
                combatant.ID      = *(uint *)&p[combatantOffsets.ID];
                combatant.OwnerID = *(uint *)&p[combatantOffsets.OwnerID];
                if (combatant.OwnerID == 3758096384u)
                {
                    combatant.OwnerID = 0u;
                }
                combatant.Type = (ObjectType)p[combatantOffsets.Type];
                combatant.EffectiveDistance = p[combatantOffsets.EffectiveDistance];

                combatant.PosX    = *(float *)&p[combatantOffsets.PosX];
                combatant.PosZ    = *(float *)&p[combatantOffsets.PosZ];
                combatant.PosY    = *(float *)&p[combatantOffsets.PosY];
                combatant.Heading = *(float *)&p[combatantOffsets.Heading];


                if (combatant.Type == ObjectType.Monster)
                {
                    //if(*(uint*)&p[0xE4]==2149253119)//necessary?
                    combatant.FateID    = *(uint *)&p[combatantOffsets.FateID];
                    combatant.ContentID = *(ushort *)&p[combatantOffsets.ContentID];
                }
                else
                {
                    combatant.FateID = combatant.ContentID = 0;
                }

                combatant.TargetID = *(uint *)&p[combatantOffsets.TargetID];
                if (combatant.TargetID == 3758096384u)
                {
                    combatant.TargetID = *(uint *)&p[combatantOffsets.TargetID2];
                }

                if (combatant.Type == ObjectType.PC || combatant.Type == ObjectType.Monster)
                {
                    combatant.Job       = (JobEnum)p[combatantOffsets.Job];
                    combatant.Level     = p[combatantOffsets.Level];
                    combatant.CurrentHP = *(uint *)&p[combatantOffsets.CurrentHP];
                    combatant.MaxHP     = *(uint *)&p[combatantOffsets.MaxHP];
                    combatant.CurrentMP = *(uint *)&p[combatantOffsets.CurrentMP];
                    combatant.MaxMP     = *(uint *)&p[combatantOffsets.MaxMP];
                    combatant.CurrentTP = *(ushort *)&p[combatantOffsets.CurrentTP];
                    combatant.MaxTP     = 1000;
                    combatant.CurrentGP = *(ushort *)&p[combatantOffsets.CurrentGP];
                    combatant.MaxGP     = *(ushort *)&p[combatantOffsets.MaxGP];
                    combatant.CurrentCP = *(ushort *)&p[combatantOffsets.CurrentCP];
                    combatant.MaxCP     = *(ushort *)&p[combatantOffsets.MaxCP];

                    offset = combatantOffsets.StatusEffectsStart;
                    int countedStatusEffects = 0;
                    while (countedStatusEffects < 32)
                    {
                        Status status = new Status {
                            ID = *(short *)&p[offset]
                        };
                        if (status.ID != 00)
                        {
                            status.Value    = *(short *)&p[offset + 2];
                            status.Timer    = *(float *)&p[offset + 4];
                            status.CasterId = *(uint *)&p[offset + 8];
                            combatant.StatusList.Add(status);
                        }
                        offset += 12;
                        countedStatusEffects++;
                    }
                }
                else
                {
                    combatant.CurrentHP                                 =
                        combatant.MaxHP                                 =
                            combatant.CurrentMP                         =
                                combatant.MaxMP                         =
                                    combatant.MaxTP                     =
                                        combatant.MaxGP                 =
                                            combatant.CurrentGP         =
                                                combatant.CurrentCP     =
                                                    combatant.CurrentTP = 0;
                }
            }

            return(combatant);
        }
Ejemplo n.º 3
0
        private bool GetPointerAddress()
        {
            string charmapSignature                       = !Is64Bit ? charmapSignature32 : charmapSignature64;
            string targetSignature                        = !Is64Bit ? targetSignature32 : targetSignature64;
            string zoneIdSignature                        = !Is64Bit ? zoneIdSignature32 : zoneIdSignature64;
            string serverTimeSignature                    = !Is64Bit ? serverTimeSignature32 : serverTimeSignature64;
            string chatLogStartSignature                  = !Is64Bit ? chatLogStartSignature32 : chatLogStartSignature64;
            string fateListSignature                      = !Is64Bit ? fateListSignature32 : fateListSignature64;
            string contentFinderConditionSignature        = !Is64Bit ? contentFinderConditionSignature32 : contentFinderConditionSignature64;
            string serverIdSignature                      = !Is64Bit ? serverIdSignature32 : serverIdSignature64;
            string lastFailedCommandSignature             = !Is64Bit ? lastFailedCommandSignature32 : lastFailedCommandSignature64;
            string currentContentFinderConditionSignature = !Is64Bit ? currentContentFinderConditionSignature32 : currentContentFinderConditionSignature64;

            int[] serverTimeOffset                    = !Is64Bit ? serverTimeOffset32 : serverTimeOffset64;
            int[] chatLogStartOffset                  = !Is64Bit ? chatLogStartOffset32 : chatLogStartOffset64;
            int[] chatLogTailOffset                   = !Is64Bit ? chatLogTailOffset32 : chatLogTailOffset64;
            int[] serverIdOffset                      = !Is64Bit ? serverIdOffset32 : serverIdOffset64;
            int   contentFinderConditionOffset        = !Is64Bit ? contentFinderConditionOffset32 : contentFinderConditionOffset64;
            int   currentContentFinderConditionOffset = !Is64Bit ? currentContentFinderConditionOffset32 : currentContentFinderConditionOffset64;
            int   lastFailedCommandOffset             = !Is64Bit ? lastFailedCommandOffset32 : lastFailedCommandOffset64;

            List <string> fail = new List <string>();

            bool bRIP = Is64Bit;

            // SERVERID
            List <IntPtr> list = SigScan(serverIdSignature, 0, bRIP);

            if (list == null || list.Count == 0)
            {
                serverIdAddress = IntPtr.Zero;
            }
            if (list.Count == 1)
            {
                serverIdAddress = ResolvePointerPath(list[0], serverIdOffset);
            }
            if (serverIdAddress == IntPtr.Zero)
            {
                fail.Add(nameof(serverIdAddress));
            }

            string regionpostpend = " game detected.";

            if (GameResources.IsChineseWorld(GetServerId()))
            {
                LogHost.Default.Info(GameRegion.Chinese.ToString() + regionpostpend);
                contentFinderOffsets = new ContentFinderOffsets(Is64Bit, GameRegion.Chinese);
                combatantOffsets     = new CombatantOffsets(Is64Bit, GameRegion.Chinese);
            }
            else if (GameResources.IsKoreanWorld(GetServerId()))
            {
                LogHost.Default.Info(GameRegion.Korean.ToString() + regionpostpend);
                serverTimeOffset[2]           = Is64Bit ? 0x684 : 0x52C;
                contentFinderConditionOffset -= Is64Bit ? 0x8 : 0xC;
                contentFinderOffsets          = new ContentFinderOffsets(Is64Bit, GameRegion.Korean);
                combatantOffsets              = new CombatantOffsets(Is64Bit, GameRegion.Korean);
            }
            else
            {
                LogHost.Default.Info(GameRegion.Global.ToString() + regionpostpend);
                contentFinderOffsets = new ContentFinderOffsets(Is64Bit, GameRegion.Global);
                combatantOffsets     = new CombatantOffsets(Is64Bit, GameRegion.Global);
            }

            // CHARMAP
            list = SigScan(charmapSignature, 0, bRIP);
            if (list == null || list.Count == 0)
            {
                charmapAddress = IntPtr.Zero;
            }
            if (list.Count == 1)
            {
                charmapAddress = list[0];
            }
            if (charmapAddress == IntPtr.Zero)
            {
                fail.Add(nameof(charmapAddress));
            }

            // TARGET
            list = SigScan(targetSignature, 0, bRIP);
            if (list == null || list.Count == 0)
            {
                targetAddress = IntPtr.Zero;
            }
            if (list.Count == 1)
            {
                targetAddress = list[0];
            }
            if (targetAddress == IntPtr.Zero)
            {
                fail.Add(nameof(targetAddress));
            }

            // ZONEID
            list = SigScan(zoneIdSignature, 0, bRIP);
            if (list.Count == 1)
            {
                zoneIdAddress = list[0];
            }
            if (zoneIdAddress == IntPtr.Zero)
            {
                fail.Add(nameof(zoneIdAddress));
            }

            // SERVERTIME
            list = SigScan(serverTimeSignature, 0, bRIP);
            if (list == null || list.Count == 0)
            {
                serverTimeAddress = IntPtr.Zero;
            }
            if (list.Count == 1)
            {
                serverTimeAddress = ResolvePointerPath(list[0], serverTimeOffset);
            }
            if (serverTimeAddress == IntPtr.Zero)
            {
                fail.Add(nameof(serverTimeAddress));
            }

            // CHATLOGSTART
            list = SigScan(chatLogStartSignature, 0, bRIP);
            if (list == null || list.Count == 0)
            {
                chatLogStartAddress = IntPtr.Zero;
            }
            if (list.Count == 1)
            {
                chatLogStartAddress = ResolvePointerPath(list[0], chatLogStartOffset);
                // CHATLOGTAIL
                chatLogTailAddress = ResolvePointerPath(list[0], chatLogTailOffset);
            }
            if (chatLogStartAddress == IntPtr.Zero)
            {
                fail.Add(nameof(chatLogStartAddress));
            }
            if (chatLogTailAddress == IntPtr.Zero)
            {
                fail.Add(nameof(chatLogTailAddress));
            }

            // FATELIST
            list = SigScan(fateListSignature, 0, bRIP);
            if (list == null || list.Count == 0)
            {
                fateListAddress = IntPtr.Zero;
            }
            if (list.Count == 1)
            {
                fateListAddress = list[0];
            }
            if (fateListAddress == IntPtr.Zero)
            {
                fail.Add(nameof(fateListAddress));
            }

            // CURRENTCONTENFINDERCONDITION
            list = SigScan(currentContentFinderConditionSignature, 0, bRIP);
            if (list == null || list.Count == 0)
            {
                currentContentFinderConditionAddress = IntPtr.Zero;
            }
            if (list.Count == 1)
            {
                currentContentFinderConditionAddress = list[0] + currentContentFinderConditionOffset;
            }
            if (currentContentFinderConditionAddress == IntPtr.Zero)
            {
                fail.Add(nameof(currentContentFinderConditionAddress));
            }

            // CONTENTFINDERCONDITION
            list = SigScan(contentFinderConditionSignature, 0, bRIP);
            if (list == null || list.Count == 0)
            {
                contentFinderConditionAddress = IntPtr.Zero;
            }
            if (list.Count == 1)
            {
                contentFinderConditionAddress = list[0] + contentFinderConditionOffset;
            }
            if (contentFinderConditionAddress == IntPtr.Zero)
            {
                fail.Add(nameof(contentFinderConditionAddress));
            }

            // LASTFAILEDCOMMAND
            list = SigScan(lastFailedCommandSignature, 0, bRIP);
            if (list == null || list.Count == 0)
            {
                lastFailedCommandAddress = IntPtr.Zero;
            }
            if (list.Count == 1)
            {
                lastFailedCommandAddress = list[0] + lastFailedCommandOffset;
            }
            if (lastFailedCommandAddress == IntPtr.Zero)
            {
                fail.Add(nameof(lastFailedCommandAddress));
            }

            Debug.WriteLine(nameof(charmapAddress) + ": 0x{0:X}", charmapAddress.ToInt64());
            Debug.WriteLine(nameof(targetAddress) + ": 0x{0:X}", targetAddress.ToInt64());
            Debug.WriteLine(nameof(zoneIdAddress) + ": 0x{0:X}", zoneIdAddress.ToInt64());
            Debug.WriteLine(nameof(chatLogStartAddress) + ": 0x{0:X}", chatLogStartAddress.ToInt64());
            Debug.WriteLine(nameof(chatLogTailAddress) + ": 0x{0:X}", chatLogTailAddress.ToInt64());
            Debug.WriteLine(nameof(fateListAddress) + ": 0x{0:X}", fateListAddress.ToInt64());
            Debug.WriteLine(nameof(serverIdAddress) + ": 0x{0:X}", serverIdAddress.ToInt64());
            Debug.WriteLine(nameof(serverTimeAddress) + ": 0x{0:X}", serverTimeAddress.ToInt64());
            Debug.WriteLine(nameof(contentFinderConditionAddress) + ": 0x{0:X}", contentFinderConditionAddress.ToInt64());
            Debug.WriteLine(nameof(currentContentFinderConditionAddress) + ": 0x{0:X}", currentContentFinderConditionAddress.ToInt64());
            Debug.WriteLine(nameof(lastFailedCommandAddress) + ": 0x{0:X}", lastFailedCommandAddress.ToInt64());

            Combatant c = GetSelfCombatant();

            if (c == null)
            {
                throw new MemoryScanException(string.Format(Properties.Resources.FailedToSigScan, nameof(charmapAddress)));
            }
            else
            {
                Debug.WriteLine("MyCharacter: '{0}' ({1})", c.Name, c.ID);
            }

            if (fail.Any())
            {
                throw new MemoryScanException(string.Format(Properties.Resources.FailedToSigScan, string.Join(",", fail)));
            }
            return(!fail.Any());
        }
Ejemplo n.º 4
0
 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);
         }
     }
 }
Ejemplo n.º 5
0
 public bool IsCrafter()
 {
     return(Combatant.IsCrafter(this.Job));
 }
Ejemplo n.º 6
0
 public bool IsGatherer()
 {
     return(Combatant.IsGatherer(this.Job));
 }
Ejemplo n.º 7
0
        public override void Update()
        {
            // Raises the events only when the given interval has
            // passed since the last event, so it is okay to call every frame
            _tickEngine.Pulse();
            if (!OverlayWindow.IsVisible)
            {
                return;
            }
            if (!MouseDown)
            {
                FollowTargetWindow();
            }
            Combatant        self  = Program.mem?.GetSelfCombatant();
            List <Combatant> clist = Program.mem?._getCombatantList();

            if (self != null && clist != null)
            {
                clist.RemoveAll(c => c.OwnerID == self.ID);
                foreach (uint ID in clist.Where(c => c.Type == ObjectType.PC).Select(x => x.ID).ToList())
                {
                    clist.RemoveAll(c => c.OwnerID == ID);
                }
                RemoveUnvantedCombatants(self, clist);

                double centerY = OverlayWindow.Height / 2;
                double centerX = OverlayWindow.Width / 2;
                foreach (Combatant c in clist)
                {                                                                        //ridiculous posx+posy as key, no idea what else to use
                    if (c.ID == 3758096384 && !miscDrawMap.ContainsKey(c.PosX + c.PosY)) //for aetherytes, npcs, and other stuff;
                    {
                        miscDrawMap.Add(c.PosX + c.PosY, new EntityOverlayControl(c));
                        OverlayWindow.Add(miscDrawMap[c.PosX + c.PosY]);
                    }
                    else if (!drawMap.ContainsKey(c.ID))
                    {
                        drawMap.Add(c.ID, new EntityOverlayControl(c, c.ID == self.ID));
                        OverlayWindow.Add(drawMap[c.ID]);
                    }

                    double Top  = (c.PosY - self.PosY);
                    double Left = (c.PosX - self.PosX);
                    Top  += centerY + (Top * OverlayWindow.Height * .003 * Properties.Settings.Default.RadarZoom);
                    Left += centerX + (Left * OverlayWindow.Width * .003 * Properties.Settings.Default.RadarZoom);
                    if (drawMap.ContainsKey(c.ID))
                    {
                        drawMap[c.ID].Update(c);
                        Top  -= (drawMap[c.ID].ActualHeight / 2);
                        Left -= (drawMap[c.ID].ActualWidth / 2);
                        if (Top < 0)
                        {
                            Canvas.SetTop(drawMap[c.ID], 0);
                        }
                        else if (Top > OverlayWindow.Height - drawMap[c.ID].ActualHeight)
                        {
                            Canvas.SetTop(drawMap[c.ID], OverlayWindow.Height - drawMap[c.ID].ActualHeight);
                        }
                        else
                        {
                            Canvas.SetTop(drawMap[c.ID], Top);
                        }

                        if (Left < 0)
                        {
                            Canvas.SetLeft(drawMap[c.ID], 0);
                        }
                        else if (Left > OverlayWindow.Width - drawMap[c.ID].ActualWidth)
                        {
                            Canvas.SetLeft(drawMap[c.ID], OverlayWindow.Width - drawMap[c.ID].ActualWidth);
                        }
                        else
                        {
                            Canvas.SetLeft(drawMap[c.ID], Left);
                        }
                    }
                    else if (miscDrawMap.ContainsKey(c.PosX + c.PosY))
                    {
                        miscDrawMap[c.PosX + c.PosY].Update(c);
                        Top  -= (miscDrawMap[c.ID].ActualHeight / 2);
                        Left -= (miscDrawMap[c.ID].ActualWidth / 2);
                        Canvas.SetTop(miscDrawMap[c.PosX + c.PosY], Top);
                        Canvas.SetLeft(miscDrawMap[c.PosX + c.PosY], Left);
                    }
                }
            }

            //cleanup
            foreach (KeyValuePair <uint, EntityOverlayControl> entry in drawMap.ToArray())
            {
                //Hide hoard/cairn, after Banded Coffer appeared... hmm Hoard will re-appear if going out of "sight" and in again
                if (entry.Value.GetName().Equals("Hoard!") && (clist?.Any(c => c.EventType == EObjType.Banded) ?? false))
                {
                    entry.Value.Visibility = Visibility.Collapsed;
                    if (!hoardsDiscovered.Contains(entry.Key))
                    {
                        hoardsDiscovered.Add(entry.Key);
                    }
                    continue;
                }

                if (clist?.Exists(c => c.ID == entry.Key) ?? false)
                {
                    continue;
                }
                else
                {
                    entry.Value.Visibility = Visibility.Collapsed;
                    drawMap.Remove(entry.Key);
                }
            }
            foreach (KeyValuePair <float, EntityOverlayControl> entry in miscDrawMap.ToArray())
            {
                if (clist?.Exists(c => c.PosX + c.PosY == entry.Key) ?? false)
                {
                    continue;
                }
                else
                {
                    entry.Value.Visibility = Visibility.Collapsed;
                    miscDrawMap.Remove(entry.Key);
                }
            }
        }