Skip to main content
gamedev.net
🔒 Locked

Game updates & patching (C++)

Started by QTheBrain 5 replies 1.1k views
Original Post
QTheBrain
QTheBrain
Hi all, whenever I see a game with an ''automatic update'' feature I wondered how they do it, this updating. I mean, you buy (or download) a game, and then after a few weeks or months a new patch is available, including new weaponry, maps or whatever. How does this updating/patching work? The new resources (graphics and sound and other data files) won''t be a problem, these are easily copied to the game directory. But HOW do they patch the executable file? The game has been compiled and everything is hard coded, so how can they suddenly add new functions, routines and ''source code''? Were the extra features already in the executable (in C&C Renegade there were already flying vehicles in single player before multiplayer support in the new patch, so the ''objects'' already existed), or do they use some kind of other trick? When I look at the game directory of some popular (3D) games I see lots of DLL files and stuff, but also multiple executables (some games appear to run two executables at the same time, as I saw in most Westwood games). I am currently writing a game (engine), so I''m wondering how to implement a patch feature in my game. Do I need to follow some kind of scheme / do I need to write my code in a certain way? After all, it would be ''cool'' for the people playing an older version of my game to have an update/patch available. If you know how to make a game patchable, please tell me. I''m programming in VC++ 6 and with DX8 and WINAPI. Please post your replies here, do not send me email (I won''t receive your emails because of the spam filter, sorry). Thanx, QTheBrain & Yoshi The Netherlands
Guardian_Light
Guardian_Light
Usually, you send the entire file you are updating. For executables, you send a new build, and destroy the old one. It''s possible to update only parts of a file, and usually this is done by creating a new file from the original and modifying it with a patch (executable creating the new file).

Maybe that clears up some of the mystery =)

It was neither power nor money that corrupted man. Rather it was evolution.
~Michael Sikora
QTheBrain
QTheBrain
Say I need to write a patch program that upgrades from build 1.00 to 1.06. This program then requires a game executable build 1.00 and ''knows'' the differences between the 1.00 and 1.06 build file. All the patch program has to do is changing the bytes that are different from the new 1.06 build to the correct value, enlarging the executable if necessairy? I can do that. Thanx!
Erunama
Erunama
Or, to make it easier, you just replace the executable with an updated one. Usually, the EXE file is fairly small since all of the resources are not located inside of it, and usually some DLL files hold functions and stuff.

So basically, the patch program could look at the date the EXE was last modified (or you could embed the version information inside the EXE file), and then it would check the server where the updates are held to see if there is a newer version. If so, just copy the new EXE over the old EXE (or just delete the old EXE, and drop the new one in).
Ravyne
Ravyne
I agree, the easiest way to do it is to simply replace the EXE file. If you code it right, you can seperate your program into the master .EXE and several .DLLs. One for sound, one for rendering, one for input, etc. If you support both DirectX and Open GL you could have a module for each, easing the upgrade process as well as lowering your memory use a wee bit. Anyways, when you release a patch you just have your utility find where the program was installed and overwrite the files. As Erunama said earlier, the bulk of program size is the various resources, not code so don''t worry about having super-sized patches. with this approach you could almost use something as simple as winzip, with overwrite enabled, if you could trust the user to always specify the correct path. Of coarse, you CAN''T, so don''t. But you get the idea. Also you should have less problems with your patch corrupting the code. I downloaded a TFC patch that made it run so ungodly slow I haven''t messed with it since....hmm...I should get to doing that shouldn''t I?
throw table_exception("(? ???)? ? ???");
Chem0sh
Chem0sh
I really don''t trust byte-level patching (actually modifying the binary data instead of replacing the file). I agree with the others. It''s much simpler and safer to just replace the file unless the files are massive.

You may want to check out PatchMaker from Clickteam.

/*=========================================*/
/* Chem0sh */
/* Lead Software Engineer & Tech Support */
/* http://www.eFaces.biz */
/*=========================================*/
/*=========================================// Chem0sh// Lead Software Engineer & Tech Support// http://www.eFaces.biz=========================================*/
QTheBrain
QTheBrain
I will replace the whole executable instead of binary modifying it. Nasty things may happen if my patcher modifies the executable not the way I want. That EXE and DLL stuff sounds interesting to me. The EXE is just compiled game code and DLL''s will contain engine code. As I said earlier, I''m writing an engine in VC++ 6 which uses DirectX. If I put this ''engine'' in a DLL, I write my game and compile it to a normal executable, which loads this engine DLL, am I right? This makes it even easier for me if I find someone to help me writing game code - I put someone else on the game code for instance while I tweak and optimize my engine DLL! This is nice. And ofcourse, I only have to replace the DLL if only the engine has changed. Same goes for the EXE file, if the game code has been edited. Thanx for this advice, but does anyone know how to accomplish this? I mean, how can I make this DLL and have an EXE use it? The situation is this: I have a (small version of) my game and the engine coded in a single EXE file for now (this is the default), and I have seperate classes for game and engine objects. But how to seperate these things over an EXE and a DLL file? For instance, suppose my engine has a texture class (with functions to use a texture in an easy and friendly way, without having to bother about D3D). How can I use this texture class in my game (EXE) while this class is coded in a DLL? Currently, I have one global pointer to the engine, so I wonder: can I still have this pointer and have access to the complete engine classes when seperating the game & engine? If so, how? (I don''t understand how to use a DLL and what this means for my currently written code, but I know how to compile one)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.