Unity3D Speed Hack Detection - c#

I want to know, is there any way to detect within our game against speed hack applications like game guardian?
I searched all over the internet but I didn't get a satisfying answer.

The solution is not more software on top. The solution is not being vulnerable to this from the start.
Example:
If you allow your users to send your server their coordinates on the world map ("I am the blue player and since I moved my full allowance, I'm now at 156/467"), it's trivial for somebody to write a teleport cheat. Just send different coordinates, boom teleported. Kids play.
If you only allow your users to send messages of intent to your server ("I am the blue player and I intend to move my full allowance in the direction of 156/467") and let your server figure out what that means (is the player allowed to move, what is his allowance, how far will the blue player get in one unit of time) and send the result back, you will never have that problem.
Do not trust client input. First rule of video game security: The client is in the hands of the enemy.
There is little point in shoving more and more software on top of your client if you keep trusting your client. Just stop and design your game so the client can send intent and the server determines outcome.

It depends on your game, but you can try detecting speed hacks by simply checking player position every frame.
Determine maximum possible move distance per second and put it in constant, so that the player wouldn't be able to change that at runtime.
Cache current position.
On next update, check the distance the player travelled and multiply it by the Time.deltaTime.
If the player travelled more than maximum allowed, the player must have cheated.
Return to step no. 2
It will be framerate independent checking as you will be using maximum allowed distance per second.

If the server has all player positions at all time and your problem is with speed hacking the solution is not that hard (assuming player position is being sent to server constantly).
Please do the following, first before updating player position check if the distance between current position and old position isn't too big
var distance = Vector3.Distance(old.position, currentposition);
if(distance<=alloweddistance)
...
and if it is avoid updating position\set player to old position\kick player. A better solution to even that, is to not allow players to send their current position to server, rather send direction they are moving and speed. The server should change their position with the direction and move speed, not client.

I found Solution for my own project that is online multiplayer and it works for any online game.
For solving this problem just we need to calculate time in server. for example we can use stopwatch and doing this in client side... and in an specific situation we can compare them over network and if there was any difference between them, (some thing like more than 3 second) then becomes clear that player is used speed hack.
I tried this method in my game and it works fine.

Related

Im trying to recreate spider square in unity but i cant figure out how to make the web

As stated in the title. I will include a video of what I'm trying to make. I'm not sure how to make the part that the player swings on.
https://youtu.be/Z_RVr0nFpVE
Description of the mechanic: when the player taps a "web" is created that goes from the player to the roof at a slight angle forward. This web gets shorter over time. When the player stops tapping the web goes away.
I’m sure that there is no physical rope or string simulation. The easiest way is to slow the horizontal speed down, add decelerating up-directed velocity, and draw a rope from the origin to the player. After parameters adjustment the result should look similar to what you’ve shown.

How to validate chess moves with a server? Winboard and Unity 2020.3

I'm looking for advice on how to implement online chess move validation using a winboard chess engine. I am creating a mobile battle chess game in Unity 2020.3. Right now I have the possible moves for each player, castle rights, check status, etc being generated by an open source C# chess engine. I chose this engine because it's written in C# and the code could be directly included in my Unity Project. I successfully wrote my own code that connects this chess engine to a 3D battle chess game.
How the game works (video preview):
A piece is selected by the player clicking it with their mouse or
tapping the screen.
The possible moves for the current board are calculated by the chess engine.
I use the possible move indexes to show possible move highlights.
When a player makes one of these possible moves, the move is applied on the chess engine.
It becomes the other player's turn.
I have some custom code to run player animations, based on the kind of move (ex. an attack animation runs when a piece is captured). I also show have screens that show when it's time for a promotion, a player is in check, or the game is over.
I'd like to somehow make the process of calculating possible moves and applying moves to be done on a server. My goal is to protect from players sending illegal moves to the board and breaking the game.
How would you recommend I approach this problem? This is the last thing I need to turn this game into an enjoyable online experience. I just lack the crucial skill of understanding how to make this game online.
On the server, you'll have a separate version of the chess game running.
A player(/client) will send a move to the server (so a unique piece ID, and the target square the player wants to move).
On the server-side, you'll need to check to see if that move is indeed possible. This could be by getting all possible moves from that piece, and checking to see if the intendedChessPosition can be found in the list of possibleChessPositions that was calculated on server-side. Only then, will you actually move the piece server-side.
All players/clients will communicate using the server as the middleman and authority.
The exact implementation could change depending on the API of the chess engine you're using, but that's the basic idea.

Real time sync in Unity using Photon Unity Network(multiplayer)

