Esempio n. 1
0
            private void Retarget()
            {
                if (this.viewModel != null)
                {
                    this.viewModel.PropertyChanged += this.OnViewModelPropertyChanged;
                }

                this.viewModel = null;

                List <ActorTableActor> actors = TargetService.GetActors();

                foreach (ActorTableActor actor in actors)
                {
                    if (actor.Name == this.Name && actor.Pointer != null)
                    {
                        ActorViewModel vm = new ActorViewModel((IntPtr)actor.Pointer);

                        // Handle case where multiple actor table entries point ot the same actor, but
                        // its not the actor we actually want.
                        if (vm.Id != this.Id)
                        {
                            continue;
                        }

                        this.Pointer   = actor.Pointer;
                        this.Model     = actor.Model;
                        this.viewModel = vm;
                        this.viewModel.PropertyChanged += this.OnViewModelPropertyChanged;
                    }
                }

                this.IsValid = this.viewModel != null;
            }
Esempio n. 2
0
            private void Retarget()
            {
                lock (this)
                {
                    if (this.viewModel != null)
                    {
                        this.viewModel.PropertyChanged -= this.OnViewModelPropertyChanged;
                    }

                    List <ActorTableActor> actors = TargetService.GetActors();
                    bool found = false;
                    foreach (ActorTableActor actor in actors)
                    {
                        if (actor.Id == this.Id && actor.Pointer != null)
                        {
                            // Handle case where multiple actor table entries point ot the same actor, but
                            // its not the actor we actually want.
                            ////if (actor.Id != this.Id)
                            ////	continue;

                            if (this.viewModel != null)
                            {
                                this.viewModel.Pointer = actor.Pointer;
                            }
                            else
                            {
                                this.viewModel = new ActorViewModel((IntPtr)actor.Pointer);
                            }

                            this.Pointer = actor.Pointer;
                            this.Model   = actor.Model;
                            this.viewModel.PropertyChanged += this.OnViewModelPropertyChanged;
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        this.viewModel?.Dispose();
                        this.viewModel = null;
                    }
                    else if (this.viewModel != null)
                    {
                        this.name = this.viewModel.Name;
                        this.viewModel.OnRetargeted();
                    }

                    Log.Information($"Retargeting actor: {this.Initials}. Success: {found}. Checked {actors.Count} actors.");
                    this.IsValid = found;
                }
            }