Jump to content

Possible to Save Ship from Persistence File?


Recommended Posts

I totally hit delete on my save game, without realizing it also deleted hours worth of craft files, development versions, and my backup craft files! All I have remaining is a persistent game file I somehow manage to save prior to the whole incident. It has the latest version of the space shuttle I worked so hard on, sitting on the pad ready for launch. Pristine condition. I just can't figure out a way to save it to a craft file.

Is there any chance or way whatsoever to save that ship as a craft file again? I am desperate.

UPDATE 1/13/2015 - THIS HAS BEEN ANSWERED AND THE ENDING IS HAPPY!

Starwhip was working on a converter in Python but it looks like Claw beat him to it in C#. :D

InflightShipSave

https://github.com/ClawKSP/InflightShipSave/releases

put this dll in your GameData folder, load KSP, load your active vessel in flight, and hit F6 to save it as a file named the craft name with _rescued appended at the end of it in your save game VAB folder.

Beautiful. Simply beautiful.

Space Shuttle Intrepid (version 22) was rescued from its persistence.sfs file (formerly a quicksave file I luckily didn't delete) and made into a .craft file! Thanks Claw! Hours of work (on those wings) rescued for sure. I hope Google has helped you find this post in joy. If so, reply!

bGnyxb1.png

Edited by inigma
Link to comment
Share on other sites

Oh dear ... :(

You can try and open the save file (e.g. with notepad+) and search for the craft's name.

Then compare the layout of this part of the file with another regular craft file - but I am almost sure there are big differences ...

Link to comment
Share on other sites

If you have Windows 7 (or later) go to the KSP folder and right-click on the "saves" folder, go to "Properties". Look at the "Previous Versions" tab and save out a copy of your older "save" folder.

(I also strongly suggest installing a backup tool like Acronis True Image or something else that images the entire drive on a monthly basis.)

Link to comment
Share on other sites

I think I've disabled system restores but I will check.

I was going to reboot my game after accidentally hyperediting Kerbin just 70km from the sun. So I went to my save folder and copied my sph and vab folders to the root of the saves folder, and moved to the recycle bin the persistence and quicksave files. I reloaded KSP and it told me I had invalid saves and asked me if I wish to delete. It was a blank GUI with nothing listed for deletion so I assumed it was the default save game folder it was asking to delete. Well, after clicking delete it deleted from my saves folder the default savegame folder as expected, but it also deleted my sph and vab folders I had copied to the saves folder. Argh! 22 development versions of my shuttle gone. All that remained was my persistence and quicksave in the recycle bin. Not even Recuva could find the craft files. As if game deletion permanently erases them somehow. I loaded the persistence file from the recycle bin back into KSP and thankfully my latest version 22 of my shuttle sits on the pad. I just need to find a way to convert it to a craft file. If anyone else has ideas, please share. I'm sure I'm not the only one who's run into this kind of need.

Edited by inigma
Link to comment
Share on other sites

Can't you just rename the persistent file something like "TEST.sfs", make a new game

Wait, you want the craft file. :(

Try copy-pasting the CRAFT{...} part that applies to the ship into a new .craft file. Create a notepad document if you can, or any other simple text file, and rename the extension to .craft.

You might want to make a .craft with just a capsule so that you can put the right starting info, instead of the orbit/speed stuff that a persist contains.

EDIT:

Hold on, I'll try it myself. Just gotta make a test craft.

Link to comment
Share on other sites

Haha. I play from my Downloads folder. Heh. Its the only folder I don't back up. Go figure.

Is it possible to copy paste values into a craft file? I suppose I could create a new craft file and insert all the parts roughly back in the SPH, save, and then edit the file by copy pasting values as needed... hmmm. This could get tedious but worth it if it works.

Link to comment
Share on other sites

Yikes. This is complicated.

I tried it with a kind-of-simple craft, but I don't know enough about the .craft file to be able to convert back to a ship from the .sfs.

PROBLEM #1:

You need rotation/offset values.

PROBLEM #2:

You need all of the other stuff in a .craft file that the .sfs does not contain, like the. Even the test craft, at <20 parts, is a huge block of code.

I assume your shuttle is a hell of a lot more than 20 parts.

Mid-Post UPDATE

Actually, if you had the time, it's not as bad as I thought.

Only the first 20 lines or so of every PART{...} block need to be fixed: the rest is identical. Make some backups of the .sfs so that you've got something to fall back on.

If you've got the time, I think that this is possible... though I certaintly think that just starting again based off of what's on the pad is the best plan. Take some screenshots of every stage and just start over.

Link to comment
Share on other sites

Yikes. This is complicated.

I tried it with a kind-of-simple craft, but I don't know enough about the .craft file to be able to convert back to a ship from the .sfs.

PROBLEM #1:

You need rotation/offset values.

PROBLEM #2:

You need all of the other stuff in a .craft file that the .sfs does not contain, like the. Even the test craft, at <20 parts, is a huge block of code.

I assume your shuttle is a hell of a lot more than 20 parts.

Mid-Post UPDATE

Actually, if you had the time, it's not as bad as I thought.

Only the first 20 lines or so of every PART{...} block need to be fixed: the rest is identical. Make some backups of the .sfs so that you've got something to fall back on.

If you've got the time, I think that this is possible... though I certaintly think that just starting again based off of what's on the pad is the best plan. Take some screenshots of every stage and just start over.

138 parts.

I am studying the differences between craft and persistence, and there is a lot of shared information that I think could be done to make it work. The point is if it can be done manually, then it can be done via a simple script, which could do it instantly, no matter the part count. :) Maybe start with one part and go from there to reconstruct it? Say, reconstruct from a persistence file the following into a craft file:

Mk3 Cockpit

TT18-A Launch Stability Enhancer

If that can manually be done... then programming a converter should be doable.

Edited by inigma
Link to comment
Share on other sites

138 parts.

I am studying the differences between craft and persistence, and there is a lot of shared information that I think could be done to make it work. The point is if it can be done manually, then it can be done via a simple script, which could do it instantly, no matter the part count. :) Maybe start with one part and go from there to reconstruct it? Say, reconstruct from a persistence file the following into a craft file:

Mk3 Cockpit

TT18-A Launch Stability Enhancer

If that can manually be done... then programming a converter should be doable.

Do you have any experience with this type of coding? I do. I made a program in Python to check a hexadecimal file from a calender program and convert the events stored within into readable text.

If you could figure out how the persistence location/rotation relates to the .craft loc/rot, I'll be happy to try this myself.

EDIT:

To prove that I'm not just blowing hot air:


#EVENTMINDER TRANSLATOR

CPersonFlag = "97 00 0F 00 FF FF 64 00 07 00 43 50 65 72 73 6F 6E"
CFamilyFlag = "47 00 0F 00 FF FF 64 00 07 00 43 46 61 6D 69 6C 79"
CEventFlag = "60 00 5B 00 FF FF 64 00 06 00 43 45 76 65 6E 74"
CReminderFlag = "6D 07 7B 07 FF FF 64 00 09 00 43 52 65 6D 69 6E 64 65 72"

TestEntryFlag = "6A 6F 65 20 30 38 3A 30 30 20 74 68 65 72 61 70 79"

NewReminderFlag = "3D 81"
NewEventFlag = "E1 80"

RawHexFile = "C:\Python34\EVENTMNDRawHexValues.txt"
TransHexFile = "C:\Python34\EVENTMNDTranslated.txt"
DecomHexFile = "C:\Python34\EVENTMNDDecompiled.txt"
DBCEventFlagFile = "C:\Python34\DBCEventFlag.txt"

TempFileString = ""

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(' ')
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 getRecords(FileSList,RecordFlag,EFlag):
'''Returns records under RecordFlag specified by S(tart) and E(nd) Flags'''
tempString = returnFromPosToPos(FileSList,len(RecordFlag.split(' ')) - 1,len(FileSList))
tempString = tempString.split(EFlag)
return tempString

def convertToChar(num):
'''Returns ASCII equivalent of hexadecimal value num'''
num = chr(int(num, base=16))
return num




Months = ['January','Feburary','March','April','May','June','July',
'August','September','October','November','December']

MonthDays = [31,28,31,30,31,30,31,31,30,31,30,31]

ZeroDate = 28539
ZeroYear = 2005
ZeroDay = 1
ZeroMonth = 1

def GetDate(Value):
'''Function gets the hexadecimal values for a date'''
HexDate = Value.split(' ')
return HexDate

def ConvertToChar(hexNum):
'''Returns ASCII equivalent of hexadecimal value hexNum'''
hexNum = chr(int(hexNum, base=16))
return hexNum

def ConvertToHex(char):
'''Returns Hexadecimal equivalent of ASCII value char'''
char = int(char, base=16)
return char

def IsLeapYear(Year):
'''Returns TRUE or FALSE'''
if (Year % 4) == 0:
return True

else:
return False

def DaysOfYear(Year):
'''Returns 365 or 366'''
LeapYear = IsLeapYear(Year)
lyd = 366
nyd = 365
if LeapYear:
return lyd

else:
return nyd

def DaysOfMonth(Month,Year):
'''Returns numeric value of days based on numeric month value'''
Days = DaysOfYear(Year)
if Days == 366:
if Month == 2:
return (MonthDays[Month-1] + 1)

return MonthDays[Month-1]


def ConvertToDate(HD):
HexDate = GetDate(HD)
ConvertedDate = []
for i in range(len(HexDate)):
ConvertedDate.append(ConvertToHex(HexDate[i]))

## print(ConvertedDate)

Value = 0
Value += ConvertedDate[0]
Value += ConvertedDate[1] * 256

Value -= ZeroDate

Year = ZeroYear
Month = ZeroMonth
Day = ZeroDay

if Value < 0:
pass
## print("Warning: Date Before 1/1/2005")

else:
while Value > 1:
while Value >= DaysOfYear(Year):
Value -= DaysOfYear(Year)
Year += 1

while Value > DaysOfMonth(Month,Year):
Value -= DaysOfMonth(Month,Year)
Month += 1

if Value > 1:
Value -= 1
Day += 1

date = "Date: "
MonthStr = Months[Month-1]
date += (MonthStr + ' ' + str(Day) + ' ' + str(Year))

TempFileString = decompileFile(RawHexFile)

EndOfList = lenOfList(TempFileString)

CRFPos = searchString(TempFileString,CReminderFlag,0)

AfterCRF = returnFromPosToPos(TempFileString,CRFPos,EndOfList)

writeToFile("AfterCRF.txt",AfterCRF)

AfterCRF = decompileFile("AfterCRF.txt")

CReminderRecords = getRecords(AfterCRF,CReminderFlag,NewReminderFlag)

writeToFile("CReminderRecords.txt","\n")

for i in range(len(CReminderRecords)):
tempSList = CReminderRecords[i].split(' ')
del tempSList[0]
del tempSList[len(tempSList) - 1]

if len(tempSList) > 28:
lenOfStr = int(tempSList[28], base = 16)


tempString = ''
for i in range(len(tempSList)):
if i == 0 or i == 4 or i == 8:
toConvert = str(tempSList[i]) + ' ' + str(tempSList[i+1])
print(toConvert)
tempString += str(ConvertToDate(toConvert))

if i == 1 or i == 2 or i == 3 or i == 5 or i == 6 or i == 7 or i == 9 or i == 10 or i == 11:
pass

else:

if i == 29:
tempString += "---------- "

if len(tempSList) > 28:
if i == (29+lenOfStr):
for x in range(60 - lenOfStr):
tempString += '-'

if i > 28 and i < (29+lenOfStr):
tempString += convertToChar(tempSList[i])

else:
tempString += tempSList[i]
tempString += ' '

appendToFile("CReminderRecords.txt",tempString)
appendToFile("CReminderRecords.txt",'\n')


:)

