• This repository has been archived on 08/Sep/2023
  • Stars
    star
    128
  • Rank 281,044 (Top 6 %)
  • Language
    C
  • License
    MIT License
  • Created about 6 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

ViGEm Client SDK for feeder development.

ViGEm Client Native SDK

C/C++ developer SDK for communication with ViGEmBus.

Build status Discord

About

TL;DR: use this if you want to create virtual game controllers from your C/C++ application 😊

The ViGEmClient provides a small library exposing a simple API for creating and "feeding" (periodically updating it with new input data) virtual game controllers through ViGEmBus. The library takes care of discovering a compatible instance of the bus driver on the user's system and abstracting away the inner workings of the emulation framework. You can use and distribute it with your project as either a static component (recommended) or a dynamic library (DLL). This library is not thread-safe, ensure proper synchronization in a multi-threaded environment.

How to build

Prerequisites

  • Visual Studio 2019 (Community Edition is just fine)
    • When linking statically, make sure to also link against setupapi.lib

Contribute

Bugs & Features

Found a bug and want it fixed? Open a detailed issue on the GitHub issue tracker!

Have an idea for a new feature? Let's have a chat about your request on our support channels.

Questions & Support

Please respect that the GitHub issue tracker isn't a helpdesk. We offer support resources, where you're welcome to check out and engage in discussions!

How to use

Integration

Integrating this library into your project is pretty straight-forward, there are no additional 3rd party dependencies. You can either git submodule or git subtree this repository directly into your source tree or use the provided vcpkg package manager integration found here (recommended, can be updated with ease). The library tries to handle driver compatibility internally so static linking is recommended to avoid DLL hell 😊

API usage

For a general overview of the provided types and functions take a look at the main include file.

Now, onwards to a practical example πŸ˜‰ First, include some basic headers:

//
// Windows basic types 'n' fun
//
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

//
// Optional depending on your use case
//
#include <Xinput.h>

//
// The ViGEm API
//
#include <ViGEm/Client.h>

//
// Link against SetupAPI
//
#pragma comment(lib, "setupapi.lib")

To initialize the API call vigem_alloc which gives you an opaque handle to the underlying driver:

const auto client = vigem_alloc();

if (client == nullptr)
{
    std::cerr << "Uh, not enough memory to do that?!" << std::endl;
    return -1;
}

Establish connection to the driver:

const auto retval = vigem_connect(client);

if (!VIGEM_SUCCESS(retval))
{
    std::cerr << "ViGEm Bus connection failed with error code: 0x" << std::hex << retval << std::endl;
    return -1;
}

πŸ‘‰ Note: this is an "expensive" operation, it's recommended you do this once in your project, not every frame for performance benefits.


With this handle we're prepared to spawn (connect) and feed (supply with periodic input updates) one or many emulated controller devices. So let's spawn an Xbox 360 controller:

//
// Allocate handle to identify new pad
//
const auto pad = vigem_target_x360_alloc();

//
// Add client to the bus, this equals a plug-in event
//
const auto pir = vigem_target_add(client, pad);

//
// Error handling
//
if (!VIGEM_SUCCESS(pir))
{
    std::cerr << "Target plugin failed with error code: 0x" << std::hex << pir << std::endl;
    return -1;
}

XINPUT_STATE state;

//
// Grab the input from a physical X36ß pad in this example
//
XInputGetState(0, &state);

//
// The XINPUT_GAMEPAD structure is identical to the XUSB_REPORT structure
// so we can simply take it "as-is" and cast it.
//
// Call this function on every input state change e.g. in a loop polling
// another joystick or network device or thermometer or... you get the idea.
//
vigem_target_x360_update(client, pad, *reinterpret_cast<XUSB_REPORT*>(&state.Gamepad));

//
// We're done with this pad, free resources (this disconnects the virtual device)
//
vigem_target_remove(client, pad);
vigem_target_free(pad);

