Beispiel #1
0
        public int GetInt32(IntPtr address, long offset = 0)
        {
            var value = new byte[4];

            Peek(new IntPtr(address.ToInt64() + offset), value);
            return(BitConverter.TryToInt32(value, 0));
        }
Beispiel #2
0
 public long GetPlatformIntFromBytes(byte[] source, int index = 0)
 {
     if (ProcessModel.IsWin64)
     {
         return(BitConverter.TryToInt64(source, index));
     }
     return(BitConverter.TryToInt32(source, index));
 }
Beispiel #3
0
        public IntPtr ReadPointer(IntPtr address, long offset = 0)
        {
            if (ProcessModel.IsWin64)
            {
                var win64 = new byte[8];
                Peek(new IntPtr(address.ToInt64() + offset), win64);
                return(new IntPtr(BitConverter.TryToInt64(win64, 0)));
            }
            var win32 = new byte[4];

            Peek(new IntPtr(address.ToInt64() + offset), win32);
            return(IntPtr.Add(IntPtr.Zero, BitConverter.TryToInt32(win32, 0)));
        }
Beispiel #4
0
        public static ActorReadResult GetActors()
        {
            var result = new ActorReadResult();

            if (!Scanner.Instance.Locations.ContainsKey("CHARMAP"))
            {
                return(result);
            }

            try
            {
                #region Ensure Target

                var targetAddress = IntPtr.Zero;

                #endregion

                var endianSize = MemoryHandler.Instance.ProcessModel.IsWin64 ? 8 : 4;

                var limit = MemoryHandler.Instance.Structures.ActorInfo.Size;

                var characterAddressMap = MemoryHandler.Instance.GetByteArray(Scanner.Instance.Locations["CHARMAP"], endianSize * limit);
                var uniqueAddresses     = new Dictionary <IntPtr, IntPtr>();
                var firstAddress        = IntPtr.Zero;

                var firstTime = true;

                for (var i = 0; i < limit; i++)
                {
                    IntPtr characterAddress;

                    if (MemoryHandler.Instance.ProcessModel.IsWin64)
                    {
                        characterAddress = new IntPtr(BitConverter.TryToInt64(characterAddressMap, i * endianSize));
                    }
                    else
                    {
                        characterAddress = new IntPtr(BitConverter.TryToInt32(characterAddressMap, i * endianSize));
                    }
                    if (characterAddress == IntPtr.Zero)
                    {
                        continue;
                    }

                    if (firstTime)
                    {
                        firstAddress = characterAddress;
                        firstTime    = false;
                    }
                    uniqueAddresses[characterAddress] = characterAddress;
                }

                #region ActorEntity Handlers

                result.RemovedMonster = MonsterWorkerDelegate.EntitiesDictionary.Keys.ToDictionary(key => key);
                result.RemovedNPC     = NPCWorkerDelegate.EntitiesDictionary.Keys.ToDictionary(key => key);
                result.RemovedPC      = PCWorkerDelegate.EntitiesDictionary.Keys.ToDictionary(key => key);

                foreach (var kvp in uniqueAddresses)
                {
                    try
                    {
                        var source = MemoryHandler.Instance.GetByteArray(new IntPtr(kvp.Value.ToInt64()), 0x23F0);
                        //var source = MemoryHandler.Instance.GetByteArray(characterAddress, 0x3F40);

                        var         ID       = BitConverter.TryToUInt32(source, MemoryHandler.Instance.Structures.ActorEntity.ID);
                        var         NPCID2   = BitConverter.TryToUInt32(source, MemoryHandler.Instance.Structures.ActorEntity.NPCID2);
                        var         Type     = (Actor.Type)source[MemoryHandler.Instance.Structures.ActorEntity.Type];
                        ActorEntity existing = null;
                        var         newEntry = false;

                        switch (Type)
                        {
                        case Actor.Type.Monster:
                            if (result.RemovedMonster.ContainsKey(ID))
                            {
                                result.RemovedMonster.Remove(ID);
                                existing = MonsterWorkerDelegate.GetEntity(ID);
                            }
                            else
                            {
                                result.NewMonster.Add(ID);
                                newEntry = true;
                            }
                            break;

                        case Actor.Type.PC:
                            if (result.RemovedPC.ContainsKey(ID))
                            {
                                result.RemovedPC.Remove(ID);
                                existing = PCWorkerDelegate.GetEntity(ID);
                            }
                            else
                            {
                                result.NewPC.Add(ID);
                                newEntry = true;
                            }
                            break;

                        case Actor.Type.NPC:
                        case Actor.Type.Aetheryte:
                        case Actor.Type.EObj:
                            if (result.RemovedNPC.ContainsKey(NPCID2))
                            {
                                result.RemovedNPC.Remove(NPCID2);
                                existing = NPCWorkerDelegate.GetEntity(NPCID2);
                            }
                            else
                            {
                                result.NewNPC.Add(NPCID2);
                                newEntry = true;
                            }
                            break;

                        default:
                            if (result.RemovedNPC.ContainsKey(ID))
                            {
                                result.RemovedNPC.Remove(ID);
                                existing = NPCWorkerDelegate.GetEntity(ID);
                            }
                            else
                            {
                                result.NewNPC.Add(ID);
                                newEntry = true;
                            }
                            break;
                        }

                        var isFirstEntry = kvp.Value.ToInt64() == firstAddress.ToInt64();

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

                        #region Ensure Map & Zone

                        EnsureMapAndZone(entry);

                        #endregion

                        if (isFirstEntry)
                        {
                            if (targetAddress.ToInt64() > 0)
                            {
                                var targetInfoSource = MemoryHandler.Instance.GetByteArray(targetAddress, 128);
                                entry.TargetID = (int)BitConverter.TryToUInt32(targetInfoSource, MemoryHandler.Instance.Structures.ActorEntity.ID);
                            }
                        }
                        if (!entry.IsValid)
                        {
                            result.NewMonster.Remove(entry.ID);
                            result.NewMonster.Remove(entry.NPCID2);
                            result.NewNPC.Remove(entry.ID);
                            result.NewNPC.Remove(entry.NPCID2);
                            result.NewPC.Remove(entry.ID);
                            result.NewPC.Remove(entry.NPCID2);
                            continue;
                        }
                        if (existing != null)
                        {
                            continue;
                        }

                        if (newEntry)
                        {
                            switch (entry.Type)
                            {
                            case Actor.Type.Monster:
                                MonsterWorkerDelegate.EnsureEntity(entry.ID, entry);
                                break;

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

                            case Actor.Type.Aetheryte:
                            case Actor.Type.EObj:
                            case Actor.Type.NPC:
                                NPCWorkerDelegate.EnsureEntity(entry.NPCID2, entry);
                                break;

                            default:
                                NPCWorkerDelegate.EnsureEntity(entry.ID, entry);
                                break;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MemoryHandler.Instance.RaiseException(Logger, ex, true);
                    }
                }

                try
                {
                    // REMOVE OLD MONSTERS FROM LIVE CURRENT DICTIONARY
                    foreach (var kvp in result.RemovedMonster)
                    {
                        MonsterWorkerDelegate.RemoveEntity(kvp.Key);
                    }

                    // REMOVE OLD NPC'S FROM LIVE CURRENT DICTIONARY
                    foreach (var kvp in result.RemovedNPC)
                    {
                        NPCWorkerDelegate.RemoveEntity(kvp.Key);
                    }

                    // REMOVE OLD PC'S FROM LIVE CURRENT DICTIONARY
                    foreach (var kvp in result.RemovedPC)
                    {
                        PCWorkerDelegate.RemoveEntity(kvp.Key);
                    }
                }
                catch (Exception ex)
                {
                    MemoryHandler.Instance.RaiseException(Logger, ex, true);
                }

                MemoryHandler.Instance.ScanCount++;

                #endregion
            }
            catch (Exception ex)
            {
                MemoryHandler.Instance.RaiseException(Logger, ex, true);
            }

            return(result);
        }
Beispiel #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,
                    UUID          = actorEntity.UUID,
                    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 defaultStatusEffectOffset = MemoryHandler.Instance.Structures.PartyEntity.DefaultStatusEffectOffset;
                var entry = new PartyEntity();
                try
                {
                    entry.X          = BitConverter.TryToSingle(source, MemoryHandler.Instance.Structures.PartyEntity.X);
                    entry.Z          = BitConverter.TryToSingle(source, MemoryHandler.Instance.Structures.PartyEntity.Z);
                    entry.Y          = BitConverter.TryToSingle(source, MemoryHandler.Instance.Structures.PartyEntity.Y);
                    entry.Coordinate = new Coordinate(entry.X, entry.Z, entry.Z);
                    entry.ID         = BitConverter.TryToUInt32(source, MemoryHandler.Instance.Structures.PartyEntity.ID);
                    entry.UUID       = Guid.NewGuid()
                                       .ToString();
                    entry.Name      = MemoryHandler.Instance.GetStringFromBytes(source, MemoryHandler.Instance.Structures.PartyEntity.Name);
                    entry.JobID     = source[MemoryHandler.Instance.Structures.PartyEntity.Job];
                    entry.Job       = (Actor.Job)entry.JobID;
                    entry.Level     = source[MemoryHandler.Instance.Structures.PartyEntity.Level];
                    entry.HPCurrent = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.PartyEntity.HPCurrent);
                    entry.HPMax     = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.PartyEntity.HPMax);
                    entry.MPCurrent = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PartyEntity.MPCurrent);
                    entry.MPMax     = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PartyEntity.MPMax);
                    const int limit = 15;
                    entry.StatusEntries = new List <StatusEntry>();
                    const int statusSize     = 12;
                    var       statusesSource = new byte[limit * statusSize];

                    Buffer.BlockCopy(source, defaultStatusEffectOffset, statusesSource, 0, limit * 12);
                    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.TryToInt16(statusSource, MemoryHandler.Instance.Structures.StatusEntry.StatusID),
                            Stacks     = statusSource[MemoryHandler.Instance.Structures.StatusEntry.Stacks],
                            Duration   = BitConverter.TryToSingle(statusSource, MemoryHandler.Instance.Structures.StatusEntry.Duration),
                            CasterID   = BitConverter.TryToUInt32(statusSource, MemoryHandler.Instance.Structures.StatusEntry.CasterID)
                        };
                        try
                        {
                            var pc      = PCWorkerDelegate.GetEntity(statusEntry.CasterID);
                            var npc     = NPCWorkerDelegate.GetEntity(statusEntry.CasterID);
                            var monster = MonsterWorkerDelegate.GetEntity(statusEntry.CasterID);
                            statusEntry.SourceEntity = (pc ?? npc) ?? monster;
                        }
                        catch (Exception ex)
                        {
                            MemoryHandler.Instance.RaiseException(Logger, ex, true);
                        }
                        try
                        {
                            if (statusEntry.StatusID > 0)
                            {
                                var statusInfo = StatusEffectHelper.StatusInfo((uint)statusEntry.StatusID);
                                statusEntry.IsCompanyAction = statusInfo.CompanyAction;
                                var statusKey = statusInfo.Name.English;
                                switch (MemoryHandler.Instance.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;

                                case "Korean":
                                    statusKey = statusInfo.Name.Korean;
                                    break;
                                }
                                statusEntry.StatusName = statusKey;
                            }
                        }
                        catch (Exception)
                        {
                            statusEntry.StatusName = "UNKNOWN";
                        }
                        if (statusEntry.IsValid())
                        {
                            entry.StatusEntries.Add(statusEntry);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MemoryHandler.Instance.RaiseException(Logger, ex, true);
                }
                CleanXPValue(ref entry);
                return(entry);
            }
        }
        public static PlayerEntity ResolvePlayerFromBytes(byte[] source)
        {
            var entry = new PlayerEntity();

            try
            {
                entry.Name = MemoryHandler.Instance.GetStringFromBytes(source, 1);

                switch (MemoryHandler.Instance.GameLanguage)
                {
                default:
                    entry.JobID = source[MemoryHandler.Instance.Structures.PlayerEntity.JobID];
                    entry.Job   = (Actor.Job)entry.JobID;

                    #region Job Levels

                    entry.PGL = source[MemoryHandler.Instance.Structures.PlayerEntity.PGL];
                    entry.GLD = source[MemoryHandler.Instance.Structures.PlayerEntity.GLD];
                    entry.MRD = source[MemoryHandler.Instance.Structures.PlayerEntity.MRD];
                    entry.ARC = source[MemoryHandler.Instance.Structures.PlayerEntity.ARC];
                    entry.LNC = source[MemoryHandler.Instance.Structures.PlayerEntity.LNC];
                    entry.THM = source[MemoryHandler.Instance.Structures.PlayerEntity.THM];
                    entry.CNJ = source[MemoryHandler.Instance.Structures.PlayerEntity.CNJ];

                    entry.CPT = source[MemoryHandler.Instance.Structures.PlayerEntity.CPT];
                    entry.BSM = source[MemoryHandler.Instance.Structures.PlayerEntity.BSM];
                    entry.ARM = source[MemoryHandler.Instance.Structures.PlayerEntity.ARM];
                    entry.GSM = source[MemoryHandler.Instance.Structures.PlayerEntity.GSM];
                    entry.LTW = source[MemoryHandler.Instance.Structures.PlayerEntity.LTW];
                    entry.WVR = source[MemoryHandler.Instance.Structures.PlayerEntity.WVR];
                    entry.ALC = source[MemoryHandler.Instance.Structures.PlayerEntity.ALC];
                    entry.CUL = source[MemoryHandler.Instance.Structures.PlayerEntity.CUL];

                    entry.MIN = source[MemoryHandler.Instance.Structures.PlayerEntity.MIN];
                    entry.BTN = source[MemoryHandler.Instance.Structures.PlayerEntity.BTN];
                    entry.FSH = source[MemoryHandler.Instance.Structures.PlayerEntity.FSH];

                    entry.ACN = source[MemoryHandler.Instance.Structures.PlayerEntity.ACN];
                    entry.ROG = source[MemoryHandler.Instance.Structures.PlayerEntity.ROG];

                    entry.MCH = source[MemoryHandler.Instance.Structures.PlayerEntity.MCH];
                    entry.DRK = source[MemoryHandler.Instance.Structures.PlayerEntity.DRK];
                    entry.AST = source[MemoryHandler.Instance.Structures.PlayerEntity.AST];

                    entry.SAM = source[MemoryHandler.Instance.Structures.PlayerEntity.SAM];
                    entry.RDM = source[MemoryHandler.Instance.Structures.PlayerEntity.RDM];

                    #endregion

                    #region Current Experience

                    entry.PGL_CurrentEXP = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.PlayerEntity.PGL_CurrentEXP);
                    entry.GLD_CurrentEXP = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.PlayerEntity.GLD_CurrentEXP);
                    entry.MRD_CurrentEXP = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.PlayerEntity.MRD_CurrentEXP);
                    entry.ARC_CurrentEXP = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.PlayerEntity.ARC_CurrentEXP);
                    entry.LNC_CurrentEXP = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.PlayerEntity.LNC_CurrentEXP);
                    entry.THM_CurrentEXP = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.PlayerEntity.THM_CurrentEXP);
                    entry.CNJ_CurrentEXP = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.PlayerEntity.CNJ_CurrentEXP);

                    entry.CPT_CurrentEXP = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.PlayerEntity.CPT_CurrentEXP);
                    entry.BSM_CurrentEXP = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.PlayerEntity.BSM_CurrentEXP);
                    entry.ARM_CurrentEXP = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.PlayerEntity.ARM_CurrentEXP);
                    entry.GSM_CurrentEXP = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.PlayerEntity.GSM_CurrentEXP);
                    entry.LTW_CurrentEXP = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.PlayerEntity.LTW_CurrentEXP);
                    entry.WVR_CurrentEXP = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.PlayerEntity.WVR_CurrentEXP);
                    entry.ALC_CurrentEXP = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.PlayerEntity.ALC_CurrentEXP);
                    entry.CUL_CurrentEXP = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.PlayerEntity.CUL_CurrentEXP);

                    entry.MIN_CurrentEXP = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.PlayerEntity.MIN_CurrentEXP);
                    entry.BTN_CurrentEXP = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.PlayerEntity.BTN_CurrentEXP);
                    entry.FSH_CurrentEXP = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.PlayerEntity.FSH_CurrentEXP);

                    entry.ACN_CurrentEXP = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.PlayerEntity.ACN_CurrentEXP);
                    entry.ROG_CurrentEXP = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.PlayerEntity.ROG_CurrentEXP);

                    entry.MCH_CurrentEXP = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.PlayerEntity.MCH_CurrentEXP);
                    entry.DRK_CurrentEXP = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.PlayerEntity.DRK_CurrentEXP);
                    entry.AST_CurrentEXP = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.PlayerEntity.AST_CurrentEXP);

                    entry.SAM_CurrentEXP = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.PlayerEntity.SAM_CurrentEXP);
                    entry.RDM_CurrentEXP = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.PlayerEntity.RDM_CurrentEXP);

                    #endregion

                    #region Base Stats

                    entry.BaseStrength     = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.BaseStrength);
                    entry.BaseDexterity    = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.BaseDexterity);
                    entry.BaseVitality     = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.BaseVitality);
                    entry.BaseIntelligence = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.BaseIntelligence);
                    entry.BaseMind         = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.BaseMind);
                    entry.BasePiety        = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.BasePiety);

                    #endregion

                    #region Base Stats (base+gear+bonus)

                    entry.Strength     = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.Strength);
                    entry.Dexterity    = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.Dexterity);
                    entry.Vitality     = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.Vitality);
                    entry.Intelligence = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.Intelligence);
                    entry.Mind         = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.Mind);
                    entry.Piety        = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.Piety);

                    #endregion

                    #region Basic Info

                    entry.HPMax = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.HPMax);
                    entry.MPMax = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.MPMax);
                    entry.TPMax = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.TPMax);
                    entry.GPMax = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.GPMax);
                    entry.CPMax = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.CPMax);

                    #endregion

                    #region Offensive Properties

                    entry.DirectHit       = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.DirectHit);
                    entry.CriticalHitRate = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.CriticalHitRate);
                    entry.Determination   = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.Determination);

                    #endregion

                    #region Defensive Properties

                    entry.Tenacity     = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.Tenacity);
                    entry.Defense      = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.Defense);
                    entry.MagicDefense = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.MagicDefense);

                    #endregion

                    #region Phyiscal Properties

                    entry.AttackPower = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.AttackPower);
                    entry.SkillSpeed  = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.SkillSpeed);

                    #endregion

                    #region Mental Properties

                    entry.SpellSpeed          = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.SpellSpeed);
                    entry.AttackMagicPotency  = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.AttackMagicPotency);
                    entry.HealingMagicPotency = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.HealingMagicPotency);

                    #endregion

                    #region Elemental Resistances

                    entry.FireResistance      = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.FireResistance);
                    entry.IceResistance       = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.IceResistance);
                    entry.WindResistance      = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.WindResistance);
                    entry.EarthResistance     = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.EarthResistance);
                    entry.LightningResistance = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.LightningResistance);
                    entry.WaterResistance     = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.WaterResistance);

                    #endregion

                    #region Physical Resistances

                    entry.SlashingResistance = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.SlashingResistance);
                    entry.PiercingResistance = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.PiercingResistance);
                    entry.BluntResistance    = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.BluntResistance);

                    #endregion

                    #region Crafting

                    entry.Craftmanship = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.Craftmanship);
                    entry.Control      = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.Control);

                    #endregion

                    #region Gathering

                    entry.Gathering  = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.Gathering);
                    entry.Perception = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PlayerEntity.Perception);

                    #endregion

                    break;
                }
            }
            catch (Exception ex)
            {
                MemoryHandler.Instance.RaiseException(Logger, ex, true);
            }
            return(entry);
        }
