PERSONAL
2,608
MARDEK Re-release - Secure saving solution? (UPDATE)
5 years ago - Edited 5 years ago1,440 words
I'm feeling better, and I have some ideas for how to
maybe handle the MARDEK Re-release technical issues regarding saving!
UPDATE:
I've already got this working! Once I put my mind to it, it didn't take very long.
The game does a check every five minutes: first, it checks if the directory that .sol files save into exists, using a path it works out rather than asking for the player to specify it (though they could also do that manually if this doesn't work). Once it knows that directory exists, it copies all the MARDEK .sol files from it into a backup directory. When the game starts up, it checks the contents of its backups directory against the contents of the .sol directory. If there are files in the backups directory but not the .sol one, copies are generated for that .sol directory.
I'm unsure how versatile or accurate it'll be across different machines, but it might very well be the solution I've been hoping for!
I just wanted to post an update because I've been in bed depressed for a week - as I wrote about in the previous post - and it's only today that that fog's started clearing. It's difficult to go straight from that to the old work mode, though, so hopefully writing this will help as a transition.
I was wondering whether to talk more about the specifics of what's weighed me down so much, but I don't know, maybe I talk more than I should about my various personal issues here. Maybe it's best to just say things are clearing up and leave it at that.
Though I've mostly been in bed wasting time or playing Animal Crossing this past week, I've had a few moments of clarity where I've been able to try to solve the MARDEK Re-release issues. I've had no success though. I followed
∞ Matt Roszak's advice ∞ and tried to set up something called LocalConnection, which can apparently allow AS2 and AS3 swf files to communicate with one another. I think I set up everything correctly - I even used a couple of classes written by someone else which seemed more competently made than I could manage myself - but it's just not working for me; the swfs aren't able to find one another, so I'm not able to load in data from the MARDEK AS2 file or send data to it, as I'd need to to generate less fragile save files. I actually emailed him (finally) asking for any assistance, though I feel like my issue's probably too unclear anyway so I don't know if there's any hope there (no reply yet).
Maybe I've talked about this already, but here's a bit of a refresher: The only real way that Flash (or at least the version MARDEK was written in) can save data is as 'SharedObject' files with a .sol extension, and since Flash was mostly meant as a browser extension, they're treated as cookies, and deleted when browser cookies are. Or some people can have security settings that prevent them from even being saved at all. As such, a few people have told me that their saves for MARDEK were unreliable, so they never even finished the game. They were looking forward to a Steam release as it would presumably address that with more secure saves.
So my plan was to write a wrapper in AS3 (ActionScript 3, the 'new' Flash coding language) - which, unlike AS2 (ActionScript 2, which MARDEK was written in), can write to and read from the disk - which would load in the AS2 swf (embeddable Flash file), and connect with it via LocalConnection. Saving, then, would involve sending the data from the AS2 to the AS3 and writing it as a .txt file in the game's local domain, where Steam would back it up automatically. I'd also need to send the .txt file(s) back to the AS2 and parse it/them for loading.
As I said, though, LocalConnection just doesn't connect, so that path's blocked to me.
Months ago, I made a wrapper in C sharp which could load in the exe projector version of MARDEK; I've talked about this a few times already. That worked fine, but there was no way to get data between the projector and the wrapper, so there was no way to preserve the saves.
Or that's what I thought. But an idea's occurred to me: Instead of rewriting the whole save system - potentially buggering something up in the process - and passing data back and forth between the wrapper and game, instead I could just have the wrapper listen for any changes to the directory in which the .sol files are saved in (C sharp handily has something called FileSystemWatcher for this exact purpose), and whenever they change, copies of the files are transferred to the place I'd be saving the .txt files to if I'd managed to get that working.
There are a couple of less-than-user-friendly barriers to this though. One is that the program couldn't know the directory itself, because it includes a folder with a randomised name. My path looks like this:
C:/Users/user/AppData/Roaming/Macromedia/Flash Player/[hash]SharedObjects/9CTAKGAT/localhost
I'm not even certain that the same path would be used on everyone's computer;
∞ this page ∞ - which I linked to last time - describes a different path for Flash .sol saves. The "9CTAKGAT" is definitely a random string. And I don't know how well it'd hold up in the long term, if people play this years from now. Though maybe the same could be said of any game's saves.
Anyway, I'd need to include some button to have the user manually navigate to this path the first time, after which it'd be stored as a .txt for future reference, though if MARDEK hasn't even run the first time, it wouldn't exist... so they'd probably need to start the game, then quit, and reload it just to set up this path. Hmm. Unless I wrote something to briefly load in the swf before unloading it, if the path txt didn't exist...
Once the program knew the path, it could save it and use it in future to listen for changes to that directory, but restoring them might have to be a manual action. That is, if you notice your saves are missing, you might have to press a Restore Saves button on the wrapper. Or maybe the wrapper could check in its folder for the saves it'd backed up, and if any are missing from the specified save folder, it could automatically copy them over... I'm unsure how deleting save files would work though.
I'd also need to include some kind of README .txt file with instructions about how to navigate to the directory, and any common issues like saves not even being created in the first place (basically what that page I linked to goes over). Bundling it as a file seems more secure than having it on my site.
If I did go down this path, I'd not be able to add Steam API integration (i.e. achievements). That seems to be a lesser concern than the saving thing, but it's still something that'd be a shame to have to omit. It's due to technical issues rather than choice, though.
Notably, while I got an AS3 wrapper working with the AS2 swf embedded as per Matt Roszak's advice, I noticed that the performance there was noticeably more sluggish than with the C sharp wrapper. There were also significant issues loading in music from an external folder, for whatever reason, which the C sharp wrapper didn't have. So I feel that the performance increases from the C sharp wrapper might be worth the lack of achievements integration. But presumably different players would have different preferences.
Also, to get the .txt files thing working would have required rewriting the whole save system, which was very intimidating and very likely to introduce a lot of issues that might take a long time to fix (if I even managed to catch them all at all). Copying over the .sol files like this would allow for preservation of the old save system, so none of these issues should be introduced.
So that's where I am at the moment. There are some big challenges, but this is a potential solution which
might work (though I've yet to actually experiment). I'll keep you posted.
I'm looking forward to getting this out of the way and getting back to Divine Dreams!
7