Edited by Starwhip
Link to comment
Share on other sites

rot/loc conversion...I wonder if a Squad dev would be happy to provide this info.

Either that or trial and error with a single part.

And I only have php experience. This would be a whole new challenge to develop. Feel free to share anything you discover too.

Link to comment
Share on other sites

Here's the difference in PART{...} blocks.

First is an actual .craft

part = landerCabinSmall_4294737886
partName = Part
pos = 0,15,0
attPos = 0,0,0
attPos0 = 0,15,0
rot = 0,0,0,1
attRot = 0,0,0,1
attRot0 = 0,0,0,1
mir = 1,1,1
symMethod = Radial
istg = 0
dstg = 0
sidx = -1
sqor = -1
attm = 0
modCost = 0
modMass = 0
modSize = (0.0, 0.0, 0.0)
link = Mk1FuselageStructural_4294727434
attN = bottom,Mk1FuselageStructural_4294727434

In the .sfs


name = landerCabinSmall
cid = 4294737886
uid = 3824442438
mid = 3416635193
launchID = 22
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, 1
attN = None, -1
mass = 0.6
temp = 16.07135
expt = 0.5
state = 0
connected = True
attached = True
flag = Squad/Flags/esa_black
rTrf = landerCabinSmall
modCost = 0
crew = Jebediah Kerman

