Jump to content

Possible to Save Ship from Persistence File?


Recommended Posts

If you guys still want it, I made an Add-On that allows you to save an active, in-flight vessel out to a .craft file. You can find it here: https://github.com/ClawKSP/InflightShipSave/releases

Install the .dll to your GameData directory and start up KSP. Go to the vessel you want to save and press F6. That will save it out to the VAB directory. It will be named after your ship with "_Rescued" appended to the end. That way you can go back to the VAB and load it up.

So it'll be at ===> KSP\Saves\[saveName]\Ships\VAB\[VesselName]_Rescued.craft

Please bear in mind that it's a work in progress. Certain things on the ship, once activated can cause a problem for the Editor. Also, launch clamps cause the placement to be a bit wonky. I've trapped and cleaned as many of these things as I can, but check your ALT+F2 log. If you are getting a lot of NullRefs, something on your ship is still active. Providing me a picture of your craft and/or the .craft file would help.

Cheers,

~Claw

By the way, here is your shuttle. Looks like the utility worked for it: http://pastebin.com/ti2w3F6N

*gasp* *insert second speechless gasp*

wow. thank you Claw!

Starwhip, looks like Claw's already invented the wheel. :D

Nice job. I have a shuttle, and not just any shuttle, my shuttle. Thank you! The Intrepid is back in development! I seriously almost came to tears today over the work I put into those wings. You have turn sorrow in to joy. Thank you dear sir.

bGnyxb1.png

W4GBCO0.png

gwGrIfJ.png

PEKUT4G.png

The only thing I need to do is recreate the solid booster stack. That was a permanent loss, but easy to recreate. I will be sure everyone here in this thread receives special mention and thanks in the Spacecraft Exchange thread for this shuttle once I finalize the lifting stack, and other balance issues, and then publish it. I'll IM you all. :)

You have made Jebediah's day. Thank you Claw. (and thanks for taking a swing crackin' the code Starwhip). You guys are awesome. You guys are what makes KSP literally the best game ever. Updating OP.

Edited by inigma
Link to comment
Share on other sites

That's an awesome shuttle - easily one of the best (prettiest) I've seen, I see why you were so determined to keep it :D.

I will be sure everyone here in this thread receives special mention and thanks in the Spacecraft Exchange thread for this shuttle once I finalize the lifting stack, and other balance issues, and then publish it.

Everyone? I didn't even help :(; you should leave me off that list :P.

Link to comment
Share on other sites

That's an awesome shuttle - easily one of the best (prettiest) I've seen, I see why you were so determined to keep it :D.

Everyone? I didn't even help :(; you should leave me off that list :P.

Thank you very much. I have high hopes for this design.

And yes everyone deserves mention since even a single post causes a thread to get noticed that much more. Thank you. :)

- - - Updated - - -

Just a general note with Claw's converter. It works as expected. Only that in the craft file some animated parts may have

isEnabled = False

rather than set to

isEnabled = True

do a find/replace on your craft file and you should be all set.

Cargo bays are locked and cockpit lights not toggleable until you do this. I'll post a github bug on it.

Link to comment
Share on other sites

If you guys still want it, I made an Add-On that allows you to save an active, in-flight vessel out to a .craft file. You can find it here: https://github.com/ClawKSP/InflightShipSave/releases

Nice... I play with KCT, and I've lost a few changes in the past by editing but not saving an under-construction vessel; end up with a ship on the launch pad that doesn't resemble it's original .craft file anymore. This looks like the perfect save tool :)

Really nice shuttle, btw, Inigma - does it fly as well as it looks? :)

Link to comment
Share on other sites

Really nice shuttle, btw, Inigma - does it fly as well as it looks? :)

Thanks for the compliment! Yes it really does fly as well as it looks. Empty and full. In fact, I spent nearly 2 hours drop testing the shuttle using HyperEdit the night before I lost the files, simply because its a dream to fly and land, but I'll let you decide for yourself once I publish it. I'll IM you when its ready. I'm on a quest to design the nearest to perfect NASA-like KSP mk3 shuttle using all the engineering techniques I know and learned from leading SSI, and techniques I have borrowed from other successful STS makers.

