Detect when user takes a screenshot in Unity - c#

So in this maze kind of game I'm making, I will show the maze to the player for 30 seconds.
What I don't want is that the player taking screenshot of the maze.
I want to do something like Snapchat, or Instagram, how it detects when you take a screenshot of a snap/story.
I'm using C#. It can also prevent user to take screenshot. I don't mind.
Is there a possible way to detect when the user takes screenshots or prevent it in Unity?

No, you can't detect this reliably. They also could make a photo with a digi cam. Furthermore there are endless ways to create a screenshot and the os has no "callback" to inform an application about that. You could try to detect the "print screen" key but as I said there are other screenshot / screen recording tools which could use any hotkey or no hotkey at all. I have never used Snapchat but it seems it's not safe either.
There are even monitors and video projectors which have a freeze mode to keep the current image. You could also run your browser in a virtual machine. There you can actually freeze the whole virtual PC or take screen shots from the virtual screen and an application running inside the VM has no way to even detect or prevent that.

I once had to do something similar. If you just want to do what snapchat did then it can be done but remember that as long as the app is running on anyone's device instead of your server, it can be de-compiled, modified and compiled again so this screenshot detection can be circumvented.
First of all you need to know this about Apple's rule:
2.5.9 Apps that alter or disable the functions of standard switches, such as the Volume Up/Down and Ring/Silent switches, or other native
user interface elements or behaviors will be rejected.
So, the idea of altering what happens when you take a screenshot is eliminated.
What you do is start the game, do the following when you are showing the show the maze to the player for 30 seconds:
On iOS:
Continuously check if the player presses the power and the home button at the-same time. If this happens, restart the game and show the maze to the player for 30 seconds again. Do it over and over again until player stops doing it. You can even disconnect or ban the player if you detect power + the home button press.
On Android:
Continuously check if the player presses the the power and volume down buttons at the-same time. Perform the-same action described above.
You cannot just do this with C#. You have to use make plugins for both iOS and Android devices. The plugin should use Java to the the detection on android and Object-C to do the detection for iOS. This is because the API required is not available in C#. You can then call the Java and Objective-C functions from C#.
Other improvement to make:
Check or external display devices and disable them when you are
showing the maze to the player for 30 seconds. Enable them back
during this time.
When you detect the screenshot button press as described above,
immediate take your own screenshot too. Loop through images on the player's picture gallery and load all the images taken that day.
Compare it with the screenshot you just took and see if they match.
If they do, you are now very sure that the player is trying to cheat.
Take action like banning the player, restarting the game or even
trolling the player by sending their screenshot to the other player. You can also use it as a proof to show that the user is cheating when they complain after being banned.
Finally, you can even go deeper by using OpenCV. When you are
showing the player the maze for 30 seconds, start the front camera of
the device and use OpenCV to continuously check if any object other
than the player's head is in front of the camera. If so, then the
player is trying to take a screenshot with another device. Take
action immediately. You can use machine language to train this.
How far to go depends on how much time you want to spend and how much you care about player's cheating online. The only thing to worry about is players de-compiling the game and removing those features but it is worth implementing.
My Android phone takes screenshots differently. I swipe down from the
top of the screen and select the "Capture" option.
Nothing is always the-same on Android. This is different on some older or different Android devices. You can detect swipe patterns on the screen. The best way to do this is to build a profile that handles each Android device from different manufactures.
For those commenting, this is possible to do. You must do it especially if it is a multiplayer game. Just because a game can be hacked does not mean that a programmer should not implement basic hack prevention mechanism. Basic hack prevention mechanism should be implemented then improved as you get feedback from players.

Related

change scene with a button and also do it with an effect? Unity

I'm new to Unity and my goal is not to make a game, but a mobile application, I don't use the Android SDK because I need to do something with augmented reality and I need to do it with Unity, it's getting quite complicated because I'm not familiar or with the language or with anything, in short, I was able to change scenes by means of a button, like a log that verifies things, but Unity does not have a scene transition effect or something similar, I saw several videos where it can be done a transition, effects and so on, but they are for when you touch a button or touch the screen in this case, I would like to know if there is the possibility of being able to implement an effect after it effectively validates the information and then makes a translation effect to the other scene, is this possible, thanks!
You could use:
SceneManager.LoadSceneAsync
Unity SceneManager.LoadSceneAsync manual
for loading scene while you run your own transition. Fade in/out is the most common transition for such occasions.

Unity LowLevel Touch Screen Detect android