The first four lines can be deleted.

the position and rotation flags need to be converted to pos and rot


mirror = 1,1,1
symMethod = Radial
istg = 0
dstg = 0
sqor = -1
sidx = -1
attm = 0

These can be kept as is.


modCost = 0
modMass = 0
modSize = (0.0, 0.0, 0.0)

This needs to be added.

Link and attN can most likely be figured out by looking at the .sfs's next part, but I haven't figured that out yet.

EDIT:

Woah, wait, you can't delete the cid tag!

That's what identifies the part attachment! :D Looky!

.sfs:

name = Mk1FuselageStructural

cid = 4294727434

.craft:

link =Mk1FuselageStructural_4294727434

Notice anything? :wink:

- - - Updated - - -

This! THIS IS POSSIBLE!

name = Mk1FuselageStructural
cid = 4294727434
[s]uid = 1913635372
mid = 3416635193
launchID = 22[/s] Delete these
parent = 0
position = 0,-1.5625,0 <-- This one's the pos tag
rotation = 0,0,0,1 <-- This one's the rot tag
[b]mirror = 1,1,1
symMethod = Radial
istg = 0
dstg = 0
sqor = -1
sidx = -1
attm = 0[/b] Keep all of this verbatim
srfN = None, -1
attN = top, 0
attN = None, -1 <-- This stuff for the attachment logic
[s]mass = 0.1
temp = 16.09112
expt = 0.5
state = 0
connected = True
attached = True
flag = Squad/Flags/esa_black[/s] get rid of that
rTrf = Mk1FuselageStructural <-- Not sure yet.
[s]modCost = 0[/s] Nope.