Alright, so we got the feeding side of things done, but what about the other direction? After all, the virtual device can receive some state changes as well (for the Xbox 360 device the LED ring can change and rumble/vibration requests can arrive) and this information is of interest for us. This is achieved by defining a notification callback like so:

//
// Define the callback function
//
VOID CALLBACK notification(
    PVIGEM_CLIENT Client,
    PVIGEM_TARGET Target,
    UCHAR LargeMotor,
    UCHAR SmallMotor,
    UCHAR LedNumber,
    LPVOID UserData
)
{
    static int count = 1;

    std::cout.width(3);
    std::cout << count++ << " ";
    std::cout.width(3);
    std::cout << (int)LargeMotor << " ";
    std::cout.width(3);
    std::cout << (int)SmallMotor << std::endl;
}

Register it:

const auto retval = vigem_target_x360_register_notification(client, pad, &notification, nullptr);

//
// Error handling
//
if (!VIGEM_SUCCESS(retval))
{
    std::cerr << "Registering for notification failed with error code: 0x" << std::hex << retval << std::endl;
    return -1;
}

The function notification will now get invoked every time a rumble request was sent to the virtual controller and can get handled accordingly. This is a blocking call and the invocation will take place in the order the underlying requests arrived.


Once ViGEm interaction is no longer required (e.g. the application is about to end) the acquired resources need to be freed properly:

vigem_disconnect(client);
vigem_free(client);

After that the client handle will become invalid and must not be used again.

More Repositories

1

ScpToolkit

Windows Driver and XInput Wrapper for Sony DualShock 3/4 Controllers
C#
3,025
star
2

ViGEmBus

Windows kernel-mode driver emulating well-known USB game controllers.
C++
2,582
star
3

DsHidMini

Virtual HID Mini-user-mode-driver for Sony DualShock 3 Controllers
C
1,174
star
4

HidHide

Gaming Input Peripherals Device Firewall for Windows.
C++
888
star
5

BthPS3

Windows kernel-mode Bluetooth Profile & Filter Drivers for PS3 peripherals
HTML
630
star
6

Injector

Command line utility to inject and eject DLLs
C++
375
star
7

Indicium-Supra

DirectX API-hooking framework
C++
300
star
8

FireShock

Windows USB Driver for Sony DualShock 3 Controllers
C
210
star
9

Legacinator

The one and only Legacinator
C#
173
star
10

HidGuardian

Windows kernel-mode driver for controlling access to various input devices.
C
171
star
11

Shibari

Gaming input peripherals prototyping platform for Windows
C#
139
star
12

ViGEm.NET

.NET bindings for the ViGEmClient library.
C#
99
star
13

VDX

XInput/x360ce to ViGEm sample application
C++
88
star
14

ViGEm.github.io

Sources of ViGEm Website.
HTML
74
star
15

vicius

Nefarius' nŏvīcĭus universal software updater agent for Windows.
C++
49
star
16

nefcon

Windows device driver installation and management tool.
C++
45
star
17

ScpVBus

Scarlett.Crush Productions Virtual Bus Driver
C
40
star
18

AirBender

Windows Bluetooth Host Driver for Sony DualShock Controllers
C
39
star
19

socksifier

One DLL to redirect them all to a SOCKS5 server.
C
35
star
20

sm-ext-socket

This extension provides networking functionality for SourceMod scripts.
C++
33
star
21

XInputHooker

XInput reverse-engineering tools and documentation
C++
30
star
22

Nefarius.Utilities.DeviceManagement

Managed wrappers around SetupAPI, Cfgmgr32, NewDev and DrvStore native APIs on Windows.
C#
30
star
23

Identinator

Rewrites hardware identification properties of USB devices on Microsoft Windows
C#
28
star
24

docs.nefarius.at

Sources of Nefarius' Knowledge-Base Website
HTML
20
star
25

WpfRichText.Ex

Simple WYSIWYG HTML editor control for WPF
C#
19
star
26

Nefarius.DSharpPlus.Extensions.Hosting

