Hi, Habr! In my first post I will tell you how we have been writing the unofficial multiplayer for NFS Most Wanted 2005 release for half a year. I’ll say right away that there will be no links, just screenshots, so that they don’t count it as a banal advertisement. If it is interesting - ask in the comments. Go!

It all started at the end of 2016, that is, the past, the year, and more precisely in November. I talked to the developer of trainers MWInside, which, frankly, did not shine with special knowledge. I said that I would like to learn how to control cars that are different from the player - rivals, police and ordinary traffic machines. He did not respond to this, because then nobody knew about it. Let's skip to the end of December when I met Jojez, the man who inspired me for all this, and the ExOpts team that helped me with ideas. So, I had the addresses of coordinates, speed, tilt and rotation of the player on my hands. Through some research, I figured out that they are all fields of the same structure, supposedly ISimable, 176 bytes in size, i.e. adding 176 to all of these addresses gave the same values from the other car. It was a discovery that, in fact, opened dozens of ways, but first, until the end of January, I did not write online, but a simple trainer to control a police helicopter. Once again, skip to the twenty-third of January.
Itself, in fact, multiplayer
So, the twenty-third number, morning. I suggest to my friend, YaNet, to write multiplayer. He agrees, takes the code from his old projects, and by the twenty-fourth we have a minimal server and client in C #. Subsequently, it was rewritten in C, but that’s another story. On the twenty-fourth, we began to do work with the game. By the way, we used the NFSScript API to create mods from DennisStanistan. We forced the client to ask for a random number from the server, and then, after it arrived, they would display it on the screen by means of the game. It was only the beginning ...
')
Sync players - hell
Soon it was time to do real multiplayer. It worked quite simply: customers sent their coordinates, the server sent them to the others, those on their side assigned them to the machines. Nothing interesting, but it was also terribly unstable and bagano: the cars were literally under attack, they were shaking and throwing up. At the same time, one of the administrators of the site, whose name I will not disclose, in order not to advertise, ArturoPlayerOne, created a fixed topic that says that an open test is being conducted. Of course, people got into the chat, but because of the really breaking all the bugs, no one could play normally, although they remained interested. Subsequently, all these bugs, of course, were corrected, but only by completely rewriting the client and server in C. Synchronization was also fixed, but that's another story ...
And this is a piece of code :)
mw_write_memory(MW_ADDR_AI_STR_RACE, "AIActionNone", 13);
Pretty long code, to be honest. I wrote the comments about fifteen minutes. Okay, let's go on!
What problems have we experienced
There were a lot of them, some are there now, but today we will talk about the three most important ones, from the very end. Go!
Number three: sync
Why even in third place, you ask? Because especially she did not interfere, IMHO. Yes, she was terrible, but did not break the gameplay. How did we fix it?
To be honest, we didn’t completely fix it to this day, but let me tell you about everything we tried to do.
- Severe Chelyabinsk method : we tried to synchronize all physical parameters and as often as possible. Ha-ha, nope! No changes, only everything began to slow down hopelessly. In the trash.
- Reducing the size of packages . The action is not bad, because the client "eats" less traffic, only as a solution to the synchronization problem is meaningless to the bone. In a landfill.
- And finally. separation of coordinates and speeds , really working decision. Previously, we synchronized everything and always, but now it has changed: speed and rotation are always synchronized, but the coordinates are only every few seconds. This made the players smooth and beautiful.
Number two: devouring the whole compound
Yes, yes, once our client scored the channel, which is closely related to the number one. On connections worse than the Google data center connection, the client simply
did not work , or did not let the rest work. This was fixed only recently, in version 0.6. As it turned out, in some unknown way, I wrote code that not only did DoS- (and if there are five players on the players' server, then in general DDoS-) attacking the server, it also killed the connection, sending a byte so a thousand times in millisecond! I do not know what else can be said about this bug, but it has been fixed, so everything is ok. Go to the first place!
Number one: reruns
Even more precisely, shutdown. The withdrawal of players from the game simply was not provided. If a person went to an empty server once, his ID was equal to one. If he restarts the client, his ID will already be equal to two. Strange isn't it? And what if three players chase together, one has a connection, and he comes in again? Need I say that three players were the maximum? This terribly enraged me and all the players. In the end, I rallied and did write off the players. If there are no packages from the player within two seconds, he is disconnected. Accidental disconnection is excluded - twice a second, "ping" still comes. I think that is all.
Another screenshotAfterword
He will not be. The only thing -
GrimMaple , respond! I also want to say thanks:
- nlgzrgn for a way to get seven opponents in a race;
- SpeedyHeart / speedycat / SpeedyChan for help with synchronization;
- Xanvier and DennisStanistan for the addresses of the functions of the game and for their use;
- elaymm4 for design, ideas, video, in one word for the “face” of fashion;
- YaNet (dz3n) for help at first;
- Numerous players for loyalty to our project. A glass for you!
That's all! Bye everyone If, however, they publish, I will be glad and release a sequel, for here I have described only the most important. See you!
PS I was asked a lot in the comments, so I post the information and links:
The project is called MW-Online.
Gameplay video:
https://youtu.be/LMGLWHeLuJo .
Screenshots are in the article, if you want to play, that is,
Discord-server . Communication is mainly in English, but there is a Russian channel.