Empty it lands as light as a feather and just as easy.

Full, well, this baby is designed to haul a full orange tank and full yellow rcs into orbit, so it's designed with a launch abort above 4000 km in mind. Any abort less than that that alt and you're escape plan with a full orange and full yellow tank in the cargo bay is the old fashioned baileroo and hope you land on a bouncy part. The shuttle carries no fuel except monopropellant to feed the OMS, but if you gun the main engines to steal from the full orange tank cargo (after all its an emergency landing right?) and reach about 200 m/s you can pull out of the dive in about 3700m of altitude loss and flatten your angle of attack for a nice horizontal landing...but it takes practice. I did it on the third try.

In between, it handles very very very well. So over all, the shuttle itself can handle pretty much any cargo you can fit into the bay, and survive a return.

The good news, the shuttle itself is completed tonight. Now all that remains is to design the external tank and boosters. I was in the beginning stages of my testing when I lost everything. Now that it's back, the shuttle is done, and I think I've settled on an external tank design. What a chore. :) Next come the boosters and tuning the whole STS. Its my first shuttle. We'll see what happens.

Edited by inigma
Link to comment
Share on other sites

I'm not sure if this is possible via KSP's API, but could you not reset all parts' err... tweakables? extra data? ... whatever it's called, to the defaults?

Personally I try to avoid doing blanket things like this when I build code, but it's definitely something to consider. Because what if I reset a tweakable (like fuel) and that isn't what you wanted? It becomes a complex guessing game of "what should it be," so sometimes it's easier to leave it as-is.

Just a general note with Claw's converter. It works as expected. Only that in the craft file some animated parts may have

...

Cargo bays are locked and cockpit lights not toggleable until you do this. I'll post a github bug on it.

Yep, this is the kind of stuff I will need help with. I figured this was a utility that was better off getting released right away (given the circumstance) rather than waiting for me to test, test, TEST!!! I tried to catch the stuff that breaks the editor, but I didn't do testing for functional things like this.

So feel free to post that stuff as a bug report in Git, or on my add-on thread here: http://forum.kerbalspaceprogram.com/threads/97285-KSP-v0-90-Stock-Bug-Fix-Modules-%28Release-v0-1-7d-6-Jan-15%29-Misc-Utilities-%2813-Jan-15%29

And you are very welcome. I was wanting to do this before, but it's easier to get motivated when someone really needs it. :D

Happy flying!

Cheers,

~Claw

Link to comment
Share on other sites

Darn you, Claw. I was so close. :(

CONVERTED

Went from


name = mk3Cockpit.Shuttle
cid = 4294791282
uid = 3208160340
mid = 1140234191
launchID = 6
parent = 0
position = 0,0,0
rotation = 0,0,0,1
mirror = 1,1,1
symMethod = Radial
istg = 0
dstg = 0
sqor = -1
sidx = -1
attm = 0
srfN = None, -1
attN = bottom, 19
attN = top, 1
mass = 3.5
temp = 19.81638
expt = 0.5
state = 0
connected = True
attached = True
flag = NASAmission/Flags/NASA
rTrf = mk3Cockpit.Shuttle (Space Shuttle Intrepid 22)
modCost = 0
crew = Merman Kerman
crew = Kencas Kerman
crew = Alddon Kerman
crew = Lemcal Kerman

to


name = mk3Cockpit.Shuttle_4294791282
parent = 0
position = 0,0,0
mirror = 1,1,1
symMethod = Radial
istg = 0
dstg = 0
sqor = -1
sidx = -1
attm = 0
srfN = None, -1
attN = bottom, 19
attN = top, 1
rTrf = mk3Cockpit.Shuttle (Space Shuttle Intrepid 22)
modCost = 0

But hey, great work anyway! :) Glad to see you got it back.

I'm still going to work on that program, though.

Oh, and yeah, here's the program... :D


##KSP .sfs to .craft converter

