Example #1
0
        public PartyMember ResolvePartyMemberFromBytes(byte[] source, ActorItem actorItem = null)
        {
            this._foundStatuses.Clear();

            if (actorItem != null)
            {
                PartyMember memberFromActorItem = new PartyMember {
                    X            = actorItem.X,
                    Y            = actorItem.Y,
                    Z            = actorItem.Z,
                    Coordinate   = actorItem.Coordinate,
                    ID           = actorItem.ID,
                    UUID         = actorItem.UUID,
                    Name         = actorItem.Name,
                    Job          = actorItem.Job,
                    Level        = actorItem.Level,
                    HPCurrent    = actorItem.HPCurrent,
                    HPMax        = actorItem.HPMax,
                    MPCurrent    = actorItem.MPCurrent,
                    HitBoxRadius = actorItem.HitBoxRadius,
                };
                memberFromActorItem.StatusItems.AddRange(actorItem.StatusItems);
                this.CleanXPValue(ref memberFromActorItem);
                return(memberFromActorItem);
            }

            int         defaultStatusEffectOffset = this._memoryHandler.Structures.PartyMember.DefaultStatusEffectOffset;
            PartyMember entry = new PartyMember();

            try {
                const int limit      = 15;
                int       statusSize = this._memoryHandler.Structures.StatusItem.SourceSize;

                byte[] statusesMap = this._memoryHandler.BufferPool.Rent(statusSize * limit);
                byte[] statusMap   = this._memoryHandler.BufferPool.Rent(statusSize);

                try {
                    entry.X            = SharlayanBitConverter.TryToSingle(source, this._memoryHandler.Structures.PartyMember.X);
                    entry.Z            = SharlayanBitConverter.TryToSingle(source, this._memoryHandler.Structures.PartyMember.Z);
                    entry.Y            = SharlayanBitConverter.TryToSingle(source, this._memoryHandler.Structures.PartyMember.Y);
                    entry.Coordinate   = new Coordinate(entry.X, entry.Z, entry.Z);
                    entry.ID           = SharlayanBitConverter.TryToUInt32(source, this._memoryHandler.Structures.PartyMember.ID);
                    entry.UUID         = Guid.NewGuid().ToString();
                    entry.Name         = this._memoryHandler.GetStringFromBytes(source, this._memoryHandler.Structures.PartyMember.Name);
                    entry.JobID        = source[this._memoryHandler.Structures.PartyMember.Job];
                    entry.Job          = (Actor.Job)entry.JobID;
                    entry.HitBoxRadius = 0.5f;
                    entry.Level        = source[this._memoryHandler.Structures.PartyMember.Level];
                    entry.HPCurrent    = SharlayanBitConverter.TryToInt32(source, this._memoryHandler.Structures.PartyMember.HPCurrent);
                    entry.HPMax        = SharlayanBitConverter.TryToInt32(source, this._memoryHandler.Structures.PartyMember.HPMax);
                    entry.MPCurrent    = SharlayanBitConverter.TryToInt16(source, this._memoryHandler.Structures.PartyMember.MPCurrent);

                    Buffer.BlockCopy(source, defaultStatusEffectOffset, statusesMap, 0, limit * statusSize);
                    for (int i = 0; i < limit; i++)
                    {
                        bool isNewStatus = false;

                        Buffer.BlockCopy(statusesMap, i * statusSize, statusMap, 0, statusSize);

                        short statusID = SharlayanBitConverter.TryToInt16(statusMap, this._memoryHandler.Structures.StatusItem.StatusID);
                        uint  casterID = SharlayanBitConverter.TryToUInt32(statusMap, this._memoryHandler.Structures.StatusItem.CasterID);

                        StatusItem statusEntry = entry.StatusItems.FirstOrDefault(x => x.CasterID == casterID && x.StatusID == statusID);

                        if (statusEntry == null)
                        {
                            statusEntry = new StatusItem();
                            isNewStatus = true;
                        }

                        statusEntry.TargetEntity = null;
                        statusEntry.TargetName   = entry.Name;
                        statusEntry.StatusID     = statusID;
                        statusEntry.Stacks       = statusMap[this._memoryHandler.Structures.StatusItem.Stacks];
                        statusEntry.Duration     = SharlayanBitConverter.TryToSingle(statusMap, this._memoryHandler.Structures.StatusItem.Duration);
                        statusEntry.CasterID     = casterID;

                        this._foundStatuses.Add(statusEntry);

                        try {
                            ActorItem pc      = this._pcWorkerDelegate.GetActorItem(statusEntry.CasterID);
                            ActorItem npc     = this._npcWorkerDelegate.GetActorItem(statusEntry.CasterID);
                            ActorItem monster = this._monsterWorkerDelegate.GetActorItem(statusEntry.CasterID);
                            statusEntry.SourceEntity = (pc ?? npc) ?? monster;
                        }
                        catch (Exception ex) {
                            this._memoryHandler.RaiseException(Logger, ex);
                        }

                        try {
                            if (statusEntry.StatusID > 0)
                            {
                                Models.XIVDatabase.StatusItem statusInfo = StatusEffectLookup.GetStatusInfo((uint)statusEntry.StatusID);
                                statusEntry.IsCompanyAction = statusInfo.CompanyAction;
                                string statusKey = statusInfo.Name.English;
                                switch (this._memoryHandler.Configuration.GameLanguage)
                                {
                                case GameLanguage.French:
                                    statusKey = statusInfo.Name.French;
                                    break;

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

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

                                case GameLanguage.Chinese:
                                    statusKey = statusInfo.Name.Chinese;
                                    break;

                                case GameLanguage.Korean:
                                    statusKey = statusInfo.Name.Korean;
                                    break;
                                }

                                statusEntry.StatusName = statusKey;
                            }
                        }
                        catch (Exception) {
                            statusEntry.StatusName = Constants.UNKNOWN_LOCALIZED_NAME;
                        }

                        if (statusEntry.IsValid())
                        {
                            if (isNewStatus)
                            {
                                entry.StatusItems.Add(statusEntry);
                            }

                            this._foundStatuses.Add(statusEntry);
                        }
                    }
                }
                catch (Exception ex) {
                    this._memoryHandler.RaiseException(Logger, ex);
                }
                finally {
                    this._memoryHandler.BufferPool.Return(statusesMap);
                    this._memoryHandler.BufferPool.Return(statusMap);
                }

                entry.StatusItems.RemoveAll(x => !this._foundStatuses.Contains(x));
            }
            catch (Exception ex) {
                this._memoryHandler.RaiseException(Logger, ex);
            }

            this.CleanXPValue(ref entry);

            return(entry);
        }