Glues .NET Core Hosting and DSharpPlus together for use with DI.
C#
15
star
27

MACAddressChanger

Easily change your network adapters MAC address with this little tool.
C++
13
star
28

CntlmUI

Graphical User Interface and Startup-Agent for the Cntlm Authorization Proxy
C#
12
star
29

DLLSpy

DLL Hijacking Detection Tool
C++
11
star
30

Nefarius.Drivers.WinUSB

WinUSB .NET wrapper library
C#
11
star
31

rtmp-server

Self-hosted RTMP streaming server with web player
HTML
10
star
32

libsbc

Bluetooth low-complexity, subband codec (SBC) library
C
10
star
33

Nefarius.Drivers.HidHide

Managed API for configuring HidHide.
C#
10
star
34

Nefarius.Utilities.Bluetooth

Utility library for unconventional Bluetooth tasks on Windows.
C#
9
star
35

WorkshopMapLoader

Advanced Workshop Map Loader and Game Type Adjuster
SourcePawn
9
star
36

Nefarius.Utilities.WindowsVersion

Utility classes to get detailed Windows version and some extras like UEFI and BCD properties.
C#
8
star
37

udpflood

Simple network stress test tool which penetrates a target host with random UDP packages.
C
8
star
38

WinApiSniffer

Windows API sniffer and dumper utility for reverse engineering.
C
8
star
39

WinDbgSymbolsCachingProxy

WinDbg Symbols Caching Proxy.
C#
8
star
40

HideDS4

A small helper-library which prevents a process from accessing a connected DualShock 4 controller
C++
7
star
41

Nefarius.Peripherals.SerialPort

P/Invoke wrapper for Win32API serial port
C#
7
star
42

Nefarius.Utilities.HIDReportKit

Managed types and utility classes for HID report parsing and transforming.
C#
7
star
43

AnnoyingFlooder

Wanna make a little prank to your IT-Friends? Use this tool and fill his hard drive with hidden garbage files!
C#
6
star
44

WDF-Utils

Windows Device Driver Development Utilities Collection
C
6
star
45

WireShock

Windows Bluetooth Host Driver for Sony DualShock Controllers
C
6
star
46

TrueMount-2

Automounter for TrueCrypt.
C#
5
star
47

HidCerberus

Companion service to manage HidGuardian device blocking and process whitelisting.
C#
5
star
48

GotifySmtpForwarder

Forwards e-mails to a Gotify application.
C#
4
star
49

ViGEm.Setup

Resources for builing a setup to redistribute a device driver reliably.
C#
4
star
50

EPPT

A simple, self-contained Windows tool to display and toggle "Enhanced Pointer Precision" a.k.a. mouse acceleration.
C++
4
star
51

ViGEm.Management

Tools for distribution, installation and management of the ViGEm framework drivers.
C#
4
star
52

StreamsFinder

MicrosoftΒ΄s new technology file system has a pretty unknown feature called data streams. Find hidden ones easily with this tool!
C#
4
star
53

putty-tunnel-manager

Automatically exported from code.google.com/p/putty-tunnel-manager
C#
4
star
54

ViGEmClient.vcpkg

Vcpkg portfile for native ViGEm Client library
CMake
3
star
55

SourceSec

Proof-of-concept RSA SourceMod extension
C++
3
star
56

TrueMount-3

Automounter for TrueCrypt
C#
3
star
57

XInputPlayerToDevicePath

XInput User Index to Device Instance ID PoC
C++
3
star
58

Nefarius.Utilities.SessionNotification

Utility classes to get notified about session state changes on Windows.
C#
3
star
59

CitrixConfigurator

Edit the registry-stored configuration of the Citrix Online Plug-in with this small tool.
C#
3
star
60

garbage-and-scam-sites

My personal little rule set for uBlacklist blocking useless and scam trash sites 🚯
3
star
61

vpatch

Versioning helper command line utility
C#
3
star
62

AppVeyorArtifactsReceiver