sfsFileLoc = "C:\\Users\\Tris\\Downloads\\intrepid22.txt"
craftFileDest = "C:\\Users\\Tris\\Desktop\\CONVERTED.txt"
craftFileDest2 = "C:\\Users\\Tris\\Desktop\\CONVERTED2.txt"
progFileDest = "C:\\Users\\Tris\\Desktop\\intrepid22.craft"

vessNameFlag = "name = Space Shuttle Intrepid 22"

##Things to ADD
toAdd = []

##Things to REMOVE
toRemove = ["landed","landedAt","splashed","met","lct","root","lat","lon",
"alt","hgt","nrm","rot","CoM","stg","prst","ref","ctrl","cPch",
"cHdg","cMod","uid","crew","mid","launchID","mass","temp","expt",
"state","connected","attached","flag"]

vessFlag = "VESSEL"
partFlag = "part"
partNFlag = "partName"
posFlag = "position"
rotFlag = "rotation"

##Use these two flags to copy-paste the first chunk
mirFlag = "mir"
attmFlag = "attm"

def goToMatchingBracket(FileSList,startPos):
'''RETURNS LOCATION OF MATCHING BRACKET'''
lenOfFSL = len(FileSList)
currentPos = startPos + 1
bracket_lCount = 1
bracket_rCount = 0
tempChar = ''
found = False
while found == False:
tempChar = FileSList[currentPos]
if tempChar == '{':
bracket_lCount += 1
elif tempChar == '}':
bracket_rCount += 1
if bracket_lCount == bracket_rCount:
return currentPos
if currentPos >= lenOfFSL:
break
else:
currentPos += 1

def loadFile(File):
'''RETURNS FILE TO STRING'''
TempFile = open(File, 'r')
tString = ""
for line in TempFile:
tString += line
TempFile.close()
return tString

def writeToFile(File,toWrite):
'''IMPORTANT: FUNCTION OVERWRITES FILE'''
TempFile = open(File, 'w')
TempFile.write(str(toWrite))
TempFile.close()

def appendToFile(File,toAppend):
'''ADDS TEXT TO FILE'''
TempFile = open(File, 'a')
TempFile.write(str(toAppend))
TempFile.close()

def clearFile(File):
'''ERASES DATA IN FILE'''
writeToFile(File,"")

def decompileFile(File):
'''RETURNS FILE AS LIST'''
tString = loadFile(File)
tString = tString.split('{')
tString2 = []
for str2 in tString:
tString2 += str2.split('}')
return tString

def matchString(string1,string2):
'''COMPARES STRINGS 1&2, IF ==, RETURNS TRUE, ELSE RETURNS FALSE'''
if string1 == string2:
return True
else:
return False

def searchString(FileSList,toFind,startPos):
'''SEARCHES FileSList FOR toFind.split(' '), RETURNS start pos of string OR FALSE'''
TFSPosToStart = len(FileSList) + startPos
#toFind = toFind.split(' ')
lenToFind = len(toFind)
print("Length Of String: %s" %(lenToFind))
for pos in range(TFSPosToStart):
for toFindPos in range(lenToFind):
string1 = FileSList[pos + toFindPos]
string2 = toFind[toFindPos]

check = matchString(string1,string2)

if check == True:
if toFindPos == lenToFind - 1:
print("STRING MATCH FOUND AT POS %s" %(pos + 1))
return pos
else:
break
return False

def lenOfList(FileSList):
'''Returns INT value for len(FileSList)'''
return len(FileSList)

def returnFromPosToPos(FileSList,StartPos,EndPos):
'''Returns FileSList from StartPos to EndPos'''
tempString = ''
ReturnLength = (len(FileSList) - StartPos) - (len(FileSList) - EndPos)
for pos in range(ReturnLength):
tempString += (FileSList[pos + StartPos]) + ' '

return tempString

def cleanFile(FileSList):
'''Deletes \\t characters from Start to End, splits on lines'''
tempList = []
tempStr = ''
for char in FileSList:
if char != '\t':
tempList.append(char)
for char in tempList:
tempStr += char
tempList = tempStr.split("\n")
return tempList