part = Mk1FuselageStructural_4294727434
partName = Part
pos = 0,13.4375,0
attPos = 0,0,0
attPos0 = 0,-1.5625,0
rot = 0,0,0,1
attRot = 0,0,0,1
attRot0 = 0,0,0,1
mir = 1,1,1
symMethod = Radial
istg = 0
dstg = 0
sidx = -1
sqor = -1
attm = 0
modCost = 0
modMass = 0
modSize = (0.0, 0.0, 0.0)
link = Mk1FuselageStructural_4294727306
link = Mk1FuselageStructural_4294727226
attN = top,landerCabinSmall_4294737886

Edited by Starwhip
Link to comment
Share on other sites

Yeah, I think so. Already working on the program. I'm going to try to just extract the VESSEL{...} block first, then move ahead from there.

- - - Updated - - -

Tried to put the program output up here, but it was 2,000,000 characters. :)

It looks a lot like this:

guiIcon = Change Name Tag\n\t\t\t\t\t\t\tguiName = Change Name Tag\n\t\t\t\t\t\t\tcategory = Change Name Tag\n\t\t\t\t\t\t\tguiActiveUnfocused = False\n\t\t\t\t\t\t\tunfocusedRange = 2\n\t\t\t\t\t\t\texternalToEVAOnly = True\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tACTIONS\n\t\t\t\t\t', '\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tPART\n\t\t\t', '\n\t\t\t\tname = Mk1FuselageStructural\n\t\t\t\tcid = 4294727098\n\t\t\t\tuid = 1070256818\n\t\t\t\tmid = 3416635193\n\t\t\t\tlaunchID = 22\n\t\t\t\tparent = 6\n\t\t\t\tposition = 1.88097715377808,-0.157959938049316,-2.91306832878035E-07\n\t\t\t\trotation = -0.4994757,0.5005239,0.4994752,0.5005243\n\t\t\t\tmirror = 1,1,1\n\t\t\t\tsymMethod = Radial\n\t\t\t\tistg = 0\n\t\t\t\tdstg = 0\n\t\t\t\tsqor = -1\n\t\t\t\tsidx = -1\n\t\t\t\tattm = 1\n\t\t\t\tsym = 3\n\t\t\t\tsrfN = srfAttach, 6\n\t\t\t\tattN = None, -1\n\t\t\t\tattN = None, -1\n\t\t\t\tmass = 0.1\n\t\t\t\ttemp = 16.05903\n\t\t\t\texpt = 0.5\n\t\t\t\tstate = 0\n\t\t\t\tconnected = True\n\t\t\t\tattached = True\n\t\t\t\tflag = Squad/Flags/esa_black\n\t\t\t\trTrf = Mk1FuselageStructural\n\t\t\t\tmodCost = 0\n\t\t\t\tEVENTS\n\t\t\t\t', '\n\t\t\t\t}\n\t\t\t\tACTIONS\n\t\t\t\t', '\n\t\t\t\t}\n\t\t\t\tPARTDATA\n\t\t\t\t', '\n\t\t\t\t}\n\t\t\t\tMODULE\n\t\t\t\t', '\n\t\t\t\t\tname = KOSNameTag\n\t\t\t\t\tisEnabled = True\n\t\t\t\t\tnameTag = \n\t\t\t\t\tEVENTS\n\t\t\t\t\t', '\n\t\t\t\t\t\tPopupNameTagChanger\n\t\t\t\t\t\t', '\n\t\t\t\t\t\t\tactive = True\n\t\t\t\t\t\t\tguiActive = True\n\t\t\t\t\t\t\tguiActiveEditor = True\n\t\t\t\t\t\t\tguiIcon = Change Name Tag\n\t\t\t\t\t\t\tguiName = Change Name Tag\n\t\t\t\t\t\t\tcategory = Change Name Tag\n\t\t\t\t\t\t\tguiActiveUnfocused = False\n\t\t\t\t\t\t\tunfocusedRange = 2\n\t\t\t\t\t\t\texternalToEVAOnly = True\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tACTIONS\n\t\t\t\t\t', '\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tPART\n\t\t\t', '\n\t\t\t\tname = GooExperiment\n\t\t\t\tcid = 4294713946\n\t\t\t\tuid = 2310267452\n\t\t\t\tmid = 3416635193\n\t\t\t\tlaunchID = 22\n\t\t\t\tparent = 7\n\t\t\t\tposition = 2.52319931983948,-0.159310340881348,0.468961000442505\n\t\t\t\trotation = 0.7063646,-0.7078475,-0.0007417688,0.0007400255\n\t\t\t\tmirror = 1,1,1\n\t\t\t\tsymMethod = Radial\n\t\t\t\tistg = 0\n\t\t\t\tdstg = 0\n\t\t\t\tsqor = -1\n\t\t\t\tsidx = -1\n\t\t\t\tattm = 1\n\t\t\t\tsym = 4\n\t\t\t\tsrfN = srfAttach, 7\n\t\t\t\tmass = 0.15\n\t\t\t\ttemp =

