mirror of
https://github.com/nefarius/ViGEmBus.git
synced 2025-08-10 00:52:17 +00:00
Made new and delete work
This commit is contained in:
@@ -36,6 +36,7 @@ DEFINE_GUID(GUID_DEVCLASS_VIGEM_RAWPDO,
|
||||
|
||||
#pragma once
|
||||
|
||||
EXTERN_C_START
|
||||
|
||||
//
|
||||
// Describes the current stage a PDO completed
|
||||
@@ -85,3 +86,4 @@ VOID FORCEINLINE BUS_PDO_REPORT_STAGE_RESULT(
|
||||
(*Interface.BusPdoStageResult)(&Interface.InterfaceHeader, Stage, Serial, Status);
|
||||
}
|
||||
|
||||
EXTERN_C_END
|
||||
|
||||
@@ -1,38 +1,64 @@
|
||||
#pragma once
|
||||
#include <ntifs.h>
|
||||
|
||||
constexpr auto cpp_pool_tag = 'EGiV';
|
||||
|
||||
#ifdef _AMD64_
|
||||
|
||||
static void* operator new(size_t lBlockSize)
|
||||
void* operator new
|
||||
(
|
||||
size_t size
|
||||
)
|
||||
{
|
||||
return ExAllocatePoolWithTag(NonPagedPoolNx, lBlockSize, cpp_pool_tag);
|
||||
return ExAllocatePoolWithTag(NonPagedPoolNx, size, cpp_pool_tag);
|
||||
}
|
||||
|
||||
static void operator delete(void* p)
|
||||
void* operator new[]
|
||||
(
|
||||
size_t size
|
||||
)
|
||||
{
|
||||
if (p == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ExFreePoolWithTag(p, cpp_pool_tag);
|
||||
return ExAllocatePoolWithTag(NonPagedPoolNx, size, cpp_pool_tag);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static void* __CRTDECL operator new(size_t lBlockSize)
|
||||
void operator delete
|
||||
(
|
||||
void* what
|
||||
)
|
||||
{
|
||||
return ExAllocatePoolWithTag(NonPagedPoolNx, lBlockSize, CPP_POOL_TAG);
|
||||
if (what == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ExFreePoolWithTag(what, cpp_pool_tag);
|
||||
}
|
||||
|
||||
static void __CRTDECL operator delete(void* p)
|
||||
void operator delete
|
||||
(
|
||||
void* what,
|
||||
size_t size
|
||||
)
|
||||
{
|
||||
if (!p)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ExFreePoolWithTag(p, CPP_POOL_TAG);
|
||||
UNREFERENCED_PARAMETER(size);
|
||||
|
||||
if (what == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ExFreePoolWithTag(what, cpp_pool_tag);
|
||||
}
|
||||
|
||||
#endif
|
||||
void operator delete[]
|
||||
(
|
||||
void* what,
|
||||
size_t size
|
||||
)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(size);
|
||||
|
||||
if (what == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ExFreePoolWithTag(what, cpp_pool_tag);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
EXTERN_C_START
|
||||
|
||||
//
|
||||
// Used to identify children in the device list of the bus.
|
||||
//
|
||||
@@ -194,3 +196,4 @@ typedef struct _FDO_PLUGIN_REQUEST_DATA
|
||||
|
||||
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(FDO_PLUGIN_REQUEST_DATA, PluginRequestGetData)
|
||||
|
||||
EXTERN_C_END
|
||||
|
||||
@@ -10,7 +10,7 @@ using namespace ViGEm::Bus::Targets;
|
||||
|
||||
PCWSTR EmulationTargetDS4::_deviceDescription = L"Virtual DualShock 4 Controller";
|
||||
|
||||
NTSTATUS EmulationTargetDS4::PrepareDevice(PWDFDEVICE_INIT DeviceInit, USHORT VendorId, USHORT ProductId,
|
||||
NTSTATUS EmulationTargetDS4::PrepareDevice(PWDFDEVICE_INIT DeviceInit, USHORT VID, USHORT PID,
|
||||
PUNICODE_STRING DeviceId, PUNICODE_STRING DeviceDescription)
|
||||
{
|
||||
NTSTATUS status;
|
||||
@@ -19,8 +19,8 @@ NTSTATUS EmulationTargetDS4::PrepareDevice(PWDFDEVICE_INIT DeviceInit, USHORT Ve
|
||||
//
|
||||
// TODO: implement usage!
|
||||
//
|
||||
UNREFERENCED_PARAMETER(VendorId);
|
||||
UNREFERENCED_PARAMETER(ProductId);
|
||||
UNREFERENCED_PARAMETER(VID);
|
||||
UNREFERENCED_PARAMETER(PID);
|
||||
|
||||
// prepare device description
|
||||
status = RtlUnicodeStringInit(DeviceDescription, _deviceDescription);
|
||||
@@ -381,7 +381,7 @@ VOID EmulationTargetDS4::GetConfigurationDescriptorType(PUCHAR Buffer, ULONG Len
|
||||
RtlCopyBytes(Buffer, Ds4DescriptorData, Length);
|
||||
}
|
||||
|
||||
VOID EmulationTargetDS4::GetDeviceDescriptorType(PUSB_DEVICE_DESCRIPTOR pDescriptor, USHORT VendorId, USHORT ProductId)
|
||||
VOID EmulationTargetDS4::GetDeviceDescriptorType(PUSB_DEVICE_DESCRIPTOR pDescriptor)
|
||||
{
|
||||
pDescriptor->bLength = 0x12;
|
||||
pDescriptor->bDescriptorType = USB_DEVICE_DESCRIPTOR_TYPE;
|
||||
@@ -390,8 +390,8 @@ VOID EmulationTargetDS4::GetDeviceDescriptorType(PUSB_DEVICE_DESCRIPTOR pDescrip
|
||||
pDescriptor->bDeviceSubClass = 0x00;
|
||||
pDescriptor->bDeviceProtocol = 0x00;
|
||||
pDescriptor->bMaxPacketSize0 = 0x40;
|
||||
pDescriptor->idVendor = VendorId;
|
||||
pDescriptor->idProduct = ProductId;
|
||||
pDescriptor->idVendor = this->VendorId;
|
||||
pDescriptor->idProduct = this->ProductId;
|
||||
pDescriptor->bcdDevice = 0x0100;
|
||||
pDescriptor->iManufacturer = 0x01;
|
||||
pDescriptor->iProduct = 0x02;
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace ViGEm::Bus::Targets
|
||||
EmulationTargetDS4() = default;
|
||||
~EmulationTargetDS4() = default;
|
||||
|
||||
NTSTATUS PrepareDevice(PWDFDEVICE_INIT DeviceInit, USHORT VendorId, USHORT ProductId,
|
||||
NTSTATUS PrepareDevice(PWDFDEVICE_INIT DeviceInit, USHORT VID, USHORT PID,
|
||||
PUNICODE_STRING DeviceId, PUNICODE_STRING DeviceDescription) override;
|
||||
|
||||
NTSTATUS PrepareHardware(WDFDEVICE Device) override;
|
||||
@@ -22,7 +22,7 @@ namespace ViGEm::Bus::Targets
|
||||
|
||||
VOID GetConfigurationDescriptorType(PUCHAR Buffer, ULONG Length) override;
|
||||
|
||||
VOID GetDeviceDescriptorType(PUSB_DEVICE_DESCRIPTOR pDescriptor, USHORT VendorId, USHORT ProductId) override;
|
||||
VOID GetDeviceDescriptorType(PUSB_DEVICE_DESCRIPTOR pDescriptor) override;
|
||||
|
||||
VOID SelectConfiguration(PUSBD_INTERFACE_INFORMATION pInfo) override;
|
||||
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
#include "EmulationTargetPDO.hpp"
|
||||
#include "CRTCPP.hpp"
|
||||
|
||||
using namespace ViGEm::Bus::Core;
|
||||
|
||||
BOOLEAN USB_BUSIFFN EmulationTargetPDO::UsbIsDeviceHighSpeed(IN PVOID BusContext)
|
||||
BOOLEAN USB_BUSIFFN ViGEm::Bus::Core::EmulationTargetPDO::UsbIsDeviceHighSpeed(IN PVOID BusContext)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(BusContext);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
NTSTATUS USB_BUSIFFN EmulationTargetPDO::UsbQueryBusInformation(IN PVOID BusContext, IN ULONG Level,
|
||||
IN OUT PVOID BusInformationBuffer,
|
||||
IN OUT PULONG BusInformationBufferLength,
|
||||
OUT PULONG BusInformationActualLength)
|
||||
NTSTATUS USB_BUSIFFN ViGEm::Bus::Core::EmulationTargetPDO::UsbQueryBusInformation(IN PVOID BusContext, IN ULONG Level,
|
||||
IN OUT PVOID BusInformationBuffer,
|
||||
IN OUT PULONG BusInformationBufferLength,
|
||||
OUT PULONG BusInformationActualLength)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(BusContext);
|
||||
UNREFERENCED_PARAMETER(Level);
|
||||
@@ -23,7 +23,7 @@ NTSTATUS USB_BUSIFFN EmulationTargetPDO::UsbQueryBusInformation(IN PVOID BusCont
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
|
||||
NTSTATUS USB_BUSIFFN EmulationTargetPDO::UsbSubmitIsoOutUrb(IN PVOID BusContext, IN PURB Urb)
|
||||
NTSTATUS USB_BUSIFFN ViGEm::Bus::Core::EmulationTargetPDO::UsbSubmitIsoOutUrb(IN PVOID BusContext, IN PURB Urb)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(BusContext);
|
||||
UNREFERENCED_PARAMETER(Urb);
|
||||
@@ -31,7 +31,7 @@ NTSTATUS USB_BUSIFFN EmulationTargetPDO::UsbSubmitIsoOutUrb(IN PVOID BusContext,
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
|
||||
NTSTATUS USB_BUSIFFN EmulationTargetPDO::UsbQueryBusTime(IN PVOID BusContext, IN OUT PULONG CurrentUsbFrame)
|
||||
NTSTATUS USB_BUSIFFN ViGEm::Bus::Core::EmulationTargetPDO::UsbQueryBusTime(IN PVOID BusContext, IN OUT PULONG CurrentUsbFrame)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(BusContext);
|
||||
UNREFERENCED_PARAMETER(CurrentUsbFrame);
|
||||
@@ -39,9 +39,9 @@ NTSTATUS USB_BUSIFFN EmulationTargetPDO::UsbQueryBusTime(IN PVOID BusContext, IN
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
|
||||
VOID USB_BUSIFFN EmulationTargetPDO::UsbGetUSBDIVersion(IN PVOID BusContext,
|
||||
IN OUT PUSBD_VERSION_INFORMATION VersionInformation,
|
||||
IN OUT PULONG HcdCapabilities)
|
||||
VOID USB_BUSIFFN ViGEm::Bus::Core::EmulationTargetPDO::UsbGetUSBDIVersion(IN PVOID BusContext,
|
||||
IN OUT PUSBD_VERSION_INFORMATION VersionInformation,
|
||||
IN OUT PULONG HcdCapabilities)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(BusContext);
|
||||
|
||||
@@ -56,3 +56,7 @@ VOID USB_BUSIFFN EmulationTargetPDO::UsbGetUSBDIVersion(IN PVOID BusContext,
|
||||
*HcdCapabilities = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ViGEm::Bus::Core::EmulationTargetPDO::EmulationTargetPDO(USHORT VID, USHORT PID): VendorId(VID), ProductId(PID)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace ViGEm::Bus::Core
|
||||
class EmulationTargetPDO
|
||||
{
|
||||
public:
|
||||
EmulationTargetPDO() = default;
|
||||
EmulationTargetPDO(USHORT VID, USHORT PID);
|
||||
|
||||
virtual ~EmulationTargetPDO() = default;
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace ViGEm::Bus::Core
|
||||
|
||||
virtual VOID GetConfigurationDescriptorType(PUCHAR Buffer, ULONG Length) = 0;
|
||||
|
||||
virtual VOID GetDeviceDescriptorType(PUSB_DEVICE_DESCRIPTOR pDescriptor, USHORT VendorId, USHORT ProductId) = 0;
|
||||
virtual VOID GetDeviceDescriptorType(PUSB_DEVICE_DESCRIPTOR pDescriptor) = 0;
|
||||
|
||||
virtual VOID SelectConfiguration(PUSBD_INTERFACE_INFORMATION pInfo) = 0;
|
||||
protected:
|
||||
@@ -63,12 +63,12 @@ namespace ViGEm::Bus::Core
|
||||
//
|
||||
// Unique serial number of the device on the bus
|
||||
//
|
||||
ULONG SerialNo;
|
||||
ULONG SerialNo{};
|
||||
|
||||
//
|
||||
// PID of the process creating this PDO
|
||||
//
|
||||
DWORD OwnerProcessId;
|
||||
DWORD OwnerProcessId{};
|
||||
|
||||
//
|
||||
// Device type this PDO is emulating
|
||||
@@ -78,21 +78,21 @@ namespace ViGEm::Bus::Core
|
||||
//
|
||||
// If set, the vendor ID the emulated device is reporting
|
||||
//
|
||||
USHORT VendorId;
|
||||
USHORT VendorId{};
|
||||
|
||||
//
|
||||
// If set, the product ID the emulated device is reporting
|
||||
//
|
||||
USHORT ProductId;
|
||||
USHORT ProductId{};
|
||||
|
||||
//
|
||||
// Queue for incoming data interrupt transfer
|
||||
//
|
||||
WDFQUEUE PendingUsbInRequests;
|
||||
WDFQUEUE PendingUsbInRequests{};
|
||||
|
||||
//
|
||||
// Queue for inverted calls
|
||||
//
|
||||
WDFQUEUE PendingNotificationRequests;
|
||||
WDFQUEUE PendingNotificationRequests{};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ using namespace ViGEm::Bus::Targets;
|
||||
|
||||
PCWSTR EmulationTargetXUSB::_deviceDescription = L"Virtual Xbox 360 Controller";
|
||||
|
||||
NTSTATUS EmulationTargetXUSB::PrepareDevice(PWDFDEVICE_INIT DeviceInit, USHORT VendorId,
|
||||
USHORT ProductId, PUNICODE_STRING DeviceId,
|
||||
NTSTATUS EmulationTargetXUSB::PrepareDevice(PWDFDEVICE_INIT DeviceInit, USHORT VID,
|
||||
USHORT PID, PUNICODE_STRING DeviceId,
|
||||
PUNICODE_STRING DeviceDescription)
|
||||
{
|
||||
NTSTATUS status;
|
||||
@@ -29,7 +29,7 @@ NTSTATUS EmulationTargetXUSB::PrepareDevice(PWDFDEVICE_INIT DeviceInit, USHORT V
|
||||
}
|
||||
|
||||
// Set hardware ID
|
||||
RtlUnicodeStringPrintf(&buffer, L"USB\\VID_%04X&PID_%04X", VendorId, ProductId);
|
||||
RtlUnicodeStringPrintf(&buffer, L"USB\\VID_%04X&PID_%04X", VID, PID);
|
||||
|
||||
RtlUnicodeStringCopy(DeviceId, &buffer);
|
||||
|
||||
@@ -443,7 +443,7 @@ VOID EmulationTargetXUSB::GetConfigurationDescriptorType(PUCHAR Buffer, ULONG Le
|
||||
RtlCopyBytes(Buffer, XusbDescriptorData, Length);
|
||||
}
|
||||
|
||||
VOID EmulationTargetXUSB::GetDeviceDescriptorType(PUSB_DEVICE_DESCRIPTOR pDescriptor, USHORT VendorId, USHORT ProductId)
|
||||
VOID EmulationTargetXUSB::GetDeviceDescriptorType(PUSB_DEVICE_DESCRIPTOR pDescriptor)
|
||||
{
|
||||
pDescriptor->bLength = 0x12;
|
||||
pDescriptor->bDescriptorType = USB_DEVICE_DESCRIPTOR_TYPE;
|
||||
@@ -452,8 +452,8 @@ VOID EmulationTargetXUSB::GetDeviceDescriptorType(PUSB_DEVICE_DESCRIPTOR pDescri
|
||||
pDescriptor->bDeviceSubClass = 0xFF;
|
||||
pDescriptor->bDeviceProtocol = 0xFF;
|
||||
pDescriptor->bMaxPacketSize0 = 0x08;
|
||||
pDescriptor->idVendor = VendorId;
|
||||
pDescriptor->idProduct = ProductId;
|
||||
pDescriptor->idVendor = this->VendorId;
|
||||
pDescriptor->idProduct = this->ProductId;
|
||||
pDescriptor->bcdDevice = 0x0114;
|
||||
pDescriptor->iManufacturer = 0x01;
|
||||
pDescriptor->iProduct = 0x02;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace ViGEm::Bus::Targets
|
||||
{
|
||||
constexpr auto XUSB_POOL_TAG = 'EGiV';
|
||||
|
||||
|
||||
typedef struct _XUSB_INTERRUPT_IN_PACKET
|
||||
{
|
||||
UCHAR Id;
|
||||
@@ -15,30 +15,28 @@ namespace ViGEm::Bus::Targets
|
||||
UCHAR Size;
|
||||
|
||||
XUSB_REPORT Report;
|
||||
|
||||
} XUSB_INTERRUPT_IN_PACKET, * PXUSB_INTERRUPT_IN_PACKET;
|
||||
} XUSB_INTERRUPT_IN_PACKET, *PXUSB_INTERRUPT_IN_PACKET;
|
||||
|
||||
|
||||
|
||||
class EmulationTargetXUSB : public Core::EmulationTargetPDO
|
||||
{
|
||||
public:
|
||||
EmulationTargetXUSB() = default;
|
||||
~EmulationTargetXUSB() = default;
|
||||
|
||||
NTSTATUS PrepareDevice(PWDFDEVICE_INIT DeviceInit, USHORT VendorId, USHORT ProductId,
|
||||
PUNICODE_STRING DeviceId, PUNICODE_STRING DeviceDescription);
|
||||
NTSTATUS PrepareDevice(PWDFDEVICE_INIT DeviceInit, USHORT VID, USHORT PID,
|
||||
PUNICODE_STRING DeviceId, PUNICODE_STRING DeviceDescription) override;
|
||||
|
||||
NTSTATUS PrepareHardware(WDFDEVICE Device);
|
||||
NTSTATUS PrepareHardware(WDFDEVICE Device) override;
|
||||
|
||||
NTSTATUS InitContext(WDFDEVICE Device);
|
||||
NTSTATUS InitContext(WDFDEVICE Device) override;
|
||||
|
||||
VOID GetConfigurationDescriptorType(PUCHAR Buffer, ULONG Length);
|
||||
VOID GetConfigurationDescriptorType(PUCHAR Buffer, ULONG Length) override;
|
||||
|
||||
VOID GetDeviceDescriptorType(PUSB_DEVICE_DESCRIPTOR pDescriptor, USHORT VendorId, USHORT ProductId);
|
||||
VOID GetDeviceDescriptorType(PUSB_DEVICE_DESCRIPTOR pDescriptor) override;
|
||||
|
||||
VOID SelectConfiguration(PUSBD_INTERFACE_INFORMATION pInfo) override;
|
||||
|
||||
VOID SelectConfiguration(PUSBD_INTERFACE_INFORMATION pInfo);
|
||||
|
||||
private:
|
||||
static PCWSTR _deviceDescription;
|
||||
|
||||
@@ -53,7 +51,7 @@ namespace ViGEm::Bus::Targets
|
||||
static const int XUSB_LEDNUM_SIZE = 0x01;
|
||||
static const int XUSB_INIT_STAGE_SIZE = 0x03;
|
||||
static const int XUSB_BLOB_STORAGE_SIZE = 0x2A;
|
||||
|
||||
|
||||
static const int XUSB_BLOB_00_OFFSET = 0x00;
|
||||
static const int XUSB_BLOB_01_OFFSET = 0x03;
|
||||
static const int XUSB_BLOB_02_OFFSET = 0x06;
|
||||
@@ -62,7 +60,7 @@ namespace ViGEm::Bus::Targets
|
||||
static const int XUSB_BLOB_05_OFFSET = 0x20;
|
||||
static const int XUSB_BLOB_06_OFFSET = 0x23;
|
||||
static const int XUSB_BLOB_07_OFFSET = 0x26;
|
||||
|
||||
|
||||
//
|
||||
// Rumble buffer
|
||||
//
|
||||
@@ -105,8 +103,7 @@ namespace ViGEm::Bus::Targets
|
||||
typedef struct _XUSB_PDO_CONTEXT
|
||||
{
|
||||
EmulationTargetXUSB* Context;
|
||||
|
||||
} XUSB_PDO_CONTEXT, * PXUSB_PDO_CONTEXT;
|
||||
} XUSB_PDO_CONTEXT, *PXUSB_PDO_CONTEXT;
|
||||
|
||||
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(XUSB_PDO_CONTEXT, XusbPdoGetContext)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user