Ejemplo n.º 1
0
        private int[] LoadAssembly(Assembly newAssembly)
        {
            Module[] newScripts = newAssembly.GetModules();
            int[]    count      = new int[2];
            foreach (Module newScript in newScripts)
            {
                Type[] types = newScript.GetTypes();
                foreach (Type npcType in types)
                {
                    try
                    {
                        if (npcType.IsAbstract == true)
                        {
                            continue;
                        }
                        if (npcType.BaseType == typeof(Scripting.QuestElement))
                        {
                            continue;
                        }
                        if (npcType.GetCustomAttributes(false).Length > 0)
                        {
                            continue;
                        }
                        Npc newNpc;
                        try
                        {
                            newNpc = (Npc)newAssembly.CreateInstance(npcType.FullName);
                        }
                        catch (Exception)
                        {
                            continue;
                        }
                        Map newScriptMap = null;
                        int mapID;
                        if (newNpc == null)
                        {
                            continue;
                        }
                        if (newNpc.isItem == true)
                        {
                            ActorItem newitem = new ActorItem();
                            MapItem   item    = (MapItem)newNpc;
                            item.ActorI = newitem;
                            item.OnInit();
                            newitem.itemtype = item.Type;
                            mapID            = MapManager.Instance.GetMapId(newNpc.MapName);
                            if (!MapManager.Instance.GetMap(mapID, out newScriptMap))
                            {
                                Logger.ShowError("Could not obtain map for script ", null);
                                continue;
                            }
                            item.Map           = newScriptMap;
                            newitem.name       = newNpc.Name;
                            newitem.e          = item;
                            newitem.x          = item.StartX;
                            newitem.y          = item.StartY;
                            newitem.z          = item.StartZ;
                            newitem.yaw        = item.Startyaw;
                            newitem.sightRange = Global.MakeSightRange(1000);
                            if (newScriptMap.RegisterActor(newitem))
                            {
                                scripts.Add(newScriptMap.ID + "-" + item.Name, item);
                                count[0]++;
                                //Logger.ShowInfo(newNpc.Name.PadRight(20) + " MapItem added at " + newScriptMap.Name + ":" + newitem.x + "#" + newitem.y + "#" + newitem.z, null);
                            }
                            else
                            {
                                Logger.ShowError("Error while registering MapItem: " + newNpc.Name, null);
                            }
                        }
                        else
                        {
                            ActorNPC newActor = new ActorNPC(newNpc.Type, 100, 100, 100, 100);
                            newNpc.Actor = newActor;
                            newNpc.OnInit();
                            newActor.npcType = newNpc.Type;

                            // Get the map for this npc
                            mapID = MapManager.Instance.GetMapId(newNpc.MapName);
                            if (!MapManager.Instance.GetMap(mapID, out newScriptMap))
                            {
                                Logger.ShowError("Could not obtain map for script ", null);
                                continue;
                            }


                            newNpc.Map     = newScriptMap;
                            newActor.name  = newNpc.Name;
                            newActor.mapID = (byte)mapID;
                            newActor.e     = newNpc;
                            newActor.x     = newNpc.StartX;
                            newActor.y     = newNpc.StartY;
                            //newNpc.StartZ = newScriptMap.HeightMap.GetZ(newNpc.StartX, newNpc.StartY);
                            newActor.z          = newNpc.StartZ;
                            newActor.yaw        = newNpc.Startyaw;
                            newActor.sightRange = Global.MakeSightRange(1000);
                            newActor.scriptName = npcType.Name;
                            newActor.version    = newNpc.Version;

                            if (newNpc.Persistent)
                            {
                                ActorNPC persActor = MapServer.charDB.GetNpc(npcType.Name);
                                if (persActor == null)
                                {
                                    Logger.ShowInfo("New persistent actor: " + npcType.Name, null);
                                }
                                // different version of the actor found, use all new values
                                else if (persActor.version != newNpc.Version)
                                {
                                    Logger.ShowWarning("different version for: " + npcType.Name + " version changed to: " + newNpc.Version, null);
                                    MapServer.charDB.DeleteNpc(new ActorNPC(npcType.Name));
                                }
                                // persistant actor found in db, use old values only update the event link
                                else if (persActor.version == newNpc.Version)
                                {
                                    Logger.ShowInfo("Found persistant actor in the db: " + npcType.Name, null);
                                    newActor   = persActor;
                                    newActor.e = newNpc;
                                }
                                // whatever the outcome store the current situation in the db
                                MapServer.charDB.SaveNpc(newActor);
                            }

                            if (newScriptMap.RegisterActor(newActor))
                            {
                                scripts.Add(newScriptMap.ID + "-" + newNpc.Name, newNpc);
                                count[1]++;
                                //Logger.ShowInfo(newNpc.Name.PadRight(20) + " NPC added at " + newScriptMap.Name + ":" + newActor.x + "#" + newActor.y + "#" + newActor.z, null);
                            }
                            else
                            {
                                Logger.ShowError("Error while registering npc: " + newNpc.Name, null);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.ShowError(ex);
                    }
                }
            }
            return(count);
        }
Ejemplo n.º 2
0
        public virtual void RaiseNewCurrentUserEvent(MemoryHandler memoryHandler, ActorItem eventData)
        {
            this.OnNewCurrentUser?.Invoke(this, memoryHandler, eventData);

            RaiseElectronEvent("OnNewCurrentUser", eventData);
        }
Ejemplo n.º 3
0
        public ActorResult GetActors()
        {
            ActorResult result = new ActorResult();

            if (!this.CanGetActors() || !this._memoryHandler.IsAttached)
            {
                return(result);
            }

            IntPtr targetAddress = IntPtr.Zero;

            int limit      = this._memoryHandler.Structures.ActorItem.EntityCount;
            int sourceSize = this._memoryHandler.Structures.ActorItem.SourceSize;

            byte[] characterAddressMap = this._memoryHandler.BufferPool.Rent(8 * limit);
            byte[] sourceMap           = this._memoryHandler.BufferPool.Rent(sourceSize);
            byte[] targetInfoMap       = this._memoryHandler.BufferPool.Rent(128);

            try {
                this._memoryHandler.GetByteArray(this._memoryHandler.Scanner.Locations[Signatures.CHARMAP_KEY], characterAddressMap);

                IntPtr firstAddress = IntPtr.Zero;

                DateTime now = DateTime.Now;

                TimeSpan staleActorRemovalTime = TimeSpan.FromSeconds(0.25);

                bool firstTime = true;

                for (int i = 0; i < limit; i++)
                {
                    IntPtr characterAddress = new IntPtr(SharlayanBitConverter.TryToInt64(characterAddressMap, i * 8));

                    if (characterAddress == IntPtr.Zero)
                    {
                        continue;
                    }

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

                    this._uniqueCharacterAddresses[characterAddress] = characterAddress;
                }

                foreach (KeyValuePair <uint, ActorItem> kvp in this._monsterWorkerDelegate.ActorItems)
                {
                    result.RemovedMonsters.TryAdd(kvp.Key, kvp.Value.Clone());
                }

                foreach (KeyValuePair <uint, ActorItem> kvp in this._npcWorkerDelegate.ActorItems)
                {
                    result.RemovedNPCs.TryAdd(kvp.Key, kvp.Value.Clone());
                }

                foreach (KeyValuePair <uint, ActorItem> kvp in this._pcWorkerDelegate.ActorItems)
                {
                    result.RemovedPCs.TryAdd(kvp.Key, kvp.Value.Clone());
                }

                (uint mapID, uint mapIndex, uint mapTerritory) = this.GetMapInfo();

                foreach (KeyValuePair <IntPtr, IntPtr> kvp in this._uniqueCharacterAddresses)
                {
                    try {
                        IntPtr characterAddress = new IntPtr(kvp.Value.ToInt64());
                        this._memoryHandler.GetByteArray(characterAddress, sourceMap);

                        uint       ID     = SharlayanBitConverter.TryToUInt32(sourceMap, this._memoryHandler.Structures.ActorItem.ID);
                        uint       NPCID2 = SharlayanBitConverter.TryToUInt32(sourceMap, this._memoryHandler.Structures.ActorItem.NPCID2);
                        Actor.Type Type   = (Actor.Type)sourceMap[this._memoryHandler.Structures.ActorItem.Type];

                        ActorItem existing = null;
                        bool      newEntry = false;

                        switch (Type)
                        {
                        case Actor.Type.Monster:
                            if (result.RemovedMonsters.ContainsKey(ID))
                            {
                                result.RemovedMonsters.TryRemove(ID, out ActorItem removedMonster);
                                existing = this._monsterWorkerDelegate.GetActorItem(ID);
                            }
                            else
                            {
                                newEntry = true;
                            }

                            break;

                        case Actor.Type.PC:
                            if (result.RemovedPCs.ContainsKey(ID))
                            {
                                result.RemovedPCs.TryRemove(ID, out ActorItem removedPC);
                                existing = this._pcWorkerDelegate.GetActorItem(ID);
                            }
                            else
                            {
                                newEntry = true;
                            }

                            break;

                        case Actor.Type.NPC:
                        case Actor.Type.Aetheryte:
                        case Actor.Type.EventObject:
                            if (result.RemovedNPCs.ContainsKey(NPCID2))
                            {
                                result.RemovedNPCs.TryRemove(NPCID2, out ActorItem removedNPC);
                                existing = this._npcWorkerDelegate.GetActorItem(NPCID2);
                            }
                            else
                            {
                                newEntry = true;
                            }

                            break;

                        default:
                            if (result.RemovedNPCs.ContainsKey(ID))
                            {
                                result.RemovedNPCs.TryRemove(ID, out ActorItem removedNPC);
                                existing = this._npcWorkerDelegate.GetActorItem(ID);
                            }
                            else
                            {
                                newEntry = true;
                            }

                            break;
                        }

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

                        ActorItem entry = this._actorItemResolver.ResolveActorFromBytes(sourceMap, isFirstEntry, existing);

                        if (entry != null && entry.IsValid)
                        {
                            if (this._expiringActors.ContainsKey(ID))
                            {
                                this._expiringActors.TryRemove(ID, out DateTime removedDateTime);
                            }
                        }

                        if (entry.Type == Actor.Type.EventObject)
                        {
                            (ushort EventObjectTypeID, Actor.EventObjectType EventObjectType) = this.GetEventObjectType(targetAddress);
                            entry.EventObjectTypeID = EventObjectTypeID;
                            entry.EventObjectType   = EventObjectType;
                        }

                        entry.MapID        = mapID;
                        entry.MapIndex     = mapIndex;
                        entry.MapTerritory = mapTerritory;

                        if (isFirstEntry)
                        {
                            if (targetAddress.ToInt64() > 0)
                            {
                                this._memoryHandler.GetByteArray(targetAddress, targetInfoMap);
                                entry.TargetID = (int)SharlayanBitConverter.TryToUInt32(targetInfoMap, this._memoryHandler.Structures.ActorItem.ID);
                            }
                        }

                        if (!entry.IsValid)
                        {
                            result.NewMonsters.TryRemove(entry.ID, out ActorItem _);
                            result.NewMonsters.TryRemove(entry.NPCID2, out ActorItem _);
                            result.NewNPCs.TryRemove(entry.ID, out ActorItem _);
                            result.NewNPCs.TryRemove(entry.NPCID2, out ActorItem _);
                            result.NewPCs.TryRemove(entry.ID, out ActorItem _);
                            result.NewPCs.TryRemove(entry.NPCID2, out ActorItem _);
                            continue;
                        }

                        if (existing != null)
                        {
                            continue;
                        }

                        if (newEntry)
                        {
                            switch (entry.Type)
                            {
                            case Actor.Type.Monster:
                                this._monsterWorkerDelegate.EnsureActorItem(entry.ID, entry);
                                result.NewMonsters.TryAdd(entry.ID, entry.Clone());
                                break;

                            case Actor.Type.PC:
                                this._pcWorkerDelegate.EnsureActorItem(entry.ID, entry);
                                result.NewPCs.TryAdd(entry.ID, entry.Clone());
                                break;

                            case Actor.Type.Aetheryte:
                            case Actor.Type.EventObject:
                            case Actor.Type.NPC:
                                this._npcWorkerDelegate.EnsureActorItem(entry.NPCID2, entry);
                                result.NewNPCs.TryAdd(entry.NPCID2, entry.Clone());
                                break;

                            default:
                                this._npcWorkerDelegate.EnsureActorItem(entry.ID, entry);
                                result.NewNPCs.TryAdd(entry.ID, entry.Clone());
                                break;
                            }
                        }
                    }
                    catch (Exception ex) {
                        this._memoryHandler.RaiseException(Logger, ex);
                    }
                }

                try {
                    // add the "removed" actors to the expiring list
                    foreach (KeyValuePair <uint, ActorItem> kvp in result.RemovedMonsters)
                    {
                        if (!this._expiringActors.ContainsKey(kvp.Key))
                        {
                            this._expiringActors[kvp.Key] = now + staleActorRemovalTime;
                        }
                    }

                    foreach (KeyValuePair <uint, ActorItem> kvp in result.RemovedNPCs)
                    {
                        if (!this._expiringActors.ContainsKey(kvp.Key))
                        {
                            this._expiringActors[kvp.Key] = now + staleActorRemovalTime;
                        }
                    }

                    foreach (KeyValuePair <uint, ActorItem> kvp in result.RemovedPCs)
                    {
                        if (!this._expiringActors.ContainsKey(kvp.Key))
                        {
                            this._expiringActors[kvp.Key] = now + staleActorRemovalTime;
                        }
                    }

                    // check expiring list for stale actors
                    foreach (KeyValuePair <uint, DateTime> kvp in this._expiringActors)
                    {
                        if (now > kvp.Value)
                        {
                            // Stale actor. Remove it.
                            this._monsterWorkerDelegate.RemoveActorItem(kvp.Key);
                            this._npcWorkerDelegate.RemoveActorItem(kvp.Key);
                            this._pcWorkerDelegate.RemoveActorItem(kvp.Key);

                            this._expiringActors.TryRemove(kvp.Key, out DateTime removedDateTime);
                        }
                        else
                        {
                            // Not stale enough yet. We're not actually removing it.
                            result.RemovedMonsters.TryRemove(kvp.Key, out ActorItem _);
                            result.RemovedNPCs.TryRemove(kvp.Key, out ActorItem _);
                            result.RemovedPCs.TryRemove(kvp.Key, out ActorItem _);
                        }
                    }
                }
                catch (Exception ex) {
                    this._memoryHandler.RaiseException(Logger, ex);
                }

                this._memoryHandler.ScanCount++;
            }
            catch (Exception ex) {
                this._memoryHandler.RaiseException(Logger, ex);
            }
            finally {
                this._memoryHandler.BufferPool.Return(characterAddressMap);
                this._memoryHandler.BufferPool.Return(sourceMap);
                this._memoryHandler.BufferPool.Return(targetInfoMap);
            }

            result.CurrentMonsters = this._monsterWorkerDelegate.ActorItems;
            result.CurrentNPCs     = this._npcWorkerDelegate.ActorItems;
            result.CurrentPCs      = this._pcWorkerDelegate.ActorItems;

            this._uniqueCharacterAddresses.Clear();

            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// State if this entity should be ignored or not
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool IsIgnored(string type, ActorItem entity)
        {
            // skip if missing data or unknown
            if (entity.Type.ToString().ToLower() == "unknown" ||
                entity.Type.ToString().ToLower() == "minion" ||
                entity.NPCID2 == 0 ||
                entity.MapID == 0 ||
                entity.Name == String.Empty)
            {
                return(true);
            }

            // if enabled, non English entities will be ignored.
            // off by default
            if (Properties.Settings.Default.IgnoreNoneEnglish)
            {
                Regex  rgx  = new Regex("[^a-zA-Z0-9 -]");
                string name = rgx.Replace(entity.Name.ToString(), "");

                // name too short or too long
                if (entity.Name.ToString().Length < 2 || entity.Name.ToString().Length > 64)
                {
                    return(true);
                }
            }

            // has a stupid big id (100 million)
            if (entity.NPCID2 > 100000000)
            {
                return(true);
            }

            // egis and fairies
            uint[] egis = { 1881, 1404, 1403, 1402, 1398, 1399 };
            if (type == "BNPC" && egis.Contains(entity.ModelID))
            {
                return(true);
            }

            // we only care about entities on the same map as the player
            if (entity.MapID != Player.MapID)
            {
                return(true);
            }

            // ignore out of range eobjs
            if (entity.Type.ToString().ToLower() == "eobj" && entity.NPCID2 > 50000000)
            {
                return(true);
            }

            // ignore if it starts with an x
            if (entity.Name[0].ToString() == "×")
            {
                return(true);
            }

            // has weird symbols
            if (entity.Name.ToString().Contains('�'))
            {
                return(true);
            }

            // restrict axis
            if (axisRestricted)
            {
                double AxisLimit = 6;
                double AxisDiff  = entity.Z - Player.Z;
                AxisDiff = Math.Abs(AxisDiff);

                // don't include stuff that is past the axis threshold
                if (AxisDiff > AxisLimit)
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 5
0
        private static void CleanXPValue(ref ActorItem entity)
        {
            if (entity.HPCurrent < 0 || entity.HPMax < 0)
            {
                entity.HPCurrent = 1;
                entity.HPMax     = 1;
            }

            if (entity.HPCurrent > entity.HPMax)
            {
                if (entity.HPMax == 0)
                {
                    entity.HPCurrent = 1;
                    entity.HPMax     = 1;
                }
                else
                {
                    entity.HPCurrent = entity.HPMax;
                }
            }

            if (entity.MPCurrent < 0 || entity.MPMax < 0)
            {
                entity.MPCurrent = 1;
                entity.MPMax     = 1;
            }

            if (entity.MPCurrent > entity.MPMax)
            {
                if (entity.MPMax == 0)
                {
                    entity.MPCurrent = 1;
                    entity.MPMax     = 1;
                }
                else
                {
                    entity.MPCurrent = entity.MPMax;
                }
            }

            if (entity.GPCurrent < 0 || entity.GPMax < 0)
            {
                entity.GPCurrent = 1;
                entity.GPMax     = 1;
            }

            if (entity.GPCurrent > entity.GPMax)
            {
                if (entity.GPMax == 0)
                {
                    entity.GPCurrent = 1;
                    entity.GPMax     = 1;
                }
                else
                {
                    entity.GPCurrent = entity.GPMax;
                }
            }

            if (entity.CPCurrent < 0 || entity.CPMax < 0)
            {
                entity.CPCurrent = 1;
                entity.CPMax     = 1;
            }

            if (entity.CPCurrent > entity.CPMax)
            {
                if (entity.CPMax == 0)
                {
                    entity.CPCurrent = 1;
                    entity.CPMax     = 1;
                }
                else
                {
                    entity.CPCurrent = entity.CPMax;
                }
            }
        }
Ejemplo n.º 6
0
        public static PartyResult GetPartyMembers()
        {
            var result = new PartyResult();

            if (!CanGetPartyMembers() || !MemoryHandler.Instance.IsAttached)
            {
                return(result);
            }

            var       PartyInfoMap  = (IntPtr)Scanner.Instance.Locations[Signatures.PartyMapKey];
            Signature PartyCountMap = Scanner.Instance.Locations[Signatures.PartyCountKey];

            foreach (KeyValuePair <uint, PartyMember> kvp in PartyWorkerDelegate.PartyMembers)
            {
                result.RemovedPartyMembers.TryAdd(kvp.Key, kvp.Value.Clone());
            }

            try {
                var partyCount = MemoryHandler.Instance.GetByte(PartyCountMap);
                var sourceSize = MemoryHandler.Instance.Structures.PartyMember.SourceSize;

                if (partyCount > 1 && partyCount < 9)
                {
                    for (uint i = 0; i < partyCount; i++)
                    {
                        var       address  = PartyInfoMap.ToInt64() + i * (uint)sourceSize;
                        byte[]    source   = MemoryHandler.Instance.GetByteArray(new IntPtr(address), sourceSize);
                        var       ID       = BitConverter.TryToUInt32(source, MemoryHandler.Instance.Structures.PartyMember.ID);
                        ActorItem existing = null;
                        var       newEntry = false;

                        if (result.RemovedPartyMembers.ContainsKey(ID))
                        {
                            result.RemovedPartyMembers.TryRemove(ID, out PartyMember removedPartyMember);
                            if (MonsterWorkerDelegate.ActorItems.ContainsKey(ID))
                            {
                                existing = MonsterWorkerDelegate.GetActorItem(ID);
                            }

                            if (PCWorkerDelegate.ActorItems.ContainsKey(ID))
                            {
                                existing = PCWorkerDelegate.GetActorItem(ID);
                            }
                        }
                        else
                        {
                            newEntry = true;
                        }

                        PartyMember entry = PartyMemberResolver.ResolvePartyMemberFromBytes(source, existing);
                        if (!entry.IsValid)
                        {
                            continue;
                        }

                        if (existing != null)
                        {
                            continue;
                        }

                        if (newEntry)
                        {
                            PartyWorkerDelegate.EnsurePartyMember(entry.ID, entry);
                            result.NewPartyMembers.TryAdd(entry.ID, entry.Clone());
                        }
                    }
                }

                if (partyCount == 1)
                {
                    PartyMember entry = PartyMemberResolver.ResolvePartyMemberFromBytes(Array.Empty <byte>(), PCWorkerDelegate.CurrentUser);
                    if (result.RemovedPartyMembers.ContainsKey(entry.ID))
                    {
                        result.RemovedPartyMembers.TryRemove(entry.ID, out PartyMember removedPartyMember);
                    }

                    PartyWorkerDelegate.EnsurePartyMember(entry.ID, entry);
                }
            }
            catch (Exception ex) {
                MemoryHandler.Instance.RaiseException(Logger, ex, true);
            }

            try {
                // REMOVE OLD PARTY MEMBERS FROM LIVE CURRENT DICTIONARY
                foreach (KeyValuePair <uint, PartyMember> kvp in result.RemovedPartyMembers)
                {
                    PartyWorkerDelegate.RemovePartyMember(kvp.Key);
                }
            }
            catch (Exception ex) {
                MemoryHandler.Instance.RaiseException(Logger, ex, true);
            }

            return(result);
        }
Ejemplo n.º 7
0
            public static bool Prefix(int key)
            {
                if (!Main.enabled)
                {
                    return(true);
                }

                int  key1    = acotrId;
                int  key2    = giveActorId;
                bool selGive = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl);

                // Main.Logger.Log(selGive + " 设置角色属性 " + key);

                if (selGive)
                {
                    if (giveActorId == key)
                    {
                        // Main.Logger.Log(key + "=========相同赠送:" + giveActorId);
                        return(false);
                    }
                    else
                    {
                        giveActorId = key;
                    }
                }
                if (!selGive)
                {
                    if (acotrId == key)
                    {
                        // Main.Logger.Log(key + "=========相同选中:" + acotrId);
                        return(true);
                    }
                    else
                    {
                        acotrId = key;
                    }
                }
                bool result = false;
                var  tf     = m_listActorsHolder.rectContent;

                if (tf.childCount > 0)
                {
                    // 设置选中
                    string name  = "Actor," + key;
                    var    child = tf.Find(name);
                    if (child != null)
                    {
                        ActorItem   item      = child.GetComponentInChildren <ActorItem>();
                        ChildData   childData = item.childDatas[0];
                        SelectState selectState;
                        if (selGive)
                        {
                            if (key == acotrId)
                            {
                                selectState = SelectState.All;
                            }
                            else
                            {
                                selectState = SelectState.Give;
                            }
                        }
                        else
                        {
                            if (key == giveActorId)
                            {
                                selectState = SelectState.All;
                            }
                            else
                            {
                                selectState = SelectState.Select;
                            }
                            result = true;
                        }
                        // Main.Logger.Log("设置选中:" + selectState);
                        childData.Select(selectState);
                    }
                    // 取消原来的赠送
                    if (selGive)
                    {
                        name  = "Actor," + key2;
                        child = tf.Find(name);
                        if (child != null)
                        {
                            ActorItem   item      = child.GetComponentInChildren <ActorItem>();
                            ChildData   childData = item.childDatas[0];
                            SelectState selectState;
                            if (key2 == acotrId)
                            {
                                selectState = SelectState.Select;
                            }
                            else
                            {
                                selectState = SelectState.Node;
                            }
                            // Main.Logger.Log("取消原来的赠送:" + selectState);
                            childData.Select(selectState);
                        }
                    }
                    else // 取消原来的选择
                    {
                        name  = "Actor," + key1;
                        child = tf.Find(name);
                        if (child != null)
                        {
                            ActorItem   item      = child.GetComponentInChildren <ActorItem>();
                            ChildData   childData = item.childDatas[0];
                            SelectState selectState;
                            if (key1 == giveActorId)
                            {
                                selectState = SelectState.Give;
                            }
                            else
                            {
                                selectState = SelectState.Node;
                            }
                            childData.Select(selectState);
                        }
                    }
                }
                // Main.Logger.Log("是否更新选中:" + result);
                // Main.Logger.Log("=========选中:" + acotrId);
                // Main.Logger.Log("=========赠送:" + giveActorId);
                return(result);
            }
Ejemplo n.º 8
0
        private void InitUI()
        {
            isInit = true;

            Vector2 size       = new Vector2(230, 830);
            Vector2 pos        = new Vector2(0, 0);
            Vector2 cellSize   = new Vector2(230, 97);
            float   cellWidth  = cellSize.x;
            float   cellHeight = cellSize.y;
            // Main.Logger.Log("10");

            GameObject scrollView = CreateUI.NewScrollView(size, BarType.Vertical, ContentType.VerticalLayout); // 创建滑动UI

            scrollRect = scrollView.GetComponent <ScrollRect>();                                                // 拿到滑动组件
            //WorldMapSystem.instance.actorHolder = scrollRect.content;
            rectContent = scrollRect.content;                                                                   // 内容啊 content
            rectContent.GetComponent <ContentSizeFitter>().enabled   = false;                                   //关闭高度自动适应
            rectContent.GetComponent <VerticalLayoutGroup>().enabled = false;                                   // 关闭自动排序
            // Main.Logger.Log("完");

            scrollRect.verticalNormalizedPosition = 1;                         // 设置最上的位置
            Image imgScrollView = scrollView.GetComponentInChildren <Image>(); // 拿到背景图

            imgScrollView.color         = new Color(0.5f, 0.5f, 0.5f, 1f);     // 背景图颜色
            imgScrollView.raycastTarget = false;                               // 设置背景不可点击
            RectTransform rScrollView = ((RectTransform)scrollView.transform); // 拿到滑动UI

            rScrollView.SetParent(gameObject.transform, false);                // 设置父物体
            rScrollView.anchoredPosition = pos;                                // 设置位置

            //scrollView.GetComponentInChildren<Mask>().enabled = false;
            // Main.Logger.Log("完0");

            GameObject    gItemCell = new GameObject("line", new System.Type[] { typeof(RectTransform) }); // 创建一行
            RectTransform rItemCell = gItemCell.GetComponent <RectTransform>();                            // 得到transform

            rItemCell.SetParent(transform, false);                                                         // 设置父物体
            rItemCell.anchoredPosition = new Vector2(10000, 10000);                                        // 隐藏于遥远虚空
            rItemCell.sizeDelta        = new Vector2(cellWidth, cellHeight);                               // 设置大小
                                                                                                           //Image imgItemCell = gItemCell.AddComponent<Image>();
                                                                                                           //imgItemCell.color = new Color(1, 0, 0, 0.5f);
            // Main.Logger.Log("完成");

            GameObject prefab = ActorMenu.instance.listActor;           // 拿到子物体预制件  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!

            for (int i = 0; i < lineCount; i++)                         // 一行几个
            {
                GameObject go = UnityEngine.Object.Instantiate(prefab); // 创建每行子物体
                go.transform.SetParent(rItemCell, false);               // 设置父物体
                Toggle tog = go.GetComponentInChildren <Toggle>();
                var    tar = tog.targetGraphic;
                // Main.Logger.Log(tog + "隐藏" + tog.graphic + " " + tog.graphic.transform.parent);
                DestroyImmediate(tog);
                Button btn = go.AddComponent <Button>();
                btn.targetGraphic = tar;
            }
            // Main.Logger.Log("完成0");


            GridLayoutGroup gridLayoutGroup = gItemCell.AddComponent <GridLayoutGroup>();   // 控制子物体

            gridLayoutGroup.cellSize     = prefab.GetComponent <RectTransform>().sizeDelta; // 设置子物体大小
            gridLayoutGroup.spacing      = new Vector2(0, 0);                               // 子物体边距
            gridLayoutGroup.padding.left = (int)(12);                                       // 左偏移
            gridLayoutGroup.padding.top  = (int)(0);                                        // 上偏移
            // Main.Logger.Log("完成1");


            ActorItem itemCell = gItemCell.AddComponent <ActorItem>(); // 添加大数据子物体关联组件

            bigDataScroll = gameObject.AddComponent <BigDataScroll>(); // 添加大数据管理组件
            bigDataScroll.Init(scrollRect, itemCell, SetCell);         // 初始化大数据组件
            bigDataScroll.cellHeight = cellHeight;                     // 设置一行高度

            //GuiBaseUI.Main.LogAllChild(transform, true);



            // 以下是设置滑动条图片
            ScrollRect scroll = transform.GetComponent <ScrollRect>();
            // Main.Logger.Log("完成v");
            RectTransform otherRect = scroll.verticalScrollbar.GetComponent <RectTransform>();
            Image         other     = otherRect.GetComponent <Image>();
            // Main.Logger.Log("完成a");
            RectTransform myRect = scrollRect.verticalScrollbar.GetComponent <RectTransform>();
            //myRect.sizeDelta = new Vector2(10, 0);
            // Main.Logger.Log("完成b");
            Image my = myRect.GetComponent <Image>();

            // Main.Logger.Log("完成e");
            //my.color = new Color(0.9490196f, 0.509803951f, 0.503921571f);
            my.sprite = other.sprite;
            my.type   = Image.Type.Sliced;
            // Main.Logger.Log("完成p");

            // Main.Logger.Log("完成V");
            RectTransform otherRect2 = scrollRect.verticalScrollbar.targetGraphic.GetComponent <RectTransform>();
            Image         other2     = otherRect2.GetComponent <Image>();
            // Main.Logger.Log("完成A");
            RectTransform myRect2 = scrollRect.verticalScrollbar.targetGraphic.GetComponent <RectTransform>();
            // Main.Logger.Log("完成B");
            //myRect2.sizeDelta = new Vector2(10, 10);
            Image my2 = myRect2.GetComponent <Image>();

            // Main.Logger.Log("完成C");
            //my2.color = new Color(0.5882353f, 0.807843149f, 0.8156863f);
            my2.sprite = other2.sprite;
            my2.type   = Image.Type.Sliced;
            // Main.Logger.Log("完成D");


            // Main.Logger.Log("完成3");
            SetData();
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Add an item to the inventory according to a pre-existing item.
 /// </summary>
 /// <param name="item"></param>
 public void AddItem(ActorItem item)
 {
     inventory.Add(item);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Removing an item from the inventory according to a pre-existing item.
 /// </summary>
 /// <param name="item"></param>
 public void RemoveItem(ActorItem item)
 {
     inventory.Remove(item);
 }
Ejemplo n.º 11
0
 public Item_EventHandler(ActorItem actor, Map map)
 {
     this.I   = actor;
     this.map = map;
 }
        private static void UpdateBeneficialGain(Match beneficial, Line line, Expressions exp, FilterType type)
        {
            _type = type;
            try {
                if (string.IsNullOrWhiteSpace(line.Source))
                {
                    line.Source = Convert.ToString(beneficial.Groups["source"].Value);
                }

                if (string.IsNullOrWhiteSpace(line.Target))
                {
                    line.Target = Convert.ToString(beneficial.Groups["target"].Value);
                }

                line.Action = Convert.ToString(beneficial.Groups["status"].Value);
                var isStoneSkin = false;
                foreach (var stoneSkin in MagicBarrierHelper.StoneSkin.Where(stoneSkin => string.Equals(stoneSkin, line.Action, Constants.InvariantComparer)))
                {
                    isStoneSkin = true;
                }

                switch (line.EventDirection)
                {
                case EventDirection.You:
                    line.Target = You;
                    break;
                }

                if (line.IsEmpty())
                {
                    return;
                }

                if (isStoneSkin)
                {
                    var multiplier = 0.1m;
                    try {
                        var       cleanedName = Regex.Replace(line.Source, @"\[[\w]+\]", string.Empty).Trim();
                        ActorItem source      = XIVInfoViewModel.Instance.CurrentPCs.FirstOrDefault(kvp => kvp.Value.Name.Equals(cleanedName, Constants.InvariantComparer)).Value;
                        if (source != null)
                        {
                            multiplier = source.Job == Actor.Job.WHM
                                             ? 0.18m
                                             : multiplier;
                        }
                    }
                    catch (Exception ex) {
                        Logging.Log(Logger, new LogItem(ex, true));
                    }

                    try {
                        var       cleanedName = Regex.Replace(line.Target, @"\[[\w]+\]", string.Empty).Trim();
                        ActorItem target      = XIVInfoViewModel.Instance.CurrentPCs.FirstOrDefault(kvp => kvp.Value.Name.Equals(cleanedName, Constants.InvariantComparer)).Value;
                        if (target != null)
                        {
                            line.Amount = (double)(target.HPMax * multiplier);
                            ParseControl.Instance.Timeline.GetSetPlayer(line.Source).SetupHealingMitigated(line, "stoneskin");
                        }
                    }
                    catch (Exception ex) {
                        Logging.Log(Logger, new LogItem(ex, true));
                    }
                }
            }
            catch (Exception ex) {
                ParsingLogHelper.Error(Logger, "Cure", exp.Event, ex);
            }
        }
Ejemplo n.º 13
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            var bc = new BrushConverter();

            ActorItem user = XIVInfoViewModel.Instance.CurrentUser;

            if (user == null)
            {
                return;
            }

            var origin = new Coordinate {
                X = (float)(this.ActualWidth / 2),
                Y = (float)(this.ActualHeight / 2)
            };

            var scale = (float)(this.ActualHeight / 2.0f) / 125.0f;
            var angle = Math.Abs(user.Heading * (180 / Math.PI) - 180);

            var drawingGroup = new DrawingGroup();

            if (Settings.Default.RadarCompassMode)
            {
                drawingGroup.Transform = new RotateTransform {
                    Angle   = angle,
                    CenterX = origin.X,
                    CenterY = origin.Y
                };
            }

            drawingGroup.Children.Add(new ImageDrawing(Game.RadarHeading, new Rect(origin.X - 64, origin.Y - 128, 128, 128)));
            drawingGroup.Children.Add(new ImageDrawing(Game.Player, new Rect(origin.X - 8, origin.Y - 16, 16, 21)));

            this.DrawDrawing(drawingContext, drawingGroup);

            var sb = new StringBuilder();

            List <ActorItem> npcEntites     = new List <ActorItem>(XIVInfoViewModel.Instance.CurrentNPCs.Select(kvp => kvp.Value).ToList());
            List <ActorItem> monsterEntites = new List <ActorItem>(XIVInfoViewModel.Instance.CurrentMonsters.Select(kvp => kvp.Value).ToList());
            List <ActorItem> pcEntites      = new List <ActorItem>(XIVInfoViewModel.Instance.CurrentPCs.Select(kvp => kvp.Value).ToList());



            if (Settings.Default.FilterRadarItems)
            {
                List <RadarFilterItem> npcFilters = PluginViewModel.Instance.Filters.Where(filter => filter.Type != "PC" && filter.Type != "Monster").ToList();
                if (npcFilters.Any())
                {
                    npcEntites = RadarFilterHelper.ResolveFilteredEntities(npcFilters, npcEntites);
                }

                List <RadarFilterItem> monsterFilters = PluginViewModel.Instance.Filters.Where(filter => filter.Type == "Monster").ToList();
                if (PluginViewModel.Instance.RankedFilters.Any())
                {
                    monsterFilters.AddRange(PluginViewModel.Instance.RankedFilters);
                }

                if (monsterFilters.Any())
                {
                    monsterEntites = RadarFilterHelper.ResolveFilteredEntities(monsterFilters, monsterEntites);
                }

                List <RadarFilterItem> pcFilters = PluginViewModel.Instance.Filters.Where(filter => filter.Type == "PC").ToList();
                if (pcFilters.Any())
                {
                    pcEntites = RadarFilterHelper.ResolveFilteredEntities(pcFilters, pcEntites);
                }

                monsterEntites = RadarFilterHelper.CleanupEntities(monsterEntites);
            }



            #region Resolve PCs

            if (Settings.Default.PCShow)
            {
                foreach (ActorItem actorEntity in pcEntites)
                {
                    sb.Clear();
                    var fontSizeModifier = 0;
                    drawingContext.PushOpacity(1);
                    try {
                        if (!actorEntity.IsValid || user == null)
                        {
                            continue;
                        }

                        if (actorEntity.ID == user.ID)
                        {
                            continue;
                        }

                        Coordinate screen;
                        if (Settings.Default.RadarCompassMode)
                        {
                            Coordinate coord = user.Coordinate.Subtract(actorEntity.Coordinate).Scale(scale);
                            screen = new Coordinate(-coord.X, 0, -coord.Y).Add(origin);
                        }
                        else
                        {
                            screen = user.Coordinate.Subtract(actorEntity.Coordinate).Rotate2D(user.Heading).Scale(scale).Add(origin);
                        }

                        screen = screen.Add(-8, -8, 0);
                        if (Settings.Default.PCShowName)
                        {
                            sb.Append(actorEntity.Name);
                        }

                        if (Settings.Default.PCShowHPPercent)
                        {
                            sb.AppendFormat(" {0:P0}", actorEntity.HPPercent);
                        }

                        if (Settings.Default.PCShowDistance)
                        {
                            sb.AppendFormat(" {0:N2} {1}", user.GetDistanceTo(actorEntity), this.ResolveHeightVariance(user, actorEntity));
                        }

                        var useJob = Settings.Default.PCShowJob;
                        if (Settings.Default.PCShowJob)
                        {
                            #region Get Job Icons

                            switch (actorEntity.Job)
                            {
                            case Actor.Job.Unknown:
                                if (actorEntity.OwnerID > 0 && actorEntity.OwnerID < 3758096384)
                                {
                                    this.DrawImage(drawingContext, Game.Chocobo, new Rect(new Point(), new Size(16, 16)));
                                }

                                useJob = false;
                                break;

                            default:
                                this.DrawImage(drawingContext, Game.GetIconByName(actorEntity.Job.ToString()), new Rect(new Point(screen.X, screen.Y), new Size(16, 16)));
                                break;
                            }

                            #endregion
                        }

                        if (!useJob)
                        {
                            BitmapImage imageSource = actorEntity.HPCurrent > 0
                                                          ? Game.Player
                                                          : Game.Unknown;
                            this.DrawImage(drawingContext, imageSource, new Rect(new Point(screen.X, screen.Y), new Size(16, 16)));
                        }

                        this.RenderDebugInformation(actorEntity, ref sb);

                        if (Settings.Default.PCShowName || Settings.Default.PCShowHPPercent)
                        {
                            var text = new FormattedText(sb.ToString(), this._cultureInfo, this._flowDirection, this._typeface, int.Parse(Settings.Default.PCFontSize) + fontSizeModifier, (SolidColorBrush)bc.ConvertFromString(Settings.Default.PCFontColor));
                            this.DrawText(drawingContext, text, screen.X + 20, screen.Y);
                        }
                    }
                    catch (Exception ex) {
                        Logging.Log(Logger, new LogItem(ex, true));
                    }

                    drawingContext.Pop();
                }
            }

            #endregion

            #region Resolve Monsters

            if (Settings.Default.MonsterShow)
            {
                foreach (ActorItem actorEntity in monsterEntites)
                {
                    sb.Clear();
                    var fontSizeModifier = 0;
                    var fontColor        = Settings.Default.MonsterFontColor;

                    List <string> RankB = LocaleHelper.GetRankedMonsters("B");
                    List <string> RankA = LocaleHelper.GetRankedMonsters("A");
                    List <string> RankS = LocaleHelper.GetRankedMonsters("S");

                    var isRanked = false;

                    if (Settings.Default.MonsterShowRankColor)
                    {
                        if (RankA.Any(x => x.Equals(actorEntity.Name, StringComparison.InvariantCultureIgnoreCase)))
                        {
                            fontColor         = Settings.Default.MonsterFontColorARank;
                            fontSizeModifier += 2;
                            isRanked          = true;
                        }
                        else if (RankS.Any(x => x.Equals(actorEntity.Name, StringComparison.InvariantCultureIgnoreCase)))
                        {
                            fontColor         = Settings.Default.MonsterFontColorSRank;
                            fontSizeModifier += 2;
                            isRanked          = true;
                        }
                        else if (RankB.Any(x => x.Equals(actorEntity.Name, StringComparison.InvariantCultureIgnoreCase)))
                        {
                            fontColor         = Settings.Default.MonsterFontColorBRank;
                            fontSizeModifier += 2;
                            isRanked          = true;
                        }
                    }

                    drawingContext.PushOpacity(1);

                    try {
                        if (!actorEntity.IsValid || user == null)
                        {
                            continue;
                        }

                        if (actorEntity.ID == user.ID)
                        {
                            continue;
                        }

                        Coordinate screen;
                        if (Settings.Default.RadarCompassMode)
                        {
                            Coordinate coord = user.Coordinate.Subtract(actorEntity.Coordinate).Scale(scale);
                            screen = new Coordinate(-coord.X, 0, -coord.Y).Add(origin);
                        }
                        else
                        {
                            screen = user.Coordinate.Subtract(actorEntity.Coordinate).Rotate2D(user.Heading).Scale(scale).Add(origin);
                        }

                        screen = screen.Add(-8, -8, 0);
                        BitmapImage actorIcon;

                        if (actorEntity.IsFate)
                        {
                            actorIcon = Game.MobFate;
                        }
                        else
                        {
                            switch (actorEntity.DifficultyRank)
                            {
                            case 6:
                                actorIcon = actorEntity.IsAggressive
                                                    ? Game.MobAggressive5
                                                    : Game.MobPassive5;
                                break;

                            case 4:
                                actorIcon = actorEntity.IsAggressive
                                                    ? Game.MobAggressive3
                                                    : Game.MobPassive3;
                                break;

                            case 3:
                                actorIcon = actorEntity.IsAggressive
                                                    ? Game.MobAggressive2
                                                    : Game.MobPassive2;
                                break;

                            case 2:
                                actorIcon = actorEntity.IsAggressive
                                                    ? Game.MobAggressive6
                                                    : Game.MobPassive6;
                                break;

                            case 1:
                                actorIcon = actorEntity.IsAggressive
                                                    ? Game.MobAggressive4
                                                    : Game.MobPassive4;
                                break;

                            default:
                                actorIcon = actorEntity.IsAggressive
                                                    ? Game.MobAggressive1
                                                    : Game.MobPassive1;
                                break;
                            }

                            if (actorEntity.OwnerID > 0 && actorEntity.OwnerID < 3758096384)
                            {
                                actorIcon = Game.Chocobo;
                            }
                        }

                        var iconSize = new Size(16, 16);
                        var point    = new Point(screen.X, screen.Y);

                        if (isRanked)
                        {
                            iconSize = new Size(24, 24);
                            point    = new Point(screen.X - 4, screen.Y - 4);
                        }

                        if (actorEntity.HPCurrent > 0)
                        {
                            if (actorIcon != null)
                            {
                                this.DrawImage(drawingContext, actorIcon, new Rect(point, iconSize));
                            }
                        }
                        else
                        {
                            this.DrawImage(drawingContext, Game.Unknown, new Rect(point, iconSize));
                        }

                        if (Settings.Default.MonsterShowName)
                        {
                            sb.Append(actorEntity.Name);
                        }

                        if (Settings.Default.MonsterShowHPPercent)
                        {
                            sb.AppendFormat(" {0:P0}", actorEntity.HPPercent);
                        }

                        if (Settings.Default.MonsterShowDistance)
                        {
                            sb.AppendFormat(" {0:N2} {1}", user.GetDistanceTo(actorEntity), this.ResolveHeightVariance(user, actorEntity));
                        }

                        this.RenderDebugInformation(actorEntity, ref sb);

                        if (Settings.Default.MonsterShowName || Settings.Default.MonsterShowHPPercent)
                        {
                            var text = new FormattedText(sb.ToString(), this._cultureInfo, this._flowDirection, this._typeface, int.Parse(Settings.Default.MonsterFontSize) + fontSizeModifier, (SolidColorBrush)bc.ConvertFromString(fontColor));
                            this.DrawText(drawingContext, text, screen.X + 20, screen.Y);
                        }
                    }
                    catch (Exception ex) {
                        Logging.Log(Logger, new LogItem(ex, true));
                    }

                    drawingContext.Pop();
                }
            }

            #endregion

            #region Resolve NPCs, Gathering & Other

            foreach (ActorItem actorEntity in npcEntites)
            {
                sb.Clear();
                var fontSizeModifier = 0;
                drawingContext.PushOpacity(1);

                try {
                    if (!actorEntity.IsValid || user == null)
                    {
                        continue;
                    }

                    if (actorEntity.ID == user.ID)
                    {
                        continue;
                    }

                    Coordinate screen;
                    if (Settings.Default.RadarCompassMode)
                    {
                        Coordinate coord = user.Coordinate.Subtract(actorEntity.Coordinate).Scale(scale);
                        screen = new Coordinate(-coord.X, 0, -coord.Y).Add(origin);
                    }
                    else
                    {
                        screen = user.Coordinate.Subtract(actorEntity.Coordinate).Rotate2D(user.Heading).Scale(scale).Add(origin);
                    }

                    screen = screen.Add(-8, -8, 0);
                    BitmapImage actorIcon;

                    switch (actorEntity.Type)
                    {
                    case Actor.Type.NPC:

                        #region Resolve NPCs

                        if (Settings.Default.NPCShow)
                        {
                            try {
                                if (Settings.Default.NPCShowName)
                                {
                                    sb.Append(actorEntity.Name);
                                }

                                if (Settings.Default.NPCShowHPPercent)
                                {
                                    sb.AppendFormat(" {0:P0}", actorEntity.HPPercent);
                                }

                                if (Settings.Default.NPCShowDistance)
                                {
                                    sb.AppendFormat(" {0:N2} {1}", user.GetDistanceTo(actorEntity), this.ResolveHeightVariance(user, actorEntity));
                                }

                                actorIcon = actorEntity.HPCurrent > 0
                                                    ? Game.Vendor
                                                    : Game.Unknown;
                                this.DrawImage(drawingContext, actorIcon, new Rect(new Point(screen.X, screen.Y), new Size(16, 16)));

                                this.RenderDebugInformation(actorEntity, ref sb);

                                if (Settings.Default.NPCShowName || Settings.Default.NPCShowHPPercent)
                                {
                                    var text = new FormattedText(sb.ToString(), this._cultureInfo, this._flowDirection, this._typeface, int.Parse(Settings.Default.NPCFontSize) + fontSizeModifier, (SolidColorBrush)bc.ConvertFromString(Settings.Default.NPCFontColor));
                                    this.DrawText(drawingContext, text, screen.X + 20, screen.Y);
                                }
                            }
                            catch (Exception ex) {
                                Logging.Log(Logger, new LogItem(ex, true));
                            }

                            drawingContext.Pop();
                        }

                        #endregion

                        break;

                    case Actor.Type.Gathering:

                        #region Resolve Gathering

                        if (Settings.Default.GatheringShow && actorEntity.GatheringInvisible == 0)
                        {
                            try {
                                if (Settings.Default.GatheringShowName)
                                {
                                    sb.Append(actorEntity.Name);
                                }

                                if (Settings.Default.GatheringShowHPPercent)
                                {
                                    sb.AppendFormat(" {0:P0}", actorEntity.HPPercent);
                                }

                                if (Settings.Default.GatheringShowDistance)
                                {
                                    sb.AppendFormat(" {0:N2} {1}", user.GetDistanceTo(actorEntity), this.ResolveHeightVariance(user, actorEntity));
                                }

                                actorIcon = Game.Gathering;
                                if (Constants.GatheringNodes.TryGetValue(user.Job.ToString(), out List <GatheringNode> node))
                                {
                                    GatheringNode nodeMatch = node.FirstOrDefault(n => n.Localization.Matches(actorEntity.Name));
                                    if (nodeMatch != null)
                                    {
                                        switch (user.Job)
                                        {
                                        case Actor.Job.BTN:
                                            actorIcon = Game.Harvesting;
                                            switch (nodeMatch.Rarity)
                                            {
                                            case GatheringRarity.Unspoiled:
                                            case GatheringRarity.Ephemeral:
                                            case GatheringRarity.Legendary:
                                                actorIcon = Game.HarvestingSuper;
                                                break;
                                            }

                                            break;

                                        case Actor.Job.FSH:
                                            actorIcon = Game.Fishing;
                                            break;

                                        case Actor.Job.MIN:
                                            actorIcon = Game.Mining;
                                            switch (nodeMatch.Rarity)
                                            {
                                            case GatheringRarity.Unspoiled:
                                            case GatheringRarity.Ephemeral:
                                            case GatheringRarity.Legendary:
                                                actorIcon = Game.MiningSuper;
                                                break;
                                            }

                                            break;
                                        }
                                    }
                                }

                                this.DrawImage(drawingContext, actorIcon, new Rect(new Point(screen.X, screen.Y), new Size(16, 16)));

                                this.RenderDebugInformation(actorEntity, ref sb);

                                if (Settings.Default.GatheringShowName || Settings.Default.GatheringShowHPPercent)
                                {
                                    var text = new FormattedText(sb.ToString(), this._cultureInfo, this._flowDirection, this._typeface, int.Parse(Settings.Default.GatheringFontSize) + fontSizeModifier, (SolidColorBrush)bc.ConvertFromString(Settings.Default.GatheringFontColor));
                                    this.DrawText(drawingContext, text, screen.X + 20, screen.Y);
                                }
                            }
                            catch (Exception ex) {
                                Logging.Log(Logger, new LogItem(ex, true));
                            }

                            drawingContext.Pop();
                        }

                        #endregion

                        break;

                    default:

                        #region Resolve Other

                        if (Settings.Default.OtherShow)
                        {
                            try {
                                switch (actorEntity.Type)
                                {
                                case Actor.Type.Aetheryte:
                                    actorIcon = Game.Aetheryte;
                                    break;

                                case Actor.Type.Minion:
                                    actorIcon = Game.Avatar;
                                    break;

                                default:
                                    actorIcon = Game.Vendor;
                                    break;
                                }

                                if (actorEntity.HPCurrent > 0 || actorEntity.Type == Actor.Type.Aetheryte)
                                {
                                    if (actorIcon != null)
                                    {
                                        this.DrawImage(drawingContext, actorIcon, new Rect(new Point(screen.X, screen.Y), new Size(16, 16)));
                                    }
                                }
                                else
                                {
                                    this.DrawImage(drawingContext, Game.Unknown, new Rect(new Point(screen.X, screen.Y), new Size(16, 16)));
                                }

                                if (Settings.Default.OtherShowName)
                                {
                                    sb.Append(actorEntity.Name);
                                }

                                if (Settings.Default.OtherShowHPPercent)
                                {
                                    sb.AppendFormat(" {0:P0}", actorEntity.HPPercent);
                                }

                                if (Settings.Default.OtherShowDistance)
                                {
                                    sb.AppendFormat(" {0:N2} {1}", user.GetDistanceTo(actorEntity), this.ResolveHeightVariance(user, actorEntity));
                                }

                                this.RenderDebugInformation(actorEntity, ref sb);

                                if (Settings.Default.OtherShowName || Settings.Default.OtherShowHPPercent)
                                {
                                    var text = new FormattedText(sb.ToString(), this._cultureInfo, this._flowDirection, this._typeface, int.Parse(Settings.Default.OtherFontSize) + fontSizeModifier, (SolidColorBrush)bc.ConvertFromString(Settings.Default.OtherFontColor));
                                    this.DrawText(drawingContext, text, screen.X + 20, screen.Y);
                                }
                            }
                            catch (Exception ex) {
                                Logging.Log(Logger, new LogItem(ex, true));
                            }

                            drawingContext.Pop();
                        }

                        #endregion

                        break;
                    }
                }
                catch (Exception ex) { }
            }

            #endregion
        }
Ejemplo n.º 14
0
        public static ActorResult GetActors()
        {
            var result = new ActorResult();

            if (!CanGetActors() || !MemoryHandler.Instance.IsAttached)
            {
                return(result);
            }

            try {
                IntPtr targetAddress = IntPtr.Zero;

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

                var    sourceSize          = MemoryHandler.Instance.Structures.ActorItem.SourceSize;
                var    limit               = MemoryHandler.Instance.Structures.ActorItem.EntityCount;
                byte[] characterAddressMap = MemoryHandler.Instance.GetByteArray(Scanner.Instance.Locations[Signatures.CharacterMapKey], endianSize * limit);
                Dictionary <IntPtr, IntPtr> uniqueAddresses = new Dictionary <IntPtr, IntPtr>();
                IntPtr firstAddress = IntPtr.Zero;

                DateTime now = DateTime.Now;

                TimeSpan staleActorRemovalTime = TimeSpan.FromSeconds(0.25);

                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;
                }

                foreach (KeyValuePair <uint, ActorItem> kvp in MonsterWorkerDelegate.ActorItems)
                {
                    result.RemovedMonsters.TryAdd(kvp.Key, kvp.Value.Clone());
                }

                foreach (KeyValuePair <uint, ActorItem> kvp in NPCWorkerDelegate.ActorItems)
                {
                    result.RemovedNPCs.TryAdd(kvp.Key, kvp.Value.Clone());
                }

                foreach (KeyValuePair <uint, ActorItem> kvp in PCWorkerDelegate.ActorItems)
                {
                    result.RemovedPCs.TryAdd(kvp.Key, kvp.Value.Clone());
                }

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

                        // var source = MemoryHandler.Instance.GetByteArray(characterAddress, 0x3F40);
                        var ID     = BitConverter.TryToUInt32(source, MemoryHandler.Instance.Structures.ActorItem.ID);
                        var NPCID2 = BitConverter.TryToUInt32(source, MemoryHandler.Instance.Structures.ActorItem.NPCID2);
                        var Type   = (Actor.Type)source[MemoryHandler.Instance.Structures.ActorItem.Type];

                        ActorItem existing = null;
                        var       newEntry = false;

                        switch (Type)
                        {
                        case Actor.Type.Monster:
                            if (result.RemovedMonsters.ContainsKey(ID))
                            {
                                result.RemovedMonsters.TryRemove(ID, out ActorItem removedMonster);
                                existing = MonsterWorkerDelegate.GetActorItem(ID);
                            }
                            else
                            {
                                newEntry = true;
                            }

                            break;

                        case Actor.Type.PC:
                            if (result.RemovedPCs.ContainsKey(ID))
                            {
                                result.RemovedPCs.TryRemove(ID, out ActorItem removedPC);
                                existing = PCWorkerDelegate.GetActorItem(ID);
                            }
                            else
                            {
                                newEntry = true;
                            }

                            break;

                        case Actor.Type.NPC:
                        case Actor.Type.Aetheryte:
                        case Actor.Type.EventObject:
                            if (result.RemovedNPCs.ContainsKey(NPCID2))
                            {
                                result.RemovedNPCs.TryRemove(NPCID2, out ActorItem removedNPC);
                                existing = NPCWorkerDelegate.GetActorItem(NPCID2);
                            }
                            else
                            {
                                newEntry = true;
                            }

                            break;

                        default:
                            if (result.RemovedNPCs.ContainsKey(ID))
                            {
                                result.RemovedNPCs.TryRemove(ID, out ActorItem removedNPC);
                                existing = NPCWorkerDelegate.GetActorItem(ID);
                            }
                            else
                            {
                                newEntry = true;
                            }

                            break;
                        }

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

                        ActorItem entry = ActorItemResolver.ResolveActorFromBytes(source, isFirstEntry, existing);

                        if (entry != null && entry.IsValid)
                        {
                            if (expiringActors.ContainsKey(ID))
                            {
                                expiringActors.Remove(ID);
                            }
                        }

                        if (entry.Type == Actor.Type.EventObject)
                        {
                            var(EventObjectTypeID, EventObjectType) = GetEventObjectType(targetAddress);
                            entry.EventObjectTypeID = EventObjectTypeID;
                            entry.EventObjectType   = EventObjectType;
                        }

                        EnsureMapAndZone(entry);

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

                        // it doesn't matter what this is set to; it won't be used in code below
                        ActorItem removed;

                        if (!entry.IsValid)
                        {
                            result.NewMonsters.TryRemove(entry.ID, out removed);
                            result.NewMonsters.TryRemove(entry.NPCID2, out removed);
                            result.NewNPCs.TryRemove(entry.ID, out removed);
                            result.NewNPCs.TryRemove(entry.NPCID2, out removed);
                            result.NewPCs.TryRemove(entry.ID, out removed);
                            result.NewPCs.TryRemove(entry.NPCID2, out removed);
                            continue;
                        }

                        if (existing != null)
                        {
                            continue;
                        }

                        if (newEntry)
                        {
                            switch (entry.Type)
                            {
                            case Actor.Type.Monster:
                                MonsterWorkerDelegate.EnsureActorItem(entry.ID, entry);
                                result.NewMonsters.TryAdd(entry.ID, entry.Clone());
                                break;

                            case Actor.Type.PC:
                                PCWorkerDelegate.EnsureActorItem(entry.ID, entry);
                                result.NewPCs.TryAdd(entry.ID, entry.Clone());
                                break;

                            case Actor.Type.Aetheryte:
                            case Actor.Type.EventObject:
                            case Actor.Type.NPC:
                                NPCWorkerDelegate.EnsureActorItem(entry.NPCID2, entry);
                                result.NewNPCs.TryAdd(entry.NPCID2, entry.Clone());
                                break;

                            default:
                                NPCWorkerDelegate.EnsureActorItem(entry.ID, entry);
                                result.NewNPCs.TryAdd(entry.ID, entry.Clone());
                                break;
                            }
                        }
                    }
                    catch (Exception ex) {
                        MemoryHandler.Instance.RaiseException(Logger, ex, true);
                    }
                }

                try {
                    // add the "removed" actors to the expiring list
                    foreach (KeyValuePair <uint, ActorItem> kvp in result.RemovedMonsters)
                    {
                        if (!expiringActors.ContainsKey(kvp.Key))
                        {
                            expiringActors[kvp.Key] = now + staleActorRemovalTime;
                        }
                    }

                    foreach (KeyValuePair <uint, ActorItem> kvp in result.RemovedNPCs)
                    {
                        if (!expiringActors.ContainsKey(kvp.Key))
                        {
                            expiringActors[kvp.Key] = now + staleActorRemovalTime;
                        }
                    }

                    foreach (KeyValuePair <uint, ActorItem> kvp in result.RemovedPCs)
                    {
                        if (!expiringActors.ContainsKey(kvp.Key))
                        {
                            expiringActors[kvp.Key] = now + staleActorRemovalTime;
                        }
                    }

                    // check expiring list for stale actors
                    foreach (var kvp in expiringActors.ToList())
                    {
                        if (now > kvp.Value)
                        {
                            // Stale actor. Remove it.
                            MonsterWorkerDelegate.RemoveActorItem(kvp.Key);
                            NPCWorkerDelegate.RemoveActorItem(kvp.Key);
                            PCWorkerDelegate.RemoveActorItem(kvp.Key);

                            expiringActors.Remove(kvp.Key);
                        }
                        else
                        {
                            // Not stale enough yet. We're not actually removing it.
                            result.RemovedMonsters.TryRemove(kvp.Key, out ActorItem _);
                            result.RemovedNPCs.TryRemove(kvp.Key, out ActorItem _);
                            result.RemovedPCs.TryRemove(kvp.Key, out ActorItem _);
                        }
                    }
                }
                catch (Exception ex) {
                    MemoryHandler.Instance.RaiseException(Logger, ex, true);
                }

                MemoryHandler.Instance.ScanCount++;
            }
            catch (Exception ex) {
                MemoryHandler.Instance.RaiseException(Logger, ex, true);
            }

            return(result);
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
0
        private void SetCell(ItemCell itemCell, int index)
        {
            // Main.Logger.Log(index.ToString() + "设置 itemCell。。。" + itemCell.ToString() + " pos=" + scrollRect.verticalNormalizedPosition.ToString());
            ActorItem item = itemCell as ActorItem;

            if (item == null)
            {
                // Main.Logger.Log("WarehouseItem出错。。。");
                return;
            }
            // Main.Logger.Log("数据长度:" + m_data.Length);
            ChildData[] childDatas = item.childDatas;
            for (int i = 0; i < lineCount; i++)
            {
                int idx = (index - 1) * lineCount + i;
                // Main.Logger.Log("循环" + i + "获取第【" + idx + "】个元素的数据");
                if (i < childDatas.Length)
                {
                    ChildData  childData = childDatas[i];
                    GameObject go        = childData.gameObject;
                    if (idx < m_data.Length)
                    {
                        go.transform.parent.gameObject.SetActive(true);
                        if (!go.activeSelf)
                        {
                            go.SetActive(true);
                        }
                        int num2 = m_data[idx];
                        itemCell.name = "Actor," + num2;
                        // Main.Logger.Log("改名A:" + itemCell.name);
                        if (itemCell.transform.childCount > i)
                        {
                            var child = itemCell.transform.GetChild(i);
                            child.name = "Actor," + num2;
                            // Main.Logger.Log("改名B:" + itemCell.name);
                            //Toggle tog = child.GetComponent<Toggle>();
                            //tog.group = ActorMenu.instance.listActorsHolder.GetComponent<ToggleGroup>();
                            // Main.Logger.Log(ActorMenu.instance.acotrId +" "+ num2 + "判断是否选中:" + (ActorMenu.instance.acotrId == num2));
                            //tog.isOn = ActorMenu.instance.acotrId == num2;
                            if (ActorMenu.instance.acotrId == num2 && ActorMenuActorListPatch.giveActorId == num2)
                            {
                                childData.Select(SelectState.All);
                            }
                            else if (ActorMenu.instance.acotrId == num2)
                            {
                                childData.Select(SelectState.Select);
                            }
                            else if (ActorMenuActorListPatch.giveActorId == num2)
                            {
                                childData.Select(SelectState.Give);
                            }
                            else
                            {
                                childData.Select(SelectState.Node);
                            }
                            Button btn = child.GetComponentInChildren <Button>();
                            btn.onClick.RemoveAllListeners();
                            btn.onClick.AddListener(delegate()
                            {
                                ActorMenu.instance.SetActorAttr(int.Parse(go.name.Split(',')[1]));
                            });
                        }


                        SetListActor component = childData.setListActor;
                        component.SetActor(num2);

                        // Main.Logger.Log("此处是一些处理 不同身份的人处理方式不同");
                        if (!ActorMenu.instance.isEnemy)
                        {
                            if (num2 == DateFile.instance.MianActorID())
                            {
                                // Main.Logger.Log("主角");
                                component.SetInTeamIcon(true);
                                component.SetInBuildingIcon(false);
                                component.RestMoodFace();
                                component.listActorFavorText.text   = "";
                                component.listActorSamsaraText.text = "";
                            }
                            else if (DateFile.instance.acotrTeamDate.Contains(num2))
                            {
                                // Main.Logger.Log("是出战队员");
                                component.SetInTeamIcon(true);
                                component.SetInBuildingIcon(false);
                                component.RestMoodFace();
                            }
                            else if (DateFile.instance.ParseInt(DateFile.instance.GetActorDate(num2, 27, addValue: false)) == 1)
                            {
                                // Main.Logger.Log("不知道是啥");
                                component.SetInTeamIcon(false);
                                component.SetInBuildingIcon(false);
                                component.RestMoodFace();
                            }
                            else if (DateFile.instance.ActorIsWorking(num2) != null)
                            {
                                // Main.Logger.Log("正在工作的?");
                                component.SetInTeamIcon(false);
                                component.SetInBuildingIcon(true);
                                component.RestMoodFace();
                            }
                            else
                            {
                                // Main.Logger.Log("其他");
                                component.SetInTeamIcon(false);
                                component.SetInBuildingIcon(false);
                                component.RestMoodFace();
                            }
                        }
                        else
                        {
                            // Main.Logger.Log("敌人");
                            component.SetInTeamIcon(false);
                            component.SetInBuildingIcon(false);
                            component.RestMoodFace();
                        }
                    }
                    else
                    {
                        if (go.activeSelf)
                        {
                            go.SetActive(false);
                        }
                    }
                    if (i == 0 && !go.transform.parent.gameObject.activeSelf)
                    {
                        go.transform.parent.gameObject.SetActive(true);
                    }
                }
                else
                {
                    // Main.Logger.Log("数据出错。。。");
                }
                // Main.Logger.Log("人物设置完毕");
            }
        }
Ejemplo n.º 17
0
        public void ReadFromFile(BinaryReader reader)
        {
            int poolLength = reader.ReadInt32();

            pool = new string(reader.ReadChars(poolLength));

            int hashesLength = reader.ReadInt32();

            definitions = new ActorDefinition[hashesLength];

            for (int i = 0; i != hashesLength; i++)
            {
                definitions[i] = new ActorDefinition(reader);
                int pos = definitions[i].NamePos;
                definitions[i].name = pool.Substring(pos, pool.IndexOf('\0', pos) - pos);
            }

            filesize = reader.ReadInt32();
            const6   = reader.ReadInt16();
            const2   = reader.ReadInt16();
            const16  = reader.ReadInt32();
            size     = reader.ReadInt32(); //size of sector end.
            unk12    = reader.ReadInt32();
            unk13    = reader.ReadInt32();

            //if (const2 != 2)
            //    throw new Exception("const_6 is not 6");

            //if (const6 != 6)
            //    throw new Exception("const_2 is not 2");

            //if (const16 != 16)
            //    throw new Exception("const_16 is not 16");

            unk14 = reader.ReadInt32();

            if (const2 == 2)
            {
                int newpos = (unk14 / 4 - 2) * 4;
                if (unk14 - 8 != newpos)
                {
                    throw new FormatException("unk14-8 != newpos");
                }

                int count = (unk14 - 8) / sizeof(int);
                reader.BaseStream.Seek(unk14 - 12, SeekOrigin.Current);
                temp_Unks = new temp_unk[count];
                for (int i = 0; i < count; i++)
                {
                    temp_Unks[i] = new temp_unk(reader);
                }
            }
            else
            {
                unk02 = reader.ReadBytes(size - unk14);
            }

            int itemCount = reader.ReadInt32();

            reader.BaseStream.Seek(itemCount * 4, SeekOrigin.Current);

            items = new ActorItem[itemCount];
            for (int i = 0; i != itemCount; i++)
            {
                items[i]      = new ActorItem(reader);
                items[i].Data = TempUnks[items[i].DataID];
            }

            unk16 = reader.ReadInt32();

            //if (unk16 != 0)
            //    throw new Exception("UNK16 is not 0. Message Greavesy with this message and the name of the SDS you tried to read");
        }
Ejemplo n.º 18
0
        private void UpdateActors()
        {
            if (scannerState != ScannerState.Ready)
            {
                return;
            }

            try
            {
                actorScanPass++;
                bool hasChanges = false;

                long TableReadAddr = MemoryLayout.memPathActors.GetResolvedAddress();
                if (TableReadAddr != 0)
                {
                    List <long> KnownAddr = new List <long>();
                    for (long ActorIdx = 0; ActorIdx < 500; ActorIdx++, TableReadAddr += 8)
                    {
                        long ActorAddr = memoryScanner.ReadPointer(TableReadAddr);
                        if (ActorAddr != 0 && !KnownAddr.Contains(ActorAddr))
                        {
                            byte[] entryData = memoryScanner.ReadBytes(ActorAddr, MemoryLayout.ActorConsts.Size);
                            if (entryData != null)
                            {
                                KnownAddr.Add(ActorAddr);

                                ActorItem entryActor = new ActorItem();
                                entryActor.SetIdOnly(entryData);

                                bool bFound = false;
                                for (int ExistingIdx = 0; ExistingIdx < listActors.Count; ExistingIdx++)
                                {
                                    if (listActors[ExistingIdx].UniqueId == entryActor.UniqueId)
                                    {
                                        entryActor = listActors[ExistingIdx];
                                        bFound     = true;
                                    }
                                }

                                if (!bFound)
                                {
                                    listActors.Add(entryActor);
                                    hasChanges = true;
                                }

                                entryActor.SetDataOnly(entryData);
                                entryActor.LastScanPass = actorScanPass;
                                entryActor.Distance     = Vector3.Distance(entryActor.Position, camera.Position);

/*                                if (entryActor.Type == MemoryLayout.ActorType.Interaction || entryActor.Type == MemoryLayout.ActorType.Gathering)
 *                              {
 *                                  Logger.WriteLine("[" + actorScanPass + "] Name:" + entryActor.Name + ", Id:" + entryActor.ShowActorId + ", Flags: 0x" + entryActor.Flags.ToString("x2") + (entryActor.OverlaySettings.IsHighlighted ? " (SELECTED)" : ""));
 *                              }*/
                            }
                        }
                    }
                }

                for (int Idx = listActors.Count - 1; Idx >= 0; Idx--)
                {
                    if (listActors[Idx].LastScanPass != actorScanPass)
                    {
                        listActors.RemoveAt(Idx);
                        hasChanges = true;
                    }
                }

                if (hasChanges)
                {
                    OnActorListChanged?.Invoke();
                }
            }
            catch (Exception) { }
        }
Ejemplo n.º 19
0
        public static PartyMember ResolvePartyMemberFromBytes(byte[] source, ActorItem actorItem = null)
        {
            if (actorItem != null)
            {
                var entry = 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,
                    MPMax      = actorItem.MPMax
                };
                entry.StatusItems.AddRange(actorItem.StatusItems);
                CleanXPValue(ref entry);
                return(entry);
            }
            else
            {
                var defaultStatusEffectOffset = MemoryHandler.Instance.Structures.PartyMember.DefaultStatusEffectOffset;
                var entry = new PartyMember();
                try {
                    entry.X          = BitConverter.TryToSingle(source, MemoryHandler.Instance.Structures.PartyMember.X);
                    entry.Z          = BitConverter.TryToSingle(source, MemoryHandler.Instance.Structures.PartyMember.Z);
                    entry.Y          = BitConverter.TryToSingle(source, MemoryHandler.Instance.Structures.PartyMember.Y);
                    entry.Coordinate = new Coordinate(entry.X, entry.Z, entry.Z);
                    entry.ID         = BitConverter.TryToUInt32(source, MemoryHandler.Instance.Structures.PartyMember.ID);
                    entry.UUID       = Guid.NewGuid().ToString();
                    entry.Name       = MemoryHandler.Instance.GetStringFromBytes(source, MemoryHandler.Instance.Structures.PartyMember.Name);
                    entry.JobID      = source[MemoryHandler.Instance.Structures.PartyMember.Job];
                    entry.Job        = (Actor.Job)entry.JobID;

                    entry.Level     = source[MemoryHandler.Instance.Structures.PartyMember.Level];
                    entry.HPCurrent = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.PartyMember.HPCurrent);
                    entry.HPMax     = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.PartyMember.HPMax);
                    entry.MPCurrent = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PartyMember.MPCurrent);
                    entry.MPMax     = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.PartyMember.MPMax);
                    const int limit          = 15;
                    const int statusSize     = 12;
                    byte[]    statusesSource = new byte[limit * statusSize];

                    Buffer.BlockCopy(source, defaultStatusEffectOffset, statusesSource, 0, limit * 12);
                    for (var i = 0; i < limit; i++)
                    {
                        byte[] statusSource = new byte[statusSize];
                        Buffer.BlockCopy(statusesSource, i * statusSize, statusSource, 0, statusSize);
                        var statusEntry = new StatusItem {
                            TargetName = entry.Name,
                            StatusID   = BitConverter.TryToInt16(statusSource, MemoryHandler.Instance.Structures.StatusItem.StatusID),
                            Stacks     = statusSource[MemoryHandler.Instance.Structures.StatusItem.Stacks],
                            Duration   = BitConverter.TryToSingle(statusSource, MemoryHandler.Instance.Structures.StatusItem.Duration),
                            CasterID   = BitConverter.TryToUInt32(statusSource, MemoryHandler.Instance.Structures.StatusItem.CasterID)
                        };
                        try {
                            ActorItem pc      = PCWorkerDelegate.GetActorItem(statusEntry.CasterID);
                            ActorItem npc     = NPCWorkerDelegate.GetActorItem(statusEntry.CasterID);
                            ActorItem monster = MonsterWorkerDelegate.GetActorItem(statusEntry.CasterID);
                            statusEntry.SourceEntity = (pc ?? npc) ?? monster;
                        }
                        catch (Exception ex) {
                            MemoryHandler.Instance.RaiseException(Logger, ex, true);
                        }

                        try {
                            if (statusEntry.StatusID > 0)
                            {
                                Models.XIVDatabase.StatusItem statusInfo = StatusEffectLookup.GetStatusInfo((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.StatusItems.Add(statusEntry);
                        }
                    }
                }
                catch (Exception ex) {
                    MemoryHandler.Instance.RaiseException(Logger, ex, true);
                }

                CleanXPValue(ref entry);
                return(entry);
            }
        }
Ejemplo n.º 20
0
        public static ActorItem ResolveActorFromBytes(byte[] source, bool isCurrentUser = false, ActorItem entry = null)
        {
            entry = entry ?? new ActorItem();
            var defaultBaseOffset         = MemoryHandler.Instance.Structures.ActorItem.DefaultBaseOffset;
            var defaultStatOffset         = MemoryHandler.Instance.Structures.ActorItem.DefaultStatOffset;
            var defaultStatusEffectOffset = MemoryHandler.Instance.Structures.ActorItem.DefaultStatusEffectOffset;

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

                entry.TargetTypeID = source[MemoryHandler.Instance.Structures.ActorItem.TargetType];
                entry.TargetType   = (Actor.TargetType)entry.TargetTypeID;

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

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

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

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

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

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

                entry.Level            = source[MemoryHandler.Instance.Structures.ActorItem.Level + defaultStatOffset];
                entry.GrandCompany     = source[MemoryHandler.Instance.Structures.ActorItem.GrandCompany + defaultStatOffset];
                entry.GrandCompanyRank = source[MemoryHandler.Instance.Structures.ActorItem.GrandCompanyRank + defaultStatOffset];
                entry.Title            = source[MemoryHandler.Instance.Structures.ActorItem.Title + defaultStatOffset];
                entry.HPCurrent        = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.ActorItem.HPCurrent + defaultStatOffset);
                entry.HPMax            = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.ActorItem.HPMax + defaultStatOffset);
                entry.MPCurrent        = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.ActorItem.MPCurrent + defaultStatOffset);
                entry.MPMax            = BitConverter.TryToInt32(source, MemoryHandler.Instance.Structures.ActorItem.MPMax + defaultStatOffset);
                entry.TPCurrent        = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.ActorItem.TPCurrent + defaultStatOffset);
                entry.TPMax            = 1000;
                entry.GPCurrent        = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.ActorItem.GPCurrent + defaultStatOffset);
                entry.GPMax            = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.ActorItem.GPMax + defaultStatOffset);
                entry.CPCurrent        = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.ActorItem.CPCurrent + defaultStatOffset);
                entry.CPMax            = BitConverter.TryToInt16(source, MemoryHandler.Instance.Structures.ActorItem.CPMax + defaultStatOffset);

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

                int    statusSize     = MemoryHandler.Instance.Structures.StatusItem.SourceSize;
                byte[] statusesSource = new byte[limit * statusSize];

                List <StatusItem> foundStatuses = new List <StatusItem>();

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

                    byte[] statusSource = new byte[statusSize];
                    Buffer.BlockCopy(statusesSource, i * statusSize, statusSource, 0, statusSize);

                    short StatusID = BitConverter.TryToInt16(statusSource, MemoryHandler.Instance.Structures.StatusItem.StatusID);
                    uint  CasterID = BitConverter.TryToUInt32(statusSource, MemoryHandler.Instance.Structures.StatusItem.CasterID);

                    var 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       = statusSource[MemoryHandler.Instance.Structures.StatusItem.Stacks];
                    statusEntry.Duration     = BitConverter.TryToSingle(statusSource, MemoryHandler.Instance.Structures.StatusItem.Duration);
                    statusEntry.CasterID     = CasterID;



                    try {
                        ActorItem pc      = PCWorkerDelegate.GetActorItem(statusEntry.CasterID);
                        ActorItem npc     = NPCWorkerDelegate.GetActorItem(statusEntry.CasterID);
                        ActorItem monster = MonsterWorkerDelegate.GetActorItem(statusEntry.CasterID);
                        statusEntry.SourceEntity = (pc ?? npc) ?? monster;
                    }
                    catch (Exception ex) {
                        MemoryHandler.Instance.RaiseException(Logger, ex, true);
                    }

                    try {
                        Models.XIVDatabase.StatusItem statusInfo = StatusEffectLookup.GetStatusInfo((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())
                    {
                        if (isNewStatus)
                        {
                            entry.StatusItems.Add(statusEntry);
                        }
                        foundStatuses.Add(statusEntry);
                    }
                }

                entry.StatusItems.RemoveAll(x => !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) {
                MemoryHandler.Instance.RaiseException(Logger, ex, true);
            }

            CleanXPValue(ref entry);

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

            return(entry);
        }