Im working on a demo project, where I use Unity 3D and Photon Unity network(PUN) for a real time game.
The person in the top panel is an enemy unit, controlled by another player who does damage to the player on the bottom left (1/3 hp left).
However, the person on the bottom right is a healer who can heal the bottom left player (both controlled by the local player).
Here's my problem! Since it isn't turn based and has to happen real time. How do I design my multiplayer system? Ive previously worked on turn based games, where I just pass the indices and mirror the events taking place locally, in the remote player as well.
But here with latency in the picture, I do not know how to proceed!
What I would like to do is, have the healer heal the player locally as well on the remote player's phone before he is attacked by the remote player or kill the player before the healer can heal his hp depending on the timestamp in which the events happen and reflect such on both the devices.
I think you are confused with some of the pun networking features.
If the healer heals your local player, so will be the remote instances of your local player. Your healing system must be networked of course, make sure you go through our basic tutorial to learn how to implement a simple health system.
https://doc.photonengine.com/en-us/pun/v2/demos-and-tutorials/pun-basics-tutorial/player-networking#health_synchronization
What will be slightly more complex than health management is the switch between your player and healer locally. for this you have two main variants.
transfer ownership between the player and healer: https://doc.photonengine.com/en-us/pun/v1/demos-and-tutorials/package-demos/ownership-transfer (this is a v1 demo but the principle still applies to v2)
have a invisible network player, and using your own logic in your game, have the player matching this invisible network player or the healer matching it.

Unity: Machine learning - level solving

