/// <summary> /// Do the backup /// </summary> public ProtoVessel BackupVessel(Vessel vessel) { var proto = new ProtoVessel(new ConfigNode(), HighLogic.CurrentGame); proto.vesselRef = vessel; proto.protoPartSnapshots = new List <ProtoPartSnapshot>(); proto.vesselStateValues = new Dictionary <string, KSPParseable>(); proto.orbitSnapShot = new OrbitSnapshot(vessel.orbit); //This field is private so we need dirty reflection to set it... //proto.crew = new List<ProtoCrewMember>(); proto.GetType().GetField("crew", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)? .SetValue(proto, new List <ProtoCrewMember>()); proto.vesselID = vessel.id; proto.refTransform = vessel.referenceTransformId; proto.vesselType = vessel.vesselType; proto.situation = vessel.situation; proto.landed = vessel.Landed; proto.landedAt = vessel.landedAt; proto.displaylandedAt = vessel.displaylandedAt; proto.splashed = vessel.Splashed; proto.vesselName = vessel.vesselName; proto.missionTime = vessel.missionTime; proto.launchTime = vessel.launchTime; proto.lastUT = vessel.lastUT; proto.autoClean = vessel.AutoClean; proto.autoCleanReason = vessel.AutoCleanReason; proto.wasControllable = vessel.IsControllable; foreach (var item in vessel.parts) { if (item.State != PartStates.DEAD) { //Call our own mapper as otherwise it will fail miserably //proto.protoPartSnapshots.Add(new ProtoPartSnapshot(item, proto)); proto.protoPartSnapshots.Add(CreatePartSnapshot(proto, item)); } } foreach (var part in proto.protoPartSnapshots) { part.storePartRefs(); } proto.CoM = vessel.localCoM; proto.latitude = vessel.latitude; proto.longitude = vessel.longitude; proto.altitude = vessel.altitude; proto.height = vessel.heightFromTerrain; proto.normal = vessel.terrainNormal; proto.rotation = vessel.srfRelRotation; proto.stage = vessel.currentStage; proto.persistent = vessel.isPersistent; proto.actionGroups = new ConfigNode(); vessel.ActionGroups.Save(proto.actionGroups); proto.discoveryInfo = new ConfigNode(); vessel.DiscoveryInfo.Save(proto.discoveryInfo); proto.flightPlan = new ConfigNode(); if (vessel.PatchedConicsAttached) { vessel.flightPlanNode.ClearData(); vessel.patchedConicSolver.Save(vessel.flightPlanNode); } vessel.flightPlanNode.CopyTo(proto.flightPlan); proto.targetInfo = new ProtoTargetInfo(vessel.targetObject); proto.waypointInfo = new ProtoWaypointInfo(vessel.navigationWaypoint); proto.ctrlState = new ConfigNode(); vessel.ctrlState.Save(proto.ctrlState); proto.SaveVesselModules(); vessel.OnSaveFlightState(proto.vesselStateValues); proto.RebuildCrewCounts(); return(proto); }