def searchList(FileSList,startsWith,startPos):
'''RETURNS LOCATION OF LIST OBJECT THAT STARTS WITH startsWith'''
currentPos = startPos
for line in FileSList:
if line.startswith(startsWith):
return currentPos
currentPos += 1

def removeList(FileSList,startList):
tempList = []
appendList = ''
removedList = []
for line in FileSList:
linePass = True
removedList.append(line)
for removal in startList:
removedList.append(removal)
if line.startswith(removal):
linePass = False
if linePass:
tempList.append(line)

##print(removedList)
##print(lineList)

return tempList,removedList

def listToStr(List):
tempStr = ''
for item in List:
tempStr += item
return tempStr

def nameFix(FileSList):
tempList = FileSList
tempList2 = []
for linePos in range(len(FileSList)-1):
line = FileSList[linePos]
if line.startswith("cid = "):
line = list(line)
del line[0:6]
tempList[linePos-1] = tempList[linePos-1] + "_%s"%listToStr(line)

for line in FileSList:
linePass = True
if line.startswith("cid = "):
pass
else:
tempList2.append(line)

return tempList2

removedList = ''
sfsFile = cleanFile(loadFile(sfsFileLoc))

sfsFile,removedList = removeList(sfsFile,toRemove)

sfsFile = nameFix(sfsFile)

writeToFile(craftFileDest2,sfsFile)
writeToFile(progFileDest,removedList)

clearFile(craftFileDest)
for line in sfsFile:
appendToFile(craftFileDest,(line+'\n'))

##writeToFile(craftFileDest,returnFromPosToPos(sfsFile,flagPos,len(sfsFile)))

Link to comment
Share on other sites

Great job Starwhip! I had a feeling you were getting close. Perhaps we can both work on and test Claws code and add in what you have discovered works best too. He has a nice in game F6 trigger to save the craft in the VAB. I have a feeling it needs more shake down. For some reason some of the craft module values appeared different from values loaded from a craft file assembled by hand. Comparing craft values between actual craft and rescued/converted for multiple crafts using all parts is the next step to debugging his code.

Then a feature request to provide a GUI to specify the craft file name and either place in VAB or SPH. Stuff like that.

You guys are so awesome! :) both of you will receive permanent mention in the Intrepid's in game description when released. I finally made orbit without flipout last night. More testing and development to come.

Link to comment
Share on other sites

Great job Starwhip! I had a feeling you were getting close.

I have a feeling it needs more shake down. For some reason some of the craft module values appeared different from values loaded from a craft file assembled by hand.

Indeed, great work Starwhip. :)

And yes, it does need more shakedown. It worked well enough to save your ship, so I figured it was a good time to release it.

What specifically was different? I'm curious about your design since it was on the pad.

I'm leaning toward leaving the reconstructed .craft as close to the original as possible. The reason for this is because I'm thinking about making the utility also load a .craft over the top of an in-flight ship. So if there is some sort of problem, you can save the ship, edit it for repairs, then reload it in-flight.

Cheers,

-Claw

Link to comment
Share on other sites

Indeed, great work Starwhip. :)

And yes, it does need more shakedown. It worked well enough to save your ship, so I figured it was a good time to release it.

What specifically was different? I'm curious about your design since it was on the pad.

I'm leaning toward leaving the reconstructed .craft as close to the original as possible. The reason for this is because I'm thinking about making the utility also load a .craft over the top of an in-flight ship. So if there is some sort of problem, you can save the ship, edit it for repairs, then reload it in-flight.

Cheers,

-Claw

I posted on github the diff between mk3 cockpit made in sph and converted cockipit. Minor diffs, only value changes. Not sure if relevant or breaking except for the toggles being converted to false.

- - - Updated - - -

Reinsertion/ Replacing craft back into sfs is a natural progression of developing this tool. A big challenge for sure.

This feature could be redundant with HyperEdit though.

- - - Updated - - -

I was thinking another feature request might be a means to save a craft as stock ksp and thus strip out modded parts. Useful for engineers who test and build with mechjeb and others to simply save their creation as stock without having to remove their MJ and KER modules for example and thus reload their craft in a stock ksp and then save.

