Hi guys,
I’d like to create a patch/patcher/updater for my game. For example if i changed something i don’t wanna reupload all my game but only a patch that changes only what i want. Is it possible? Thanks.
For standalone builds there are generally three kinds of patchers / updaters:
- A version-to-version updater
- A live validator file-to-file updater
- An actual partial / differential file patcher which has patch instructions on a file-to-file basis
The first kind is where you would explicitly download an update from a specific version to of the game to a new version. This requires that you can identify the current version of the game in order to not apply the update to the wrong version. This is usually done by storing a version string somewhere along the game files. The actual patch / update could be distributed any way you like
For the second kind you need some webspace where you can actually host all your game files individually and which allows the automatic patcher to request any file individually. You also need to identify the “version” of each file. This is usually done by simply storing the file name, it’s size and a hash value to uniquely identifying a file version. At each start the updater would download the current file descriptions from your server and calculate the hashes of all local files. If there is some kind of difference (missing files, outdated files, corrupted files) the patcher would selectively download the latest version of each file. This however has some drawbacks. You need a way to authenticate the user to your webservice. Otherwise everyone could simply pull your game from your webservice. Most games that use such an approach are either free-to-play where it doesn’t matter or they require some kind of user account.
The last kind is more a technique than a seperate kind. It could be used in the first and second kind i’ve mentioned. However it can get quite complicated. That means you would create actual patch files which contain instructions how to bring version X of a certain file to version Y. This requires that you create actualy differential patches between all possible versions of a file. The main advantage is that patch files are usually smaller for large files if only a tiny bit has changed in that file. This technique has several drawbacks. It requires the previous version to be 100% intact. If a file is missing or corrupted it can’t be patched and you would need the complete version of the file. So using this technique in the first kind of updates would simple make the update fail if something is wrong. In the second kind the updater would choose what to download based on the current version of the files. Implementing such a feature yourself can be quite complicated and usually isn’t worth it. If you want to use differential patches you better look for existing solutions.
Since Unity packs most assets into a few asset database files the success of the differential technique highly depends on Unity’s internal asset format. AFAIK the asset files are not compressed on standalone so differences could be detected. However if the files are actually compressed differential patches would be more or less useless as changing a character in a TextAsset could result in a completely different file depending on how it’s compressed. Since the assets format is an internal implementation detail it could change in the future so i wouldn’t rely on the current implementation. In most cases you want to use a per-file patch.
Generally the updater would be composed of several “components” (not in the sense of Unity but in the sense of modules):
- Validator
- Updater
The patcher is usually a seperate application. You can create a simple .NET application. Automatic updaters do not really require much UI as they just validate the game and if it detects a new version it automatically updates the game before launch. The easiest solution is to run the actual game through the updater. So you would use the updater as game launcher. If the game is a multiplayer game which requires the user to have the latest version you may need to implement the validation in both, the updater and the game to prevent synchronisation problems / errors with outdated clients.
The validator would check the current state of the game files and if the update can be used on this game (in case of a standalone update). The live updater would start by downloading the current game file definition file (JSON, XML, a binary format, …) and then comparing each file in the current version with the expected one. This results in a list of files that need to be updated / downloaded.
The updater itself performs the actual update. The live updater should download all required files in a temporary folder to ensure all required files are there. You don’t want to patch on a file-to-file basis as this could corrupt the game. If you only update some files but not all (due to interrupted connection) the game would be broken. Once all required file are there you would replace / patch each file based on the downloaded files. When done just start the game.