Moved ActiveVessel check from UpdateModules to FixedUpdate
Moved ActiveVessel check from UpdateModules to FixedUpdate

 Binary files a/Assets/Plugins/KerbalEngineer.Unity.dll and b/Assets/Plugins/KerbalEngineer.Unity.dll differ
--- a/Documents/CHANGES.txt
+++ b/Documents/CHANGES.txt
@@ -1,6 +1,13 @@
-1.1.0.2
+1.1.0.2, 2016-04-19, KSP Build #1230
     Added: Altitude (terrain) readout now shows the altitude above underwater terrain when splashed down.
+    Added: Usage of the stock IPartMassModifier for handling the modifying of part module staged mass.
+    Added: Support for thrustTranformMultipliers
+    Changed: Fairing specific mass adjustments now make use of the generic staged mass modifier implementation.
+    Changed: App launcher button handling works with KSP build 1205 changes.
+    Changed: Impact lat/long readouts to use DMS form.
     Fixed: Log spam and physics issue caused when using the EngineerChip part due to a convex mesh collider (now uses a box collider).
+    Fixed: Issues with the disabling/enabling of the toolbar app launcher button in flight when in career mode.
+    Fixed: Bug with impact calculations.
 
 1.1.0.1, 2016-04-01, KSP Build #1179
     Fixed: Heat shields acting as staged decouplers when not set to be staged.

--- a/KerbalEngineer.Unity/CanvasGroupFader.cs
+++ b/KerbalEngineer.Unity/CanvasGroupFader.cs
@@ -100,6 +100,7 @@
                 yield return null;
             }
 
+            //print(m_CanvasGroup.alpha);
             callback?.Invoke();
 
             m_FadeCoroutine = null;

--- a/KerbalEngineer/AppLauncherButton.cs
+++ b/KerbalEngineer/AppLauncherButton.cs
@@ -28,6 +28,17 @@
         private ApplicationLauncherButton m_Button;
 
         /// <summary>
+        ///     Gets the wrapped application launcher button object.
+        /// </summary>
+        public ApplicationLauncherButton Button
+        {
+            get
+            {
+                return m_Button;
+            }
+        }
+
+        /// <summary>
         ///     Gets or sets the toggle button state.
         /// </summary>
         public bool IsOn
@@ -35,7 +46,7 @@
             get
             {
                 return m_Button != null &&
-                       m_Button.toggleButton.Button.interactable &&
+                       m_Button.IsEnabled &&
                        m_Button.toggleButton.CurrentState == UIRadioButton.State.True;
             }
             set
@@ -61,7 +72,7 @@
         /// </summary>
         public void Disable()
         {
-            if (m_Button != null && m_Button.toggleButton.Button.interactable)
+            if (m_Button != null && m_Button.IsEnabled)
             {
                 m_Button.Disable();
             }
@@ -72,7 +83,7 @@
         /// </summary>
         public void Enable()
         {
-            if (m_Button != null && m_Button.toggleButton.Button.interactable == false)
+            if (m_Button != null && !m_Button.IsEnabled)
             {
                 m_Button.Enable();
             }

--- a/KerbalEngineer/EngineerGlobals.cs
+++ b/KerbalEngineer/EngineerGlobals.cs
@@ -25,7 +25,7 @@
         /// <summary>
         ///     Current version of the Kerbal Engineer assembly.
         /// </summary>
-        public const string ASSEMBLY_VERSION = "1.1.0.1";
+        public const string ASSEMBLY_VERSION = "1.1.0.2";
 
         private static string assemblyFile;
         private static string assemblyName;

--- a/KerbalEngineer/Extensions/PartExtensions.cs
+++ b/KerbalEngineer/Extensions/PartExtensions.cs
@@ -100,7 +100,7 @@
             {
                 PartModule pm = part.Modules[i];
                 if (pm is IPartCostModifier)
-                    cost += (pm as IPartCostModifier).GetModuleCost(defaultCost);
+                    cost += (pm as IPartCostModifier).GetModuleCost(defaultCost, ModifierStagingSituation.CURRENT);
             }
             return cost;
         }

--- a/KerbalEngineer/Flight/FlightAppLauncher.cs
+++ b/KerbalEngineer/Flight/FlightAppLauncher.cs
@@ -27,7 +27,7 @@
     [KSPAddon(KSPAddon.Startup.Flight, false)]
     public class FlightAppLauncher : AppLauncherButton, IFlightAppLauncher
     {
-        private static FlightAppLauncher m_Instance;
+        private static FlightAppLauncher s_Instance;
         private FlightMenu m_FlightMenu;
         private GameObject m_MenuObject;
         private GameObject m_MenuPrefab;
@@ -39,7 +39,7 @@
         {
             get
             {
-                return m_Instance;
+                return s_Instance;
             }
         }
 
@@ -145,7 +145,7 @@
             base.Awake();
 
             // set singleton instance
-            m_Instance = this;
+            s_Instance = this;
 
             // cache menu prefab
             if (m_MenuPrefab == null && AssetBundleLoader.Prefabs != null)
@@ -175,6 +175,21 @@
         protected override void OnTrue()
         {
             Open();
+        }
+
+        protected virtual void Update()
+        {
+            if (Button == null)
+                return;
+
+            if (FlightEngineerCore.IsDisplayable && Button.IsEnabled == false)
+            {
+                Enable();
+            }
+            else if (FlightEngineerCore.IsDisplayable == false && Button.IsEnabled)
+            {
+                Disable();
+            }
         }
 
         /// <summary>

--- a/KerbalEngineer/Flight/FlightEngineerCore.cs
+++ b/KerbalEngineer/Flight/FlightEngineerCore.cs
@@ -290,6 +290,9 @@
         /// </summary>
         private void FixedUpdate()
         {
+            if (FlightGlobals.ActiveVessel == null)
+                return;
+
             try
             {
                 SectionLibrary.FixedUpdate();
@@ -351,6 +354,9 @@
         /// </summary>
         private void Update()
         {
+            if (FlightGlobals.ActiveVessel == null)
+                return;
+
             try
             {
                 SectionLibrary.Update();

--- /dev/null
+++ b/KerbalEngineer/Flight/Readouts/Miscellaneous/LogSimToggle.cs
@@ -1,1 +1,56 @@
+// 
+//     Kerbal Engineer Redux
+// 
+//     Copyright (C) 2014 CYBUTEK
+// 
+//     This program is free software: you can redistribute it and/or modify
+//     it under the terms of the GNU General Public License as published by
+//     the Free Software Foundation, either version 3 of the License, or
+//     (at your option) any later version.
+// 
+//     This program is distributed in the hope that it will be useful,
+//     but WITHOUT ANY WARRANTY; without even the implied warranty of
+//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//     GNU General Public License for more details.
+// 
+//     You should have received a copy of the GNU General Public License
+//     along with this program.  If not, see <http://www.gnu.org/licenses/>.
+// 
 
+namespace KerbalEngineer.Flight.Readouts.Miscellaneous
+{
+    #region Using Directives
+
+    using Sections;
+    using UnityEngine;
+    using VesselSimulator;
+
+    #endregion
+
+    public class LogSimToggle : ReadoutModule
+    {
+        #region Constructors
+
+        public LogSimToggle()
+        {
+            this.Name = "Log Simulation";
+            this.Category = ReadoutCategory.GetCategory("Miscellaneous");
+            this.HelpString = "Shows a button that allows you to make the next run of the simulation code dump extra debugging output.";
+            this.IsDefault = false;
+        }
+
+        #endregion
+
+        #region Methods
+
+        public override void Draw(SectionModule section)
+        {
+            GUILayout.BeginHorizontal();
+            GUILayout.Label("Log Simulation: ", this.NameStyle);
+            SimManager.logOutput = GUILayout.Toggle(SimManager.logOutput, "ENABLED", this.ButtonStyle);
+            GUILayout.EndHorizontal();
+        }
+
+        #endregion
+    }
+}

--- a/KerbalEngineer/Flight/Readouts/ReadoutLibrary.cs
+++ b/KerbalEngineer/Flight/Readouts/ReadoutLibrary.cs
@@ -192,6 +192,7 @@
                 readouts.Add(new SimulationDelay());
                 readouts.Add(new VectoredThrustToggle());
                 readouts.Add(new SystemTime());
+                readouts.Add(new LogSimToggle());
 
                 LoadHelpStrings();
             }

--- a/KerbalEngineer/Flight/Readouts/Surface/HorizontalSpeed.cs
+++ b/KerbalEngineer/Flight/Readouts/Surface/HorizontalSpeed.cs
@@ -45,11 +45,12 @@
 
         public override void Draw(SectionModule section)
         {
-            // Used to do this but the bug-fix to horizontalSrfSpeed in KSP 1.0.3 actually made it worse so workaround
-            //this.DrawLine(FlightGlobals.ActiveVessel.horizontalSrfSpeed.ToSpeed(), section.IsHud);
-            var ves = FlightGlobals.ActiveVessel;
-            double horizSpeed = Math.Sqrt(ves.srfSpeed * ves.srfSpeed - ves.verticalSpeed * ves.verticalSpeed);
-            this.DrawLine(horizSpeed.ToSpeed(), section.IsHud);
+            this.DrawLine(FlightGlobals.ActiveVessel.horizontalSrfSpeed.ToSpeed(), section.IsHud);
+
+            // This workaround was used for KSP 1.0.3 and 1.0.4 where horizontalSrfSpeed was really badly broken
+            //var ves = FlightGlobals.ActiveVessel;
+            //double horizSpeed = Math.Sqrt(ves.srfSpeed * ves.srfSpeed - ves.verticalSpeed * ves.verticalSpeed);
+            //this.DrawLine(horizSpeed.ToSpeed(), section.IsHud);
         }
 
         #endregion

--- a/KerbalEngineer/Flight/Readouts/Surface/ImpactLatitude.cs
+++ b/KerbalEngineer/Flight/Readouts/Surface/ImpactLatitude.cs
@@ -21,6 +21,7 @@
 
 using KerbalEngineer.Extensions;
 using KerbalEngineer.Flight.Sections;
+using KerbalEngineer.Helpers;
 
 #endregion
 
@@ -46,7 +47,7 @@
         {
             if (ImpactProcessor.ShowDetails)
             {
-                this.DrawLine(ImpactProcessor.Latitude.ToAngle(), section.IsHud);
+                this.DrawLine(Units.ToAngleDMS(ImpactProcessor.Latitude) + (ImpactProcessor.Latitude < 0 ? " S" : " N"), section.IsHud);
             }
         }
 

--- a/KerbalEngineer/Flight/Readouts/Surface/ImpactLongitude.cs
+++ b/KerbalEngineer/Flight/Readouts/Surface/ImpactLongitude.cs
@@ -21,6 +21,7 @@
 
 using KerbalEngineer.Extensions;
 using KerbalEngineer.Flight.Sections;
+using KerbalEngineer.Helpers;
 
 #endregion
 
@@ -46,7 +47,7 @@
         {
             if (ImpactProcessor.ShowDetails)
             {
-                this.DrawLine(ImpactProcessor.Longitude.ToAngle(), section.IsHud);
+                this.DrawLine(Units.ToAngleDMS(ImpactProcessor.Longitude) + (ImpactProcessor.Longitude < 0.0 ? "W" : " E"), section.IsHud);
             }
         }
 

--- a/KerbalEngineer/Flight/Readouts/Surface/ImpactProcessor.cs
+++ b/KerbalEngineer/Flight/Readouts/Surface/ImpactProcessor.cs
@@ -113,7 +113,7 @@
                 this.impactAltitude = 0;
                 var e = FlightGlobals.ActiveVessel.orbit.eccentricity;
                 //get current position direction vector
-                var currentpos = this.RadiusDirection(FlightGlobals.ActiveVessel.orbit.trueAnomaly);
+                var currentpos = this.RadiusDirection(FlightGlobals.ActiveVessel.orbit.trueAnomaly * 180.0 / Math.PI);
                 //calculate longitude in inertial reference frame from that
                 var currentirflong = 180 * Math.Atan2(currentpos.x, currentpos.y) / Math.PI;
 

--- a/KerbalEngineer/KerbalEngineer.csproj
+++ b/KerbalEngineer/KerbalEngineer.csproj
@@ -54,6 +54,7 @@
     <Compile Include="Flight\ActionMenuGui.cs" />
     <Compile Include="Flight\FlightAppLauncher.cs" />
     <Compile Include="Flight\Presets\Preset.cs" />
+    <Compile Include="Flight\Readouts\Miscellaneous\LogSimToggle.cs" />
     <Compile Include="Flight\Readouts\Miscellaneous\SystemTime.cs" />
     <Compile Include="Flight\Readouts\Miscellaneous\VectoredThrustToggle.cs" />
     <Compile Include="Flight\Readouts\Miscellaneous\Separator.cs" />

--- a/KerbalEngineer/VesselSimulator/AttachNodeSim.cs
+++ b/KerbalEngineer/VesselSimulator/AttachNodeSim.cs
@@ -51,7 +51,10 @@
             return nodeSim;
         }
 
-        static private void Reset(AttachNodeSim attachNodeSim) { }
+        static private void Reset(AttachNodeSim attachNodeSim)
+        {
+            attachNodeSim.attachedPartSim = null;
+        }
 
 
         public void Release()

--- a/KerbalEngineer/VesselSimulator/EngineSim.cs
+++ b/KerbalEngineer/VesselSimulator/EngineSim.cs
@@ -54,6 +54,7 @@
         {
             engineSim.resourceConsumptions.Reset();
             engineSim.resourceFlowModes.Reset();
+            engineSim.partSim = null;
             engineSim.actualThrust = 0;
             engineSim.isActive = false;
             engineSim.isp = 0;
@@ -72,26 +73,33 @@
         }
 
         public static EngineSim New(PartSim theEngine,
-                         double atmosphere,
-                         float machNumber,
-                         float maxFuelFlow,
-                         float minFuelFlow,
-                         float thrustPercentage,
-                         Vector3 vecThrust,
-                         FloatCurve atmosphereCurve,
-                         bool atmChangeFlow,
-                         FloatCurve atmCurve,
-                         FloatCurve velCurve,
-                         float currentThrottle,
-                         float IspG,
-                         bool throttleLocked,
-                         List<Propellant> propellants,
-                         bool active,
-                         float resultingThrust,
-                         List<Transform> thrustTransforms,
-                        LogMsg log)
-        {
-            EngineSim engineSim = pool.Borrow();
+									ModuleEngines engineMod,
+									double atmosphere,
+									float machNumber,
+									bool vectoredThrust,
+									bool fullThrust,
+									LogMsg log)
+        {
+            float maxFuelFlow = engineMod.maxFuelFlow;
+            float minFuelFlow = engineMod.minFuelFlow;
+            float thrustPercentage = engineMod.thrustPercentage;
+            List<Transform> thrustTransforms = engineMod.thrustTransforms;
+            List<float> thrustTransformMultipliers = engineMod.thrustTransformMultipliers;
+            Vector3 vecThrust = CalculateThrustVector(vectoredThrust ? thrustTransforms : null,
+                                                        vectoredThrust ? thrustTransformMultipliers : null,
+                                                        log);
+            FloatCurve atmosphereCurve = engineMod.atmosphereCurve;
+            bool atmChangeFlow = engineMod.atmChangeFlow;
+            FloatCurve atmCurve = engineMod.useAtmCurve ? engineMod.atmCurve : null;
+            FloatCurve velCurve = engineMod.useVelCurve ? engineMod.velCurve : null;
+            float currentThrottle = engineMod.currentThrottle;
+            float IspG = engineMod.g;
+            bool throttleLocked = engineMod.throttleLocked || fullThrust;
+            List<Propellant> propellants = engineMod.propellants;
+            bool active = engineMod.isOperational;
+            float resultingThrust = engineMod.resultingThrust;
+			
+			EngineSim engineSim = pool.Borrow();
 
             engineSim.isp = 0.0;
             engineSim.maxMach = 0.0f;
@@ -120,7 +128,7 @@
                     log.buf.AppendFormat("actual  = {0:g6}\n", engineSim.actualThrust);
                 }
 
-                if (throttleLocked)
+				if (throttleLocked)
                 {
                     if (log != null) log.buf.AppendLine("throttleLocked is true, using thrust for flowRate");
                     flowRate = GetFlowRate(engineSim.thrust, engineSim.isp);
@@ -129,7 +137,8 @@
                 {
                     if (currentThrottle > 0.0f && engineSim.partSim.isLanded == false)
                     {
-                        if (log != null) log.buf.AppendLine("throttled up and not landed, using actualThrust for flowRate");
+						// TODO: This bit doesn't work for RF engines
+						if (log != null) log.buf.AppendLine("throttled up and not landed, using actualThrust for flowRate");
                         flowRate = GetFlowRate(engineSim.actualThrust, engineSim.isp);
                     }
                     else
@@ -190,19 +199,44 @@
                 engineSim.resourceFlowModes.Add(propellant.id, (double)propellant.GetFlowMode());
             }
 
-            double thrustPerThrustTransform = engineSim.thrust / thrustTransforms.Count;
             for (int i = 0; i < thrustTransforms.Count; i++)
             {
                 Transform thrustTransform = thrustTransforms[i];
                 Vector3d direction = thrustTransform.forward.normalized;
                 Vector3d position = thrustTransform.position;
 
-                AppliedForce appliedForce = AppliedForce.New(direction * thrustPerThrustTransform, position);
+                AppliedForce appliedForce = AppliedForce.New(direction * engineSim.thrust * thrustTransformMultipliers[i], position);
                 engineSim.appliedForces.Add(appliedForce);
             }
 
             return engineSim;
         }
+
+		private static Vector3 CalculateThrustVector(List<Transform> thrustTransforms, List<float> thrustTransformMultipliers, LogMsg log)
+		{
+			if (thrustTransforms == null)
+			{
+				return Vector3.forward;
+			}
+
+			Vector3 thrustvec = Vector3.zero;
+			for (int i = 0; i < thrustTransforms.Count; ++i)
+			{
+				Transform trans = thrustTransforms[i];
+
+				if (log != null) log.buf.AppendFormat("Transform = ({0:g6}, {1:g6}, {2:g6})   length = {3:g6}\n", trans.forward.x, trans.forward.y, trans.forward.z, trans.forward.magnitude);
+
+				thrustvec -= (trans.forward * thrustTransformMultipliers[i]);
+			}
+
+			if (log != null) log.buf.AppendFormat("ThrustVec  = ({0:g6}, {1:g6}, {2:g6})   length = {3:g6}\n", thrustvec.x, thrustvec.y, thrustvec.z, thrustvec.magnitude);
+
+			thrustvec.Normalize();
+
+			if (log != null) log.buf.AppendFormat("ThrustVecN = ({0:g6}, {1:g6}, {2:g6})   length = {3:g6}\n", thrustvec.x, thrustvec.y, thrustvec.z, thrustvec.magnitude);
+
+			return thrustvec;
+		}
 
         public ResourceContainer ResourceConsumptions
         {

--- a/KerbalEngineer/VesselSimulator/PartSim.cs
+++ b/KerbalEngineer/VesselSimulator/PartSim.cs
@@ -56,8 +56,8 @@
         public bool isLanded;
         public bool isNoPhysics;
         public bool isSepratron;
-        public bool isFairing;
-        public float fairingMass;
+        //public bool isFairing;
+        public float postStageMassAdjust;
         public int stageIndex;
         public String name;
         public String noCrossFeedNodeKey;
@@ -86,9 +86,11 @@
             }
             partSim.attachNodes.Clear();
             partSim.fuelTargets.Clear();
+            partSim.surfaceMountFuelTargets.Clear();
             partSim.resourceDrains.Reset();
             partSim.resourceFlowStates.Reset();
             partSim.resources.Reset();
+            partSim.parent = null;
             partSim.baseCost = 0d;
             partSim.baseMass = 0d;
             partSim.baseMassForCoM = 0d;
@@ -100,61 +102,77 @@
             pool.Release(this);
         }
 
-        public static PartSim New(Part thePart, int id, double atmosphere, LogMsg log)
+        public static PartSim New(Part p, int id, double atmosphere, LogMsg log)
         {
             PartSim partSim = pool.Borrow();
 
-            partSim.part = thePart;
-            partSim.centerOfMass = thePart.transform.TransformPoint(thePart.CoMOffset);
+            partSim.part = p;
+            partSim.centerOfMass = p.transform.TransformPoint(p.CoMOffset);
             partSim.partId = id;
-            partSim.name = partSim.part.partInfo.name;
+            partSim.name = p.partInfo.name;
 
             if (log != null) log.buf.AppendLine("Create PartSim for " + partSim.name);
 
             partSim.parent = null;
-            partSim.parentAttach = partSim.part.attachMode;
-            partSim.fuelCrossFeed = partSim.part.fuelCrossFeed;
-            partSim.noCrossFeedNodeKey = partSim.part.NoCrossFeedNodeKey;
-            partSim.decoupledInStage = partSim.DecoupledInStage(partSim.part);
-            partSim.isFuelLine = partSim.part.HasModule<CModuleFuelLine>();
-            partSim.isFuelTank = partSim.part is FuelTank;
+            partSim.parentAttach = p.attachMode;
+            partSim.fuelCrossFeed = p.fuelCrossFeed;
+            partSim.noCrossFeedNodeKey = p.NoCrossFeedNodeKey;
+            partSim.decoupledInStage = partSim.DecoupledInStage(p);
+            partSim.isFuelLine = p.HasModule<CModuleFuelLine>();
+            partSim.isFuelTank = p is FuelTank;
             partSim.isSepratron = partSim.IsSepratron();
-            partSim.inverseStage = partSim.part.inverseStage;
+            partSim.inverseStage = p.inverseStage;
             //MonoBehaviour.print("inverseStage = " + inverseStage);
 
-            partSim.baseCost = partSim.part.GetCostDry();
+            partSim.baseCost = p.GetCostDry();
 
             if (log != null)
             {
-                log.buf.AppendLine("Parent part = " + (partSim.part.parent == null ? "null" : partSim.part.parent.partInfo.name));
-                log.buf.AppendLine("physicalSignificance = " + partSim.part.physicalSignificance);
-                log.buf.AppendLine("PhysicsSignificance = " + partSim.part.PhysicsSignificance);
+                log.buf.AppendLine("Parent part = " + (p.parent == null ? "null" : p.parent.partInfo.name));
+                log.buf.AppendLine("physicalSignificance = " + p.physicalSignificance);
+                log.buf.AppendLine("PhysicsSignificance = " + p.PhysicsSignificance);
             }
 
             // Work out if the part should have no physical significance
             // The root part is never "no physics"
-            partSim.isNoPhysics = partSim.part.physicalSignificance == Part.PhysicalSignificance.NONE ||
-                                    partSim.part.PhysicsSignificance == 1;
-
-            if (partSim.part.HasModule<LaunchClamp>())
+            partSim.isNoPhysics = p.physicalSignificance == Part.PhysicalSignificance.NONE ||
+                                    p.PhysicsSignificance == 1;
+
+            if (p.HasModule<LaunchClamp>())
             {
                 partSim.realMass = 0d;
                 if (log != null) log.buf.AppendLine("Ignoring mass of launch clamp");
             }
             else
             {
-                partSim.realMass = partSim.part.mass;
-                if (log != null)
-                {
-                    log.buf.AppendLine("Using part.mass" + partSim.part.mass);
-                }
-            }
-
-            partSim.fairingMass = partSim.part.GetModule<ModuleProceduralFairing>()?.GetModuleMass(partSim.part.mass) ?? 0.0f;
-
-            for (int i = 0; i < partSim.part.Resources.Count; i++)
-            {
-                PartResource resource = partSim.part.Resources[i];
+                partSim.realMass = p.mass;
+                if (log != null) log.buf.AppendLine("Using part.mass of " + p.mass);
+            }
+
+            partSim.postStageMassAdjust = 0f;
+            if (log != null) log.buf.AppendLine("Calculating postStageMassAdjust, prefabMass = " + p.prefabMass);
+            int count = p.Modules.Count;
+            for (int i = 0; i < count; i++)
+            {
+                if (log != null) log.buf.AppendLine("Module: " + p.Modules[i].moduleName);
+                IPartMassModifier partMassModifier = p.Modules[i] as IPartMassModifier;
+                if (partMassModifier != null)
+                {
+                    if (log != null) log.buf.AppendLine("ChangeWhen = " + partMassModifier.GetModuleMassChangeWhen());
+                    if (partMassModifier.GetModuleMassChangeWhen() == ModifierChangeWhen.STAGED)
+                    {
+                        float preStage = partMassModifier.GetModuleMass(p.prefabMass, ModifierStagingSituation.UNSTAGED);
+                        float postStage = partMassModifier.GetModuleMass(p.prefabMass, ModifierStagingSituation.STAGED);
+                        if (log != null) log.buf.AppendLine("preStage = " + preStage + "   postStage = " + postStage);
+                        partSim.postStageMassAdjust += (postStage - preStage);
+                    }
+                }
+            }
+            if (log != null) log.buf.AppendLine("postStageMassAdjust = " + partSim.postStageMassAdjust);
+
+            for (int i = 0; i < p.Resources.Count; i++)
+            {
+                PartResource resource = p.Resources[i];
 
                 // Make sure it isn't NaN as this messes up the part mass and hence most of the values
                 // This can happen if a resource capacity is 0 and tweakable
@@ -172,17 +190,17 @@
                 }
             }
 
-            partSim.hasVessel = (partSim.part.vessel != null);
-            partSim.isLanded = partSim.hasVessel && partSim.part.vessel.Landed;
+            partSim.hasVessel = (p.vessel != null);
+            partSim.isLanded = partSim.hasVessel && p.vessel.Landed;
             if (partSim.hasVessel)
             {
-                partSim.vesselName = partSim.part.vessel.vesselName;
-                partSim.vesselType = partSim.part.vesselType;
-            }
-            partSim.initialVesselName = partSim.part.initialVesselName;
-
-            partSim.hasMultiModeEngine = partSim.part.HasModule<MultiModeEngine>();
-            partSim.hasModuleEngines = partSim.part.HasModule<ModuleEngines>();
+                partSim.vesselName = p.vessel.vesselName;
+                partSim.vesselType = p.vesselType;
+            }
+            partSim.initialVesselName = p.initialVesselName;
+
+            partSim.hasMultiModeEngine = p.HasModule<MultiModeEngine>();
+            partSim.hasModuleEngines = p.HasModule<ModuleEngines>();
 
             partSim.isEngine = partSim.hasMultiModeEngine || partSim.hasModuleEngines;
 
@@ -233,27 +251,13 @@
                     {
                         if (log != null) log.buf.AppendLine("Module: " + engine.moduleName);
 
-                        Vector3 thrustvec = this.CalculateThrustVector(vectoredThrust ? engine.thrustTransforms : null, log);
-
                         EngineSim engineSim = EngineSim.New(
                             this,
-                            atmosphere,
+							engine,
+							atmosphere,
                             (float)mach,
-                            engine.maxFuelFlow,
-                            engine.minFuelFlow,
-                            engine.thrustPercentage,
-                            thrustvec,
-                            engine.atmosphereCurve,
-                            engine.atmChangeFlow,
-                            engine.useAtmCurve ? engine.atmCurve : null,
-                            engine.useVelCurve ? engine.velCurve : null,
-                            engine.currentThrottle,
-                            engine.g,
-                            engine.throttleLocked || fullThrust,
-                            engine.propellants,
-                            engine.isOperational,
-                            engine.resultingThrust,
-                            engine.thrustTransforms,
+							vectoredThrust,
+							fullThrust,
                             log);
                         allEngines.Add(engineSim);
                     }
@@ -267,28 +271,14 @@
                     ModuleEngines engine = engines[i];
                     if (log != null) log.buf.AppendLine("Module: " + engine.moduleName);
 
-                    Vector3 thrustvec = this.CalculateThrustVector(vectoredThrust ? engine.thrustTransforms : null, log);
-
                     EngineSim engineSim = EngineSim.New(
                         this,
+						engine,
                         atmosphere,
                         (float)mach,
-                        engine.maxFuelFlow,
-                        engine.minFuelFlow,
-                        engine.thrustPercentage,
-                        thrustvec,
-                        engine.atmosphereCurve,
-                        engine.atmChangeFlow,
-                        engine.useAtmCurve ? engine.atmCurve : null,
-                        engine.useVelCurve ? engine.velCurve : null,
-                        engine.currentThrottle,
-                        engine.g,
-                        engine.throttleLocked || fullThrust,
-                        engine.propellants,
-                        engine.isOperational,
-                        engine.resultingThrust,
-                        engine.thrustTransforms,
-                        log);
+						vectoredThrust,
+						fullThrust,
+						log);
                     allEngines.Add(engineSim);
                 }
             }