Link to comment
Share on other sites

Personally I try to avoid doing blanket things like this when I build code, but it's definitely something to consider. Because what if I reset a tweakable (like fuel) and that isn't what you wanted? It becomes a complex guessing game of "what should it be," so sometimes it's easier to leave it as-is.

Normally I would agree, but if having to fix the config of a few simple things manually prevents having to deal with a crash or otherwise useless/broken craft file, I think that's a small price to pay :P. Fuel would have to be something you'd reset anyway since some of it will have been used in the persistence file (unless it's sitting on the launchpad/runway of course). There is also the small technicality that if you don't write a blanket solution, then you will need to have a list of things that you should reset just to make it function, so really it's a question of which approach is the least problematic.

Link to comment
Share on other sites

Sorry, I don't mean to hijack your thread...but I guess your question is answered now, so we can discuss these utilities now if you want.

I posted on github the diff between mk3 cockpit made in sph and converted cockipit. Minor diffs, only value changes. Not sure if relevant or breaking except for the toggles being converted to false.

Value changes are what I'm after. I haven't looked yet, but thanks for giving some feedback.

This feature could be redundant with HyperEdit though.

Very true, and I have no intent on trying to supplant HyperEdit. I really just mean for this to be a simpler utility, originally intended to help with exactly what you had happen. "Help me rescue this craft I built and forgot to save!"

The second iteration is an extension from a request by another user who wanted a simple way to "fix" a vessel in the VAB and replace one in the field (for mistaken builds). It's really an independent feature, but might actually fit well with this utility.

I was thinking another feature request might be a means to save a craft as stock ksp and thus strip out modded parts.

Well now, this is also a good idea but has the potential to be very complex. Modded parts in the middle of a ship can be a huge problem. Removing something like the slap-on surface mounted MJ or KER wouldn't be too big of a deal, but pulling off stack attached part would be a mess. I mean, it would be doable in code, but the ship itself would be a mess afterward. Unless you had something else in mind.

Normally I would agree, but if having to fix the config of a few simple things manually prevents having to deal with a crash or otherwise useless/broken craft file, I think that's a small price to pay :P. Fuel would have to be something you'd reset anyway since some of it will have been used in the persistence file (unless it's sitting on the launchpad/runway of course). There is also the small technicality that if you don't write a blanket solution, then you will need to have a list of things that you should reset just to make it function, so really it's a question of which approach is the least problematic.

Hmm, maybe I sounded more dismissive than I meant to. I mean I want to avoid making blanket code along the lines of "Everything Active = False" because there may be some active things that need to be active. Science parts surprised me because some things needed to be on, while other stuff was off. I certainly don't want to leave behind a broken craft, but I would also like to change a little as required.

For example, even resetting the fuel can be a complex answer. Maybe the user had tweaked out fuel loads such as SRBs or used an LFO tank with zero Oxy (as for a space plane).

Also, I have to have a list of things that need to be reset anyway. I can't simply set all "False" things to "True" or vice versa (although I'm not sure if that's what you meant). And I haven't even looked yet to see what kind of a mess docking ports turn into.

Now, that being said, I am asking what things you guys think should be reset. I can be convinced of resetting fuel, because it's more likely that a given craft's tanks are full rather than partially drained. So in that case, refilling tanks makes sense because it would be correct more often then not. Turning off lights, stowing solar panels, and resetting science experiments also makes sense.

Now that I said all that, what about the case where a user wants to do the scenario I mentioned about "fixing" their vessel? If an intended use for this mod is to pull a vessel, fix something, then put it back...I don't want to refill all the fuel and reset everything that doesn't need to be reset. Hopefully you could see why.

So I think there's validity to each approach. I think what you propose makes sense if all the utility will ever do is rescue an in-flight vessel out to a .craft. I guess I'm just not sure how far I want to take it yet. The initial goal of this project was to see if it would work and to save inigma's shuttle. Now I'm open to suggestions for what to improve. :D

Cheers,

~Claw

Link to comment
Share on other sites

Hmm, maybe I sounded more dismissive than I meant to. I mean I want to avoid making blanket code along the lines of "Everything Active = False" because there may be some active things that need to be active.

I think you misunderstood what I meant; can't you query KSP to ask what the default values for a part are when you drag the part out of the parts list, and use those? I'm not saying you should just set everything to true or false, but rather whichever value it would be set to if the part were unmodified on placement.

Link to comment
Share on other sites

Perhaps offer the user the option to check box (off by default) Keep Persistent Values when Save is clicked. This allows the Original Pre-Launch Craft to be saved by default while giving the option to choose a persistent compatible pulled craft state.

Talking about this mod is no hijack and is welcomed. :)

Edited by inigma
Link to comment
Share on other sites

Well, that would be a roundabout way of doing it, but sure I guess :). You could of course still have a list of things to leave alone though.