Recently I've been messing around with machine learning and I wanted to see if I could create AI for the game I'm currently making. The AI should be able to solve the puzzle for you.
The game currently works as followed. You have a few tiles in a grid, some of them are movable some of them aren't. You click on a tile you want to move, and you drag it into a direction. It'll then start moving the tiles and optionally also the player character itself. The end goal is to reach the end tile. Level example, Solving the level
Playing the game yourself:
Whenever you select a tile (you do this by clicking), you then hold the mouse button down, and drag onto the direction you want the tile to move towards. Once the tiles are done moving, the player object will move one step in the same direction. If the player is on top of a tile that you move, it'll move with the tile. And afterwards do another step in the same direction.
I was wondering if it's possible (and if so, how) for machine learning to define a position on the screen, (optionally) click and then define a movement direction?
Please keep in mind that I'm fairly new to machine learning!
To give some more clarification:
The grid is static for now, to keep it simple for the AI. But later one, the goal is to generate a level randomly, and see if it can solve it.
In theory, all the AI should have to do, is select a tile to move (A number between 0 and the width of the grid, and the same for the height). And define a movement direction. Either (0, 1), (0, -1), (1, 0) or (-1, 0).
Falling off the grid will results in a reset.
Reaching the end of the grid results in a win.
Moving in an invalid direction results in a reset.
Based off of your bullet points, I would honestly suggest just implementing the A* Pathfinding algorithm, with some modifications to emulate machine learning. The A* Pathfinding algorithm determines the best path on a grid from point a to point b, and using clever programming you could achieve the result you want with a reasonable amount of overhead.
Something along the lines of having a list of "do not touch" grid points(death traps, etc), which gets filled as the AI runs into them, so on the next iteration it knows not to take that path. This is a very basic abstraction of your idea, but would be highly obtainable.
Obviously we cannot write the code for you, luckily there are tons of resources on A* Pathfinding to help you get started!
Here is a simple tutorial
Here is an implementation that was used in Unity
Here is a code review on someones implementation
Assuming you actually want to use machine learning and not just a pathing system:
I will lay out some pseudo code that you can use for a basic scenario of the AI learning a static board. There are different ways you can write and implement this code, I have only suggested one way. But before we get to that lets first discuss this project overall and some suggestions for it.
Suggestions:
I would say that you will want to measure the game state on the board, and not the mouse movements. So basically the AI is measuring what moves can be made. The mouse movement part is just a way for the player to interact with the board so it is not needed by the AI. It will be simpler to just let the AI make the moves directly.
I don't think that unity is a good platform for this kind of experimentation. I think you would be better off programming this in a console program. So for example using a 2 dimensional array (board) in a visual studio c# console program, or in a C console program via CS50 IDE (comes with free sign up via edx.org for cs50 https://manual.cs50.net/ide). I have suggested these because I think Unity will just add unnecessary layers to a machine learning experiment.
My assumption is you want to learn machine learning, and not just how to make an ai solve a puzzle in your game. Because in the latter case better options would be a proper pathing system, or having the ai brute force several attempts at the puzzle before moving and select the solution with the fewest steps.
Pseudo Code:
Now onto some pseudo code for your machine learning program.
Assumptions:
A. You have a board with set dimensions that you can pass to the Ai at the start.
B. There are tiles on the board the AI cannot move into (obstacles).
C. The AI should learn to solve the problem, instead of having the answer at the beginning because of good code that we designed (like a decent pathing system).
D. We don't want the AI to brute force this by trying a billion different combinations before moving, because this suggests perfect understanding of its environment. If the ai has perfect understanding of its environment then yes, it should use brute force where reasonable.
Coding Logic:
Scenario 1: The AI plays on the same board every time with the same starting conditions.
I. You start by setting a discrete amount of time in which the AI makes a move. For example 1 move every 1 second.
II. Have a counter for the number of moves made to reach the end tile, and record the sequence of moves associated with this counter.
III. If the AI has no history with which to make a move it makes a move in a random direction.
IV. If the move is invalid then the counter increases and the move is recorded, but the AI stays on the same tile.
V. When the AI completes the puzzle the counter and sequence of moves is stored for later use.
VI. In subsequent play throughs the AI always starts by selecting the paths it has tried with smallest count.
VII. Once the AI begins moving it has a 1% chance per move to try something different. Here is an example. When the 1% is triggered the AI has a 50% to try one of the following:
a. 50% chance: It checks through all the sequences in its history to see if there is any section in the past sequences where the counter between its current tile and the finish tile is shorter than its current path. If there are multiple it selects the shortest. When the AI finishes the round it records the new total sequence taken.
b. 50% chance. The Ai makes a move in a random direction. If it made a move in a random direction. Subsequent moves again follow this logic of 50% chance check, and 50% chance move randomly again. When completed again record the sequence of moves.
VIII. You can seed this by making the AI run the puzzle a 10,000 times in a few seconds behind the scenes, and then when you observe it afterwards it should have selected a reasonable path.
If a computer can brute force a problem in reasonable time it should start with that. However bear in mind that machine learning in a computer program where the machine already knows all the variables is different from machine learning in the environment, where for example you have a robot that has to navigate an unknown environment. The above code should work in the latter case. You may also want to investigate the idea of the AI mapping out the entire terrain by trying to move to every tile and forming an understanding of the environment, then just brute forcing a solution once it understands the variables.
In a non static environment you will want to enhance the valuation system. This answer is already too long so I won't go into it.
Short answer to both questions: Yes,
You can create an ai that uses either gamestate (so it can read the objects/properties of your grid) or you could use raw-screen input combined with image processing, which is a hard thing to create, and expensive (computational) to run.
On the Unity forms there are several answers to the question "How to mimic mouse input" or alike. Take a look here:
https://answers.unity.com/questions/564664/how-i-can-move-mouse-cursor-without-mouse-but-with.html
If you are looking for the code for the AI, sadly, you are out of luck. There are lots of ai tutorials online to create a simple ai for such a game. I would advice not to dive head-first in the fancy stuff (like neural networks) and start simple. It would be the best, in my opinion, too start with creating an (class) structure for your ai, and start learning AI by practice. Start with an "AI" that just randomly returns something, then see what you can learn & manage online and make other versions.
For one of the first AI's, take a look into goal-driven AI's or state-machines. I think they should be able to give nice results, given your gifs.

Leap Motion Coordinate System, Translations and Interaction Box with Unity C#

I am working on a Unity leap motion desktop project using latest versions of Orion and unity prefabs package. I have created a simple scene pretty much identical to the one in Desktop Demo scene. (pair of capsule hands and a simple object you can poke and move around)
https://developer.leapmotion.com/documentation/csharp/devguide/Leap_Coordinate_Mapping.html
This article covers all of the issues I am currently facing but so far, I was unable to implement these solutions in my project.
When moving hands from the maximum range of the camera for example left to right or any other direction, this only translates to a portion of available screen space, in other words, a user will never be able to reach out to the edges of a screen with their hands. From my understanding, the tracking info provided in millimetres by the camera is somehow translated into units that Unity can understand and process. I want to change that scale.
From the article, "You also have to decide how to scale the Leap Motion coordinates to suit your application (i.e. how many pixels per millimetre in a 2D application). The greater the scale factor, the more affect a small physical movement will have." - This is exactly what I want to do in Unity.
Additionally, even being able to what I think was a successful attempt at normalisation of coordinates using the InteractionBox, I am unsure what to do with the results. How or rather, where do I pass these values so that it will display the hands in an updated position.

Categories