IllustratorsLeak
Extremelyd1
Extremelyd1

patreon


HKMP Tag development information

In the post of last week I discussed the interesting developments on the networking side of HKMP, but also announced that HKMP Tag was released. In this post I'll talk about a bit more in-depth about the development of HKMP Tag and how it was possible to make a fully automatic public server that runs constant games.

Before the release of the public Tag server, the HKMP Tag mod was already in a usable state, but required manually starting/ending games. Moreover, there needed to be some agreements on which area to play in and what behaviour was not allowed. In a group of friends or responsible players, and with some communication, this was easy to achieve. However, I was still interested in bringing HKMP Tag to a more general public by automating the entire game process. To this end, there were a lot of considerations to make. Especially the manual decision making and agreements on playable area are a concern for public games. As a general rule, we can never trust the average player.

Perhaps the largest issue is that we want to restrict players movement to a certain predefined area. Players should be warped into this area and then not be allowed to leave it for the duration of the game. Warping players to a certain transition is fairly easy. The same functionality is already implemented in the "room warp" setting of the BenchWarp mod. After players are warped to the correct area, they should no longer be able to leave the predefined area. Hollow Knight consists of a lot of individual rooms that are connected by so-called "transitions". Entering the area of the transition will load the room it is connected to and put the player in the corresponding transition area of that room. When entering a room this way, the transition area is temporarily not triggered to prevent a player from getting stuck in a loop of these transitions. This is an important detail that we will elaborate on later.

Internally, the game engine of Hollow Knight, Unity handles these transition areas a collision boxes. But rather than having those collision boxes be solid, they only act as a trigger for a certain action. In our case, the action is loading another room and putting the player in it. We can simply hijack this system by making certain collision boxes for transitions solid instead of a trigger. That will make them inaccessible to players and thus effectively lock the player in. If we combine this technique with a configuration file that tells us which transitions are restricted, we can define the playable area practically and enforce that players will not leave it.

The configuration file for HKMP Tag consists of "presets". These presets contain a list of scenes for which certain transitions are restricted. Each scene that has some restrictions subsequently contains a list of the names of the transitions that should be blocked. As I might have mentioned in previous posts, I like to optimize network usage for HKMP as best as I can. Ideally, we want these playable areas to be defined on the server, which means that at some point they have to be communicated to the client along with the restricted transitions for each scene. And given that these restrictions are all in text, this would be a lot of data to send over the network to each client. The solution for this was to make an encoding of the scenes and their transitions and send the encoded data to the client, at which point it can be decoded into scenes and transitions again. In order for any encoding to work, both parties need to agree on how the encoding works exactly. So both the server and each client are equipped with a large JSON file that contains all possible scene names and their corresponding transition names. Now if the server wants to send certain restrictions to a client they simply look up the index of the scene name in this shared file and then find the indices for each of the transition names as well. These indices are then send to the client at which point the client can decode the indices back into names using the same shared file.

So presets contain the restricted transitions that players can't use, but we still need to make sure the players are warped into that playable area first. And this got a bit more tricky than anticipated. Sure the functionality for warping players already exists in the BenchWarp mod, so the implementation was done fairly quickly. However, a few issues immediately arose. If we warped the player to a scene that had an active transition restriction, they could become stuck outside of the room, because the transition area had a solid collision box, instead of a trigger-only one. To remedy this, we could make the transition temporarily not restricted, allowing the player to enter. And after that immediately restrict it again to ensure the player was kept in the playable area. The timing would have to be perfect, as soon as the player leaves the collision box we should make it solid again to ensure the player doesn't have a window to escape. And with the collision boxes of Unity this was very straightforward. Unity would tell us when something left a collision box, at which point we could make the collision box solid. Of course, there were some hiccups with this implementation at first. Players would somehow still get stuck outside of rooms and not be able to play properly. The reason for this was that Unity would sometimes tell us that the player had entered and left the collision box in the same frame and only then entered and left the collision box for a second time. After the first exit of the collision box it would become solid, and the player would be stuck outside of the room. Fortunately, we could differentiate these two behaviours by the fact that the first entering and exiting occurs in the same frame. Actually passing through the collision box would never happen in a single frame, so by checking how many frames it takes, we could only make the collision box solid on a real traversal.

The HKMP Tag server has been public for a few weeks now and seems to be running very well. If you want to check it out and play some games, feel free to join the HKMP Discord (https://discord.gg/QtAG3amg) and look at the #addons channel for more information!


More Creators