Exemple #1
0
        /// <summary>
        /// </summary>
        /// <param name="sender"> </param>
        /// <param name="e"> </param>
        private void ScanTimerElapsed(object sender, ElapsedEventArgs e)
        {
            if (_isScanning)
            {
                return;
            }
            _isScanning = true;
            double refresh = 100;

            if (Double.TryParse(Settings.Default.ActorWorkerRefresh.ToString(CultureInfo.InvariantCulture), out refresh))
            {
                _scanTimer.Interval = refresh;
            }
            Func <bool> scannerWorker = delegate
            {
                if (MemoryHandler.Instance.SigScanner.Locations.ContainsKey("GAMEMAIN"))
                {
                    if (MemoryHandler.Instance.SigScanner.Locations.ContainsKey("CHARMAP"))
                    {
                        try
                        {
                            #region Ensure Target & Map

                            long targetAddress = 0;
                            uint mapIndex      = 0;
                            if (MemoryHandler.Instance.SigScanner.Locations.ContainsKey("TARGET"))
                            {
                                try
                                {
                                    targetAddress = MemoryHandler.Instance.SigScanner.Locations["TARGET"];
                                }
                                catch (Exception ex)
                                {
                                }
                            }
                            if (MemoryHandler.Instance.SigScanner.Locations.ContainsKey("MAP"))
                            {
                                try
                                {
                                    mapIndex = (uint)MemoryHandler.Instance.GetPlatformUInt(MemoryHandler.Instance.SigScanner.Locations["MAP"]);
                                }
                                catch (Exception ex)
                                {
                                }
                            }

                            #endregion

                            var       endianSize = MemoryHandler.Instance.ProcessModel.IsWin64 ? 8 : 4;
                            const int limit      = 1372;

                            var characterAddressMap = MemoryHandler.Instance.GetByteArray(MemoryHandler.Instance.SigScanner.Locations["CHARMAP"], endianSize * limit);

                            var uniqueAddresses = new Dictionary <IntPtr, IntPtr>();

                            for (var i = 0; i < limit; i++)
                            {
                                IntPtr characterAddress;
                                if (MemoryHandler.Instance.ProcessModel.IsWin64)
                                {
                                    characterAddress = new IntPtr(BitConverter.ToInt64(characterAddressMap, i * endianSize));
                                }
                                else
                                {
                                    characterAddress = new IntPtr(BitConverter.ToInt32(characterAddressMap, i * endianSize));
                                }
                                if (characterAddress == IntPtr.Zero)
                                {
                                    continue;
                                }
                                uniqueAddresses[characterAddress] = characterAddress;
                            }

                            var sourceData = uniqueAddresses.Select(kvp => MemoryHandler.Instance.GetByteArray((long)kvp.Value, 0x3F40))
                                             .ToList();

                            #region ActorEntity Handlers

                            var firstTime = true;

                            var currentMonsterEntries = MonsterWorkerDelegate.NPCEntities.Keys.ToDictionary(key => key);
                            var currentNPCEntries     = NPCWorkerDelegate.NPCEntities.Keys.ToDictionary(key => key);
                            var currentPCEntries      = PCWorkerDelegate.NPCEntities.Keys.ToDictionary(key => key);

                            var newMonsterEntries = new List <UInt32>();
                            var newNPCEntries     = new List <UInt32>();
                            var newPCEntries      = new List <UInt32>();

                            for (var i = 0; i < sourceData.Count; i++)
                            {
                                try
                                {
                                    var source = sourceData[i];
                                    //var source = MemoryHandler.Instance.GetByteArray(characterAddress, 0x3F40);

                                    UInt32     ID;
                                    UInt32     NPCID2;
                                    Actor.Type Type;

                                    switch (Settings.Default.GameLanguage)
                                    {
                                    case "Chinese":
                                        ID     = BitConverter.ToUInt32(source, 0x74);
                                        NPCID2 = BitConverter.ToUInt32(source, 0x80);
                                        Type   = (Actor.Type)source[0x8A];
                                        break;

                                    default:
                                        ID     = BitConverter.ToUInt32(source, 0x74);
                                        NPCID2 = BitConverter.ToUInt32(source, 0x80);
                                        Type   = (Actor.Type)source[0x8A];
                                        break;
                                    }

                                    ActorEntity existing = null;

                                    switch (Type)
                                    {
                                    case Actor.Type.Monster:
                                        if (currentMonsterEntries.ContainsKey(ID))
                                        {
                                            currentMonsterEntries.Remove(ID);
                                            existing = MonsterWorkerDelegate.GetNPCEntity(ID);
                                        }
                                        else
                                        {
                                            newMonsterEntries.Add(ID);
                                        }
                                        break;

                                    case Actor.Type.PC:
                                        if (currentPCEntries.ContainsKey(ID))
                                        {
                                            currentPCEntries.Remove(ID);
                                            existing = PCWorkerDelegate.GetNPCEntity(ID);
                                        }
                                        else
                                        {
                                            newPCEntries.Add(ID);
                                        }
                                        break;

                                    case Actor.Type.NPC:
                                        if (currentNPCEntries.ContainsKey(NPCID2))
                                        {
                                            currentNPCEntries.Remove(NPCID2);
                                            existing = NPCWorkerDelegate.GetNPCEntity(NPCID2);
                                        }
                                        else
                                        {
                                            newNPCEntries.Add(NPCID2);
                                        }
                                        break;

                                    default:
                                        if (currentNPCEntries.ContainsKey(ID))
                                        {
                                            currentNPCEntries.Remove(ID);
                                            existing = NPCWorkerDelegate.GetNPCEntity(ID);
                                        }
                                        else
                                        {
                                            newNPCEntries.Add(ID);
                                        }
                                        break;
                                    }

                                    var entry = ActorEntityHelper.ResolveActorFromBytes(source, firstTime, existing);

                                    firstTime = false;

                                    //var actor = MemoryHandler.Instance.GetStructureFromBytes<Structures.NPCEntry>(source);
                                    //var actor = MemoryHandler.Instance.GetStructure<Structures.NPCEntry>(characterAddress);
                                    //var name = MemoryHandler.Instance.GetString(characterAddress, 48);
                                    //var entry = ActorEntityHelper.ResolveActorFromMemory(actor, name);
                                    entry.MapIndex = mapIndex;
                                    if (i == 0)
                                    {
                                        var name = Settings.Default.CharacterName;
                                        if (name != entry.Name || String.IsNullOrWhiteSpace(name))
                                        {
                                            Settings.Default.CharacterName = entry.Name;
                                        }
                                        if (targetAddress > 0)
                                        {
                                            uint currentTargetID;
                                            var  targetInfoSource = MemoryHandler.Instance.GetByteArray(targetAddress, 128);
                                            switch (Settings.Default.GameLanguage)
                                            {
                                            case "Chinese":
                                                currentTargetID = BitConverter.ToUInt32(targetInfoSource, 0x68);
                                                break;

                                            default:
                                                currentTargetID = BitConverter.ToUInt32(targetInfoSource, 0x68);
                                                break;
                                            }
                                            entry.TargetID = (int)currentTargetID;
                                        }
                                    }
                                    if (!entry.IsValid)
                                    {
                                        newMonsterEntries.Remove(entry.ID);
                                        newMonsterEntries.Remove(entry.NPCID2);
                                        newNPCEntries.Remove(entry.ID);
                                        newNPCEntries.Remove(entry.NPCID2);
                                        newPCEntries.Remove(entry.ID);
                                        newPCEntries.Remove(entry.NPCID2);
                                        continue;
                                    }
                                    if (existing != null)
                                    {
                                        continue;
                                    }
                                    switch (entry.Type)
                                    {
                                    case Actor.Type.Monster:
                                        MonsterWorkerDelegate.EnsureNPCEntity(entry.ID, entry);
                                        break;

                                    case Actor.Type.PC:
                                        PCWorkerDelegate.EnsureNPCEntity(entry.ID, entry);
                                        break;

                                    case Actor.Type.NPC:
                                        NPCWorkerDelegate.EnsureNPCEntity(entry.NPCID2, entry);
                                        break;

                                    default:
                                        NPCWorkerDelegate.EnsureNPCEntity(entry.ID, entry);
                                        break;
                                    }
                                }
                                catch (Exception ex)
                                {
                                }
                            }

                            if (!ReferencesSet)
                            {
                                ReferencesSet = true;
                                AppContextHelper.Instance.RaiseNewMonsterEntries(MonsterWorkerDelegate.NPCEntities);
                                AppContextHelper.Instance.RaiseNewNPCEntries(NPCWorkerDelegate.NPCEntities);
                                AppContextHelper.Instance.RaiseNewPCEntries(PCWorkerDelegate.NPCEntities);
                            }

                            if (newMonsterEntries.Any())
                            {
                                AppContextHelper.Instance.RaiseNewMonsterAddedEntries(newMonsterEntries);
                            }
                            if (newNPCEntries.Any())
                            {
                                AppContextHelper.Instance.RaiseNewNPCAddedEntries(newNPCEntries);
                            }
                            if (newPCEntries.Any())
                            {
                                AppContextHelper.Instance.RaiseNewPCAddedEntries(newPCEntries);
                            }

                            if (currentMonsterEntries.Any())
                            {
                                AppContextHelper.Instance.RaiseNewMonsterRemovedEntries(currentMonsterEntries.Keys.ToList());
                                foreach (var key in currentMonsterEntries.Keys)
                                {
                                    MonsterWorkerDelegate.RemoveNPCEntity(key);
                                }
                            }
                            if (currentNPCEntries.Any())
                            {
                                AppContextHelper.Instance.RaiseNewNPCRemovedEntries(currentNPCEntries.Keys.ToList());
                                foreach (var key in currentNPCEntries.Keys)
                                {
                                    NPCWorkerDelegate.RemoveNPCEntity(key);
                                }
                            }
                            if (currentPCEntries.Any())
                            {
                                AppContextHelper.Instance.RaiseNewPCRemovedEntries(currentPCEntries.Keys.ToList());
                                foreach (var key in currentPCEntries.Keys)
                                {
                                    PCWorkerDelegate.RemoveNPCEntity(key);
                                }
                            }

                            #endregion
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
                _isScanning = false;
                return(true);
            };

            scannerWorker.BeginInvoke(delegate { }, scannerWorker);
        }
Exemple #2
0
        /// <summary>
        /// </summary>
        /// <param name="sender"> </param>
        /// <param name="e"> </param>
        private void ScanTimerElapsed(object sender, ElapsedEventArgs e)
        {
            if (_isScanning)
            {
                return;
            }
            _isScanning = true;
            double refresh = 1000;

            if (Double.TryParse(Settings.Default.PartyInfoWorkerRefresh.ToString(CultureInfo.InvariantCulture), out refresh))
            {
                _scanTimer.Interval = refresh;
            }
            Func <bool> scannerWorker = delegate
            {
                if (MemoryHandler.Instance.SigScanner.Locations.ContainsKey("CHARMAP"))
                {
                    if (MemoryHandler.Instance.SigScanner.Locations.ContainsKey("PARTYMAP"))
                    {
                        if (MemoryHandler.Instance.SigScanner.Locations.ContainsKey("PARTYCOUNT"))
                        {
                            PartyInfoMap  = MemoryHandler.Instance.SigScanner.Locations["PARTYMAP"];
                            PartyCountMap = MemoryHandler.Instance.SigScanner.Locations["PARTYCOUNT"];
                            try
                            {
                                var partyCount = MemoryHandler.Instance.GetByte(PartyCountMap);

                                var currentPartyEntries = PartyInfoWorkerDelegate.NPCEntities.Keys.ToDictionary(key => key);

                                var newPartyEntries = new List <UInt32>();

                                if (partyCount > 1 && partyCount < 9)
                                {
                                    for (uint i = 0; i < partyCount; i++)
                                    {
                                        UInt32 ID;
                                        uint   size;
                                        switch (Settings.Default.GameLanguage)
                                        {
                                        case "Chinese":
                                            size = 594;
                                            break;

                                        default:
                                            size = 544;
                                            break;
                                        }
                                        var address = PartyInfoMap + (i * size);
                                        var source  = MemoryHandler.Instance.GetByteArray(address, (int)size);
                                        switch (Settings.Default.GameLanguage)
                                        {
                                        case "Chinese":
                                            ID = BitConverter.ToUInt32(source, 0x10);
                                            break;

                                        default:
                                            ID = BitConverter.ToUInt32(source, 0x10);
                                            break;
                                        }
                                        ActorEntity existing = null;
                                        if (currentPartyEntries.ContainsKey(ID))
                                        {
                                            currentPartyEntries.Remove(ID);
                                            if (MonsterWorkerDelegate.NPCEntities.ContainsKey(ID))
                                            {
                                                existing = MonsterWorkerDelegate.GetNPCEntity(ID);
                                            }
                                            if (PCWorkerDelegate.NPCEntities.ContainsKey(ID))
                                            {
                                                existing = PCWorkerDelegate.GetNPCEntity(ID);
                                            }
                                        }
                                        else
                                        {
                                            newPartyEntries.Add(ID);
                                        }
                                        var entry = PartyEntityHelper.ResolvePartyMemberFromBytes(source, existing);
                                        if (!entry.IsValid)
                                        {
                                            continue;
                                        }
                                        if (existing != null)
                                        {
                                            continue;
                                        }
                                        PartyInfoWorkerDelegate.EnsureNPCEntity(entry.ID, entry);
                                    }
                                }
                                else if (partyCount == 0 || partyCount == 1)
                                {
                                    var entry = PartyEntityHelper.ResolvePartyMemberFromBytes(new byte[0], PCWorkerDelegate.CurrentUser);
                                    if (entry.IsValid)
                                    {
                                        var exists = false;
                                        if (currentPartyEntries.ContainsKey(entry.ID))
                                        {
                                            currentPartyEntries.Remove(entry.ID);
                                            exists = true;
                                        }
                                        else
                                        {
                                            newPartyEntries.Add(entry.ID);
                                        }
                                        if (!exists)
                                        {
                                            PartyInfoWorkerDelegate.EnsureNPCEntity(entry.ID, entry);
                                        }
                                    }
                                }

                                if (!ReferencesSet)
                                {
                                    ReferencesSet = true;
                                    AppContextHelper.Instance.RaiseNewPartyEntries(PartyInfoWorkerDelegate.NPCEntities);
                                }

                                if (newPartyEntries.Any())
                                {
                                    AppContextHelper.Instance.RaiseNewPartyAddedEntries(newPartyEntries);
                                }

                                if (currentPartyEntries.Any())
                                {
                                    AppContextHelper.Instance.RaiseNewPartyRemovedEntries(currentPartyEntries.Keys.ToList());
                                    foreach (var key in currentPartyEntries.Keys)
                                    {
                                        PartyInfoWorkerDelegate.RemoveNPCEntity(key);
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                    }
                }
                _isScanning = false;
                return(true);
            };

            scannerWorker.BeginInvoke(delegate { }, scannerWorker);
        }
Exemple #3
0
        /// <summary>
        /// </summary>
        /// <param name="sender"> </param>
        /// <param name="e"> </param>
        private void ScanTimerElapsed(object sender, ElapsedEventArgs e)
        {
            if (_isScanning)
            {
                return;
            }
            _isScanning = true;
            double refresh = 100;

            if (Double.TryParse(Settings.Default.TargetWorkerRefresh.ToString(CultureInfo.InvariantCulture), out refresh))
            {
                _scanTimer.Interval = refresh;
            }
            Func <bool> scannerWorker = delegate
            {
                if (MemoryHandler.Instance.SigScanner.Locations.ContainsKey("GAMEMAIN"))
                {
                    if (MemoryHandler.Instance.SigScanner.Locations.ContainsKey("CHARMAP"))
                    {
                        try
                        {
                            long targetHateStructure = 0;
                            switch (Settings.Default.GameLanguage)
                            {
                            case "Chinese":
                                targetHateStructure = MemoryHandler.Instance.SigScanner.Locations["CHARMAP"] + 1136;
                                break;

                            default:
                                if (MemoryHandler.Instance.SigScanner.Locations.ContainsKey("ENMITYMAP"))
                                {
                                    targetHateStructure = MemoryHandler.Instance.SigScanner.Locations["ENMITYMAP"];
                                }
                                break;
                            }
                            var enmityEntries = new List <EnmityEntry>();
                            var targetEntity  = new TargetEntity();
                            if (MemoryHandler.Instance.SigScanner.Locations.ContainsKey("TARGET"))
                            {
                                var targetAddress  = MemoryHandler.Instance.SigScanner.Locations["TARGET"];
                                var somethingFound = false;
                                if (targetAddress > 0)
                                {
                                    //var targetInfo = MemoryHandler.Instance.GetStructure<Structures.Target>(targetAddress);
                                    uint currentTarget    = 0;
                                    uint mouseOverTarget  = 0;
                                    uint focusTarget      = 0;
                                    uint previousTarget   = 0;
                                    uint currentTargetID  = 0;
                                    var  targetInfoSource = MemoryHandler.Instance.GetByteArray(targetAddress, 192);
                                    switch (Settings.Default.GameLanguage)
                                    {
                                    case "Chinese":
                                        currentTarget   = BitConverter.ToUInt32(targetInfoSource, 0x0);
                                        mouseOverTarget = BitConverter.ToUInt32(targetInfoSource, 0xC);
                                        focusTarget     = BitConverter.ToUInt32(targetInfoSource, 0x3C);
                                        previousTarget  = BitConverter.ToUInt32(targetInfoSource, 0x48);
                                        currentTargetID = BitConverter.ToUInt32(targetInfoSource, 0x5C);
                                        break;

                                    default:
                                        currentTarget = BitConverter.ToUInt32(targetInfoSource, 0x0);
                                        if (MemoryHandler.Instance.ProcessModel.IsWin64)
                                        {
                                            mouseOverTarget = BitConverter.ToUInt32(targetInfoSource, 0x10);
                                            focusTarget     = BitConverter.ToUInt32(targetInfoSource, 0x50);
                                            previousTarget  = BitConverter.ToUInt32(targetInfoSource, 0x68);
                                            currentTargetID = BitConverter.ToUInt32(targetInfoSource, 0x80);
                                        }
                                        else
                                        {
                                            mouseOverTarget = BitConverter.ToUInt32(targetInfoSource, 0x8);
                                            focusTarget     = BitConverter.ToUInt32(targetInfoSource, 0x38);
                                            previousTarget  = BitConverter.ToUInt32(targetInfoSource, 0x44);
                                            currentTargetID = BitConverter.ToUInt32(targetInfoSource, 0x58);
                                        }
                                        break;
                                    }
                                    if (currentTarget > 0)
                                    {
                                        try
                                        {
                                            var source = MemoryHandler.Instance.GetByteArray(currentTarget, 0x3F40);
                                            var entry  = ActorEntityHelper.ResolveActorFromBytes(source);
                                            if (MemoryHandler.Instance.SigScanner.Locations.ContainsKey("MAP"))
                                            {
                                                try
                                                {
                                                    entry.MapIndex = (uint)MemoryHandler.Instance.GetPlatformUInt(MemoryHandler.Instance.SigScanner.Locations["MAP"]);
                                                }
                                                catch (Exception ex)
                                                {
                                                }
                                            }
                                            if (entry.IsValid)
                                            {
                                                somethingFound             = true;
                                                targetEntity.CurrentTarget = entry;
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                        }
                                    }
                                    if (mouseOverTarget > 0)
                                    {
                                        try
                                        {
                                            var source = MemoryHandler.Instance.GetByteArray(mouseOverTarget, 0x3F40);
                                            var entry  = ActorEntityHelper.ResolveActorFromBytes(source);
                                            if (MemoryHandler.Instance.SigScanner.Locations.ContainsKey("MAP"))
                                            {
                                                try
                                                {
                                                    entry.MapIndex = (uint)MemoryHandler.Instance.GetPlatformUInt(MemoryHandler.Instance.SigScanner.Locations["MAP"]);
                                                }
                                                catch (Exception ex)
                                                {
                                                }
                                            }
                                            if (entry.IsValid)
                                            {
                                                somethingFound = true;
                                                targetEntity.MouseOverTarget = entry;
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                        }
                                    }
                                    if (focusTarget > 0)
                                    {
                                        var source = MemoryHandler.Instance.GetByteArray(focusTarget, 0x3F40);
                                        var entry  = ActorEntityHelper.ResolveActorFromBytes(source);
                                        if (MemoryHandler.Instance.SigScanner.Locations.ContainsKey("MAP"))
                                        {
                                            try
                                            {
                                                entry.MapIndex = (uint)MemoryHandler.Instance.GetPlatformUInt(MemoryHandler.Instance.SigScanner.Locations["MAP"]);
                                            }
                                            catch (Exception ex)
                                            {
                                            }
                                        }
                                        if (entry.IsValid)
                                        {
                                            somethingFound           = true;
                                            targetEntity.FocusTarget = entry;
                                        }
                                    }
                                    if (previousTarget > 0)
                                    {
                                        try
                                        {
                                            var source = MemoryHandler.Instance.GetByteArray(previousTarget, 0x3F40);
                                            var entry  = ActorEntityHelper.ResolveActorFromBytes(source);
                                            if (MemoryHandler.Instance.SigScanner.Locations.ContainsKey("MAP"))
                                            {
                                                try
                                                {
                                                    entry.MapIndex = (uint)MemoryHandler.Instance.GetPlatformUInt(MemoryHandler.Instance.SigScanner.Locations["MAP"]);
                                                }
                                                catch (Exception ex)
                                                {
                                                }
                                            }
                                            if (entry.IsValid)
                                            {
                                                somethingFound = true;
                                                targetEntity.PreviousTarget = entry;
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                        }
                                    }
                                    if (currentTargetID > 0)
                                    {
                                        somethingFound = true;
                                        targetEntity.CurrentTargetID = currentTargetID;
                                    }
                                }
                                if (targetEntity.CurrentTargetID > 0 && targetHateStructure > 0)
                                {
                                    for (uint i = 0; i < 16; i++)
                                    {
                                        try
                                        {
                                            var address     = targetHateStructure + (i * 72);
                                            var enmityEntry = new EnmityEntry
                                            {
                                                Name   = MemoryHandler.Instance.GetString(address),
                                                ID     = (uint)MemoryHandler.Instance.GetPlatformInt(address, 64),
                                                Enmity = (uint)MemoryHandler.Instance.GetPlatformInt(address, 68)
                                            };
                                            if (enmityEntry.ID <= 0)
                                            {
                                                continue;
                                            }
                                            if (String.IsNullOrWhiteSpace(enmityEntry.Name))
                                            {
                                                var pc      = PCWorkerDelegate.GetNPCEntity(enmityEntry.ID);
                                                var npc     = NPCWorkerDelegate.GetNPCEntity(enmityEntry.ID);
                                                var monster = MonsterWorkerDelegate.GetNPCEntity(enmityEntry.ID);
                                                try
                                                {
                                                    enmityEntry.Name = (pc ?? npc).Name ?? monster.Name;
                                                }
                                                catch (Exception ex)
                                                {
                                                }
                                            }
                                            enmityEntries.Add(enmityEntry);
                                        }
                                        catch (Exception ex)
                                        {
                                        }
                                    }
                                }
                                targetEntity.EnmityEntries = enmityEntries;
                                if (somethingFound)
                                {
                                    AppContextHelper.Instance.RaiseNewTargetEntity(targetEntity);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
                _isScanning = false;
                return(true);
            };

            scannerWorker.BeginInvoke(delegate { }, scannerWorker);
        }
        public static ActorEntity ResolveActorFromBytes(byte[] source, bool isCurrentUser = false, ActorEntity entry = null)
        {
            entry = entry ?? new ActorEntity();
            try
            {
                uint targetID;
                uint pcTargetID;
                entry.MapIndex = 0;
                entry.TargetID = 0;
                switch (Settings.Default.GameLanguage)
                {
                case "Chinese":
                    entry.Name            = MemoryHandler.Instance.GetStringFromBytes(source, 48);
                    entry.ID              = BitConverter.ToUInt32(source, 0x74);
                    entry.NPCID1          = BitConverter.ToUInt32(source, 0x78);
                    entry.NPCID2          = BitConverter.ToUInt32(source, 0x80);
                    entry.OwnerID         = BitConverter.ToUInt32(source, 0x84);
                    entry.Type            = (Actor.Type)source[0x8A];
                    entry.TargetType      = (Actor.TargetType)source[0x8C];
                    entry.GatheringStatus = source[0x8E];
                    entry.Distance        = source[0x8F];
                    entry.X                  = BitConverter.ToSingle(source, 0xA0);
                    entry.Z                  = BitConverter.ToSingle(source, 0xA4);
                    entry.Y                  = BitConverter.ToSingle(source, 0xA8);
                    entry.Heading            = BitConverter.ToSingle(source, 0xB0);
                    entry.Fate               = BitConverter.ToUInt32(source, 0xE4); // ??
                    entry.GatheringInvisible = source[0x11C];                       // ??
                    entry.ModelID            = BitConverter.ToUInt32(source, 0x174);
                    entry.ActionStatus       = (Actor.ActionStatus)source[0x17C];
                    entry.IsGM               = BitConverter.ToBoolean(source, 0x183); // ?
                    entry.Icon               = (Actor.Icon)source[0x18C];
                    entry.Status             = (Actor.Status)source[0x18E];
                    entry.ClaimedByID        = BitConverter.ToUInt32(source, 0x1A0);
                    targetID                 = BitConverter.ToUInt32(source, 0x1A8);
                    pcTargetID               = BitConverter.ToUInt32(source, 0xAA8);
                    entry.Job                = (Actor.Job)source[0x17C0];
                    entry.Level              = source[0x17C1];
                    entry.GrandCompany       = source[0x17C3];
                    entry.GrandCompanyRank   = source[0x17C4];
                    entry.Title              = source[0x17C6];
                    entry.HPCurrent          = BitConverter.ToInt32(source, 0x17C8);
                    entry.HPMax              = BitConverter.ToInt32(source, 0x17CC);
                    entry.MPCurrent          = BitConverter.ToInt32(source, 0x17D0);
                    entry.MPMax              = BitConverter.ToInt32(source, 0x17D4);
                    entry.TPCurrent          = BitConverter.ToInt16(source, 0x17D8);
                    entry.TPMax              = 1000;
                    entry.GPCurrent          = BitConverter.ToInt16(source, 0x17DA);
                    entry.GPMax              = BitConverter.ToInt16(source, 0x17DC);
                    entry.CPCurrent          = BitConverter.ToInt16(source, 0x17DE);
                    entry.CPMax              = BitConverter.ToInt16(source, 0x17E0);
                    entry.Race               = source[0x2E58];            // ??
                    entry.Sex                = (Actor.Sex)source[0x2E59]; //?
                    entry.IsCasting          = BitConverter.ToBoolean(source, 0x32E0);
                    entry.CastingID          = BitConverter.ToInt16(source, 0x32E4);
                    entry.CastingTargetID    = BitConverter.ToUInt32(source, 0x32F0);
                    entry.CastingProgress    = BitConverter.ToSingle(source, 0x3314);
                    entry.CastingTime        = BitConverter.ToSingle(source, 0x33F8);
                    entry.Coordinate         = new Coordinate(entry.X, entry.Z, entry.Y);
                    break;

                default:
                    entry.Name            = MemoryHandler.Instance.GetStringFromBytes(source, 48);
                    entry.ID              = BitConverter.ToUInt32(source, 0x74);
                    entry.NPCID1          = BitConverter.ToUInt32(source, 0x7C);
                    entry.NPCID2          = BitConverter.ToUInt32(source, 0x80);
                    entry.OwnerID         = BitConverter.ToUInt32(source, 0x84);
                    entry.Type            = (Actor.Type)source[0x8A];
                    entry.TargetType      = (Actor.TargetType)source[0x8C];
                    entry.GatheringStatus = source[0x8F];
                    entry.Distance        = source[0x91];
                    var defaultBaseOffset = MemoryHandler.Instance.ProcessModel.IsWin64 ? 0x10 : 0;
                    entry.X                  = BitConverter.ToSingle(source, 0xA0 + defaultBaseOffset);
                    entry.Z                  = BitConverter.ToSingle(source, 0xA4 + defaultBaseOffset);
                    entry.Y                  = BitConverter.ToSingle(source, 0xA8 + defaultBaseOffset);
                    entry.Heading            = BitConverter.ToSingle(source, 0xB0 + defaultBaseOffset);
                    entry.HitBoxRadius       = BitConverter.ToSingle(source, 0xC0 + defaultBaseOffset);
                    entry.Fate               = BitConverter.ToUInt32(source, 0xE4 + defaultBaseOffset); // ??
                    entry.GatheringInvisible = source[0x11C];                                           // ??
                    entry.ModelID            = BitConverter.ToUInt32(source, 0x174);
                    entry.ActionStatus       = (Actor.ActionStatus)source[0x17C];
                    // 0x17D - 0 = Green name, 4 = non-agro (yellow name)
                    entry.IsGM        = BitConverter.ToBoolean(source, 0x183);                         // ?
                    entry.Icon        = (Actor.Icon)source[0x18C];
                    entry.Status      = (Actor.Status)source[0x17E];                                   //0x18E];
                    entry.ClaimedByID = BitConverter.ToUInt32(source, 0x180);                          // 0x1A0);
                    targetID          = BitConverter.ToUInt32(source, 0x188);                          // 0x1A8);
                    pcTargetID        = BitConverter.ToUInt32(source, 0x938);                          // 0xAA8);
                    var defaultStatOffset = MemoryHandler.Instance.ProcessModel.IsWin64 ? 0x230 : 0;
                    entry.Job              = (Actor.Job)source[0x14C0 + defaultStatOffset];            // 0x17C0];
                    entry.Level            = source[0x14C1 + defaultStatOffset];                       // 0x17C1];
                    entry.GrandCompany     = source[0x14C3 + defaultStatOffset];                       // 0x17C3];
                    entry.GrandCompanyRank = source[0x14C4 + defaultStatOffset];                       //0x17C4];
                    entry.Title            = source[0x1546 + defaultStatOffset];                       //0x17C6];
                    entry.HPCurrent        = BitConverter.ToInt32(source, 0x14C8 + defaultStatOffset); // 0x17C8);
                    entry.HPMax            = BitConverter.ToInt32(source, 0x14CC + defaultStatOffset); // 0x17CC);
                    entry.MPCurrent        = BitConverter.ToInt32(source, 0x14D0 + defaultStatOffset); // 0x17D0);
                    entry.MPMax            = BitConverter.ToInt32(source, 0x14D4 + defaultStatOffset); // 0x17D4);
                    entry.TPCurrent        = BitConverter.ToInt16(source, 0x14D8 + defaultStatOffset); // 0x17D8);
                    entry.TPMax            = 1000;
                    entry.GPCurrent        = BitConverter.ToInt16(source, 0x14DA + defaultStatOffset); // 0x17DA);
                    entry.GPMax            = BitConverter.ToInt16(source, 0x14DC + defaultStatOffset); // 0x17DC);
                    entry.CPCurrent        = BitConverter.ToInt16(source, 0x14DE + defaultStatOffset); // 0x17DE);
                    entry.CPMax            = BitConverter.ToInt16(source, 0x14E0 + defaultStatOffset); // 0x17E0);
                    entry.Race             = source[0x2808];                                           // ??
                    entry.Sex              = (Actor.Sex)source[0x2809];                                //?
                    entry.IsCasting        = BitConverter.ToBoolean(source, 0x2A30);                   // 0x2C90);
                    entry.CastingID        = BitConverter.ToInt16(source, 0x2A34);                     // 0x2C94);
                    entry.CastingTargetID  = BitConverter.ToUInt32(source, 0x2A40);                    // 0x2CA0);
                    entry.CastingProgress  = BitConverter.ToSingle(source, 0x2A64);                    // 0x2CC4);
                    entry.CastingTime      = BitConverter.ToSingle(source, 0x2A68);                    // 0x2DA8);
                    entry.Coordinate       = new Coordinate(entry.X, entry.Z, entry.Y);
                    break;
                }
                if (targetID > 0)
                {
                    entry.TargetID = (int)targetID;
                }
                else
                {
                    if (pcTargetID > 0)
                    {
                        entry.TargetID = (int)pcTargetID;
                    }
                }
                if (entry.CastingTargetID == 3758096384)
                {
                    entry.CastingTargetID = 0;
                }
                entry.MapIndex = 0;
                var limit = 60;
                switch (entry.Type)
                {
                case Actor.Type.PC:
                    limit = 30;
                    break;
                }
                entry.StatusEntries = new List <StatusEntry>();
                const int statusSize     = 12;
                var       statusesSource = new byte[limit * statusSize];
                switch (Settings.Default.GameLanguage)
                {
                case "Chinese":
                    Buffer.BlockCopy(source, 0x3168, statusesSource, 0, limit * 12);
                    break;

                default:
                    var defaultStatusEffectOffset = MemoryHandler.Instance.ProcessModel.IsWin64 ? 0x3740 : 0x2878;
                    Buffer.BlockCopy(source, defaultStatusEffectOffset, statusesSource, 0, limit * 12);
                    break;
                }
                for (var i = 0; i < limit; i++)
                {
                    var statusSource = new byte[statusSize];
                    Buffer.BlockCopy(statusesSource, i * statusSize, statusSource, 0, statusSize);
                    var statusEntry = new StatusEntry
                    {
                        TargetEntity = entry,
                        TargetName   = entry.Name,
                        StatusID     = BitConverter.ToInt16(statusSource, 0x0),
                        Stacks       = statusSource[0x2],
                        Duration     = BitConverter.ToSingle(statusSource, 0x4),
                        CasterID     = BitConverter.ToUInt32(statusSource, 0x8)
                    };
                    try
                    {
                        var pc      = PCWorkerDelegate.GetNPCEntity(statusEntry.CasterID);
                        var npc     = NPCWorkerDelegate.GetNPCEntity(statusEntry.CasterID);
                        var monster = MonsterWorkerDelegate.GetNPCEntity(statusEntry.CasterID);
                        statusEntry.SourceEntity = (pc ?? npc) ?? monster;
                    }
                    catch (Exception ex)
                    {
                    }
                    try
                    {
                        var statusInfo = StatusEffectHelper.StatusInfo(statusEntry.StatusID);
                        statusEntry.IsCompanyAction = statusInfo.CompanyAction;
                        var statusKey = statusInfo.Name.English;
                        switch (Settings.Default.GameLanguage)
                        {
                        case "French":
                            statusKey = statusInfo.Name.French;
                            break;

                        case "Japanese":
                            statusKey = statusInfo.Name.Japanese;
                            break;

                        case "German":
                            statusKey = statusInfo.Name.German;
                            break;

                        case "Chinese":
                            statusKey = statusInfo.Name.Chinese;
                            break;
                        }
                        statusEntry.StatusName = statusKey;
                    }
                    catch (Exception ex)
                    {
                        statusEntry.StatusName = "UNKNOWN";
                    }
                    if (statusEntry.IsValid())
                    {
                        entry.StatusEntries.Add(statusEntry);
                    }
                }
            }
            catch (Exception ex)
            {
            }
            CleanXPValue(ref entry);

            if (isCurrentUser)
            {
                PCWorkerDelegate.CurrentUser = entry;
            }
            entry.CurrentUser = PCWorkerDelegate.CurrentUser;
            return(entry);
        }
Exemple #5
0
        public static PartyEntity ResolvePartyMemberFromBytes(byte[] source, ActorEntity actorEntity = null)
        {
            if (actorEntity != null)
            {
                var entry = new PartyEntity
                {
                    X             = actorEntity.X,
                    Y             = actorEntity.Y,
                    Z             = actorEntity.Z,
                    Coordinate    = actorEntity.Coordinate,
                    ID            = actorEntity.ID,
                    Name          = actorEntity.Name,
                    Job           = actorEntity.Job,
                    Level         = actorEntity.Level,
                    HPCurrent     = actorEntity.HPCurrent,
                    HPMax         = actorEntity.HPMax,
                    MPCurrent     = actorEntity.MPCurrent,
                    MPMax         = actorEntity.MPMax,
                    StatusEntries = actorEntity.StatusEntries,
                };
                CleanXPValue(ref entry);
                return(entry);
            }
            else
            {
                var entry = new PartyEntity();
                try
                {
                    switch (Settings.Default.GameLanguage)
                    {
                    case "Chinese":
                    default:
                        entry.X          = BitConverter.ToSingle(source, 0x0);
                        entry.Z          = BitConverter.ToSingle(source, 0x4);
                        entry.Y          = BitConverter.ToSingle(source, 0x8);
                        entry.Coordinate = new Coordinate(entry.X, entry.Z, entry.Z);
                        entry.ID         = BitConverter.ToUInt32(source, 0x10);
                        entry.Name       = MemoryHandler.Instance.GetStringFromBytes(source, 0x20);
                        entry.Job        = (Actor.Job)source[0x61];
                        entry.Level      = source[0x63];
                        entry.HPCurrent  = BitConverter.ToInt32(source, 0x68);
                        entry.HPMax      = BitConverter.ToInt32(source, 0x6C);
                        entry.MPCurrent  = BitConverter.ToInt16(source, 0x70);
                        entry.MPMax      = BitConverter.ToInt16(source, 0x72);
                        break;
                    }
                    const int limit = 15;
                    entry.StatusEntries = new List <StatusEntry>();
                    const int statusSize     = 12;
                    var       statusesSource = new byte[limit * statusSize];
                    switch (Settings.Default.GameLanguage)
                    {
                    case "Chinese":
                    default:
                        var defaultStatusEffectOffset = MemoryHandler.Instance.ProcessModel.IsWin64 ? 0x88 : 0x80;
                        Buffer.BlockCopy(source, defaultStatusEffectOffset, statusesSource, 0, limit * 12);
                        break;
                    }
                    for (var i = 0; i < limit; i++)
                    {
                        var statusSource = new byte[statusSize];
                        Buffer.BlockCopy(statusesSource, i * statusSize, statusSource, 0, statusSize);
                        var statusEntry = new StatusEntry
                        {
                            TargetName = entry.Name,
                            StatusID   = BitConverter.ToInt16(statusSource, 0x0),
                            Stacks     = statusSource[0x2],
                            Duration   = BitConverter.ToSingle(statusSource, 0x4),
                            CasterID   = BitConverter.ToUInt32(statusSource, 0x8)
                        };
                        try
                        {
                            var pc      = PCWorkerDelegate.GetNPCEntity(statusEntry.CasterID);
                            var npc     = NPCWorkerDelegate.GetNPCEntity(statusEntry.CasterID);
                            var monster = MonsterWorkerDelegate.GetNPCEntity(statusEntry.CasterID);
                            statusEntry.SourceEntity = (pc ?? npc) ?? monster;
                        }
                        catch (Exception ex)
                        {
                        }
                        try
                        {
                            if (statusEntry.StatusID > 0)
                            {
                                var statusInfo = StatusEffectHelper.StatusInfo(statusEntry.StatusID);
                                statusEntry.IsCompanyAction = statusInfo.CompanyAction;
                                var statusKey = statusInfo.Name.English;
                                switch (Settings.Default.GameLanguage)
                                {
                                case "French":
                                    statusKey = statusInfo.Name.French;
                                    break;

                                case "Japanese":
                                    statusKey = statusInfo.Name.Japanese;
                                    break;

                                case "German":
                                    statusKey = statusInfo.Name.German;
                                    break;

                                case "Chinese":
                                    statusKey = statusInfo.Name.Chinese;
                                    break;
                                }
                                statusEntry.StatusName = statusKey;
                            }
                        }
                        catch (Exception ex)
                        {
                            statusEntry.StatusName = "UNKNOWN";
                        }
                        if (statusEntry.IsValid())
                        {
                            entry.StatusEntries.Add(statusEntry);
                        }
                    }
                }
                catch (Exception ex)
                {
                }
                CleanXPValue(ref entry);
                return(entry);
            }
        }