EDITED: It was too long :D

- - - Updated - - -

HA!

GKqfnjP.png

I found you, you little bugger!

(Looking for the "name = TEST OF .CRAFT" vessel)

Link to comment
Share on other sites

lol. great job so far.

here is a link to the vessel I'm trying to resurrect.

http://www./view/52l52p6swdyuhz2/intrepid22.txt

and here is it in a persistence.sfs for context:

http://www./download/edjob2415dxdyid/persistent.sfs

feel free to load up the sfs to see what im talking about. the wing design is exquisite. :)

I run Kerbal Engineer Redux, Editor Extensions, and Docking Port Alignment Indicator as the only mods.

if only i could get this craft back...

Link to comment
Share on other sites

Editing the .sfs back into a .craft by hand is a daunting task. It might actually be easier to write a KSP add-on to run through the vessel in the .sfs and output a .craft file. Although there is probably some conversion that needs to be done from parts backwards to proto-parts. Hmm...

Funny, I was thinking about this very thing the other day. Although it's piled in a tall stack of "things to do."

Good luck saving your craft,

~Claw

Link to comment
Share on other sites

I've hand-edited my .craft and save files when I switched from KER 0.6 to 1.0 beta. It sure seemed to me like the only difference between the two (wrt vessels, of course) was the indent level of the informstion. But I was only renaming a single entry on each vessel, so I wasn't paying much attention to any other differences which might have been present.