Ejemplo n.º 21
0
        public static TargetResult GetTargetInfo()
        {
            var result = new TargetResult();

            if (!CanGetTargetInfo() || !MemoryHandler.Instance.IsAttached)
            {
                return(result);
            }

            try {
                var targetAddress = (IntPtr)Scanner.Instance.Locations[Signatures.TargetKey];

                if (targetAddress.ToInt64() > 0)
                {
                    byte[] targetInfoSource = MemoryHandler.Instance.GetByteArray(targetAddress, MemoryHandler.Instance.Structures.TargetInfo.SourceSize);

                    var currentTarget   = MemoryHandler.Instance.GetPlatformIntFromBytes(targetInfoSource, MemoryHandler.Instance.Structures.TargetInfo.Current);
                    var mouseOverTarget = MemoryHandler.Instance.GetPlatformIntFromBytes(targetInfoSource, MemoryHandler.Instance.Structures.TargetInfo.MouseOver);
                    var focusTarget     = MemoryHandler.Instance.GetPlatformIntFromBytes(targetInfoSource, MemoryHandler.Instance.Structures.TargetInfo.Focus);
                    var previousTarget  = MemoryHandler.Instance.GetPlatformIntFromBytes(targetInfoSource, MemoryHandler.Instance.Structures.TargetInfo.Previous);

                    var currentTargetID = BitConverter.TryToUInt32(targetInfoSource, MemoryHandler.Instance.Structures.TargetInfo.CurrentID);

                    if (currentTarget > 0)
                    {
                        try {
                            ActorItem entry = GetTargetActorItemFromSource(currentTarget);
                            currentTargetID = entry.ID;
                            if (entry.IsValid)
                            {
                                result.TargetsFound             = true;
                                result.TargetInfo.CurrentTarget = entry;
                            }
                        }
                        catch (Exception ex) {
                            MemoryHandler.Instance.RaiseException(Logger, ex, true);
                        }
                    }

                    if (mouseOverTarget > 0)
                    {
                        try {
                            ActorItem entry = GetTargetActorItemFromSource(mouseOverTarget);
                            if (entry.IsValid)
                            {
                                result.TargetsFound = true;
                                result.TargetInfo.MouseOverTarget = entry;
                            }
                        }
                        catch (Exception ex) {
                            MemoryHandler.Instance.RaiseException(Logger, ex, true);
                        }
                    }

                    if (focusTarget > 0)
                    {
                        try {
                            ActorItem entry = GetTargetActorItemFromSource(focusTarget);
                            if (entry.IsValid)
                            {
                                result.TargetsFound           = true;
                                result.TargetInfo.FocusTarget = entry;
                            }
                        }
                        catch (Exception ex) {
                            MemoryHandler.Instance.RaiseException(Logger, ex, true);
                        }
                    }

                    if (previousTarget > 0)
                    {
                        try {
                            ActorItem entry = GetTargetActorItemFromSource(previousTarget);
                            if (entry.IsValid)
                            {
                                result.TargetsFound = true;
                                result.TargetInfo.PreviousTarget = entry;
                            }
                        }
                        catch (Exception ex) {
                            MemoryHandler.Instance.RaiseException(Logger, ex, true);
                        }
                    }

                    if (currentTargetID > 0)
                    {
                        result.TargetsFound = true;
                        result.TargetInfo.CurrentTargetID = currentTargetID;
                    }
                }

                if (result.TargetInfo.CurrentTargetID > 0)
                {
                    try {
                        if (CanGetEnmityEntities())
                        {
                            var enmityCount     = MemoryHandler.Instance.GetInt16(Scanner.Instance.Locations[Signatures.EnmityCountKey]);
                            var enmityStructure = (IntPtr)Scanner.Instance.Locations[Signatures.EnmityMapKey];

                            if (enmityCount > 0 && enmityCount < 16 && enmityStructure.ToInt64() > 0)
                            {
                                var enmitySourceSize = MemoryHandler.Instance.Structures.EnmityItem.SourceSize;
                                for (uint i = 0; i < enmityCount; i++)
                                {
                                    try {
                                        var address     = new IntPtr(enmityStructure.ToInt64() + i * enmitySourceSize);
                                        var enmityEntry = new EnmityItem {
                                            ID = (uint)MemoryHandler.Instance.GetPlatformInt(address, MemoryHandler.Instance.Structures.EnmityItem.ID),
                                            // Name = MemoryHandler.Instance.GetString(address + MemoryHandler.Instance.Structures.EnmityItem.Name),
                                            Enmity = MemoryHandler.Instance.GetUInt32(address + MemoryHandler.Instance.Structures.EnmityItem.Enmity),
                                        };
                                        if (enmityEntry.ID <= 0)
                                        {
                                            continue;
                                        }

                                        if (string.IsNullOrWhiteSpace(enmityEntry.Name))
                                        {
                                            ActorItem pc      = PCWorkerDelegate.GetActorItem(enmityEntry.ID);
                                            ActorItem npc     = NPCWorkerDelegate.GetActorItem(enmityEntry.ID);
                                            ActorItem monster = MonsterWorkerDelegate.GetActorItem(enmityEntry.ID);
                                            try {
                                                enmityEntry.Name = (pc ?? npc).Name ?? monster.Name;
                                            }
                                            catch (Exception ex) {
                                                MemoryHandler.Instance.RaiseException(Logger, ex, true);
                                            }
                                        }

                                        result.TargetInfo.EnmityItems.Add(enmityEntry);
                                    }
                                    catch (Exception ex) {
                                        MemoryHandler.Instance.RaiseException(Logger, ex, true);
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex) {
                        MemoryHandler.Instance.RaiseException(Logger, ex, true);
                    }
                }
            }
            catch (Exception ex) {
                MemoryHandler.Instance.RaiseException(Logger, ex, true);
            }

            return(result);
        }
Ejemplo n.º 22
0
 public static void EnsureActorItem(uint key, ActorItem entity)
 {
     ActorItems.AddOrUpdate(key, entity, (k, v) => entity);
 }
Ejemplo n.º 23
0
        public async Task Execute()
        {
            IList <IEventActionExecuteHandler> eaeh = EventCenter.ExecuteHandlers;

            ActionFilterAttribute[] filters = Handler.Filters;
            int  index     = 0;
            bool _continue = true;
            int  subindex  = 0;

            try
            {
                if (Controller is IActorState state)
                {
                    state.Token     = Input.Token;
                    state.EventPath = Input.EventPath;
                    if (ActorItem != null)
                    {
                        state.Sequence = ActorItem.GetSequence();
                    }
                }
                if (EventCenter.EnabledLog(LogType.Debug))
                {
                    EventCenter.Log(LogType.Debug, $"[{Input.ID}]{Input.Token} process event {Input.EventPath} beginning invoke method");
                }
                EventCenter.EventActionContext = this;
                for (int i = 0; i < eaeh.Count; i++)
                {
                    _continue = eaeh[i].Executing(EventCenter, Handler, Input, mEventOutput);
                    index++;
                    if (!_continue)
                    {
                        break;
                    }
                }
                for (int i = 0; i < filters.Length; i++)
                {
                    _continue = filters[i].Executing(EventCenter, Handler, Input, mEventOutput);
                    subindex++;
                    if (!_continue)
                    {
                        break;
                    }
                }
                if (_continue)
                {
                    var result = Handler.MethodHandler.Execute(Controller, Input.Data);
                    if (result is Task task)
                    {
                        await task;
                    }
                    object data = Handler.GetResult(result);
                    mEventOutput.EventError = EventError.Success;
                    if (data != null)
                    {
                        mEventOutput.Data = new object[] { data }
                    }
                    ;
                    if (EventCenter.EnabledLog(LogType.Debug))
                    {
                        EventCenter.Log(LogType.Debug, $"[{Input.ID}]{Input.Token} process event {Input.EventPath} invoke method completed");
                    }
                }
            }
            catch (Exception e_)
            {
                mEventOutput.EventError = EventError.InnerError;
                mEventOutput.Data       = new object[] { $"Process event {Input.EventPath} error {e_.Message}" };
                if (EventCenter.EnabledLog(LogType.Error))
                {
                    EventCenter.Log(LogType.Error, $"[{Input.ID}]{Input.Token} process event {Input.EventPath} invoke method error {e_.Message}@{e_.StackTrace}");
                }
            }
            finally
            {
                for (int i = subindex - 1; i >= 0; i--)
                {
                    try
                    {
                        filters[i].Executed(EventCenter, Handler, Input, mEventOutput);
                    }
                    catch (Exception e_)
                    {
                        if (EventCenter.EnabledLog(LogType.Error))
                        {
                            EventCenter.Log(LogType.Error, $"[{Input.ID}]{Input.Token} process event {Input.EventPath} filter invoke executed error {e_.Message}@{e_.StackTrace}");
                        }
                    }
                }

                for (int i = index - 1; i >= 0; i--)
                {
                    try
                    {
                        eaeh[i].Executed(EventCenter, Handler, Input, mEventOutput);
                    }
                    catch (Exception e_)
                    {
                        if (EventCenter.EnabledLog(LogType.Error))
                        {
                            EventCenter.Log(LogType.Error, $"[{Input.ID}]{Input.Token} process event {Input.EventPath} invoke executed handler error {e_.Message}@{e_.StackTrace}");
                        }
                    }
                }

                mEventCompleted.Completed(mEventOutput);
            }
        }