WhiteKnight - Block games from being able to see sticks using ViGEm

Post gaming related scripts
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

WhiteKnight - Block games from being able to see sticks using ViGEm

23 Jul 2017, 10:19

This is a solution for stopping games from seeing a DirectInput stick (Basically any stick except Xbox controllers) on your system.

For ages we have been able to create virtual controllers and remap a stick to that, but in the past we have not been able to stop the game from seeing the physical stick.

Well now we have a proper solution: The HidGuardian / HidCerberus components from ViGEm. HidGuardian is a device driver that you install which can hide sticks from the system. HidCerberus is a windows service that allows you to "whitelist" a process (eg your AHK script) so that your script is the ONLY thing on the system that can see through HidGuardian and read the stick. The stick even disappears from the joystick control panel in windows!

Download

There are two tools in the zip - a ready made Auto-Whitelister app, and a library if you wish to write your own solution.

Auto-Whitelister
(A pre-compiled version of this is provided, you do not need AutoHotkey installed to use it)
Image
This is used to whitelist an app of your choice (eg UJR, UCR, Joy2Key, GlovePIE maybe) with the ability to see through the HidGuardian block.
Click the button, click a window, and it will whitelist that app for you.
It keeps checking for the existence of the specified window, and tries to always keep the PID of the specified application in the whitelist up-to-date.
It will also install / uninstall HG or HC for you. It requires admin rights to run, but you will only get a UAC popup the first time.

Instruction Video:
This video demonstrates hiding a DualShock 4 controller and allowing only the remapping app "JoyShockMapper" to see the controller


Library
Usage is super simple - two lines of code: One to include the library, and one to initialize:

Code: Select all

#NoEnv
#SingleInstance force
#Persistent

; Load the library
#Include WhiteKnight.ahk

; Whitelist this script
wk := new WhiteKnight()

; Check if everything went OK
if (!wk.WhitelistState){
	MsgBox HidCerberus Whitelist failed
	ExitApp
}

; Poll a stick, to make sure it worked
Loop {
	ToolTip % GetKeyState("1JoyX")
	Sleep 100
}

^Esc::
	ExitApp
Setup
Download the attached ZIP and extract
Run the included WhiteKnight.ahk or WhiteKnight.exe and follow the instructions
Open an Administrator command prompt
Navigate to the Resources\1 HidGuardian folder from the zip
run HidGuardian Install.bat
Navigate to the Resources\2 HidCerberus folder from the zip
Navigate to the x86 folder on a 32-bit system, or the x64 folder if your system is 64-bit
run HidCerberus Install.bat

Check in your windows Services dialog if the HidCerberus service is running (Start->Services.msc)


Hiding sticks
Navigate to the HidGuardian config page (This is a link to a web server now running on your local system)
Find the stick you wish to hide from the list, and click the Hide button next to it.
Unplug the stick and plug it back in. It should now be gone from the Joystick control panel (Start->joy.cpl)
Note that in order to revert back to normal usage, you need to use this page to unhide the stick, then unplug and plug back in again.

Once a stick is hidden and you use the library from the zip, you can use normal AHK commands (eg GetKeyState) to read the state of the stick.
Last edited by evilC on 02 Oct 2019, 16:13, edited 12 times in total.
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

Re: WhiteKnight - Block games from being able to see sticks using ViGEm

24 Jul 2017, 13:37

FYI, all this library does is this:

When you start the script and load the library, it gets the PID (Process ID) of the AHK script, and adds it to the HidGuardian whitelist by making an HTTP request to http://localhost:26762/api/v1/hidguardi ... t/add/<PID of the script>".

When the script exits, it makes a call to http://localhost:26762/api/v1/hidguardi ... emove/<PID of the script>" to remove it from the whitelist.

This process is totally do-able manually - as long as you can find the PID of a process you want to whitelist, then you can just open a web browser and hit the appropriate URL.
cuyo001
Posts: 7
Joined: 12 Dec 2016, 20:25

Re: WhiteKnight - Block games from being able to see sticks using ViGEm

12 Aug 2017, 07:03

there must be something wrong with my sigth becausce i cant see the atachment zip
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

Re: WhiteKnight - Block games from being able to see sticks using ViGEm

12 Aug 2017, 12:23

Thanks for pointing that out, it seems that the edit post form allowed me to attach the zip, but when I submitted it, I guess it was too big or something and it removed it.
I uploaded it to my website instead and added a download link.
Guest

Re: WhiteKnight - Block games from being able to see sticks using ViGEm

30 Sep 2017, 00:47

Im unable to install the Hidcerberus service, when click the install button it always says "operation failed"; i can install Hidguardian without issues.
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

Re: WhiteKnight - Block games from being able to see sticks using ViGEm

30 Sep 2017, 03:51

It may well be an issue with my install scripts.

The manual install instructions are here. Give that a try and see if you can get it to install. All the files you need should be in WhiteKnight's resources folder.
Mysticalp

Re: WhiteKnight - Block games from being able to see sticks using ViGEm

02 Oct 2017, 05:22

Thanks a lot for this script! It has saved me tons of issues when using the DS4 gamepad in Windows. I had to turn off Steam, Kodi and UPlay. Not anymore :)
RecklessPrudence
Posts: 11
Joined: 27 Sep 2016, 07:40