Link to comment
Share on other sites

Right, here's my agenda for this.

1: Get a proper deletion function working

2: Get an insertion function working

3: Test them on the .sfs

4: Go over the method of conversion to see exactly what is needed.

5: Input those variables into the code.

6: Test out the code on a 1-part ship.

7: Test it on 2 parts

8: Test it on 20 parts

9: Go for real.

EDIT:


##KSP .sfs to .craft converter

sfsFileLoc = "C:\\Users\\Tris\\Downloads\\intrepid22.txt"
craftFileDest = "C:\\Users\\Tris\\Desktop\\Test Conversion.craft"

vessNameFlag = "name = Space Shuttle Intrepid 22"

toAdd1 = """version = 0.90.0
description =
type = SPH
size =
"""

toRemove1 = """
type = Ship
sit = PRELAUNCH
landed = True
landedAt = Runway
splashed = False
met = 0
lct = 43909.2879292793
root = 0
lat = -0.0488078969528881
lon = 285.274176596904
alt = 87.4177449331619
hgt = 18.21741
nrm = -0.002647814,0.9999918,-0.003074175
rot = -0.6997806,-0.09323753,-0.09810878,0.701419
CoM = 0.0002358153,-2.144555,3.381143
stg = 4
prst = False
ref = 3208160340
ctrl = True
cPch =
cHdg =
cMod = 0
ORBIT
{
SMA = 0
ECC = 1
INC = NaN
LPE = 34.7253632258839
LAN = 241.824291385492
MNA = -8.40714670366795
EPH = 43909.3079292793
REF = 1
}
"""
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

sfsFile = loadFile(sfsFileLoc)
flagPos = 0


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

Link to comment
Share on other sites

Maybe I should brush up on Python to see if I can help out here. If initial testing is successful, you could github this if you want. This project should be doable. Tedious to get all the parts programmed with their nuances. And new versions of KSP will almost certainly be a challenge. But if successful it will be the first ever converter in KSP. It could form the basis for another plugin idea I had to devlop a rotatable docking port for perfect alignment after docking... heh. :)

I'm looking forward to anything you can come up with.

Link to comment
Share on other sites

Progress! Now it cleans up the indentation in the file that you feed it.

That'll make it easier to find stuff.

- - - Updated - - -

And now it's even better. Gets rid of the irritating \t characters (TABIFY) and splits the file into a list every time there's a \n character (NEW LINE)

rnC9Ldu.png

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

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

Edited by Claw
Link to comment
Share on other sites

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.

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? I assume you mean things like activating reaction wheels or other stuff that can be changed in flight but not in the editor. It seems like that would solve the problem if it were possible, though it might mess up stuff like procedural parts. Nice work though :D

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...