I was Working on a new application on unity and i wanted to make the perfamonce good for phones so what i did is i killed the playerloop that's mean i switched to the lowlevel unsing unityengine.lowlevel (playerloop) but the problem is i can't detect any touches i tried everything :
button click (normal) - dosn't worked
event systems - dosn't worked
addlistener button - dosn't worked
mouse click on the update - dosn't worked
so i read some unity articles and everything in stackoverflow and i didn't find anything .
will i killed the playerloop because a developer named "Jon Manning" sad sow and he explained how to detect touches on iphone and he did say that detect touches on android is possible but he didn't say how you can see the video here to better understand : https://www.youtube.com/watch?v=C7CZyqHGKXw&t=1812s
so if anuone can help i will be very greatfull
I personally have created an Android app before, and the easiest way to detect touches on Android phones are with these functions:
private void OnMouseDrag() { // called every frame the user has their finger held down while touching the collider or GUI element }
private void OnMouseDown() { // called when the user presses the collider with their finger }
They work perfectly for single-touch applications, if you want multi-touch capability there are other methods you can use.
The only caveat is that these functions are only called when the user's finger touches the collider, so every object you want to have interacted with must have a collider attached, along with this script.
There are also other OnMouse functions which you can look up on the Unity Docs, if you want more control.
I don't Really understand Why unity realised the UnityEngine.lowlevel if there is no way to keep using the app or the game ones you kill the playerloop ,Will i know that it work on ios but What about android i think android is really important than ios because there is like 7% of the world using ios and the rest using android ,Will i know that the propably 7% are reach but i thnik that is not good reason
I will be using android studio and java for my app , and i hope unity team will do something about that and if anyone searching how to wake up from the lowlevel if you're not building for ios don't bother you're self go create plugin if possible or just don't use the low level and of course google play will not give you a nice number of downloads because of the perfamonce and the battery , unity is only for games stick with that i already made a lot of apps non of them got more than 10k downloads because of the perfamonce and the battery

Why would a computer game slow down an unrelated COM port?

Problem:
So I have a physical device with buttons and joysticks on it, and I'm using it to move the mouse around and click on icons, etc.
To do this I have a C# program that reads a COM port and uses InputSimulator to fake keyboard and mouse actions. (Btw this app is a graphical application with its own window, since it also displays debug data on the screen.)
This works fine in Windows, in that I can use it to navigate around the OS, open programs, etc. I'm outputting a variable "maxTimeBetweenReadings" and it doesn't really go above 20 or 30ms.
However, I then open Steam and run a computer game. My device works fine at first and I can move around the start menu. But on entering a level, comms from the device becomes incredibly choppy and the game is unplayable. My maxTimeBetweenReadings value shoots up to over a second.
Things I have tried:
I have tried using the real mouse and keyboard, which is still perfectly smooth, so I know it's not that the game is slowing down my whole computer.
I have tried setting the priority of my C# program to Realtime (though I don't want to do this in production) and the priority of the Thread it spawns to Highest. This makes no difference that I can see.
I have commented out all other activity (writing/reading files, etc) in the C# program, even though I don't think that should make a difference at all. Again no difference, but then I wasn't hopeful.
My understanding is that Windows has claimed the COM port for my C# program and now won't let anything else talk to it, so even if the game wants to interfere with it for some reason, it shouldn't be able to?
And even if the game was somehow able to mess around and interrupt the comms, wouldn't the fact that the C# program is running at Realtime priority mean that the game should never be given a chance to do so?
However there are obviously gaps in my understanding, because it doesn't line up with what I'm seeing.
We need to be able to give away this device with the reassurance that it can work with ANY game, no matter how said game was implemented, no matter what awkward things it tries to do.
If I have to go game by game to make sure they aren't interfering somehow (and I still don't understand how they can) then I'll be here for a thousand years.

Display text/image while Vuforia plane finder is detecting surface

I am developing a game with Vuforia in Unity.
What I am attempting to do is to display a Plane/Canvas/Image while vuforia is detecting the surface so my users will not feel lost while Vuforia is scanning.
But the problem is i've looked into the only 2 available scripts that i can find,
DefaultTrackableEventHandler.cs
and
DefaultInitializationErrorHandler
but I could not pin point the script where it initialize the detection.
So my request is to ask if anyone know which part of the code does Vuforia initialize the scan so i can customise it.
I am assuming you are using ground plane since you have written " detecting the surface "
The plane finder behavior script is responsible for "scanning" and finding horizontal surfaces. What you can do is check vuforia samples from asset store and there you can see this script is doing Hit tests constantly to find positions on the detected surfaces. Therefore, as long as this on Automatic Hit Test is called, it means your device has found a surface and performing hits towards your indicator.
In this example HandleAutomaticHitTest attached to PlaneManager is called every time Automatic Hit Test is called. You can modify this HandleAutomaticHitTest script to achieve what you wanted.
One last note i am not 100% sure but the scanning probably starts when the positional device tracker is started or vuforia started.
What we did was display an "instruction panel" that filled the entire screen when the scene loaded. It allowed the device to detect the environment while the user read the instructions. Then we just had an "Ok" button at the bottom that disabled the panel when clicked, thus revealing the AR experience. See attached screenshot. Instruction Panel

Delay starting XNA game switching to Fullscreen messing up intro screen

I'm making a Windows game using XNA 4.0. I have an quick little intro screen that shows our studio logo and plays a sound. It lasts 1.5 seconds and looks and works as desired in windowed mode.
We want to run the game full screen. So all I added was "graphics.IsFullScreen = true" to the Game subclass constructor after the GraphicsDeviceManager is instantiated and we've set the preferred backbuffer dimensions. When the game starts the video card just glitches my monitors for like 1 or 2 seconds switching resolutions, etc. - and that is all a customary and understandable delay between the video card, the device drivers and my monitors all figuring out this change, but XNA is running the game loop while all this nonsense is going on.
This means my intro starts, runs and is over by the time the system gets around to actually displaying what I'm drawing and by then the intro is over. What I'd really like is a way to detect when the video card is actually rendering before I start drawing and playing sound and timing things assuming the player can see them. Searching around online, I've seen reference to a "graphics.EnsureDevice()" call that seems to have been deprecated and is no longer available in XNA 4.0.
I guess this is kind of dirty, but you could fire off a thread that continually checks to see if the DeviceParameter IsFullscreen is set to true on active graphics device, after you set the GraphicsDeviceManager.IsFullscreen property to true.
Once it is set, then you would start your game loop.
You could also write it in a way that the thread would only fire off if you set GraphicsDeviceManager.IsFullscreen to true. That way it would support both modes.

Categories

Resources