···350350 definition: &DeviceDefinition,
351351 ) -> Result<(), ButtplugDeviceError> {
352352 //self.protocol_map.contains_key(identifier.protocol());
353353+ // Check validity of device
354354+ let mut index = definition.user_config().index();
355355+ let indexes: Vec<u32> = self.user_device_definitions().iter().map(|x| x.value().user_config().index()).collect();
356356+ // If we just added 1 to the maximum value of the current indexes, someone decides to set an
357357+ // index to u32::MAX-1, then we'd have a problem. This is kind of a shit solution but it'll work
358358+ // quickly for anyone that's not actively fucking with us by manually playing with user config files.
359359+ while indexes.contains(&index) {
360360+ index = index.wrapping_add(1);
361361+ }
362362+ let mut def = definition.clone();
363363+ *def.user_device_mut().user_config_mut().index_mut() = index;
353364 self
354365 .user_device_definitions
355366 .entry(identifier.clone())
356356- .insert(definition.clone());
367367+ .insert(def);
357368 Ok(())
358369 }
359370