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.
Related
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.
I am working on a C# development project which aims at controlling a flying robot thanks to a set of Optitrack cameras (infrared Motion capture system). The concept works really well, you get a position from the camera system, our application can access to these data and we can control the robot.
The problem comes, I believe, from the communication chain. We have a USB cable linking our PC to an STM32F4 based board, which acts as a bridge and simply sends everything received on USB to radio thanks to an embedded NRF module (nRF24L01+ chip). This mechanic goes both way (NRF -> USB -> PC). The board is running under C using FreeRTOS. The PC runs Windows 10.
On the PC side we use the official STM32 VCP driver 1.4 from ST. On the board firmware, we have this user-made library for VCP on STM32F4: https://stm32f4-discovery.net/2014/08/library-24-virtual-com-port-vcp-stm32f4xx/
There are no queues on the bridge board except the ones from the radio module itself and potentially the STM32 VCP driver itself. I checked, there is a circular buffer in this driver used for in and out messages. Using JSCOPE I can visualize in real time how this circular buffer behaves and I've never seen an overflow happening.
My problem comes from the fact that a delay suddenly appears.
The system works perfectly for tens of minutes (between 10 to 20 minutes) and then a delay is clearly perceptible, which makes the controller oscillate. This happens when I do a second flight.
The following have been tried:
- Restart the C# application
- Run the C# application in debug mode and stand alone mode
- Change USB cable (shorter)
- Change USB port
- Change of computer
- Reinstall the ST VCP drivers
- Lower drastically the communication frequency (the control loop)
When the problem appears, the above solutions didn't work, the delay remains completely and none of the above proved to make it more reliable.
On the C# application, I reset all communication Lists before each flight. The SerialPort port object (from System.IO) has its buffers reset as well (DiscardOutBuffer, DiscardInBuffer, BaseStream.Flush methods)
I found a "hack" to make it work, but it is not what we want as a final solution. The "hack" is to simply physically disconnect / reconnect the USB connecting the board acting as a bridge. After this manipulation, the delay disappears.
So my questions are:
What could possibly bring this delay, knowing it doesn't look to be application dependant, nor frequency related (bandwidth).
What could explain why this disappear when unplugging/plugging the bridge board ?
I know this question is about a big project and could be hard to understand from outside. Feel free to ask me for more details if needed.
Cheers,
Marc
I am looking into writing something similar to that of Steady Mouse. My grandpa has tremors pretty badly and it prevents him from doing too much on the computer. Unfortunately it doesn't appear to work on Windows 10 and it seems the developer has discontinued working on the project. Seeing as I am looking for project to add to my portfolio, I figured I would see if I could maybe hack something together, only problem being I've never done anything this low level before so I am unsure of where to begin.
It seems the Kalman Filter is my best bet as an filtering algorithm, but I am unsure of how to provide the input. I've never used the Windows API, is this something it provides? Or, do I instead hook directly into the mouse device itself, and how is this possible? Am I even on the right track here?
I am assuming this would best be a background running process booted on startup, that filters the device input before the OS draws the cursor on the screen. Obviously, this would need to access all events and mouse movements regardless of which program is being used.
Investigate Windows Message Hook functions, it is possible to intercept/change Windows messages such as WM_MOUSEMOVE.
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.
I'm having a rather odd problem with a C# and WPF HMI I am working on currently. The HMI is a fairly complex program which allows the use to add and remove modules from a work area, dragging and resizing them to make the page they work on customizable. It works well, and after optimizations actually runs smoothly and works wonderfully with touch and animations. One gesture in particular is rather helpful, as you can (using multi-touch) place two fingers down on the screen and swipe left or right to change pages.
However, I have lately been getting complaints from our apps department that the touch will randomly stop working for any sort of complex movement, read as any sort of multi-touch. I spent a few hours tracking down what the problem was and it turned out, oddly enough to be linked to windows Calculator. Whenever calculator is opened, and subsequently closed, multi-touch ceases to function, and any breakpoints placed in the code show only a single touch being used. I took to the internet, and found a few articles corroborating the issue, but nothing even hinting at a fix other than don't allow calculator to work, which is sadly not an option as this HMI is meant for engineers who are manufacturing precision parts and they are a bit attached to calculator.
I stripped the problem down to its basics in which I made a simple c# and WPF touch app which kept track of how many touches it got, just to make sure its not just shoddy programming in the HMI. After getting the same results, no matter what I tried, I came here hoping someone else has run into and perhaps fixed this issue.
Here are some specs:
This HMI runs on Windows 7 and it is fully updated.
It is a C# program using Unity containers, Prism, and WPF
The touch is being handled through simple OnPreviewTouchDown and
TouchDown events
It doesn't matter if I run calculator through a Process in C# or if we run it from the actual OS, nor how we close the program, all permutations result in the same effect on every machine in the building with a touch screen.
It is an ELO touch screen with the newest drivers, though I have also tried it with a Vista Multitouch simulator and get the same results
Any sort of assistance or direction would be much appreciated. Thanks!
You are right. Microsoft released a fix recently for this issue for Windows 8 and other OS's, perhaps it applies to Windows 7 too.
Multi-touch gesture does not work after you exit the Calculator in Windows
Symptoms
This issue occurs in applications that are started before you
close the Windows Calculator (calc.exe) in Windows 8.1, Windows RT
8.1, or Windows Server 2012 R2.
Cause
This issue occurs because the Calculator exits and changes a
property. This causes the affected applications to stop responding to
multi-touch.
Resolution
We have released an update to resolve this issue.
See https://support.microsoft.com/en-us/kb/3024755
Workaround
To work around this issue, close and reopen the affected applications after the Calculator exits.