internal void AdjustComponentDef(MechComponentDef def)
        {
            if (change == null)
            {
                return;
            }

            if (!identifier.IsCustomType(def))
            {
                return;
            }

            var newSize = change.Change(def.InventorySize);

            if (!newSize.HasValue)
            {
                return;
            }

            var value     = newSize.Value;
            var propInfo  = typeof(UpgradeDef).GetProperty("InventorySize");
            var propValue = Convert.ChangeType(value, propInfo.PropertyType);

            propInfo.SetValue(def, propValue, null);
        }
Example #2
0
        private static void ModifyInventorySlots(ref LocationDef locationDef, ChassisLocations location, ValueChange <int> change)
        {
            if (locationDef.Location != location)
            {
                return;
            }

            var newValue = change.Change(locationDef.InventorySlots);

            if (!newValue.HasValue)
            {
                return;
            }

            var info  = typeof(LocationDef).GetField("InventorySlots");
            var value = Convert.ChangeType(newValue, info.FieldType);
            var box   = (object)locationDef;

            info.SetValue(box, value);
            locationDef = (LocationDef)box;

            Control.mod.Logger.LogDebug($"set InventorySlots={locationDef.InventorySlots} on location={location}");
        }