The Adventure into Resurrecting Adventure Ponies

A journey into fiddling with old flash files
Greetings! The resident code Kirin and web master of the site here to report on a little adventure, anecdotal as it might be.
Some of you might have noticed our recent attempts to give the site a little kick, as hard to see as it might be, and s far that has mainly included going through the good old Arcade. Games added, and revised, as well as the main addition of getting Ruffle properly integrated into the site with scripts, so none of you need to install any browser plugins! As well as Ruffle works, the games should work right out of the box for you!
With the overview out of the way, one of the major issues are the ways some of the games were put together a decade ago, when flash was still alive and no one thought of the day the Adobe would drop it. Adventure Ponies, for one, the official cute little pair of games, officially made and hosted by Hasbro and The Hub, back in 2012 and 2013. It's a classic... and it doesn't work. We wanted to fix that.

The Mysterious Case of The Flash File

Do excuse me if it gets overly technical at any point. SWF. Shockwave Flash. We know it. Flash files, like Adobe loved them until they suddenly didn't. A shame, but an understandable decision, as it leaves them in a grey area of software rot. Good thing, with how prolific they were, basically defining an era online, support is in the the hooves of the community. Not that tearing them open was ever easy.
Let's get to the point. Adventure Ponies 1 and 2 wouldn't load. Let's focus on 1. Ruffle would succesfully launch the file, but it stuck on the loading screen. Well that sucks. A quick glance into the browser Network inspector revealed the culprit, however: missing assets.
Taking a look at this screenshot, this is odd. That's not the address the game is hosted at. We use Amazon AWS for game storage, as much as possible, so nothing is stored directly on the blog. Something is wrong with the flash code and needs to be fixed.

Into Unknown Territory

Decompiling flash files is certainly new to me. Always seemed like dark territory, like decompiling any regular program, which leaves you with obfuscated code you need to decipher. I've never said no to a challenge before, and it really should only take changing some text string addresses for the assets, so it shouldn't be too hard. What's a good tool... Oh, that sounds promising, JPEXS Free Flash Decompiler. Let's give it a go.
I have to be honest, I was genuinely surprised. Firing up the odd looking program, loading the file and... there we are. The entire contents of the flash file laid bare. Every single art asset, level and piece of code, right there. I thought this part was gonna be harder. The next part might be, as I have never done any work in flash or the programming language behind it, ActionScript, but how hard could it be since I have experience in other C based languages? Having to search through the copious amount of code in the scripts section might be. What we are looking after is any place that mentions "audio.swf" and "config.xml".
A bit of intuition and experience in other programming helps a lot in this. Alright, it's during the load the game fails, at the splash screen. This section named "splashworks" sounded promising. In hindsight I realize splashworks might just have been the developers of the flash game, or the engine used, but regardless I found what I was looking for.
com.splashworks.Doc. Hit the nail right on the head. A few lines, adding assets to be loaded, in particular "this.AL.addAsset(new String(Ref.myAssetPath + "swfs/audio.swf"),1);". My best guess is that Red.myAssetPath is somehow set to the site that is currently running the flash file. It was a good guess, but sparing you all the pointless search, I proceeded to spend somewhere between one and two hours searching for the magical point in the code that assigned this wrong path. Fixing it at the source might fix it everywhere, was my thought.

Epiphany!

After enough time spent hitting my head against the wall, figuring out what that Ref variable is, figuring out where the Doc class plays in, I gave up on searching and went back to basics. Just adding extra text to the path and seeing if it works. "this.AL.addAsset(new String("http://test.test/" + Ref.myAssetPath + "swfs/audio.swf"),1);" I clicked save, a surprisingly quick operation, then uploaded the modified version, adding it to the arcade page and... Well, it worked! I attempted to get http://test.test/swf/audio.swf. Not only did it prove that this weird looking program really can unpack and repack flash files with no issues, but that myAssetPath is... actually empty. Makes life easier! What if I put something in it? Ref.myAssetPath = "http://testtest.horse/". Went through the deployment process, and... Yep. This here is the key.
This has been long winded enough, so to not rambling more than I already have, this code generously taken from stack overflow and my own discoveries used has lead me to three lines.
var urlPattern:RegExp = /(^.*\/).*$/;
A regex search and replace pattern. Matches in parts, first everything until the last slash. Second the rest, covering only the file name. Everything before the file name is grouped with the parentheses so the file name can be shaved off.
var result:Array = urlPattern.exec(Ref.doc.root.loaderInfo.loaderURL);
We execute the regex search mechanism. Ref.doc.root refers to the absolute root of the flash application, I believe, and .loaderInfo.loaderURL gets the full URL to the flash file.
Ref.myAssetPath = result[1];
And finally we take only the first grouped part, as mentioned, shaving off the file name. myAssetPath has been set with a path that is gonna work perfectly! Any place the flash game is hosted, it will be looking for assets hosted at the same address the file is located!

Achievement in Preservation

What do you know? It works flawlessly, just as hoped.
So, what has been done at the end of the day? This flash game from 2012 has been decompiled. Three lines of code have been added, fixing the asset loading path. Then the game was recompiled under a new name to denote its changed nature. It was uploaded back onto our server and the arcade was updated to use it rather than the broken original. Welcome back, Adventure Ponies, you old classic! Amd Adventure Ponies 2 as well. It was the same issue, and just copying the same exact lines of code fixed it up right as rain. letting you wreck Sombra in just two kicks again.
It all sounds simple. It probably was, but the whole notion of messing with the code of games already done and released, no source code or anything else available was always a daunting barrier. Making anything more than some tiny changes very much still is. This has definitely opened some doors in terms of preservation, though.. One other game with issues that comes to my mind is Waiting is Magic, which I personally find endearing, despite its broken state. I just have to gush one last time, it really is wild just how easy, and how deep, you can just dive into old flash games. I really, really didn't expect it to be this straightforward.
For whoever actually read this far, thanks for joining me on this little adventure in legacy pony game preservation. Having this knowledge now, don't expect this to be the last time it's done, though this is probably the last time I write a wall of text like this about it. It could probably just have been a single paragraph saying "I did a thing," but here you go!
- Lex Rudera

No comments :

Post a Comment