Patching a game

Recently I decided to figure out how I would implement patches for the PC version of Bik.  At first I figured I would just have the player download the entire game again. But because of all the music, the download file will be about 150megs.

If I decide to fix a simple puzzle issue, dialogue error, or saving error, why should the user have to download 150 megs all over again.  Eventually I found this software that will create a small patch by comparing two different versions of your game. http://www.clickteam.com/patch-maker

To test it, I made a build of the game, then changed one letter from a dialogue line, then created a second build with that change.  I put both version into the patch maker expecting an extremely small patch.  Instead, I got a giant patch almost the entire size of the regular install.

What went wrong?  The patch software wasn’t to blame, it was my implementation of resource handling in Unity.  What had happened was I had been storing all my XML files, music, and sound files in the Unity resources folder.  When I changed one letter of an XML file, the resulting resources file that Unity creates is now different and so the patch maker must include the entire resources file.

The issue could be solved by using Asset Bundles, but I can’t afford Unity Pro for IOS, Android, AND desktop. So, I had to make a choice of how to handle the resources folder better.

At first I experimented with moving all the audio outside of the Unity data structure and load them in with .net or the WWW function.  This proved to be troublesome with audio on mobile platforms because now that entire audio file had to be loaded into memory and couldn’t be streamed from the disc.  (If anyone knows a way around that, please let me know!)

The only solution was to move the XML files out of unity. At first I put them manually into build directory but that proved annoying until I discovered the Unity Streaming Assets folder.  Anything in that folder will be copied exactly as it is into the build folder. And you can access that folder with a simple Application.streamingAssetsPath call.

Of note on Android it was troublesome because it is now inside a compressed file and to access it you need to use the WWW class.

So now I did the same experiment and this time the patch was incredibly small and worked as I anticipated.

This exposed another flaw in my design though, and that was that the player could now browse to the install directory, read the XML files and even alter them.  That wouldn’t be good, so I found the Elixis C# encryption library and now encrypt all the XML files during the build process in Unity. https://code.google.com/p/elixis/

This entry was posted in DevBlog. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *