public void Update() { UpdateSelectionMethod(); LabelMethod = (SlotLabelType)mainForm.comboBoxLabelMethod.SelectedItem; SortMethod = (SortMethodType)mainForm.comboBoxSortMethod.SelectedItem; // Lock label update LabelsLocked = mainForm.checkBoxObjLockLabels.Checked; // Processing sort order IEnumerable <ObjectDataModel> sortedObjects; switch (SortMethod) { case SortMethodType.ProcessingOrder: // Data is already sorted by processing order sortedObjects = DataModels.Objects.OrderBy(o => o?.ProcessIndex); break; case SortMethodType.MemoryOrder: // Order by address sortedObjects = DataModels.Objects.OrderBy(o => o?.Address); break; case SortMethodType.DistanceToMario: // Order by address var activeObjects = DataModels.Objects.Where(o => o?.IsActive ?? false).OrderBy(o => o?.DistanceToMarioCalculated); var inActiveObjects = DataModels.Objects.Where(o => !o?.IsActive ?? true).OrderBy(o => o?.DistanceToMarioCalculated); sortedObjects = activeObjects.Concat(inActiveObjects); break; default: throw new ArgumentOutOfRangeException("Uknown sort method type"); } // Update slots UpdateSlots(sortedObjects); List <ObjectDataModel> objs = DataModels.Objects.Where(o => o != null && SelectedSlotsAddresses.Contains(o.Address)).ToList(); objs.Sort((obj1, obj2) => SelectedSlotsAddresses.IndexOf(obj1.Address) - SelectedSlotsAddresses.IndexOf(obj2.Address)); SelectedObjects = objs; }
public void Update() { UpdateSelectionMethod(); LabelMethod = (SlotLabelType)_gui.LabelMethodComboBox.SelectedItem; SortMethod = (SortMethodType)_gui.SortMethodComboBox.SelectedItem; // Lock label update LabelsLocked = _gui.LockLabelsCheckbox.Checked; // Processing sort order IEnumerable <ObjectDataModel> sortedObjects; switch (SortMethod) { case SortMethodType.ProcessingOrder: // Data is already sorted by processing order sortedObjects = DataModels.Objects.OrderBy(o => o?.ProcessIndex); break; case SortMethodType.MemoryOrder: // Order by address sortedObjects = DataModels.Objects.OrderBy(o => o?.Address); break; case SortMethodType.DistanceToMario: // Order by address var activeObjects = DataModels.Objects.Where(o => o?.IsActive ?? false).OrderBy(o => o?.DistanceToMarioCalculated); var inActiveObjects = DataModels.Objects.Where(o => !o?.IsActive ?? true).OrderBy(o => o?.DistanceToMarioCalculated); sortedObjects = activeObjects.Concat(inActiveObjects); break; case SortMethodType.LockedLabels: sortedObjects = DataModels.Objects.OrderBy(o => { uint address = o.Address; if (_lockedSlotIndices.ContainsKey(address)) { Tuple <int?, int?> tuple = _lockedSlotIndices[address]; return((LabelMethod == SlotLabelType.SlotPos ? tuple.Item1 : tuple.Item2) ?? 0); } else { return(0); } }); break; default: throw new ArgumentOutOfRangeException("Uknown sort method type"); } // Update slots UpdateSlots(sortedObjects); List <ObjectDataModel> objs = DataModels.Objects.Where(o => o != null && SelectedSlotsAddresses.Contains(o.Address)).ToList(); objs.Sort((obj1, obj2) => SelectedSlotsAddresses.IndexOf(obj1.Address) - SelectedSlotsAddresses.IndexOf(obj2.Address)); SelectedObjects = objs; }
public void Update() { LabelMethod = (SlotLabelType)ManagerGui.LabelMethodComboBox.SelectedItem; SortMethod = (SortMethodType)ManagerGui.SortMethodComboBox.SelectedItem; var newObjectSlotData = GetProcessedObjects(); if (newObjectSlotData == null) { return; } // Create Memory-SlotIndex lookup table if (_memoryAddressSlotIndex == null) { _memoryAddressSlotIndex = new Dictionary <uint, int>(); var sortedList = newObjectSlotData.OrderBy((objData) => objData.Address).ToList(); foreach (var objectData in newObjectSlotData) { _memoryAddressSlotIndex.Add(objectData.Address, sortedList.FindIndex((objData) => objectData.Address == objData.Address)); } } // Check behavior bank Config.ObjectAssociations.BehaviorBankStart = Config.Stream.GetUInt32(Config.ObjectAssociations.SegmentTable + 0x13 * 4); // Get mario position float marioX, marioY, marioZ; marioX = Config.Stream.GetSingle(MarioConfig.StructAddress + MarioConfig.XOffset); marioY = Config.Stream.GetSingle(MarioConfig.StructAddress + MarioConfig.YOffset); marioZ = Config.Stream.GetSingle(MarioConfig.StructAddress + MarioConfig.ZOffset); // Calculate distance to Mario foreach (var objSlot in newObjectSlotData) { // Get object relative-to-maario position float dX, dY, dZ; dX = marioX - Config.Stream.GetSingle(objSlot.Address + ObjectConfig.XOffset); dY = marioY - Config.Stream.GetSingle(objSlot.Address + ObjectConfig.YOffset); dZ = marioZ - Config.Stream.GetSingle(objSlot.Address + ObjectConfig.ZOffset); objSlot.DistanceToMario = (float)Math.Sqrt(dX * dX + dY * dY + dZ * dZ); // Check if active/loaded objSlot.IsActive = Config.Stream.GetUInt16(objSlot.Address + ObjectConfig.ActiveOffset) != 0x0000; objSlot.Behavior = Config.Stream.GetUInt32(objSlot.Address + ObjectConfig.BehaviorScriptOffset) & 0x7FFFFFFF; } // Processing sort order switch (SortMethod) { case SortMethodType.ProcessingOrder: // Data is already sorted by processing order break; case SortMethodType.MemoryOrder: // Order by address newObjectSlotData = newObjectSlotData.OrderBy(s => s.Address).ToList(); break; case SortMethodType.DistanceToMario: // Order by address var activeObjects = newObjectSlotData.Where(s => s.IsActive).OrderBy(s => s.DistanceToMario); var inActiveObjects = newObjectSlotData.Where(s => !s.IsActive).OrderBy(s => s.DistanceToMario); newObjectSlotData = activeObjects.Concat(inActiveObjects).ToList(); break; } _activeObjectCount = 0; _stoodOnObject = Config.Stream.GetUInt32(MarioConfig.StoodOnObjectPointerAddress); _interactionObject = Config.Stream.GetUInt32(MarioConfig.InteractionObjectPointerOffset + MarioConfig.StructAddress); _heldObject = Config.Stream.GetUInt32(MarioConfig.HeldObjectPointerOffset + MarioConfig.StructAddress); _usedObject = Config.Stream.GetUInt32(MarioConfig.UsedObjectPointerOffset + MarioConfig.StructAddress); _cameraObject = Config.Stream.GetUInt32(CameraConfig.SecondaryObjectAddress); _cameraHackObject = Config.Stream.GetUInt32(CameraHackConfig.CameraHackStruct + CameraHackConfig.ObjectOffset); _modelObject = Config.ModelManager.ModelObjectAddress; List <ObjectSlotData> closestObjectCandidates = newObjectSlotData.FindAll(s => s.IsActive && s.Behavior != (MarioObjectConfig.BehaviorValue & 0x00FFFFFF) + Config.ObjectAssociations.BehaviorBankStart); if (OptionsConfig.ExcludeDustForClosestObject) { closestObjectCandidates = closestObjectCandidates.FindAll(s => s.Behavior != (ObjectConfig.DustSpawnerBehaviorValue & 0x00FFFFFF) + Config.ObjectAssociations.BehaviorBankStart && s.Behavior != (ObjectConfig.DustBallBehaviorValue & 0x00FFFFFF) + Config.ObjectAssociations.BehaviorBankStart && s.Behavior != (ObjectConfig.DustBehaviorValue & 0x00FFFFFF) + Config.ObjectAssociations.BehaviorBankStart); } _closestObject = closestObjectCandidates.OrderBy(s => s.DistanceToMario).FirstOrDefault()?.Address ?? 0; uint floorTriangleAddress = Config.Stream.GetUInt32(MarioConfig.StructAddress + MarioConfig.FloorTriangleOffset); _floorObject = floorTriangleAddress == 0 ? 0 : Config.Stream.GetUInt32(floorTriangleAddress + TriangleOffsetsConfig.AssociatedObject); uint wallTriangleAddress = Config.Stream.GetUInt32(MarioConfig.StructAddress + MarioConfig.WallTriangleOffset); _wallObject = wallTriangleAddress == 0 ? 0 : Config.Stream.GetUInt32(wallTriangleAddress + TriangleOffsetsConfig.AssociatedObject); uint ceilingTriangleAddress = Config.Stream.GetUInt32(MarioConfig.StructAddress + MarioConfig.CeilingTriangleOffset); _ceilingObject = ceilingTriangleAddress == 0 ? 0 : Config.Stream.GetUInt32(ceilingTriangleAddress + TriangleOffsetsConfig.AssociatedObject); ObjectSlot hoverObjectSlot = ObjectSlotsConfig.HoverObjectSlot; if (hoverObjectSlot != null) { _parentObject = Config.Stream.GetUInt32(hoverObjectSlot.Address + ObjectConfig.ParentOffset); _parentUnusedObject = _parentObject == ObjectSlotsConfig.UnusedSlotAddress ? hoverObjectSlot.Address : 0; _parentNoneObject = _parentObject == 0 ? hoverObjectSlot.Address : 0; } else { _parentObject = 0; _parentUnusedObject = 0; _parentNoneObject = 0; } // Update slots UpdateSlots(newObjectSlotData); }