Beispiel #7
0
        public static ActorEntity ResolveActorFromBytes(byte[] source, bool isCurrentUser = false, ActorEntity entry = null)
        {
            entry = entry ?? new ActorEntity();
            var defaultBaseOffset         = MemoryHandler.Instance.Structures.ActorEntity.DefaultBaseOffset;
            var defaultStatOffset         = MemoryHandler.Instance.Structures.ActorEntity.DefaultStatOffset;
            var defaultStatusEffectOffset = MemoryHandler.Instance.Structures.ActorEntity.DefaultStatusEffectOffset;

            try
            {
                entry.MapTerritory = 0;
                entry.MapIndex     = 0;
                entry.MapID        = 0;
                entry.TargetID     = 0;
                entry.Name         = MemoryHandler.Instance.GetStringFromBytes(source, MemoryHandler.Instance.Structures.ActorEntity.Name);
                entry.ID           = BitConverter.TryToUInt32(source, MemoryHandler.Instance.Structures.ActorEntity.ID);
                entry.UUID         = string.IsNullOrEmpty(entry.UUID) ? Guid.NewGuid()
                                     .ToString() : entry.UUID;
                entry.NPCID1       = BitConverter.TryToUInt32(source, MemoryHandler.Instance.Structures.ActorEntity.NPCID1);
                entry.NPCID2       = BitConverter.TryToUInt32(source, MemoryHandler.Instance.Structures.ActorEntity.NPCID2);
                entry.OwnerID      = BitConverter.TryToUInt32(source, MemoryHandler.Instance.Structures.ActorEntity.OwnerID);
                entry.TypeID       = source[MemoryHandler.Instance.Structures.ActorEntity.Type];
                entry.Type         = (Actor.Type)entry.TypeID;
                entry.TargetTypeID = source[MemoryHandler.Instance.Structures.ActorEntity.TargetType];
                entry.TargetType   = (Actor.TargetType)entry.TargetTypeID;

                entry.GatheringStatus = source[MemoryHandler.Instance.Structures.ActorEntity.GatheringStatus];
                entry.Distance        = source[MemoryHandler.Instance.Structures.ActorEntity.Distance];

                entry.X                  = BitConverter.TryToSingle(source, MemoryHandler.Instance.Structures.ActorEntity.X + defaultBaseOffset);
                entry.Z                  = BitConverter.TryToSingle(source, MemoryHandler.Instance.Structures.ActorEntity.Z + defaultBaseOffset);
                entry.Y                  = BitConverter.TryToSingle(source, MemoryHandler.Instance.Structures.ActorEntity.Y + defaultBaseOffset);
                entry.Heading            = BitConverter.TryToSingle(source, MemoryHandler.Instance.Structures.ActorEntity.Heading + defaultBaseOffset);
                entry.HitBoxRadius       = BitConverter.TryToSingle(source, MemoryHandler.Instance.Structures.ActorEntity.HitBoxRadius + defaultBaseOffset);
                entry.Fate               = BitConverter.TryToUInt32(source, MemoryHandler.Instance.Structures.ActorEntity.Fate + defaultBaseOffset); // ??
                entry.GatheringInvisible = source[MemoryHandler.Instance.Structures.ActorEntity.GatheringInvisible];                                 // ??
                entry.ModelID            = BitConverter.TryToUInt32(source, MemoryHandler.Instance.Structures.ActorEntity.ModelID);
                entry.ActionStatusID     = source[MemoryHandler.Instance.Structures.ActorEntity.ActionStatus];
                entry.ActionStatus       = (Actor.ActionStatus)entry.ActionStatusID;

                // 0x17D - 0 = Green name, 4 = non-agro (yellow name)
                entry.IsGM   = BitConverter.TryToBoolean(source, MemoryHandler.Instance.Structures.ActorEntity.IsGM); // ?
                entry.IconID = source[MemoryHandler.Instance.Structures.ActorEntity.Icon];
                entry.Icon   = (Actor.Icon)entry.IconID;

                entry.StatusID = source[MemoryHandler.Instance.Structures.ActorEntity.Status];
                entry.Status   = (Actor.Status)entry.StatusID;

                entry.ClaimedByID = BitConverter.TryToUInt32(source, MemoryHandler.Instance.Structures.ActorEntity.ClaimedByID);
                var targetID   = BitConverter.TryToUInt32(source, MemoryHandler.Instance.Structures.ActorEntity.TargetID);
                var pcTargetID = targetID;

                entry.JobID            = source[MemoryHandler.Instance.Structures.ActorEntity.Job + defaultStatOffset];
                entry.Job              = (Actor.Job)entry.JobID;
                entry.Level            = source[MemoryHandler.Instance.Structures.ActorEntity.Level + defaultStatOffset];
                entry.GrandCompany     = source[MemoryHandler.Instance.Structures.ActorEntity.GrandCompany + defaultStatOffset];
                entry.GrandCompanyRank = source[MemoryHandler.Instance.Structures.ActorEntity.GrandCompanyRank + defaultStatOffset];
                entry.Title            = source[MemoryHandler.Instance.Structures.ActorEntity.Title + defaultStatOffset];
                entry.HPCurrent        = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.ActorEntity.HPCurrent + defaultStatOffset);
                entry.HPMax            = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.ActorEntity.HPMax + defaultStatOffset);
                entry.MPCurrent        = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.ActorEntity.MPCurrent + defaultStatOffset);
                entry.MPMax            = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.ActorEntity.MPMax + defaultStatOffset);
                entry.TPCurrent        = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.ActorEntity.TPCurrent + defaultStatOffset);
                entry.TPMax            = 1000;
                entry.GPCurrent        = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.ActorEntity.GPCurrent + defaultStatOffset);
                entry.GPMax            = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.ActorEntity.GPMax + defaultStatOffset);
                entry.CPCurrent        = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.ActorEntity.CPCurrent + defaultStatOffset);
                entry.CPMax            = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.ActorEntity.CPMax + defaultStatOffset);
                //entry.Race = source[0x2578]; // ??
                //entry.Sex = (Actor.Sex) source[0x2579]; //?
                entry.CombatFlags     = source[MemoryHandler.Instance.Structures.ActorEntity.CombatFlags];
                entry.DifficultyRank  = source[MemoryHandler.Instance.Structures.ActorEntity.DifficultyRank];
                entry.CastingID       = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.ActorEntity.CastingID);        // 0x2C94);
                entry.CastingTargetID = BitConverter.TryToUInt32(source, MemoryHandler.Instance.Structures.ActorEntity.CastingTargetID); // 0x2CA0);
                entry.CastingProgress = BitConverter.TryToSingle(source, MemoryHandler.Instance.Structures.ActorEntity.CastingProgress); // 0x2CC4);
                entry.CastingTime     = BitConverter.TryToSingle(source, MemoryHandler.Instance.Structures.ActorEntity.CastingTime);     // 0x2DA8);
                entry.Coordinate      = new Coordinate(entry.X, entry.Z, entry.Y);
                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];

                Buffer.BlockCopy(source, defaultStatusEffectOffset, statusesSource, 0, limit * statusSize);
                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.TryToInt16(statusSource, MemoryHandler.Instance.Structures.StatusEntry.StatusID),
                        Stacks       = statusSource[MemoryHandler.Instance.Structures.StatusEntry.Stacks],
                        Duration     = BitConverter.TryToSingle(statusSource, MemoryHandler.Instance.Structures.StatusEntry.Duration),
                        CasterID     = BitConverter.TryToUInt32(statusSource, MemoryHandler.Instance.Structures.StatusEntry.CasterID)
                    };
                    try
                    {
                        var pc      = PCWorkerDelegate.GetEntity(statusEntry.CasterID);
                        var npc     = NPCWorkerDelegate.GetEntity(statusEntry.CasterID);
                        var monster = MonsterWorkerDelegate.GetEntity(statusEntry.CasterID);
                        statusEntry.SourceEntity = (pc ?? npc) ?? monster;
                    }
                    catch (Exception ex)
                    {
                        MemoryHandler.Instance.RaiseException(Logger, ex, true);
                    }
                    try
                    {
                        var statusInfo = StatusEffectHelper.StatusInfo((uint)statusEntry.StatusID);
                        if (statusInfo != null)
                        {
                            statusEntry.IsCompanyAction = statusInfo.CompanyAction;
                            var statusKey = statusInfo.Name.English;
                            switch (MemoryHandler.Instance.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;

                            case "Korean":
                                statusKey = statusInfo.Name.Korean;
                                break;
                            }
                            statusEntry.StatusName = statusKey;
                        }
                    }
                    catch (Exception)
                    {
                        statusEntry.StatusName = "UNKNOWN";
                    }
                    if (statusEntry.IsValid())
                    {
                        entry.StatusEntries.Add(statusEntry);
                    }
                }
            }
            catch (Exception ex)
            {
                MemoryHandler.Instance.RaiseException(Logger, ex, true);
            }
            CleanXPValue(ref entry);

            if (isCurrentUser)
            {
                PCWorkerDelegate.CurrentUser = entry;
            }
            return(entry);
        }