Re: WhiteKnight - Block games from being able to see sticks using ViGEm

30 Oct 2017, 23:24

Stupid question: How do get UCR to see the device again? Whether I use the Auto-Whitelister or manually do it, the correct process ID appears in the config page, but I can't seem to get UCR to respond to my button presses. It's hiding the devices just fine, I just can't seem to whitelist them. Am I whitelisting the wrong thing?

EDIT: Nevermind, I just have to reboot each time I add a device to WhiteKnight's management list.
Dook
Posts: 2
Joined: 23 Sep 2016, 19:56

Re: WhiteKnight - Block games from being able to see sticks using ViGEm

14 Feb 2018, 10:58

WhiteKnight have bugs:
1) It is not considered that the response from cp.exe may not be in English
2) It is not considered the intermediate states of the service - START_PENDING, STOP_PENDING

Fixed code attached.

Example of whitelisted own script:

Code: Select all

#Include WhiteKnight.ahk
WhiteKnight := new WhiteKnight(0)
if (!WhiteKnight.HidGuardianWhitelist(1))
msgbox Failed to add to whitelist
Attachments
WhiteKnight.zip
(2.52 KiB) Downloaded 1430 times
Dook
Posts: 2
Joined: 23 Sep 2016, 19:56

Re: WhiteKnight - Block games from being able to see sticks using ViGEm

14 Feb 2018, 11:11

Bugs in Whiteknight are related only to the interaction with the service - On / Off / Installed / Uninstalled.

Is the new version HidGuardian available for download?
Last edited by Dook on 14 Feb 2018, 11:17, edited 1 time in total.
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

Re: WhiteKnight - Block games from being able to see sticks using ViGEm

14 Feb 2018, 11:16

I don't think he has made a public release yet, closed releases are made in Nefarius' Discord Channel
Be aware though, it is not stable yet, and will most likely BSOD your machine.
When it does work though.... it has Xbox pad blocking! If you block an xbox pad, and spin up a virtual one using ViGEm, whitelisted apps will see the physical xbox controller, non-whitelisted apps will see the vigem controller. How cool is that ?!?!?!
MetalRocks
Posts: 2
Joined: 25 Mar 2017, 19:46

Re: WhiteKnight - Block games from being able to see sticks using ViGEm

26 Oct 2019, 04:20

For those like me that get the "operation failed" error when installing HIDCerberus, the workaround to whitelist an application is to install only the HIDGuardian and:
1.- Execute manually HIDCerberus.Srv.exe (found in the Resources/HidCerberus folder)
2.- Find the PID of the application you want to whitelist (for windows users you can find it in the task manager)
3.- Append the PID to the end of the URL http localhost:26762 /api/v1/hidguardian/whitelist/add/ Broken Link for safety in your browser. You will get an "OK" message.
4.- Check that the application PID is whitelisted in http localhost:26762 / Broken Link for safety
e.g.: If the PID of the application you want to whitelist is 1111 you would go to the URL http localhost:26762 /api/v1/hidguardian/whitelist/add/1111 Broken Link for safety
OneStandUpGuy
Posts: 2
Joined: 10 Mar 2020, 22:57

Re: WhiteKnight - Block games from being able to see sticks using ViGEm

10 Mar 2020, 23:38

I keep getting "localhost refused to connect." when opening the HIDguardian config page
TheTitaniumTitan
Posts: 3
Joined: 13 Apr 2020, 17:14

Re: WhiteKnight - Block games from being able to see sticks using ViGEm

28 Jul 2020, 16:53

dont have much experience with this software and only made a couple macros using sleep controlsend and controlclick but i dont know why this code isnt working. I did some troubleshooting by putting msgboxes in the code and seeing where it would get "stuck" and it seems that it cant execute this peice of code i believe:

isInstalled := WhiteKnight.IsHgInstalled()
GuiControl, , % hHgStatus, % (isInstalled ? "Installed" : "Not Installed")
GuiControl, , % hHgStatusToggle, % (isInstalled ? "Uninstall" : "Install")
return

any help would be appreciated
Big J Money
Posts: 3
Joined: 29 Jan 2014, 15:04

Re: WhiteKnight - Block games from being able to see sticks using ViGEm

19 Oct 2020, 07:46

How does one uninstall HidGuardian / HidCerberus, if necessary? I see that HidCerberus is a Windows service.
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

Re: WhiteKnight - Block games from being able to see sticks using ViGEm

20 Oct 2020, 05:55

If you no longer want to use it, then yes, you should remove it.
HG is a driver, HC is a service
WhiteKnight can do the uninstall for you - if the button next to each says "Install", then it is not installed and clicking the button will install it.
If it is installed, then the button will say "Uninstall" and clicking it will uninstall it

If you wish to do it manually, then to uninstall HC:
From an admin command prompt in Resources\HidCerberus, execute HidCerberus.Srv.exe uninstall

To uninstall HG, from an admin command prompt in Resources, execute

Code: Select all

devcon.exe remove Root\HidGuardian
devcon.exe classfilter HIDClass upper !HidGuardian

Return to “Gaming Scripts (v1)”

Who is online

Users browsing this forum: No registered users and 31 guests