Example #2
0
        public ActorItem ResolveActorFromBytes(byte[] source, bool isCurrentUser = false, ActorItem existingActorItem = null)
        {
            this._foundStatuses.Clear();

            ActorItem entry = existingActorItem ?? new ActorItem();

            int defaultBaseOffset         = this._memoryHandler.Structures.ActorItem.DefaultBaseOffset;
            int defaultStatOffset         = this._memoryHandler.Structures.ActorItem.DefaultStatOffset;
            int defaultStatusEffectOffset = this._memoryHandler.Structures.ActorItem.DefaultStatusEffectOffset;

            try {
                entry.MapTerritory = 0;
                entry.MapIndex     = 0;
                entry.MapID        = 0;
                entry.TargetID     = 0;
                entry.Name         = this._memoryHandler.GetStringFromBytes(source, this._memoryHandler.Structures.ActorItem.Name);
                entry.ID           = SharlayanBitConverter.TryToUInt32(source, this._memoryHandler.Structures.ActorItem.ID);
                entry.UUID         = string.IsNullOrEmpty(entry.UUID)
                                 ? Guid.NewGuid().ToString()
                                 : entry.UUID;
                entry.NPCID1  = SharlayanBitConverter.TryToUInt32(source, this._memoryHandler.Structures.ActorItem.NPCID1);
                entry.NPCID2  = SharlayanBitConverter.TryToUInt32(source, this._memoryHandler.Structures.ActorItem.NPCID2);
                entry.OwnerID = SharlayanBitConverter.TryToUInt32(source, this._memoryHandler.Structures.ActorItem.OwnerID);
                entry.TypeID  = source[this._memoryHandler.Structures.ActorItem.Type];
                entry.Type    = (Actor.Type)entry.TypeID;

                entry.TargetTypeID = source[this._memoryHandler.Structures.ActorItem.TargetType];
                entry.TargetType   = (Actor.TargetType)entry.TargetTypeID;

                entry.GatheringStatus = source[this._memoryHandler.Structures.ActorItem.GatheringStatus];
                entry.Distance        = source[this._memoryHandler.Structures.ActorItem.Distance];

                entry.X                  = SharlayanBitConverter.TryToSingle(source, this._memoryHandler.Structures.ActorItem.X + defaultBaseOffset);
                entry.Z                  = SharlayanBitConverter.TryToSingle(source, this._memoryHandler.Structures.ActorItem.Z + defaultBaseOffset);
                entry.Y                  = SharlayanBitConverter.TryToSingle(source, this._memoryHandler.Structures.ActorItem.Y + defaultBaseOffset);
                entry.Heading            = SharlayanBitConverter.TryToSingle(source, this._memoryHandler.Structures.ActorItem.Heading + defaultBaseOffset);
                entry.HitBoxRadius       = SharlayanBitConverter.TryToSingle(source, this._memoryHandler.Structures.ActorItem.HitBoxRadius + defaultBaseOffset);
                entry.Fate               = SharlayanBitConverter.TryToUInt32(source, this._memoryHandler.Structures.ActorItem.Fate + defaultBaseOffset); // ??
                entry.TargetFlags        = source[this._memoryHandler.Structures.ActorItem.TargetFlags];                                                 // ??
                entry.GatheringInvisible = source[this._memoryHandler.Structures.ActorItem.GatheringInvisible];                                          // ??
                entry.ModelID            = SharlayanBitConverter.TryToUInt32(source, this._memoryHandler.Structures.ActorItem.ModelID);
                entry.ActionStatusID     = source[this._memoryHandler.Structures.ActorItem.ActionStatus];
                entry.ActionStatus       = (Actor.ActionStatus)entry.ActionStatusID;

                // 0x17D - 0 = Green name, 4 = non-agro (yellow name)
                entry.IsGM   = SharlayanBitConverter.TryToBoolean(source, this._memoryHandler.Structures.ActorItem.IsGM); // ?
                entry.IconID = source[this._memoryHandler.Structures.ActorItem.Icon];
                entry.Icon   = (Actor.Icon)entry.IconID;

                entry.StatusID = source[this._memoryHandler.Structures.ActorItem.Status];
                entry.Status   = (Actor.Status)entry.StatusID;

                entry.ClaimedByID = SharlayanBitConverter.TryToUInt32(source, this._memoryHandler.Structures.ActorItem.ClaimedByID);
                uint targetID   = SharlayanBitConverter.TryToUInt32(source, this._memoryHandler.Structures.ActorItem.TargetID);
                uint pcTargetID = targetID;

                entry.JobID = source[this._memoryHandler.Structures.ActorItem.Job + defaultStatOffset];
                entry.Job   = (Actor.Job)entry.JobID;

                entry.Level            = source[this._memoryHandler.Structures.ActorItem.Level + defaultStatOffset];
                entry.GrandCompany     = source[this._memoryHandler.Structures.ActorItem.GrandCompany + defaultStatOffset];
                entry.GrandCompanyRank = source[this._memoryHandler.Structures.ActorItem.GrandCompanyRank + defaultStatOffset];
                entry.Title            = source[this._memoryHandler.Structures.ActorItem.Title + defaultStatOffset];
                entry.HPCurrent        = SharlayanBitConverter.TryToInt32(source, this._memoryHandler.Structures.ActorItem.HPCurrent + defaultStatOffset);
                entry.HPMax            = SharlayanBitConverter.TryToInt32(source, this._memoryHandler.Structures.ActorItem.HPMax + defaultStatOffset);
                entry.MPCurrent        = SharlayanBitConverter.TryToInt32(source, this._memoryHandler.Structures.ActorItem.MPCurrent + defaultStatOffset);
                entry.MPMax            = 10000;
                entry.GPCurrent        = SharlayanBitConverter.TryToInt16(source, this._memoryHandler.Structures.ActorItem.GPCurrent + defaultStatOffset);
                entry.GPMax            = SharlayanBitConverter.TryToInt16(source, this._memoryHandler.Structures.ActorItem.GPMax + defaultStatOffset);
                entry.CPCurrent        = SharlayanBitConverter.TryToInt16(source, this._memoryHandler.Structures.ActorItem.CPCurrent + defaultStatOffset);
                entry.CPMax            = SharlayanBitConverter.TryToInt16(source, this._memoryHandler.Structures.ActorItem.CPMax + defaultStatOffset);

                // entry.Race = source[0x2578]; // ??
                // entry.Sex = (Actor.Sex) source[0x2579]; //?
                entry.AgroFlags       = source[this._memoryHandler.Structures.ActorItem.AgroFlags];
                entry.CombatFlags     = source[this._memoryHandler.Structures.ActorItem.CombatFlags];
                entry.DifficultyRank  = source[this._memoryHandler.Structures.ActorItem.DifficultyRank];
                entry.CastingID       = SharlayanBitConverter.TryToInt16(source, this._memoryHandler.Structures.ActorItem.CastingID);        // 0x2C94);
                entry.CastingTargetID = SharlayanBitConverter.TryToUInt32(source, this._memoryHandler.Structures.ActorItem.CastingTargetID); // 0x2CA0);
                entry.CastingProgress = SharlayanBitConverter.TryToSingle(source, this._memoryHandler.Structures.ActorItem.CastingProgress); // 0x2CC4);
                entry.CastingTime     = SharlayanBitConverter.TryToSingle(source, this._memoryHandler.Structures.ActorItem.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;
                int limit = 60;
                switch (entry.Type)
                {
                case Actor.Type.PC:
                    limit = 30;
                    break;
                }

                int statusSize = this._memoryHandler.Structures.StatusItem.SourceSize;

                byte[] statusesMap = this._memoryHandler.BufferPool.Rent(statusSize * limit);
                byte[] statusMap   = this._memoryHandler.BufferPool.Rent(statusSize);

                try {
                    Buffer.BlockCopy(source, defaultStatusEffectOffset, statusesMap, 0, limit * statusSize);

                    for (int i = 0; i < limit; i++)
                    {
                        bool isNewStatus = false;

                        Buffer.BlockCopy(statusesMap, i * statusSize, statusMap, 0, statusSize);

                        short statusID = SharlayanBitConverter.TryToInt16(statusMap, this._memoryHandler.Structures.StatusItem.StatusID);
                        uint  casterID = SharlayanBitConverter.TryToUInt32(statusMap, this._memoryHandler.Structures.StatusItem.CasterID);

                        StatusItem statusEntry = entry.StatusItems.FirstOrDefault(x => x.CasterID == casterID && x.StatusID == statusID);

                        if (statusEntry == null)
                        {
                            statusEntry = new StatusItem();
                            isNewStatus = true;
                        }

                        statusEntry.TargetEntity = entry;
                        statusEntry.TargetName   = entry.Name;
                        statusEntry.StatusID     = statusID;
                        statusEntry.Stacks       = statusMap[this._memoryHandler.Structures.StatusItem.Stacks];
                        statusEntry.Duration     = SharlayanBitConverter.TryToSingle(statusMap, this._memoryHandler.Structures.StatusItem.Duration);
                        statusEntry.CasterID     = casterID;

                        try {
                            ActorItem pc      = this._pcWorkerDelegate.GetActorItem(statusEntry.CasterID);
                            ActorItem npc     = this._npcWorkerDelegate.GetActorItem(statusEntry.CasterID);
                            ActorItem monster = this._monsterWorkerDelegate.GetActorItem(statusEntry.CasterID);
                            statusEntry.SourceEntity = (pc ?? npc) ?? monster;
                        }
                        catch (Exception ex) {
                            this._memoryHandler.RaiseException(Logger, ex);
                        }

                        try {
                            Models.XIVDatabase.StatusItem statusInfo = StatusEffectLookup.GetStatusInfo((uint)statusEntry.StatusID);
                            if (statusInfo != null)
                            {
                                statusEntry.IsCompanyAction = statusInfo.CompanyAction;
                                string statusKey = statusInfo.Name.English;
                                switch (this._memoryHandler.Configuration.GameLanguage)
                                {
                                case GameLanguage.French:
                                    statusKey = statusInfo.Name.French;
                                    break;

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

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

                                case GameLanguage.Chinese:
                                    statusKey = statusInfo.Name.Chinese;
                                    break;

                                case GameLanguage.Korean:
                                    statusKey = statusInfo.Name.Korean;
                                    break;
                                }

                                statusEntry.StatusName = statusKey;
                            }
                        }
                        catch (Exception) {
                            statusEntry.StatusName = Constants.UNKNOWN_LOCALIZED_NAME;
                        }

                        if (statusEntry.IsValid())
                        {
                            if (isNewStatus)
                            {
                                entry.StatusItems.Add(statusEntry);
                            }

                            this._foundStatuses.Add(statusEntry);
                        }
                    }
                }
                catch (Exception ex) {
                    this._memoryHandler.RaiseException(Logger, ex);
                }
                finally {
                    this._memoryHandler.BufferPool.Return(statusesMap);
                    this._memoryHandler.BufferPool.Return(statusMap);
                }

                entry.StatusItems.RemoveAll(x => !this._foundStatuses.Contains(x));

                // handle empty names
                if (string.IsNullOrEmpty(entry.Name))
                {
                    if (entry.Type == Actor.Type.EventObject)
                    {
                        entry.Name = $"{nameof(entry.EventObjectTypeID)}: {entry.EventObjectTypeID}";
                    }
                    else
                    {
                        entry.Name = $"{nameof(entry.TypeID)}: {entry.TypeID}";
                    }
                }
            }
            catch (Exception ex) {
                this._memoryHandler.RaiseException(Logger, ex);
            }

            this.CleanXPValue(ref entry);

            if (isCurrentUser)
            {
                this._pcWorkerDelegate.CurrentUser = entry;
            }

            return(entry);
        }