Web service listening for deployment webhook calls from AppVeyor CI/CD.
C#
3
star
63

Nefarius.Utilities.Registry

Registry Export File (.reg) Parser
C#
3
star
64

Mana

A tiny work-in-progress Kibana replacement using Blazor.
C#
3
star
65

Nefarius.Utilities.GitHubUpdater

Utility classes to perform application update checks using GitHub repositories.
C#
3
star
66

LupuServ

E-Mail to SMS Gateway service for Lupusec XT1 alarm system
C#
2
star
67

IgorBot

Advanced Discord bot to automate new Member on-boarding.
C#
2
star
68

Libarius

Collection of utility classes for common .NET tasks
C#
2
star
69

ManagedDevcon

Managed wrapper around various SetupAPI functions.
C#
2
star
70

ds4sniffer

DLL performing API-hooking to find which process is talking to the DS4.
C++
2
star
71

AdvancedUpdaterGitHubProxy

Builds an Advanced Installer Updater Configuration File from GitHub Releases.
C#
2
star
72

POCO-Windows

NuGet build scripts for POCO C++ libraries
PowerShell
2
star
73

foxx-filestore

File Storage Foxx Microservice for ArangoDB
JavaScript
2
star
74

Nefarius.Standards.CAMT

Utility classes to help decoding "Bank-to-Customer Cash Management Swiss Payment Standards" a.k.a. CAMT XML files.
C#
2
star
75

CSGOLauncher

Small .NET GUI launcher for CS:GO Windows server
C#
2
star
76

Symphonia

Simple DLNA-compatible music player
C#
2
star
77

NuGetCachingProxy

A very simple caching proxy for NuGet packages
C#
2
star
78

Nefarius.Utilities.AspNetCore

My opinionated collection of utilities for ASP.NET Core applications.
C#
2
star
79

Nefarius.Utilities.DotNetInstaller

Utility classes to download and install modern .NET runtimes.
C#
1
star
80

docker-node-service-host

Provides a convenience Docker image to run Node services under Supervisord.
Dockerfile
1
star
81

Nefarius.Utilities.NtDll

Managed wrappers around NTDLL native APIs on Windows.
C#
1
star
82

metamodmmt

Proxy DLL for Metamod for Half-Life 1 enabling Windows high-resolution timers
C++
1
star
83

nefarius

My GitHub public profile!
1
star
84

SCD

To Secure, Contain, and Deny
C
1
star
85

SIF

Squid Image Fetcher
Python
1
star
86

Updater

Automatically updates SourceMod plugins and files
SourcePawn
1
star
87

ServerHibernateFix

A Sourcemod Plugin to work-around the workshop map server hibernate problem
SourcePawn
1
star
88

MightyDsHidMini

Crude quick 'n' dirty benchmark tool for DsHidMini
C#
1
star
89

ScpSamples

Sample Add-Ons for the ScpServer
C#
1
star
90

ViGEm.Jaeger

Benchmark tool for the client SDK using Jaeger Tracing
C++
1
star
91

Arduino_Uno_Audio_PWM_Modulator

Arduino
1
star
92

honestus

Versioning helper command line utility
C#
1
star
93

ReactiveProtobuf

Protobuf protocol implementation for ReactiveSockets
C#
1
star
94

Nefarius.Utilities.EnglishExceptions

Unlocalizes non-English exception messages in any .NET application.
C#
1
star
95

nefarius-vcpkg-registry

My vcpkg packages registry.
PowerShell
1
star
96

Nefarius.Utilities.WixSharp

C#
1
star
97

Nefarius.Steam.PartnerWebApi

Steamworks Web API wrapper for .NET using Refit.
C#
1
star
98

docker-mdwiki

Docker container for hosting and auto-updating an MDwiki instance.
HTML
1
star
99

CentralisedOutlookSignature

C#
1
star
100

Nefarius.HttpClient.LiteDbCache

Adds disk-based response caching to HttpClient named instances using LiteDB.
C#
1
star