I guess I didn't mean actually rebuild it, just to put it back in a state as if it were freshly built. I think that is what you are getting at?

Perhaps offer the user the option to check box (off by default) Keep Persistent Values when Save is clicked.

Yeah, I think that's what I would do if I were to take the mod that far. It would need some sort of GUI to load ships. So if I go that far then I could make that an additional option.

I think at the moment you guys are making me lean toward resetting most of the ship to a "pristine" stae. If I include a "load" option at some later point, I could modify it to reset only the editor/craft breaking things.

Cheers,

~Claw

Link to comment
Share on other sites

I guess I didn't mean actually rebuild it, just to put it back in a state as if it were freshly built. I think that is what you are getting at?

Yeah, I think that's what I would do if I were to take the mod that far. It would need some sort of GUI to load ships. So if I go that far then I could make that an additional option.

I think at the moment you guys are making me lean toward resetting most of the ship to a "pristine" stae. If I include a "load" option at some later point, I could modify it to reset only the editor/craft breaking things.

Cheers,

~Claw

Well, that's basically what the Python script would do. It had a list of things to delete, a function to solve the Name-CID relation, and will have some to restore editor rotation/position. It wouldn't touch anything else.

Any chance I could see the source code?

Link to comment
Share on other sites

Any chance I could see the source code?

Psst. If you click the project name on the github release page (linked by claw earlier), it'll take you to the master branch which contains the source code.

To save the effort:

https://github.com/ClawKSP/InflightShipSave

Edited by armagheddonsgw
Link to comment
Share on other sites

KSP actually does a fair job of converting the parts back into something usable by the editor. It's deciding what states to reset the MODULEs to that needs to be done in the code. I am debating if I "want" to reset everything, but that's probably what I'm leaning toward at the moment.

And yeah, source code is up on Git.

Cheers,

~Claw

Link to comment
Share on other sites

One thing left to fix before a test run that will, unfortunately, most likely fail.

Generating this:

link = Mk1FuselageStructural_4294727434

attN = bottom,Mk1FuselageStructural_4294727434

From this:

srfN = None, -1

attN = bottom, 1

attN = None, -1

And the next part = tag. If there's an attN tag, the program will search for the next part =, copy it, and replace the 1/-1 that exists currently.

:huh:

I think that's all that's left.

Link to comment
Share on other sites

I finished the STS. An empty cargo bay version of Space Shuttle Intrepid is done! The tank and boosters are completed. Maiden voyage was a success even landing back at KSC runway without mods. My goal with this ship is to build it in such a way that Squad might consider it for stock vessel inclusion.

The thing is beautiful. An eye candy craft that delivers and flies easy.

gPkfRkw.png

Now for the fun part. Next up is testing various cargoes to find the optimum launch stack placement so all anyone has to do is tweak the least amount of parts to orbit different cargo weights. I want to publish three versions of the craft: empty, standard, and heavy (orange tank payload) with standard being the most popular with a crew module so the shuttle carries 7 or 8, docking port, and 1 large or 2 medium satellites.

After that comes mechjeb testing so even new players can fly it without much think. I might even try it in FAR for those who really care.

Edited by inigma
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...