📜 ⬆️ ⬇️

As we multiplayer for NFS MW wrote

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!

image

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); //    ? float hud_scale = 0.97265; //-,   HUD          Xbox 360 mw_write_memory(MW_ADDR_HUD_WIDTH, &hud_scale, 4); // HUD... mw_write_memory(MW_ADDR_HUD_HEIGHT, &hud_scale, 4); uint8_t opcode = 0xC3; //...  .   ,  HUD,   . mw_write_memory((void*)0x604DA0, &opcode, 1); uint8_t widescreen_splash_patch[] = {0x90, 0x90}; mw_write_memory((void*)0x5A3080, widescreen_splash_patch, 1); void* ws_screen_pointer = 0x89F828; mw_write_memory((void*)0x8F3C68, &ws_screen_pointer, 4); mw_write_memory((void*)0x8F3C88, &ws_screen_pointer, 4); mw_write_memory((void*)0x8F3CA4, &ws_screen_pointer, 4); uint8_t force_7_ai_patch1[] = {0xB8, 0x06, 0x00, 0x00, 0x00}; //    :     7 .  ,     ,   ... mw_write_memory((void*)0x5DA122, force_7_ai_patch1, 5); uint8_t force_7_ai_patch2[] = {0xB8, 0xC5, 0x88, 0x3B, 0x9F, 0x50, 0xE8, 0x22, 0x45, 0xFE, 0xFF, 0x83, 0xC4, 0x04, 0x5E, 0xC2, 0x04, 0x00}; //...    . ,   ?     :   [eax]    "character_smart"          .  EAX     ,      , , ,      ,    ,    EAX  /.  ,  ,    . mw_write_memory((void*)0x5FD353, force_7_ai_patch2, 18); 

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.


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.

image

Another screenshot

Afterword


He will not be. The only thing - GrimMaple , respond! I also want to say thanks:


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.

Source: https://habr.com/ru/post/334744/


All Articles