@@ -416,9 +406,9 @@
                 mass += resources.GetResourceMass(resources.Types[i]);
             }
 
-            if (fairingMass > 0.0 && currentStage <= inverseStage)
-            {
-                mass -= fairingMass;
+            if (postStageMassAdjust != 0.0 && currentStage <= inverseStage)
+            {
+                mass += postStageMassAdjust;
             }
 
             return mass;
@@ -638,6 +628,17 @@
                     this.fuelTargets[i] = null;
                 }
             }
+
+            // Loop through the surface attached fuel targets (surface attached parts for new flow modes)
+            for (int i = 0; i < this.surfaceMountFuelTargets.Count; i++)
+            {
+                PartSim fuelTargetSim = this.surfaceMountFuelTargets[i];
+                // If the part is in the set then "remove" it by clearing the PartSim reference
+                if (fuelTargetSim != null && partSims.Contains(fuelTargetSim))
+                {
+                    this.surfaceMountFuelTargets[i] = null;
+                }
+            }
         }
 
         public void SetupAttachNodes(Dictionary<Part, PartSim> partSimLookup, LogMsg log)

 Binary files a/Output/KerbalEngineer/KerbalEngineer.Unity.dll and b/Output/KerbalEngineer/KerbalEngineer.Unity.dll differ
 Binary files a/Output/KerbalEngineer/KerbalEngineer.dll and b/Output/KerbalEngineer/KerbalEngineer.dll differ
--- a/Output/KerbalEngineer/KerbalEngineer.version
+++ b/Output/KerbalEngineer/KerbalEngineer.version
@@ -6,7 +6,7 @@
 		"MAJOR":1,
 		"MINOR":1,
 		"PATCH":0,
-		"BUILD":1
+		"BUILD":2
 	},
 	"KSP_VERSION":
 	{

 Binary files a/Output/KerbalEngineer/MiniAVC.dll and b/Output/KerbalEngineer/MiniAVC.dll differ