private async Task Watch() { await Task.Delay(500); IInjectionService injection = App.Services.Get <IInjectionService>(); while (this.IsAlive) { try { await Task.Delay(1000); Selection.Modes mode = this.GetMode(); IBaseMemoryOffset baseOffset = mode == Selection.Modes.GPose ? Offsets.Gpose : Offsets.Target; ActorTypes type = baseOffset.GetValue(Offsets.ActorType); string name = baseOffset.GetValue(Offsets.Name); // Hide name while debugging #if DEBUG name = "Tester"; #endif string actorId = mode.ToString() + "_" + name; if (string.IsNullOrEmpty(actorId)) { this.CurrentGameTarget = null; continue; } if (this.CurrentGameTarget == null || this.CurrentGameTarget.Type != type || this.CurrentGameTarget.ActorId != actorId || this.CurrentGameTarget.Mode != mode) { this.CurrentGameTarget = new Selection(type, baseOffset, actorId, name, mode); } if (this.UseGameTarget && this.CurrentSelection != this.CurrentGameTarget) { this.CurrentSelection = this.CurrentGameTarget; } } catch (MemoryException) { // If the user has _never_ selected anything in game, then the memory wont be read correctly. // once the user has selected something, even if they then select nothing, the memory will work // fine, leaving the old selected behind. // so in this case, we just swallow the error, and let the thread loop. } catch (Exception ex) { Log.Write(ex); } } }
private void GetEntities() { try { Selection.Modes mode = this.selection.GetMode(); ActorTableOffset actorTableOffset; BaseOffset targetOffset; // clear the entity list this.Entities.Clear(); if (mode == Selection.Modes.GPose) { actorTableOffset = Offsets.GposeActorTable; targetOffset = Offsets.Gpose; } else if (mode == Selection.Modes.Overworld) { actorTableOffset = Offsets.ActorTable; targetOffset = Offsets.Target; } else { throw new Exception("Unknown selection mode: " + mode); } byte count = actorTableOffset.GetCount(); HashSet <string> ids = new HashSet <string>(); for (byte i = 0; i < count; i++) { ActorTypes type = actorTableOffset.GetActorValue(i, Offsets.ActorType); string name = actorTableOffset.GetActorValue(i, Offsets.Name); string id = mode.ToString() + "_" + type + "_" + name; if (ids.Contains(id)) { continue; } ids.Add(id); if (string.IsNullOrEmpty(name)) { name = "Unknown"; } PossibleSelection selection = new PossibleSelection(type, targetOffset, id, name, mode); selection.IsSelected = !this.selection.UseGameTarget && this.selection.CurrentSelection != null && this.selection.CurrentSelection.Name == name; this.Entities.Add(selection); } this.AutoRadio.IsChecked = this.selection.UseGameTarget; if (this.selection.CurrentGameTarget != null) { this.InGameSelection = this.selection.CurrentGameTarget.Name; this.InGameIcon = this.selection.CurrentGameTarget.Type.GetIcon(); } else { this.InGameSelection = null; this.InGameIcon = IconChar.None; } } catch (Exception ex) { Log.Write(ex); } }