public void RaiseNewNPCEntries(List <ActorEntity> actorEntities) { if (!actorEntities.Any()) { return; } NPCWorkerDelegate.ReplaceNPCEntities(new List <ActorEntity>(actorEntities)); Func <bool> saveToDictionary = delegate { try { var enumerable = NPCWorkerDelegate.GetUniqueNPCEntities(); foreach (var actor in actorEntities) { var exists = enumerable.FirstOrDefault(n => n.NPCID2 == actor.NPCID2); if (exists != null) { continue; } NPCWorkerDelegate.AddUniqueNPCEntity(actor); } } catch (Exception ex) { } return(true); }; saveToDictionary.BeginInvoke(null, saveToDictionary); // THIRD PARTY PluginHost.Instance.RaiseNewNPCEntries(actorEntities); }
private static void OnNewNPCEntries(object sender, ActorEntitiesEvent actorEntitiesEvent) { // delegate event from npc entities from ram, not required to subsribe // this list includes anything that is not a player or monster // this updates 10x a second and only sends data if the items are found in ram // currently there no change/new/removed event handling (looking into it) if (sender == null) { return; } var npcEntities = actorEntitiesEvent.ActorEntities; if (!npcEntities.Any()) { return; } NPCWorkerDelegate.ReplaceNPCEntities(new List <ActorEntity>(npcEntities)); Func <bool> saveToDictionary = delegate { try { var enumerable = NPCWorkerDelegate.GetUniqueNPCEntities(); foreach (var actor in npcEntities) { var exists = enumerable.FirstOrDefault(n => n.NPCID2 == actor.NPCID2); if (exists != null) { continue; } NPCWorkerDelegate.AddUniqueNPCEntity(actor); } } catch (Exception ex) { } return(true); }; saveToDictionary.BeginInvoke(null, saveToDictionary); }
/// <summary> /// </summary> /// <param name="sender"> </param> /// <param name="e"> </param> private void ScanTimerElapsed(object sender, ElapsedEventArgs e) { if (_isScanning) { return; } _isScanning = true; double refresh = 100; if (Double.TryParse(Settings.Default.TargetWorkerRefresh.ToString(CultureInfo.InvariantCulture), out refresh)) { _scanTimer.Interval = refresh; } Func <bool> scannerWorker = delegate { if (MemoryHandler.Instance.SigScanner.Locations.ContainsKey("GAMEMAIN")) { if (MemoryHandler.Instance.SigScanner.Locations.ContainsKey("CHARMAP")) { try { uint targetHateStructure; switch (Settings.Default.GameLanguage) { case "Chinese": targetHateStructure = MemoryHandler.Instance.SigScanner.Locations["CHARMAP"] + 1136; break; default: targetHateStructure = MemoryHandler.Instance.SigScanner.Locations["CHARMAP"] - 120664; break; } var enmityEntries = new List <EnmityEntry>(); var targetEntity = new TargetEntity(); if (MemoryHandler.Instance.SigScanner.Locations.ContainsKey("TARGET")) { var targetAddress = MemoryHandler.Instance.SigScanner.Locations["TARGET"]; var somethingFound = false; if (targetAddress > 0) { //var targetInfo = MemoryHandler.Instance.GetStructure<Structures.Target>(targetAddress); uint currentTarget; uint mouseOverTarget; uint focusTarget; uint previousTarget; uint currentTargetID; var targetInfoSource = MemoryHandler.Instance.GetByteArray(targetAddress, 128); switch (Settings.Default.GameLanguage) { case "Chinese": currentTarget = BitConverter.ToUInt32(targetInfoSource, 0x0); mouseOverTarget = BitConverter.ToUInt32(targetInfoSource, 0x18); focusTarget = BitConverter.ToUInt32(targetInfoSource, 0x48); previousTarget = BitConverter.ToUInt32(targetInfoSource, 0x54); currentTargetID = BitConverter.ToUInt32(targetInfoSource, 0x68); break; default: currentTarget = BitConverter.ToUInt32(targetInfoSource, 0x0); mouseOverTarget = BitConverter.ToUInt32(targetInfoSource, 0xC); focusTarget = BitConverter.ToUInt32(targetInfoSource, 0x3C); previousTarget = BitConverter.ToUInt32(targetInfoSource, 0x48); currentTargetID = BitConverter.ToUInt32(targetInfoSource, 0x5C); break; } if (currentTarget > 0) { try { var source = MemoryHandler.Instance.GetByteArray(currentTarget, 0x3F40); var entry = ActorEntityHelper.ResolveActorFromBytes(source); if (MemoryHandler.Instance.SigScanner.Locations.ContainsKey("MAP")) { try { entry.MapIndex = MemoryHandler.Instance.GetUInt32(MemoryHandler.Instance.SigScanner.Locations["MAP"]); } catch (Exception ex) { } } if (entry.IsValid) { somethingFound = true; targetEntity.CurrentTarget = entry; } } catch (Exception ex) { } } if (mouseOverTarget > 0) { try { var source = MemoryHandler.Instance.GetByteArray(mouseOverTarget, 0x3F40); var entry = ActorEntityHelper.ResolveActorFromBytes(source); if (MemoryHandler.Instance.SigScanner.Locations.ContainsKey("MAP")) { try { entry.MapIndex = MemoryHandler.Instance.GetUInt32(MemoryHandler.Instance.SigScanner.Locations["MAP"]); } catch (Exception ex) { } } if (entry.IsValid) { somethingFound = true; targetEntity.MouseOverTarget = entry; } } catch (Exception ex) { } } if (focusTarget > 0) { var source = MemoryHandler.Instance.GetByteArray(focusTarget, 0x3F40); var entry = ActorEntityHelper.ResolveActorFromBytes(source); if (MemoryHandler.Instance.SigScanner.Locations.ContainsKey("MAP")) { try { entry.MapIndex = MemoryHandler.Instance.GetUInt32(MemoryHandler.Instance.SigScanner.Locations["MAP"]); } catch (Exception ex) { } } if (entry.IsValid) { somethingFound = true; targetEntity.FocusTarget = entry; } } if (previousTarget > 0) { try { var source = MemoryHandler.Instance.GetByteArray(previousTarget, 0x3F40); var entry = ActorEntityHelper.ResolveActorFromBytes(source); if (MemoryHandler.Instance.SigScanner.Locations.ContainsKey("MAP")) { try { entry.MapIndex = MemoryHandler.Instance.GetUInt32(MemoryHandler.Instance.SigScanner.Locations["MAP"]); } catch (Exception ex) { } } if (entry.IsValid) { somethingFound = true; targetEntity.PreviousTarget = entry; } } catch (Exception ex) { } } if (currentTargetID > 0) { somethingFound = true; targetEntity.CurrentTargetID = currentTargetID; } } if (targetEntity.CurrentTargetID > 0) { for (uint i = 0; i < 16; i++) { var address = targetHateStructure + (i * 72); var enmityEntry = new EnmityEntry { ID = (uint)MemoryHandler.Instance.GetInt32(address), Enmity = (uint)MemoryHandler.Instance.GetInt32(address, 4) }; if (enmityEntry.ID <= 0) { continue; } if (PCWorkerDelegate.GetUniqueNPCEntities() .Any()) { if (PCWorkerDelegate.GetUniqueNPCEntities() .Any(a => a.ID == enmityEntry.ID)) { enmityEntry.Name = PCWorkerDelegate.GetUniqueNPCEntities() .First(a => a.ID == enmityEntry.ID) .Name; } } if (String.IsNullOrWhiteSpace(enmityEntry.Name)) { if (NPCWorkerDelegate.GetUniqueNPCEntities() .Any()) { if (NPCWorkerDelegate.GetUniqueNPCEntities() .Any(a => a.ID == enmityEntry.ID)) { enmityEntry.Name = NPCWorkerDelegate.GetUniqueNPCEntities() .First(a => a.NPCID2 == enmityEntry.ID) .Name; } } } if (String.IsNullOrWhiteSpace(enmityEntry.Name)) { if (MonsterWorkerDelegate.GetUniqueNPCEntities() .Any()) { if (MonsterWorkerDelegate.GetUniqueNPCEntities() .Any(a => a.ID == enmityEntry.ID)) { enmityEntry.Name = MonsterWorkerDelegate.GetUniqueNPCEntities() .First(a => a.ID == enmityEntry.ID) .Name; } } } enmityEntries.Add(enmityEntry); } } targetEntity.EnmityEntries = enmityEntries; if (somethingFound) { AppContextHelper.Instance.RaiseNewTargetEntity(targetEntity); } } } catch (Exception ex) { } } } _isScanning = false; return(true); }; scannerWorker.BeginInvoke(delegate { }, scannerWorker); }